(ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any)
| 30 | * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters. |
| 31 | */ |
| 32 | export const piePlot = (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 | let trace: Data = { |
| 38 | values: ndframe.values as any, |
| 39 | labels: config["labels"] || ndframe.index as any, |
| 40 | type: 'pie', |
| 41 | name: config.labels, |
| 42 | hoverinfo: 'label+percent+name', |
| 43 | automargin: true |
| 44 | }; |
| 45 | |
| 46 | Plotly.newPlot(divId, [trace], layout, config); |
| 47 | |
| 48 | } else { |
| 49 | if (config["labels"]) { |
| 50 | |
| 51 | if (!ndframe.columns.includes(config['labels'])) { |
| 52 | throw Error(`Column Error: ${config['labels']} not found in columns. Param "labels" name must be one of [ ${ndframe.columns}]`); |
| 53 | } |
| 54 | |
| 55 | if (config["values"]) { |
| 56 | |
| 57 | if (!ndframe.columns.includes(config['values'])) { |
| 58 | throw Error(`Column Error: ${config['values']} not found in columns. Param "values" name must be one of [ ${ndframe.columns}]`); |
| 59 | } |
| 60 | |
| 61 | let trace: Data = { |
| 62 | values: ndframe[config['values']].values as any, |
| 63 | labels: ndframe[config["labels"]].values as any, |
| 64 | type: 'pie', |
| 65 | name: config.labels, |
| 66 | hoverinfo: 'label+percent+name', |
| 67 | automargin: true |
| 68 | }; |
| 69 | |
| 70 | Plotly.newPlot(divId, [trace], layout, config); |
| 71 | |
| 72 | } else { |
| 73 | // if columns is not specified in config, then plot all columns |
| 74 | const cols = config["columns"] ? checkIfColsExist(ndframe, config['columns']) : ndframe.columns; |
| 75 | |
| 76 | if (config['rowPositions']) { |
| 77 | if (config['rowPositions'].length != cols.length) { |
| 78 | throw Error(`length of rowPositions array must be equal to number of columns. Got ${config['rowPositions'].length}, expected ${cols.length - 1}`); |
| 79 | } |
| 80 | } else { |
| 81 | let tempArr = []; |
| 82 | for (let i = 0; i < cols.length - 1; i++) { |
| 83 | tempArr.push(0); |
| 84 | } |
| 85 | config['rowPositions'] = tempArr; |
| 86 | |
| 87 | } |
| 88 | |
| 89 | if (config['columnPositions']) { |
no test coverage detected