@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 YANDEX LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @gravity-ui/charts · [](https://www.npmjs.com/package/@gravity-ui/charts) [](https://github.com/gravity-ui/charts/actions/workflows/ci.yml?query=branch:main) [](https://preview.gravity-ui.com/charts/)
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install --save-dev @gravity-ui/uikit @gravity-ui/charts
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Development
|
|
10
|
+
|
|
11
|
+
To start the development server with storybook run the following:
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm run start
|
|
15
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartScale, PreparedAxis, PreparedSplit } from '../../hooks';
|
|
3
|
+
import './styles.css';
|
|
4
|
+
type Props = {
|
|
5
|
+
axis: PreparedAxis;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
scale: ChartScale;
|
|
9
|
+
split: PreparedSplit;
|
|
10
|
+
};
|
|
11
|
+
export declare function getTitlePosition(args: {
|
|
12
|
+
axis: PreparedAxis;
|
|
13
|
+
width: number;
|
|
14
|
+
rowCount: number;
|
|
15
|
+
}): {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const AxisX: React.NamedExoticComponent<Props>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { select } from 'd3';
|
|
3
|
+
import { block, formatAxisTickLabel, getAxisTitleRows, getClosestPointsRange, getMaxTickCount, getScaleTicks, getTicksCount, handleOverflowingText, } from '../../utils';
|
|
4
|
+
import { axisBottom } from '../../utils/chart/axis-generators';
|
|
5
|
+
import './styles.css';
|
|
6
|
+
const b = block('d3-axis');
|
|
7
|
+
function getLabelFormatter({ axis, scale }) {
|
|
8
|
+
const ticks = getScaleTicks(scale);
|
|
9
|
+
const tickStep = getClosestPointsRange(axis, ticks);
|
|
10
|
+
return (value) => {
|
|
11
|
+
if (!axis.labels.enabled) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
return formatAxisTickLabel({
|
|
15
|
+
axis,
|
|
16
|
+
value,
|
|
17
|
+
step: tickStep,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function getTitlePosition(args) {
|
|
22
|
+
const { axis, width, rowCount } = args;
|
|
23
|
+
if (rowCount < 1) {
|
|
24
|
+
return { x: 0, y: 0 };
|
|
25
|
+
}
|
|
26
|
+
let x;
|
|
27
|
+
const y = axis.title.height / rowCount + axis.title.margin + axis.labels.height + axis.labels.margin;
|
|
28
|
+
switch (axis.title.align) {
|
|
29
|
+
case 'left': {
|
|
30
|
+
x = axis.title.width / 2;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case 'right': {
|
|
34
|
+
x = width - axis.title.width / 2;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'center': {
|
|
38
|
+
x = width / 2;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { x, y };
|
|
43
|
+
}
|
|
44
|
+
export const AxisX = React.memo(function AxisX(props) {
|
|
45
|
+
const { axis, width, height: totalHeight, scale, split } = props;
|
|
46
|
+
const ref = React.useRef(null);
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
if (!ref.current) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
let tickItems = [];
|
|
52
|
+
if (axis.grid.enabled) {
|
|
53
|
+
tickItems = new Array(split.plots.length || 1).fill(null).map((_, index) => {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
const top = ((_a = split.plots[index]) === null || _a === void 0 ? void 0 : _a.top) || 0;
|
|
56
|
+
const height = ((_b = split.plots[index]) === null || _b === void 0 ? void 0 : _b.height) || totalHeight;
|
|
57
|
+
return [-top, -(top + height)];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const xAxisGenerator = axisBottom({
|
|
61
|
+
scale: scale,
|
|
62
|
+
ticks: {
|
|
63
|
+
items: tickItems,
|
|
64
|
+
labelFormat: getLabelFormatter({ axis, scale }),
|
|
65
|
+
labelsPaddings: axis.labels.padding,
|
|
66
|
+
labelsMargin: axis.labels.margin,
|
|
67
|
+
labelsStyle: axis.labels.style,
|
|
68
|
+
labelsMaxWidth: axis.labels.maxWidth,
|
|
69
|
+
labelsLineHeight: axis.labels.lineHeight,
|
|
70
|
+
count: getTicksCount({ axis, range: width }),
|
|
71
|
+
maxTickCount: getMaxTickCount({ axis, width }),
|
|
72
|
+
rotation: axis.labels.rotation,
|
|
73
|
+
},
|
|
74
|
+
domain: {
|
|
75
|
+
size: width,
|
|
76
|
+
color: axis.lineColor,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const svgElement = select(ref.current);
|
|
80
|
+
svgElement.selectAll('*').remove();
|
|
81
|
+
svgElement.call(xAxisGenerator).attr('class', b());
|
|
82
|
+
// add an axis header if necessary
|
|
83
|
+
if (axis.title.text) {
|
|
84
|
+
const titleRows = getAxisTitleRows({ axis, textMaxWidth: width });
|
|
85
|
+
svgElement
|
|
86
|
+
.append('text')
|
|
87
|
+
.attr('class', b('title'))
|
|
88
|
+
.attr('transform', () => {
|
|
89
|
+
const { x, y } = getTitlePosition({ axis, width, rowCount: titleRows.length });
|
|
90
|
+
return `translate(${x}, ${y})`;
|
|
91
|
+
})
|
|
92
|
+
.attr('font-size', axis.title.style.fontSize)
|
|
93
|
+
.attr('text-anchor', 'middle')
|
|
94
|
+
.selectAll('tspan')
|
|
95
|
+
.data(titleRows)
|
|
96
|
+
.join('tspan')
|
|
97
|
+
.attr('x', 0)
|
|
98
|
+
.attr('y', (d) => d.y)
|
|
99
|
+
.text((d) => d.text)
|
|
100
|
+
.each((_d, index, nodes) => {
|
|
101
|
+
if (index === axis.title.maxRowCount - 1) {
|
|
102
|
+
handleOverflowingText(nodes[index], width);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}, [axis, width, totalHeight, scale, split]);
|
|
107
|
+
return React.createElement("g", { ref: ref });
|
|
108
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartScale, PreparedAxis, PreparedSplit } from '../../hooks';
|
|
3
|
+
import './styles.css';
|
|
4
|
+
type Props = {
|
|
5
|
+
axes: PreparedAxis[];
|
|
6
|
+
scale: ChartScale[];
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
split: PreparedSplit;
|
|
10
|
+
};
|
|
11
|
+
export declare const AxisY: (props: Props) => React.JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { axisLeft, axisRight, line, select } from 'd3';
|
|
3
|
+
import { block, calculateCos, calculateSin, formatAxisTickLabel, getAxisHeight, getAxisTitleRows, getClosestPointsRange, getScaleTicks, getTicksCount, handleOverflowingText, parseTransformStyle, setEllipsisForOverflowTexts, wrapText, } from '../../utils';
|
|
4
|
+
import './styles.css';
|
|
5
|
+
const b = block('d3-axis');
|
|
6
|
+
function transformLabel(args) {
|
|
7
|
+
const { node, axis } = args;
|
|
8
|
+
let topOffset = axis.labels.lineHeight / 2;
|
|
9
|
+
let leftOffset = axis.labels.margin;
|
|
10
|
+
if (axis.position === 'left') {
|
|
11
|
+
leftOffset = leftOffset * -1;
|
|
12
|
+
}
|
|
13
|
+
if (axis.labels.rotation) {
|
|
14
|
+
if (axis.labels.rotation > 0) {
|
|
15
|
+
leftOffset -= axis.labels.lineHeight * calculateSin(axis.labels.rotation);
|
|
16
|
+
topOffset = axis.labels.lineHeight * calculateCos(axis.labels.rotation);
|
|
17
|
+
if (axis.labels.rotation % 360 === 90) {
|
|
18
|
+
topOffset = ((node === null || node === void 0 ? void 0 : node.getBoundingClientRect().width) || 0) / 2;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
topOffset = 0;
|
|
23
|
+
if (axis.labels.rotation % 360 === -90) {
|
|
24
|
+
topOffset = -((node === null || node === void 0 ? void 0 : node.getBoundingClientRect().width) || 0) / 2;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return `translate(${leftOffset}px, ${topOffset}px) rotate(${axis.labels.rotation}deg)`;
|
|
28
|
+
}
|
|
29
|
+
return `translate(${leftOffset}px, ${topOffset}px)`;
|
|
30
|
+
}
|
|
31
|
+
function getAxisGenerator(args) {
|
|
32
|
+
const { preparedAxis, axisGenerator: generator, width, height, scale } = args;
|
|
33
|
+
const tickSize = preparedAxis.grid.enabled ? width * -1 : 0;
|
|
34
|
+
const step = getClosestPointsRange(preparedAxis, getScaleTicks(scale));
|
|
35
|
+
let axisGenerator = generator
|
|
36
|
+
.tickSize(tickSize)
|
|
37
|
+
.tickPadding(preparedAxis.labels.margin)
|
|
38
|
+
.tickFormat((value) => {
|
|
39
|
+
if (!preparedAxis.labels.enabled) {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
return formatAxisTickLabel({
|
|
43
|
+
axis: preparedAxis,
|
|
44
|
+
value,
|
|
45
|
+
step,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const ticksCount = getTicksCount({ axis: preparedAxis, range: height });
|
|
49
|
+
if (ticksCount) {
|
|
50
|
+
axisGenerator = axisGenerator.ticks(ticksCount);
|
|
51
|
+
}
|
|
52
|
+
return axisGenerator;
|
|
53
|
+
}
|
|
54
|
+
function getTitlePosition(args) {
|
|
55
|
+
const { axis, axisHeight, rowCount } = args;
|
|
56
|
+
if (rowCount < 1) {
|
|
57
|
+
return { x: 0, y: 0 };
|
|
58
|
+
}
|
|
59
|
+
const x = -(axis.title.height -
|
|
60
|
+
axis.title.height / rowCount +
|
|
61
|
+
axis.title.margin +
|
|
62
|
+
axis.labels.margin +
|
|
63
|
+
axis.labels.width);
|
|
64
|
+
let y;
|
|
65
|
+
switch (axis.title.align) {
|
|
66
|
+
case 'left': {
|
|
67
|
+
y = axisHeight - axis.title.width / 2;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case 'right': {
|
|
71
|
+
y = axis.title.width / 2;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case 'center': {
|
|
75
|
+
y = axisHeight / 2;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { x, y };
|
|
80
|
+
}
|
|
81
|
+
export const AxisY = (props) => {
|
|
82
|
+
const { axes, width, height: totalHeight, scale, split } = props;
|
|
83
|
+
const height = getAxisHeight({ split, boundsHeight: totalHeight });
|
|
84
|
+
const ref = React.useRef(null);
|
|
85
|
+
React.useEffect(() => {
|
|
86
|
+
if (!ref.current) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const svgElement = select(ref.current);
|
|
90
|
+
svgElement.selectAll('*').remove();
|
|
91
|
+
const axisSelection = svgElement
|
|
92
|
+
.selectAll('axis')
|
|
93
|
+
.data(axes)
|
|
94
|
+
.join('g')
|
|
95
|
+
.attr('class', b())
|
|
96
|
+
.style('transform', (d) => {
|
|
97
|
+
var _a;
|
|
98
|
+
const top = ((_a = split.plots[d.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
|
|
99
|
+
if (d.position === 'left') {
|
|
100
|
+
return `translate(0, ${top}px)`;
|
|
101
|
+
}
|
|
102
|
+
return `translate(${width}px, 0)`;
|
|
103
|
+
});
|
|
104
|
+
axisSelection.each((d, index, node) => {
|
|
105
|
+
const seriesScale = scale[index];
|
|
106
|
+
const axisItem = select(node[index]);
|
|
107
|
+
const yAxisGenerator = getAxisGenerator({
|
|
108
|
+
axisGenerator: d.position === 'left'
|
|
109
|
+
? axisLeft(seriesScale)
|
|
110
|
+
: axisRight(seriesScale),
|
|
111
|
+
preparedAxis: d,
|
|
112
|
+
height,
|
|
113
|
+
width,
|
|
114
|
+
scale: seriesScale,
|
|
115
|
+
});
|
|
116
|
+
yAxisGenerator(axisItem);
|
|
117
|
+
if (d.labels.enabled) {
|
|
118
|
+
const tickTexts = axisItem
|
|
119
|
+
.selectAll('.tick text')
|
|
120
|
+
// The offset must be applied before the labels are rotated.
|
|
121
|
+
// Therefore, we reset the values and make an offset in transform attribute.
|
|
122
|
+
// FIXME: give up axisLeft(d3) and switch to our own generation method
|
|
123
|
+
.attr('x', null)
|
|
124
|
+
.attr('dy', null)
|
|
125
|
+
.style('font-size', d.labels.style.fontSize)
|
|
126
|
+
.style('transform', function () {
|
|
127
|
+
return transformLabel({ node: this, axis: d });
|
|
128
|
+
});
|
|
129
|
+
const textMaxWidth = !d.labels.rotation || Math.abs(d.labels.rotation) % 360 !== 90
|
|
130
|
+
? d.labels.maxWidth
|
|
131
|
+
: (height - d.labels.padding * (tickTexts.size() - 1)) / tickTexts.size();
|
|
132
|
+
tickTexts.call(setEllipsisForOverflowTexts, textMaxWidth);
|
|
133
|
+
}
|
|
134
|
+
// remove overlapping ticks
|
|
135
|
+
// Note: this method do not prepared for rotated labels
|
|
136
|
+
if (!d.labels.rotation) {
|
|
137
|
+
let elementY = 0;
|
|
138
|
+
axisItem
|
|
139
|
+
.selectAll('.tick')
|
|
140
|
+
.filter(function (_d, tickIndex) {
|
|
141
|
+
const tickNode = this;
|
|
142
|
+
const r = tickNode.getBoundingClientRect();
|
|
143
|
+
if (r.bottom > elementY && tickIndex !== 0) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
elementY = r.top - d.labels.padding;
|
|
147
|
+
return false;
|
|
148
|
+
})
|
|
149
|
+
.remove();
|
|
150
|
+
}
|
|
151
|
+
return axisItem;
|
|
152
|
+
});
|
|
153
|
+
axisSelection
|
|
154
|
+
.select('.domain')
|
|
155
|
+
.attr('d', () => {
|
|
156
|
+
const points = [
|
|
157
|
+
[0, 0],
|
|
158
|
+
[0, height],
|
|
159
|
+
];
|
|
160
|
+
return line()(points);
|
|
161
|
+
})
|
|
162
|
+
.style('stroke', (d) => d.lineColor || '');
|
|
163
|
+
svgElement.selectAll('.tick').each((_d, index, nodes) => {
|
|
164
|
+
const tickNode = select(nodes[index]);
|
|
165
|
+
if (parseTransformStyle(tickNode.attr('transform')).y === height) {
|
|
166
|
+
// Remove stroke from tick that has the same y coordinate like domain
|
|
167
|
+
tickNode.select('line').style('stroke', 'none');
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
axisSelection
|
|
171
|
+
.append('text')
|
|
172
|
+
.attr('class', b('title'))
|
|
173
|
+
.attr('text-anchor', 'middle')
|
|
174
|
+
.attr('font-size', (d) => d.title.style.fontSize)
|
|
175
|
+
.attr('transform', (d) => {
|
|
176
|
+
const titleRows = wrapText({
|
|
177
|
+
text: d.title.text,
|
|
178
|
+
style: d.title.style,
|
|
179
|
+
width: height,
|
|
180
|
+
});
|
|
181
|
+
const rowCount = Math.min(titleRows.length, d.title.maxRowCount);
|
|
182
|
+
const { x, y } = getTitlePosition({ axis: d, axisHeight: height, rowCount });
|
|
183
|
+
const angle = d.position === 'left' ? -90 : 90;
|
|
184
|
+
return `translate(${x}, ${y}) rotate(${angle})`;
|
|
185
|
+
})
|
|
186
|
+
.selectAll('tspan')
|
|
187
|
+
.data((d) => getAxisTitleRows({ axis: d, textMaxWidth: height }))
|
|
188
|
+
.join('tspan')
|
|
189
|
+
.attr('x', 0)
|
|
190
|
+
.attr('y', (d) => d.y)
|
|
191
|
+
.text((d) => d.text)
|
|
192
|
+
.each((_d, index, nodes) => {
|
|
193
|
+
if (index === nodes.length - 1) {
|
|
194
|
+
handleOverflowingText(nodes[index], height);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}, [axes, width, height, scale, split]);
|
|
198
|
+
return React.createElement("g", { ref: ref, className: b('container') });
|
|
199
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.gcharts-d3-axis .domain {
|
|
2
|
+
stroke: var(--g-color-line-generic-active);
|
|
3
|
+
}
|
|
4
|
+
.gcharts-d3-axis .tick text {
|
|
5
|
+
color: var(--g-color-text-secondary);
|
|
6
|
+
alignment-baseline: after-edge;
|
|
7
|
+
}
|
|
8
|
+
.gcharts-d3-axis .tick line, .gcharts-d3-axis .tick path {
|
|
9
|
+
stroke: var(--g-color-line-generic);
|
|
10
|
+
}
|
|
11
|
+
.gcharts-d3-axis__title {
|
|
12
|
+
alignment-baseline: after-edge;
|
|
13
|
+
fill: var(--g-color-text-secondary);
|
|
14
|
+
}
|
|
15
|
+
.gcharts-d3-axis__title tspan {
|
|
16
|
+
alignment-baseline: after-edge;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartData } from '../../types';
|
|
3
|
+
import './styles.css';
|
|
4
|
+
type Props = {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
data: ChartData;
|
|
8
|
+
};
|
|
9
|
+
export declare const ChartInner: (props: Props) => React.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { pointer } from 'd3';
|
|
3
|
+
import throttle from 'lodash/throttle';
|
|
4
|
+
import { useAxisScales, useChartDimensions, useChartOptions, useSeries, useShapes, } from '../../hooks';
|
|
5
|
+
import { getYAxisWidth } from '../../hooks/useChartDimensions/utils';
|
|
6
|
+
import { getPreparedXAxis } from '../../hooks/useChartOptions/x-axis';
|
|
7
|
+
import { getPreparedYAxis } from '../../hooks/useChartOptions/y-axis';
|
|
8
|
+
import { useSplit } from '../../hooks/useSplit';
|
|
9
|
+
import { block, getD3Dispatcher } from '../../utils';
|
|
10
|
+
import { getClosestPoints } from '../../utils/chart/get-closest-data';
|
|
11
|
+
import { AxisX, AxisY } from '../Axis';
|
|
12
|
+
import { Legend } from '../Legend';
|
|
13
|
+
import { PlotTitle } from '../PlotTitle';
|
|
14
|
+
import { Title } from '../Title';
|
|
15
|
+
import { Tooltip } from '../Tooltip';
|
|
16
|
+
import './styles.css';
|
|
17
|
+
const b = block('d3');
|
|
18
|
+
const THROTTLE_DELAY = 50;
|
|
19
|
+
export const ChartInner = (props) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const { width, height, data } = props;
|
|
22
|
+
const svgRef = React.useRef(null);
|
|
23
|
+
const htmlLayerRef = React.useRef(null);
|
|
24
|
+
const dispatcher = React.useMemo(() => {
|
|
25
|
+
return getD3Dispatcher();
|
|
26
|
+
}, []);
|
|
27
|
+
const { chart, title, tooltip } = useChartOptions({
|
|
28
|
+
data,
|
|
29
|
+
});
|
|
30
|
+
const xAxis = React.useMemo(() => getPreparedXAxis({ xAxis: data.xAxis, width, series: data.series.data }), [data, width]);
|
|
31
|
+
const yAxis = React.useMemo(() => getPreparedYAxis({
|
|
32
|
+
series: data.series.data,
|
|
33
|
+
yAxis: data.yAxis,
|
|
34
|
+
height,
|
|
35
|
+
}), [data, height]);
|
|
36
|
+
const { legendItems, legendConfig, preparedSeries, preparedSeriesOptions, preparedLegend, handleLegendItemClick, } = useSeries({
|
|
37
|
+
chartWidth: width,
|
|
38
|
+
chartHeight: height,
|
|
39
|
+
chartMargin: chart.margin,
|
|
40
|
+
series: data.series,
|
|
41
|
+
legend: data.legend,
|
|
42
|
+
preparedYAxis: yAxis,
|
|
43
|
+
});
|
|
44
|
+
const { boundsWidth, boundsHeight } = useChartDimensions({
|
|
45
|
+
width,
|
|
46
|
+
height,
|
|
47
|
+
margin: chart.margin,
|
|
48
|
+
preparedLegend,
|
|
49
|
+
preparedXAxis: xAxis,
|
|
50
|
+
preparedYAxis: yAxis,
|
|
51
|
+
preparedSeries: preparedSeries,
|
|
52
|
+
});
|
|
53
|
+
const preparedSplit = useSplit({ split: data.split, boundsHeight, chartWidth: width });
|
|
54
|
+
const { xScale, yScale } = useAxisScales({
|
|
55
|
+
boundsWidth,
|
|
56
|
+
boundsHeight,
|
|
57
|
+
series: preparedSeries,
|
|
58
|
+
xAxis,
|
|
59
|
+
yAxis,
|
|
60
|
+
split: preparedSplit,
|
|
61
|
+
});
|
|
62
|
+
const { shapes, shapesData } = useShapes({
|
|
63
|
+
boundsWidth,
|
|
64
|
+
boundsHeight,
|
|
65
|
+
dispatcher,
|
|
66
|
+
series: preparedSeries,
|
|
67
|
+
seriesOptions: preparedSeriesOptions,
|
|
68
|
+
xAxis,
|
|
69
|
+
xScale,
|
|
70
|
+
yAxis,
|
|
71
|
+
yScale,
|
|
72
|
+
split: preparedSplit,
|
|
73
|
+
htmlLayout: htmlLayerRef.current,
|
|
74
|
+
});
|
|
75
|
+
const clickHandler = (_b = (_a = data.chart) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.click;
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
if (clickHandler) {
|
|
78
|
+
dispatcher.on('click-chart', clickHandler);
|
|
79
|
+
}
|
|
80
|
+
return () => {
|
|
81
|
+
dispatcher.on('click-chart', null);
|
|
82
|
+
};
|
|
83
|
+
}, [dispatcher, clickHandler]);
|
|
84
|
+
const boundsOffsetTop = chart.margin.top;
|
|
85
|
+
// We only need to consider the width of the first left axis
|
|
86
|
+
const boundsOffsetLeft = chart.margin.left + getYAxisWidth(yAxis[0]);
|
|
87
|
+
const isOutsideBounds = React.useCallback((x, y) => {
|
|
88
|
+
return x < 0 || x > boundsWidth || y < 0 || y > boundsHeight;
|
|
89
|
+
}, [boundsHeight, boundsWidth]);
|
|
90
|
+
const handleMouseMove = (event) => {
|
|
91
|
+
const [pointerX, pointerY] = pointer(event, svgRef.current);
|
|
92
|
+
const x = pointerX - boundsOffsetLeft;
|
|
93
|
+
const y = pointerY - boundsOffsetTop;
|
|
94
|
+
if (isOutsideBounds(x, y)) {
|
|
95
|
+
dispatcher.call('hover-shape', {}, undefined);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const closest = getClosestPoints({
|
|
99
|
+
position: [x, y],
|
|
100
|
+
shapesData,
|
|
101
|
+
});
|
|
102
|
+
dispatcher.call('hover-shape', event.target, closest, [pointerX, pointerY]);
|
|
103
|
+
};
|
|
104
|
+
const throttledHandleMouseMove = throttle(handleMouseMove, THROTTLE_DELAY);
|
|
105
|
+
const handleMouseLeave = () => {
|
|
106
|
+
throttledHandleMouseMove.cancel();
|
|
107
|
+
dispatcher.call('hover-shape', {}, undefined);
|
|
108
|
+
};
|
|
109
|
+
const handleChartClick = React.useCallback((event) => {
|
|
110
|
+
const [pointerX, pointerY] = pointer(event, svgRef.current);
|
|
111
|
+
const x = pointerX - boundsOffsetLeft;
|
|
112
|
+
const y = pointerY - boundsOffsetTop;
|
|
113
|
+
if (isOutsideBounds(x, y)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const items = getClosestPoints({
|
|
117
|
+
position: [x, y],
|
|
118
|
+
shapesData,
|
|
119
|
+
});
|
|
120
|
+
const selected = items === null || items === void 0 ? void 0 : items.find((item) => item.closest);
|
|
121
|
+
if (!selected) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
dispatcher.call('click-chart', undefined, { point: selected.data, series: selected.series }, event);
|
|
125
|
+
}, [boundsOffsetLeft, boundsOffsetTop, dispatcher, isOutsideBounds, shapesData]);
|
|
126
|
+
return (React.createElement(React.Fragment, null,
|
|
127
|
+
React.createElement("svg", { ref: svgRef, className: b(), width: width, height: height, onMouseMove: throttledHandleMouseMove, onMouseLeave: handleMouseLeave, onClick: handleChartClick },
|
|
128
|
+
title && React.createElement(Title, Object.assign({}, title, { chartWidth: width })),
|
|
129
|
+
React.createElement("g", { transform: `translate(0, ${boundsOffsetTop})` }, preparedSplit.plots.map((plot, index) => {
|
|
130
|
+
return React.createElement(PlotTitle, { key: `plot-${index}`, title: plot.title });
|
|
131
|
+
})),
|
|
132
|
+
React.createElement("g", { width: boundsWidth, height: boundsHeight, transform: `translate(${[boundsOffsetLeft, boundsOffsetTop].join(',')})` },
|
|
133
|
+
xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length) && (React.createElement(React.Fragment, null,
|
|
134
|
+
React.createElement(AxisY, { axes: yAxis, width: boundsWidth, height: boundsHeight, scale: yScale, split: preparedSplit }),
|
|
135
|
+
React.createElement("g", { transform: `translate(0, ${boundsHeight})` },
|
|
136
|
+
React.createElement(AxisX, { axis: xAxis, width: boundsWidth, height: boundsHeight, scale: xScale, split: preparedSplit })))),
|
|
137
|
+
shapes),
|
|
138
|
+
preparedLegend.enabled && (React.createElement(Legend, { chartSeries: preparedSeries, boundsWidth: boundsWidth, legend: preparedLegend, items: legendItems, config: legendConfig, onItemClick: handleLegendItemClick }))),
|
|
139
|
+
React.createElement("div", { className: b('html-layer'), ref: htmlLayerRef, style: {
|
|
140
|
+
transform: `translate(${boundsOffsetLeft}px, ${boundsOffsetTop}px)`,
|
|
141
|
+
} }),
|
|
142
|
+
React.createElement(Tooltip, { dispatcher: dispatcher, tooltip: tooltip, svgContainer: svgRef.current, xAxis: xAxis, yAxis: yAxis[0] })));
|
|
143
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { LegendConfig, LegendItem, OnLegendItemClick, PreparedLegend, PreparedSeries } from '../../hooks';
|
|
3
|
+
import './styles.css';
|
|
4
|
+
type Props = {
|
|
5
|
+
boundsWidth: number;
|
|
6
|
+
chartSeries: PreparedSeries[];
|
|
7
|
+
legend: PreparedLegend;
|
|
8
|
+
items: LegendItem[][];
|
|
9
|
+
config: LegendConfig;
|
|
10
|
+
onItemClick: OnLegendItemClick;
|
|
11
|
+
};
|
|
12
|
+
export declare const Legend: (props: Props) => React.JSX.Element;
|
|
13
|
+
export {};
|