@coinbase/cds-web-visualization 0.0.0 → 3.4.0-beta.1
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/CHANGELOG.md +26 -0
- package/README.md +3 -0
- package/dts/chart/CartesianChart.d.ts +36 -0
- package/dts/chart/CartesianChart.d.ts.map +1 -0
- package/dts/chart/ChartProvider.d.ts +6 -0
- package/dts/chart/ChartProvider.d.ts.map +1 -0
- package/dts/chart/Path.d.ts +34 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +61 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/Point.d.ts +153 -0
- package/dts/chart/Point.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +48 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +52 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +68 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +30 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +8 -0
- package/dts/chart/area/SolidArea.d.ts.map +1 -0
- package/dts/chart/area/index.d.ts +6 -0
- package/dts/chart/area/index.d.ts.map +1 -0
- package/dts/chart/axis/Axis.d.ts +208 -0
- package/dts/chart/axis/Axis.d.ts.map +1 -0
- package/dts/chart/axis/XAxis.d.ts +16 -0
- package/dts/chart/axis/XAxis.d.ts.map +1 -0
- package/dts/chart/axis/YAxis.d.ts +21 -0
- package/dts/chart/axis/YAxis.d.ts.map +1 -0
- package/dts/chart/axis/index.d.ts +4 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +91 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +53 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +29 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +111 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +35 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBar.d.ts +17 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +16 -0
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -0
- package/dts/chart/bar/index.d.ts +8 -0
- package/dts/chart/bar/index.d.ts.map +1 -0
- package/dts/chart/index.d.ts +13 -0
- package/dts/chart/index.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +14 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/GradientLine.d.ts +42 -0
- package/dts/chart/line/GradientLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +80 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +59 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +131 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +14 -0
- package/dts/chart/line/SolidLine.d.ts.map +1 -0
- package/dts/chart/line/index.d.ts +7 -0
- package/dts/chart/line/index.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +149 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +93 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +7 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +17 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +2 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +114 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts +55 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts.map +1 -0
- package/dts/chart/text/index.d.ts +3 -0
- package/dts/chart/text/index.d.ts.map +1 -0
- package/dts/chart/utils/axis.d.ts +342 -0
- package/dts/chart/utils/axis.d.ts.map +1 -0
- package/dts/chart/utils/bar.d.ts +20 -0
- package/dts/chart/utils/bar.d.ts.map +1 -0
- package/dts/chart/utils/chart.d.ts +97 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +95 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +8 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +107 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +75 -0
- package/dts/chart/utils/point.d.ts.map +1 -0
- package/dts/chart/utils/scale.d.ts +43 -0
- package/dts/chart/utils/scale.d.ts.map +1 -0
- package/dts/index.d.ts +3 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/sparkline/Counter.d.ts +8 -0
- package/dts/sparkline/Counter.d.ts.map +1 -0
- package/dts/sparkline/Sparkline.d.ts +67 -0
- package/dts/sparkline/Sparkline.d.ts.map +1 -0
- package/dts/sparkline/SparklineArea.d.ts +15 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts +14 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -0
- package/dts/sparkline/SparklineGradient.d.ts +23 -0
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -0
- package/dts/sparkline/SparklinePath.d.ts +12 -0
- package/dts/sparkline/SparklinePath.d.ts.map +1 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +2 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts.map +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts +11 -0
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -0
- package/dts/sparkline/index.d.ts +6 -0
- package/dts/sparkline/index.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +199 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +26 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +8 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +17 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +30 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +18 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +31 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +112 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts.map +1 -0
- package/esm/chart/CartesianChart.css +1 -0
- package/esm/chart/CartesianChart.js +258 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +89 -0
- package/esm/chart/PeriodSelector.css +1 -0
- package/esm/chart/PeriodSelector.js +126 -0
- package/esm/chart/Point.css +2 -0
- package/esm/chart/Point.js +171 -0
- package/esm/chart/area/Area.js +85 -0
- package/esm/chart/area/AreaChart.js +164 -0
- package/esm/chart/area/DottedArea.js +141 -0
- package/esm/chart/area/GradientArea.js +111 -0
- package/esm/chart/area/SolidArea.js +29 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +46 -0
- package/esm/chart/axis/XAxis.css +2 -0
- package/esm/chart/axis/XAxis.js +195 -0
- package/esm/chart/axis/YAxis.css +2 -0
- package/esm/chart/axis/YAxis.js +183 -0
- package/esm/chart/axis/index.js +5 -0
- package/esm/chart/bar/Bar.js +59 -0
- package/esm/chart/bar/BarChart.js +147 -0
- package/esm/chart/bar/BarPlot.js +96 -0
- package/esm/chart/bar/BarStack.js +519 -0
- package/esm/chart/bar/BarStackGroup.js +96 -0
- package/esm/chart/bar/DefaultBar.js +64 -0
- package/esm/chart/bar/DefaultBarStack.js +60 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/index.js +14 -0
- package/esm/chart/line/DottedLine.js +38 -0
- package/esm/chart/line/GradientLine.js +58 -0
- package/esm/chart/line/Line.js +159 -0
- package/esm/chart/line/LineChart.js +120 -0
- package/esm/chart/line/ReferenceLine.js +142 -0
- package/esm/chart/line/SolidLine.js +34 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/scrubber/Scrubber.js +483 -0
- package/esm/chart/scrubber/ScrubberBeacon.js +195 -0
- package/esm/chart/scrubber/ScrubberBeaconLabel.js +33 -0
- package/esm/chart/scrubber/ScrubberProvider.js +228 -0
- package/esm/chart/scrubber/index.js +2 -0
- package/esm/chart/text/ChartText.js +236 -0
- package/esm/chart/text/SmartChartTextGroup.js +226 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +593 -0
- package/esm/chart/utils/bar.js +24 -0
- package/esm/chart/utils/chart.js +229 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/index.js +9 -0
- package/esm/chart/utils/path.js +204 -0
- package/esm/chart/utils/point.js +118 -0
- package/esm/chart/utils/scale.js +48 -0
- package/esm/index.js +4 -0
- package/esm/sparkline/Counter.css +3 -0
- package/esm/sparkline/Counter.js +35 -0
- package/esm/sparkline/Sparkline.js +164 -0
- package/esm/sparkline/SparklineArea.js +18 -0
- package/esm/sparkline/SparklineAreaPattern.js +37 -0
- package/esm/sparkline/SparklineGradient.js +30 -0
- package/esm/sparkline/SparklinePath.js +19 -0
- package/esm/sparkline/__figma__/Sparkline.figma.js +24 -0
- package/esm/sparkline/generateSparklineWithId.js +7 -0
- package/esm/sparkline/index.js +5 -0
- package/esm/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.js +21 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +317 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +108 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +26 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.js +24 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.css +4 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +65 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.css +1 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +80 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +56 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +70 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +45 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.css +5 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.js +199 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.js +39 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +92 -0
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +89 -0
- package/esm/sparkline/sparkline-interactive/fade.css +2 -0
- package/esm/sparkline/sparkline-interactive/fade.js +14 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +28 -0
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +225 -0
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +108 -0
- package/package.json +68 -6
- package/index.js +0 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
const _excluded = ["series", "stacked", "showXAxis", "showYAxis", "xAxis", "yAxis", "inset", "children", "barPadding", "BarComponent", "fillOpacity", "stroke", "strokeWidth", "borderRadius", "roundBaseline", "BarStackComponent", "stackGap", "barMinSize", "stackMinSize"],
|
|
2
|
+
_excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
|
|
3
|
+
_excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"];
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
10
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
11
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
12
|
+
import { XAxis, YAxis } from '../axis';
|
|
13
|
+
import { CartesianChart } from '../CartesianChart';
|
|
14
|
+
import { defaultChartInset, defaultStackId, getChartInset } from '../utils';
|
|
15
|
+
import { BarPlot } from './BarPlot';
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
export const BarChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
18
|
+
let {
|
|
19
|
+
series,
|
|
20
|
+
stacked,
|
|
21
|
+
showXAxis,
|
|
22
|
+
showYAxis,
|
|
23
|
+
xAxis,
|
|
24
|
+
yAxis,
|
|
25
|
+
inset: userInset,
|
|
26
|
+
children,
|
|
27
|
+
barPadding,
|
|
28
|
+
BarComponent,
|
|
29
|
+
fillOpacity,
|
|
30
|
+
stroke,
|
|
31
|
+
strokeWidth,
|
|
32
|
+
borderRadius,
|
|
33
|
+
roundBaseline,
|
|
34
|
+
BarStackComponent,
|
|
35
|
+
stackGap,
|
|
36
|
+
barMinSize,
|
|
37
|
+
stackMinSize
|
|
38
|
+
} = _ref,
|
|
39
|
+
chartProps = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
+
const calculatedInset = useMemo(() => getChartInset(userInset, defaultChartInset), [userInset]);
|
|
41
|
+
|
|
42
|
+
// Convert BarSeries to Series for Chart context
|
|
43
|
+
const chartSeries = useMemo(() => {
|
|
44
|
+
return series === null || series === void 0 ? void 0 : series.map(s => ({
|
|
45
|
+
id: s.id,
|
|
46
|
+
data: s.data,
|
|
47
|
+
label: s.label,
|
|
48
|
+
color: s.color,
|
|
49
|
+
yAxisId: s.yAxisId,
|
|
50
|
+
stackId: s.stackId
|
|
51
|
+
}));
|
|
52
|
+
}, [series]);
|
|
53
|
+
const transformedSeries = useMemo(() => {
|
|
54
|
+
if (!stacked || !chartSeries) return chartSeries;
|
|
55
|
+
return chartSeries.map(s => {
|
|
56
|
+
var _s$stackId;
|
|
57
|
+
return _objectSpread(_objectSpread({}, s), {}, {
|
|
58
|
+
stackId: (_s$stackId = s.stackId) !== null && _s$stackId !== void 0 ? _s$stackId : defaultStackId
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}, [chartSeries, stacked]);
|
|
62
|
+
const seriesToRender = transformedSeries !== null && transformedSeries !== void 0 ? transformedSeries : chartSeries;
|
|
63
|
+
|
|
64
|
+
// Keep the original series with bar-specific props for BarPlot
|
|
65
|
+
const barSeriesToRender = useMemo(() => {
|
|
66
|
+
if (!stacked || !series) return series;
|
|
67
|
+
return series.map(s => {
|
|
68
|
+
var _s$stackId2;
|
|
69
|
+
return _objectSpread(_objectSpread({}, s), {}, {
|
|
70
|
+
stackId: (_s$stackId2 = s.stackId) !== null && _s$stackId2 !== void 0 ? _s$stackId2 : defaultStackId
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}, [series, stacked]);
|
|
74
|
+
|
|
75
|
+
// Split axis props into config props for Chart and visual props for axis components
|
|
76
|
+
const _ref2 = xAxis || {},
|
|
77
|
+
{
|
|
78
|
+
scaleType: xScaleType,
|
|
79
|
+
data: xData,
|
|
80
|
+
categoryPadding: xCategoryPadding,
|
|
81
|
+
domain: xDomain,
|
|
82
|
+
domainLimit: xDomainLimit,
|
|
83
|
+
range: xRange
|
|
84
|
+
} = _ref2,
|
|
85
|
+
xAxisVisualProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
86
|
+
const _ref3 = yAxis || {},
|
|
87
|
+
{
|
|
88
|
+
scaleType: yScaleType,
|
|
89
|
+
data: yData,
|
|
90
|
+
categoryPadding: yCategoryPadding,
|
|
91
|
+
domain: yDomain,
|
|
92
|
+
domainLimit: yDomainLimit,
|
|
93
|
+
range: yRange,
|
|
94
|
+
id: yAxisId
|
|
95
|
+
} = _ref3,
|
|
96
|
+
yAxisVisualProps = _objectWithoutProperties(_ref3, _excluded3);
|
|
97
|
+
const xAxisConfig = {
|
|
98
|
+
scaleType: xScaleType !== null && xScaleType !== void 0 ? xScaleType : 'band',
|
|
99
|
+
data: xData,
|
|
100
|
+
categoryPadding: xCategoryPadding,
|
|
101
|
+
domain: xDomain,
|
|
102
|
+
domainLimit: xDomainLimit,
|
|
103
|
+
range: xRange
|
|
104
|
+
};
|
|
105
|
+
const hasNegativeValues = useMemo(() => {
|
|
106
|
+
if (!series) return false;
|
|
107
|
+
return series.some(s => {
|
|
108
|
+
var _s$data;
|
|
109
|
+
return (_s$data = s.data) === null || _s$data === void 0 ? void 0 : _s$data.some(value => typeof value === 'number' && value < 0 || Array.isArray(value) && value.some(v => typeof v === 'number' && v < 0));
|
|
110
|
+
});
|
|
111
|
+
}, [series]);
|
|
112
|
+
|
|
113
|
+
// Set default min domain to 0 for area chart, but only if there are no negative values
|
|
114
|
+
const yAxisConfig = {
|
|
115
|
+
scaleType: yScaleType,
|
|
116
|
+
data: yData,
|
|
117
|
+
categoryPadding: yCategoryPadding,
|
|
118
|
+
domain: hasNegativeValues ? yDomain : _objectSpread({
|
|
119
|
+
min: 0
|
|
120
|
+
}, yDomain),
|
|
121
|
+
domainLimit: yDomainLimit,
|
|
122
|
+
range: yRange
|
|
123
|
+
};
|
|
124
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _objectSpread(_objectSpread({}, chartProps), {}, {
|
|
125
|
+
ref: ref,
|
|
126
|
+
inset: calculatedInset,
|
|
127
|
+
series: seriesToRender,
|
|
128
|
+
xAxis: xAxisConfig,
|
|
129
|
+
yAxis: yAxisConfig,
|
|
130
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
|
|
131
|
+
axisId: yAxisId
|
|
132
|
+
}, yAxisVisualProps)), /*#__PURE__*/_jsx(BarPlot, {
|
|
133
|
+
BarComponent: BarComponent,
|
|
134
|
+
BarStackComponent: BarStackComponent,
|
|
135
|
+
barMinSize: barMinSize,
|
|
136
|
+
barPadding: barPadding,
|
|
137
|
+
borderRadius: borderRadius,
|
|
138
|
+
fillOpacity: fillOpacity,
|
|
139
|
+
roundBaseline: roundBaseline,
|
|
140
|
+
seriesIds: barSeriesToRender === null || barSeriesToRender === void 0 ? void 0 : barSeriesToRender.map(s => s.id),
|
|
141
|
+
stackGap: stackGap,
|
|
142
|
+
stackMinSize: stackMinSize,
|
|
143
|
+
stroke: stroke,
|
|
144
|
+
strokeWidth: strokeWidth
|
|
145
|
+
}), children]
|
|
146
|
+
}));
|
|
147
|
+
}));
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { memo, useId, useMemo } from 'react';
|
|
2
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
3
|
+
import { defaultAxisId } from '../utils';
|
|
4
|
+
import { BarStackGroup } from './BarStackGroup';
|
|
5
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* BarPlot component that handles multiple series with proper stacking coordination.
|
|
8
|
+
* Groups series by stack ID + y-axis ID combination and renders BarStackGroup for each group.
|
|
9
|
+
* This allows series with different y-axes to be rendered side by side while preventing
|
|
10
|
+
* cross-axis stacking (e.g., comparing $1M vs $1B companies on different scales).
|
|
11
|
+
*/
|
|
12
|
+
export const BarPlot = /*#__PURE__*/memo(_ref => {
|
|
13
|
+
let {
|
|
14
|
+
seriesIds,
|
|
15
|
+
barPadding = 0.1,
|
|
16
|
+
BarComponent: defaultBarComponent,
|
|
17
|
+
fillOpacity: defaultFillOpacity,
|
|
18
|
+
stroke: defaultStroke,
|
|
19
|
+
strokeWidth: defaultStrokeWidth,
|
|
20
|
+
borderRadius: defaultBorderRadius,
|
|
21
|
+
roundBaseline,
|
|
22
|
+
BarStackComponent,
|
|
23
|
+
stackGap,
|
|
24
|
+
barMinSize,
|
|
25
|
+
stackMinSize
|
|
26
|
+
} = _ref;
|
|
27
|
+
const {
|
|
28
|
+
series: allSeries,
|
|
29
|
+
drawingArea
|
|
30
|
+
} = useCartesianChartContext();
|
|
31
|
+
const clipPathId = useId();
|
|
32
|
+
const targetSeries = useMemo(() => {
|
|
33
|
+
// Then filter by seriesIds if provided
|
|
34
|
+
if (seriesIds !== undefined) {
|
|
35
|
+
return allSeries.filter(s => seriesIds.includes(s.id));
|
|
36
|
+
}
|
|
37
|
+
return allSeries;
|
|
38
|
+
}, [allSeries, seriesIds]);
|
|
39
|
+
const stackGroups = useMemo(() => {
|
|
40
|
+
const groups = new Map();
|
|
41
|
+
|
|
42
|
+
// Group series into stacks based on stackId + yAxisId combination
|
|
43
|
+
targetSeries.forEach(series => {
|
|
44
|
+
var _series$yAxisId;
|
|
45
|
+
const yAxisId = (_series$yAxisId = series.yAxisId) !== null && _series$yAxisId !== void 0 ? _series$yAxisId : defaultAxisId;
|
|
46
|
+
const stackId = series.stackId || "individual-".concat(series.id);
|
|
47
|
+
const stackKey = "".concat(stackId, ":").concat(yAxisId);
|
|
48
|
+
if (!groups.has(stackKey)) {
|
|
49
|
+
groups.set(stackKey, {
|
|
50
|
+
stackId: stackKey,
|
|
51
|
+
series: [],
|
|
52
|
+
yAxisId: series.yAxisId
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const group = groups.get(stackKey);
|
|
56
|
+
group.series.push(series);
|
|
57
|
+
});
|
|
58
|
+
return Array.from(groups.values());
|
|
59
|
+
}, [targetSeries]);
|
|
60
|
+
if (!drawingArea) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
64
|
+
children: [/*#__PURE__*/_jsx("defs", {
|
|
65
|
+
children: /*#__PURE__*/_jsx("clipPath", {
|
|
66
|
+
id: clipPathId,
|
|
67
|
+
children: /*#__PURE__*/_jsx("rect", {
|
|
68
|
+
height: drawingArea.height,
|
|
69
|
+
width: drawingArea.width,
|
|
70
|
+
x: drawingArea.x,
|
|
71
|
+
y: drawingArea.y
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
75
|
+
clipPath: "url(#".concat(clipPathId, ")"),
|
|
76
|
+
"data-testid": "whoa",
|
|
77
|
+
children: stackGroups.map((group, stackIndex) => /*#__PURE__*/_jsx(BarStackGroup, {
|
|
78
|
+
BarComponent: defaultBarComponent,
|
|
79
|
+
BarStackComponent: BarStackComponent,
|
|
80
|
+
barMinSize: barMinSize,
|
|
81
|
+
barPadding: barPadding,
|
|
82
|
+
borderRadius: defaultBorderRadius,
|
|
83
|
+
fillOpacity: defaultFillOpacity,
|
|
84
|
+
roundBaseline: roundBaseline,
|
|
85
|
+
series: group.series,
|
|
86
|
+
stackGap: stackGap,
|
|
87
|
+
stackIndex: stackIndex,
|
|
88
|
+
stackMinSize: stackMinSize,
|
|
89
|
+
stroke: defaultStroke,
|
|
90
|
+
strokeWidth: defaultStrokeWidth,
|
|
91
|
+
totalStacks: stackGroups.length,
|
|
92
|
+
yAxisId: group.yAxisId
|
|
93
|
+
}, group.stackId))
|
|
94
|
+
})]
|
|
95
|
+
});
|
|
96
|
+
});
|