(ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any)
| 28 | * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters. |
| 29 | */ |
| 30 | export const scatterPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => { |
| 31 | const config = plotConfig["config"] |
| 32 | const layout = plotConfig["layout"] |
| 33 | |
| 34 | if (ndframe instanceof Series) { |
| 35 | const y = ndframe.values as any; |
| 36 | let trace: Data = { |
| 37 | x: ndframe.index as any, |
| 38 | y, |
| 39 | type: 'scatter', |
| 40 | mode: 'markers', |
| 41 | }; |
| 42 | |
| 43 | Plotly.newPlot(divId, [trace], layout, config); |
| 44 | |
| 45 | } else { |
| 46 | |
| 47 | if (config["x"] && config["y"]) { |
| 48 | //Plotting two columns against each other, when user specifies x and y column names in configuration |
| 49 | throwErrorOnWrongColName(ndframe, config["x"]); |
| 50 | throwErrorOnWrongColName(ndframe, config["y"]); |
| 51 | |
| 52 | const x = ndframe[config.x].values; |
| 53 | const y = ndframe[config.y].values; |
| 54 | |
| 55 | const trace: Data = { |
| 56 | x, |
| 57 | y, |
| 58 | type: 'scatter', |
| 59 | mode: 'markers', |
| 60 | }; |
| 61 | const _layout = { |
| 62 | xaxis: { |
| 63 | title: config.x, |
| 64 | }, |
| 65 | yaxis: { |
| 66 | title: config.y, |
| 67 | }, |
| 68 | ...layout, |
| 69 | }; |
| 70 | |
| 71 | Plotly.newPlot(divId, [trace], _layout, config); |
| 72 | |
| 73 | } else if (config["x"] || config["y"]) { |
| 74 | //plot single column specified in either of param [x | y] against index |
| 75 | if (config["x"]) { |
| 76 | throwErrorOnWrongColName(ndframe, config.x); |
| 77 | |
| 78 | const x = ndframe[config.x].values; |
| 79 | const y = ndframe.index; |
| 80 | |
| 81 | const trace: Data = { |
| 82 | x, |
| 83 | y, |
| 84 | type: 'scatter', |
| 85 | mode: 'markers', |
| 86 | }; |
| 87 | const _layout = { |
no test coverage detected