@rowsncolumns/charts 27.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +100 -0
- package/Readme.md +81 -0
- package/dist/cjs/atoms/editing-chart.atom.d.ts +13 -0
- package/dist/cjs/atoms/editing-chart.atom.d.ts.map +1 -0
- package/dist/cjs/atoms/editing-chart.atom.js +26 -0
- package/dist/cjs/basic-chart/basic-chart.d.ts +5 -0
- package/dist/cjs/basic-chart/basic-chart.d.ts.map +1 -0
- package/dist/cjs/basic-chart/basic-chart.js +2250 -0
- package/dist/cjs/basic-chart/helpers.d.ts +12 -0
- package/dist/cjs/basic-chart/helpers.d.ts.map +1 -0
- package/dist/cjs/basic-chart/helpers.js +105 -0
- package/dist/cjs/basic-chart/index.d.ts +5 -0
- package/dist/cjs/basic-chart/index.d.ts.map +1 -0
- package/dist/cjs/basic-chart/index.js +12 -0
- package/dist/cjs/components/dialogs/chart-editor-dialog.d.ts +5 -0
- package/dist/cjs/components/dialogs/chart-editor-dialog.d.ts.map +1 -0
- package/dist/cjs/components/dialogs/chart-editor-dialog.js +25 -0
- package/dist/cjs/components/editors/chart-editor.d.ts +10 -0
- package/dist/cjs/components/editors/chart-editor.d.ts.map +1 -0
- package/dist/cjs/components/editors/chart-editor.js +631 -0
- package/dist/cjs/components/editors/chart-range-input.d.ts +17 -0
- package/dist/cjs/components/editors/chart-range-input.d.ts.map +1 -0
- package/dist/cjs/components/editors/chart-range-input.js +16 -0
- package/dist/cjs/config.d.ts +19 -0
- package/dist/cjs/config.d.ts.map +1 -0
- package/dist/cjs/config.js +196 -0
- package/dist/cjs/hooks/use-chart-editor.d.ts +8 -0
- package/dist/cjs/hooks/use-chart-editor.d.ts.map +1 -0
- package/dist/cjs/hooks/use-chart-editor.js +29 -0
- package/dist/cjs/hooks/use-charts.d.ts +35 -0
- package/dist/cjs/hooks/use-charts.d.ts.map +1 -0
- package/dist/cjs/hooks/use-charts.js +67 -0
- package/dist/cjs/hooks/use-on-create-chart.d.ts +13 -0
- package/dist/cjs/hooks/use-on-create-chart.d.ts.map +1 -0
- package/dist/cjs/hooks/use-on-create-chart.js +24 -0
- package/dist/cjs/hooks/use-on-delete-chart.d.ts +8 -0
- package/dist/cjs/hooks/use-on-delete-chart.d.ts.map +1 -0
- package/dist/cjs/hooks/use-on-delete-chart.js +19 -0
- package/dist/cjs/hooks/use-on-move-chart.d.ts +8 -0
- package/dist/cjs/hooks/use-on-move-chart.d.ts.map +1 -0
- package/dist/cjs/hooks/use-on-move-chart.js +15 -0
- package/dist/cjs/hooks/use-on-resize-chart.d.ts +8 -0
- package/dist/cjs/hooks/use-on-resize-chart.d.ts.map +1 -0
- package/dist/cjs/hooks/use-on-resize-chart.js +15 -0
- package/dist/cjs/hooks/use-on-update-chart.d.ts +9 -0
- package/dist/cjs/hooks/use-on-update-chart.d.ts.map +1 -0
- package/dist/cjs/hooks/use-on-update-chart.js +15 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/interface/create-chart.d.ts +9 -0
- package/dist/cjs/interface/create-chart.d.ts.map +1 -0
- package/dist/cjs/interface/create-chart.js +110 -0
- package/dist/cjs/interface/delete-chart.d.ts +4 -0
- package/dist/cjs/interface/delete-chart.d.ts.map +1 -0
- package/dist/cjs/interface/delete-chart.js +26 -0
- package/dist/cjs/interface/move-chart.d.ts +5 -0
- package/dist/cjs/interface/move-chart.d.ts.map +1 -0
- package/dist/cjs/interface/move-chart.js +28 -0
- package/dist/cjs/interface/resize-chart.d.ts +5 -0
- package/dist/cjs/interface/resize-chart.d.ts.map +1 -0
- package/dist/cjs/interface/resize-chart.js +30 -0
- package/dist/cjs/interface/update-chart.d.ts +4 -0
- package/dist/cjs/interface/update-chart.d.ts.map +1 -0
- package/dist/cjs/interface/update-chart.js +29 -0
- package/dist/cjs/plotly/basic-chart/basic-chart.d.ts +5 -0
- package/dist/cjs/plotly/basic-chart/basic-chart.d.ts.map +1 -0
- package/dist/cjs/plotly/basic-chart/basic-chart.js +1586 -0
- package/dist/cjs/plotly/basic-chart/helpers.d.ts +20 -0
- package/dist/cjs/plotly/basic-chart/helpers.d.ts.map +1 -0
- package/dist/cjs/plotly/basic-chart/helpers.js +114 -0
- package/dist/cjs/plotly/basic-chart/index.d.ts +5 -0
- package/dist/cjs/plotly/basic-chart/index.d.ts.map +1 -0
- package/dist/cjs/plotly/basic-chart/index.js +12 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/cjs/types.d.ts +27 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/aggregation.d.ts +6 -0
- package/dist/cjs/utils/aggregation.d.ts.map +1 -0
- package/dist/cjs/utils/aggregation.js +127 -0
- package/dist/cjs/utils/bar-layout.d.ts +57 -0
- package/dist/cjs/utils/bar-layout.d.ts.map +1 -0
- package/dist/cjs/utils/bar-layout.js +81 -0
- package/dist/cjs/utils/boxplot.d.ts +62 -0
- package/dist/cjs/utils/boxplot.d.ts.map +1 -0
- package/dist/cjs/utils/boxplot.js +105 -0
- package/dist/cjs/utils/bubble.d.ts +52 -0
- package/dist/cjs/utils/bubble.d.ts.map +1 -0
- package/dist/cjs/utils/bubble.js +139 -0
- package/dist/cjs/utils/chart-spec-utils.d.ts +67 -0
- package/dist/cjs/utils/chart-spec-utils.d.ts.map +1 -0
- package/dist/cjs/utils/chart-spec-utils.js +355 -0
- package/dist/cjs/utils/echarts-gl-loader.d.ts +11 -0
- package/dist/cjs/utils/echarts-gl-loader.d.ts.map +1 -0
- package/dist/cjs/utils/echarts-gl-loader.js +59 -0
- package/dist/cjs/utils/error-bars.d.ts +58 -0
- package/dist/cjs/utils/error-bars.d.ts.map +1 -0
- package/dist/cjs/utils/error-bars.js +154 -0
- package/dist/cjs/utils/gradient.d.ts +52 -0
- package/dist/cjs/utils/gradient.d.ts.map +1 -0
- package/dist/cjs/utils/gradient.js +93 -0
- package/dist/cjs/utils/hierarchy.d.ts +28 -0
- package/dist/cjs/utils/hierarchy.d.ts.map +1 -0
- package/dist/cjs/utils/hierarchy.js +186 -0
- package/dist/cjs/utils/histogram.d.ts +46 -0
- package/dist/cjs/utils/histogram.d.ts.map +1 -0
- package/dist/cjs/utils/histogram.js +125 -0
- package/dist/cjs/utils/of-pie.d.ts +101 -0
- package/dist/cjs/utils/of-pie.d.ts.map +1 -0
- package/dist/cjs/utils/of-pie.js +159 -0
- package/dist/cjs/utils/overrides.d.ts +12 -0
- package/dist/cjs/utils/overrides.d.ts.map +1 -0
- package/dist/cjs/utils/overrides.js +171 -0
- package/dist/cjs/utils/radar.d.ts +37 -0
- package/dist/cjs/utils/radar.d.ts.map +1 -0
- package/dist/cjs/utils/radar.js +70 -0
- package/dist/cjs/utils/region-map-loader.d.ts +22 -0
- package/dist/cjs/utils/region-map-loader.d.ts.map +1 -0
- package/dist/cjs/utils/region-map-loader.js +174 -0
- package/dist/cjs/utils/region-map.d.ts +100 -0
- package/dist/cjs/utils/region-map.d.ts.map +1 -0
- package/dist/cjs/utils/region-map.js +327 -0
- package/dist/cjs/utils/stock.d.ts +64 -0
- package/dist/cjs/utils/stock.d.ts.map +1 -0
- package/dist/cjs/utils/stock.js +153 -0
- package/dist/cjs/utils/three-d.d.ts +96 -0
- package/dist/cjs/utils/three-d.d.ts.map +1 -0
- package/dist/cjs/utils/three-d.js +191 -0
- package/dist/cjs/utils/trendline.d.ts +41 -0
- package/dist/cjs/utils/trendline.d.ts.map +1 -0
- package/dist/cjs/utils/trendline.js +303 -0
- package/dist/cjs/utils/waterfall.d.ts +24 -0
- package/dist/cjs/utils/waterfall.d.ts.map +1 -0
- package/dist/cjs/utils/waterfall.js +61 -0
- package/dist/cjs/utils/webgl.d.ts +12 -0
- package/dist/cjs/utils/webgl.d.ts.map +1 -0
- package/dist/cjs/utils/webgl.js +36 -0
- package/dist/cjs/vitest.config.d.ts +3 -0
- package/dist/cjs/vitest.config.d.ts.map +1 -0
- package/dist/cjs/vitest.config.js +9 -0
- package/dist/esm/atoms/editing-chart.atom.d.ts +13 -0
- package/dist/esm/atoms/editing-chart.atom.d.ts.map +1 -0
- package/dist/esm/atoms/editing-chart.atom.js +12 -0
- package/dist/esm/basic-chart/basic-chart.d.ts +5 -0
- package/dist/esm/basic-chart/basic-chart.d.ts.map +1 -0
- package/dist/esm/basic-chart/basic-chart.js +2343 -0
- package/dist/esm/basic-chart/helpers.d.ts +12 -0
- package/dist/esm/basic-chart/helpers.d.ts.map +1 -0
- package/dist/esm/basic-chart/helpers.js +98 -0
- package/dist/esm/basic-chart/index.d.ts +5 -0
- package/dist/esm/basic-chart/index.d.ts.map +1 -0
- package/dist/esm/basic-chart/index.js +7 -0
- package/dist/esm/components/dialogs/chart-editor-dialog.d.ts +5 -0
- package/dist/esm/components/dialogs/chart-editor-dialog.d.ts.map +1 -0
- package/dist/esm/components/dialogs/chart-editor-dialog.js +19 -0
- package/dist/esm/components/editors/chart-editor.d.ts +10 -0
- package/dist/esm/components/editors/chart-editor.d.ts.map +1 -0
- package/dist/esm/components/editors/chart-editor.js +550 -0
- package/dist/esm/components/editors/chart-range-input.d.ts +17 -0
- package/dist/esm/components/editors/chart-range-input.d.ts.map +1 -0
- package/dist/esm/components/editors/chart-range-input.js +10 -0
- package/dist/esm/config.d.ts +19 -0
- package/dist/esm/config.d.ts.map +1 -0
- package/dist/esm/config.js +161 -0
- package/dist/esm/hooks/use-chart-editor.d.ts +8 -0
- package/dist/esm/hooks/use-chart-editor.d.ts.map +1 -0
- package/dist/esm/hooks/use-chart-editor.js +32 -0
- package/dist/esm/hooks/use-charts.d.ts +35 -0
- package/dist/esm/hooks/use-charts.d.ts.map +1 -0
- package/dist/esm/hooks/use-charts.js +62 -0
- package/dist/esm/hooks/use-on-create-chart.d.ts +13 -0
- package/dist/esm/hooks/use-on-create-chart.d.ts.map +1 -0
- package/dist/esm/hooks/use-on-create-chart.js +19 -0
- package/dist/esm/hooks/use-on-delete-chart.d.ts +8 -0
- package/dist/esm/hooks/use-on-delete-chart.d.ts.map +1 -0
- package/dist/esm/hooks/use-on-delete-chart.js +14 -0
- package/dist/esm/hooks/use-on-move-chart.d.ts +8 -0
- package/dist/esm/hooks/use-on-move-chart.d.ts.map +1 -0
- package/dist/esm/hooks/use-on-move-chart.js +10 -0
- package/dist/esm/hooks/use-on-resize-chart.d.ts +8 -0
- package/dist/esm/hooks/use-on-resize-chart.d.ts.map +1 -0
- package/dist/esm/hooks/use-on-resize-chart.js +10 -0
- package/dist/esm/hooks/use-on-update-chart.d.ts +9 -0
- package/dist/esm/hooks/use-on-update-chart.d.ts.map +1 -0
- package/dist/esm/hooks/use-on-update-chart.js +10 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/interface/create-chart.d.ts +9 -0
- package/dist/esm/interface/create-chart.d.ts.map +1 -0
- package/dist/esm/interface/create-chart.js +126 -0
- package/dist/esm/interface/delete-chart.d.ts +4 -0
- package/dist/esm/interface/delete-chart.d.ts.map +1 -0
- package/dist/esm/interface/delete-chart.js +20 -0
- package/dist/esm/interface/move-chart.d.ts +5 -0
- package/dist/esm/interface/move-chart.d.ts.map +1 -0
- package/dist/esm/interface/move-chart.js +22 -0
- package/dist/esm/interface/resize-chart.d.ts +5 -0
- package/dist/esm/interface/resize-chart.d.ts.map +1 -0
- package/dist/esm/interface/resize-chart.js +24 -0
- package/dist/esm/interface/update-chart.d.ts +4 -0
- package/dist/esm/interface/update-chart.d.ts.map +1 -0
- package/dist/esm/interface/update-chart.js +26 -0
- package/dist/esm/plotly/basic-chart/basic-chart.d.ts +5 -0
- package/dist/esm/plotly/basic-chart/basic-chart.d.ts.map +1 -0
- package/dist/esm/plotly/basic-chart/basic-chart.js +1682 -0
- package/dist/esm/plotly/basic-chart/helpers.d.ts +20 -0
- package/dist/esm/plotly/basic-chart/helpers.d.ts.map +1 -0
- package/dist/esm/plotly/basic-chart/helpers.js +107 -0
- package/dist/esm/plotly/basic-chart/index.d.ts +5 -0
- package/dist/esm/plotly/basic-chart/index.d.ts.map +1 -0
- package/dist/esm/plotly/basic-chart/index.js +7 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/esm/types.d.ts +27 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/aggregation.d.ts +6 -0
- package/dist/esm/utils/aggregation.d.ts.map +1 -0
- package/dist/esm/utils/aggregation.js +96 -0
- package/dist/esm/utils/bar-layout.d.ts +57 -0
- package/dist/esm/utils/bar-layout.d.ts.map +1 -0
- package/dist/esm/utils/bar-layout.js +70 -0
- package/dist/esm/utils/boxplot.d.ts +62 -0
- package/dist/esm/utils/boxplot.d.ts.map +1 -0
- package/dist/esm/utils/boxplot.js +91 -0
- package/dist/esm/utils/bubble.d.ts +52 -0
- package/dist/esm/utils/bubble.d.ts.map +1 -0
- package/dist/esm/utils/bubble.js +122 -0
- package/dist/esm/utils/chart-spec-utils.d.ts +67 -0
- package/dist/esm/utils/chart-spec-utils.d.ts.map +1 -0
- package/dist/esm/utils/chart-spec-utils.js +270 -0
- package/dist/esm/utils/echarts-gl-loader.d.ts +11 -0
- package/dist/esm/utils/echarts-gl-loader.d.ts.map +1 -0
- package/dist/esm/utils/echarts-gl-loader.js +51 -0
- package/dist/esm/utils/error-bars.d.ts +58 -0
- package/dist/esm/utils/error-bars.d.ts.map +1 -0
- package/dist/esm/utils/error-bars.js +134 -0
- package/dist/esm/utils/gradient.d.ts +52 -0
- package/dist/esm/utils/gradient.d.ts.map +1 -0
- package/dist/esm/utils/gradient.js +84 -0
- package/dist/esm/utils/hierarchy.d.ts +28 -0
- package/dist/esm/utils/hierarchy.d.ts.map +1 -0
- package/dist/esm/utils/hierarchy.js +150 -0
- package/dist/esm/utils/histogram.d.ts +46 -0
- package/dist/esm/utils/histogram.d.ts.map +1 -0
- package/dist/esm/utils/histogram.js +95 -0
- package/dist/esm/utils/of-pie.d.ts +101 -0
- package/dist/esm/utils/of-pie.d.ts.map +1 -0
- package/dist/esm/utils/of-pie.js +141 -0
- package/dist/esm/utils/overrides.d.ts +12 -0
- package/dist/esm/utils/overrides.d.ts.map +1 -0
- package/dist/esm/utils/overrides.js +159 -0
- package/dist/esm/utils/radar.d.ts +37 -0
- package/dist/esm/utils/radar.d.ts.map +1 -0
- package/dist/esm/utils/radar.js +49 -0
- package/dist/esm/utils/region-map-loader.d.ts +22 -0
- package/dist/esm/utils/region-map-loader.d.ts.map +1 -0
- package/dist/esm/utils/region-map-loader.js +141 -0
- package/dist/esm/utils/region-map.d.ts +100 -0
- package/dist/esm/utils/region-map.d.ts.map +1 -0
- package/dist/esm/utils/region-map.js +266 -0
- package/dist/esm/utils/stock.d.ts +64 -0
- package/dist/esm/utils/stock.d.ts.map +1 -0
- package/dist/esm/utils/stock.js +123 -0
- package/dist/esm/utils/three-d.d.ts +96 -0
- package/dist/esm/utils/three-d.d.ts.map +1 -0
- package/dist/esm/utils/three-d.js +162 -0
- package/dist/esm/utils/trendline.d.ts +41 -0
- package/dist/esm/utils/trendline.d.ts.map +1 -0
- package/dist/esm/utils/trendline.js +257 -0
- package/dist/esm/utils/waterfall.d.ts +24 -0
- package/dist/esm/utils/waterfall.d.ts.map +1 -0
- package/dist/esm/utils/waterfall.js +55 -0
- package/dist/esm/utils/webgl.d.ts +12 -0
- package/dist/esm/utils/webgl.d.ts.map +1 -0
- package/dist/esm/utils/webgl.js +30 -0
- package/dist/esm/vitest.config.d.ts +3 -0
- package/dist/esm/vitest.config.d.ts.map +1 -0
- package/dist/esm/vitest.config.js +7 -0
- package/package.json +96 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Histogram binning utility shared by chart renderers.
|
|
3
|
+
*
|
|
4
|
+
* Plotly has native histogram trace support, so it does its own binning.
|
|
5
|
+
* Echarts has no native histogram series, so the renderer pre-bins values
|
|
6
|
+
* here and emits a bar series with the bin labels as the x-axis category.
|
|
7
|
+
*/
|
|
8
|
+
export type HistogramBins = {
|
|
9
|
+
labels: string[];
|
|
10
|
+
counts: number[];
|
|
11
|
+
};
|
|
12
|
+
export type ParetoData = {
|
|
13
|
+
/** Bin labels reordered by descending count. */
|
|
14
|
+
labels: string[];
|
|
15
|
+
/** Bin counts sorted descending (stable — ties keep bin order). */
|
|
16
|
+
counts: number[];
|
|
17
|
+
/**
|
|
18
|
+
* Running cumulative percentage of the total count per sorted bin.
|
|
19
|
+
* The final entry is exactly 100 (avoids float drift), so the line
|
|
20
|
+
* always meets the top of a 0-100 secondary axis.
|
|
21
|
+
*/
|
|
22
|
+
cumulativePercents: number[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* True when a chart spec should render as a Pareto chart: either a
|
|
26
|
+
* native `pareto` chartType token, or a histogram payload that was
|
|
27
|
+
* degraded from an authored Pareto chart (`sourceChartType: "PARETO"`,
|
|
28
|
+
* preserved verbatim through the document).
|
|
29
|
+
*/
|
|
30
|
+
export declare const isParetoSpec: (spec: {
|
|
31
|
+
chartType?: string;
|
|
32
|
+
sourceChartType?: string | null;
|
|
33
|
+
}) => boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Transform histogram bins into Pareto form: bins sorted by count
|
|
36
|
+
* descending (stable sort — equal counts keep their original bin
|
|
37
|
+
* order) plus the cumulative percentage of the running total for the
|
|
38
|
+
* secondary-axis overlay line.
|
|
39
|
+
*/
|
|
40
|
+
export declare const computePareto: (bins: HistogramBins) => ParetoData;
|
|
41
|
+
/**
|
|
42
|
+
* Bin a set of numeric values into `binCount` equal-width bins.
|
|
43
|
+
* When `binCount` is omitted, uses Sturges' rule: ceil(log2(n) + 1).
|
|
44
|
+
*/
|
|
45
|
+
export declare const binHistogram: (values: (number | null | undefined)[], binCount?: number | null) => HistogramBins;
|
|
46
|
+
//# sourceMappingURL=histogram.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"histogram.d.ts","sourceRoot":"","sources":["../../../utils/histogram.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,gDAAgD;IAChD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,mEAAmE;IACnE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;;;;OAIG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,KAAG,OAGgD,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,aAAa,KAAG,UAmBnD,CAAC;AASF;;;GAGG;AACH,eAAO,MAAM,YAAY,GACvB,QAAQ,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,EACrC,WAAW,MAAM,GAAG,IAAI,KACvB,aA0CF,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Histogram binning utility shared by chart renderers.
|
|
4
|
+
*
|
|
5
|
+
* Plotly has native histogram trace support, so it does its own binning.
|
|
6
|
+
* Echarts has no native histogram series, so the renderer pre-bins values
|
|
7
|
+
* here and emits a bar series with the bin labels as the x-axis category.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.binHistogram = exports.computePareto = exports.isParetoSpec = void 0;
|
|
11
|
+
var tslib_1 = require("tslib");
|
|
12
|
+
/**
|
|
13
|
+
* True when a chart spec should render as a Pareto chart: either a
|
|
14
|
+
* native `pareto` chartType token, or a histogram payload that was
|
|
15
|
+
* degraded from an authored Pareto chart (`sourceChartType: "PARETO"`,
|
|
16
|
+
* preserved verbatim through the document).
|
|
17
|
+
*/
|
|
18
|
+
var isParetoSpec = function (spec) {
|
|
19
|
+
return spec.chartType === "pareto" ||
|
|
20
|
+
(typeof spec.sourceChartType === "string" &&
|
|
21
|
+
spec.sourceChartType.toUpperCase() === "PARETO");
|
|
22
|
+
};
|
|
23
|
+
exports.isParetoSpec = isParetoSpec;
|
|
24
|
+
/**
|
|
25
|
+
* Transform histogram bins into Pareto form: bins sorted by count
|
|
26
|
+
* descending (stable sort — equal counts keep their original bin
|
|
27
|
+
* order) plus the cumulative percentage of the running total for the
|
|
28
|
+
* secondary-axis overlay line.
|
|
29
|
+
*/
|
|
30
|
+
var computePareto = function (bins) {
|
|
31
|
+
var order = bins.counts.map(function (_, i) { return i; });
|
|
32
|
+
order.sort(function (a, b) { return bins.counts[b] - bins.counts[a] || a - b; });
|
|
33
|
+
var counts = order.map(function (i) { return bins.counts[i]; });
|
|
34
|
+
var labels = order.map(function (i) { var _a; return (_a = bins.labels[i]) !== null && _a !== void 0 ? _a : ""; });
|
|
35
|
+
var total = counts.reduce(function (sum, c) { return sum + c; }, 0);
|
|
36
|
+
var cumulativePercents = new Array(counts.length);
|
|
37
|
+
var running = 0;
|
|
38
|
+
for (var i = 0; i < counts.length; i++) {
|
|
39
|
+
running += counts[i];
|
|
40
|
+
if (total <= 0) {
|
|
41
|
+
cumulativePercents[i] = 0;
|
|
42
|
+
}
|
|
43
|
+
else if (i === counts.length - 1) {
|
|
44
|
+
cumulativePercents[i] = 100;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
cumulativePercents[i] = (running / total) * 100;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { labels: labels, counts: counts, cumulativePercents: cumulativePercents };
|
|
51
|
+
};
|
|
52
|
+
exports.computePareto = computePareto;
|
|
53
|
+
var formatBinBound = function (value) {
|
|
54
|
+
if (!Number.isFinite(value))
|
|
55
|
+
return String(value);
|
|
56
|
+
var abs = Math.abs(value);
|
|
57
|
+
if (abs >= 1000 || abs < 0.01)
|
|
58
|
+
return value.toExponential(2);
|
|
59
|
+
return Number.parseFloat(value.toFixed(2)).toString();
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Bin a set of numeric values into `binCount` equal-width bins.
|
|
63
|
+
* When `binCount` is omitted, uses Sturges' rule: ceil(log2(n) + 1).
|
|
64
|
+
*/
|
|
65
|
+
var binHistogram = function (values, binCount) {
|
|
66
|
+
var e_1, _a, e_2, _b;
|
|
67
|
+
var numeric = values.filter(function (v) { return typeof v === "number" && Number.isFinite(v); });
|
|
68
|
+
if (numeric.length === 0) {
|
|
69
|
+
return { labels: [], counts: [] };
|
|
70
|
+
}
|
|
71
|
+
var min = numeric[0];
|
|
72
|
+
var max = numeric[0];
|
|
73
|
+
try {
|
|
74
|
+
for (var numeric_1 = tslib_1.__values(numeric), numeric_1_1 = numeric_1.next(); !numeric_1_1.done; numeric_1_1 = numeric_1.next()) {
|
|
75
|
+
var v = numeric_1_1.value;
|
|
76
|
+
if (v < min)
|
|
77
|
+
min = v;
|
|
78
|
+
if (v > max)
|
|
79
|
+
max = v;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
+
finally {
|
|
84
|
+
try {
|
|
85
|
+
if (numeric_1_1 && !numeric_1_1.done && (_a = numeric_1.return)) _a.call(numeric_1);
|
|
86
|
+
}
|
|
87
|
+
finally { if (e_1) throw e_1.error; }
|
|
88
|
+
}
|
|
89
|
+
var sturges = Math.max(1, Math.ceil(Math.log2(numeric.length) + 1));
|
|
90
|
+
var bins = typeof binCount === "number" && binCount > 0
|
|
91
|
+
? Math.floor(binCount)
|
|
92
|
+
: sturges;
|
|
93
|
+
if (min === max) {
|
|
94
|
+
return { labels: [formatBinBound(min)], counts: [numeric.length] };
|
|
95
|
+
}
|
|
96
|
+
var width = (max - min) / bins;
|
|
97
|
+
var counts = new Array(bins).fill(0);
|
|
98
|
+
try {
|
|
99
|
+
for (var numeric_2 = tslib_1.__values(numeric), numeric_2_1 = numeric_2.next(); !numeric_2_1.done; numeric_2_1 = numeric_2.next()) {
|
|
100
|
+
var v = numeric_2_1.value;
|
|
101
|
+
var idx = Math.floor((v - min) / width);
|
|
102
|
+
if (idx >= bins)
|
|
103
|
+
idx = bins - 1;
|
|
104
|
+
if (idx < 0)
|
|
105
|
+
idx = 0;
|
|
106
|
+
counts[idx]++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
110
|
+
finally {
|
|
111
|
+
try {
|
|
112
|
+
if (numeric_2_1 && !numeric_2_1.done && (_b = numeric_2.return)) _b.call(numeric_2);
|
|
113
|
+
}
|
|
114
|
+
finally { if (e_2) throw e_2.error; }
|
|
115
|
+
}
|
|
116
|
+
var labels = new Array(bins);
|
|
117
|
+
for (var i = 0; i < bins; i++) {
|
|
118
|
+
var lo = min + width * i;
|
|
119
|
+
var hi = min + width * (i + 1);
|
|
120
|
+
var closing = i === bins - 1 ? "]" : ")";
|
|
121
|
+
labels[i] = "[".concat(formatBinBound(lo), ", ").concat(formatBinBound(hi)).concat(closing);
|
|
122
|
+
}
|
|
123
|
+
return { labels: labels, counts: counts };
|
|
124
|
+
};
|
|
125
|
+
exports.binHistogram = binHistogram;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pie-of-pie / bar-of-pie (OOXML `<c:ofPieChart>`) split math.
|
|
3
|
+
*
|
|
4
|
+
* Excel splits the minor slices of a pie into a secondary pie or
|
|
5
|
+
* stacked bar next to the main pie. The main pie replaces the moved
|
|
6
|
+
* slices with a single aggregated "Other" slice, and connector lines
|
|
7
|
+
* join the Other slice to the secondary plot. The rule deciding which
|
|
8
|
+
* points move is `<c:splitType>` + `<c:splitPos>`:
|
|
9
|
+
*
|
|
10
|
+
* - position — the last `splitPos` categories move (Excel default,
|
|
11
|
+
* `splitPos` 3)
|
|
12
|
+
* - value — points whose value is < `splitPos` move
|
|
13
|
+
* - percent — points whose share of the grand total is < `splitPos`%
|
|
14
|
+
* move
|
|
15
|
+
*
|
|
16
|
+
* OOXML also allows `auto` (app decides) and `cust` (explicit per-point
|
|
17
|
+
* assignment via `<c:custSplit>`). Neither has a spec representation
|
|
18
|
+
* here, so both degrade to Excel's default: position with `splitPos` 3.
|
|
19
|
+
*/
|
|
20
|
+
type MaybeLike<T> = T | null | undefined;
|
|
21
|
+
export type OfPieType = "pie" | "bar";
|
|
22
|
+
export type OfPieSplitType = "position" | "value" | "percent";
|
|
23
|
+
/** Excel's default split: the last 3 categories move to the second plot. */
|
|
24
|
+
export declare const DEFAULT_OF_PIE_SPLIT_POS = 3;
|
|
25
|
+
/** OOXML `<c:secondPieSize>` default — secondary plot is 75% of the main pie. */
|
|
26
|
+
export declare const DEFAULT_SECOND_PIE_SIZE = 75;
|
|
27
|
+
/** Label of the aggregated slice representing the secondary plot's total. */
|
|
28
|
+
export declare const OF_PIE_OTHER_LABEL = "Other";
|
|
29
|
+
export type OfPieSlice = {
|
|
30
|
+
label: string;
|
|
31
|
+
value: number;
|
|
32
|
+
};
|
|
33
|
+
export type OfPieSplitResult = {
|
|
34
|
+
/**
|
|
35
|
+
* Main-pie slices. When the secondary plot is non-empty the last
|
|
36
|
+
* entry is the aggregated "Other" slice (value = `otherTotal`).
|
|
37
|
+
*/
|
|
38
|
+
main: OfPieSlice[];
|
|
39
|
+
/** Secondary-plot slices, in original data order. */
|
|
40
|
+
secondary: OfPieSlice[];
|
|
41
|
+
/** Sum of the secondary values — the "Other" slice's value. */
|
|
42
|
+
otherTotal: number;
|
|
43
|
+
/** Grand total of all (finite) input values. */
|
|
44
|
+
total: number;
|
|
45
|
+
};
|
|
46
|
+
export type OfPieSplitOptions = {
|
|
47
|
+
/**
|
|
48
|
+
* Accepts both spec tokens ("position" | "value" | "percent") and
|
|
49
|
+
* raw OOXML tokens ("pos" | "val" | "percent" | "auto" | "cust").
|
|
50
|
+
* Unknown/absent values fall back to "position".
|
|
51
|
+
*/
|
|
52
|
+
splitType?: MaybeLike<string>;
|
|
53
|
+
/** Threshold for the split rule. Defaults to 3 (Excel's default). */
|
|
54
|
+
splitPos?: MaybeLike<number>;
|
|
55
|
+
/** Override for the aggregated slice's label. Defaults to "Other". */
|
|
56
|
+
otherLabel?: MaybeLike<string>;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Normalize a split-type token to the renderer's vocabulary. Maps the
|
|
60
|
+
* raw OOXML tokens (`pos`/`val`) and degrades `auto`/`cust`/unknown to
|
|
61
|
+
* "position" (Excel's default behavior).
|
|
62
|
+
*/
|
|
63
|
+
export declare const normalizeOfPieSplitType: (raw: MaybeLike<string>) => OfPieSplitType;
|
|
64
|
+
/** Coerce `<c:ofPieType>`-ish input to "pie" | "bar" (default "pie"). */
|
|
65
|
+
export declare const resolveOfPieType: (raw: MaybeLike<string>) => OfPieType;
|
|
66
|
+
/** Clamp `<c:secondPieSize>` to its OOXML 5–200 range (default 75). */
|
|
67
|
+
export declare const clampSecondPieSize: (raw: MaybeLike<number>) => number;
|
|
68
|
+
/**
|
|
69
|
+
* True when a basic-chart spec should render as an of-pie composite:
|
|
70
|
+
* a pie chart whose authored type was OF_PIE, or one that explicitly
|
|
71
|
+
* carries an `ofPieType`. Plain pies (neither marker) are unaffected.
|
|
72
|
+
*/
|
|
73
|
+
export declare const isOfPieChartSpec: (spec: {
|
|
74
|
+
chartType?: string;
|
|
75
|
+
sourceChartType?: MaybeLike<string>;
|
|
76
|
+
ofPieType?: MaybeLike<string>;
|
|
77
|
+
}) => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Half of the angle (radians) subtended by the "Other" slice. The
|
|
80
|
+
* renderers rotate the main pie so the Other slice's angular midpoint
|
|
81
|
+
* points at the secondary plot; the two connector lines then leave the
|
|
82
|
+
* circle at ±this angle from that midpoint.
|
|
83
|
+
*/
|
|
84
|
+
export declare const otherSliceHalfAngle: (otherTotal: number, total: number) => number;
|
|
85
|
+
/**
|
|
86
|
+
* Split a pie's data points into the main plot (+ aggregated "Other"
|
|
87
|
+
* slice) and the secondary plot, honoring the of-pie split rule.
|
|
88
|
+
*
|
|
89
|
+
* Degenerate inputs degrade gracefully:
|
|
90
|
+
* - empty values → both plots empty
|
|
91
|
+
* - a single point never moves (the main pie keeps ≥ 1 real slice
|
|
92
|
+
* under the position rule; value/percent rules may move everything,
|
|
93
|
+
* leaving the main pie as a single 100% "Other" slice — Excel does
|
|
94
|
+
* the same)
|
|
95
|
+
* - position `splitPos` larger than the point count is clamped to
|
|
96
|
+
* `count - 1`
|
|
97
|
+
* - an empty secondary plot yields no "Other" slice (plain pie)
|
|
98
|
+
*/
|
|
99
|
+
export declare const splitOfPie: (values: MaybeLike<number>[], labels: MaybeLike<string | number>[], options?: OfPieSplitOptions) => OfPieSplitResult;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=of-pie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"of-pie.d.ts","sourceRoot":"","sources":["../../../utils/of-pie.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAEzC,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,CAAC;AACtC,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,CAAC;AAE9D,4EAA4E;AAC5E,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,iFAAiF;AACjF,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;OAGG;IACH,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,qDAAqD;IACrD,SAAS,EAAE,UAAU,EAAE,CAAC;IACxB,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC7B,sEAAsE;IACtE,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CAChC,CAAC;AAOF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,KAAK,SAAS,CAAC,MAAM,CAAC,KACrB,cAeF,CAAC;AAEF,yEAAyE;AACzE,eAAO,MAAM,gBAAgB,GAAI,KAAK,SAAS,CAAC,MAAM,CAAC,KAAG,SACC,CAAC;AAE5D,uEAAuE;AACvE,eAAO,MAAM,kBAAkB,GAAI,KAAK,SAAS,CAAC,MAAM,CAAC,KAAG,MAM3D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACpC,SAAS,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CAC/B,KAAG,OAIyB,CAAC;AAE9B;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,YAAY,MAAM,EAClB,OAAO,MAAM,KACZ,MAIF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,GACrB,QAAQ,SAAS,CAAC,MAAM,CAAC,EAAE,EAC3B,QAAQ,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EACpC,UAAU,iBAAiB,KAC1B,gBAiDF,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pie-of-pie / bar-of-pie (OOXML `<c:ofPieChart>`) split math.
|
|
4
|
+
*
|
|
5
|
+
* Excel splits the minor slices of a pie into a secondary pie or
|
|
6
|
+
* stacked bar next to the main pie. The main pie replaces the moved
|
|
7
|
+
* slices with a single aggregated "Other" slice, and connector lines
|
|
8
|
+
* join the Other slice to the secondary plot. The rule deciding which
|
|
9
|
+
* points move is `<c:splitType>` + `<c:splitPos>`:
|
|
10
|
+
*
|
|
11
|
+
* - position — the last `splitPos` categories move (Excel default,
|
|
12
|
+
* `splitPos` 3)
|
|
13
|
+
* - value — points whose value is < `splitPos` move
|
|
14
|
+
* - percent — points whose share of the grand total is < `splitPos`%
|
|
15
|
+
* move
|
|
16
|
+
*
|
|
17
|
+
* OOXML also allows `auto` (app decides) and `cust` (explicit per-point
|
|
18
|
+
* assignment via `<c:custSplit>`). Neither has a spec representation
|
|
19
|
+
* here, so both degrade to Excel's default: position with `splitPos` 3.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.splitOfPie = exports.otherSliceHalfAngle = exports.isOfPieChartSpec = exports.clampSecondPieSize = exports.resolveOfPieType = exports.normalizeOfPieSplitType = exports.OF_PIE_OTHER_LABEL = exports.DEFAULT_SECOND_PIE_SIZE = exports.DEFAULT_OF_PIE_SPLIT_POS = void 0;
|
|
23
|
+
/** Excel's default split: the last 3 categories move to the second plot. */
|
|
24
|
+
exports.DEFAULT_OF_PIE_SPLIT_POS = 3;
|
|
25
|
+
/** OOXML `<c:secondPieSize>` default — secondary plot is 75% of the main pie. */
|
|
26
|
+
exports.DEFAULT_SECOND_PIE_SIZE = 75;
|
|
27
|
+
/** Label of the aggregated slice representing the secondary plot's total. */
|
|
28
|
+
exports.OF_PIE_OTHER_LABEL = "Other";
|
|
29
|
+
var toFiniteNumber = function (value) {
|
|
30
|
+
var n = typeof value === "number" ? value : Number(value);
|
|
31
|
+
return Number.isFinite(n) ? n : 0;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Normalize a split-type token to the renderer's vocabulary. Maps the
|
|
35
|
+
* raw OOXML tokens (`pos`/`val`) and degrades `auto`/`cust`/unknown to
|
|
36
|
+
* "position" (Excel's default behavior).
|
|
37
|
+
*/
|
|
38
|
+
var normalizeOfPieSplitType = function (raw) {
|
|
39
|
+
switch (String(raw !== null && raw !== void 0 ? raw : "").toLowerCase()) {
|
|
40
|
+
case "value":
|
|
41
|
+
case "val":
|
|
42
|
+
return "value";
|
|
43
|
+
case "percent":
|
|
44
|
+
return "percent";
|
|
45
|
+
case "position":
|
|
46
|
+
case "pos":
|
|
47
|
+
return "position";
|
|
48
|
+
// "auto" / "cust" / unknown — no renderer equivalent, use Excel's
|
|
49
|
+
// default rule.
|
|
50
|
+
default:
|
|
51
|
+
return "position";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.normalizeOfPieSplitType = normalizeOfPieSplitType;
|
|
55
|
+
/** Coerce `<c:ofPieType>`-ish input to "pie" | "bar" (default "pie"). */
|
|
56
|
+
var resolveOfPieType = function (raw) {
|
|
57
|
+
return String(raw !== null && raw !== void 0 ? raw : "").toLowerCase() === "bar" ? "bar" : "pie";
|
|
58
|
+
};
|
|
59
|
+
exports.resolveOfPieType = resolveOfPieType;
|
|
60
|
+
/** Clamp `<c:secondPieSize>` to its OOXML 5–200 range (default 75). */
|
|
61
|
+
var clampSecondPieSize = function (raw) {
|
|
62
|
+
var v = typeof raw === "number" && Number.isFinite(raw)
|
|
63
|
+
? raw
|
|
64
|
+
: exports.DEFAULT_SECOND_PIE_SIZE;
|
|
65
|
+
return Math.min(200, Math.max(5, v));
|
|
66
|
+
};
|
|
67
|
+
exports.clampSecondPieSize = clampSecondPieSize;
|
|
68
|
+
/**
|
|
69
|
+
* True when a basic-chart spec should render as an of-pie composite:
|
|
70
|
+
* a pie chart whose authored type was OF_PIE, or one that explicitly
|
|
71
|
+
* carries an `ofPieType`. Plain pies (neither marker) are unaffected.
|
|
72
|
+
*/
|
|
73
|
+
var isOfPieChartSpec = function (spec) {
|
|
74
|
+
var _a;
|
|
75
|
+
return (spec === null || spec === void 0 ? void 0 : spec.chartType) === "pie" &&
|
|
76
|
+
(String((_a = spec.sourceChartType) !== null && _a !== void 0 ? _a : "").toUpperCase() === "OF_PIE" ||
|
|
77
|
+
spec.ofPieType === "pie" ||
|
|
78
|
+
spec.ofPieType === "bar");
|
|
79
|
+
};
|
|
80
|
+
exports.isOfPieChartSpec = isOfPieChartSpec;
|
|
81
|
+
/**
|
|
82
|
+
* Half of the angle (radians) subtended by the "Other" slice. The
|
|
83
|
+
* renderers rotate the main pie so the Other slice's angular midpoint
|
|
84
|
+
* points at the secondary plot; the two connector lines then leave the
|
|
85
|
+
* circle at ±this angle from that midpoint.
|
|
86
|
+
*/
|
|
87
|
+
var otherSliceHalfAngle = function (otherTotal, total) {
|
|
88
|
+
if (!(total > 0))
|
|
89
|
+
return 0;
|
|
90
|
+
var fraction = Math.min(1, Math.max(0, otherTotal / total));
|
|
91
|
+
return Math.PI * fraction;
|
|
92
|
+
};
|
|
93
|
+
exports.otherSliceHalfAngle = otherSliceHalfAngle;
|
|
94
|
+
/**
|
|
95
|
+
* Split a pie's data points into the main plot (+ aggregated "Other"
|
|
96
|
+
* slice) and the secondary plot, honoring the of-pie split rule.
|
|
97
|
+
*
|
|
98
|
+
* Degenerate inputs degrade gracefully:
|
|
99
|
+
* - empty values → both plots empty
|
|
100
|
+
* - a single point never moves (the main pie keeps ≥ 1 real slice
|
|
101
|
+
* under the position rule; value/percent rules may move everything,
|
|
102
|
+
* leaving the main pie as a single 100% "Other" slice — Excel does
|
|
103
|
+
* the same)
|
|
104
|
+
* - position `splitPos` larger than the point count is clamped to
|
|
105
|
+
* `count - 1`
|
|
106
|
+
* - an empty secondary plot yields no "Other" slice (plain pie)
|
|
107
|
+
*/
|
|
108
|
+
var splitOfPie = function (values, labels, options) {
|
|
109
|
+
var _a;
|
|
110
|
+
var slices = (values !== null && values !== void 0 ? values : []).map(function (v, i) {
|
|
111
|
+
var _a;
|
|
112
|
+
return ({
|
|
113
|
+
label: String((_a = labels === null || labels === void 0 ? void 0 : labels[i]) !== null && _a !== void 0 ? _a : ""),
|
|
114
|
+
value: toFiniteNumber(v),
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
var total = slices.reduce(function (sum, s) { return sum + s.value; }, 0);
|
|
118
|
+
var splitType = (0, exports.normalizeOfPieSplitType)(options === null || options === void 0 ? void 0 : options.splitType);
|
|
119
|
+
var splitPos = typeof (options === null || options === void 0 ? void 0 : options.splitPos) === "number" && Number.isFinite(options.splitPos)
|
|
120
|
+
? options.splitPos
|
|
121
|
+
: exports.DEFAULT_OF_PIE_SPLIT_POS;
|
|
122
|
+
var moved = slices.map(function () { return false; });
|
|
123
|
+
if (slices.length > 1) {
|
|
124
|
+
if (splitType === "position") {
|
|
125
|
+
// Last N categories; the main pie keeps at least one real slice.
|
|
126
|
+
var n = Math.min(Math.max(Math.floor(splitPos), 0), slices.length - 1);
|
|
127
|
+
for (var i = slices.length - n; i < slices.length; i++) {
|
|
128
|
+
moved[i] = true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (splitType === "value") {
|
|
132
|
+
slices.forEach(function (s, i) {
|
|
133
|
+
if (s.value < splitPos)
|
|
134
|
+
moved[i] = true;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// percent — share of the grand total below splitPos%.
|
|
139
|
+
slices.forEach(function (s, i) {
|
|
140
|
+
if (total > 0 && (s.value / total) * 100 < splitPos)
|
|
141
|
+
moved[i] = true;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
var main = [];
|
|
146
|
+
var secondary = [];
|
|
147
|
+
slices.forEach(function (s, i) {
|
|
148
|
+
(moved[i] ? secondary : main).push(s);
|
|
149
|
+
});
|
|
150
|
+
var otherTotal = secondary.reduce(function (sum, s) { return sum + s.value; }, 0);
|
|
151
|
+
if (secondary.length > 0) {
|
|
152
|
+
main.push({
|
|
153
|
+
label: (_a = options === null || options === void 0 ? void 0 : options.otherLabel) !== null && _a !== void 0 ? _a : exports.OF_PIE_OTHER_LABEL,
|
|
154
|
+
value: otherTotal,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return { main: main, secondary: secondary, otherTotal: otherTotal, total: total };
|
|
158
|
+
};
|
|
159
|
+
exports.splitOfPie = splitOfPie;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LegendComponentOption } from "echarts";
|
|
2
|
+
/** Build an echarts `textStyle` from a parsed `ChartTextFormat`. */
|
|
3
|
+
export declare const textFormatToEchartsTextStyle: (fmt: any) => Record<string, any> | undefined;
|
|
4
|
+
export declare const applyLegendOverrides: (legend: LegendComponentOption, opts: any) => LegendComponentOption;
|
|
5
|
+
export declare const applyAxisOverrides: (axis: any, opts: any) => any;
|
|
6
|
+
export declare const dataLabelFormatter: (opts: any) => (params: any) => string;
|
|
7
|
+
export declare const buildSeriesLabelOption: (opts: any) => {
|
|
8
|
+
readonly show: true;
|
|
9
|
+
readonly position: any;
|
|
10
|
+
readonly formatter: (params: any) => string;
|
|
11
|
+
} | undefined;
|
|
12
|
+
//# sourceMappingURL=overrides.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overrides.d.ts","sourceRoot":"","sources":["../../../utils/overrides.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AASrD,oEAAoE;AACpE,eAAO,MAAM,4BAA4B,GAAI,KAAK,GAAG,oCASpD,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,qBAAqB,EAC7B,MAAM,GAAG,KACR,qBA6CF,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,MAAM,GAAG,EAAE,MAAM,GAAG,QAsBtD,CAAC;AAqBF,eAAO,MAAM,kBAAkB,GAAI,MAAM,GAAG,MAAM,QAAQ,GAAG,WA4B5D,CAAC;AAWF,eAAO,MAAM,sBAAsB,GAAI,MAAM,GAAG;;;iCAvCU,GAAG;aA+C5D,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSeriesLabelOption = exports.dataLabelFormatter = exports.applyAxisOverrides = exports.applyLegendOverrides = exports.textFormatToEchartsTextStyle = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var utils_1 = require("@rowsncolumns/utils");
|
|
6
|
+
// Map ChartSpec.legend / dataLabels / axisOptions to ECharts option
|
|
7
|
+
// fragments. Each helper is a no-op when the spec field is missing, so
|
|
8
|
+
// callers can spread the result without checks. Shared by the main
|
|
9
|
+
// option assembly and the bubble / hierarchy / radar / stock early
|
|
10
|
+
// branches in `basic-chart.tsx` so every chart type honors the same
|
|
11
|
+
// spec-level overrides.
|
|
12
|
+
/** Build an echarts `textStyle` from a parsed `ChartTextFormat`. */
|
|
13
|
+
var textFormatToEchartsTextStyle = function (fmt) {
|
|
14
|
+
if (!fmt)
|
|
15
|
+
return undefined;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (fmt.color)
|
|
18
|
+
result.color = fmt.color;
|
|
19
|
+
if (fmt.fontFamily)
|
|
20
|
+
result.fontFamily = fmt.fontFamily;
|
|
21
|
+
if (typeof fmt.fontSize === "number")
|
|
22
|
+
result.fontSize = fmt.fontSize;
|
|
23
|
+
if (fmt.bold)
|
|
24
|
+
result.fontWeight = "bold";
|
|
25
|
+
if (fmt.italic)
|
|
26
|
+
result.fontStyle = "italic";
|
|
27
|
+
return Object.keys(result).length ? result : undefined;
|
|
28
|
+
};
|
|
29
|
+
exports.textFormatToEchartsTextStyle = textFormatToEchartsTextStyle;
|
|
30
|
+
var applyLegendOverrides = function (legend, opts) {
|
|
31
|
+
var _a;
|
|
32
|
+
if (!opts)
|
|
33
|
+
return legend;
|
|
34
|
+
var next = tslib_1.__assign({}, legend);
|
|
35
|
+
if (opts.position === "none") {
|
|
36
|
+
next.show = false;
|
|
37
|
+
return next;
|
|
38
|
+
}
|
|
39
|
+
next.show = true;
|
|
40
|
+
switch (opts.position) {
|
|
41
|
+
case "top":
|
|
42
|
+
next.top = 10;
|
|
43
|
+
next.bottom = undefined;
|
|
44
|
+
next.left = "center";
|
|
45
|
+
next.orient = "horizontal";
|
|
46
|
+
break;
|
|
47
|
+
case "bottom":
|
|
48
|
+
next.bottom = 10;
|
|
49
|
+
next.top = undefined;
|
|
50
|
+
next.left = "center";
|
|
51
|
+
next.orient = "horizontal";
|
|
52
|
+
break;
|
|
53
|
+
case "left":
|
|
54
|
+
next.left = 0;
|
|
55
|
+
next.right = undefined;
|
|
56
|
+
next.top = "middle";
|
|
57
|
+
next.orient = "vertical";
|
|
58
|
+
break;
|
|
59
|
+
case "right":
|
|
60
|
+
next.right = 0;
|
|
61
|
+
next.left = undefined;
|
|
62
|
+
next.top = "middle";
|
|
63
|
+
next.orient = "vertical";
|
|
64
|
+
break;
|
|
65
|
+
case "topRight":
|
|
66
|
+
next.top = 10;
|
|
67
|
+
next.right = 0;
|
|
68
|
+
next.left = undefined;
|
|
69
|
+
next.orient = "vertical";
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
var legendTextStyle = (0, exports.textFormatToEchartsTextStyle)(opts.textFormat);
|
|
73
|
+
if (legendTextStyle) {
|
|
74
|
+
next.textStyle = tslib_1.__assign(tslib_1.__assign({}, ((_a = next.textStyle) !== null && _a !== void 0 ? _a : {})), legendTextStyle);
|
|
75
|
+
}
|
|
76
|
+
return next;
|
|
77
|
+
};
|
|
78
|
+
exports.applyLegendOverrides = applyLegendOverrides;
|
|
79
|
+
var applyAxisOverrides = function (axis, opts) {
|
|
80
|
+
var _a, _b, _c, _d;
|
|
81
|
+
if (!opts)
|
|
82
|
+
return axis;
|
|
83
|
+
var next = tslib_1.__assign({}, axis);
|
|
84
|
+
if (opts.logarithmic)
|
|
85
|
+
next.type = "log";
|
|
86
|
+
if (opts.reverse)
|
|
87
|
+
next.inverse = true;
|
|
88
|
+
if (typeof opts.min === "number")
|
|
89
|
+
next.min = opts.min;
|
|
90
|
+
if (typeof opts.max === "number")
|
|
91
|
+
next.max = opts.max;
|
|
92
|
+
if (opts.visible === false)
|
|
93
|
+
next.show = false;
|
|
94
|
+
if (opts.showMajorGridlines === false) {
|
|
95
|
+
next.splitLine = tslib_1.__assign(tslib_1.__assign({}, ((_a = next.splitLine) !== null && _a !== void 0 ? _a : {})), { show: false });
|
|
96
|
+
}
|
|
97
|
+
if (opts.showMajorGridlines === true) {
|
|
98
|
+
next.splitLine = tslib_1.__assign(tslib_1.__assign({}, ((_b = next.splitLine) !== null && _b !== void 0 ? _b : {})), { show: true });
|
|
99
|
+
}
|
|
100
|
+
// Axis label text style (tick labels) + axis title font come from
|
|
101
|
+
// <c:txPr>. Without this echarts uses its default (~black on light).
|
|
102
|
+
var axisTextStyle = (0, exports.textFormatToEchartsTextStyle)(opts.textFormat);
|
|
103
|
+
if (axisTextStyle) {
|
|
104
|
+
next.axisLabel = tslib_1.__assign(tslib_1.__assign({}, ((_c = next.axisLabel) !== null && _c !== void 0 ? _c : {})), axisTextStyle);
|
|
105
|
+
next.nameTextStyle = tslib_1.__assign(tslib_1.__assign({}, ((_d = next.nameTextStyle) !== null && _d !== void 0 ? _d : {})), axisTextStyle);
|
|
106
|
+
}
|
|
107
|
+
return next;
|
|
108
|
+
};
|
|
109
|
+
exports.applyAxisOverrides = applyAxisOverrides;
|
|
110
|
+
/**
|
|
111
|
+
* Format a numeric data-label value through the chart's
|
|
112
|
+
* `<c:dLbls><c:numFmt formatCode=…>` pattern when present. For
|
|
113
|
+
* percent-stacked bars the `originalValue` (raw dollars) is preferred
|
|
114
|
+
* over the normalized percentage so labels read "$1,831" not "84.6"
|
|
115
|
+
* — Excel's behaviour.
|
|
116
|
+
*/
|
|
117
|
+
var formatLabelValue = function (rawValue, originalValue, pattern) {
|
|
118
|
+
var target = originalValue !== null && originalValue !== void 0 ? originalValue : rawValue;
|
|
119
|
+
if (pattern) {
|
|
120
|
+
return (0, utils_1.ssfFormat)(pattern, target);
|
|
121
|
+
}
|
|
122
|
+
return target === undefined || target === null ? "" : String(target);
|
|
123
|
+
};
|
|
124
|
+
var dataLabelFormatter = function (opts) { return function (params) {
|
|
125
|
+
var parts = [];
|
|
126
|
+
if (opts.showSeriesName && params.seriesName)
|
|
127
|
+
parts.push(params.seriesName);
|
|
128
|
+
if (opts.showCategoryName && params.name)
|
|
129
|
+
parts.push(params.name);
|
|
130
|
+
if (opts.showPercent && params.percent !== undefined) {
|
|
131
|
+
parts.push("".concat(params.percent, "%"));
|
|
132
|
+
}
|
|
133
|
+
var showVal = opts.showValue !== false &&
|
|
134
|
+
!opts.showCategoryName &&
|
|
135
|
+
!opts.showPercent &&
|
|
136
|
+
!opts.showSeriesName
|
|
137
|
+
? true
|
|
138
|
+
: !!opts.showValue;
|
|
139
|
+
if (showVal && params.value !== undefined) {
|
|
140
|
+
// PERCENT_STACKED stores the raw value on the data object so the
|
|
141
|
+
// label can still surface the dollar amount instead of the
|
|
142
|
+
// normalized percentage. Plain stacked / clustered have just a
|
|
143
|
+
// scalar `value`.
|
|
144
|
+
var originalValue = typeof params.data === "object" && params.data
|
|
145
|
+
? params.data.originalValue
|
|
146
|
+
: undefined;
|
|
147
|
+
parts.push(formatLabelValue(params.value, originalValue, opts.numberFormatPattern));
|
|
148
|
+
}
|
|
149
|
+
return parts.join(": ");
|
|
150
|
+
}; };
|
|
151
|
+
exports.dataLabelFormatter = dataLabelFormatter;
|
|
152
|
+
var ECHARTS_DLBL_POS = {
|
|
153
|
+
center: "inside",
|
|
154
|
+
inside: "inside",
|
|
155
|
+
outside: "outside",
|
|
156
|
+
insideEnd: "insideTop",
|
|
157
|
+
outsideEnd: "top",
|
|
158
|
+
bestFit: "top",
|
|
159
|
+
};
|
|
160
|
+
var buildSeriesLabelOption = function (opts) {
|
|
161
|
+
var _a;
|
|
162
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.show))
|
|
163
|
+
return undefined;
|
|
164
|
+
var position = (_a = (opts.position && ECHARTS_DLBL_POS[opts.position])) !== null && _a !== void 0 ? _a : "top";
|
|
165
|
+
return {
|
|
166
|
+
show: true,
|
|
167
|
+
position: position,
|
|
168
|
+
formatter: (0, exports.dataLabelFormatter)(opts),
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
exports.buildSeriesLabelOption = buildSeriesLabelOption;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Radar-chart shaping shared by chart renderers.
|
|
3
|
+
*
|
|
4
|
+
* A radar chart plots each series as a closed polygon over a set of
|
|
5
|
+
* "indicators" (one axis per category). echarts needs a top-level
|
|
6
|
+
* `radar.indicator: [{ name, max }]` plus series of shape
|
|
7
|
+
* `{ value: number[], name }`. plotly uses `scatterpolar` traces with
|
|
8
|
+
* `r` (the values) and `theta` (the category names).
|
|
9
|
+
*
|
|
10
|
+
* These helpers are pure transforms over already-extracted category
|
|
11
|
+
* labels and per-series numeric values.
|
|
12
|
+
*/
|
|
13
|
+
export type RadarSeriesInput = {
|
|
14
|
+
name: string;
|
|
15
|
+
values: (number | null | undefined)[];
|
|
16
|
+
};
|
|
17
|
+
export type RadarIndicator = {
|
|
18
|
+
name: string;
|
|
19
|
+
max: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Build echarts radar indicators from category labels and series.
|
|
23
|
+
* The `max` per indicator is the largest value seen across all series at
|
|
24
|
+
* that category (rounded up a touch so the polygon doesn't touch the
|
|
25
|
+
* rim). When every series is empty at an index, `max` defaults to 1.
|
|
26
|
+
*/
|
|
27
|
+
export declare const buildRadarIndicators: (categories: (string | number | boolean | null | undefined)[], series: RadarSeriesInput[]) => RadarIndicator[];
|
|
28
|
+
/**
|
|
29
|
+
* Shape series into echarts radar data: one entry per series with its
|
|
30
|
+
* value vector aligned to the indicator order. Missing/non-numeric
|
|
31
|
+
* values become 0 so the polygon stays closed.
|
|
32
|
+
*/
|
|
33
|
+
export declare const buildRadarSeriesData: (series: RadarSeriesInput[], indicatorCount: number) => Array<{
|
|
34
|
+
value: number[];
|
|
35
|
+
name: string;
|
|
36
|
+
}>;
|
|
37
|
+
//# sourceMappingURL=radar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radar.d.ts","sourceRoot":"","sources":["../../../utils/radar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAQ3D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,YAAY,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,EAC5D,QAAQ,gBAAgB,EAAE,KACzB,cAAc,EAahB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,gBAAgB,EAAE,EAC1B,gBAAgB,MAAM,KACrB,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAQzC,CAAC"}
|