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