@impulse-ui-native/charts 2.1.0 → 2.1.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/index.d.mts +17 -0
- package/dist/components/index.js +8 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/line-chart-body.d.mts +14 -0
- package/dist/components/line-chart-body.js +90 -0
- package/dist/components/line-chart-body.js.map +1 -0
- package/dist/components/line-chart.d.mts +10 -0
- package/dist/components/line-chart.js +21 -0
- package/dist/components/line-chart.js.map +1 -0
- package/dist/components/multi-line-chart-body.d.mts +11 -0
- package/dist/components/multi-line-chart-body.js +98 -0
- package/dist/components/multi-line-chart-body.js.map +1 -0
- package/dist/components/multi-line-chart.d.mts +11 -0
- package/dist/components/multi-line-chart.js +21 -0
- package/dist/components/multi-line-chart.js.map +1 -0
- package/dist/components/primitives/grid.d.mts +10 -0
- package/dist/components/primitives/grid.js +65 -0
- package/dist/components/primitives/grid.js.map +1 -0
- package/dist/components/primitives/index.d.mts +14 -0
- package/dist/components/primitives/index.js +13 -0
- package/dist/components/primitives/index.js.map +1 -0
- package/dist/components/primitives/label.d.mts +10 -0
- package/dist/components/primitives/label.js +94 -0
- package/dist/components/primitives/label.js.map +1 -0
- package/dist/components/primitives/line.d.mts +11 -0
- package/dist/components/primitives/line.js +50 -0
- package/dist/components/primitives/line.js.map +1 -0
- package/dist/components/primitives/x-axis.d.mts +11 -0
- package/dist/components/primitives/x-axis.js +93 -0
- package/dist/components/primitives/x-axis.js.map +1 -0
- package/dist/components/primitives/y-axis.d.mts +11 -0
- package/dist/components/primitives/y-axis.js +95 -0
- package/dist/components/primitives/y-axis.js.map +1 -0
- package/dist/constants/axis.constants.d.mts +6 -0
- package/dist/constants/axis.constants.js +11 -0
- package/dist/constants/axis.constants.js.map +1 -0
- package/dist/constants/grid.constants.d.mts +6 -0
- package/dist/constants/grid.constants.js +11 -0
- package/dist/constants/grid.constants.js.map +1 -0
- package/dist/constants/index.d.mts +11 -0
- package/dist/constants/index.js +6 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/label.constants.d.mts +11 -0
- package/dist/constants/label.constants.js +12 -0
- package/dist/constants/label.constants.js.map +1 -0
- package/dist/constants/line-chart.constants.d.mts +8 -0
- package/dist/constants/line-chart.constants.js +7 -0
- package/dist/constants/line-chart.constants.js.map +1 -0
- package/dist/constants/line.constants.d.mts +15 -0
- package/dist/constants/line.constants.js +18 -0
- package/dist/constants/line.constants.js.map +1 -0
- package/dist/contexts/index.d.mts +2 -0
- package/dist/contexts/index.js +1 -0
- package/dist/contexts/index.js.map +1 -0
- package/dist/hooks/index.d.mts +12 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/use-chart-canvas.hook.d.mts +9 -0
- package/dist/hooks/use-chart-canvas.hook.js +10 -0
- package/dist/hooks/use-chart-canvas.hook.js.map +1 -0
- package/dist/hooks/use-line-chart.hook.d.mts +10 -0
- package/dist/hooks/use-line-chart.hook.js +13 -0
- package/dist/hooks/use-line-chart.hook.js.map +1 -0
- package/dist/hooks/use-multi-line-chart.hook.d.mts +12 -0
- package/dist/hooks/use-multi-line-chart.hook.js +44 -0
- package/dist/hooks/use-multi-line-chart.hook.js.map +1 -0
- package/dist/index.d.mts +36 -321
- package/dist/index.js +6 -1083
- package/dist/index.js.map +1 -1
- package/dist/line-chart.types-yxru5uWc.d.mts +62 -0
- package/dist/types/axis.types.d.mts +49 -0
- package/dist/types/axis.types.js +1 -0
- package/dist/types/axis.types.js.map +1 -0
- package/dist/types/common.types.d.mts +57 -0
- package/dist/types/common.types.js +1 -0
- package/dist/types/common.types.js.map +1 -0
- package/dist/types/grid.types.d.mts +5 -0
- package/dist/types/grid.types.js +1 -0
- package/dist/types/grid.types.js.map +1 -0
- package/dist/types/index.d.mts +11 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/label.types.d.mts +24 -0
- package/dist/types/label.types.js +1 -0
- package/dist/types/label.types.js.map +1 -0
- package/dist/types/line-chart.types.d.mts +5 -0
- package/dist/types/line-chart.types.js +1 -0
- package/dist/types/line-chart.types.js.map +1 -0
- package/dist/types/line.types.d.mts +11 -0
- package/dist/types/line.types.js +1 -0
- package/dist/types/line.types.js.map +1 -0
- package/dist/types/multi-line-chart.types.d.mts +23 -0
- package/dist/types/multi-line-chart.types.js +1 -0
- package/dist/types/multi-line-chart.types.js.map +1 -0
- package/dist/types/style.types.d.mts +19 -0
- package/dist/types/style.types.js +1 -0
- package/dist/types/style.types.js.map +1 -0
- package/dist/types/use-line-chart.types.d.mts +29 -0
- package/dist/types/use-line-chart.types.js +1 -0
- package/dist/types/use-line-chart.types.js.map +1 -0
- package/dist/types/use-multi-line-chart.types.d.mts +16 -0
- package/dist/types/use-multi-line-chart.types.js +1 -0
- package/dist/types/use-multi-line-chart.types.js.map +1 -0
- package/dist/utils/axis.util.d.mts +15 -0
- package/dist/utils/axis.util.js +82 -0
- package/dist/utils/axis.util.js.map +1 -0
- package/dist/utils/chart-layout.util.d.mts +8 -0
- package/dist/utils/chart-layout.util.js +55 -0
- package/dist/utils/chart-layout.util.js.map +1 -0
- package/dist/utils/grid.util.d.mts +11 -0
- package/dist/utils/grid.util.js +56 -0
- package/dist/utils/grid.util.js.map +1 -0
- package/dist/utils/index.d.mts +17 -0
- package/dist/utils/index.js +44 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/label.util.d.mts +10 -0
- package/dist/utils/label.util.js +24 -0
- package/dist/utils/label.util.js.map +1 -0
- package/dist/utils/line-chart.util.d.mts +11 -0
- package/dist/utils/line-chart.util.js +133 -0
- package/dist/utils/line-chart.util.js.map +1 -0
- package/dist/utils/line.util.d.mts +10 -0
- package/dist/utils/line.util.js +36 -0
- package/dist/utils/line.util.js.map +1 -0
- package/dist/utils/multi-line-chart.util.d.mts +10 -0
- package/dist/utils/multi-line-chart.util.js +23 -0
- package/dist/utils/multi-line-chart.util.js.map +1 -0
- package/dist/utils/paragraph-builder.util.d.mts +10 -0
- package/dist/utils/paragraph-builder.util.js +16 -0
- package/dist/utils/paragraph-builder.util.js.map +1 -0
- package/package.json +7 -6
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
function createAxisTicks(values, scale) {
|
|
2
|
+
return values.reduce((ticks, value) => {
|
|
3
|
+
const position = scale(value);
|
|
4
|
+
if (position !== void 0 && Number.isFinite(position)) {
|
|
5
|
+
ticks.push({ value, position });
|
|
6
|
+
}
|
|
7
|
+
return ticks;
|
|
8
|
+
}, []);
|
|
9
|
+
}
|
|
10
|
+
function createXAxisLayout(props) {
|
|
11
|
+
const ticks = createAxisTicks(props.values, props.scale);
|
|
12
|
+
const axisY = props.plot.y + props.plot.height;
|
|
13
|
+
const labelOffset = props.tickLength + props.labelGap;
|
|
14
|
+
return {
|
|
15
|
+
line: {
|
|
16
|
+
start: { x: props.plot.x, y: axisY },
|
|
17
|
+
end: { x: props.plot.x + props.plot.width, y: axisY }
|
|
18
|
+
},
|
|
19
|
+
ticks: ticks.map((tick, index) => ({
|
|
20
|
+
...tick,
|
|
21
|
+
start: { x: tick.position, y: axisY },
|
|
22
|
+
end: { x: tick.position, y: axisY + props.tickLength },
|
|
23
|
+
labelRect: createXAxisLabelRect(ticks, index, props.region, labelOffset)
|
|
24
|
+
}))
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createYAxisLayout(props) {
|
|
28
|
+
const ticks = createAxisTicks(props.values, props.scale);
|
|
29
|
+
const axisX = props.plot.x;
|
|
30
|
+
const labelWidth = props.region.width - props.tickLength - props.labelGap;
|
|
31
|
+
return {
|
|
32
|
+
line: {
|
|
33
|
+
start: { x: axisX, y: props.plot.y },
|
|
34
|
+
end: { x: axisX, y: props.plot.y + props.plot.height }
|
|
35
|
+
},
|
|
36
|
+
ticks: ticks.map((tick) => ({
|
|
37
|
+
...tick,
|
|
38
|
+
start: { x: axisX - props.tickLength, y: tick.position },
|
|
39
|
+
end: { x: axisX, y: tick.position },
|
|
40
|
+
labelRect: createYAxisLabelRect(
|
|
41
|
+
tick.position,
|
|
42
|
+
props.region,
|
|
43
|
+
labelWidth,
|
|
44
|
+
props.fontSize
|
|
45
|
+
)
|
|
46
|
+
}))
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function createXAxisLabelRect(ticks, index, region, offset) {
|
|
50
|
+
const tick = ticks[index];
|
|
51
|
+
const previous = ticks[index - 1];
|
|
52
|
+
const next = ticks[index + 1];
|
|
53
|
+
const previousSpacing = previous ? Math.abs(tick.position - previous.position) : next ? Math.abs(next.position - tick.position) : region.width;
|
|
54
|
+
const nextSpacing = next ? Math.abs(next.position - tick.position) : previous ? Math.abs(tick.position - previous.position) : region.width;
|
|
55
|
+
const width = Math.max(0, Math.min(previousSpacing, nextSpacing));
|
|
56
|
+
return {
|
|
57
|
+
x: tick.position - width / 2,
|
|
58
|
+
y: region.y + offset,
|
|
59
|
+
width,
|
|
60
|
+
height: Math.max(0, region.height - offset)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function createYAxisLabelRect(position, region, width, fontSize) {
|
|
64
|
+
return {
|
|
65
|
+
x: region.x,
|
|
66
|
+
y: position - fontSize,
|
|
67
|
+
width: Math.max(0, width),
|
|
68
|
+
height: fontSize * 2
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function formatAxisTick(value, format) {
|
|
72
|
+
return format ? format(value) : String(value);
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
createAxisTicks,
|
|
76
|
+
createXAxisLabelRect,
|
|
77
|
+
createXAxisLayout,
|
|
78
|
+
createYAxisLabelRect,
|
|
79
|
+
createYAxisLayout,
|
|
80
|
+
formatAxisTick
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=axis.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/axis.util.ts"],"sourcesContent":["import {\n AxisLayout,\n AxisTick,\n ChartRect,\n CreateAxisLayoutProps,\n CreateYAxisLayoutProps,\n LineChartScale,\n} from \"../types\";\n\nexport function createAxisTicks<Value>(\n values: readonly Value[],\n scale: LineChartScale<Value>,\n): AxisTick<Value>[] {\n return values.reduce<AxisTick<Value>[]>((ticks, value) => {\n const position = scale(value);\n\n if (position !== undefined && Number.isFinite(position)) {\n ticks.push({ value, position });\n }\n\n return ticks;\n }, []);\n}\n\nexport function createXAxisLayout<Value>(\n props: CreateAxisLayoutProps<Value>,\n): AxisLayout<Value> {\n const ticks = createAxisTicks(props.values, props.scale);\n const axisY = props.plot.y + props.plot.height;\n const labelOffset = props.tickLength + props.labelGap;\n\n return {\n line: {\n start: { x: props.plot.x, y: axisY },\n end: { x: props.plot.x + props.plot.width, y: axisY },\n },\n ticks: ticks.map((tick, index) => ({\n ...tick,\n start: { x: tick.position, y: axisY },\n end: { x: tick.position, y: axisY + props.tickLength },\n labelRect: createXAxisLabelRect(ticks, index, props.region, labelOffset),\n })),\n };\n}\n\nexport function createYAxisLayout(\n props: CreateYAxisLayoutProps,\n): AxisLayout<number> {\n const ticks = createAxisTicks(props.values, props.scale);\n const axisX = props.plot.x;\n const labelWidth = props.region.width - props.tickLength - props.labelGap;\n\n return {\n line: {\n start: { x: axisX, y: props.plot.y },\n end: { x: axisX, y: props.plot.y + props.plot.height },\n },\n ticks: ticks.map((tick) => ({\n ...tick,\n start: { x: axisX - props.tickLength, y: tick.position },\n end: { x: axisX, y: tick.position },\n labelRect: createYAxisLabelRect(\n tick.position,\n props.region,\n labelWidth,\n props.fontSize,\n ),\n })),\n };\n}\n\nexport function createXAxisLabelRect(\n ticks: readonly AxisTick<unknown>[],\n index: number,\n region: ChartRect,\n offset: number,\n): ChartRect {\n const tick = ticks[index]!;\n const previous = ticks[index - 1];\n const next = ticks[index + 1];\n const previousSpacing = previous\n ? Math.abs(tick.position - previous.position)\n : next\n ? Math.abs(next.position - tick.position)\n : region.width;\n const nextSpacing = next\n ? Math.abs(next.position - tick.position)\n : previous\n ? Math.abs(tick.position - previous.position)\n : region.width;\n const width = Math.max(0, Math.min(previousSpacing, nextSpacing));\n\n return {\n x: tick.position - width / 2,\n y: region.y + offset,\n width,\n height: Math.max(0, region.height - offset),\n };\n}\n\nexport function createYAxisLabelRect(\n position: number,\n region: ChartRect,\n width: number,\n fontSize: number,\n): ChartRect {\n return {\n x: region.x,\n y: position - fontSize,\n width: Math.max(0, width),\n height: fontSize * 2,\n };\n}\n\nexport function formatAxisTick<Value>(\n value: Value,\n format?: (value: Value) => string,\n): string {\n return format ? format(value) : String(value);\n}\n"],"mappings":"AASO,SAAS,gBACd,QACA,OACmB;AACnB,SAAO,OAAO,OAA0B,CAAC,OAAO,UAAU;AACxD,UAAM,WAAW,MAAM,KAAK;AAE5B,QAAI,aAAa,UAAa,OAAO,SAAS,QAAQ,GAAG;AACvD,YAAM,KAAK,EAAE,OAAO,SAAS,CAAC;AAAA,IAChC;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEO,SAAS,kBACd,OACmB;AACnB,QAAM,QAAQ,gBAAgB,MAAM,QAAQ,MAAM,KAAK;AACvD,QAAM,QAAQ,MAAM,KAAK,IAAI,MAAM,KAAK;AACxC,QAAM,cAAc,MAAM,aAAa,MAAM;AAE7C,SAAO;AAAA,IACL,MAAM;AAAA,MACJ,OAAO,EAAE,GAAG,MAAM,KAAK,GAAG,GAAG,MAAM;AAAA,MACnC,KAAK,EAAE,GAAG,MAAM,KAAK,IAAI,MAAM,KAAK,OAAO,GAAG,MAAM;AAAA,IACtD;AAAA,IACA,OAAO,MAAM,IAAI,CAAC,MAAM,WAAW;AAAA,MACjC,GAAG;AAAA,MACH,OAAO,EAAE,GAAG,KAAK,UAAU,GAAG,MAAM;AAAA,MACpC,KAAK,EAAE,GAAG,KAAK,UAAU,GAAG,QAAQ,MAAM,WAAW;AAAA,MACrD,WAAW,qBAAqB,OAAO,OAAO,MAAM,QAAQ,WAAW;AAAA,IACzE,EAAE;AAAA,EACJ;AACF;AAEO,S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SAAS,MAAM;AAAA,EAC5C;AACF;AAEO,SAAS,qBACd,UACA,QACA,OACA,UACW;AACX,SAAO;AAAA,IACL,GAAG,OAAO;AAAA,IACV,GAAG,WAAW;AAAA,IACd,OAAO,KAAK,IAAI,GAAG,KAAK;AAAA,IACxB,QAAQ,WAAW;AAAA,EACrB;AACF;AAEO,SAAS,eACd,OACA,QACQ;AACR,SAAO,SAAS,OAAO,KAAK,IAAI,OAAO,KAAK;AAC9C;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChartSize, ChartInsets, ChartLayout, ChartRect } from '../types/common.types.mjs';
|
|
2
|
+
import '../types/style.types.mjs';
|
|
3
|
+
import '@shopify/react-native-skia';
|
|
4
|
+
|
|
5
|
+
declare function createChartLayout(size: ChartSize, insets?: Partial<ChartInsets>): ChartLayout;
|
|
6
|
+
declare function createInsetRect(rect: ChartRect, amount: number): ChartRect;
|
|
7
|
+
|
|
8
|
+
export { createChartLayout, createInsetRect };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function createChartLayout(size, insets = {}) {
|
|
2
|
+
const resolvedInsets = {
|
|
3
|
+
top: insets.top ?? 0,
|
|
4
|
+
right: insets.right ?? 0,
|
|
5
|
+
bottom: insets.bottom ?? 0,
|
|
6
|
+
left: insets.left ?? 0
|
|
7
|
+
};
|
|
8
|
+
const plotWidth = Math.max(
|
|
9
|
+
0,
|
|
10
|
+
size.width - resolvedInsets.left - resolvedInsets.right
|
|
11
|
+
);
|
|
12
|
+
const plotHeight = Math.max(
|
|
13
|
+
0,
|
|
14
|
+
size.height - resolvedInsets.top - resolvedInsets.bottom
|
|
15
|
+
);
|
|
16
|
+
const plot = {
|
|
17
|
+
x: resolvedInsets.left,
|
|
18
|
+
y: resolvedInsets.top,
|
|
19
|
+
width: plotWidth,
|
|
20
|
+
height: plotHeight
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
size,
|
|
24
|
+
insets: resolvedInsets,
|
|
25
|
+
plot,
|
|
26
|
+
xAxis: {
|
|
27
|
+
x: plot.x,
|
|
28
|
+
y: plot.y + plot.height,
|
|
29
|
+
width: plot.width,
|
|
30
|
+
height: resolvedInsets.bottom
|
|
31
|
+
},
|
|
32
|
+
yAxis: {
|
|
33
|
+
x: 0,
|
|
34
|
+
y: plot.y,
|
|
35
|
+
width: resolvedInsets.left,
|
|
36
|
+
height: plot.height
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function createInsetRect(rect, amount) {
|
|
41
|
+
const inset = Math.max(0, amount);
|
|
42
|
+
const horizontalInset = Math.min(inset, rect.width / 2);
|
|
43
|
+
const verticalInset = Math.min(inset, rect.height / 2);
|
|
44
|
+
return {
|
|
45
|
+
x: rect.x + horizontalInset,
|
|
46
|
+
y: rect.y + verticalInset,
|
|
47
|
+
width: Math.max(0, rect.width - horizontalInset * 2),
|
|
48
|
+
height: Math.max(0, rect.height - verticalInset * 2)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
createChartLayout,
|
|
53
|
+
createInsetRect
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=chart-layout.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/chart-layout.util.ts"],"sourcesContent":["import { ChartInsets, ChartLayout, ChartRect, ChartSize } from \"../types\";\n\nexport function createChartLayout(\n size: ChartSize,\n insets: Partial<ChartInsets> = {},\n): ChartLayout {\n const resolvedInsets: ChartInsets = {\n top: insets.top ?? 0,\n right: insets.right ?? 0,\n bottom: insets.bottom ?? 0,\n left: insets.left ?? 0,\n };\n\n const plotWidth = Math.max(\n 0,\n size.width - resolvedInsets.left - resolvedInsets.right,\n );\n const plotHeight = Math.max(\n 0,\n size.height - resolvedInsets.top - resolvedInsets.bottom,\n );\n\n const plot = {\n x: resolvedInsets.left,\n y: resolvedInsets.top,\n width: plotWidth,\n height: plotHeight,\n };\n\n return {\n size,\n insets: resolvedInsets,\n plot,\n xAxis: {\n x: plot.x,\n y: plot.y + plot.height,\n width: plot.width,\n height: resolvedInsets.bottom,\n },\n yAxis: {\n x: 0,\n y: plot.y,\n width: resolvedInsets.left,\n height: plot.height,\n },\n };\n}\n\nexport function createInsetRect(rect: ChartRect, amount: number): ChartRect {\n const inset = Math.max(0, amount);\n const horizontalInset = Math.min(inset, rect.width / 2);\n const verticalInset = Math.min(inset, rect.height / 2);\n\n return {\n x: rect.x + horizontalInset,\n y: rect.y + verticalInset,\n width: Math.max(0, rect.width - horizontalInset * 2),\n height: Math.max(0, rect.height - verticalInset * 2),\n };\n}\n"],"mappings":"AAEO,SAAS,kBACd,MACA,SAA+B,CAAC,GACnB;AACb,QAAM,iBAA8B;AAAA,IAClC,KAAK,OAAO,OAAO;AAAA,IACnB,OAAO,OAAO,SAAS;AAAA,IACvB,QAAQ,OAAO,UAAU;AAAA,IACzB,MAAM,OAAO,QAAQ;AAAA,EACvB;AAEA,QAAM,YAAY,KAAK;AAAA,IACrB;AAAA,IACA,KAAK,QAAQ,eAAe,OAAO,eAAe;AAAA,EACpD;AACA,QAAM,aAAa,KAAK;AAAA,IACtB;AAAA,IACA,KAAK,SAAS,eAAe,MAAM,eAAe;AAAA,EACpD;AAEA,QAAM,OAAO;AAAA,IACX,GAAG,eAAe;AAAA,IAClB,GAAG,eAAe;AAAA,IAClB,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAEA,SAAO;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,OAAO;AAAA,MACL,GAAG,KAAK;AAAA,MACR,GAAG,KAAK,IAAI,KAAK;AAAA,MACjB,OAAO,KAAK;AAAA,MACZ,QAAQ,eAAe;AAAA,IACzB;AAAA,IACA,OAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAG,KAAK;AAAA,MACR,OAAO,eAAe;AAAA,MACtB,QAAQ,KAAK;AAAA,IACf;AAAA,EACF;AACF;AAEO,SAAS,gBAAgB,MAAiB,QAA2B;AAC1E,QAAM,QAAQ,KAAK,IAAI,GAAG,MAAM;AAChC,QAAM,kBAAkB,KAAK,IAAI,OAAO,KAAK,QAAQ,CAAC;AACtD,QAAM,gBAAgB,KAAK,IAAI,OAAO,KAAK,SAAS,CAAC;AAErD,SAAO;AAAA,IACL,GAAG,KAAK,IAAI;AAAA,IACZ,GAAG,KAAK,IAAI;AAAA,IACZ,OAAO,KAAK,IAAI,GAAG,KAAK,QAAQ,kBAAkB,CAAC;AAAA,IACnD,QAAQ,KAAK,IAAI,GAAG,KAAK,SAAS,gBAAgB,CAAC;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SkPath } from '@shopify/react-native-skia';
|
|
2
|
+
import { ChartRect } from '../types/common.types.mjs';
|
|
3
|
+
import { h as LineChartScale, C as ChartGridLineOptions, R as ResolvedGridLineOptions } from '../line-chart.types-yxru5uWc.mjs';
|
|
4
|
+
import '../types/style.types.mjs';
|
|
5
|
+
import '@impulse-ui-native/theme';
|
|
6
|
+
|
|
7
|
+
declare function createVerticalGridPath<Value>(values: readonly Value[], scale: LineChartScale<Value>, plot: ChartRect): SkPath | null;
|
|
8
|
+
declare function createHorizontalGridPath<Value>(values: readonly Value[], scale: LineChartScale<Value>, plot: ChartRect): SkPath | null;
|
|
9
|
+
declare function resolveGridLineOptions(options: boolean | ChartGridLineOptions | undefined, defaultVisible: boolean, defaultColor: string): ResolvedGridLineOptions;
|
|
10
|
+
|
|
11
|
+
export { createHorizontalGridPath, createVerticalGridPath, resolveGridLineOptions };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Skia } from "@shopify/react-native-skia";
|
|
2
|
+
import { GridDefaultOpacity, GridDefaultWidth } from "../constants";
|
|
3
|
+
import { createAxisTicks } from "./axis.util";
|
|
4
|
+
function createVerticalGridPath(values, scale, plot) {
|
|
5
|
+
const ticks = createAxisTicks(values, scale);
|
|
6
|
+
if (ticks.length === 0) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const path = Skia.Path.Make();
|
|
10
|
+
ticks.forEach(({ position }) => {
|
|
11
|
+
path.moveTo(position, plot.y);
|
|
12
|
+
path.lineTo(position, plot.y + plot.height);
|
|
13
|
+
});
|
|
14
|
+
return path;
|
|
15
|
+
}
|
|
16
|
+
function createHorizontalGridPath(values, scale, plot) {
|
|
17
|
+
const ticks = createAxisTicks(values, scale);
|
|
18
|
+
if (ticks.length === 0) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const path = Skia.Path.Make();
|
|
22
|
+
ticks.forEach(({ position }) => {
|
|
23
|
+
path.moveTo(plot.x, position);
|
|
24
|
+
path.lineTo(plot.x + plot.width, position);
|
|
25
|
+
});
|
|
26
|
+
return path;
|
|
27
|
+
}
|
|
28
|
+
function resolveGridLineOptions(options, defaultVisible, defaultColor) {
|
|
29
|
+
if (typeof options === "boolean") {
|
|
30
|
+
return {
|
|
31
|
+
visible: options,
|
|
32
|
+
color: defaultColor,
|
|
33
|
+
width: GridDefaultWidth,
|
|
34
|
+
opacity: GridDefaultOpacity
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
visible: isGridLineVisible(options, defaultVisible),
|
|
39
|
+
color: options?.color ?? defaultColor,
|
|
40
|
+
width: options?.width ?? GridDefaultWidth,
|
|
41
|
+
opacity: options?.opacity ?? GridDefaultOpacity,
|
|
42
|
+
dash: options?.dash
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function isGridLineVisible(options, defaultVisible) {
|
|
46
|
+
if (typeof options === "boolean") {
|
|
47
|
+
return options;
|
|
48
|
+
}
|
|
49
|
+
return options?.visible ?? defaultVisible;
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
createHorizontalGridPath,
|
|
53
|
+
createVerticalGridPath,
|
|
54
|
+
resolveGridLineOptions
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=grid.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/grid.util.ts"],"sourcesContent":["import { Skia, SkPath } from \"@shopify/react-native-skia\";\n\nimport { GridDefaultOpacity, GridDefaultWidth } from \"../constants\";\nimport {\n ChartGridLineOptions,\n ChartRect,\n LineChartScale,\n ResolvedGridLineOptions,\n} from \"../types\";\nimport { createAxisTicks } from \"./axis.util\";\n\nexport function createVerticalGridPath<Value>(\n values: readonly Value[],\n scale: LineChartScale<Value>,\n plot: ChartRect,\n): SkPath | null {\n const ticks = createAxisTicks(values, scale);\n\n if (ticks.length === 0) {\n return null;\n }\n\n const path = Skia.Path.Make();\n\n ticks.forEach(({ position }) => {\n path.moveTo(position, plot.y);\n path.lineTo(position, plot.y + plot.height);\n });\n\n return path;\n}\n\nexport function createHorizontalGridPath<Value>(\n values: readonly Value[],\n scale: LineChartScale<Value>,\n plot: ChartRect,\n): SkPath | null {\n const ticks = createAxisTicks(values, scale);\n\n if (ticks.length === 0) {\n return null;\n }\n\n const path = Skia.Path.Make();\n\n ticks.forEach(({ position }) => {\n path.moveTo(plot.x, position);\n path.lineTo(plot.x + plot.width, position);\n });\n\n return path;\n}\n\nexport function resolveGridLineOptions(\n options: boolean | ChartGridLineOptions | undefined,\n defaultVisible: boolean,\n defaultColor: string,\n): ResolvedGridLineOptions {\n if (typeof options === \"boolean\") {\n return {\n visible: options,\n color: defaultColor,\n width: GridDefaultWidth,\n opacity: GridDefaultOpacity,\n };\n }\n\n return {\n visible: isGridLineVisible(options, defaultVisible),\n color: options?.color ?? defaultColor,\n width: options?.width ?? GridDefaultWidth,\n opacity: options?.opacity ?? GridDefaultOpacity,\n dash: options?.dash,\n };\n}\n\nfunction isGridLineVisible(\n options: boolean | ChartGridLineOptions | undefined,\n defaultVisible: boolean,\n): boolean {\n if (typeof options === \"boolean\") {\n return options;\n }\n\n return options?.visible ?? defaultVisible;\n}\n"],"mappings":"AAAA,SAAS,YAAoB;AAE7B,SAAS,oBAAoB,wBAAwB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LabelRect, createYAxisLayout, formatAxisTick } from './axis.util.mjs';
|
|
2
|
+
export { createChartLayout, createInsetRect } from './chart-layout.util.mjs';
|
|
3
|
+
export { createHorizontalGridPath, createVerticalGridPath, resolveGridLineOptions } from './grid.util.mjs';
|
|
4
|
+
export { getLabelTextAlign, getLabelY } from './label.util.mjs';
|
|
5
|
+
export { createLinePath, fitLineCoordinatesToRect } from './line.util.mjs';
|
|
6
|
+
export { createLineChartCoordinates, createLineChartModel } from './line-chart.util.mjs';
|
|
7
|
+
export { createDrawableMultiLineChartSeries } from './multi-line-chart.util.mjs';
|
|
8
|
+
export { createParagraphBuilder } from './paragraph-builder.util.mjs';
|
|
9
|
+
import '../types/axis.types.mjs';
|
|
10
|
+
import '@shopify/react-native-skia';
|
|
11
|
+
import '@impulse-ui-native/theme';
|
|
12
|
+
import '../types/common.types.mjs';
|
|
13
|
+
import '../types/style.types.mjs';
|
|
14
|
+
import '../line-chart.types-yxru5uWc.mjs';
|
|
15
|
+
import '../types/label.types.mjs';
|
|
16
|
+
import '../types/use-line-chart.types.mjs';
|
|
17
|
+
import '../types/multi-line-chart.types.mjs';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAxisTicks,
|
|
3
|
+
createXAxisLayout,
|
|
4
|
+
createXAxisLabelRect,
|
|
5
|
+
createYAxisLayout,
|
|
6
|
+
createYAxisLabelRect,
|
|
7
|
+
formatAxisTick
|
|
8
|
+
} from "./axis.util";
|
|
9
|
+
import { createChartLayout, createInsetRect } from "./chart-layout.util";
|
|
10
|
+
import {
|
|
11
|
+
createHorizontalGridPath,
|
|
12
|
+
createVerticalGridPath,
|
|
13
|
+
resolveGridLineOptions
|
|
14
|
+
} from "./grid.util";
|
|
15
|
+
import { getLabelTextAlign, getLabelY } from "./label.util";
|
|
16
|
+
import { createLinePath, fitLineCoordinatesToRect } from "./line.util";
|
|
17
|
+
import {
|
|
18
|
+
createLineChartCoordinates,
|
|
19
|
+
createLineChartModel
|
|
20
|
+
} from "./line-chart.util";
|
|
21
|
+
import { createDrawableMultiLineChartSeries } from "./multi-line-chart.util";
|
|
22
|
+
import { createParagraphBuilder } from "./paragraph-builder.util";
|
|
23
|
+
export {
|
|
24
|
+
createAxisTicks,
|
|
25
|
+
createChartLayout,
|
|
26
|
+
createDrawableMultiLineChartSeries,
|
|
27
|
+
createHorizontalGridPath,
|
|
28
|
+
createInsetRect,
|
|
29
|
+
createLineChartCoordinates,
|
|
30
|
+
createLineChartModel,
|
|
31
|
+
createLinePath,
|
|
32
|
+
createParagraphBuilder,
|
|
33
|
+
createVerticalGridPath,
|
|
34
|
+
createXAxisLabelRect,
|
|
35
|
+
createXAxisLayout,
|
|
36
|
+
createYAxisLabelRect,
|
|
37
|
+
createYAxisLayout,
|
|
38
|
+
fitLineCoordinatesToRect,
|
|
39
|
+
formatAxisTick,
|
|
40
|
+
getLabelTextAlign,
|
|
41
|
+
getLabelY,
|
|
42
|
+
resolveGridLineOptions
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export {\n createAxisTicks,\n createXAxisLayout,\n createXAxisLabelRect,\n createYAxisLayout,\n createYAxisLabelRect,\n formatAxisTick,\n} from \"./axis.util\";\nexport { createChartLayout, createInsetRect } from \"./chart-layout.util\";\nexport {\n createHorizontalGridPath,\n createVerticalGridPath,\n resolveGridLineOptions,\n} from \"./grid.util\";\nexport { getLabelTextAlign, getLabelY } from \"./label.util\";\nexport { createLinePath, fitLineCoordinatesToRect } from \"./line.util\";\nexport {\n createLineChartCoordinates,\n createLineChartModel,\n} from \"./line-chart.util\";\nexport { createDrawableMultiLineChartSeries } from \"./multi-line-chart.util\";\nexport { createParagraphBuilder } from \"./paragraph-builder.util\";\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB,uBAAuB;AACnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB,iBAAiB;AAC7C,SAAS,gBAAgB,gCAAgC;AACzD;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0CAA0C;AACnD,SAAS,8BAA8B;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TextAlign } from '@shopify/react-native-skia';
|
|
2
|
+
import { ChartRect } from '../types/common.types.mjs';
|
|
3
|
+
import { LabelHorizontalAlignment, LabelVerticalAlignment } from '../types/label.types.mjs';
|
|
4
|
+
import '../types/style.types.mjs';
|
|
5
|
+
import '@impulse-ui-native/theme';
|
|
6
|
+
|
|
7
|
+
declare function getLabelTextAlign(alignment: LabelHorizontalAlignment): TextAlign;
|
|
8
|
+
declare function getLabelY(rect: ChartRect, paragraphHeight: number, alignment: LabelVerticalAlignment): number;
|
|
9
|
+
|
|
10
|
+
export { getLabelTextAlign, getLabelY };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TextAlign } from "@shopify/react-native-skia";
|
|
2
|
+
function getLabelTextAlign(alignment) {
|
|
3
|
+
if (alignment === "center") {
|
|
4
|
+
return TextAlign.Center;
|
|
5
|
+
}
|
|
6
|
+
if (alignment === "right") {
|
|
7
|
+
return TextAlign.Right;
|
|
8
|
+
}
|
|
9
|
+
return TextAlign.Left;
|
|
10
|
+
}
|
|
11
|
+
function getLabelY(rect, paragraphHeight, alignment) {
|
|
12
|
+
if (alignment === "center") {
|
|
13
|
+
return rect.y + (rect.height - paragraphHeight) / 2;
|
|
14
|
+
}
|
|
15
|
+
if (alignment === "bottom") {
|
|
16
|
+
return rect.y + rect.height - paragraphHeight;
|
|
17
|
+
}
|
|
18
|
+
return rect.y;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
getLabelTextAlign,
|
|
22
|
+
getLabelY
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=label.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/label.util.ts"],"sourcesContent":["import { TextAlign } from \"@shopify/react-native-skia\";\n\nimport {\n ChartRect,\n LabelHorizontalAlignment,\n LabelVerticalAlignment,\n} from \"../types\";\n\nexport function getLabelTextAlign(\n alignment: LabelHorizontalAlignment,\n): TextAlign {\n if (alignment === \"center\") {\n return TextAlign.Center;\n }\n\n if (alignment === \"right\") {\n return TextAlign.Right;\n }\n\n return TextAlign.Left;\n}\n\nexport function getLabelY(\n rect: ChartRect,\n paragraphHeight: number,\n alignment: LabelVerticalAlignment,\n): number {\n if (alignment === \"center\") {\n return rect.y + (rect.height - paragraphHeight) / 2;\n }\n\n if (alignment === \"bottom\") {\n return rect.y + rect.height - paragraphHeight;\n }\n\n return rect.y;\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAQnB,SAAS,kBACd,WACW;AACX,MAAI,cAAc,UAAU;AAC1B,WAAO,UAAU;AAAA,EACnB;AAEA,MAAI,cAAc,SAAS;AACzB,WAAO,UAAU;AAAA,EACnB;AAEA,SAAO,UAAU;AACnB;AAEO,SAAS,UACd,MACA,iBACA,WACQ;AACR,MAAI,cAAc,UAAU;AAC1B,WAAO,KAAK,KAAK,KAAK,SAAS,mBAAmB;AAAA,EACpD;AAEA,MAAI,cAAc,UAAU;AAC1B,WAAO,KAAK,IAAI,KAAK,SAAS;AAAA,EAChC;AAEA,SAAO,KAAK;AACd;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { b as ChartXValue, f as LineChartPoint, h as LineChartScale, c as LineChartCoordinate } from '../line-chart.types-yxru5uWc.mjs';
|
|
2
|
+
import { UseLineChartProps, UseLineChartResult } from '../types/use-line-chart.types.mjs';
|
|
3
|
+
import '@shopify/react-native-skia';
|
|
4
|
+
import '../types/common.types.mjs';
|
|
5
|
+
import '../types/style.types.mjs';
|
|
6
|
+
import '@impulse-ui-native/theme';
|
|
7
|
+
|
|
8
|
+
declare function createLineChartModel<X extends ChartXValue>(props: UseLineChartProps<X>): UseLineChartResult<X>;
|
|
9
|
+
declare function createLineChartCoordinates<X extends ChartXValue>(data: readonly LineChartPoint<X>[], xScale: LineChartScale<X>, yScale: LineChartScale<number>): LineChartCoordinate<X>[];
|
|
10
|
+
|
|
11
|
+
export { createLineChartCoordinates, createLineChartModel };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { extent } from "d3-array";
|
|
2
|
+
import { scaleLinear, scalePoint, scaleTime } from "d3-scale";
|
|
3
|
+
import {
|
|
4
|
+
LineChartDefaultNumericDomain,
|
|
5
|
+
LineChartDefaultTickCount
|
|
6
|
+
} from "../constants";
|
|
7
|
+
function createLineChartModel(props) {
|
|
8
|
+
const xTickCount = getTickCount(props.xAxis?.tickCount);
|
|
9
|
+
const yTickCount = getTickCount(props.yAxis?.tickCount);
|
|
10
|
+
const xRange = [
|
|
11
|
+
props.plot.x,
|
|
12
|
+
props.plot.x + props.plot.width
|
|
13
|
+
];
|
|
14
|
+
const yRange = [
|
|
15
|
+
props.plot.y + props.plot.height,
|
|
16
|
+
props.plot.y
|
|
17
|
+
];
|
|
18
|
+
const xModel = createXScale(
|
|
19
|
+
props.data.map((point) => point.x),
|
|
20
|
+
props.xScaleType ?? "linear",
|
|
21
|
+
xRange,
|
|
22
|
+
xTickCount
|
|
23
|
+
);
|
|
24
|
+
const yValues = props.data.reduce((values, point) => {
|
|
25
|
+
if (point.y !== null && Number.isFinite(point.y)) {
|
|
26
|
+
values.push(point.y);
|
|
27
|
+
}
|
|
28
|
+
return values;
|
|
29
|
+
}, []);
|
|
30
|
+
const yDomain = props.yAxis?.domain ?? getNumericDomain(yValues);
|
|
31
|
+
const d3YScale = scaleLinear().domain(yDomain).range(yRange);
|
|
32
|
+
if (!props.yAxis?.domain && yTickCount > 0) {
|
|
33
|
+
d3YScale.nice(yTickCount);
|
|
34
|
+
}
|
|
35
|
+
const resolvedYDomain = d3YScale.domain();
|
|
36
|
+
const yScale = (value) => d3YScale(value);
|
|
37
|
+
const coordinates = createLineChartCoordinates(
|
|
38
|
+
props.data,
|
|
39
|
+
xModel.scale,
|
|
40
|
+
yScale
|
|
41
|
+
);
|
|
42
|
+
return {
|
|
43
|
+
xDomain: xModel.domain,
|
|
44
|
+
yDomain: resolvedYDomain,
|
|
45
|
+
xTicks: xModel.ticks,
|
|
46
|
+
yTicks: d3YScale.ticks(yTickCount),
|
|
47
|
+
coordinates,
|
|
48
|
+
xScale: xModel.scale,
|
|
49
|
+
yScale
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function createLineChartCoordinates(data, xScale, yScale) {
|
|
53
|
+
return data.map((datum, index) => {
|
|
54
|
+
const x = xScale(datum.x);
|
|
55
|
+
const y = datum.y === null ? void 0 : yScale(datum.y);
|
|
56
|
+
return {
|
|
57
|
+
datum,
|
|
58
|
+
index,
|
|
59
|
+
x: isFiniteCoordinate(x) ? x : null,
|
|
60
|
+
y: isFiniteCoordinate(y) ? y : null
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function createXScale(values, scaleType, range, tickCount) {
|
|
65
|
+
if (scaleType === "point") {
|
|
66
|
+
const d3Scale2 = scalePoint().domain(values).range(range);
|
|
67
|
+
const domain = d3Scale2.domain();
|
|
68
|
+
return {
|
|
69
|
+
domain,
|
|
70
|
+
ticks: selectPointTicks(domain, tickCount),
|
|
71
|
+
scale: (value) => d3Scale2(value)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (scaleType === "time") {
|
|
75
|
+
const dates = values.filter(
|
|
76
|
+
(value) => value instanceof Date && Number.isFinite(value.getTime())
|
|
77
|
+
);
|
|
78
|
+
const [minimum, maximum] = extent(dates);
|
|
79
|
+
const domain = minimum && maximum ? [minimum, maximum] : [/* @__PURE__ */ new Date(0), /* @__PURE__ */ new Date(1)];
|
|
80
|
+
const d3Scale2 = scaleTime().domain(domain).range(range);
|
|
81
|
+
if (tickCount > 0) {
|
|
82
|
+
d3Scale2.nice(tickCount);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
domain: d3Scale2.domain(),
|
|
86
|
+
ticks: d3Scale2.ticks(tickCount),
|
|
87
|
+
scale: (value) => value instanceof Date && Number.isFinite(value.getTime()) ? d3Scale2(value) : void 0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const numbers = values.filter(
|
|
91
|
+
(value) => typeof value === "number" && Number.isFinite(value)
|
|
92
|
+
);
|
|
93
|
+
const d3Scale = scaleLinear().domain(getNumericDomain(numbers)).range(range);
|
|
94
|
+
if (tickCount > 0) {
|
|
95
|
+
d3Scale.nice(tickCount);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
domain: d3Scale.domain(),
|
|
99
|
+
ticks: d3Scale.ticks(tickCount),
|
|
100
|
+
scale: (value) => typeof value === "number" && Number.isFinite(value) ? d3Scale(value) : void 0
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function getNumericDomain(values) {
|
|
104
|
+
const [minimum, maximum] = extent(values);
|
|
105
|
+
return minimum === void 0 || maximum === void 0 ? LineChartDefaultNumericDomain : [minimum, maximum];
|
|
106
|
+
}
|
|
107
|
+
function getTickCount(tickCount) {
|
|
108
|
+
return tickCount === void 0 || !Number.isFinite(tickCount) ? LineChartDefaultTickCount : Math.max(0, Math.floor(tickCount));
|
|
109
|
+
}
|
|
110
|
+
function selectPointTicks(values, tickCount) {
|
|
111
|
+
if (tickCount <= 0 || values.length === 0) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
if (values.length <= tickCount) {
|
|
115
|
+
return [...values];
|
|
116
|
+
}
|
|
117
|
+
if (tickCount === 1) {
|
|
118
|
+
return [values[0]];
|
|
119
|
+
}
|
|
120
|
+
const lastIndex = values.length - 1;
|
|
121
|
+
return Array.from({ length: tickCount }, (_, index) => {
|
|
122
|
+
const valueIndex = Math.round(index * lastIndex / (tickCount - 1));
|
|
123
|
+
return values[valueIndex];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function isFiniteCoordinate(value) {
|
|
127
|
+
return value !== void 0 && Number.isFinite(value);
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
createLineChartCoordinates,
|
|
131
|
+
createLineChartModel
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=line-chart.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/line-chart.util.ts"],"sourcesContent":["import { extent } from \"d3-array\";\nimport { scaleLinear, scalePoint, scaleTime } from \"d3-scale\";\n\nimport {\n LineChartDefaultNumericDomain,\n LineChartDefaultTickCount,\n} from \"../constants\";\nimport {\n ChartNumericDomain,\n ChartXValue,\n LineChartCoordinate,\n LineChartPoint,\n LineChartScale,\n LineChartXScaleModel,\n UseLineChartProps,\n UseLineChartResult,\n} from \"../types\";\n\nexport function createLineChartModel<X extends ChartXValue>(\n props: UseLineChartProps<X>,\n): UseLineChartResult<X> {\n const xTickCount = getTickCount(props.xAxis?.tickCount);\n const yTickCount = getTickCount(props.yAxis?.tickCount);\n const xRange: ChartNumericDomain = [\n props.plot.x,\n props.plot.x + props.plot.width,\n ];\n const yRange: ChartNumericDomain = [\n props.plot.y + props.plot.height,\n props.plot.y,\n ];\n\n const xModel = createXScale(\n props.data.map((point) => point.x),\n props.xScaleType ?? \"linear\",\n xRange,\n xTickCount,\n );\n\n const yValues = props.data.reduce<number[]>((values, point) => {\n if (point.y !== null && Number.isFinite(point.y)) {\n values.push(point.y);\n }\n\n return values;\n }, []);\n const yDomain = props.yAxis?.domain ?? getNumericDomain(yValues);\n const d3YScale = scaleLinear().domain(yDomain).range(yRange);\n\n if (!props.yAxis?.domain && yTickCount > 0) {\n d3YScale.nice(yTickCount);\n }\n\n const resolvedYDomain = d3YScale.domain() as [number, number];\n const yScale: LineChartScale<number> = (value) => d3YScale(value);\n const coordinates = createLineChartCoordinates(\n props.data,\n xModel.scale,\n yScale,\n );\n\n return {\n xDomain: xModel.domain,\n yDomain: resolvedYDomain,\n xTicks: xModel.ticks,\n yTicks: d3YScale.ticks(yTickCount),\n coordinates,\n xScale: xModel.scale,\n yScale,\n };\n}\n\nexport function createLineChartCoordinates<X extends ChartXValue>(\n data: readonly LineChartPoint<X>[],\n xScale: LineChartScale<X>,\n yScale: LineChartScale<number>,\n): LineChartCoordinate<X>[] {\n return data.map((datum, index) => {\n const x = xScale(datum.x);\n const y = datum.y === null ? undefined : yScale(datum.y);\n\n return {\n datum,\n index,\n x: isFiniteCoordinate(x) ? x : null,\n y: isFiniteCoordinate(y) ? y : null,\n };\n });\n}\n\nfunction createXScale<X extends ChartXValue>(\n values: readonly X[],\n scaleType: UseLineChartProps<X>[\"xScaleType\"],\n range: ChartNumericDomain,\n tickCount: number,\n): LineChartXScaleModel<X> {\n if (scaleType === \"point\") {\n const d3Scale = scalePoint<X>().domain(values).range(range);\n const domain = d3Scale.domain();\n\n return {\n domain,\n ticks: selectPointTicks(domain, tickCount),\n scale: (value) => d3Scale(value),\n };\n }\n\n if (scaleType === \"time\") {\n const dates = values.filter(\n (value): value is Extract<X, Date> =>\n value instanceof Date && Number.isFinite(value.getTime()),\n );\n const [minimum, maximum] = extent(dates);\n const domain =\n minimum && maximum\n ? ([minimum, maximum] as const)\n : ([new Date(0), new Date(1)] as const);\n const d3Scale = scaleTime().domain(domain).range(range);\n\n if (tickCount > 0) {\n d3Scale.nice(tickCount);\n }\n\n return {\n domain: d3Scale.domain() as X[],\n ticks: d3Scale.ticks(tickCount) as X[],\n scale: (value) =>\n value instanceof Date && Number.isFinite(value.getTime())\n ? d3Scale(value)\n : undefined,\n };\n }\n\n const numbers = values.filter(\n (value): value is Extract<X, number> =>\n typeof value === \"number\" && Number.isFinite(value),\n );\n const d3Scale = scaleLinear().domain(getNumericDomain(numbers)).range(range);\n\n if (tickCount > 0) {\n d3Scale.nice(tickCount);\n }\n\n return {\n domain: d3Scale.domain() as X[],\n ticks: d3Scale.ticks(tickCount) as X[],\n scale: (value) =>\n typeof value === \"number\" && Number.isFinite(value)\n ? d3Scale(value)\n : undefined,\n };\n}\n\nfunction getNumericDomain(values: readonly number[]): ChartNumericDomain {\n const [minimum, maximum] = extent(values);\n\n return minimum === undefined || maximum === undefined\n ? LineChartDefaultNumericDomain\n : [minimum, maximum];\n}\n\nfunction getTickCount(tickCount: number | undefined): number {\n return tickCount === undefined || !Number.isFinite(tickCount)\n ? LineChartDefaultTickCount\n : Math.max(0, Math.floor(tickCount));\n}\n\nfunction selectPointTicks<X>(values: readonly X[], tickCount: number): X[] {\n if (tickCount <= 0 || values.length === 0) {\n return [];\n }\n\n if (values.length <= tickCount) {\n return [...values];\n }\n\n if (tickCount === 1) {\n return [values[0]!];\n }\n\n const lastIndex = values.length - 1;\n\n return Array.from({ length: tickCount }, (_, index) => {\n const valueIndex = Math.round((index * lastIndex) / (tickCount - 1));\n\n return values[valueIndex]!;\n });\n}\n\nfunction isFiniteCoordinate(value: number | undefined): value is number {\n return value !== undefined && Number.isFinite(value);\n}\n"],"mappings":"AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,YAAY,iBAAiB;AAEnD;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAYA,SAAS,qBACd,OACuB;AACvB,QAAM,aAAa,aAAa,MAAM,OAAO,SAAS;AACtD,QAAM,aAAa,aAAa,MAAM,OAAO,SAAS;AACtD,QAAM,SAA6B;AAAA,IACjC,MAAM,KAAK;AAAA,IACX,MAAM,KAAK,IAAI,MAAM,KAAK;AAAA,EAC5B;AACA,QAAM,SAA6B;AAAA,IACjC,MAAM,KAAK,IAAI,MAAM,KAAK;AAAA,IAC1B,MAAM,KAAK;AAAA,EACb;AAEA,QAAM,SAAS;AAAA,IACb,MAAM,KAAK,IAAI,CAAC,UAAU,MAAM,CAAC;AAAA,IACjC,MAAM,cAAc;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAEA,QAAM,UAAU,MAAM,KAAK,OAAiB,CAA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A,CAAC,SAAS,OAAO;AACvB;AAEA,SAAS,aAAa,WAAuC;AAC3D,SAAO,cAAc,UAAa,CAAC,OAAO,SAAS,SAAS,IACxD,4BACA,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,CAAC;AACvC;AAEA,SAAS,iBAAoB,QAAsB,WAAwB;AACzE,MAAI,aAAa,KAAK,OAAO,WAAW,GAAG;AACzC,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,OAAO,UAAU,WAAW;AAC9B,WAAO,CAAC,GAAG,MAAM;AAAA,EACnB;AAEA,MAAI,cAAc,GAAG;AACnB,WAAO,CAAC,OAAO,CAAC,CAAE;AAAA,EACpB;AAEA,QAAM,YAAY,OAAO,SAAS;AAElC,SAAO,MAAM,KAAK,EAAE,QAAQ,UAAU,GAAG,CAAC,GAAG,UAAU;AACrD,UAAM,aAAa,KAAK,MAAO,QAAQ,aAAc,YAAY,EAAE;AAEnE,WAAO,OAAO,UAAU;AAAA,EAC1B,CAAC;AACH;AAEA,SAAS,mBAAmB,OAA4C;AACtE,SAAO,UAAU,UAAa,OAAO,SAAS,KAAK;AACrD;","names":["d3Scale"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SkPath } from '@shopify/react-native-skia';
|
|
2
|
+
import { ChartRect } from '../types/common.types.mjs';
|
|
3
|
+
import { b as ChartXValue, c as LineChartCoordinate, d as LineChartCurve } from '../line-chart.types-yxru5uWc.mjs';
|
|
4
|
+
import '../types/style.types.mjs';
|
|
5
|
+
import '@impulse-ui-native/theme';
|
|
6
|
+
|
|
7
|
+
declare function createLinePath<X extends ChartXValue>(coordinates: readonly LineChartCoordinate<X>[], curve: LineChartCurve): SkPath | null;
|
|
8
|
+
declare function fitLineCoordinatesToRect<X extends ChartXValue>(coordinates: readonly LineChartCoordinate<X>[], source: ChartRect, target: ChartRect): LineChartCoordinate<X>[];
|
|
9
|
+
|
|
10
|
+
export { createLinePath, fitLineCoordinatesToRect };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Skia } from "@shopify/react-native-skia";
|
|
2
|
+
import { line as createD3Line, curveLinear, curveMonotoneX } from "d3-shape";
|
|
3
|
+
function createLinePath(coordinates, curve) {
|
|
4
|
+
const pathData = createD3Line().defined((coordinate) => coordinate.x !== null && coordinate.y !== null).x((coordinate) => coordinate.x).y((coordinate) => coordinate.y).curve(curve === "monotone" ? curveMonotoneX : curveLinear)(coordinates);
|
|
5
|
+
return pathData ? Skia.Path.MakeFromSVGString(pathData) : null;
|
|
6
|
+
}
|
|
7
|
+
function fitLineCoordinatesToRect(coordinates, source, target) {
|
|
8
|
+
return coordinates.map((coordinate) => ({
|
|
9
|
+
...coordinate,
|
|
10
|
+
x: coordinate.x === null ? null : mapCoordinate(
|
|
11
|
+
coordinate.x,
|
|
12
|
+
source.x,
|
|
13
|
+
source.width,
|
|
14
|
+
target.x,
|
|
15
|
+
target.width
|
|
16
|
+
),
|
|
17
|
+
y: coordinate.y === null ? null : mapCoordinate(
|
|
18
|
+
coordinate.y,
|
|
19
|
+
source.y,
|
|
20
|
+
source.height,
|
|
21
|
+
target.y,
|
|
22
|
+
target.height
|
|
23
|
+
)
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
function mapCoordinate(value, sourceStart, sourceLength, targetStart, targetLength) {
|
|
27
|
+
if (sourceLength <= 0) {
|
|
28
|
+
return targetStart + targetLength / 2;
|
|
29
|
+
}
|
|
30
|
+
return targetStart + (value - sourceStart) / sourceLength * targetLength;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
createLinePath,
|
|
34
|
+
fitLineCoordinatesToRect
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=line.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/line.util.ts"],"sourcesContent":["import { Skia, SkPath } from \"@shopify/react-native-skia\";\nimport { line as createD3Line, curveLinear, curveMonotoneX } from \"d3-shape\";\n\nimport {\n ChartRect,\n ChartXValue,\n LineChartCoordinate,\n LineChartCurve,\n} from \"../types\";\n\nexport function createLinePath<X extends ChartXValue>(\n coordinates: readonly LineChartCoordinate<X>[],\n curve: LineChartCurve,\n): SkPath | null {\n const pathData = createD3Line<LineChartCoordinate<X>>()\n .defined((coordinate) => coordinate.x !== null && coordinate.y !== null)\n .x((coordinate) => coordinate.x!)\n .y((coordinate) => coordinate.y!)\n .curve(curve === \"monotone\" ? curveMonotoneX : curveLinear)(coordinates);\n\n return pathData ? Skia.Path.MakeFromSVGString(pathData) : null;\n}\n\nexport function fitLineCoordinatesToRect<X extends ChartXValue>(\n coordinates: readonly LineChartCoordinate<X>[],\n source: ChartRect,\n target: ChartRect,\n): LineChartCoordinate<X>[] {\n return coordinates.map((coordinate) => ({\n ...coordinate,\n x:\n coordinate.x === null\n ? null\n : mapCoordinate(\n coordinate.x,\n source.x,\n source.width,\n target.x,\n target.width,\n ),\n y:\n coordinate.y === null\n ? null\n : mapCoordinate(\n coordinate.y,\n source.y,\n source.height,\n target.y,\n target.height,\n ),\n }));\n}\n\nfunction mapCoordinate(\n value: number,\n sourceStart: number,\n sourceLength: number,\n targetStart: number,\n targetLength: number,\n): number {\n if (sourceLength <= 0) {\n return targetStart + targetLength / 2;\n }\n\n return targetStart + ((value - sourceStart) / sourceLength) * targetLength;\n}\n"],"mappings":"AAAA,SAAS,YAAoB;AAC7B,SAAS,QAAQ,cAAc,aAAa,sBAAsB;AAS3D,SAAS,eACd,aACA,OACe;AACf,QAAM,WAAW,aAAqC,EACnD,QAAQ,CAAC,eAAe,WAAW,MAAM,QAAQ,WAAW,MAAM,IAAI,EACtE,EAAE,CAAC,eAAe,WAAW,CAAE,EAC/B,EAAE,CAAC,eAAe,WAAW,CAAE,EAC/B,MAAM,UAAU,aAAa,iBAAiB,WAAW,EAAE,WAAW;AAEzE,SAAO,WAAW,KAAK,KAAK,kBAAkB,QAAQ,IAAI;AAC5D;AAEO,SAAS,yBACd,aACA,QACA,QAC0B;AAC1B,SAAO,YAAY,IAAI,CAAC,gBAAgB;AAAA,IACtC,GAAG;AAAA,IACH,GACE,WAAW,MAAM,OACb,OACA;AAAA,MACE,WAAW;AAAA,MACX,OAAO;AAAA,MACP,OAAO;AAAA,MACP,OAAO;AAAA,MACP,OAAO;AAAA,IACT;AAAA,IACN,GACE,WAAW,MAAM,OACb,OACA;AAAA,MACE,WAAW;AAAA,MACX,OAAO;AAAA,MACP,OAAO;AAAA,MACP,OAAO;AAAA,MACP,OAAO;AAAA,IACT;AAAA,EACR,EAAE;AACJ;AAEA,SAAS,cACP,OACA,aACA,cACA,aACA,cACQ;AACR,MAAI,gBAAgB,GAAG;AACrB,WAAO,cAAc,eAAe;AAAA,EACtC;AAEA,SAAO,eAAgB,QAAQ,eAAe,eAAgB;AAChE;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChartRect } from '../types/common.types.mjs';
|
|
2
|
+
import { b as ChartXValue } from '../line-chart.types-yxru5uWc.mjs';
|
|
3
|
+
import { MultiLineChartSeriesModel } from '../types/multi-line-chart.types.mjs';
|
|
4
|
+
import '../types/style.types.mjs';
|
|
5
|
+
import '@shopify/react-native-skia';
|
|
6
|
+
import '@impulse-ui-native/theme';
|
|
7
|
+
|
|
8
|
+
declare function createDrawableMultiLineChartSeries<X extends ChartXValue>(series: MultiLineChartSeriesModel<X>, index: number, plot: ChartRect): MultiLineChartSeriesModel<X>;
|
|
9
|
+
|
|
10
|
+
export { createDrawableMultiLineChartSeries };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LineDefaultColor,
|
|
3
|
+
LineDefaultColors,
|
|
4
|
+
LineDefaultWidth
|
|
5
|
+
} from "../constants";
|
|
6
|
+
import { createInsetRect } from "./chart-layout.util";
|
|
7
|
+
import { fitLineCoordinatesToRect } from "./line.util";
|
|
8
|
+
function createDrawableMultiLineChartSeries(series, index, plot) {
|
|
9
|
+
const width = series.line?.width ?? LineDefaultWidth;
|
|
10
|
+
const linePlot = createInsetRect(plot, width / 2);
|
|
11
|
+
return {
|
|
12
|
+
...series,
|
|
13
|
+
coordinates: fitLineCoordinatesToRect(series.coordinates, plot, linePlot),
|
|
14
|
+
line: {
|
|
15
|
+
...series.line,
|
|
16
|
+
color: series.line?.color ?? LineDefaultColors[index % LineDefaultColors.length] ?? LineDefaultColor
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
createDrawableMultiLineChartSeries
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=multi-line-chart.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/multi-line-chart.util.ts"],"sourcesContent":["import {\n LineDefaultColor,\n LineDefaultColors,\n LineDefaultWidth,\n} from \"../constants\";\nimport { ChartRect, ChartXValue, MultiLineChartSeriesModel } from \"../types\";\nimport { createInsetRect } from \"./chart-layout.util\";\nimport { fitLineCoordinatesToRect } from \"./line.util\";\n\nexport function createDrawableMultiLineChartSeries<X extends ChartXValue>(\n series: MultiLineChartSeriesModel<X>,\n index: number,\n plot: ChartRect,\n): MultiLineChartSeriesModel<X> {\n const width = series.line?.width ?? LineDefaultWidth;\n const linePlot = createInsetRect(plot, width / 2);\n\n return {\n ...series,\n coordinates: fitLineCoordinatesToRect(series.coordinates, plot, linePlot),\n line: {\n ...series.line,\n color:\n series.line?.color ??\n LineDefaultColors[index % LineDefaultColors.length] ??\n LineDefaultColor,\n },\n };\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AAElC,SAAS,mCACd,QACA,OACA,MAC8B;AAC9B,QAAM,QAAQ,OAAO,MAAM,SAAS;AACpC,QAAM,WAAW,gBAAgB,MAAM,QAAQ,CAAC;AAEhD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,aAAa,yBAAyB,OAAO,aAAa,MAAM,QAAQ;AAAA,IACxE,MAAM;AAAA,MACJ,GAAG,OAAO;AAAA,MACV,OACE,OAAO,MAAM,SACb,kBAAkB,QAAQ,kBAAkB,MAAM,KAClD;AAAA,IACJ;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _shopify_react_native_skia from '@shopify/react-native-skia';
|
|
2
|
+
import { SkParagraphStyle, SkTypefaceFontProvider } from '@shopify/react-native-skia';
|
|
3
|
+
|
|
4
|
+
interface CreateParagraphBuilderProps {
|
|
5
|
+
paragraphStyle?: SkParagraphStyle;
|
|
6
|
+
typefaceProvider?: SkTypefaceFontProvider;
|
|
7
|
+
}
|
|
8
|
+
declare function createParagraphBuilder(props: CreateParagraphBuilderProps): _shopify_react_native_skia.SkParagraphBuilder;
|
|
9
|
+
|
|
10
|
+
export { createParagraphBuilder };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Skia
|
|
3
|
+
} from "@shopify/react-native-skia";
|
|
4
|
+
function createParagraphBuilder(props) {
|
|
5
|
+
if (props.typefaceProvider) {
|
|
6
|
+
return Skia.ParagraphBuilder.Make(
|
|
7
|
+
props.paragraphStyle,
|
|
8
|
+
props.typefaceProvider
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
return Skia.ParagraphBuilder.Make(props.paragraphStyle);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
createParagraphBuilder
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=paragraph-builder.util.js.map
|