@mui/x-charts 6.0.0-alpha.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/BarChart/BarChart.d.ts +19 -0
- package/BarChart/BarChart.js +262 -0
- package/BarChart/BarElement.d.ts +21 -0
- package/BarChart/BarElement.js +92 -0
- package/BarChart/BarPlot.d.ts +2 -0
- package/BarChart/BarPlot.js +76 -0
- package/BarChart/extremums.d.ts +3 -0
- package/BarChart/extremums.js +27 -0
- package/BarChart/formatter.d.ts +3 -0
- package/BarChart/formatter.js +54 -0
- package/BarChart/index.d.ts +2 -0
- package/BarChart/index.js +19 -0
- package/BarChart/package.json +6 -0
- package/CHANGELOG.md +3211 -0
- package/ChartContainer/index.d.ts +9 -0
- package/ChartContainer/index.js +61 -0
- package/ChartContainer/package.json +6 -0
- package/ChartsAxis/ChartsAxis.d.ts +33 -0
- package/ChartsAxis/ChartsAxis.js +152 -0
- package/ChartsAxis/axisClasses.d.ts +29 -0
- package/ChartsAxis/axisClasses.js +13 -0
- package/ChartsAxis/index.d.ts +2 -0
- package/ChartsAxis/index.js +27 -0
- package/ChartsAxis/package.json +6 -0
- package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +10 -0
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +67 -0
- package/ChartsAxisHighlight/index.d.ts +1 -0
- package/ChartsAxisHighlight/index.js +16 -0
- package/ChartsAxisHighlight/package.json +6 -0
- package/ChartsClipPath/ChartsClipPath.d.ts +15 -0
- package/ChartsClipPath/ChartsClipPath.js +54 -0
- package/ChartsClipPath/index.d.ts +1 -0
- package/ChartsClipPath/index.js +16 -0
- package/ChartsClipPath/package.json +6 -0
- package/ChartsLegend/ChartsLegend.d.ts +44 -0
- package/ChartsLegend/ChartsLegend.js +202 -0
- package/ChartsLegend/chartsLegendClasses.d.ts +17 -0
- package/ChartsLegend/chartsLegendClasses.js +13 -0
- package/ChartsLegend/index.d.ts +2 -0
- package/ChartsLegend/index.js +27 -0
- package/ChartsLegend/package.json +6 -0
- package/ChartsLegend/utils.d.ts +14 -0
- package/ChartsLegend/utils.js +9 -0
- package/ChartsSurface.d.ts +21 -0
- package/ChartsSurface.js +58 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +40 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.js +116 -0
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +27 -0
- package/ChartsTooltip/ChartsItemTooltipContent.js +70 -0
- package/ChartsTooltip/ChartsTooltip.d.ts +32 -0
- package/ChartsTooltip/ChartsTooltip.js +104 -0
- package/ChartsTooltip/ChartsTooltipTable.d.ts +26 -0
- package/ChartsTooltip/ChartsTooltipTable.js +81 -0
- package/ChartsTooltip/index.d.ts +1 -0
- package/ChartsTooltip/index.js +16 -0
- package/ChartsTooltip/package.json +6 -0
- package/ChartsTooltip/tooltipClasses.d.ts +13 -0
- package/ChartsTooltip/tooltipClasses.js +13 -0
- package/ChartsTooltip/utils.d.ts +24 -0
- package/ChartsTooltip/utils.js +91 -0
- package/ChartsXAxis/ChartsXAxis.d.ts +7 -0
- package/ChartsXAxis/ChartsXAxis.js +191 -0
- package/ChartsXAxis/index.d.ts +1 -0
- package/ChartsXAxis/index.js +16 -0
- package/ChartsXAxis/package.json +6 -0
- package/ChartsYAxis/ChartsYAxis.d.ts +7 -0
- package/ChartsYAxis/ChartsYAxis.js +192 -0
- package/ChartsYAxis/index.d.ts +1 -0
- package/ChartsYAxis/index.js +16 -0
- package/ChartsYAxis/package.json +6 -0
- package/LICENSE +21 -0
- package/LineChart/AreaElement.d.ts +28 -0
- package/LineChart/AreaElement.js +115 -0
- package/LineChart/AreaPlot.d.ts +2 -0
- package/LineChart/AreaPlot.js +67 -0
- package/LineChart/LineChart.d.ts +19 -0
- package/LineChart/LineChart.js +266 -0
- package/LineChart/LineElement.d.ts +28 -0
- package/LineChart/LineElement.js +117 -0
- package/LineChart/LinePlot.d.ts +2 -0
- package/LineChart/LinePlot.js +67 -0
- package/LineChart/MarkElement.d.ts +38 -0
- package/LineChart/MarkElement.js +140 -0
- package/LineChart/MarkPlot.d.ts +2 -0
- package/LineChart/MarkPlot.js +86 -0
- package/LineChart/extremums.d.ts +3 -0
- package/LineChart/extremums.js +36 -0
- package/LineChart/formatter.d.ts +3 -0
- package/LineChart/formatter.js +55 -0
- package/LineChart/index.d.ts +7 -0
- package/LineChart/index.js +75 -0
- package/LineChart/package.json +6 -0
- package/README.md +5 -0
- package/ResponsiveChartContainer/index.d.ts +5 -0
- package/ResponsiveChartContainer/index.js +54 -0
- package/ResponsiveChartContainer/package.json +6 -0
- package/ScatterChart/Scatter.d.ts +15 -0
- package/ScatterChart/Scatter.js +114 -0
- package/ScatterChart/ScatterChart.d.ts +19 -0
- package/ScatterChart/ScatterChart.js +252 -0
- package/ScatterChart/ScatterPlot.d.ts +2 -0
- package/ScatterChart/ScatterPlot.js +52 -0
- package/ScatterChart/extremums.d.ts +3 -0
- package/ScatterChart/extremums.js +49 -0
- package/ScatterChart/formatter.d.ts +3 -0
- package/ScatterChart/formatter.js +19 -0
- package/ScatterChart/index.d.ts +3 -0
- package/ScatterChart/index.js +26 -0
- package/ScatterChart/package.json +6 -0
- package/colorPalettes/colorPalettes.d.ts +11 -0
- package/colorPalettes/colorPalettes.js +24 -0
- package/colorPalettes/index.d.ts +1 -0
- package/colorPalettes/index.js +16 -0
- package/colorPalettes/package.json +6 -0
- package/constants.d.ts +8 -0
- package/constants.js +17 -0
- package/context/CartesianContextProvider.d.ts +30 -0
- package/context/CartesianContextProvider.js +227 -0
- package/context/DrawingProvider.d.ts +22 -0
- package/context/DrawingProvider.js +64 -0
- package/context/HighlightProvider.d.ts +28 -0
- package/context/HighlightProvider.js +57 -0
- package/context/InteractionProvider.d.ts +34 -0
- package/context/InteractionProvider.js +62 -0
- package/context/SeriesContextProvider.d.ts +17 -0
- package/context/SeriesContextProvider.js +69 -0
- package/context/index.d.ts +3 -0
- package/context/index.js +19 -0
- package/context/package.json +6 -0
- package/esm/BarChart/BarChart.js +255 -0
- package/esm/BarChart/BarElement.js +80 -0
- package/esm/BarChart/BarPlot.js +70 -0
- package/esm/BarChart/extremums.js +20 -0
- package/esm/BarChart/formatter.js +46 -0
- package/esm/BarChart/index.js +2 -0
- package/esm/ChartContainer/index.js +53 -0
- package/esm/ChartsAxis/ChartsAxis.js +145 -0
- package/esm/ChartsAxis/axisClasses.js +5 -0
- package/esm/ChartsAxis/index.js +2 -0
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +60 -0
- package/esm/ChartsAxisHighlight/index.js +1 -0
- package/esm/ChartsClipPath/ChartsClipPath.js +46 -0
- package/esm/ChartsClipPath/index.js +1 -0
- package/esm/ChartsLegend/ChartsLegend.js +189 -0
- package/esm/ChartsLegend/chartsLegendClasses.js +5 -0
- package/esm/ChartsLegend/index.js +2 -0
- package/esm/ChartsLegend/utils.js +3 -0
- package/esm/ChartsSurface.js +49 -0
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +108 -0
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +63 -0
- package/esm/ChartsTooltip/ChartsTooltip.js +96 -0
- package/esm/ChartsTooltip/ChartsTooltipTable.js +69 -0
- package/esm/ChartsTooltip/index.js +1 -0
- package/esm/ChartsTooltip/tooltipClasses.js +5 -0
- package/esm/ChartsTooltip/utils.js +81 -0
- package/esm/ChartsXAxis/ChartsXAxis.js +184 -0
- package/esm/ChartsXAxis/index.js +1 -0
- package/esm/ChartsYAxis/ChartsYAxis.js +185 -0
- package/esm/ChartsYAxis/index.js +1 -0
- package/esm/LineChart/AreaElement.js +104 -0
- package/esm/LineChart/AreaPlot.js +58 -0
- package/esm/LineChart/LineChart.js +259 -0
- package/esm/LineChart/LineElement.js +106 -0
- package/esm/LineChart/LinePlot.js +58 -0
- package/esm/LineChart/MarkElement.js +130 -0
- package/esm/LineChart/MarkPlot.js +78 -0
- package/esm/LineChart/extremums.js +29 -0
- package/esm/LineChart/formatter.js +48 -0
- package/esm/LineChart/index.js +7 -0
- package/esm/ResponsiveChartContainer/index.js +46 -0
- package/esm/ScatterChart/Scatter.js +106 -0
- package/esm/ScatterChart/ScatterChart.js +245 -0
- package/esm/ScatterChart/ScatterPlot.js +44 -0
- package/esm/ScatterChart/extremums.js +41 -0
- package/esm/ScatterChart/formatter.js +11 -0
- package/esm/ScatterChart/index.js +3 -0
- package/esm/colorPalettes/colorPalettes.js +9 -0
- package/esm/colorPalettes/index.js +1 -0
- package/esm/constants.js +8 -0
- package/esm/context/CartesianContextProvider.js +221 -0
- package/esm/context/DrawingProvider.js +52 -0
- package/esm/context/HighlightProvider.js +46 -0
- package/esm/context/InteractionProvider.js +51 -0
- package/esm/context/SeriesContextProvider.js +60 -0
- package/esm/context/index.js +2 -0
- package/esm/hooks/useAxisEvents.js +145 -0
- package/esm/hooks/useChartDimensions.js +14 -0
- package/esm/hooks/useInteractionItemProps.js +68 -0
- package/esm/hooks/useScale.js +33 -0
- package/esm/hooks/useTicks.js +46 -0
- package/esm/index.js +15 -0
- package/esm/internals/components/AxisSharedComponents.js +81 -0
- package/esm/internals/defaultizeColor.js +7 -0
- package/esm/internals/defaultizeValueFormatter.js +11 -0
- package/esm/internals/getCurve.js +39 -0
- package/esm/internals/stackSeries.js +93 -0
- package/esm/internals/utils.js +5 -0
- package/esm/models/axis.js +1 -0
- package/esm/models/helpers.js +1 -0
- package/esm/models/index.js +1 -0
- package/esm/models/layout.js +1 -0
- package/esm/models/seriesType/bar.js +1 -0
- package/esm/models/seriesType/common.js +1 -0
- package/esm/models/seriesType/config.js +1 -0
- package/esm/models/seriesType/index.js +12 -0
- package/esm/models/seriesType/line.js +1 -0
- package/esm/models/seriesType/pie.js +1 -0
- package/esm/models/seriesType/scatter.js +1 -0
- package/esm/themeAugmentation/index.js +3 -0
- package/hooks/useAxisEvents.d.ts +1 -0
- package/hooks/useAxisEvents.js +154 -0
- package/hooks/useChartDimensions.d.ts +8 -0
- package/hooks/useChartDimensions.js +24 -0
- package/hooks/useInteractionItemProps.d.ts +8 -0
- package/hooks/useInteractionItemProps.js +79 -0
- package/hooks/useScale.d.ts +13 -0
- package/hooks/useScale.js +41 -0
- package/hooks/useTicks.d.ts +23 -0
- package/hooks/useTicks.js +50 -0
- package/index.d.ts +15 -0
- package/index.js +177 -0
- package/internals/components/AxisSharedComponents.d.ts +6 -0
- package/internals/components/AxisSharedComponents.js +93 -0
- package/internals/defaultizeColor.d.ts +41 -0
- package/internals/defaultizeColor.js +14 -0
- package/internals/defaultizeValueFormatter.d.ts +8 -0
- package/internals/defaultizeValueFormatter.js +19 -0
- package/internals/getCurve.d.ts +2 -0
- package/internals/getCurve.js +45 -0
- package/internals/stackSeries.d.ts +29 -0
- package/internals/stackSeries.js +102 -0
- package/internals/utils.d.ts +2 -0
- package/internals/utils.js +11 -0
- package/legacy/BarChart/BarChart.js +260 -0
- package/legacy/BarChart/BarElement.js +78 -0
- package/legacy/BarChart/BarPlot.js +65 -0
- package/legacy/BarChart/extremums.js +25 -0
- package/legacy/BarChart/formatter.js +49 -0
- package/legacy/BarChart/index.js +2 -0
- package/legacy/ChartContainer/index.js +51 -0
- package/legacy/ChartsAxis/ChartsAxis.js +143 -0
- package/legacy/ChartsAxis/axisClasses.js +5 -0
- package/legacy/ChartsAxis/index.js +2 -0
- package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +56 -0
- package/legacy/ChartsAxisHighlight/index.js +1 -0
- package/legacy/ChartsClipPath/ChartsClipPath.js +43 -0
- package/legacy/ChartsClipPath/index.js +1 -0
- package/legacy/ChartsLegend/ChartsLegend.js +186 -0
- package/legacy/ChartsLegend/chartsLegendClasses.js +5 -0
- package/legacy/ChartsLegend/index.js +2 -0
- package/legacy/ChartsLegend/utils.js +9 -0
- package/legacy/ChartsSurface.js +52 -0
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +106 -0
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +59 -0
- package/legacy/ChartsTooltip/ChartsTooltip.js +92 -0
- package/legacy/ChartsTooltip/ChartsTooltipTable.js +73 -0
- package/legacy/ChartsTooltip/index.js +1 -0
- package/legacy/ChartsTooltip/tooltipClasses.js +5 -0
- package/legacy/ChartsTooltip/utils.js +91 -0
- package/legacy/ChartsXAxis/ChartsXAxis.js +172 -0
- package/legacy/ChartsXAxis/index.js +1 -0
- package/legacy/ChartsYAxis/ChartsYAxis.js +173 -0
- package/legacy/ChartsYAxis/index.js +1 -0
- package/legacy/LineChart/AreaElement.js +102 -0
- package/legacy/LineChart/AreaPlot.js +62 -0
- package/legacy/LineChart/LineChart.js +265 -0
- package/legacy/LineChart/LineElement.js +104 -0
- package/legacy/LineChart/LinePlot.js +60 -0
- package/legacy/LineChart/MarkElement.js +128 -0
- package/legacy/LineChart/MarkPlot.js +75 -0
- package/legacy/LineChart/extremums.js +39 -0
- package/legacy/LineChart/formatter.js +51 -0
- package/legacy/LineChart/index.js +7 -0
- package/legacy/ResponsiveChartContainer/index.js +59 -0
- package/legacy/ScatterChart/Scatter.js +103 -0
- package/legacy/ScatterChart/ScatterChart.js +245 -0
- package/legacy/ScatterChart/ScatterPlot.js +39 -0
- package/legacy/ScatterChart/extremums.js +39 -0
- package/legacy/ScatterChart/formatter.js +12 -0
- package/legacy/ScatterChart/index.js +3 -0
- package/legacy/colorPalettes/colorPalettes.js +15 -0
- package/legacy/colorPalettes/index.js +1 -0
- package/legacy/constants.js +8 -0
- package/legacy/context/CartesianContextProvider.js +241 -0
- package/legacy/context/DrawingProvider.js +51 -0
- package/legacy/context/HighlightProvider.js +55 -0
- package/legacy/context/InteractionProvider.js +60 -0
- package/legacy/context/SeriesContextProvider.js +61 -0
- package/legacy/context/index.js +2 -0
- package/legacy/hooks/useAxisEvents.js +140 -0
- package/legacy/hooks/useChartDimensions.js +16 -0
- package/legacy/hooks/useInteractionItemProps.js +66 -0
- package/legacy/hooks/useScale.js +37 -0
- package/legacy/hooks/useTicks.js +46 -0
- package/legacy/index.js +22 -0
- package/legacy/internals/components/AxisSharedComponents.js +80 -0
- package/legacy/internals/defaultizeColor.js +8 -0
- package/legacy/internals/defaultizeValueFormatter.js +11 -0
- package/legacy/internals/getCurve.js +39 -0
- package/legacy/internals/stackSeries.js +90 -0
- package/legacy/internals/utils.js +5 -0
- package/legacy/models/axis.js +1 -0
- package/legacy/models/helpers.js +1 -0
- package/legacy/models/index.js +1 -0
- package/legacy/models/layout.js +1 -0
- package/legacy/models/seriesType/bar.js +1 -0
- package/legacy/models/seriesType/common.js +1 -0
- package/legacy/models/seriesType/config.js +1 -0
- package/legacy/models/seriesType/index.js +12 -0
- package/legacy/models/seriesType/line.js +1 -0
- package/legacy/models/seriesType/pie.js +1 -0
- package/legacy/models/seriesType/scatter.js +1 -0
- package/legacy/themeAugmentation/index.js +3 -0
- package/models/axis.d.ts +118 -0
- package/models/axis.js +5 -0
- package/models/helpers.d.ts +2 -0
- package/models/helpers.js +5 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +16 -0
- package/models/layout.d.ts +10 -0
- package/models/layout.js +5 -0
- package/models/package.json +6 -0
- package/models/seriesType/bar.d.ts +18 -0
- package/models/seriesType/bar.js +5 -0
- package/models/seriesType/common.d.ts +26 -0
- package/models/seriesType/common.js +5 -0
- package/models/seriesType/config.d.ts +66 -0
- package/models/seriesType/config.js +5 -0
- package/models/seriesType/index.d.ts +13 -0
- package/models/seriesType/index.js +38 -0
- package/models/seriesType/line.d.ts +25 -0
- package/models/seriesType/line.js +5 -0
- package/models/seriesType/pie.d.ts +5 -0
- package/models/seriesType/pie.js +5 -0
- package/models/seriesType/scatter.d.ts +24 -0
- package/models/seriesType/scatter.js +5 -0
- package/modern/BarChart/BarChart.js +255 -0
- package/modern/BarChart/BarElement.js +80 -0
- package/modern/BarChart/BarPlot.js +68 -0
- package/modern/BarChart/extremums.js +19 -0
- package/modern/BarChart/formatter.js +46 -0
- package/modern/BarChart/index.js +2 -0
- package/modern/ChartContainer/index.js +53 -0
- package/modern/ChartsAxis/ChartsAxis.js +145 -0
- package/modern/ChartsAxis/axisClasses.js +5 -0
- package/modern/ChartsAxis/index.js +2 -0
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +60 -0
- package/modern/ChartsAxisHighlight/index.js +1 -0
- package/modern/ChartsClipPath/ChartsClipPath.js +46 -0
- package/modern/ChartsClipPath/index.js +1 -0
- package/modern/ChartsLegend/ChartsLegend.js +189 -0
- package/modern/ChartsLegend/chartsLegendClasses.js +5 -0
- package/modern/ChartsLegend/index.js +2 -0
- package/modern/ChartsLegend/utils.js +3 -0
- package/modern/ChartsSurface.js +49 -0
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +107 -0
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +62 -0
- package/modern/ChartsTooltip/ChartsTooltip.js +96 -0
- package/modern/ChartsTooltip/ChartsTooltipTable.js +69 -0
- package/modern/ChartsTooltip/index.js +1 -0
- package/modern/ChartsTooltip/tooltipClasses.js +5 -0
- package/modern/ChartsTooltip/utils.js +81 -0
- package/modern/ChartsXAxis/ChartsXAxis.js +184 -0
- package/modern/ChartsXAxis/index.js +1 -0
- package/modern/ChartsYAxis/ChartsYAxis.js +185 -0
- package/modern/ChartsYAxis/index.js +1 -0
- package/modern/LineChart/AreaElement.js +104 -0
- package/modern/LineChart/AreaPlot.js +58 -0
- package/modern/LineChart/LineChart.js +259 -0
- package/modern/LineChart/LineElement.js +106 -0
- package/modern/LineChart/LinePlot.js +58 -0
- package/modern/LineChart/MarkElement.js +129 -0
- package/modern/LineChart/MarkPlot.js +78 -0
- package/modern/LineChart/extremums.js +28 -0
- package/modern/LineChart/formatter.js +48 -0
- package/modern/LineChart/index.js +7 -0
- package/modern/ResponsiveChartContainer/index.js +45 -0
- package/modern/ScatterChart/Scatter.js +106 -0
- package/modern/ScatterChart/ScatterChart.js +245 -0
- package/modern/ScatterChart/ScatterPlot.js +44 -0
- package/modern/ScatterChart/extremums.js +41 -0
- package/modern/ScatterChart/formatter.js +11 -0
- package/modern/ScatterChart/index.js +3 -0
- package/modern/colorPalettes/colorPalettes.js +9 -0
- package/modern/colorPalettes/index.js +1 -0
- package/modern/constants.js +8 -0
- package/modern/context/CartesianContextProvider.js +217 -0
- package/modern/context/DrawingProvider.js +52 -0
- package/modern/context/HighlightProvider.js +46 -0
- package/modern/context/InteractionProvider.js +51 -0
- package/modern/context/SeriesContextProvider.js +58 -0
- package/modern/context/index.js +2 -0
- package/modern/hooks/useAxisEvents.js +145 -0
- package/modern/hooks/useChartDimensions.js +14 -0
- package/modern/hooks/useInteractionItemProps.js +68 -0
- package/modern/hooks/useScale.js +33 -0
- package/modern/hooks/useTicks.js +40 -0
- package/modern/index.js +22 -0
- package/modern/internals/components/AxisSharedComponents.js +81 -0
- package/modern/internals/defaultizeColor.js +7 -0
- package/modern/internals/defaultizeValueFormatter.js +11 -0
- package/modern/internals/getCurve.js +39 -0
- package/modern/internals/stackSeries.js +93 -0
- package/modern/internals/utils.js +5 -0
- package/modern/models/axis.js +1 -0
- package/modern/models/helpers.js +1 -0
- package/modern/models/index.js +1 -0
- package/modern/models/layout.js +1 -0
- package/modern/models/seriesType/bar.js +1 -0
- package/modern/models/seriesType/common.js +1 -0
- package/modern/models/seriesType/config.js +1 -0
- package/modern/models/seriesType/index.js +12 -0
- package/modern/models/seriesType/line.js +1 -0
- package/modern/models/seriesType/pie.js +1 -0
- package/modern/models/seriesType/scatter.js +1 -0
- package/modern/themeAugmentation/index.js +3 -0
- package/package.json +57 -0
- package/themeAugmentation/components.d.ts +72 -0
- package/themeAugmentation/index.d.ts +3 -0
- package/themeAugmentation/index.js +38 -0
- package/themeAugmentation/overrides.d.ts +29 -0
- package/themeAugmentation/package.json +6 -0
- package/themeAugmentation/props.d.ts +43 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { scaleBand, scalePoint } from 'd3-scale';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { getExtremumX as getBarExtremumX, getExtremumY as getBarExtremumY } from '../BarChart/extremums';
|
|
6
|
+
import { getExtremumX as getScatterExtremumX, getExtremumY as getScatterExtremumY } from '../ScatterChart/extremums';
|
|
7
|
+
import { getExtremumX as getLineExtremumX, getExtremumY as getLineExtremumY } from '../LineChart/extremums';
|
|
8
|
+
import { getScale } from '../hooks/useScale';
|
|
9
|
+
import { DrawingContext } from './DrawingProvider';
|
|
10
|
+
import { SeriesContext } from './SeriesContextProvider';
|
|
11
|
+
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
12
|
+
import { getTicksNumber } from '../hooks/useTicks';
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
// TODO: those might be better placed in a distinct file
|
|
15
|
+
const xExtremumGetters = {
|
|
16
|
+
bar: getBarExtremumX,
|
|
17
|
+
scatter: getScatterExtremumX,
|
|
18
|
+
line: getLineExtremumX
|
|
19
|
+
};
|
|
20
|
+
const yExtremumGetters = {
|
|
21
|
+
bar: getBarExtremumY,
|
|
22
|
+
scatter: getScatterExtremumY,
|
|
23
|
+
line: getLineExtremumY
|
|
24
|
+
};
|
|
25
|
+
export const CartesianContext = /*#__PURE__*/React.createContext({
|
|
26
|
+
xAxis: {},
|
|
27
|
+
yAxis: {},
|
|
28
|
+
xAxisIds: [],
|
|
29
|
+
yAxisIds: []
|
|
30
|
+
});
|
|
31
|
+
function CartesianContextProvider({
|
|
32
|
+
xAxis,
|
|
33
|
+
yAxis,
|
|
34
|
+
children
|
|
35
|
+
}) {
|
|
36
|
+
const formattedSeries = React.useContext(SeriesContext);
|
|
37
|
+
const drawingArea = React.useContext(DrawingContext);
|
|
38
|
+
const value = React.useMemo(() => {
|
|
39
|
+
var _xAxis$map, _yAxis$map;
|
|
40
|
+
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
|
|
41
|
+
var _ref, _formattedSeries$char;
|
|
42
|
+
const getter = getters[chartType];
|
|
43
|
+
const series = (_ref = (_formattedSeries$char = formattedSeries[chartType]) == null ? void 0 : _formattedSeries$char.series) != null ? _ref : {};
|
|
44
|
+
const [minChartTypeData, maxChartTypeData] = getter({
|
|
45
|
+
series,
|
|
46
|
+
axis,
|
|
47
|
+
isDefaultAxis
|
|
48
|
+
});
|
|
49
|
+
const [minData, maxData] = acc;
|
|
50
|
+
if (minData === null || maxData === null) {
|
|
51
|
+
return [minChartTypeData, maxChartTypeData];
|
|
52
|
+
}
|
|
53
|
+
if (minChartTypeData === null || maxChartTypeData === null) {
|
|
54
|
+
return [minData, maxData];
|
|
55
|
+
}
|
|
56
|
+
return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
|
|
57
|
+
};
|
|
58
|
+
const getAxisExtremum = (axis, getters, isDefaultAxis) => {
|
|
59
|
+
const charTypes = Object.keys(getters);
|
|
60
|
+
return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis), [null, null]);
|
|
61
|
+
};
|
|
62
|
+
const allXAxis = [...((_xAxis$map = xAxis == null ? void 0 : xAxis.map((axis, index) => _extends({
|
|
63
|
+
id: `deaultized-x-axis-${index}`
|
|
64
|
+
}, axis))) != null ? _xAxis$map : []),
|
|
65
|
+
// Allows to specify an axis with id=DEFAULT_X_AXIS_KEY
|
|
66
|
+
...(xAxis === undefined || xAxis.findIndex(({
|
|
67
|
+
id
|
|
68
|
+
}) => id === DEFAULT_X_AXIS_KEY) === -1 ? [{
|
|
69
|
+
id: DEFAULT_X_AXIS_KEY,
|
|
70
|
+
scaleType: 'linear'
|
|
71
|
+
}] : [])];
|
|
72
|
+
const completedXAxis = {};
|
|
73
|
+
allXAxis.forEach((axis, axisIndex) => {
|
|
74
|
+
var _axis$scaleType, _axis$min, _axis$max, _axis$min2, _axis$max2;
|
|
75
|
+
const isDefaultAxis = axisIndex === 0;
|
|
76
|
+
const [minData, maxData] = getAxisExtremum(axis, xExtremumGetters, isDefaultAxis);
|
|
77
|
+
const scaleType = (_axis$scaleType = axis.scaleType) != null ? _axis$scaleType : 'linear';
|
|
78
|
+
const range = [drawingArea.left, drawingArea.left + drawingArea.width];
|
|
79
|
+
if (scaleType === 'band') {
|
|
80
|
+
completedXAxis[axis.id] = _extends({}, axis, {
|
|
81
|
+
scaleType,
|
|
82
|
+
scale: scaleBand(axis.data, range),
|
|
83
|
+
ticksNumber: axis.data.length
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (scaleType === 'point') {
|
|
88
|
+
completedXAxis[axis.id] = _extends({}, axis, {
|
|
89
|
+
scaleType,
|
|
90
|
+
scale: scalePoint(axis.data, range),
|
|
91
|
+
ticksNumber: axis.data.length
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const extremums = [(_axis$min = axis.min) != null ? _axis$min : minData, (_axis$max = axis.max) != null ? _axis$max : maxData];
|
|
96
|
+
const ticksNumber = getTicksNumber(_extends({}, axis, {
|
|
97
|
+
range
|
|
98
|
+
}));
|
|
99
|
+
const niceScale = getScale(scaleType, extremums, range).nice(ticksNumber);
|
|
100
|
+
const niceDomain = niceScale.domain();
|
|
101
|
+
const domain = [(_axis$min2 = axis.min) != null ? _axis$min2 : niceDomain[0], (_axis$max2 = axis.max) != null ? _axis$max2 : niceDomain[1]];
|
|
102
|
+
completedXAxis[axis.id] = _extends({}, axis, {
|
|
103
|
+
scaleType,
|
|
104
|
+
scale: niceScale.domain(domain),
|
|
105
|
+
ticksNumber
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
const allYAxis = [...((_yAxis$map = yAxis == null ? void 0 : yAxis.map((axis, index) => _extends({
|
|
109
|
+
id: `deaultized-y-axis-${index}`
|
|
110
|
+
}, axis))) != null ? _yAxis$map : []), ...(yAxis === undefined || yAxis.findIndex(({
|
|
111
|
+
id
|
|
112
|
+
}) => id === DEFAULT_Y_AXIS_KEY) === -1 ? [{
|
|
113
|
+
id: DEFAULT_Y_AXIS_KEY,
|
|
114
|
+
scaleType: 'linear'
|
|
115
|
+
}] : [])];
|
|
116
|
+
const completedYAxis = {};
|
|
117
|
+
allYAxis.forEach((axis, axisIndex) => {
|
|
118
|
+
var _axis$scaleType2, _axis$min3, _axis$max3, _axis$min4, _axis$max4;
|
|
119
|
+
const isDefaultAxis = axisIndex === 0;
|
|
120
|
+
const [minData, maxData] = getAxisExtremum(axis, yExtremumGetters, isDefaultAxis);
|
|
121
|
+
const range = [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
122
|
+
const scaleType = (_axis$scaleType2 = axis.scaleType) != null ? _axis$scaleType2 : 'linear';
|
|
123
|
+
if (scaleType === 'band') {
|
|
124
|
+
completedYAxis[axis.id] = _extends({}, axis, {
|
|
125
|
+
scaleType,
|
|
126
|
+
scale: scaleBand(axis.data, range),
|
|
127
|
+
ticksNumber: axis.data.length
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (scaleType === 'point') {
|
|
132
|
+
completedYAxis[axis.id] = _extends({}, axis, {
|
|
133
|
+
scaleType,
|
|
134
|
+
scale: scalePoint(axis.data, range),
|
|
135
|
+
ticksNumber: axis.data.length
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const extremums = [(_axis$min3 = axis.min) != null ? _axis$min3 : minData, (_axis$max3 = axis.max) != null ? _axis$max3 : maxData];
|
|
140
|
+
const ticksNumber = getTicksNumber(_extends({}, axis, {
|
|
141
|
+
range
|
|
142
|
+
}));
|
|
143
|
+
const niceScale = getScale(scaleType, extremums, range).nice(ticksNumber);
|
|
144
|
+
const niceDomain = niceScale.domain();
|
|
145
|
+
const domain = [(_axis$min4 = axis.min) != null ? _axis$min4 : niceDomain[0], (_axis$max4 = axis.max) != null ? _axis$max4 : niceDomain[1]];
|
|
146
|
+
completedYAxis[axis.id] = _extends({}, axis, {
|
|
147
|
+
scaleType,
|
|
148
|
+
scale: niceScale.domain(domain),
|
|
149
|
+
ticksNumber
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
return {
|
|
153
|
+
xAxis: completedXAxis,
|
|
154
|
+
yAxis: completedYAxis,
|
|
155
|
+
xAxisIds: allXAxis.map(({
|
|
156
|
+
id
|
|
157
|
+
}) => id),
|
|
158
|
+
yAxisIds: allYAxis.map(({
|
|
159
|
+
id
|
|
160
|
+
}) => id)
|
|
161
|
+
};
|
|
162
|
+
}, [drawingArea.height, drawingArea.left, drawingArea.top, drawingArea.width, formattedSeries, xAxis, yAxis]);
|
|
163
|
+
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
return /*#__PURE__*/_jsx(CartesianContext.Provider, {
|
|
166
|
+
value: value,
|
|
167
|
+
children: children
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
171
|
+
// ----------------------------- Warning --------------------------------
|
|
172
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
173
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
174
|
+
// ----------------------------------------------------------------------
|
|
175
|
+
children: PropTypes.node,
|
|
176
|
+
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
177
|
+
axisId: PropTypes.string,
|
|
178
|
+
classes: PropTypes.object,
|
|
179
|
+
data: PropTypes.array,
|
|
180
|
+
disableLine: PropTypes.bool,
|
|
181
|
+
disableTicks: PropTypes.bool,
|
|
182
|
+
fill: PropTypes.string,
|
|
183
|
+
id: PropTypes.string,
|
|
184
|
+
label: PropTypes.string,
|
|
185
|
+
labelFontSize: PropTypes.number,
|
|
186
|
+
max: PropTypes.number,
|
|
187
|
+
maxTicks: PropTypes.number,
|
|
188
|
+
min: PropTypes.number,
|
|
189
|
+
minTicks: PropTypes.number,
|
|
190
|
+
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
191
|
+
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
192
|
+
stroke: PropTypes.string,
|
|
193
|
+
tickFontSize: PropTypes.number,
|
|
194
|
+
tickSize: PropTypes.number,
|
|
195
|
+
tickSpacing: PropTypes.number,
|
|
196
|
+
valueFormatter: PropTypes.func
|
|
197
|
+
})),
|
|
198
|
+
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
199
|
+
axisId: PropTypes.string,
|
|
200
|
+
classes: PropTypes.object,
|
|
201
|
+
data: PropTypes.array,
|
|
202
|
+
disableLine: PropTypes.bool,
|
|
203
|
+
disableTicks: PropTypes.bool,
|
|
204
|
+
fill: PropTypes.string,
|
|
205
|
+
id: PropTypes.string,
|
|
206
|
+
label: PropTypes.string,
|
|
207
|
+
labelFontSize: PropTypes.number,
|
|
208
|
+
max: PropTypes.number,
|
|
209
|
+
maxTicks: PropTypes.number,
|
|
210
|
+
min: PropTypes.number,
|
|
211
|
+
minTicks: PropTypes.number,
|
|
212
|
+
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
213
|
+
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
214
|
+
stroke: PropTypes.string,
|
|
215
|
+
tickFontSize: PropTypes.number,
|
|
216
|
+
tickSize: PropTypes.number,
|
|
217
|
+
tickSpacing: PropTypes.number,
|
|
218
|
+
valueFormatter: PropTypes.func
|
|
219
|
+
}))
|
|
220
|
+
} : void 0;
|
|
221
|
+
export { CartesianContextProvider };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import useChartDimensions from '../hooks/useChartDimensions';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Defines the area in which it is possible to draw the charts
|
|
7
|
+
*/
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
export const DrawingContext = /*#__PURE__*/React.createContext({
|
|
10
|
+
top: 0,
|
|
11
|
+
left: 0,
|
|
12
|
+
height: 300,
|
|
13
|
+
width: 400
|
|
14
|
+
});
|
|
15
|
+
export const SVGContext = /*#__PURE__*/React.createContext({
|
|
16
|
+
current: null
|
|
17
|
+
});
|
|
18
|
+
function DrawingProvider({
|
|
19
|
+
width,
|
|
20
|
+
height,
|
|
21
|
+
margin,
|
|
22
|
+
svgRef,
|
|
23
|
+
children
|
|
24
|
+
}) {
|
|
25
|
+
const drawingArea = useChartDimensions(width, height, margin);
|
|
26
|
+
return /*#__PURE__*/_jsx(SVGContext.Provider, {
|
|
27
|
+
value: svgRef,
|
|
28
|
+
children: /*#__PURE__*/_jsx(DrawingContext.Provider, {
|
|
29
|
+
value: drawingArea,
|
|
30
|
+
children: children
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
process.env.NODE_ENV !== "production" ? DrawingProvider.propTypes = {
|
|
35
|
+
// ----------------------------- Warning --------------------------------
|
|
36
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
37
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
38
|
+
// ----------------------------------------------------------------------
|
|
39
|
+
children: PropTypes.node,
|
|
40
|
+
height: PropTypes.number.isRequired,
|
|
41
|
+
margin: PropTypes.shape({
|
|
42
|
+
bottom: PropTypes.number,
|
|
43
|
+
left: PropTypes.number,
|
|
44
|
+
right: PropTypes.number,
|
|
45
|
+
top: PropTypes.number
|
|
46
|
+
}),
|
|
47
|
+
svgRef: PropTypes.shape({
|
|
48
|
+
current: PropTypes.object
|
|
49
|
+
}).isRequired,
|
|
50
|
+
width: PropTypes.number.isRequired
|
|
51
|
+
} : void 0;
|
|
52
|
+
export { DrawingProvider };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
const defaultScope = {
|
|
5
|
+
highlighted: 'none',
|
|
6
|
+
faded: 'none'
|
|
7
|
+
};
|
|
8
|
+
export const HighlighContext = /*#__PURE__*/React.createContext({
|
|
9
|
+
item: null,
|
|
10
|
+
scope: defaultScope,
|
|
11
|
+
dispatch: () => null
|
|
12
|
+
});
|
|
13
|
+
const dataReducer = (prevState, action) => {
|
|
14
|
+
switch (action.type) {
|
|
15
|
+
case 'enterItem':
|
|
16
|
+
return _extends({}, prevState, {
|
|
17
|
+
item: action.item,
|
|
18
|
+
scope: _extends({}, defaultScope, action.scope)
|
|
19
|
+
});
|
|
20
|
+
case 'leaveItem':
|
|
21
|
+
if (prevState.item === null || Object.keys(action.item).some(key => action.item[key] !== prevState.item[key])) {
|
|
22
|
+
// The item is already something else
|
|
23
|
+
return prevState;
|
|
24
|
+
}
|
|
25
|
+
return _extends({}, prevState, {
|
|
26
|
+
item: null
|
|
27
|
+
});
|
|
28
|
+
default:
|
|
29
|
+
return prevState;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export function HighlightProvider({
|
|
33
|
+
children
|
|
34
|
+
}) {
|
|
35
|
+
const [data, dispatch] = React.useReducer(dataReducer, {
|
|
36
|
+
item: null,
|
|
37
|
+
scope: defaultScope
|
|
38
|
+
});
|
|
39
|
+
const value = React.useMemo(() => _extends({}, data, {
|
|
40
|
+
dispatch
|
|
41
|
+
}), [data]);
|
|
42
|
+
return /*#__PURE__*/_jsx(HighlighContext.Provider, {
|
|
43
|
+
value: value,
|
|
44
|
+
children: children
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export const InteractionContext = /*#__PURE__*/React.createContext({
|
|
5
|
+
item: null,
|
|
6
|
+
axis: {
|
|
7
|
+
x: null,
|
|
8
|
+
y: null
|
|
9
|
+
},
|
|
10
|
+
dispatch: () => null
|
|
11
|
+
});
|
|
12
|
+
const dataReducer = (prevState, action) => {
|
|
13
|
+
switch (action.type) {
|
|
14
|
+
case 'enterItem':
|
|
15
|
+
return _extends({}, prevState, {
|
|
16
|
+
item: action.data
|
|
17
|
+
});
|
|
18
|
+
case 'leaveItem':
|
|
19
|
+
if (prevState.item === null || Object.keys(action.data).some(key => action.data[key] !== prevState.item[key])) {
|
|
20
|
+
// The item is already something else
|
|
21
|
+
return prevState;
|
|
22
|
+
}
|
|
23
|
+
return _extends({}, prevState, {
|
|
24
|
+
item: null
|
|
25
|
+
});
|
|
26
|
+
case 'updateAxis':
|
|
27
|
+
return _extends({}, prevState, {
|
|
28
|
+
axis: action.data
|
|
29
|
+
});
|
|
30
|
+
default:
|
|
31
|
+
return prevState;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export function InteractionProvider({
|
|
35
|
+
children
|
|
36
|
+
}) {
|
|
37
|
+
const [data, dispatch] = React.useReducer(dataReducer, {
|
|
38
|
+
item: null,
|
|
39
|
+
axis: {
|
|
40
|
+
x: null,
|
|
41
|
+
y: null
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const value = React.useMemo(() => _extends({}, data, {
|
|
45
|
+
dispatch
|
|
46
|
+
}), [data]);
|
|
47
|
+
return /*#__PURE__*/_jsx(InteractionContext.Provider, {
|
|
48
|
+
value: value,
|
|
49
|
+
children: children
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useTheme } from '@mui/material/styles';
|
|
4
|
+
import barSeriesFormatter from '../BarChart/formatter';
|
|
5
|
+
import scatterSeriesFormatter from '../ScatterChart/formatter';
|
|
6
|
+
import lineSeriesFormatter from '../LineChart/formatter';
|
|
7
|
+
import { defaultizeColor } from '../internals/defaultizeColor';
|
|
8
|
+
import { blueberryTwilightPalette } from '../colorPalettes';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
export const SeriesContext = /*#__PURE__*/React.createContext({});
|
|
11
|
+
const seriesTypeFormatter = {
|
|
12
|
+
bar: barSeriesFormatter,
|
|
13
|
+
scatter: scatterSeriesFormatter,
|
|
14
|
+
line: lineSeriesFormatter
|
|
15
|
+
};
|
|
16
|
+
const formatSeries = (series, colors) => {
|
|
17
|
+
// Group series by type
|
|
18
|
+
const seriesGroups = {};
|
|
19
|
+
series.forEach((seriesData, seriesIndex) => {
|
|
20
|
+
var _seriesGroups$type;
|
|
21
|
+
const {
|
|
22
|
+
id = `auto-generated-id-${seriesIndex}`,
|
|
23
|
+
type
|
|
24
|
+
} = seriesData;
|
|
25
|
+
if (seriesGroups[type] === undefined) {
|
|
26
|
+
seriesGroups[type] = {
|
|
27
|
+
series: {},
|
|
28
|
+
seriesOrder: []
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (((_seriesGroups$type = seriesGroups[type]) == null ? void 0 : _seriesGroups$type.series[id]) !== undefined) {
|
|
32
|
+
throw new Error(`MUI: series' id "${id}" is not unique`);
|
|
33
|
+
}
|
|
34
|
+
seriesGroups[type].series[id] = _extends({
|
|
35
|
+
id
|
|
36
|
+
}, defaultizeColor(seriesData, seriesIndex, colors));
|
|
37
|
+
seriesGroups[type].seriesOrder.push(id);
|
|
38
|
+
});
|
|
39
|
+
const formattedSeries = {};
|
|
40
|
+
// Apply formater on a type group
|
|
41
|
+
Object.keys(seriesTypeFormatter).forEach(type => {
|
|
42
|
+
if (seriesGroups[type] !== undefined) {
|
|
43
|
+
var _seriesTypeFormatter$, _seriesTypeFormatter$2;
|
|
44
|
+
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type])) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return formattedSeries;
|
|
48
|
+
};
|
|
49
|
+
export function SeriesContextProvider({
|
|
50
|
+
series,
|
|
51
|
+
colors = blueberryTwilightPalette,
|
|
52
|
+
children
|
|
53
|
+
}) {
|
|
54
|
+
const theme = useTheme();
|
|
55
|
+
const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors), [series, colors, theme.palette.mode]);
|
|
56
|
+
return /*#__PURE__*/_jsx(SeriesContext.Provider, {
|
|
57
|
+
value: formattedSeries,
|
|
58
|
+
children: children
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
|
+
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
4
|
+
import { SVGContext, DrawingContext } from '../context/DrawingProvider';
|
|
5
|
+
import { isBandScale } from './useScale';
|
|
6
|
+
export const useAxisEvents = disableAxisListener => {
|
|
7
|
+
const svgRef = React.useContext(SVGContext);
|
|
8
|
+
const {
|
|
9
|
+
width,
|
|
10
|
+
height,
|
|
11
|
+
top,
|
|
12
|
+
left
|
|
13
|
+
} = React.useContext(DrawingContext);
|
|
14
|
+
const {
|
|
15
|
+
xAxis,
|
|
16
|
+
yAxis,
|
|
17
|
+
xAxisIds,
|
|
18
|
+
yAxisIds
|
|
19
|
+
} = React.useContext(CartesianContext);
|
|
20
|
+
const {
|
|
21
|
+
dispatch
|
|
22
|
+
} = React.useContext(InteractionContext);
|
|
23
|
+
const usedXAxis = xAxisIds[0];
|
|
24
|
+
const usedYAxis = yAxisIds[0];
|
|
25
|
+
|
|
26
|
+
// Use a ref to avoid rerendering on every mousemove event.
|
|
27
|
+
const mousePosition = React.useRef({
|
|
28
|
+
x: -1,
|
|
29
|
+
y: -1
|
|
30
|
+
});
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
const element = svgRef.current;
|
|
33
|
+
if (element === null || disableAxisListener) {
|
|
34
|
+
return () => {};
|
|
35
|
+
}
|
|
36
|
+
const getUpdateY = y => {
|
|
37
|
+
if (usedYAxis === null) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const {
|
|
41
|
+
scale: yScale,
|
|
42
|
+
data: yAxisData
|
|
43
|
+
} = yAxis[usedYAxis];
|
|
44
|
+
if (!isBandScale(yScale)) {
|
|
45
|
+
return {
|
|
46
|
+
value: yScale.invert(y)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const dataIndex = Math.floor((y - yScale.range()[0]) / yScale.step());
|
|
50
|
+
if (dataIndex < 0 || dataIndex >= yAxisData.length) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
index: dataIndex,
|
|
55
|
+
value: yAxisData[dataIndex]
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const getUpdateX = x => {
|
|
59
|
+
if (usedXAxis === null) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const {
|
|
63
|
+
scale: xScale,
|
|
64
|
+
data: xAxisData
|
|
65
|
+
} = xAxis[usedXAxis];
|
|
66
|
+
if (!isBandScale(xScale)) {
|
|
67
|
+
const value = xScale.invert(x);
|
|
68
|
+
const closestIndex = xAxisData == null ? void 0 : xAxisData.findIndex((v, index) => {
|
|
69
|
+
if (v > value) {
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
if (index === 0 || Math.abs(value - v) <= Math.abs(value - xAxisData[index - 1])) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (v <= value) {
|
|
76
|
+
if (index === xAxisData.length - 1 ||
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
Math.abs(value - v) < Math.abs(value - xAxisData[index + 1])) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
value: closestIndex !== undefined && closestIndex >= 0 ? xAxisData[closestIndex] : value,
|
|
86
|
+
index: closestIndex
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const dataIndex = xScale.bandwidth() === 0 ? Math.floor((x - xScale.range()[0] + xScale.step() / 2) / xScale.step()) : Math.floor((x - xScale.range()[0]) / xScale.step());
|
|
90
|
+
if (dataIndex < 0 || dataIndex >= xAxisData.length) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
index: dataIndex,
|
|
95
|
+
value: xAxisData[dataIndex]
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const handleMouseOut = () => {
|
|
99
|
+
mousePosition.current = {
|
|
100
|
+
x: -1,
|
|
101
|
+
y: -1
|
|
102
|
+
};
|
|
103
|
+
dispatch({
|
|
104
|
+
type: 'updateAxis',
|
|
105
|
+
data: {
|
|
106
|
+
x: null,
|
|
107
|
+
y: null
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const handleMouseMove = event => {
|
|
112
|
+
mousePosition.current = {
|
|
113
|
+
x: event.offsetX,
|
|
114
|
+
y: event.offsetY
|
|
115
|
+
};
|
|
116
|
+
const outsideX = event.offsetX < left || event.offsetX > left + width;
|
|
117
|
+
const outsideY = event.offsetY < top || event.offsetY > top + height;
|
|
118
|
+
if (outsideX || outsideY) {
|
|
119
|
+
dispatch({
|
|
120
|
+
type: 'updateAxis',
|
|
121
|
+
data: {
|
|
122
|
+
x: null,
|
|
123
|
+
y: null
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const newStateX = getUpdateX(event.offsetX);
|
|
129
|
+
const newStateY = getUpdateY(event.offsetY);
|
|
130
|
+
dispatch({
|
|
131
|
+
type: 'updateAxis',
|
|
132
|
+
data: {
|
|
133
|
+
x: newStateX,
|
|
134
|
+
y: newStateY
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
element.addEventListener('mouseout', handleMouseOut);
|
|
139
|
+
element.addEventListener('mousemove', handleMouseMove);
|
|
140
|
+
return () => {
|
|
141
|
+
element.removeEventListener('mouseout', handleMouseOut);
|
|
142
|
+
element.removeEventListener('mousemove', handleMouseMove);
|
|
143
|
+
};
|
|
144
|
+
}, [svgRef, dispatch, left, width, top, height, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener]);
|
|
145
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { DEFAULT_MARGINS } from '../constants';
|
|
4
|
+
const useChartDimensions = (width, height, margin) => {
|
|
5
|
+
const defaultizedMargin = _extends({}, DEFAULT_MARGINS, margin);
|
|
6
|
+
const drawingArea = React.useMemo(() => ({
|
|
7
|
+
left: defaultizedMargin.left,
|
|
8
|
+
top: defaultizedMargin.top,
|
|
9
|
+
width: Math.max(0, width - defaultizedMargin.left - defaultizedMargin.right),
|
|
10
|
+
height: Math.max(0, height - defaultizedMargin.top - defaultizedMargin.bottom)
|
|
11
|
+
}), [width, height, defaultizedMargin.top, defaultizedMargin.bottom, defaultizedMargin.left, defaultizedMargin.right]);
|
|
12
|
+
return drawingArea;
|
|
13
|
+
};
|
|
14
|
+
export default useChartDimensions;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
|
+
import { HighlighContext } from '../context/HighlightProvider';
|
|
4
|
+
export const useInteractionItemProps = scope => {
|
|
5
|
+
const {
|
|
6
|
+
dispatch: dispatchInteraction
|
|
7
|
+
} = React.useContext(InteractionContext);
|
|
8
|
+
const {
|
|
9
|
+
dispatch: dispatchHighlight
|
|
10
|
+
} = React.useContext(HighlighContext);
|
|
11
|
+
const getInteractionItemProps = data => {
|
|
12
|
+
const onMouseEnter = () => {
|
|
13
|
+
dispatchInteraction({
|
|
14
|
+
type: 'enterItem',
|
|
15
|
+
data
|
|
16
|
+
});
|
|
17
|
+
dispatchHighlight({
|
|
18
|
+
type: 'enterItem',
|
|
19
|
+
item: data,
|
|
20
|
+
scope
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const onMouseLeave = () => {
|
|
24
|
+
dispatchInteraction({
|
|
25
|
+
type: 'leaveItem',
|
|
26
|
+
data
|
|
27
|
+
});
|
|
28
|
+
dispatchHighlight({
|
|
29
|
+
type: 'leaveItem',
|
|
30
|
+
item: data
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
onMouseEnter,
|
|
35
|
+
onMouseLeave
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
return getInteractionItemProps;
|
|
39
|
+
};
|
|
40
|
+
export const getIsHighlighted = (selectedItem, currentItem, highlightScope) => {
|
|
41
|
+
if (!(highlightScope != null && highlightScope.highlighted) || highlightScope.highlighted === 'none' || selectedItem === null) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const isSeriesSelected = selectedItem.type === currentItem.type && selectedItem.seriesId === currentItem.seriesId;
|
|
45
|
+
if (!isSeriesSelected) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (highlightScope.highlighted === 'series') {
|
|
49
|
+
return isSeriesSelected;
|
|
50
|
+
}
|
|
51
|
+
return selectedItem.dataIndex !== undefined && selectedItem.dataIndex === currentItem.dataIndex;
|
|
52
|
+
};
|
|
53
|
+
export const getIsFaded = (selectedItem, currentItem, highlightScope) => {
|
|
54
|
+
if (!(highlightScope != null && highlightScope.faded) || highlightScope.faded === 'none' || selectedItem === null) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const isSeriesSelected = selectedItem.type === currentItem.type && selectedItem.seriesId === currentItem.seriesId;
|
|
58
|
+
if (highlightScope.faded === 'series') {
|
|
59
|
+
return isSeriesSelected && selectedItem.dataIndex !== currentItem.dataIndex;
|
|
60
|
+
}
|
|
61
|
+
if (highlightScope.faded === 'global') {
|
|
62
|
+
if (!isSeriesSelected) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return selectedItem.dataIndex !== undefined && selectedItem.dataIndex !== currentItem.dataIndex;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
};
|