@gravity-ui/charts 0.1.0
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 +21 -0
- package/README.md +15 -0
- package/dist/cjs/components/Axis/AxisX.d.ts +20 -0
- package/dist/cjs/components/Axis/AxisX.js +108 -0
- package/dist/cjs/components/Axis/AxisY.d.ts +12 -0
- package/dist/cjs/components/Axis/AxisY.js +199 -0
- package/dist/cjs/components/Axis/index.d.ts +2 -0
- package/dist/cjs/components/Axis/index.js +2 -0
- package/dist/cjs/components/Axis/styles.css +17 -0
- package/dist/cjs/components/ChartInner/index.d.ts +10 -0
- package/dist/cjs/components/ChartInner/index.js +143 -0
- package/dist/cjs/components/ChartInner/styles.css +10 -0
- package/dist/cjs/components/Legend/index.d.ts +13 -0
- package/dist/cjs/components/Legend/index.js +278 -0
- package/dist/cjs/components/Legend/styles.css +47 -0
- package/dist/cjs/components/PlotTitle/index.d.ts +8 -0
- package/dist/cjs/components/PlotTitle/index.js +13 -0
- package/dist/cjs/components/PlotTitle/styles.css +5 -0
- package/dist/cjs/components/Title/index.d.ts +8 -0
- package/dist/cjs/components/Title/index.js +9 -0
- package/dist/cjs/components/Title/styles.css +5 -0
- package/dist/cjs/components/Tooltip/DefaultContent.d.ts +10 -0
- package/dist/cjs/components/Tooltip/DefaultContent.js +101 -0
- package/dist/cjs/components/Tooltip/index.d.ts +13 -0
- package/dist/cjs/components/Tooltip/index.js +29 -0
- package/dist/cjs/components/Tooltip/styles.css +29 -0
- package/dist/cjs/components/index.d.ts +18 -0
- package/dist/cjs/components/index.js +66 -0
- package/dist/cjs/constants/defaults/axis.d.ts +14 -0
- package/dist/cjs/constants/defaults/axis.js +18 -0
- package/dist/cjs/constants/defaults/index.d.ts +3 -0
- package/dist/cjs/constants/defaults/index.js +3 -0
- package/dist/cjs/constants/defaults/legend.d.ts +13 -0
- package/dist/cjs/constants/defaults/legend.js +12 -0
- package/dist/cjs/constants/defaults/series-options.d.ts +24 -0
- package/dist/cjs/constants/defaults/series-options.js +106 -0
- package/dist/cjs/constants/index.d.ts +46 -0
- package/dist/cjs/constants/index.js +71 -0
- package/dist/cjs/hooks/index.d.ts +10 -0
- package/dist/cjs/hooks/index.js +10 -0
- package/dist/cjs/hooks/useAxisScales/index.d.ts +25 -0
- package/dist/cjs/hooks/useAxisScales/index.js +183 -0
- package/dist/cjs/hooks/useChartDimensions/index.d.ts +16 -0
- package/dist/cjs/hooks/useChartDimensions/index.js +34 -0
- package/dist/cjs/hooks/useChartDimensions/utils.d.ts +10 -0
- package/dist/cjs/hooks/useChartDimensions/utils.js +32 -0
- package/dist/cjs/hooks/useChartOptions/chart.d.ts +6 -0
- package/dist/cjs/hooks/useChartOptions/chart.js +28 -0
- package/dist/cjs/hooks/useChartOptions/index.d.ts +7 -0
- package/dist/cjs/hooks/useChartOptions/index.js +21 -0
- package/dist/cjs/hooks/useChartOptions/title.d.ts +5 -0
- package/dist/cjs/hooks/useChartOptions/title.js +18 -0
- package/dist/cjs/hooks/useChartOptions/tooltip.d.ts +5 -0
- package/dist/cjs/hooks/useChartOptions/tooltip.js +5 -0
- package/dist/cjs/hooks/useChartOptions/types.d.ts +47 -0
- package/dist/cjs/hooks/useChartOptions/types.js +1 -0
- package/dist/cjs/hooks/useChartOptions/x-axis.d.ts +7 -0
- package/dist/cjs/hooks/useChartOptions/x-axis.js +115 -0
- package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +7 -0
- package/dist/cjs/hooks/useChartOptions/y-axis.js +117 -0
- package/dist/cjs/hooks/useSeries/constants.d.ts +8 -0
- package/dist/cjs/hooks/useSeries/constants.js +19 -0
- package/dist/cjs/hooks/useSeries/index.d.ts +29 -0
- package/dist/cjs/hooks/useSeries/index.js +82 -0
- package/dist/cjs/hooks/useSeries/prepare-area.d.ts +19 -0
- package/dist/cjs/hooks/useSeries/prepare-area.js +63 -0
- package/dist/cjs/hooks/useSeries/prepare-bar-x.d.ts +10 -0
- package/dist/cjs/hooks/useSeries/prepare-bar-x.js +38 -0
- package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +10 -0
- package/dist/cjs/hooks/useSeries/prepare-bar-y.js +48 -0
- package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +27 -0
- package/dist/cjs/hooks/useSeries/prepare-legend.js +144 -0
- package/dist/cjs/hooks/useSeries/prepare-line.d.ts +22 -0
- package/dist/cjs/hooks/useSeries/prepare-line.js +82 -0
- package/dist/cjs/hooks/useSeries/prepare-options.d.ts +3 -0
- package/dist/cjs/hooks/useSeries/prepare-options.js +5 -0
- package/dist/cjs/hooks/useSeries/prepare-pie.d.ts +9 -0
- package/dist/cjs/hooks/useSeries/prepare-pie.js +62 -0
- package/dist/cjs/hooks/useSeries/prepare-scatter.d.ts +11 -0
- package/dist/cjs/hooks/useSeries/prepare-scatter.js +46 -0
- package/dist/cjs/hooks/useSeries/prepare-treemap.d.ts +11 -0
- package/dist/cjs/hooks/useSeries/prepare-treemap.js +38 -0
- package/dist/cjs/hooks/useSeries/prepare-waterfall.d.ts +10 -0
- package/dist/cjs/hooks/useSeries/prepare-waterfall.js +37 -0
- package/dist/cjs/hooks/useSeries/prepareSeries.d.ts +10 -0
- package/dist/cjs/hooks/useSeries/prepareSeries.js +65 -0
- package/dist/cjs/hooks/useSeries/types.d.ts +253 -0
- package/dist/cjs/hooks/useSeries/types.js +1 -0
- package/dist/cjs/hooks/useSeries/utils.d.ts +7 -0
- package/dist/cjs/hooks/useSeries/utils.js +33 -0
- package/dist/cjs/hooks/useShapes/HtmlLayer.d.ts +8 -0
- package/dist/cjs/hooks/useShapes/HtmlLayer.js +22 -0
- package/dist/cjs/hooks/useShapes/area/index.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/area/index.js +143 -0
- package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +158 -0
- package/dist/cjs/hooks/useShapes/area/types.d.ts +27 -0
- package/dist/cjs/hooks/useShapes/area/types.js +1 -0
- package/dist/cjs/hooks/useShapes/bar-x/index.d.ts +13 -0
- package/dist/cjs/hooks/useShapes/bar-x/index.js +95 -0
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +13 -0
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +160 -0
- package/dist/cjs/hooks/useShapes/bar-x/types.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/bar-x/types.js +1 -0
- package/dist/cjs/hooks/useShapes/bar-y/index.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/bar-y/index.js +84 -0
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +169 -0
- package/dist/cjs/hooks/useShapes/bar-y/types.d.ts +13 -0
- package/dist/cjs/hooks/useShapes/bar-y/types.js +1 -0
- package/dist/cjs/hooks/useShapes/constants.d.ts +3 -0
- package/dist/cjs/hooks/useShapes/constants.js +3 -0
- package/dist/cjs/hooks/useShapes/index.d.ts +33 -0
- package/dist/cjs/hooks/useShapes/index.js +154 -0
- package/dist/cjs/hooks/useShapes/line/index.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/line/index.js +130 -0
- package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +13 -0
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +91 -0
- package/dist/cjs/hooks/useShapes/line/types.d.ts +29 -0
- package/dist/cjs/hooks/useShapes/line/types.js +1 -0
- package/dist/cjs/hooks/useShapes/marker.d.ts +14 -0
- package/dist/cjs/hooks/useShapes/marker.js +75 -0
- package/dist/cjs/hooks/useShapes/pie/index.d.ts +13 -0
- package/dist/cjs/hooks/useShapes/pie/index.js +171 -0
- package/dist/cjs/hooks/useShapes/pie/prepare-data.d.ts +9 -0
- package/dist/cjs/hooks/useShapes/pie/prepare-data.js +186 -0
- package/dist/cjs/hooks/useShapes/pie/types.d.ts +41 -0
- package/dist/cjs/hooks/useShapes/pie/types.js +1 -0
- package/dist/cjs/hooks/useShapes/pie/utils.d.ts +4 -0
- package/dist/cjs/hooks/useShapes/pie/utils.js +15 -0
- package/dist/cjs/hooks/useShapes/scatter/index.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/scatter/index.js +69 -0
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.d.ts +11 -0
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +31 -0
- package/dist/cjs/hooks/useShapes/scatter/types.d.ts +17 -0
- package/dist/cjs/hooks/useShapes/scatter/types.js +1 -0
- package/dist/cjs/hooks/useShapes/styles.css +35 -0
- package/dist/cjs/hooks/useShapes/treemap/index.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/treemap/index.js +98 -0
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.d.ts +7 -0
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +114 -0
- package/dist/cjs/hooks/useShapes/treemap/types.d.ts +16 -0
- package/dist/cjs/hooks/useShapes/treemap/types.js +1 -0
- package/dist/cjs/hooks/useShapes/utils.d.ts +29 -0
- package/dist/cjs/hooks/useShapes/utils.js +53 -0
- package/dist/cjs/hooks/useShapes/waterfall/index.d.ts +13 -0
- package/dist/cjs/hooks/useShapes/waterfall/index.js +127 -0
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +12 -0
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +133 -0
- package/dist/cjs/hooks/useShapes/waterfall/types.d.ts +14 -0
- package/dist/cjs/hooks/useShapes/waterfall/types.js +1 -0
- package/dist/cjs/hooks/useSplit/index.d.ts +14 -0
- package/dist/cjs/hooks/useSplit/index.js +57 -0
- package/dist/cjs/hooks/useSplit/types.d.ts +17 -0
- package/dist/cjs/hooks/useSplit/types.js +1 -0
- package/dist/cjs/hooks/useTooltip/index.d.ts +13 -0
- package/dist/cjs/hooks/useTooltip/index.js +17 -0
- package/dist/cjs/hooks/useTooltip/types.d.ts +1 -0
- package/dist/cjs/hooks/useTooltip/types.js +1 -0
- package/dist/cjs/i18n/index.d.ts +8 -0
- package/dist/cjs/i18n/index.js +10 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/libs/chart-error/index.d.ts +16 -0
- package/dist/cjs/libs/chart-error/index.js +19 -0
- package/dist/cjs/libs/format-number/i18n/en.json +17 -0
- package/dist/cjs/libs/format-number/i18n/i18n.d.ts +5 -0
- package/dist/cjs/libs/format-number/i18n/i18n.js +8 -0
- package/dist/cjs/libs/format-number/i18n/ru.json +17 -0
- package/dist/cjs/libs/format-number/index.d.ts +5 -0
- package/dist/cjs/libs/format-number/index.js +87 -0
- package/dist/cjs/libs/format-number/types.d.ts +14 -0
- package/dist/cjs/libs/format-number/types.js +1 -0
- package/dist/cjs/libs/index.d.ts +2 -0
- package/dist/cjs/libs/index.js +2 -0
- package/dist/cjs/types/chart/area.d.ts +76 -0
- package/dist/cjs/types/chart/area.js +1 -0
- package/dist/cjs/types/chart/axis.d.ts +85 -0
- package/dist/cjs/types/chart/axis.js +1 -0
- package/dist/cjs/types/chart/bar-x.d.ts +67 -0
- package/dist/cjs/types/chart/bar-x.js +1 -0
- package/dist/cjs/types/chart/bar-y.d.ts +60 -0
- package/dist/cjs/types/chart/bar-y.js +1 -0
- package/dist/cjs/types/chart/base.d.ts +48 -0
- package/dist/cjs/types/chart/base.js +1 -0
- package/dist/cjs/types/chart/chart.d.ts +15 -0
- package/dist/cjs/types/chart/chart.js +1 -0
- package/dist/cjs/types/chart/halo.d.ts +9 -0
- package/dist/cjs/types/chart/halo.js +1 -0
- package/dist/cjs/types/chart/legend.d.ts +92 -0
- package/dist/cjs/types/chart/legend.js +1 -0
- package/dist/cjs/types/chart/line.d.ts +57 -0
- package/dist/cjs/types/chart/line.js +1 -0
- package/dist/cjs/types/chart/marker.d.ts +12 -0
- package/dist/cjs/types/chart/marker.js +1 -0
- package/dist/cjs/types/chart/pie.d.ts +88 -0
- package/dist/cjs/types/chart/pie.js +1 -0
- package/dist/cjs/types/chart/scatter.d.ts +46 -0
- package/dist/cjs/types/chart/scatter.js +1 -0
- package/dist/cjs/types/chart/series.d.ts +226 -0
- package/dist/cjs/types/chart/series.js +1 -0
- package/dist/cjs/types/chart/split.d.ts +13 -0
- package/dist/cjs/types/chart/split.js +1 -0
- package/dist/cjs/types/chart/title.d.ts +5 -0
- package/dist/cjs/types/chart/title.js +1 -0
- package/dist/cjs/types/chart/tooltip.d.ts +67 -0
- package/dist/cjs/types/chart/tooltip.js +1 -0
- package/dist/cjs/types/chart/treemap.d.ts +46 -0
- package/dist/cjs/types/chart/treemap.js +1 -0
- package/dist/cjs/types/chart/waterfall.d.ts +40 -0
- package/dist/cjs/types/chart/waterfall.js +1 -0
- package/dist/cjs/types/chart-ui.d.ts +24 -0
- package/dist/cjs/types/chart-ui.js +1 -0
- package/dist/cjs/types/formatter.d.ts +14 -0
- package/dist/cjs/types/formatter.js +1 -0
- package/dist/cjs/types/index.d.ts +42 -0
- package/dist/cjs/types/index.js +19 -0
- package/dist/cjs/types/misc.d.ts +4 -0
- package/dist/cjs/types/misc.js +1 -0
- package/dist/cjs/utils/chart/axis-generators/bottom.d.ts +24 -0
- package/dist/cjs/utils/chart/axis-generators/bottom.js +126 -0
- package/dist/cjs/utils/chart/axis-generators/index.d.ts +1 -0
- package/dist/cjs/utils/chart/axis-generators/index.js +1 -0
- package/dist/cjs/utils/chart/axis.d.ts +31 -0
- package/dist/cjs/utils/chart/axis.js +71 -0
- package/dist/cjs/utils/chart/color.d.ts +10 -0
- package/dist/cjs/utils/chart/color.js +43 -0
- package/dist/cjs/utils/chart/get-closest-data.d.ts +15 -0
- package/dist/cjs/utils/chart/get-closest-data.js +172 -0
- package/dist/cjs/utils/chart/index.d.ts +78 -0
- package/dist/cjs/utils/chart/index.js +210 -0
- package/dist/cjs/utils/chart/labels.d.ts +6 -0
- package/dist/cjs/utils/chart/labels.js +44 -0
- package/dist/cjs/utils/chart/legend.d.ts +8 -0
- package/dist/cjs/utils/chart/legend.js +23 -0
- package/dist/cjs/utils/chart/math.d.ts +25 -0
- package/dist/cjs/utils/chart/math.js +51 -0
- package/dist/cjs/utils/chart/series/index.d.ts +1 -0
- package/dist/cjs/utils/chart/series/index.js +1 -0
- package/dist/cjs/utils/chart/series/waterfall.d.ts +4 -0
- package/dist/cjs/utils/chart/series/waterfall.js +25 -0
- package/dist/cjs/utils/chart/symbol.d.ts +3 -0
- package/dist/cjs/utils/chart/symbol.js +36 -0
- package/dist/cjs/utils/chart/text.d.ts +29 -0
- package/dist/cjs/utils/chart/text.js +139 -0
- package/dist/cjs/utils/chart/time.d.ts +3 -0
- package/dist/cjs/utils/chart/time.js +34 -0
- package/dist/cjs/utils/chart-ui/index.d.ts +4 -0
- package/dist/cjs/utils/chart-ui/index.js +4 -0
- package/dist/cjs/utils/chart-ui/pie-center-text.d.ts +7 -0
- package/dist/cjs/utils/chart-ui/pie-center-text.js +23 -0
- package/dist/cjs/utils/cn.d.ts +3 -0
- package/dist/cjs/utils/cn.js +4 -0
- package/dist/cjs/utils/d3-dispatcher.d.ts +1 -0
- package/dist/cjs/utils/d3-dispatcher.js +4 -0
- package/dist/cjs/utils/index.d.ts +5 -0
- package/dist/cjs/utils/index.js +5 -0
- package/dist/cjs/utils/misc.d.ts +2 -0
- package/dist/cjs/utils/misc.js +8 -0
- package/dist/cjs/validation/index.d.ts +2 -0
- package/dist/cjs/validation/index.js +220 -0
- package/dist/esm/components/Axis/AxisX.d.ts +20 -0
- package/dist/esm/components/Axis/AxisX.js +108 -0
- package/dist/esm/components/Axis/AxisY.d.ts +12 -0
- package/dist/esm/components/Axis/AxisY.js +199 -0
- package/dist/esm/components/Axis/index.d.ts +2 -0
- package/dist/esm/components/Axis/index.js +2 -0
- package/dist/esm/components/Axis/styles.css +17 -0
- package/dist/esm/components/ChartInner/index.d.ts +10 -0
- package/dist/esm/components/ChartInner/index.js +143 -0
- package/dist/esm/components/ChartInner/styles.css +10 -0
- package/dist/esm/components/Legend/index.d.ts +13 -0
- package/dist/esm/components/Legend/index.js +278 -0
- package/dist/esm/components/Legend/styles.css +47 -0
- package/dist/esm/components/PlotTitle/index.d.ts +8 -0
- package/dist/esm/components/PlotTitle/index.js +13 -0
- package/dist/esm/components/PlotTitle/styles.css +5 -0
- package/dist/esm/components/Title/index.d.ts +8 -0
- package/dist/esm/components/Title/index.js +9 -0
- package/dist/esm/components/Title/styles.css +5 -0
- package/dist/esm/components/Tooltip/DefaultContent.d.ts +10 -0
- package/dist/esm/components/Tooltip/DefaultContent.js +101 -0
- package/dist/esm/components/Tooltip/index.d.ts +13 -0
- package/dist/esm/components/Tooltip/index.js +29 -0
- package/dist/esm/components/Tooltip/styles.css +29 -0
- package/dist/esm/components/index.d.ts +18 -0
- package/dist/esm/components/index.js +66 -0
- package/dist/esm/constants/defaults/axis.d.ts +14 -0
- package/dist/esm/constants/defaults/axis.js +18 -0
- package/dist/esm/constants/defaults/index.d.ts +3 -0
- package/dist/esm/constants/defaults/index.js +3 -0
- package/dist/esm/constants/defaults/legend.d.ts +13 -0
- package/dist/esm/constants/defaults/legend.js +12 -0
- package/dist/esm/constants/defaults/series-options.d.ts +24 -0
- package/dist/esm/constants/defaults/series-options.js +106 -0
- package/dist/esm/constants/index.d.ts +46 -0
- package/dist/esm/constants/index.js +71 -0
- package/dist/esm/hooks/index.d.ts +10 -0
- package/dist/esm/hooks/index.js +10 -0
- package/dist/esm/hooks/useAxisScales/index.d.ts +25 -0
- package/dist/esm/hooks/useAxisScales/index.js +183 -0
- package/dist/esm/hooks/useChartDimensions/index.d.ts +16 -0
- package/dist/esm/hooks/useChartDimensions/index.js +34 -0
- package/dist/esm/hooks/useChartDimensions/utils.d.ts +10 -0
- package/dist/esm/hooks/useChartDimensions/utils.js +32 -0
- package/dist/esm/hooks/useChartOptions/chart.d.ts +6 -0
- package/dist/esm/hooks/useChartOptions/chart.js +28 -0
- package/dist/esm/hooks/useChartOptions/index.d.ts +7 -0
- package/dist/esm/hooks/useChartOptions/index.js +21 -0
- package/dist/esm/hooks/useChartOptions/title.d.ts +5 -0
- package/dist/esm/hooks/useChartOptions/title.js +18 -0
- package/dist/esm/hooks/useChartOptions/tooltip.d.ts +5 -0
- package/dist/esm/hooks/useChartOptions/tooltip.js +5 -0
- package/dist/esm/hooks/useChartOptions/types.d.ts +47 -0
- package/dist/esm/hooks/useChartOptions/types.js +1 -0
- package/dist/esm/hooks/useChartOptions/x-axis.d.ts +7 -0
- package/dist/esm/hooks/useChartOptions/x-axis.js +115 -0
- package/dist/esm/hooks/useChartOptions/y-axis.d.ts +7 -0
- package/dist/esm/hooks/useChartOptions/y-axis.js +117 -0
- package/dist/esm/hooks/useSeries/constants.d.ts +8 -0
- package/dist/esm/hooks/useSeries/constants.js +19 -0
- package/dist/esm/hooks/useSeries/index.d.ts +29 -0
- package/dist/esm/hooks/useSeries/index.js +82 -0
- package/dist/esm/hooks/useSeries/prepare-area.d.ts +19 -0
- package/dist/esm/hooks/useSeries/prepare-area.js +63 -0
- package/dist/esm/hooks/useSeries/prepare-bar-x.d.ts +10 -0
- package/dist/esm/hooks/useSeries/prepare-bar-x.js +38 -0
- package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +10 -0
- package/dist/esm/hooks/useSeries/prepare-bar-y.js +48 -0
- package/dist/esm/hooks/useSeries/prepare-legend.d.ts +27 -0
- package/dist/esm/hooks/useSeries/prepare-legend.js +144 -0
- package/dist/esm/hooks/useSeries/prepare-line.d.ts +22 -0
- package/dist/esm/hooks/useSeries/prepare-line.js +82 -0
- package/dist/esm/hooks/useSeries/prepare-options.d.ts +3 -0
- package/dist/esm/hooks/useSeries/prepare-options.js +5 -0
- package/dist/esm/hooks/useSeries/prepare-pie.d.ts +9 -0
- package/dist/esm/hooks/useSeries/prepare-pie.js +62 -0
- package/dist/esm/hooks/useSeries/prepare-scatter.d.ts +11 -0
- package/dist/esm/hooks/useSeries/prepare-scatter.js +46 -0
- package/dist/esm/hooks/useSeries/prepare-treemap.d.ts +11 -0
- package/dist/esm/hooks/useSeries/prepare-treemap.js +38 -0
- package/dist/esm/hooks/useSeries/prepare-waterfall.d.ts +10 -0
- package/dist/esm/hooks/useSeries/prepare-waterfall.js +37 -0
- package/dist/esm/hooks/useSeries/prepareSeries.d.ts +10 -0
- package/dist/esm/hooks/useSeries/prepareSeries.js +65 -0
- package/dist/esm/hooks/useSeries/types.d.ts +253 -0
- package/dist/esm/hooks/useSeries/types.js +1 -0
- package/dist/esm/hooks/useSeries/utils.d.ts +7 -0
- package/dist/esm/hooks/useSeries/utils.js +33 -0
- package/dist/esm/hooks/useShapes/HtmlLayer.d.ts +8 -0
- package/dist/esm/hooks/useShapes/HtmlLayer.js +22 -0
- package/dist/esm/hooks/useShapes/area/index.d.ts +12 -0
- package/dist/esm/hooks/useShapes/area/index.js +143 -0
- package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +12 -0
- package/dist/esm/hooks/useShapes/area/prepare-data.js +158 -0
- package/dist/esm/hooks/useShapes/area/types.d.ts +27 -0
- package/dist/esm/hooks/useShapes/area/types.js +1 -0
- package/dist/esm/hooks/useShapes/bar-x/index.d.ts +13 -0
- package/dist/esm/hooks/useShapes/bar-x/index.js +95 -0
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +13 -0
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +160 -0
- package/dist/esm/hooks/useShapes/bar-x/types.d.ts +12 -0
- package/dist/esm/hooks/useShapes/bar-x/types.js +1 -0
- package/dist/esm/hooks/useShapes/bar-y/index.d.ts +12 -0
- package/dist/esm/hooks/useShapes/bar-y/index.js +84 -0
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +12 -0
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +169 -0
- package/dist/esm/hooks/useShapes/bar-y/types.d.ts +13 -0
- package/dist/esm/hooks/useShapes/bar-y/types.js +1 -0
- package/dist/esm/hooks/useShapes/constants.d.ts +3 -0
- package/dist/esm/hooks/useShapes/constants.js +3 -0
- package/dist/esm/hooks/useShapes/index.d.ts +33 -0
- package/dist/esm/hooks/useShapes/index.js +154 -0
- package/dist/esm/hooks/useShapes/line/index.d.ts +12 -0
- package/dist/esm/hooks/useShapes/line/index.js +130 -0
- package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +13 -0
- package/dist/esm/hooks/useShapes/line/prepare-data.js +91 -0
- package/dist/esm/hooks/useShapes/line/types.d.ts +29 -0
- package/dist/esm/hooks/useShapes/line/types.js +1 -0
- package/dist/esm/hooks/useShapes/marker.d.ts +14 -0
- package/dist/esm/hooks/useShapes/marker.js +75 -0
- package/dist/esm/hooks/useShapes/pie/index.d.ts +13 -0
- package/dist/esm/hooks/useShapes/pie/index.js +171 -0
- package/dist/esm/hooks/useShapes/pie/prepare-data.d.ts +9 -0
- package/dist/esm/hooks/useShapes/pie/prepare-data.js +186 -0
- package/dist/esm/hooks/useShapes/pie/types.d.ts +41 -0
- package/dist/esm/hooks/useShapes/pie/types.js +1 -0
- package/dist/esm/hooks/useShapes/pie/utils.d.ts +4 -0
- package/dist/esm/hooks/useShapes/pie/utils.js +15 -0
- package/dist/esm/hooks/useShapes/scatter/index.d.ts +12 -0
- package/dist/esm/hooks/useShapes/scatter/index.js +69 -0
- package/dist/esm/hooks/useShapes/scatter/prepare-data.d.ts +11 -0
- package/dist/esm/hooks/useShapes/scatter/prepare-data.js +31 -0
- package/dist/esm/hooks/useShapes/scatter/types.d.ts +17 -0
- package/dist/esm/hooks/useShapes/scatter/types.js +1 -0
- package/dist/esm/hooks/useShapes/styles.css +35 -0
- package/dist/esm/hooks/useShapes/treemap/index.d.ts +12 -0
- package/dist/esm/hooks/useShapes/treemap/index.js +98 -0
- package/dist/esm/hooks/useShapes/treemap/prepare-data.d.ts +7 -0
- package/dist/esm/hooks/useShapes/treemap/prepare-data.js +114 -0
- package/dist/esm/hooks/useShapes/treemap/types.d.ts +16 -0
- package/dist/esm/hooks/useShapes/treemap/types.js +1 -0
- package/dist/esm/hooks/useShapes/utils.d.ts +29 -0
- package/dist/esm/hooks/useShapes/utils.js +53 -0
- package/dist/esm/hooks/useShapes/waterfall/index.d.ts +13 -0
- package/dist/esm/hooks/useShapes/waterfall/index.js +127 -0
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +12 -0
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +133 -0
- package/dist/esm/hooks/useShapes/waterfall/types.d.ts +14 -0
- package/dist/esm/hooks/useShapes/waterfall/types.js +1 -0
- package/dist/esm/hooks/useSplit/index.d.ts +14 -0
- package/dist/esm/hooks/useSplit/index.js +57 -0
- package/dist/esm/hooks/useSplit/types.d.ts +17 -0
- package/dist/esm/hooks/useSplit/types.js +1 -0
- package/dist/esm/hooks/useTooltip/index.d.ts +13 -0
- package/dist/esm/hooks/useTooltip/index.js +17 -0
- package/dist/esm/hooks/useTooltip/types.d.ts +1 -0
- package/dist/esm/hooks/useTooltip/types.js +1 -0
- package/dist/esm/i18n/index.d.ts +8 -0
- package/dist/esm/i18n/index.js +10 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/libs/chart-error/index.d.ts +16 -0
- package/dist/esm/libs/chart-error/index.js +19 -0
- package/dist/esm/libs/format-number/i18n/en.json +17 -0
- package/dist/esm/libs/format-number/i18n/i18n.d.ts +5 -0
- package/dist/esm/libs/format-number/i18n/i18n.js +8 -0
- package/dist/esm/libs/format-number/i18n/ru.json +17 -0
- package/dist/esm/libs/format-number/index.d.ts +5 -0
- package/dist/esm/libs/format-number/index.js +87 -0
- package/dist/esm/libs/format-number/types.d.ts +14 -0
- package/dist/esm/libs/format-number/types.js +1 -0
- package/dist/esm/libs/index.d.ts +2 -0
- package/dist/esm/libs/index.js +2 -0
- package/dist/esm/types/chart/area.d.ts +76 -0
- package/dist/esm/types/chart/area.js +1 -0
- package/dist/esm/types/chart/axis.d.ts +85 -0
- package/dist/esm/types/chart/axis.js +1 -0
- package/dist/esm/types/chart/bar-x.d.ts +67 -0
- package/dist/esm/types/chart/bar-x.js +1 -0
- package/dist/esm/types/chart/bar-y.d.ts +60 -0
- package/dist/esm/types/chart/bar-y.js +1 -0
- package/dist/esm/types/chart/base.d.ts +48 -0
- package/dist/esm/types/chart/base.js +1 -0
- package/dist/esm/types/chart/chart.d.ts +15 -0
- package/dist/esm/types/chart/chart.js +1 -0
- package/dist/esm/types/chart/halo.d.ts +9 -0
- package/dist/esm/types/chart/halo.js +1 -0
- package/dist/esm/types/chart/legend.d.ts +92 -0
- package/dist/esm/types/chart/legend.js +1 -0
- package/dist/esm/types/chart/line.d.ts +57 -0
- package/dist/esm/types/chart/line.js +1 -0
- package/dist/esm/types/chart/marker.d.ts +12 -0
- package/dist/esm/types/chart/marker.js +1 -0
- package/dist/esm/types/chart/pie.d.ts +88 -0
- package/dist/esm/types/chart/pie.js +1 -0
- package/dist/esm/types/chart/scatter.d.ts +46 -0
- package/dist/esm/types/chart/scatter.js +1 -0
- package/dist/esm/types/chart/series.d.ts +226 -0
- package/dist/esm/types/chart/series.js +1 -0
- package/dist/esm/types/chart/split.d.ts +13 -0
- package/dist/esm/types/chart/split.js +1 -0
- package/dist/esm/types/chart/title.d.ts +5 -0
- package/dist/esm/types/chart/title.js +1 -0
- package/dist/esm/types/chart/tooltip.d.ts +67 -0
- package/dist/esm/types/chart/tooltip.js +1 -0
- package/dist/esm/types/chart/treemap.d.ts +46 -0
- package/dist/esm/types/chart/treemap.js +1 -0
- package/dist/esm/types/chart/waterfall.d.ts +40 -0
- package/dist/esm/types/chart/waterfall.js +1 -0
- package/dist/esm/types/chart-ui.d.ts +24 -0
- package/dist/esm/types/chart-ui.js +1 -0
- package/dist/esm/types/formatter.d.ts +14 -0
- package/dist/esm/types/formatter.js +1 -0
- package/dist/esm/types/index.d.ts +42 -0
- package/dist/esm/types/index.js +19 -0
- package/dist/esm/types/misc.d.ts +4 -0
- package/dist/esm/types/misc.js +1 -0
- package/dist/esm/utils/chart/axis-generators/bottom.d.ts +24 -0
- package/dist/esm/utils/chart/axis-generators/bottom.js +126 -0
- package/dist/esm/utils/chart/axis-generators/index.d.ts +1 -0
- package/dist/esm/utils/chart/axis-generators/index.js +1 -0
- package/dist/esm/utils/chart/axis.d.ts +31 -0
- package/dist/esm/utils/chart/axis.js +71 -0
- package/dist/esm/utils/chart/color.d.ts +10 -0
- package/dist/esm/utils/chart/color.js +43 -0
- package/dist/esm/utils/chart/get-closest-data.d.ts +15 -0
- package/dist/esm/utils/chart/get-closest-data.js +172 -0
- package/dist/esm/utils/chart/index.d.ts +78 -0
- package/dist/esm/utils/chart/index.js +210 -0
- package/dist/esm/utils/chart/labels.d.ts +6 -0
- package/dist/esm/utils/chart/labels.js +44 -0
- package/dist/esm/utils/chart/legend.d.ts +8 -0
- package/dist/esm/utils/chart/legend.js +23 -0
- package/dist/esm/utils/chart/math.d.ts +25 -0
- package/dist/esm/utils/chart/math.js +51 -0
- package/dist/esm/utils/chart/series/index.d.ts +1 -0
- package/dist/esm/utils/chart/series/index.js +1 -0
- package/dist/esm/utils/chart/series/waterfall.d.ts +4 -0
- package/dist/esm/utils/chart/series/waterfall.js +25 -0
- package/dist/esm/utils/chart/symbol.d.ts +3 -0
- package/dist/esm/utils/chart/symbol.js +36 -0
- package/dist/esm/utils/chart/text.d.ts +29 -0
- package/dist/esm/utils/chart/text.js +139 -0
- package/dist/esm/utils/chart/time.d.ts +3 -0
- package/dist/esm/utils/chart/time.js +34 -0
- package/dist/esm/utils/chart-ui/index.d.ts +4 -0
- package/dist/esm/utils/chart-ui/index.js +4 -0
- package/dist/esm/utils/chart-ui/pie-center-text.d.ts +7 -0
- package/dist/esm/utils/chart-ui/pie-center-text.js +23 -0
- package/dist/esm/utils/cn.d.ts +3 -0
- package/dist/esm/utils/cn.js +4 -0
- package/dist/esm/utils/d3-dispatcher.d.ts +1 -0
- package/dist/esm/utils/d3-dispatcher.js +4 -0
- package/dist/esm/utils/index.d.ts +5 -0
- package/dist/esm/utils/index.js +5 -0
- package/dist/esm/utils/misc.d.ts +2 -0
- package/dist/esm/utils/misc.js +8 -0
- package/dist/esm/validation/index.d.ts +2 -0
- package/dist/esm/validation/index.js +220 -0
- package/package.json +140 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { symbolCircle, symbolDiamond2, symbolSquare, symbolTriangle2 } from 'd3';
|
|
2
|
+
import { SymbolType } from '../../constants';
|
|
3
|
+
export const getSymbolType = (index) => {
|
|
4
|
+
const scatterStyles = Object.values(SymbolType);
|
|
5
|
+
return scatterStyles[index % scatterStyles.length];
|
|
6
|
+
};
|
|
7
|
+
// This is an inverted triangle
|
|
8
|
+
// Based on https://github.com/d3/d3-shape/blob/main/src/symbol/triangle2.js
|
|
9
|
+
const sqrt3 = Math.sqrt(3);
|
|
10
|
+
const triangleDown = {
|
|
11
|
+
draw: (context, size) => {
|
|
12
|
+
const s = Math.sqrt(size) * 0.6824;
|
|
13
|
+
const t = s / 2;
|
|
14
|
+
const u = (s * sqrt3) / 2;
|
|
15
|
+
context.moveTo(0, s);
|
|
16
|
+
context.lineTo(u, -t);
|
|
17
|
+
context.lineTo(-u, -t);
|
|
18
|
+
context.closePath();
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export const getSymbol = (symbolType) => {
|
|
22
|
+
switch (symbolType) {
|
|
23
|
+
case SymbolType.Diamond:
|
|
24
|
+
return symbolDiamond2;
|
|
25
|
+
case SymbolType.Circle:
|
|
26
|
+
return symbolCircle;
|
|
27
|
+
case SymbolType.Square:
|
|
28
|
+
return symbolSquare;
|
|
29
|
+
case SymbolType.Triangle:
|
|
30
|
+
return symbolTriangle2;
|
|
31
|
+
case SymbolType.TriangleDown:
|
|
32
|
+
return triangleDown;
|
|
33
|
+
default:
|
|
34
|
+
return symbolCircle;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Selection } from 'd3';
|
|
2
|
+
import type { BaseTextStyle, MeaningfulAny } from '../../types';
|
|
3
|
+
export declare function handleOverflowingText(tSpan: SVGTSpanElement | null, maxWidth: number): void;
|
|
4
|
+
export declare function setEllipsisForOverflowText<T>(selection: Selection<SVGTextElement, T, null, unknown>, maxWidth: number): void;
|
|
5
|
+
export declare function setEllipsisForOverflowTexts<T>(selection: Selection<SVGTextElement, T, MeaningfulAny, unknown>, maxWidth: ((datum: T) => number) | number): void;
|
|
6
|
+
export declare function hasOverlappingLabels({ width, labels, padding, style, }: {
|
|
7
|
+
width: number;
|
|
8
|
+
labels: string[];
|
|
9
|
+
style?: BaseTextStyle;
|
|
10
|
+
padding?: number;
|
|
11
|
+
}): boolean;
|
|
12
|
+
export declare function getLabelsSize({ labels, style, rotation, html, }: {
|
|
13
|
+
labels: string[];
|
|
14
|
+
style?: BaseTextStyle;
|
|
15
|
+
rotation?: number;
|
|
16
|
+
html?: boolean;
|
|
17
|
+
}): {
|
|
18
|
+
maxHeight: number;
|
|
19
|
+
maxWidth: number;
|
|
20
|
+
};
|
|
21
|
+
export type TextRow = {
|
|
22
|
+
text: string;
|
|
23
|
+
y: number;
|
|
24
|
+
};
|
|
25
|
+
export declare function wrapText(args: {
|
|
26
|
+
text: string;
|
|
27
|
+
style?: BaseTextStyle;
|
|
28
|
+
width: number;
|
|
29
|
+
}): TextRow[];
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { select } from 'd3-selection';
|
|
2
|
+
export function handleOverflowingText(tSpan, maxWidth) {
|
|
3
|
+
var _a, _b, _c;
|
|
4
|
+
if (!tSpan) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const svg = tSpan.closest('svg');
|
|
8
|
+
if (!svg) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const textNode = tSpan.closest('text');
|
|
12
|
+
const angle = ((_a = Array.from((textNode === null || textNode === void 0 ? void 0 : textNode.transform.baseVal) || []).find((item) => item.angle)) === null || _a === void 0 ? void 0 : _a.angle) || 0;
|
|
13
|
+
const revertRotation = svg.createSVGTransform();
|
|
14
|
+
revertRotation.setRotate(-angle, 0, 0);
|
|
15
|
+
textNode === null || textNode === void 0 ? void 0 : textNode.transform.baseVal.appendItem(revertRotation);
|
|
16
|
+
let text = tSpan.textContent || '';
|
|
17
|
+
let textLength = ((_b = tSpan.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width) || 0;
|
|
18
|
+
while (textLength > maxWidth && text.length > 1) {
|
|
19
|
+
text = text.slice(0, -1);
|
|
20
|
+
tSpan.textContent = text + '…';
|
|
21
|
+
textLength = ((_c = tSpan.getBoundingClientRect()) === null || _c === void 0 ? void 0 : _c.width) || 0;
|
|
22
|
+
}
|
|
23
|
+
textNode === null || textNode === void 0 ? void 0 : textNode.transform.baseVal.removeItem((textNode === null || textNode === void 0 ? void 0 : textNode.transform.baseVal.length) - 1);
|
|
24
|
+
}
|
|
25
|
+
export function setEllipsisForOverflowText(selection, maxWidth) {
|
|
26
|
+
const text = selection.text();
|
|
27
|
+
selection.text(null).append('title').text(text);
|
|
28
|
+
const tSpan = selection.append('tspan').text(text).style('alignment-baseline', 'inherit');
|
|
29
|
+
handleOverflowingText(tSpan.node(), maxWidth);
|
|
30
|
+
}
|
|
31
|
+
export function setEllipsisForOverflowTexts(selection, maxWidth) {
|
|
32
|
+
selection.each(function (datum) {
|
|
33
|
+
const textMaxWidth = typeof maxWidth === 'function' ? maxWidth(datum) : maxWidth;
|
|
34
|
+
setEllipsisForOverflowText(select(this), textMaxWidth);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function hasOverlappingLabels({ width, labels, padding = 0, style, }) {
|
|
38
|
+
const maxWidth = (width - padding * (labels.length - 1)) / labels.length;
|
|
39
|
+
const textElement = select(document.body)
|
|
40
|
+
.append('text')
|
|
41
|
+
.style('font-size', (style === null || style === void 0 ? void 0 : style.fontSize) || '');
|
|
42
|
+
const result = labels.some((label) => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const textWidth = ((_b = (_a = textElement.text(label).node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width) || 0;
|
|
45
|
+
return textWidth > maxWidth;
|
|
46
|
+
});
|
|
47
|
+
textElement.remove();
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
function renderLabels(selection, { labels, style = {}, attrs = {}, }) {
|
|
51
|
+
const text = selection.append('g').append('text');
|
|
52
|
+
text.style('font-size', style.fontSize || '');
|
|
53
|
+
text.style('font-weight', style.fontWeight || '');
|
|
54
|
+
Object.entries(attrs).forEach(([name, value]) => {
|
|
55
|
+
text.attr(name, value);
|
|
56
|
+
});
|
|
57
|
+
text.selectAll('tspan')
|
|
58
|
+
.data(labels)
|
|
59
|
+
.enter()
|
|
60
|
+
.append('tspan')
|
|
61
|
+
.attr('x', 0)
|
|
62
|
+
.attr('dy', 0)
|
|
63
|
+
.text((d) => d);
|
|
64
|
+
return text;
|
|
65
|
+
}
|
|
66
|
+
export function getLabelsSize({ labels, style, rotation, html, }) {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
if (!labels.filter(Boolean).length) {
|
|
69
|
+
return { maxHeight: 0, maxWidth: 0 };
|
|
70
|
+
}
|
|
71
|
+
const container = select(document.body).append('div');
|
|
72
|
+
// TODO: Why do we need this styles?
|
|
73
|
+
// .attr('class', 'chartkit chartkit-theme_common');
|
|
74
|
+
const result = { maxHeight: 0, maxWidth: 0 };
|
|
75
|
+
let labelWrapper;
|
|
76
|
+
if (html) {
|
|
77
|
+
labelWrapper = container.append('div').style('position', 'absolute').node();
|
|
78
|
+
const { height, width } = labels.reduce((acc, l) => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
if (labelWrapper) {
|
|
81
|
+
labelWrapper.innerHTML = l;
|
|
82
|
+
}
|
|
83
|
+
const rect = labelWrapper === null || labelWrapper === void 0 ? void 0 : labelWrapper.getBoundingClientRect();
|
|
84
|
+
return {
|
|
85
|
+
width: Math.max(acc.width, (_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0),
|
|
86
|
+
height: Math.max(acc.height, (_b = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _b !== void 0 ? _b : 0),
|
|
87
|
+
};
|
|
88
|
+
}, { height: 0, width: 0 });
|
|
89
|
+
result.maxWidth = width;
|
|
90
|
+
result.maxHeight = height;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const svg = container.append('svg');
|
|
94
|
+
const textSelection = renderLabels(svg, { labels, style });
|
|
95
|
+
if (rotation) {
|
|
96
|
+
textSelection
|
|
97
|
+
.attr('text-anchor', rotation > 0 ? 'start' : 'end')
|
|
98
|
+
.style('transform', `rotate(${rotation}deg)`);
|
|
99
|
+
}
|
|
100
|
+
const rect = (_a = svg.select('g').node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
101
|
+
result.maxWidth = (_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0;
|
|
102
|
+
result.maxHeight = (_c = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _c !== void 0 ? _c : 0;
|
|
103
|
+
}
|
|
104
|
+
container.remove();
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
export function wrapText(args) {
|
|
108
|
+
const { text, style, width } = args;
|
|
109
|
+
const height = getLabelsSize({
|
|
110
|
+
labels: [text],
|
|
111
|
+
style: style,
|
|
112
|
+
}).maxHeight;
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
const segmenter = new Intl.Segmenter([], { granularity: 'word' });
|
|
115
|
+
const segments = Array.from(segmenter.segment(text));
|
|
116
|
+
return segments.reduce((acc, s) => {
|
|
117
|
+
const item = s;
|
|
118
|
+
if (!acc.length) {
|
|
119
|
+
acc.push({
|
|
120
|
+
text: '',
|
|
121
|
+
y: acc.length * height,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
let lastRow = acc[acc.length - 1];
|
|
125
|
+
if (item.isWordLike &&
|
|
126
|
+
getLabelsSize({
|
|
127
|
+
labels: [lastRow.text + item.segment],
|
|
128
|
+
style,
|
|
129
|
+
}).maxWidth > width) {
|
|
130
|
+
lastRow = {
|
|
131
|
+
text: '',
|
|
132
|
+
y: acc.length * height,
|
|
133
|
+
};
|
|
134
|
+
acc.push(lastRow);
|
|
135
|
+
}
|
|
136
|
+
lastRow.text += item.segment;
|
|
137
|
+
return acc;
|
|
138
|
+
}, []);
|
|
139
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const TIME_UNITS = {
|
|
2
|
+
millisecond: 1,
|
|
3
|
+
second: 1000,
|
|
4
|
+
minute: 60000,
|
|
5
|
+
hour: 3600000,
|
|
6
|
+
day: 24 * 3600000,
|
|
7
|
+
week: 7 * 24 * 3600000,
|
|
8
|
+
month: 28 * 24 * 3600000,
|
|
9
|
+
year: 364 * 24 * 3600000,
|
|
10
|
+
};
|
|
11
|
+
export const DATETIME_LABEL_FORMATS = {
|
|
12
|
+
millisecond: 'DD.MM.YY HH:mm:ss.SSS',
|
|
13
|
+
second: 'DD.MM.YY HH:mm:ss',
|
|
14
|
+
minute: 'DD.MM.YY HH:mm',
|
|
15
|
+
hour: 'DD.MM.YY HH:mm',
|
|
16
|
+
day: 'DD.MM.YY',
|
|
17
|
+
week: 'DD.MM.YY',
|
|
18
|
+
month: "MMM 'YY",
|
|
19
|
+
year: 'YYYY',
|
|
20
|
+
};
|
|
21
|
+
function getTimeUnit(range) {
|
|
22
|
+
const units = Object.keys(TIME_UNITS);
|
|
23
|
+
const index = units.findIndex((unit) => range < TIME_UNITS[unit]);
|
|
24
|
+
return index === -1 ? 'year' : units[index - 1];
|
|
25
|
+
}
|
|
26
|
+
export function getDefaultDateFormat(range) {
|
|
27
|
+
if (range) {
|
|
28
|
+
const unit = getTimeUnit(range);
|
|
29
|
+
if (unit in DATETIME_LABEL_FORMATS) {
|
|
30
|
+
return DATETIME_LABEL_FORMATS[unit];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return DATETIME_LABEL_FORMATS.day;
|
|
34
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { create } from 'd3-selection';
|
|
2
|
+
import get from 'lodash/get';
|
|
3
|
+
import { getLabelsSize } from '../chart/text';
|
|
4
|
+
const MAX_FONT_SIZE = 64;
|
|
5
|
+
export function pieCenterText(text, options) {
|
|
6
|
+
if (!text) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const padding = get(options, 'padding', 12);
|
|
10
|
+
return function (args) {
|
|
11
|
+
let fontSize = MAX_FONT_SIZE;
|
|
12
|
+
const textSize = getLabelsSize({ labels: [text], style: { fontSize: `${fontSize}px` } });
|
|
13
|
+
fontSize = (fontSize * (args.series.innerRadius - padding) * 2) / textSize.maxWidth;
|
|
14
|
+
const container = create('svg:g');
|
|
15
|
+
container
|
|
16
|
+
.append('text')
|
|
17
|
+
.text(text)
|
|
18
|
+
.attr('text-anchor', 'middle')
|
|
19
|
+
.attr('alignment-baseline', 'middle')
|
|
20
|
+
.style('font-size', `${fontSize}px`);
|
|
21
|
+
return container.node();
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getD3Dispatcher: () => import("d3-dispatch").Dispatch<object>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const randomString = (length, chars) => {
|
|
2
|
+
let result = '';
|
|
3
|
+
for (let i = length; i > 0; --i) {
|
|
4
|
+
result += chars[Math.floor(Math.random() * chars.length)];
|
|
5
|
+
}
|
|
6
|
+
return result;
|
|
7
|
+
};
|
|
8
|
+
export const getUniqId = () => `gravity-chart.${randomString(5, '0123456789abcdefghijklmnopqrstuvwxyz')}`;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import get from 'lodash/get';
|
|
2
|
+
import isEmpty from 'lodash/isEmpty';
|
|
3
|
+
import { DEFAULT_AXIS_TYPE, SeriesType } from '../constants';
|
|
4
|
+
import { i18n } from '../i18n';
|
|
5
|
+
import { CHART_ERROR_CODE, ChartError } from '../libs';
|
|
6
|
+
const AVAILABLE_SERIES_TYPES = Object.values(SeriesType);
|
|
7
|
+
const validateXYSeries = (args) => {
|
|
8
|
+
const { series, xAxis, yAxis = [] } = args;
|
|
9
|
+
const yAxisIndex = get(series, 'yAxis', 0);
|
|
10
|
+
const seriesYAxis = yAxis[yAxisIndex];
|
|
11
|
+
if (yAxisIndex !== 0 && typeof seriesYAxis === 'undefined') {
|
|
12
|
+
throw new ChartError({
|
|
13
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
14
|
+
message: i18n('error', 'label_invalid-y-axis-index', {
|
|
15
|
+
index: yAxisIndex,
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const xType = get(xAxis, 'type', DEFAULT_AXIS_TYPE);
|
|
20
|
+
const yType = get(seriesYAxis, 'type', DEFAULT_AXIS_TYPE);
|
|
21
|
+
series.data.forEach(({ x, y }) => {
|
|
22
|
+
switch (xType) {
|
|
23
|
+
case 'category': {
|
|
24
|
+
if (typeof x !== 'string' && typeof x !== 'number') {
|
|
25
|
+
throw new ChartError({
|
|
26
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
27
|
+
message: i18n('error', 'label_invalid-axis-category-data-point', {
|
|
28
|
+
key: 'x',
|
|
29
|
+
seriesName: series.name,
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 'datetime': {
|
|
36
|
+
if (typeof x !== 'number') {
|
|
37
|
+
throw new ChartError({
|
|
38
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
39
|
+
message: i18n('error', 'label_invalid-axis-datetime-data-point', {
|
|
40
|
+
key: 'x',
|
|
41
|
+
seriesName: series.name,
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'linear': {
|
|
48
|
+
if (typeof x !== 'number' && x !== null) {
|
|
49
|
+
throw new ChartError({
|
|
50
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
51
|
+
message: i18n('error', 'label_invalid-axis-linear-data-point', {
|
|
52
|
+
key: 'x',
|
|
53
|
+
seriesName: series.name,
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
switch (yType) {
|
|
60
|
+
case 'category': {
|
|
61
|
+
if (typeof y !== 'string' && typeof y !== 'number') {
|
|
62
|
+
throw new ChartError({
|
|
63
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
64
|
+
message: i18n('error', 'label_invalid-axis-category-data-point', {
|
|
65
|
+
key: 'y',
|
|
66
|
+
seriesName: series.name,
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'datetime': {
|
|
73
|
+
if (typeof y !== 'number') {
|
|
74
|
+
throw new ChartError({
|
|
75
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
76
|
+
message: i18n('error', 'label_invalid-axis-datetime-data-point', {
|
|
77
|
+
key: 'y',
|
|
78
|
+
seriesName: series.name,
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case 'linear': {
|
|
85
|
+
if (typeof y !== 'number' && y !== null) {
|
|
86
|
+
throw new ChartError({
|
|
87
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
88
|
+
message: i18n('error', 'label_invalid-axis-linear-data-point', {
|
|
89
|
+
key: 'y',
|
|
90
|
+
seriesName: series.name,
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
const validatePieSeries = ({ series }) => {
|
|
99
|
+
series.data.forEach(({ value }) => {
|
|
100
|
+
if (typeof value !== 'number') {
|
|
101
|
+
throw new ChartError({
|
|
102
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
103
|
+
message: i18n('error', 'label_invalid-pie-data-value'),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const validateStacking = ({ series }) => {
|
|
109
|
+
const availableStackingValues = ['normal', 'percent'];
|
|
110
|
+
if (series.stacking && !availableStackingValues.includes(series.stacking)) {
|
|
111
|
+
throw new ChartError({
|
|
112
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
113
|
+
message: i18n('error', 'label_invalid-series-property', {
|
|
114
|
+
key: 'stacking',
|
|
115
|
+
values: availableStackingValues,
|
|
116
|
+
}),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const validateTreemapSeries = ({ series }) => {
|
|
121
|
+
const parentIds = {};
|
|
122
|
+
series.data.forEach((d) => {
|
|
123
|
+
if (d.parentId && !parentIds[d.parentId]) {
|
|
124
|
+
parentIds[d.parentId] = true;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
series.data.forEach((d) => {
|
|
128
|
+
let idOrName = d.id;
|
|
129
|
+
if (!idOrName) {
|
|
130
|
+
idOrName = Array.isArray(d.name) ? d.name.join() : d.name;
|
|
131
|
+
}
|
|
132
|
+
if (parentIds[idOrName] && typeof d.value === 'number') {
|
|
133
|
+
throw new ChartError({
|
|
134
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
135
|
+
message: i18n('error', 'label_invalid-treemap-redundant-value', {
|
|
136
|
+
id: d.id,
|
|
137
|
+
name: d.name,
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (!parentIds[idOrName] && typeof d.value !== 'number') {
|
|
142
|
+
throw new ChartError({
|
|
143
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
144
|
+
message: i18n('error', 'label_invalid-treemap-missing-value', {
|
|
145
|
+
id: d.id,
|
|
146
|
+
name: d.name,
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
const validateSeries = (args) => {
|
|
153
|
+
const { series, xAxis, yAxis } = args;
|
|
154
|
+
if (!AVAILABLE_SERIES_TYPES.includes(series.type)) {
|
|
155
|
+
throw new ChartError({
|
|
156
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
157
|
+
message: i18n('error', 'label_invalid-series-type', {
|
|
158
|
+
types: AVAILABLE_SERIES_TYPES.join(', '),
|
|
159
|
+
}),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
switch (series.type) {
|
|
163
|
+
case 'area':
|
|
164
|
+
case 'bar-y':
|
|
165
|
+
case 'bar-x': {
|
|
166
|
+
validateXYSeries({ series, xAxis, yAxis });
|
|
167
|
+
validateStacking({ series });
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case 'line':
|
|
171
|
+
case 'scatter': {
|
|
172
|
+
validateXYSeries({ series, xAxis, yAxis });
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case 'pie': {
|
|
176
|
+
validatePieSeries({ series });
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case 'treemap': {
|
|
180
|
+
validateTreemapSeries({ series });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const countSeriesByType = (args) => {
|
|
185
|
+
const { series, type } = args;
|
|
186
|
+
let count = 0;
|
|
187
|
+
series.forEach((s) => {
|
|
188
|
+
if (s.type === type) {
|
|
189
|
+
count += 1;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return count;
|
|
193
|
+
};
|
|
194
|
+
export const validateData = (data) => {
|
|
195
|
+
if (isEmpty(data) || isEmpty(data.series) || isEmpty(data.series.data)) {
|
|
196
|
+
throw new ChartError({
|
|
197
|
+
code: CHART_ERROR_CODE.NO_DATA,
|
|
198
|
+
message: i18n('error', 'label_no-data'),
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
if (data.series.data.some((s) => isEmpty(s.data))) {
|
|
202
|
+
throw new ChartError({
|
|
203
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
204
|
+
message: 'You should specify data for all series',
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const treemapSeriesCount = countSeriesByType({
|
|
208
|
+
series: data.series.data,
|
|
209
|
+
type: SeriesType.Treemap,
|
|
210
|
+
});
|
|
211
|
+
if (treemapSeriesCount > 1) {
|
|
212
|
+
throw new ChartError({
|
|
213
|
+
code: CHART_ERROR_CODE.INVALID_DATA,
|
|
214
|
+
message: 'It looks like you are trying to define more than one "treemap" series.',
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
data.series.data.forEach((series) => {
|
|
218
|
+
validateSeries({ series, yAxis: data.yAxis, xAxis: data.xAxis });
|
|
219
|
+
});
|
|
220
|
+
};
|