| 25 | * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters. |
| 26 | */ |
| 27 | export const tablePlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => { |
| 28 | const config = plotConfig["config"] |
| 29 | const layout = plotConfig["layout"] |
| 30 | let header: any = {}; |
| 31 | let cells: any = {}; |
| 32 | let colsData: any[] = []; |
| 33 | let cols2Show: any[] = [] |
| 34 | |
| 35 | if (config['columns']) { |
| 36 | |
| 37 | config['columns'].forEach((cname) => { |
| 38 | if (!ndframe.columns.includes(cname)) { |
| 39 | throw Error(`Column Error: ${cname} not found in columns. Columns should be one of [ ${ndframe.columns} ]`); |
| 40 | } |
| 41 | |
| 42 | let idx = ndframe.columns.indexOf(cname); |
| 43 | colsData.push(ndframe.getColumnData[idx]); |
| 44 | }); |
| 45 | |
| 46 | cols2Show = config['columns']; |
| 47 | } else { |
| 48 | |
| 49 | cols2Show = ndframe.columns; |
| 50 | colsData = ndframe.getColumnData; |
| 51 | |
| 52 | } |
| 53 | |
| 54 | header['values'] = cols2Show.map((col) => [col]); |
| 55 | cells['values'] = colsData; |
| 56 | |
| 57 | if (config['tableHeaderStyle']) { |
| 58 | Object.keys(config['tableHeaderStyle']).forEach((param) => { |
| 59 | header[param] = config['tableHeaderStyle'][param]; |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | if (config['tableCellStyle']) { |
| 64 | Object.keys(config['tableCellStyle']).forEach((param) => { |
| 65 | cells[param] = config['tableCellStyle'][param]; |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | const trace = { |
| 70 | type: 'table', |
| 71 | header, |
| 72 | cells |
| 73 | }; |
| 74 | /* @ts-ignore */ |
| 75 | Plotly.newPlot(divId, [trace], layout, config); |
| 76 | |
| 77 | } |