@shohojdhara/atomix 0.2.4 → 0.2.6
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/README.md +19 -0
- package/dist/atomix.css +1300 -1418
- package/dist/atomix.min.css +3 -3
- package/dist/index.d.ts +1259 -874
- package/dist/index.esm.js +16256 -26366
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +15691 -22295
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/themes/applemix.css +15036 -0
- package/dist/themes/applemix.min.css +72 -0
- package/dist/themes/boomdevs.css +1300 -1419
- package/dist/themes/boomdevs.min.css +3 -3
- package/dist/themes/esrar.css +1301 -1419
- package/dist/themes/esrar.min.css +3 -3
- package/dist/themes/flashtrade.css +15187 -0
- package/dist/themes/flashtrade.min.css +86 -0
- package/dist/themes/mashroom.css +1299 -1417
- package/dist/themes/mashroom.min.css +5 -5
- package/dist/themes/shaj-default.css +1300 -1418
- package/dist/themes/shaj-default.min.css +3 -3
- package/package.json +6 -17
- package/src/components/Accordion/Accordion.stories.tsx +4 -26
- package/src/components/Accordion/Accordion.tsx +21 -12
- package/src/components/AtomixGlass/AtomixGlass.test.tsx +106 -72
- package/src/components/AtomixGlass/AtomixGlass.tsx +485 -1215
- package/src/components/AtomixGlass/AtomixGlassContainer.tsx +399 -0
- package/src/components/AtomixGlass/GlassFilter.tsx +156 -0
- package/src/components/AtomixGlass/README.md +124 -2
- package/src/components/AtomixGlass/atomixGLass.old.tsx +1266 -0
- package/src/components/AtomixGlass/glass-utils.ts +263 -0
- package/src/components/AtomixGlass/shader-utils.ts +404 -236
- package/src/components/AtomixGlass/{AtomixGlass.stories.tsx → stories/AtomixGlass.stories.tsx} +55 -35
- package/src/components/AtomixGlass/stories/Examples.stories.tsx +57 -89
- package/src/components/AtomixGlass/stories/Modes.stories.tsx +149 -149
- package/src/components/AtomixGlass/stories/Playground.stories.tsx +95 -32
- package/src/components/AtomixGlass/stories/ShaderVariants.stories.tsx +0 -2
- package/src/components/AtomixGlass/stories/shared-components.tsx +9 -18
- package/src/components/AtomixGlass/utils.ts +3 -3
- package/src/components/Avatar/Avatar.tsx +3 -0
- package/src/components/Avatar/AvatarGroup.tsx +2 -1
- package/src/components/Badge/Badge.stories.tsx +74 -54
- package/src/components/Badge/Badge.tsx +8 -12
- package/src/components/Breadcrumb/Breadcrumb.tsx +23 -4
- package/src/components/Button/Button.tsx +3 -5
- package/src/components/Callout/Callout.stories.tsx +86 -35
- package/src/components/Callout/Callout.tsx +4 -0
- package/src/components/Card/Card.stories.tsx +89 -85
- package/src/components/Card/Card.tsx +15 -4
- package/src/components/Card/ElevationCard.tsx +2 -0
- package/src/components/Chart/AnimatedChart.tsx +179 -156
- package/src/components/Chart/AreaChart.tsx +123 -12
- package/src/components/Chart/BarChart.tsx +91 -100
- package/src/components/Chart/BaseChart.tsx +80 -0
- package/src/components/Chart/BubbleChart.tsx +114 -290
- package/src/components/Chart/CandlestickChart.tsx +282 -622
- package/src/components/Chart/Chart.stories.tsx +576 -179
- package/src/components/Chart/Chart.tsx +374 -75
- package/src/components/Chart/ChartRenderer.tsx +371 -220
- package/src/components/Chart/ChartToolbar.tsx +372 -61
- package/src/components/Chart/ChartTooltip.tsx +33 -18
- package/src/components/Chart/DonutChart.tsx +172 -254
- package/src/components/Chart/FunnelChart.tsx +169 -240
- package/src/components/Chart/GaugeChart.tsx +224 -392
- package/src/components/Chart/HeatmapChart.tsx +302 -440
- package/src/components/Chart/LineChart.tsx +148 -103
- package/src/components/Chart/MultiAxisChart.tsx +267 -395
- package/src/components/Chart/PieChart.tsx +114 -64
- package/src/components/Chart/RadarChart.tsx +202 -218
- package/src/components/Chart/ScatterChart.tsx +111 -97
- package/src/components/Chart/TreemapChart.tsx +147 -222
- package/src/components/Chart/WaterfallChart.tsx +253 -291
- package/src/components/Chart/index.ts +11 -9
- package/src/components/Chart/types.ts +85 -9
- package/src/components/Chart/utils.ts +66 -0
- package/src/components/ColorModeToggle/ColorModeToggle.stories.tsx +121 -11
- package/src/components/ColorModeToggle/ColorModeToggle.tsx +149 -45
- package/src/components/ColorModeToggle/index.ts +1 -1
- package/src/components/Countdown/Countdown.tsx +4 -0
- package/src/components/DataTable/DataTable.tsx +2 -1
- package/src/components/DatePicker/DatePicker.stories.tsx +0 -11
- package/src/components/DatePicker/DatePicker.tsx +3 -9
- package/src/components/DatePicker/types.ts +5 -0
- package/src/components/Dropdown/Dropdown.stories.tsx +32 -25
- package/src/components/Dropdown/Dropdown.tsx +26 -28
- package/src/components/EdgePanel/EdgePanel.stories.tsx +13 -15
- package/src/components/EdgePanel/EdgePanel.tsx +20 -5
- package/src/components/Footer/Footer.stories.tsx +187 -60
- package/src/components/Footer/Footer.test.tsx +134 -0
- package/src/components/Footer/Footer.tsx +133 -34
- package/src/components/Footer/FooterLink.tsx +1 -1
- package/src/components/Footer/FooterSection.tsx +53 -36
- package/src/components/Footer/FooterSocialLink.tsx +32 -29
- package/src/components/Footer/README.md +82 -3
- package/src/components/Footer/index.ts +1 -1
- package/src/components/Form/Checkbox.stories.tsx +13 -5
- package/src/components/Form/Checkbox.tsx +3 -6
- package/src/components/Form/Form.stories.tsx +10 -3
- package/src/components/Form/Form.tsx +2 -0
- package/src/components/Form/FormGroup.tsx +2 -1
- package/src/components/Form/Input.stories.tsx +12 -11
- package/src/components/Form/Input.tsx +97 -95
- package/src/components/Form/Radio.stories.tsx +22 -7
- package/src/components/Form/Radio.tsx +3 -6
- package/src/components/Form/Select.stories.tsx +21 -6
- package/src/components/Form/Select.tsx +3 -5
- package/src/components/Form/Textarea.stories.tsx +13 -11
- package/src/components/Form/Textarea.tsx +88 -86
- package/src/components/Hero/Hero.stories.tsx +2 -3
- package/src/components/Hero/Hero.tsx +5 -6
- package/src/components/Icon/Icon.tsx +12 -1
- package/src/components/List/List.tsx +2 -1
- package/src/components/List/ListGroup.tsx +2 -1
- package/src/components/Messages/Messages.tsx +3 -2
- package/src/components/Modal/Modal.stories.tsx +48 -34
- package/src/components/Modal/Modal.tsx +19 -23
- package/src/components/Navigation/Menu/MegaMenu.tsx +2 -2
- package/src/components/Navigation/Menu/Menu.tsx +2 -2
- package/src/components/Navigation/Nav/Nav.tsx +6 -1
- package/src/components/Navigation/Nav/NavDropdown.tsx +10 -1
- package/src/components/Navigation/Navbar/Navbar.tsx +4 -1
- package/src/components/Navigation/SideMenu/SideMenu.tsx +3 -2
- package/src/components/Pagination/Pagination.stories.tsx +13 -6
- package/src/components/Pagination/Pagination.tsx +7 -6
- package/src/components/PhotoViewer/PhotoViewer.tsx +2 -1
- package/src/components/Popover/Popover.stories.tsx +32 -24
- package/src/components/Popover/Popover.tsx +4 -1
- package/src/components/ProductReview/ProductReview.tsx +8 -2
- package/src/components/Progress/Progress.tsx +2 -1
- package/src/components/Rating/Rating.stories.tsx +11 -6
- package/src/components/Rating/Rating.tsx +3 -5
- package/src/components/River/River.tsx +5 -5
- package/src/components/SectionIntro/SectionIntro.tsx +8 -2
- package/src/components/Slider/Slider.stories.tsx +4 -4
- package/src/components/Slider/Slider.tsx +4 -3
- package/src/components/Spinner/Spinner.tsx +2 -1
- package/src/components/Steps/Steps.stories.tsx +5 -4
- package/src/components/Steps/Steps.tsx +8 -5
- package/src/components/Tab/Tab.stories.tsx +4 -3
- package/src/components/Tab/Tab.tsx +8 -6
- package/src/components/Testimonial/Testimonial.tsx +8 -2
- package/src/components/Todo/Todo.tsx +2 -1
- package/src/components/Toggle/Toggle.stories.tsx +5 -4
- package/src/components/Toggle/Toggle.tsx +8 -5
- package/src/components/Tooltip/Tooltip.stories.tsx +40 -30
- package/src/components/Tooltip/Tooltip.tsx +9 -2
- package/src/components/Upload/Upload.stories.tsx +252 -0
- package/src/components/Upload/Upload.tsx +92 -53
- package/src/components/VideoPlayer/VideoPlayer.tsx +3 -1
- package/src/components/index.ts +0 -4
- package/src/layouts/Grid/Grid.stories.tsx +10 -23
- package/src/layouts/Grid/Grid.tsx +20 -1
- package/src/layouts/Grid/GridCol.tsx +76 -48
- package/src/lib/composables/useAtomixGlass.ts +861 -44
- package/src/lib/composables/useBarChart.ts +13 -6
- package/src/lib/composables/useChart.ts +17 -13
- package/src/lib/composables/useChartExport.ts +19 -78
- package/src/lib/composables/useChartToolbar.ts +0 -1
- package/src/lib/composables/useEdgePanel.ts +111 -103
- package/src/lib/composables/useFooter.ts +3 -3
- package/src/lib/composables/useGlassContainer.ts +16 -7
- package/src/lib/composables/useLineChart.ts +8 -1
- package/src/lib/composables/useRiver.ts +5 -0
- package/src/lib/composables/useSlider.ts +62 -24
- package/src/lib/composables/useVideoPlayer.ts +60 -63
- package/src/lib/constants/components.ts +146 -32
- package/src/lib/types/components.ts +258 -10
- package/src/lib/utils/displacement-generator.ts +55 -49
- package/src/lib/utils/icons.ts +1 -1
- package/src/lib/utils/index.ts +16 -10
- package/src/styles/01-settings/_settings.accordion.scss +19 -19
- package/src/styles/01-settings/_settings.animations.scss +5 -5
- package/src/styles/01-settings/_settings.avatar-group.scss +1 -1
- package/src/styles/01-settings/_settings.avatar.scss +17 -17
- package/src/styles/01-settings/_settings.background.scss +1 -4
- package/src/styles/01-settings/_settings.badge.scss +1 -1
- package/src/styles/01-settings/_settings.breadcrumb.scss +1 -1
- package/src/styles/01-settings/_settings.card.scss +1 -1
- package/src/styles/01-settings/_settings.chart.scss +65 -2
- package/src/styles/01-settings/_settings.dropdown.scss +1 -1
- package/src/styles/01-settings/_settings.footer.scss +35 -42
- package/src/styles/01-settings/_settings.input.scss +1 -1
- package/src/styles/01-settings/_settings.list.scss +1 -1
- package/src/styles/01-settings/_settings.rating.scss +1 -1
- package/src/styles/01-settings/_settings.tabs.scss +1 -1
- package/src/styles/01-settings/_settings.upload.scss +6 -5
- package/src/styles/02-tools/_tools.animations.scss +4 -5
- package/src/styles/02-tools/_tools.background.scss +1 -13
- package/src/styles/02-tools/_tools.glass.scss +0 -1
- package/src/styles/02-tools/_tools.utility-api.scss +42 -34
- package/src/styles/03-generic/_generic.root.scss +1 -4
- package/src/styles/04-elements/_elements.body.scss +0 -1
- package/src/styles/06-components/_components.atomix-glass.scss +217 -39
- package/src/styles/06-components/_components.badge.scss +6 -8
- package/src/styles/06-components/_components.button.scss +8 -3
- package/src/styles/06-components/_components.card.scss +2 -14
- package/src/styles/06-components/_components.chart.scss +969 -1449
- package/src/styles/06-components/_components.color-mode-toggle.scss +43 -6
- package/src/styles/06-components/_components.dropdown.scss +19 -7
- package/src/styles/06-components/_components.edge-panel.scss +4 -2
- package/src/styles/06-components/_components.footer.scss +166 -85
- package/src/styles/06-components/_components.input.scss +8 -9
- package/src/styles/06-components/_components.list.scss +1 -0
- package/src/styles/06-components/_components.modal.scss +5 -3
- package/src/styles/06-components/_components.skeleton.scss +8 -6
- package/src/styles/06-components/_components.upload.scss +219 -4
- package/src/styles/06-components/old.chart.styles.scss +1 -30
- package/src/styles/99-utilities/_utilities.opacity.scss +1 -1
- package/src/styles/99-utilities/_utilities.scss +1 -1
- package/src/components/Chart/AdvancedChart.tsx +0 -624
- package/src/components/Chart/LineChartNew.tsx +0 -167
- package/src/components/Chart/RealTimeChart.tsx +0 -436
- package/src/components/DatePicker/DatePicker copy.tsx +0 -551
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { forwardRef, memo
|
|
1
|
+
import { forwardRef, memo } from 'react';
|
|
2
|
+
import BaseChart from './BaseChart';
|
|
2
3
|
import { ChartProps } from '../../lib/types/components';
|
|
3
|
-
import
|
|
4
|
-
import ChartRenderer from './ChartRenderer';
|
|
4
|
+
import { ChartRenderContentParams } from './types';
|
|
5
5
|
|
|
6
6
|
export interface WaterfallDataPoint {
|
|
7
7
|
label: string;
|
|
@@ -97,7 +97,7 @@ const WaterfallChart = memo(
|
|
|
97
97
|
) => {
|
|
98
98
|
const {
|
|
99
99
|
showConnectors = true,
|
|
100
|
-
connectorColor = '
|
|
100
|
+
connectorColor = 'var(--atomix-gray-1)',
|
|
101
101
|
connectorStyle = 'dashed',
|
|
102
102
|
showValues = true,
|
|
103
103
|
valuePosition = 'top',
|
|
@@ -109,338 +109,299 @@ const WaterfallChart = memo(
|
|
|
109
109
|
},
|
|
110
110
|
barWidth = 0.6,
|
|
111
111
|
showCumulativeLine = false,
|
|
112
|
-
cumulativeLineColor = '
|
|
112
|
+
cumulativeLineColor = 'var(--atomix-primary)',
|
|
113
113
|
animate = true,
|
|
114
114
|
animationDuration = 1000,
|
|
115
115
|
animationDelay = 100,
|
|
116
116
|
valueFormatter = value => value.toLocaleString(),
|
|
117
117
|
showBaseline = true,
|
|
118
|
-
baselineColor = '
|
|
118
|
+
baselineColor = 'var(--atomix-gray-2)',
|
|
119
119
|
} = waterfallOptions;
|
|
120
120
|
|
|
121
|
-
const renderContent =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return {
|
|
155
|
-
...item,
|
|
156
|
-
startValue,
|
|
157
|
-
endValue,
|
|
158
|
-
cumulativeValue,
|
|
159
|
-
index,
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// Calculate scales
|
|
164
|
-
const allValues = processedData.flatMap(d => [d.startValue, d.endValue]);
|
|
165
|
-
const minValue = Math.min(0, ...allValues);
|
|
166
|
-
const maxValue = Math.max(...allValues);
|
|
167
|
-
const valueRange = maxValue - minValue;
|
|
168
|
-
|
|
169
|
-
const barWidthPx = (chartWidth / waterfallData.length) * barWidth;
|
|
170
|
-
const barSpacing = chartWidth / waterfallData.length;
|
|
171
|
-
|
|
172
|
-
const xScale = (index: number) => padding + index * barSpacing + barSpacing / 2;
|
|
173
|
-
const yScale = (value: number) =>
|
|
174
|
-
padding + chartHeight - ((value - minValue) / valueRange) * chartHeight;
|
|
175
|
-
|
|
176
|
-
const elements = [];
|
|
177
|
-
|
|
178
|
-
// Baseline
|
|
179
|
-
if (showBaseline) {
|
|
180
|
-
const baselineY = yScale(0);
|
|
181
|
-
elements.push(
|
|
182
|
-
<line
|
|
183
|
-
key="baseline"
|
|
184
|
-
x1={padding}
|
|
185
|
-
y1={baselineY}
|
|
186
|
-
x2={scales.width - padding}
|
|
187
|
-
y2={baselineY}
|
|
188
|
-
stroke={baselineColor}
|
|
189
|
-
strokeWidth="2"
|
|
190
|
-
opacity="0.7"
|
|
191
|
-
/>
|
|
192
|
-
);
|
|
121
|
+
const renderContent = ({
|
|
122
|
+
scales,
|
|
123
|
+
colors,
|
|
124
|
+
datasets: renderedDatasets,
|
|
125
|
+
handlers,
|
|
126
|
+
hoveredPoint,
|
|
127
|
+
toolbarState,
|
|
128
|
+
config: renderConfig,
|
|
129
|
+
}: ChartRenderContentParams) => {
|
|
130
|
+
if (!waterfallData.length) return null;
|
|
131
|
+
|
|
132
|
+
// Use toolbar state if available, fallback to config for backward compatibility
|
|
133
|
+
const shouldAnimate = toolbarState?.animationsEnabled ?? renderConfig?.animate ?? animate;
|
|
134
|
+
|
|
135
|
+
const padding = 60;
|
|
136
|
+
const chartWidth = scales.width - padding * 2;
|
|
137
|
+
const chartHeight = scales.height - padding * 2;
|
|
138
|
+
|
|
139
|
+
// Calculate cumulative values and positions
|
|
140
|
+
let cumulativeValue = 0;
|
|
141
|
+
const processedData = waterfallData.map((item, index) => {
|
|
142
|
+
const startValue =
|
|
143
|
+
item.type === 'total' || item.type === 'subtotal' ? 0 : cumulativeValue;
|
|
144
|
+
|
|
145
|
+
let endValue: number;
|
|
146
|
+
if (item.type === 'total' || item.type === 'subtotal') {
|
|
147
|
+
endValue = item.value;
|
|
148
|
+
cumulativeValue = item.value;
|
|
149
|
+
} else {
|
|
150
|
+
endValue = cumulativeValue + item.value;
|
|
151
|
+
cumulativeValue = endValue;
|
|
193
152
|
}
|
|
194
153
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
let barColor = item.color;
|
|
204
|
-
if (!barColor) {
|
|
205
|
-
if (item.type === 'total') barColor = waterfallColors.total;
|
|
206
|
-
else if (item.type === 'subtotal') barColor = waterfallColors.subtotal;
|
|
207
|
-
else if (item.value >= 0) barColor = waterfallColors.positive;
|
|
208
|
-
else barColor = waterfallColors.negative;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Bar rectangle
|
|
212
|
-
elements.push(
|
|
213
|
-
<rect
|
|
214
|
-
key={`bar-${index}`}
|
|
215
|
-
x={x - barWidthPx / 2}
|
|
216
|
-
y={barTop}
|
|
217
|
-
width={barWidthPx}
|
|
218
|
-
height={Math.max(barHeight, 2)}
|
|
219
|
-
fill={barColor}
|
|
220
|
-
rx="4"
|
|
221
|
-
className={`c-chart__waterfall-bar ${animate ? 'c-chart__waterfall-bar--animated' : ''}`}
|
|
222
|
-
style={{
|
|
223
|
-
animationDelay: animate ? `${index * animationDelay}ms` : '0ms',
|
|
224
|
-
}}
|
|
225
|
-
onClick={() => handlers.onDataPointClick?.(item as any, 0, index)}
|
|
226
|
-
/>
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
// Value labels
|
|
230
|
-
if (showValues) {
|
|
231
|
-
let labelY = barTop;
|
|
232
|
-
let labelValue = item.value;
|
|
233
|
-
|
|
234
|
-
if (valuePosition === 'center') {
|
|
235
|
-
labelY = barTop + barHeight / 2;
|
|
236
|
-
} else if (valuePosition === 'bottom') {
|
|
237
|
-
labelY = barBottom + 15;
|
|
238
|
-
} else {
|
|
239
|
-
labelY = barTop - 5;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// For total/subtotal bars, show the cumulative value
|
|
243
|
-
if (item.type === 'total' || item.type === 'subtotal') {
|
|
244
|
-
labelValue = item.endValue;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
elements.push(
|
|
248
|
-
<text
|
|
249
|
-
key={`value-${index}`}
|
|
250
|
-
x={x}
|
|
251
|
-
y={labelY}
|
|
252
|
-
textAnchor="middle"
|
|
253
|
-
dominantBaseline={valuePosition === 'center' ? 'middle' : 'auto'}
|
|
254
|
-
className={`c-chart__waterfall-value ${valuePosition === 'center' ? 'c-chart__waterfall-value--center' : 'c-chart__waterfall-value--outside'}`}
|
|
255
|
-
>
|
|
256
|
-
{valueFormatter(labelValue)}
|
|
257
|
-
</text>
|
|
258
|
-
);
|
|
259
|
-
}
|
|
154
|
+
return {
|
|
155
|
+
...item,
|
|
156
|
+
startValue,
|
|
157
|
+
endValue,
|
|
158
|
+
cumulativeValue,
|
|
159
|
+
index,
|
|
160
|
+
};
|
|
161
|
+
});
|
|
260
162
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const nextStartY = yScale(nextItem.startValue);
|
|
267
|
-
const nextX = xScale(index + 1);
|
|
268
|
-
|
|
269
|
-
// Only show connector if there's a gap to bridge
|
|
270
|
-
if (Math.abs(item.endValue - nextItem.startValue) > 0.01) {
|
|
271
|
-
const strokeDasharray =
|
|
272
|
-
connectorStyle === 'dashed'
|
|
273
|
-
? '5,5'
|
|
274
|
-
: connectorStyle === 'dotted'
|
|
275
|
-
? '2,2'
|
|
276
|
-
: 'none';
|
|
277
|
-
|
|
278
|
-
elements.push(
|
|
279
|
-
<line
|
|
280
|
-
key={`connector-${index}`}
|
|
281
|
-
x1={x + barWidthPx / 2}
|
|
282
|
-
y1={currentEndY}
|
|
283
|
-
x2={nextX - barWidthPx / 2}
|
|
284
|
-
y2={nextStartY}
|
|
285
|
-
stroke={connectorColor}
|
|
286
|
-
strokeDasharray={strokeDasharray}
|
|
287
|
-
className="c-chart__waterfall-connector"
|
|
288
|
-
/>
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
});
|
|
163
|
+
// Calculate scales
|
|
164
|
+
const allValues = processedData.flatMap(d => [d.startValue, d.endValue]);
|
|
165
|
+
const minValue = Math.min(0, ...allValues);
|
|
166
|
+
const maxValue = Math.max(...allValues);
|
|
167
|
+
const valueRange = maxValue - minValue;
|
|
294
168
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const linePoints = processedData.map((item, index) => ({
|
|
298
|
-
x: xScale(index),
|
|
299
|
-
y: yScale(item.cumulativeValue),
|
|
300
|
-
}));
|
|
169
|
+
const barWidthPx = (chartWidth / waterfallData.length) * barWidth;
|
|
170
|
+
const barSpacing = chartWidth / waterfallData.length;
|
|
301
171
|
|
|
302
|
-
|
|
172
|
+
const xScale = (index: number) => padding + index * barSpacing + barSpacing / 2;
|
|
173
|
+
const yScale = (value: number) =>
|
|
174
|
+
padding + chartHeight - ((value - minValue) / valueRange) * chartHeight;
|
|
303
175
|
|
|
304
|
-
|
|
305
|
-
<path
|
|
306
|
-
key="cumulative-line"
|
|
307
|
-
d={linePath}
|
|
308
|
-
fill="none"
|
|
309
|
-
stroke={cumulativeLineColor}
|
|
310
|
-
className="c-chart__waterfall-cumulative-line"
|
|
311
|
-
/>
|
|
312
|
-
);
|
|
176
|
+
const elements = [];
|
|
313
177
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
<circle
|
|
318
|
-
key={`line-point-${index}`}
|
|
319
|
-
cx={point.x}
|
|
320
|
-
cy={point.y}
|
|
321
|
-
r="4"
|
|
322
|
-
fill={cumulativeLineColor}
|
|
323
|
-
className="c-chart__waterfall-cumulative-point"
|
|
324
|
-
/>
|
|
325
|
-
);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// X-axis
|
|
178
|
+
// Baseline
|
|
179
|
+
if (showBaseline) {
|
|
180
|
+
const baselineY = yScale(0);
|
|
330
181
|
elements.push(
|
|
331
182
|
<line
|
|
332
|
-
key="
|
|
183
|
+
key="baseline"
|
|
333
184
|
x1={padding}
|
|
334
|
-
y1={
|
|
185
|
+
y1={baselineY}
|
|
335
186
|
x2={scales.width - padding}
|
|
336
|
-
y2={
|
|
337
|
-
stroke=
|
|
338
|
-
|
|
187
|
+
y2={baselineY}
|
|
188
|
+
stroke={baselineColor}
|
|
189
|
+
className="c-chart__axis-line"
|
|
190
|
+
opacity="0.7"
|
|
339
191
|
/>
|
|
340
192
|
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Bars
|
|
196
|
+
processedData.forEach((item, index) => {
|
|
197
|
+
const x = xScale(index);
|
|
198
|
+
const barTop = Math.min(yScale(item.startValue), yScale(item.endValue));
|
|
199
|
+
const barBottom = Math.max(yScale(item.startValue), yScale(item.endValue));
|
|
200
|
+
const barHeight = barBottom - barTop;
|
|
201
|
+
|
|
202
|
+
// Determine bar color
|
|
203
|
+
let barColor = item.color;
|
|
204
|
+
if (!barColor) {
|
|
205
|
+
if (item.type === 'total') barColor = waterfallColors.total;
|
|
206
|
+
else if (item.type === 'subtotal') barColor = waterfallColors.subtotal;
|
|
207
|
+
else if (item.value >= 0) barColor = waterfallColors.positive;
|
|
208
|
+
else barColor = waterfallColors.negative;
|
|
209
|
+
}
|
|
341
210
|
|
|
342
|
-
//
|
|
211
|
+
// Bar rectangle
|
|
343
212
|
elements.push(
|
|
344
|
-
<
|
|
345
|
-
key=
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
213
|
+
<rect
|
|
214
|
+
key={`bar-${index}`}
|
|
215
|
+
x={x - barWidthPx / 2}
|
|
216
|
+
y={barTop}
|
|
217
|
+
width={barWidthPx}
|
|
218
|
+
height={Math.max(barHeight, 2)}
|
|
219
|
+
fill={barColor}
|
|
220
|
+
className={`c-chart__waterfall-bar ${shouldAnimate ? 'c-chart__waterfall-bar--animated' : ''}`}
|
|
221
|
+
style={{
|
|
222
|
+
animationDelay: shouldAnimate ? `${index * animationDelay}ms` : '0ms',
|
|
223
|
+
}}
|
|
224
|
+
onClick={() => handlers.onDataPointClick?.(item as any, 0, index)}
|
|
225
|
+
onMouseEnter={e => {
|
|
226
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
227
|
+
handlers.onPointHover(
|
|
228
|
+
0,
|
|
229
|
+
index,
|
|
230
|
+
x,
|
|
231
|
+
barTop,
|
|
232
|
+
rect.left + rect.width / 2,
|
|
233
|
+
rect.top + rect.height / 2
|
|
234
|
+
);
|
|
235
|
+
}}
|
|
236
|
+
onMouseLeave={handlers.onPointLeave}
|
|
352
237
|
/>
|
|
353
238
|
);
|
|
354
239
|
|
|
355
|
-
//
|
|
356
|
-
|
|
357
|
-
|
|
240
|
+
// Value labels
|
|
241
|
+
if (showValues) {
|
|
242
|
+
let labelY = barTop;
|
|
243
|
+
let labelValue = item.value;
|
|
244
|
+
|
|
245
|
+
if (valuePosition === 'center') {
|
|
246
|
+
labelY = barTop + barHeight / 2;
|
|
247
|
+
} else if (valuePosition === 'bottom') {
|
|
248
|
+
labelY = barBottom + 15;
|
|
249
|
+
} else {
|
|
250
|
+
labelY = barTop - 5;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// For total/subtotal bars, show the cumulative value
|
|
254
|
+
if (item.type === 'total' || item.type === 'subtotal') {
|
|
255
|
+
labelValue = item.endValue;
|
|
256
|
+
}
|
|
257
|
+
|
|
358
258
|
elements.push(
|
|
359
259
|
<text
|
|
360
|
-
key={`
|
|
260
|
+
key={`value-${index}`}
|
|
361
261
|
x={x}
|
|
362
|
-
y={
|
|
262
|
+
y={labelY}
|
|
363
263
|
textAnchor="middle"
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
transform={`rotate(-45, ${x}, ${scales.height - padding + 20})`}
|
|
264
|
+
dominantBaseline={valuePosition === 'center' ? 'middle' : 'auto'}
|
|
265
|
+
className={`c-chart__waterfall-value ${valuePosition === 'center' ? 'c-chart__waterfall-value--center' : 'c-chart__waterfall-value--outside'}`}
|
|
367
266
|
>
|
|
368
|
-
{
|
|
267
|
+
{valueFormatter(labelValue)}
|
|
369
268
|
</text>
|
|
370
269
|
);
|
|
371
|
-
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Connectors
|
|
273
|
+
if (showConnectors && index < processedData.length - 1) {
|
|
274
|
+
const nextItem = processedData[index + 1];
|
|
275
|
+
if (nextItem) {
|
|
276
|
+
const currentEndY = yScale(item.endValue);
|
|
277
|
+
const nextStartY = yScale(nextItem.startValue);
|
|
278
|
+
const nextX = xScale(index + 1);
|
|
279
|
+
|
|
280
|
+
// Only show connector if there's a gap to bridge
|
|
281
|
+
if (Math.abs(item.endValue - nextItem.startValue) > 0.01) {
|
|
282
|
+
const strokeDasharray =
|
|
283
|
+
connectorStyle === 'dashed'
|
|
284
|
+
? '5,5'
|
|
285
|
+
: connectorStyle === 'dotted'
|
|
286
|
+
? '2,2'
|
|
287
|
+
: 'none';
|
|
288
|
+
|
|
289
|
+
elements.push(
|
|
290
|
+
<line
|
|
291
|
+
key={`connector-${index}`}
|
|
292
|
+
x1={x + barWidthPx / 2}
|
|
293
|
+
y1={currentEndY}
|
|
294
|
+
x2={nextX - barWidthPx / 2}
|
|
295
|
+
y2={nextStartY}
|
|
296
|
+
stroke={connectorColor}
|
|
297
|
+
strokeDasharray={strokeDasharray}
|
|
298
|
+
className="c-chart__waterfall-connector"
|
|
299
|
+
/>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// Cumulative line
|
|
307
|
+
if (showCumulativeLine) {
|
|
308
|
+
const linePoints = processedData.map((item, index) => ({
|
|
309
|
+
x: xScale(index),
|
|
310
|
+
y: yScale(item.cumulativeValue),
|
|
311
|
+
}));
|
|
372
312
|
|
|
373
|
-
|
|
374
|
-
const yTicks = 5;
|
|
375
|
-
for (let i = 0; i <= yTicks; i++) {
|
|
376
|
-
const value = minValue + (i / yTicks) * valueRange;
|
|
377
|
-
const y = yScale(value);
|
|
313
|
+
const linePath = `M ${linePoints.map(p => `${p.x},${p.y}`).join(' L ')}`;
|
|
378
314
|
|
|
315
|
+
elements.push(
|
|
316
|
+
<path
|
|
317
|
+
key="cumulative-line"
|
|
318
|
+
d={linePath}
|
|
319
|
+
fill="none"
|
|
320
|
+
stroke={cumulativeLineColor}
|
|
321
|
+
className="c-chart__waterfall-cumulative-line"
|
|
322
|
+
/>
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
// Line points
|
|
326
|
+
linePoints.forEach((point, index) => {
|
|
379
327
|
elements.push(
|
|
380
|
-
<
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
/>
|
|
389
|
-
<text
|
|
390
|
-
x={padding - 10}
|
|
391
|
-
y={y}
|
|
392
|
-
textAnchor="end"
|
|
393
|
-
dominantBaseline="middle"
|
|
394
|
-
fontSize="11"
|
|
395
|
-
fill="var(--atomix-gray-6)"
|
|
396
|
-
>
|
|
397
|
-
{valueFormatter(value)}
|
|
398
|
-
</text>
|
|
399
|
-
</g>
|
|
328
|
+
<circle
|
|
329
|
+
key={`line-point-${index}`}
|
|
330
|
+
cx={point.x}
|
|
331
|
+
cy={point.y}
|
|
332
|
+
r="4"
|
|
333
|
+
fill={cumulativeLineColor}
|
|
334
|
+
className="c-chart__waterfall-cumulative-point"
|
|
335
|
+
/>
|
|
400
336
|
);
|
|
401
|
-
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// X-axis
|
|
341
|
+
elements.push(
|
|
342
|
+
<line
|
|
343
|
+
key="x-axis"
|
|
344
|
+
x1={padding}
|
|
345
|
+
y1={scales.height - padding}
|
|
346
|
+
x2={scales.width - padding}
|
|
347
|
+
y2={scales.height - padding}
|
|
348
|
+
stroke="var(--atomix-gray-4)"
|
|
349
|
+
strokeWidth="2"
|
|
350
|
+
/>
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
// Y-axis
|
|
354
|
+
elements.push(
|
|
355
|
+
<line
|
|
356
|
+
key="y-axis"
|
|
357
|
+
x1={padding}
|
|
358
|
+
y1={padding}
|
|
359
|
+
x2={padding}
|
|
360
|
+
y2={scales.height - padding}
|
|
361
|
+
stroke="var(--atomix-gray-4)"
|
|
362
|
+
className="c-chart__axis-line"
|
|
363
|
+
/>
|
|
364
|
+
);
|
|
402
365
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
baselineColor,
|
|
421
|
-
]
|
|
422
|
-
);
|
|
366
|
+
// X-axis labels
|
|
367
|
+
processedData.forEach((item, index) => {
|
|
368
|
+
const x = padding + index * barSpacing + barSpacing / 2;
|
|
369
|
+
elements.push(
|
|
370
|
+
<text
|
|
371
|
+
key={`x-label-${index}`}
|
|
372
|
+
x={x}
|
|
373
|
+
y={scales.height - padding + 20}
|
|
374
|
+
textAnchor="middle"
|
|
375
|
+
className="c-chart__axis-label"
|
|
376
|
+
fill="var(--atomix-gray-6)"
|
|
377
|
+
transform={`rotate(-45, ${x}, ${scales.height - padding + 20})`}
|
|
378
|
+
>
|
|
379
|
+
{item.label}
|
|
380
|
+
</text>
|
|
381
|
+
);
|
|
382
|
+
});
|
|
423
383
|
|
|
424
|
-
|
|
384
|
+
return <g>{elements}</g>;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// Convert waterfallData to datasets format for BaseChart
|
|
425
388
|
const datasets = [
|
|
426
389
|
{
|
|
427
390
|
label: 'Waterfall Data',
|
|
428
|
-
data: waterfallData
|
|
429
|
-
label: item.label,
|
|
430
|
-
value: item.value,
|
|
431
|
-
})),
|
|
391
|
+
data: waterfallData,
|
|
432
392
|
},
|
|
433
393
|
];
|
|
434
394
|
|
|
435
395
|
return (
|
|
436
|
-
<
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
396
|
+
<BaseChart
|
|
397
|
+
ref={ref}
|
|
398
|
+
type="waterfall"
|
|
399
|
+
datasets={datasets}
|
|
400
|
+
config={config}
|
|
401
|
+
renderContent={renderContent}
|
|
402
|
+
onDataPointClick={onDataPointClick}
|
|
403
|
+
{...props}
|
|
404
|
+
/>
|
|
444
405
|
);
|
|
445
406
|
}
|
|
446
407
|
)
|
|
@@ -448,3 +409,4 @@ const WaterfallChart = memo(
|
|
|
448
409
|
|
|
449
410
|
WaterfallChart.displayName = 'WaterfallChart';
|
|
450
411
|
export default WaterfallChart;
|
|
412
|
+
export type { WaterfallChartProps, WaterfallDataPoint };
|