@wallarm-org/design-system 0.39.0 → 0.39.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/dist/components/SimpleCharts/LineChart/LineChartLine.js +2 -6
- package/dist/components/SimpleCharts/LineChart/LineChartTooltip.js +3 -3
- package/dist/components/SimpleCharts/LineChart/LineChartXAxis.js +12 -3
- package/dist/components/SimpleCharts/LineChart/LineChartYAxis.js +6 -15
- package/dist/components/SimpleCharts/LineChart/LineChartZoomBrush.js +19 -8
- package/dist/components/SimpleCharts/LineChart/classes.js +1 -1
- package/dist/components/SimpleCharts/LineChart/constants.d.ts +1 -1
- package/dist/components/SimpleCharts/LineChart/constants.js +2 -2
- package/dist/components/SimpleCharts/LineChart/lib/formatRange.d.ts +5 -9
- package/dist/components/SimpleCharts/LineChart/lib/formatRange.js +1 -6
- package/dist/components/SimpleCharts/LineChart/lib/renderAxisTick.d.ts +13 -0
- package/dist/components/SimpleCharts/LineChart/lib/renderAxisTick.js +20 -0
- package/dist/components/SimpleCharts/LineChart/lib/sampleData.js +3 -3
- package/dist/components/SimpleCharts/hooks/useChartTimeFormatters.d.ts +0 -5
- package/dist/components/SimpleCharts/hooks/useChartTimeFormatters.js +1 -2
- package/dist/metadata/components.json +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useEffect } from "react";
|
|
3
3
|
import { Line } from "recharts";
|
|
4
|
-
import {
|
|
4
|
+
import { LINE_ANIMATION_BEGIN, LINE_ANIMATION_DURATION, LINE_DASH_DASHARRAY, LINE_INACTIVE_OPACITY, LINE_STROKE_FILL, LINE_STROKE_WIDTH, resolveSeriesColor } from "./constants.js";
|
|
5
5
|
import { LineChartActiveContext, LineChartDataContext } from "./LineChartContext.js";
|
|
6
6
|
import { warnLineChartLine } from "./lib/warn.js";
|
|
7
7
|
const wrap = (cb)=>cb ? (_props, event)=>cb(event) : void 0;
|
|
@@ -34,11 +34,7 @@ const LineChartLine = ({ seriesKey, curve = 'monotone', disableAnimation = false
|
|
|
34
34
|
strokeLinecap: "round",
|
|
35
35
|
strokeLinejoin: "round",
|
|
36
36
|
dot: false,
|
|
37
|
-
activeDot:
|
|
38
|
-
r: LINE_ACTIVE_DOT_RADIUS,
|
|
39
|
-
stroke,
|
|
40
|
-
strokeWidth: 0
|
|
41
|
-
},
|
|
37
|
+
activeDot: false,
|
|
42
38
|
opacity: opacity,
|
|
43
39
|
connectNulls: connectNulls,
|
|
44
40
|
isAnimationActive: disableAnimation ? false : 'auto',
|
|
@@ -2,15 +2,15 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useContext, useMemo } from "react";
|
|
3
3
|
import { Tooltip, usePlotArea } from "recharts";
|
|
4
4
|
import { lineChartTooltipCenterClasses } from "./classes.js";
|
|
5
|
-
import { HOVER_POPOVER_TOP } from "./constants.js";
|
|
5
|
+
import { HOVER_POPOVER_TOP, LINE_CURSOR_DASHARRAY } from "./constants.js";
|
|
6
6
|
import { LineChartDataContext, LineChartSelectionContext, LineChartZoomContext } from "./LineChartContext.js";
|
|
7
7
|
import { LineChartHoverPopover } from "./LineChartHoverPopover.js";
|
|
8
8
|
import { LineChartHoverPopoverRow } from "./LineChartHoverPopoverRow.js";
|
|
9
9
|
import { LineChartHoverPopoverTimestamp } from "./LineChartHoverPopoverTimestamp.js";
|
|
10
10
|
const TOOLTIP_CURSOR = {
|
|
11
|
-
stroke: 'var(--color-border-primary
|
|
11
|
+
stroke: 'var(--color-border-strong-primary)',
|
|
12
12
|
strokeWidth: 1,
|
|
13
|
-
strokeDasharray:
|
|
13
|
+
strokeDasharray: LINE_CURSOR_DASHARRAY
|
|
14
14
|
};
|
|
15
15
|
const TOOLTIP_ALLOW_ESCAPE = {
|
|
16
16
|
x: false,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { XAxis } from "recharts";
|
|
4
|
-
import { LINE_AXIS_TICK_TEXT_PROPS } from "./constants.js";
|
|
5
4
|
import { LineChartDataContext } from "./LineChartContext.js";
|
|
5
|
+
import { renderAxisTick } from "./lib/renderAxisTick.js";
|
|
6
6
|
const DENSITY_MIN_TICK_GAP = {
|
|
7
7
|
sparse: 64,
|
|
8
8
|
normal: 32,
|
|
@@ -11,7 +11,16 @@ const DENSITY_MIN_TICK_GAP = {
|
|
|
11
11
|
const AXIS_LINE_PROPS = {
|
|
12
12
|
stroke: 'var(--color-border-primary-light)'
|
|
13
13
|
};
|
|
14
|
-
const
|
|
14
|
+
const renderTick = renderAxisTick(({ index, visibleTicksCount })=>{
|
|
15
|
+
if (0 === index) return {
|
|
16
|
+
anchor: 'start'
|
|
17
|
+
};
|
|
18
|
+
if (index === visibleTicksCount - 1) return {
|
|
19
|
+
anchor: 'end'
|
|
20
|
+
};
|
|
21
|
+
return {};
|
|
22
|
+
});
|
|
23
|
+
const LineChartXAxis = ({ tickFormatter, density, interval = 'preserveStartEnd', tickCount, ticks, minTickGap, domain, padding, type, hideTicks = false, axisLine = true })=>{
|
|
15
24
|
const dataCtx = useContext(LineChartDataContext);
|
|
16
25
|
const xKey = dataCtx?.xKey ?? 'x';
|
|
17
26
|
const resolvedMinTickGap = minTickGap ?? (density ? DENSITY_MIN_TICK_GAP[density] : void 0);
|
|
@@ -20,7 +29,7 @@ const LineChartXAxis = ({ tickFormatter, density, interval, tickCount, ticks, mi
|
|
|
20
29
|
type: type,
|
|
21
30
|
tickLine: false,
|
|
22
31
|
axisLine: axisLine ? AXIS_LINE_PROPS : false,
|
|
23
|
-
tick: hideTicks ? false :
|
|
32
|
+
tick: hideTicks ? false : renderTick,
|
|
24
33
|
tickFormatter: tickFormatter,
|
|
25
34
|
interval: interval,
|
|
26
35
|
tickCount: tickCount,
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return /*#__PURE__*/ jsx(Text, {
|
|
9
|
-
x: x,
|
|
10
|
-
y: y,
|
|
11
|
-
textAnchor: textAnchor,
|
|
12
|
-
verticalAnchor: verticalAnchor,
|
|
13
|
-
...LINE_AXIS_TICK_TEXT_PROPS,
|
|
14
|
-
children: value
|
|
15
|
-
});
|
|
16
|
-
};
|
|
2
|
+
import { YAxis } from "recharts";
|
|
3
|
+
import { LINE_Y_LABEL_WIDTH } from "./constants.js";
|
|
4
|
+
import { renderAxisTick } from "./lib/renderAxisTick.js";
|
|
5
|
+
const renderTick = renderAxisTick(({ index, visibleTicksCount })=>({
|
|
6
|
+
skip: index === visibleTicksCount - 1
|
|
7
|
+
}));
|
|
17
8
|
const LineChartYAxis = ({ tickFormatter, tickCount, ticks, domain, padding, width = LINE_Y_LABEL_WIDTH, hideTicks = false })=>/*#__PURE__*/ jsx(YAxis, {
|
|
18
9
|
width: width,
|
|
19
10
|
tickLine: false,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useEffect, useMemo, useRef } from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
|
-
import { ReferenceArea } from "recharts";
|
|
4
|
+
import { ReferenceArea, usePlotArea } from "recharts";
|
|
5
|
+
import { formatChartDateTime } from "../lib/timeFormatters.js";
|
|
5
6
|
import { lineChartZoomCursorPopoverClasses } from "./classes.js";
|
|
6
7
|
import { useZoomPendingListeners } from "./hooks/useZoomPendingListeners.js";
|
|
7
8
|
import { LineChartDataContext, LineChartZoomContext } from "./LineChartContext.js";
|
|
@@ -9,12 +10,24 @@ import { LineChartZoomPopover } from "./LineChartZoomPopover.js";
|
|
|
9
10
|
import { LineChartZoomPopoverConfirm } from "./LineChartZoomPopoverConfirm.js";
|
|
10
11
|
import { LineChartZoomPopoverRange } from "./LineChartZoomPopoverRange.js";
|
|
11
12
|
import { formatRange as formatRange_js_formatRange } from "./lib/formatRange.js";
|
|
13
|
+
const defaultFormatRange = formatRange_js_formatRange((value)=>formatChartDateTime(value) || String(value));
|
|
12
14
|
const POPOVER_OFFSET_X = 12;
|
|
13
|
-
const
|
|
14
|
-
const LineChartZoomBrush = ({ disabled = false, formatRange = formatRange_js_formatRange, confirmLabel = 'Zoom in', container })=>{
|
|
15
|
+
const LineChartZoomBrush = ({ disabled = false, formatRange = defaultFormatRange, confirmLabel = 'Zoom in', container })=>{
|
|
15
16
|
const dataCtx = useContext(LineChartDataContext);
|
|
16
17
|
const zoomCtx = useContext(LineChartZoomContext);
|
|
17
18
|
const popoverRef = useRef(null);
|
|
19
|
+
const plotArea = usePlotArea();
|
|
20
|
+
const rootRef = zoomCtx?.rootRef;
|
|
21
|
+
const centerY = useMemo(()=>{
|
|
22
|
+
if (!plotArea || !rootRef?.current) return null;
|
|
23
|
+
const surface = rootRef.current.querySelector('.recharts-surface');
|
|
24
|
+
if (!surface) return null;
|
|
25
|
+
const rect = surface.getBoundingClientRect();
|
|
26
|
+
return rect.top + plotArea.y + plotArea.height / 2;
|
|
27
|
+
}, [
|
|
28
|
+
plotArea,
|
|
29
|
+
rootRef
|
|
30
|
+
]);
|
|
18
31
|
const registerEnabled = zoomCtx?.registerEnabled;
|
|
19
32
|
useEffect(()=>{
|
|
20
33
|
if (disabled || !registerEnabled) return;
|
|
@@ -27,7 +40,6 @@ const LineChartZoomBrush = ({ disabled = false, formatRange = formatRange_js_for
|
|
|
27
40
|
const pending = zoomCtx?.pending ?? null;
|
|
28
41
|
const cancelPending = zoomCtx?.cancelPending;
|
|
29
42
|
const confirmZoom = zoomCtx?.confirmZoom;
|
|
30
|
-
const rootRef = zoomCtx?.rootRef;
|
|
31
43
|
useZoomPendingListeners({
|
|
32
44
|
enabled: null !== pending,
|
|
33
45
|
rootRef,
|
|
@@ -67,9 +79,9 @@ const LineChartZoomBrush = ({ disabled = false, formatRange = formatRange_js_for
|
|
|
67
79
|
"data-zoom-state": isPending ? 'pending' : 'dragging',
|
|
68
80
|
className: lineChartZoomCursorPopoverClasses,
|
|
69
81
|
style: {
|
|
70
|
-
top: popoverPosition.clientY
|
|
82
|
+
top: centerY ?? popoverPosition.clientY,
|
|
71
83
|
left: popoverPosition.clientX + POPOVER_OFFSET_X,
|
|
72
|
-
transform: 'translateY(-
|
|
84
|
+
transform: 'translateY(-50%)',
|
|
73
85
|
pointerEvents: isPending ? 'auto' : 'none'
|
|
74
86
|
},
|
|
75
87
|
onMouseDown: (e)=>e.stopPropagation(),
|
|
@@ -92,8 +104,7 @@ const LineChartZoomBrush = ({ disabled = false, formatRange = formatRange_js_for
|
|
|
92
104
|
x2: range.to,
|
|
93
105
|
fill: "var(--color-states-primary-hover)",
|
|
94
106
|
fillOpacity: 1,
|
|
95
|
-
stroke: "
|
|
96
|
-
strokeOpacity: 1,
|
|
107
|
+
stroke: "none",
|
|
97
108
|
ifOverflow: "visible"
|
|
98
109
|
}) : null,
|
|
99
110
|
popoverContent ? /*#__PURE__*/ createPortal(popoverContent, container ?? document.body) : null
|
|
@@ -6,7 +6,7 @@ const lineChartZoomCursorPopoverClasses = "fixed z-30 pointer-events-none";
|
|
|
6
6
|
const lineChartLegendVariants = cva('flex', {
|
|
7
7
|
variants: {
|
|
8
8
|
orientation: {
|
|
9
|
-
horizontal: 'flex-row flex-wrap items-center gap-6 pl-12 py-2',
|
|
9
|
+
horizontal: 'flex-row flex-wrap items-center gap-6 pl-12 py-2 [&:last-child]:pb-8',
|
|
10
10
|
vertical: 'flex-col gap-6 px-12 py-2 max-w-160'
|
|
11
11
|
},
|
|
12
12
|
align: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { CHART_PALETTE_FILL as LINE_STROKE_FILL, resolveChartColor as resolveSeriesColor, } from '../lib/chartPalette';
|
|
2
2
|
export declare const LINE_STROKE_WIDTH = 2;
|
|
3
3
|
export declare const LINE_DASH_DASHARRAY = "6 4";
|
|
4
|
-
export declare const LINE_ACTIVE_DOT_RADIUS = 4;
|
|
5
4
|
export declare const LINE_GRID_DASHARRAY = "4 4";
|
|
5
|
+
export declare const LINE_CURSOR_DASHARRAY = "4 2";
|
|
6
6
|
export declare const LINE_ANIMATION_DURATION = 400;
|
|
7
7
|
export declare const LINE_ANIMATION_BEGIN = 0;
|
|
8
8
|
export declare const LINE_INACTIVE_OPACITY = 0.3;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CHART_PALETTE_FILL, resolveChartColor } from "../lib/chartPalette.js";
|
|
2
2
|
const LINE_STROKE_WIDTH = 2;
|
|
3
3
|
const LINE_DASH_DASHARRAY = '6 4';
|
|
4
|
-
const LINE_ACTIVE_DOT_RADIUS = 4;
|
|
5
4
|
const LINE_GRID_DASHARRAY = '4 4';
|
|
5
|
+
const LINE_CURSOR_DASHARRAY = '4 2';
|
|
6
6
|
const LINE_ANIMATION_DURATION = 400;
|
|
7
7
|
const LINE_ANIMATION_BEGIN = 0;
|
|
8
8
|
const LINE_INACTIVE_OPACITY = 0.3;
|
|
@@ -23,4 +23,4 @@ const LINE_AXIS_TICK_TEXT_PROPS = {
|
|
|
23
23
|
fontFamily: 'var(--font-sans)',
|
|
24
24
|
fontWeight: 400
|
|
25
25
|
};
|
|
26
|
-
export { HOVER_POPOVER_TOP,
|
|
26
|
+
export { HOVER_POPOVER_TOP, LINE_ANIMATION_BEGIN, LINE_ANIMATION_DURATION, LINE_AXIS_TICK_TEXT_PROPS, LINE_CARD_HEIGHT, LINE_CURSOR_DASHARRAY, LINE_DASH_DASHARRAY, LINE_DEFAULT_BODY_MARGIN, LINE_GRID_DASHARRAY, LINE_HEADER_HEIGHT, LINE_INACTIVE_OPACITY, CHART_PALETTE_FILL as LINE_STROKE_FILL, LINE_STROKE_WIDTH, LINE_X_LABEL_HEIGHT, LINE_Y_LABEL_WIDTH, resolveChartColor as resolveSeriesColor };
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* `DateFormatProvider`. Falls back to `String(value)` for non-numeric X values.
|
|
7
|
-
* Consumers override via the `formatRange` prop on `<LineChartZoomBrush>`.
|
|
8
|
-
*/
|
|
9
|
-
export declare const formatRange: (range: LineChartZoomRange) => string;
|
|
1
|
+
/** Higher-order range formatter — joins `format(from)` and `format(to)` with `→`. */
|
|
2
|
+
export declare const formatRange: (format: (value: unknown) => string) => (range: {
|
|
3
|
+
from: unknown;
|
|
4
|
+
to: unknown;
|
|
5
|
+
}) => string;
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
const formatRange = (range)=>{
|
|
3
|
-
const from = formatChartDateTime(range.from) || String(range.from);
|
|
4
|
-
const to = formatChartDateTime(range.to) || String(range.to);
|
|
5
|
-
return `${from} → ${to}`;
|
|
6
|
-
};
|
|
1
|
+
const formatRange = (format)=>(range)=>`${format(range.from)} → ${format(range.to)}`;
|
|
7
2
|
export { formatRange };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { TextAnchor } from 'recharts/types/component/Text';
|
|
3
|
+
import type { XAxisTickContentProps, YAxisTickContentProps } from 'recharts/types/util/types';
|
|
4
|
+
export interface AxisTickDecision {
|
|
5
|
+
/** When `true`, render nothing for this tick. */
|
|
6
|
+
skip?: boolean;
|
|
7
|
+
/** Override the axis-derived text anchor. */
|
|
8
|
+
anchor?: TextAnchor;
|
|
9
|
+
}
|
|
10
|
+
type AxisTickProps = XAxisTickContentProps | YAxisTickContentProps;
|
|
11
|
+
type Decide<T extends AxisTickProps> = (props: T) => AxisTickDecision;
|
|
12
|
+
export declare const renderAxisTick: <T extends AxisTickProps>(decide?: Decide<T>) => (props: T) => ReactNode;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Text } from "recharts";
|
|
3
|
+
import { LINE_AXIS_TICK_TEXT_PROPS } from "../constants.js";
|
|
4
|
+
const renderAxisTick = (decide)=>(props)=>{
|
|
5
|
+
const decision = decide?.(props) ?? {};
|
|
6
|
+
if (decision.skip) return null;
|
|
7
|
+
const { x, y, payload, textAnchor, verticalAnchor, tickFormatter, orientation } = props;
|
|
8
|
+
const value = tickFormatter ? tickFormatter(payload.value, payload.index) : payload.value;
|
|
9
|
+
const isHorizontal = 'top' === orientation || 'bottom' === orientation;
|
|
10
|
+
const anchorToCoordinate = null != decision.anchor;
|
|
11
|
+
return /*#__PURE__*/ jsx(Text, {
|
|
12
|
+
x: anchorToCoordinate && isHorizontal ? payload.coordinate : x,
|
|
13
|
+
y: anchorToCoordinate && !isHorizontal ? payload.coordinate : y,
|
|
14
|
+
textAnchor: decision.anchor ?? textAnchor,
|
|
15
|
+
verticalAnchor: verticalAnchor,
|
|
16
|
+
...LINE_AXIS_TICK_TEXT_PROPS,
|
|
17
|
+
children: value
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export { renderAxisTick };
|
|
@@ -3,7 +3,7 @@ const jitter = (i, seed, salt)=>{
|
|
|
3
3
|
return v - Math.floor(v);
|
|
4
4
|
};
|
|
5
5
|
const genHourly = (count, seed = 1)=>{
|
|
6
|
-
const start = Date
|
|
6
|
+
const start = new Date(2025, 0, 1, 0, 0, 0).getTime();
|
|
7
7
|
const out = [];
|
|
8
8
|
for(let i = 0; i < count; i++){
|
|
9
9
|
const t = start + 60 * i * 60000;
|
|
@@ -20,7 +20,7 @@ const genHourly = (count, seed = 1)=>{
|
|
|
20
20
|
return out;
|
|
21
21
|
};
|
|
22
22
|
const genDaily = (count)=>{
|
|
23
|
-
const start = Date
|
|
23
|
+
const start = new Date(2024, 0, 1, 0, 0, 0).getTime();
|
|
24
24
|
const out = [];
|
|
25
25
|
for(let i = 0; i < count; i++){
|
|
26
26
|
const t = start + 24 * i * 3600000;
|
|
@@ -90,7 +90,7 @@ const dailyData60 = genDaily(60);
|
|
|
90
90
|
const hourlyData1000 = genHourly(1000);
|
|
91
91
|
const singlePointData = [
|
|
92
92
|
{
|
|
93
|
-
timestamp: Date
|
|
93
|
+
timestamp: new Date(2025, 0, 1, 12, 0, 0).getTime(),
|
|
94
94
|
requests: 142
|
|
95
95
|
}
|
|
96
96
|
];
|
|
@@ -7,11 +7,6 @@ export interface ChartTimeFormatters {
|
|
|
7
7
|
formatHourWithTimezone: (value: unknown) => ReactNode;
|
|
8
8
|
formatDateWithTimezone: (value: unknown) => ReactNode;
|
|
9
9
|
formatDateTimeWithTimezone: (value: unknown) => ReactNode;
|
|
10
|
-
/** `from → to` using `formatDate`. Suitable for `<LineChartZoomBrush formatRange>`. */
|
|
11
|
-
formatDateRange: (range: {
|
|
12
|
-
from: unknown;
|
|
13
|
-
to: unknown;
|
|
14
|
-
}) => string;
|
|
15
10
|
}
|
|
16
11
|
/**
|
|
17
12
|
* Memoised bundle of chart time formatters bound to `DateFormatProvider`
|
|
@@ -22,8 +22,7 @@ const useChartTimeFormatters = ()=>{
|
|
|
22
22
|
formatTimezone: formatChartTimezone,
|
|
23
23
|
formatHourWithTimezone: withTimezoneChip(formatHour),
|
|
24
24
|
formatDateWithTimezone: withTimezoneChip(formatDate),
|
|
25
|
-
formatDateTimeWithTimezone: withTimezoneChip(formatDateTime)
|
|
26
|
-
formatDateRange: ({ from, to })=>`${formatDate(from)} → ${formatDate(to)}`
|
|
25
|
+
formatDateTimeWithTimezone: withTimezoneChip(formatDateTime)
|
|
27
26
|
};
|
|
28
27
|
}, [
|
|
29
28
|
order,
|