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