@juspay/svelte-ui-components 2.30.0 → 2.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AreaChart/AreaChart.svelte +421 -0
- package/dist/AreaChart/AreaChart.svelte.d.ts +4 -0
- package/dist/AreaChart/properties.d.ts +62 -0
- package/dist/AreaChart/properties.js +1 -0
- package/dist/BarChart/BarChart.svelte +372 -0
- package/dist/BarChart/BarChart.svelte.d.ts +4 -0
- package/dist/BarChart/properties.d.ts +44 -0
- package/dist/BarChart/properties.js +1 -0
- package/dist/LineChart/LineChart.svelte +361 -0
- package/dist/LineChart/LineChart.svelte.d.ts +4 -0
- package/dist/LineChart/properties.d.ts +59 -0
- package/dist/LineChart/properties.js +1 -0
- package/dist/PieChart/PieChart.svelte +236 -0
- package/dist/PieChart/PieChart.svelte.d.ts +4 -0
- package/dist/PieChart/properties.d.ts +36 -0
- package/dist/PieChart/properties.js +1 -0
- package/dist/SankeyChart/SankeyChart.svelte +312 -0
- package/dist/SankeyChart/SankeyChart.svelte.d.ts +4 -0
- package/dist/SankeyChart/properties.d.ts +52 -0
- package/dist/SankeyChart/properties.js +1 -0
- package/dist/Select/Select.svelte +43 -24
- package/dist/Select/properties.d.ts +5 -0
- package/dist/_chart/Axis.svelte +143 -0
- package/dist/_chart/Axis.svelte.d.ts +4 -0
- package/dist/_chart/ChartContainer.svelte +81 -0
- package/dist/_chart/ChartContainer.svelte.d.ts +4 -0
- package/dist/_chart/ChartTooltip.svelte +81 -0
- package/dist/_chart/ChartTooltip.svelte.d.ts +4 -0
- package/dist/_chart/Legend.svelte +59 -0
- package/dist/_chart/Legend.svelte.d.ts +4 -0
- package/dist/_chart/colors.d.ts +4 -0
- package/dist/_chart/colors.js +36 -0
- package/dist/_chart/format.d.ts +3 -0
- package/dist/_chart/format.js +28 -0
- package/dist/_chart/geometry.d.ts +24 -0
- package/dist/_chart/geometry.js +204 -0
- package/dist/_chart/paths.d.ts +4 -0
- package/dist/_chart/paths.js +138 -0
- package/dist/_chart/scales.d.ts +5 -0
- package/dist/_chart/scales.js +77 -0
- package/dist/_chart/types.d.ts +128 -0
- package/dist/_chart/types.js +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export function niceLinearDomain(min, max) {
|
|
2
|
+
if (min === max) {
|
|
3
|
+
return min === 0 ? [0, 1] : [min > 0 ? 0 : min * 2, max > 0 ? max * 2 : 0];
|
|
4
|
+
}
|
|
5
|
+
const range = max - min;
|
|
6
|
+
const exp = Math.floor(Math.log10(range));
|
|
7
|
+
const step = Math.pow(10, exp);
|
|
8
|
+
const niceMin = Math.floor(min / step) * step;
|
|
9
|
+
const niceMax = Math.ceil(max / step) * step;
|
|
10
|
+
return [niceMin, niceMax];
|
|
11
|
+
}
|
|
12
|
+
export function computeLinearTicks(domain, count = 5) {
|
|
13
|
+
const [min, max] = domain;
|
|
14
|
+
if (min === max) {
|
|
15
|
+
return [min];
|
|
16
|
+
}
|
|
17
|
+
const rawStep = (max - min) / count;
|
|
18
|
+
const exp = Math.floor(Math.log10(rawStep));
|
|
19
|
+
const base = Math.pow(10, exp);
|
|
20
|
+
let step;
|
|
21
|
+
const ratio = rawStep / base;
|
|
22
|
+
if (ratio <= 1.5) {
|
|
23
|
+
step = base;
|
|
24
|
+
}
|
|
25
|
+
else if (ratio <= 3) {
|
|
26
|
+
step = base * 2;
|
|
27
|
+
}
|
|
28
|
+
else if (ratio <= 7) {
|
|
29
|
+
step = base * 5;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
step = base * 10;
|
|
33
|
+
}
|
|
34
|
+
const ticks = [];
|
|
35
|
+
let tick = Math.ceil(min / step) * step;
|
|
36
|
+
while (tick <= max + step * 0.001) {
|
|
37
|
+
ticks.push(Math.round(tick * 1e10) / 1e10);
|
|
38
|
+
tick += step;
|
|
39
|
+
}
|
|
40
|
+
return ticks;
|
|
41
|
+
}
|
|
42
|
+
export function createLinearScale(domain, range) {
|
|
43
|
+
const [d0, d1] = domain;
|
|
44
|
+
const [r0, r1] = range;
|
|
45
|
+
const dSpan = d1 - d0 || 1;
|
|
46
|
+
const rSpan = r1 - r0;
|
|
47
|
+
const fn = (value) => r0 + ((value - d0) / dSpan) * rSpan;
|
|
48
|
+
return Object.assign(fn, {
|
|
49
|
+
domain,
|
|
50
|
+
range,
|
|
51
|
+
ticks: (count) => computeLinearTicks(domain, count),
|
|
52
|
+
invert: (pixel) => d0 + ((pixel - r0) / rSpan) * dSpan
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export function createBandScale(domain, range, padding = 0.1) {
|
|
56
|
+
const [r0, r1] = range;
|
|
57
|
+
const n = domain.length || 1;
|
|
58
|
+
const totalRange = r1 - r0;
|
|
59
|
+
// d3-scale band formula (paddingOuter = 0): step = range / (n - padding)
|
|
60
|
+
// Derivation: n*bandwidth + (n-1)*gap = totalRange,
|
|
61
|
+
// with bandwidth = step*(1-padding) and gap = step*padding
|
|
62
|
+
// → step*(n - padding) = totalRange
|
|
63
|
+
const step = totalRange / Math.max(1, n - padding);
|
|
64
|
+
const bandwidth = step * (1 - padding);
|
|
65
|
+
const indexMap = new Map();
|
|
66
|
+
domain.forEach((label, i) => indexMap.set(label, i));
|
|
67
|
+
const fn = (label) => {
|
|
68
|
+
const idx = indexMap.get(label) ?? 0;
|
|
69
|
+
return r0 + idx * step;
|
|
70
|
+
};
|
|
71
|
+
return Object.assign(fn, {
|
|
72
|
+
domain,
|
|
73
|
+
range,
|
|
74
|
+
bandwidth,
|
|
75
|
+
step
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { BarChartDataPoint } from '../BarChart/properties';
|
|
3
|
+
export type Margin = {
|
|
4
|
+
top: number;
|
|
5
|
+
right: number;
|
|
6
|
+
bottom: number;
|
|
7
|
+
left: number;
|
|
8
|
+
};
|
|
9
|
+
export type Point = {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
};
|
|
13
|
+
export type ChartDimensions = {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
margin: Margin;
|
|
17
|
+
innerWidth: number;
|
|
18
|
+
innerHeight: number;
|
|
19
|
+
};
|
|
20
|
+
export type LinearScale = {
|
|
21
|
+
(value: number): number;
|
|
22
|
+
domain: [number, number];
|
|
23
|
+
range: [number, number];
|
|
24
|
+
ticks: (count?: number) => number[];
|
|
25
|
+
invert: (pixel: number) => number;
|
|
26
|
+
};
|
|
27
|
+
export type BandScale = {
|
|
28
|
+
(label: string): number;
|
|
29
|
+
domain: string[];
|
|
30
|
+
range: [number, number];
|
|
31
|
+
bandwidth: number;
|
|
32
|
+
step: number;
|
|
33
|
+
};
|
|
34
|
+
export type CurveType = 'linear' | 'monotone' | 'step' | 'natural';
|
|
35
|
+
export type AxisOrientation = 'top' | 'right' | 'bottom' | 'left';
|
|
36
|
+
export type PieSliceLayout = {
|
|
37
|
+
index: number;
|
|
38
|
+
startAngle: number;
|
|
39
|
+
endAngle: number;
|
|
40
|
+
midAngle: number;
|
|
41
|
+
value: number;
|
|
42
|
+
percentage: number;
|
|
43
|
+
label: string;
|
|
44
|
+
color?: string;
|
|
45
|
+
};
|
|
46
|
+
export type ComputedSankeyNode = {
|
|
47
|
+
id: string;
|
|
48
|
+
label: string;
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
value: number;
|
|
54
|
+
color?: string;
|
|
55
|
+
column: number;
|
|
56
|
+
};
|
|
57
|
+
export type ComputedSankeyLink = {
|
|
58
|
+
source: string;
|
|
59
|
+
target: string;
|
|
60
|
+
value: number;
|
|
61
|
+
color?: string;
|
|
62
|
+
sourceX: number;
|
|
63
|
+
sourceY: number;
|
|
64
|
+
targetX: number;
|
|
65
|
+
targetY: number;
|
|
66
|
+
width: number;
|
|
67
|
+
path: string;
|
|
68
|
+
};
|
|
69
|
+
export type BarRect = {
|
|
70
|
+
x: number;
|
|
71
|
+
y: number;
|
|
72
|
+
width: number;
|
|
73
|
+
height: number;
|
|
74
|
+
color: string;
|
|
75
|
+
si: number;
|
|
76
|
+
pi: number;
|
|
77
|
+
dataPoint: BarChartDataPoint;
|
|
78
|
+
seriesName: string;
|
|
79
|
+
};
|
|
80
|
+
export type StackedPoint = {
|
|
81
|
+
x: number;
|
|
82
|
+
y0: number;
|
|
83
|
+
y1: number;
|
|
84
|
+
};
|
|
85
|
+
export type TooltipData = {
|
|
86
|
+
title?: string;
|
|
87
|
+
items: Array<{
|
|
88
|
+
label: string;
|
|
89
|
+
value: string;
|
|
90
|
+
color?: string;
|
|
91
|
+
}>;
|
|
92
|
+
};
|
|
93
|
+
export type LegendItem = {
|
|
94
|
+
label: string;
|
|
95
|
+
color: string;
|
|
96
|
+
};
|
|
97
|
+
export type ChartContainerProperties = {
|
|
98
|
+
width?: number;
|
|
99
|
+
height?: number;
|
|
100
|
+
aspectRatio?: number;
|
|
101
|
+
minHeight?: number;
|
|
102
|
+
testId?: string;
|
|
103
|
+
classes?: string;
|
|
104
|
+
children: Snippet;
|
|
105
|
+
};
|
|
106
|
+
export type AxisProperties = {
|
|
107
|
+
orientation: AxisOrientation;
|
|
108
|
+
scale: LinearScale | BandScale;
|
|
109
|
+
tickCount?: number;
|
|
110
|
+
tickFormat?: (value: number | string) => string;
|
|
111
|
+
showGridlines?: boolean;
|
|
112
|
+
gridlineLength?: number;
|
|
113
|
+
label?: string;
|
|
114
|
+
classes?: string;
|
|
115
|
+
};
|
|
116
|
+
export type ChartTooltipProperties = {
|
|
117
|
+
data: TooltipData | null;
|
|
118
|
+
mouseX?: number;
|
|
119
|
+
mouseY?: number;
|
|
120
|
+
customSnippet?: Snippet<[TooltipData]>;
|
|
121
|
+
classes?: string;
|
|
122
|
+
};
|
|
123
|
+
export type LegendProperties = {
|
|
124
|
+
items: LegendItem[];
|
|
125
|
+
position?: 'top' | 'bottom';
|
|
126
|
+
customSnippet?: Snippet<[LegendItem[]]>;
|
|
127
|
+
classes?: string;
|
|
128
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -59,6 +59,11 @@ export { default as SplitInput } from './SplitInput/SplitInput.svelte';
|
|
|
59
59
|
export { default as FileInput } from './FileInput/FileInput.svelte';
|
|
60
60
|
export { default as DateRangePicker } from './DateRangePicker/DateRangePicker.svelte';
|
|
61
61
|
export { default as Breadcrumb } from './Breadcrumb/Breadcrumb.svelte';
|
|
62
|
+
export { default as LineChart } from './LineChart/LineChart.svelte';
|
|
63
|
+
export { default as AreaChart } from './AreaChart/AreaChart.svelte';
|
|
64
|
+
export { default as BarChart } from './BarChart/BarChart.svelte';
|
|
65
|
+
export { default as PieChart } from './PieChart/PieChart.svelte';
|
|
66
|
+
export { default as SankeyChart } from './SankeyChart/SankeyChart.svelte';
|
|
62
67
|
export type * from './Button/properties';
|
|
63
68
|
export type * from './Modal/properties';
|
|
64
69
|
export type * from './Input/properties';
|
|
@@ -114,4 +119,9 @@ export type * from './SplitInput/properties';
|
|
|
114
119
|
export type * from './FileInput/properties';
|
|
115
120
|
export type * from './DateRangePicker/properties';
|
|
116
121
|
export type * from './Breadcrumb/properties';
|
|
122
|
+
export type * from './LineChart/properties';
|
|
123
|
+
export type * from './AreaChart/properties';
|
|
124
|
+
export type * from './BarChart/properties';
|
|
125
|
+
export type * from './PieChart/properties';
|
|
126
|
+
export type * from './SankeyChart/properties';
|
|
117
127
|
export { validateInput } from './utils';
|
package/dist/index.js
CHANGED
|
@@ -59,4 +59,9 @@ export { default as SplitInput } from './SplitInput/SplitInput.svelte';
|
|
|
59
59
|
export { default as FileInput } from './FileInput/FileInput.svelte';
|
|
60
60
|
export { default as DateRangePicker } from './DateRangePicker/DateRangePicker.svelte';
|
|
61
61
|
export { default as Breadcrumb } from './Breadcrumb/Breadcrumb.svelte';
|
|
62
|
+
export { default as LineChart } from './LineChart/LineChart.svelte';
|
|
63
|
+
export { default as AreaChart } from './AreaChart/AreaChart.svelte';
|
|
64
|
+
export { default as BarChart } from './BarChart/BarChart.svelte';
|
|
65
|
+
export { default as PieChart } from './PieChart/PieChart.svelte';
|
|
66
|
+
export { default as SankeyChart } from './SankeyChart/SankeyChart.svelte';
|
|
62
67
|
export { validateInput } from './utils';
|