reburn-ui 0.2.0 → 0.3.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.
Files changed (153) hide show
  1. package/dist/core/MantineProvider/color-functions/get-contrast-color.svelte.js +1 -1
  2. package/dist/core/MantineProvider/color-functions/index.d.ts +1 -1
  3. package/dist/core/MantineProvider/color-functions/index.js +1 -1
  4. package/dist/core/MantineProvider/color-functions/parse-theme-color.svelte.js +1 -1
  5. package/dist/core/MantineProvider/theme.types.d.ts +5 -6
  6. package/dist/core/charts/ChartRoot/ChartContext.svelte.d.ts +64 -0
  7. package/dist/core/charts/ChartRoot/ChartContext.svelte.js +56 -0
  8. package/dist/core/charts/ChartRoot/ChartRoot.svelte +238 -0
  9. package/dist/core/charts/ChartRoot/ChartRoot.svelte.d.ts +87 -0
  10. package/dist/core/charts/ChartRoot/ChartXGrid.svelte +32 -0
  11. package/dist/core/charts/ChartRoot/ChartXGrid.svelte.d.ts +18 -0
  12. package/dist/core/charts/ChartRoot/ChartXLabels.svelte +26 -0
  13. package/dist/core/charts/ChartRoot/ChartXLabels.svelte.d.ts +18 -0
  14. package/dist/core/charts/ChartRoot/ChartYGrid.svelte +32 -0
  15. package/dist/core/charts/ChartRoot/ChartYGrid.svelte.d.ts +18 -0
  16. package/dist/core/charts/ChartRoot/ChartYLabels.svelte +31 -0
  17. package/dist/core/charts/ChartRoot/ChartYLabels.svelte.d.ts +18 -0
  18. package/dist/core/charts/ChartRoot/tickLabels.d.ts +8 -0
  19. package/dist/core/charts/ChartRoot/tickLabels.js +21 -0
  20. package/dist/core/charts/ChartTooltip/ChartTooltip.svelte +260 -0
  21. package/dist/core/charts/ChartTooltip/ChartTooltip.svelte.d.ts +34 -0
  22. package/dist/core/charts/ChartTooltip/ChartTooltipData.svelte +47 -0
  23. package/dist/core/charts/ChartTooltip/ChartTooltipData.svelte.d.ts +29 -0
  24. package/dist/core/charts/ChartTooltip/utils/findClosestElement.d.ts +2 -0
  25. package/dist/core/charts/ChartTooltip/utils/findClosestElement.js +21 -0
  26. package/dist/core/charts/ChartTooltip/utils/getTooltipPosition.d.ts +9 -0
  27. package/dist/core/charts/ChartTooltip/utils/getTooltipPosition.js +6 -0
  28. package/dist/core/charts/CompositeChart/CompositeChart.svelte +82 -0
  29. package/dist/core/charts/CompositeChart/CompositeChart.svelte.d.ts +60 -0
  30. package/dist/core/charts/LineChart/LineChart.svelte +30 -321
  31. package/dist/core/charts/LineChart/LineChart.svelte.d.ts +16 -64
  32. package/dist/core/charts/LineChart/LineChartInner.svelte +66 -0
  33. package/dist/core/charts/LineChart/LineChartInner.svelte.d.ts +34 -0
  34. package/dist/core/charts/ScatterChart/ScatterChart.svelte +33 -0
  35. package/dist/core/charts/ScatterChart/ScatterChart.svelte.d.ts +39 -0
  36. package/dist/core/charts/ScatterChart/ScatterChartInner.svelte +67 -0
  37. package/dist/core/charts/ScatterChart/ScatterChartInner.svelte.d.ts +32 -0
  38. package/dist/core/charts/d3/array/tick.d.ts +1 -0
  39. package/dist/core/charts/d3/array/tick.js +66 -0
  40. package/dist/core/charts/d3/scale/scaleLinear.d.ts +4 -0
  41. package/dist/core/charts/d3/scale/scaleLinear.js +14 -0
  42. package/dist/core/charts/d3/shape/curve/curveLinear.d.ts +2 -0
  43. package/dist/core/charts/d3/shape/curve/curveLinear.js +16 -0
  44. package/dist/core/charts/d3/shape/line.d.ts +7 -0
  45. package/dist/core/charts/d3/shape/line.js +6 -0
  46. package/dist/core/charts/d3/shape/toFixed.d.ts +1 -0
  47. package/dist/core/charts/d3/shape/toFixed.js +7 -0
  48. package/dist/core/charts/d3/shape/withPath.d.ts +1 -0
  49. package/dist/core/charts/d3/shape/withPath.js +18 -0
  50. package/dist/core/charts/index.d.ts +5 -0
  51. package/dist/core/charts/index.js +5 -0
  52. package/dist/core/charts/types.d.ts +10 -0
  53. package/dist/core/charts/utils/minMaxObject.d.ts +6 -0
  54. package/dist/core/charts/utils/minMaxObject.js +26 -0
  55. package/dist/core/components/Badge/Badge.svelte +1 -1
  56. package/dist/core/components/Burger/Burger.svelte +1 -1
  57. package/dist/core/components/Checkbox/Checkbox.svelte +1 -1
  58. package/dist/core/components/Checkbox/CheckboxCard/CheckboxCard.svelte +8 -6
  59. package/dist/core/components/Checkbox/CheckboxIndicator.svelte +4 -1
  60. package/dist/core/components/ColorPicker/ColorSlider.svelte +10 -14
  61. package/dist/core/components/ColorPicker/Saturation.svelte +8 -4
  62. package/dist/core/components/ColorPicker/converters/index.d.ts +2 -2
  63. package/dist/core/components/ColorPicker/converters/index.js +2 -2
  64. package/dist/core/components/Combobox/ComboboxChevron.svelte +4 -3
  65. package/dist/core/components/Combobox/ComboboxDropdown.svelte +0 -3
  66. package/dist/core/components/Dropzone/Dropzone.svelte +396 -0
  67. package/dist/core/components/Dropzone/Dropzone.svelte.d.ts +104 -0
  68. package/dist/core/components/Dropzone/DropzoneContext.svelte.js +3 -0
  69. package/dist/core/components/Dropzone/index.d.ts +3 -0
  70. package/dist/core/components/Dropzone/index.js +2 -0
  71. package/dist/core/components/Dropzone/mime-types.d.ts +30 -0
  72. package/dist/core/components/Dropzone/mime-types.js +41 -0
  73. package/dist/core/components/Dropzone/utils/acceptPropAsAccaptAttr.d.ts +5 -0
  74. package/dist/core/components/Dropzone/utils/acceptPropAsAccaptAttr.js +21 -0
  75. package/dist/core/components/Dropzone/utils/fromEvent.d.ts +6 -0
  76. package/dist/core/components/Dropzone/utils/fromEvent.js +45 -0
  77. package/dist/core/components/Dropzone/utils/getAllFilesAccepted.d.ts +35 -0
  78. package/dist/core/components/Dropzone/utils/getAllFilesAccepted.js +69 -0
  79. package/dist/core/components/Dropzone/utils/isEvtWithFiles.d.ts +1 -0
  80. package/dist/core/components/Dropzone/utils/isEvtWithFiles.js +8 -0
  81. package/dist/core/components/Dropzone/utils/isExt.d.ts +4 -0
  82. package/dist/core/components/Dropzone/utils/isExt.js +6 -0
  83. package/dist/core/components/Dropzone/utils/isMIMEType.d.ts +6 -0
  84. package/dist/core/components/Dropzone/utils/isMIMEType.js +8 -0
  85. package/dist/core/components/Dropzone/utils/isPropagationStopped.d.ts +1 -0
  86. package/dist/core/components/Dropzone/utils/isPropagationStopped.js +12 -0
  87. package/dist/core/components/Fieldset/Fieldset.svelte +76 -0
  88. package/dist/core/components/Fieldset/Fieldset.svelte.d.ts +15 -0
  89. package/dist/core/components/Floating/CreateFloating.svelte.js +0 -5
  90. package/dist/core/components/Group/Group.svelte +4 -9
  91. package/dist/core/components/Input/Input.svelte.d.ts +2 -2
  92. package/dist/core/components/InputBase/InputBase.svelte.d.ts +2 -2
  93. package/dist/core/components/Loader/Loader.svelte +1 -1
  94. package/dist/core/components/LoadingOverlay/LoadingOverlay.svelte +72 -0
  95. package/dist/core/components/LoadingOverlay/LoadingOverlay.svelte.d.ts +19 -0
  96. package/dist/core/components/Modal/ModalContent.svelte +4 -2
  97. package/dist/core/components/NavLink/NavLink.svelte +4 -3
  98. package/dist/core/components/Notification/Notification.svelte +5 -4
  99. package/dist/core/components/Pill/Pill.svelte +172 -0
  100. package/dist/core/components/Pill/Pill.svelte.d.ts +23 -0
  101. package/dist/core/components/Pill/PillGroup.svelte +47 -0
  102. package/dist/core/components/Pill/PillGroup.svelte.d.ts +13 -0
  103. package/dist/core/components/Pill/PillGroupContext.svelte.d.ts +15 -0
  104. package/dist/core/components/Pill/PillGroupContext.svelte.js +13 -0
  105. package/dist/core/components/Pill/index.d.ts +8 -0
  106. package/dist/core/components/Pill/index.js +5 -0
  107. package/dist/core/components/Progress/ProgressSection.svelte +3 -1
  108. package/dist/core/components/SegmentedControl/SegmentedControl.svelte +18 -7
  109. package/dist/core/components/Select/Select.svelte.d.ts +1 -1
  110. package/dist/core/components/Slider/SliderRoot.svelte +5 -1
  111. package/dist/core/components/Slider/Thumb.svelte +5 -1
  112. package/dist/core/components/Slider/Track.svelte +16 -6
  113. package/dist/core/components/Switch/Switch.svelte +1 -1
  114. package/dist/core/components/Table/Table.svelte +158 -0
  115. package/dist/core/components/Table/Table.svelte.d.ts +51 -0
  116. package/dist/core/components/Table/TableBodyContext.d.ts +2 -0
  117. package/dist/core/components/Table/TableBodyContext.js +5 -0
  118. package/dist/core/components/Table/TableCaption.svelte +30 -0
  119. package/dist/core/components/Table/TableCaption.svelte.d.ts +7 -0
  120. package/dist/core/components/Table/TableContext.svelte.d.ts +25 -0
  121. package/dist/core/components/Table/TableContext.svelte.js +19 -0
  122. package/dist/core/components/Table/TableDataRenderer.svelte +55 -0
  123. package/dist/core/components/Table/TableDataRenderer.svelte.d.ts +7 -0
  124. package/dist/core/components/Table/TableHeaderContext.d.ts +2 -0
  125. package/dist/core/components/Table/TableHeaderContext.js +5 -0
  126. package/dist/core/components/Table/TableTbody.svelte +20 -0
  127. package/dist/core/components/Table/TableTbody.svelte.d.ts +7 -0
  128. package/dist/core/components/Table/TableTd.svelte +27 -0
  129. package/dist/core/components/Table/TableTd.svelte.d.ts +7 -0
  130. package/dist/core/components/Table/TableTfoot.svelte +15 -0
  131. package/dist/core/components/Table/TableTfoot.svelte.d.ts +7 -0
  132. package/dist/core/components/Table/TableTh.svelte +45 -0
  133. package/dist/core/components/Table/TableTh.svelte.d.ts +7 -0
  134. package/dist/core/components/Table/TableThead.svelte +32 -0
  135. package/dist/core/components/Table/TableThead.svelte.d.ts +7 -0
  136. package/dist/core/components/Table/TableTr.svelte +62 -0
  137. package/dist/core/components/Table/TableTr.svelte.d.ts +7 -0
  138. package/dist/core/components/Table/getTableDataAttr.d.ts +12 -0
  139. package/dist/core/components/Table/getTableDataAttr.js +28 -0
  140. package/dist/core/components/Table/index.d.ts +20 -0
  141. package/dist/core/components/Table/index.js +17 -0
  142. package/dist/core/components/index.d.ts +5 -0
  143. package/dist/core/components/index.js +5 -0
  144. package/dist/core/hooks/use-id.d.ts +1 -0
  145. package/dist/core/hooks/use-id.js +4 -0
  146. package/dist/core/utils/get-default-z-index.d.ts +1 -1
  147. package/package.json +11 -9
  148. package/dist/core/charts/LineChart/LineChart.types.js +0 -1
  149. package/dist/core/charts/LineChart/types.d.ts +0 -68
  150. /package/dist/core/MantineProvider/color-functions/{get-primary-shade.d.ts → get-primary-shade.svelte.d.ts} +0 -0
  151. /package/dist/core/MantineProvider/color-functions/{get-primary-shade.js → get-primary-shade.svelte.js} +0 -0
  152. /package/dist/core/charts/{LineChart/types.js → types.js} +0 -0
  153. /package/dist/core/{charts/LineChart/LineChart.types.d.ts → components/Dropzone/DropzoneContext.svelte.d.ts} +0 -0
@@ -1,29 +1,20 @@
1
1
  <script lang="ts" module>
2
- import type { DivElement } from '../../element-types.js';
3
2
  import type { MantineColor } from '../../MantineProvider/theme.types.js';
4
- import { scaleLinear, scaleTime } from 'd3';
5
- import type { Snippet } from 'svelte';
6
- import type { ChartSeries } from './types.js';
3
+ import type { ChartRootProps } from '../ChartRoot/ChartRoot.svelte';
4
+ import type { ChartData } from '../types.js';
7
5
 
8
6
  export type LineChartType = 'default' | 'gradient';
9
7
 
8
+ export type LineChartCurveType = 'bump' | 'linear' | 'natural' | 'monotone' | 'step' | 'stepBefore' | 'stepAfter';
9
+
10
10
  export interface LineChartGradientStop {
11
11
  offset: number;
12
12
  color: MantineColor;
13
13
  }
14
14
 
15
- export type LineChartCurveType = 'bump' | 'linear' | 'natural' | 'monotone' | 'step' | 'stepBefore' | 'stepAfter';
16
-
17
- export interface LineChartSeries extends ChartSeries {
18
- strokeDasharray?: string | number;
19
- }
20
-
21
- export interface LineChartProps<T extends Record<string, any>> extends DivElement {
22
- /** Data used to display chart */
23
- data: T[];
24
-
25
- /** An array of objects with `name` and `color` keys. Determines which data should be consumed from the `data` array. */
26
- series?: LineChartSeries[];
15
+ export interface __LineChartProps {
16
+ /** Type of the curve, `'monotone'` by default */
17
+ curveType?: LineChartCurveType;
27
18
 
28
19
  /** Controls styles of the line, `'default'` by default */
29
20
  type?: LineChartType;
@@ -31,320 +22,38 @@
31
22
  /** Data used to generate gradient stops, `[{ offset: 0, color: 'red' }, { offset: 100, color: 'blue' }]` by default */
32
23
  gradientStops?: LineChartGradientStop[];
33
24
 
34
- /** Type of the curve, `'monotone'` by default */
35
- curveType?: LineChartCurveType;
36
-
37
- /** Controls fill opacity of all lines, `1` by default */
38
- fillOpacity?: number;
39
-
40
- /** Determines whether dots should be displayed, `true` by default */
41
- withDots?: boolean;
42
-
43
- /** Props passed down to all dots. Ignored if `withDots={false}` is set. */
44
- // dotProps?: Omit<DotProps, 'ref'>;
45
-
46
- /** Props passed down to all active dots. Ignored if `withDots={false}` is set. */
47
- // activeDotProps?: Omit<DotProps, 'ref'>;
48
-
49
- /** Stroke width for the chart lines, `2` by default */
50
- strokeWidth?: number;
51
-
52
- /** Props passed down to recharts `LineChart` component */
53
- // lineChartProps?: React.ComponentPropsWithoutRef<typeof ReChartsLineChart>;
54
-
55
- /** Determines whether points with `null` values should be connected, `true` by default */
56
- connectNulls?: boolean;
57
-
58
- /** Additional components that are rendered inside recharts `LineChart` component */
59
- children?: Snippet;
60
-
61
- /** Props passed down to recharts `Line` component */
62
- // lineProps?: ((series: LineChartSeries) => Partial<Omit<LineProps, 'ref'>>) | Partial<Omit<LineProps, 'ref'>>;
63
-
64
- /** Determines whether each point should have associated label, `false` by default */
65
- withPointLabels?: boolean;
66
-
67
- /** Key of the `data` object for x-axis values */
68
- xKey: keyof T;
69
-
70
- /** Key of the `data` object for y-axis values */
71
- yKey: keyof T;
72
-
73
- /** A function to calculate the range of the x-axis */
74
- xRangeFn?: (data: T) => number;
75
-
76
- /** A function to calculate the range of the y-axis */
77
- yRangeFn?: (data: T) => number;
78
-
79
- /** The scale of the x-axis */
80
- xScale?: typeof scaleLinear | typeof scaleTime;
81
-
82
- /** The scale of the y-axis */
83
- yScale?: typeof scaleLinear | typeof scaleTime;
84
-
85
- /** Width of the chart */
86
- width?: number | string;
87
-
88
- /** Height of the chart */
89
- height?: number | string;
25
+ /** Curve function to use for the line */
26
+ curve?: typeof curveLinear;
90
27
 
91
28
  /** Color of the chart */
92
29
  color?: MantineColor;
93
-
94
- /** Whether to show x-axis grid lines, `true` by default */
95
- xGrid?: boolean;
96
-
97
- /** Whether to show y-axis grid lines, `true` by default */
98
- yGrid?: boolean;
99
-
100
- /** Whether to show x-axis labels, `true` by default */
101
- showXLabels?: boolean;
102
-
103
- /** Whether to show y-axis labels, `true` by default */
104
- showYLabels?: boolean;
105
-
106
- /** Format function for x-axis labels */
107
- xLabelsFormat?: (value: string) => string;
108
-
109
- /** Format function for y-axis labels */
110
- yLabelsFormat?: (value: string) => string;
111
30
  }
112
- </script>
113
31
 
114
- <!-- TODO: add multiple lines -->
32
+ export interface LineChartProps<T extends ChartData> extends __LineChartProps, Omit<ChartRootProps<T>, 'children'> {}
33
+ </script>
115
34
 
116
- <script lang="ts" generics="T extends Record<string, any>">
117
- import { getThemeColor } from '../../MantineProvider/color-functions/get-theme-color.js';
118
- import { rem } from '../../utils/units-converters/rem.js';
119
- import { line as d3Line } from 'd3';
120
- import { nanoid } from 'nanoid';
121
- import { minMax } from '../utils/minMax.js';
35
+ <script lang="ts" generics="T extends ChartData">
36
+ import ChartRoot from '../ChartRoot/ChartRoot.svelte';
37
+ import { curveLinear } from '../d3/shape/curve/curveLinear.js';
38
+ import LineChartInner from './LineChartInner.svelte';
122
39
 
123
40
  let {
124
- data,
125
- xKey,
126
- yKey,
127
- xRangeFn = (d) => d[xKey],
128
- yRangeFn = (d) => d[yKey],
129
- xScale = scaleLinear,
130
- yScale = scaleLinear,
131
- width = '100%',
132
- height = '100%',
133
- color = 'blue',
134
- gradientStops,
41
+ curveType = 'linear',
135
42
  type = 'default',
136
- xGrid = true,
137
- yGrid = true,
138
- showXLabels = true,
139
- showYLabels = true,
140
- xLabelsFormat,
141
- yLabelsFormat,
43
+ gradientStops = [
44
+ { offset: 0, color: 'red' },
45
+ { offset: 100, color: 'blue' },
46
+ ],
47
+ curve = curveLinear,
48
+ color,
49
+ withXAxis = true,
50
+ withYAxis = true,
51
+ ...props
142
52
  }: LineChartProps<T> = $props();
143
-
144
- const xRange = $derived(minMax(data, xRangeFn));
145
- const _xScale = $derived(xScale().domain(xRange).range([0, 100]));
146
-
147
- const yRange = $derived(minMax(data, yRangeFn));
148
- const _yScale = $derived(yScale().domain(yRange).range([0, 100]));
149
-
150
- $inspect(xRange);
151
- $inspect(yRange);
152
-
153
- const line = $derived(
154
- d3Line<T>()
155
- .x((d) => _xScale(xRangeFn(d)))
156
- .y((d) => _yScale(yRangeFn(d)))
157
- );
158
-
159
- const xTicks = $derived.by(() => {
160
- const ticks = _xScale.ticks();
161
- const formattedLabels: { label: string; left: number }[] = [];
162
-
163
- let maxLabelLength = 0;
164
-
165
- for (let i = 0; i < ticks.length; i++) {
166
- const tick = ticks[i];
167
- const label = tick.toString();
168
- const length = label.length;
169
- if (length > maxLabelLength) maxLabelLength = length;
170
-
171
- formattedLabels.push({
172
- label: label,
173
- left: _xScale(tick) as number,
174
- });
175
- }
176
-
177
- return {
178
- labels: formattedLabels,
179
- maxLength: maxLabelLength,
180
- };
181
- });
182
-
183
- const yTicks = $derived.by(() => {
184
- const ticks = _yScale.ticks();
185
-
186
- const formattedLabels: { label: string; top: number }[] = [];
187
-
188
- let maxLabelLength = 0;
189
-
190
- for (let i = 0; i < ticks.length; i++) {
191
- const tick = ticks[i] as number;
192
- const label = tick.toString();
193
- const length = label.length;
194
- if (length > maxLabelLength) maxLabelLength = length;
195
-
196
- formattedLabels.push({
197
- label,
198
- top: _yScale(tick) as number,
199
- });
200
- }
201
-
202
- return {
203
- labels: formattedLabels,
204
- maxLength: maxLabelLength,
205
- };
206
- });
207
-
208
- const yLabels = $derived.by(() => {
209
- const allLabels = yTicks.labels;
210
-
211
- const top = allLabels[0];
212
- const bottom = allLabels[allLabels.length - 1];
213
-
214
- return { top, bottom };
215
- });
216
-
217
- const xLabels = $derived.by(() => {
218
- const allLabels = xTicks.labels;
219
-
220
- const left = allLabels[0];
221
- const right = allLabels[allLabels.length - 1];
222
-
223
- return { left, right };
224
- });
225
-
226
- const lineColor = $derived(getThemeColor(color));
227
-
228
- const gradientId = $derived('gradient-' + nanoid(8));
229
53
  </script>
230
54
 
231
- <div class="root" style:width={rem(width)} style:height={rem(height)}>
232
- <svg class="chart" width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none">
233
- {#if type === 'gradient' && gradientStops}
234
- <defs>
235
- <linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
236
- {#each gradientStops as stop}
237
- <stop offset="{stop.offset}%" stop-color={getThemeColor(stop.color)} />
238
- {/each}
239
- </linearGradient>
240
- </defs>
241
- {/if}
242
-
243
- <path
244
- class="line"
245
- fill="none"
246
- stroke={type === 'gradient' ? `url(#${gradientId})` : lineColor}
247
- stroke-width={2}
248
- d={line(data)}
249
- vector-effect="non-scaling-stroke"
250
- />
251
-
252
- {#if yGrid}
253
- {#each yTicks.labels as tick}
254
- <line class="grid-lines" x1={0} x2={100} y1={tick.top} y2={tick.top} orientation="vertical" />
255
- {/each}
256
- {/if}
257
-
258
- <!-- add a way to show the top and bottom grid lines -->
259
- <!-- <line class="grid-lines" x1={0} x2={100} y1={yLabels.top.top} y2={yLabels.top.top} orientation="vertical" /> -->
260
- <!-- <line class="grid-lines" x1={0} x2={100} y1={yLabels.bottom.top} y2={yLabels.bottom.top} orientation="vertical" /> -->
261
-
262
- {#if xGrid}
263
- {#each xTicks.labels as tick}
264
- <line class="grid-lines" x1={tick.left} x2={tick.left} y1={0} y2={100} orientation="horizontal" />
265
- {/each}
266
- {/if}
267
- </svg>
268
-
269
- {#if showYLabels}
270
- <div class="y-axis-container" style:width="{yTicks.maxLength * 8}px">
271
- {#each yTicks.labels as tick}
272
- <span class="y-axis-tick-label" style:top="{tick.top}%">
273
- {yLabelsFormat ? yLabelsFormat(tick.label) : tick.label}
274
- </span>
275
- {/each}
276
- </div>
277
- {/if}
278
-
279
- {#if showXLabels}
280
- <div class="x-axis-container">
281
- {#each xTicks.labels as tick}
282
- <span class="x-axis-tick-label" style:left="{tick.left}%">
283
- {xLabelsFormat ? xLabelsFormat(tick.label) : tick.label}
284
- </span>
285
- {/each}
286
- </div>
287
- {/if}
288
- </div>
289
-
290
- <style>.root {
291
- display: block;
292
- user-select: none;
293
- display: grid;
294
- grid-template-columns: max-content 1fr;
295
- grid-template-rows: 1fr max-content;
296
- grid-template-areas: "y-axis chart" "empty x-axis";
297
- position: relative;
298
- --chart-bar-label-color: var(--mantine-color-dimmed);
299
- }
300
- :global(:where([data-mantine-color-scheme="light"])) .root {
301
- --chart-grid-color: rgba(173, 181, 189, 0.6);
302
- --chart-cursor-fill: rgba(173, 181, 189, 0.15);
303
- }
304
- :global(:where([data-mantine-color-scheme="dark"])) .root {
305
- --chart-cursor-fill: rgba(105, 105, 105, 0.15);
306
- --chart-grid-color: rgba(105, 105, 105, 0.6);
307
- }
308
- .root :where(text) {
309
- font-family: var(--mantine-font-family);
310
- color: var(--chart-text-color, var(--mantine-color-dimmed));
311
- }
312
-
313
- .chart {
314
- grid-area: chart;
315
- }
316
-
317
- .grid-lines {
318
- stroke-opacity: 0.25;
319
- stroke-width: 2;
320
- stroke: var(--chart-grid-color);
321
- stroke-dasharray: 2 4;
322
- vector-effect: non-scaling-stroke;
323
- }
324
-
325
- .y-axis-container {
326
- grid-area: y-axis;
327
- position: relative;
328
- margin-right: 0.5rem;
329
- }
330
-
331
- .x-axis-tick-label,
332
- .y-axis-tick-label {
333
- position: absolute;
334
- font-size: 0.75rem;
335
- font-family: var(--mantine-font-family);
336
- color: var(--chart-text-color, var(--mantine-color-dimmed));
337
- }
338
-
339
- .x-axis-tick-label {
340
- transform: translateX(-50%);
341
- }
342
-
343
- .y-axis-tick-label {
344
- text-align: right;
345
- transform: translateY(-50%);
346
- right: 0;
347
- height: 0;
348
- width: 100%;
349
- line-height: 0;
350
- }</style>
55
+ <ChartRoot {...props}>
56
+ {#snippet children(context)}
57
+ <LineChartInner {context} {type} {gradientStops} {curve} {color} />
58
+ {/snippet}
59
+ </ChartRoot>
@@ -1,83 +1,35 @@
1
- import type { DivElement } from '../../element-types.js';
2
1
  import type { MantineColor } from '../../MantineProvider/theme.types.js';
3
- import { scaleLinear, scaleTime } from 'd3';
4
- import type { Snippet } from 'svelte';
5
- import type { ChartSeries } from './types.js';
2
+ import type { ChartRootProps } from '../ChartRoot/ChartRoot.svelte';
3
+ import type { ChartData } from '../types.js';
6
4
  export type LineChartType = 'default' | 'gradient';
5
+ export type LineChartCurveType = 'bump' | 'linear' | 'natural' | 'monotone' | 'step' | 'stepBefore' | 'stepAfter';
7
6
  export interface LineChartGradientStop {
8
7
  offset: number;
9
8
  color: MantineColor;
10
9
  }
11
- export type LineChartCurveType = 'bump' | 'linear' | 'natural' | 'monotone' | 'step' | 'stepBefore' | 'stepAfter';
12
- export interface LineChartSeries extends ChartSeries {
13
- strokeDasharray?: string | number;
14
- }
15
- export interface LineChartProps<T extends Record<string, any>> extends DivElement {
16
- /** Data used to display chart */
17
- data: T[];
18
- /** An array of objects with `name` and `color` keys. Determines which data should be consumed from the `data` array. */
19
- series?: LineChartSeries[];
10
+ export interface __LineChartProps {
11
+ /** Type of the curve, `'monotone'` by default */
12
+ curveType?: LineChartCurveType;
20
13
  /** Controls styles of the line, `'default'` by default */
21
14
  type?: LineChartType;
22
15
  /** Data used to generate gradient stops, `[{ offset: 0, color: 'red' }, { offset: 100, color: 'blue' }]` by default */
23
16
  gradientStops?: LineChartGradientStop[];
24
- /** Type of the curve, `'monotone'` by default */
25
- curveType?: LineChartCurveType;
26
- /** Controls fill opacity of all lines, `1` by default */
27
- fillOpacity?: number;
28
- /** Determines whether dots should be displayed, `true` by default */
29
- withDots?: boolean;
30
- /** Props passed down to all dots. Ignored if `withDots={false}` is set. */
31
- /** Props passed down to all active dots. Ignored if `withDots={false}` is set. */
32
- /** Stroke width for the chart lines, `2` by default */
33
- strokeWidth?: number;
34
- /** Props passed down to recharts `LineChart` component */
35
- /** Determines whether points with `null` values should be connected, `true` by default */
36
- connectNulls?: boolean;
37
- /** Additional components that are rendered inside recharts `LineChart` component */
38
- children?: Snippet;
39
- /** Props passed down to recharts `Line` component */
40
- /** Determines whether each point should have associated label, `false` by default */
41
- withPointLabels?: boolean;
42
- /** Key of the `data` object for x-axis values */
43
- xKey: keyof T;
44
- /** Key of the `data` object for y-axis values */
45
- yKey: keyof T;
46
- /** A function to calculate the range of the x-axis */
47
- xRangeFn?: (data: T) => number;
48
- /** A function to calculate the range of the y-axis */
49
- yRangeFn?: (data: T) => number;
50
- /** The scale of the x-axis */
51
- xScale?: typeof scaleLinear | typeof scaleTime;
52
- /** The scale of the y-axis */
53
- yScale?: typeof scaleLinear | typeof scaleTime;
54
- /** Width of the chart */
55
- width?: number | string;
56
- /** Height of the chart */
57
- height?: number | string;
17
+ /** Curve function to use for the line */
18
+ curve?: typeof curveLinear;
58
19
  /** Color of the chart */
59
20
  color?: MantineColor;
60
- /** Whether to show x-axis grid lines, `true` by default */
61
- xGrid?: boolean;
62
- /** Whether to show y-axis grid lines, `true` by default */
63
- yGrid?: boolean;
64
- /** Whether to show x-axis labels, `true` by default */
65
- showXLabels?: boolean;
66
- /** Whether to show y-axis labels, `true` by default */
67
- showYLabels?: boolean;
68
- /** Format function for x-axis labels */
69
- xLabelsFormat?: (value: string) => string;
70
- /** Format function for y-axis labels */
71
- yLabelsFormat?: (value: string) => string;
72
21
  }
73
- declare function $$render<T extends Record<string, any>>(): {
22
+ export interface LineChartProps<T extends ChartData> extends __LineChartProps, Omit<ChartRootProps<T>, 'children'> {
23
+ }
24
+ import { curveLinear } from '../d3/shape/curve/curveLinear.js';
25
+ declare function $$render<T extends ChartData>(): {
74
26
  props: LineChartProps<T>;
75
27
  exports: {};
76
28
  bindings: "";
77
29
  slots: {};
78
30
  events: {};
79
31
  };
80
- declare class __sveltets_Render<T extends Record<string, any>> {
32
+ declare class __sveltets_Render<T extends ChartData> {
81
33
  props(): ReturnType<typeof $$render<T>>['props'];
82
34
  events(): ReturnType<typeof $$render<T>>['events'];
83
35
  slots(): ReturnType<typeof $$render<T>>['slots'];
@@ -85,12 +37,12 @@ declare class __sveltets_Render<T extends Record<string, any>> {
85
37
  exports(): {};
86
38
  }
87
39
  interface $$IsomorphicComponent {
88
- new <T extends Record<string, any>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
40
+ new <T extends ChartData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
89
41
  $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
90
42
  } & ReturnType<__sveltets_Render<T>['exports']>;
91
- <T extends Record<string, any>>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
43
+ <T extends ChartData>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
92
44
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
93
45
  }
94
46
  declare const LineChart: $$IsomorphicComponent;
95
- type LineChart<T extends Record<string, any>> = InstanceType<typeof LineChart<T>>;
47
+ type LineChart<T extends ChartData> = InstanceType<typeof LineChart<T>>;
96
48
  export default LineChart;
@@ -0,0 +1,66 @@
1
+ <script lang="ts" module>
2
+ import type { ChartContext } from '../ChartRoot/ChartContext.svelte.js';
3
+ import type { ChartData, ChartSeries } from '../types.js';
4
+ import { type __LineChartProps } from './LineChart.svelte';
5
+
6
+ type PathElement = SvelteHTMLElements['path'];
7
+
8
+ export interface LineChartInnerProps<T extends ChartData> extends __LineChartProps, Omit<PathElement, 'color' | 'type'> {
9
+ context: ChartContext<T>;
10
+
11
+ /** z-index of the line */
12
+ zIndex?: number;
13
+ }
14
+ </script>
15
+
16
+ <script lang="ts" generics="T extends ChartData">
17
+ import { getThemeColor } from '../../MantineProvider/index.js';
18
+ import { nanoid } from 'nanoid';
19
+ import type { SvelteHTMLElements } from 'svelte/elements';
20
+ import { curveLinear } from '../d3/shape/curve/curveLinear.js';
21
+ import { line } from '../d3/shape/line.js';
22
+
23
+ let { type = 'default', gradientStops, curve = curveLinear, color, context, ...props }: LineChartInnerProps<T> = $props();
24
+
25
+ const gradientId = 'gradient-' + nanoid(8);
26
+
27
+ function isLineSeries(series: ChartSeries<T, keyof T>) {
28
+ if (!('type' in series)) return true;
29
+
30
+ return series.type === 'line';
31
+ }
32
+
33
+ $inspect(context.data);
34
+ </script>
35
+
36
+ {#if type === 'gradient' && gradientStops}
37
+ <defs>
38
+ <linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
39
+ {#each gradientStops as stop}
40
+ <stop offset="{stop.offset}%" stop-color={getThemeColor(stop.color)} />
41
+ {/each}
42
+ </linearGradient>
43
+ </defs>
44
+ {/if}
45
+
46
+ {#if context.xRange}
47
+ {#each context.series as series}
48
+ {#if isLineSeries(series)}
49
+ <path
50
+ {...props}
51
+ class={['line', props.class]}
52
+ stroke={type === 'gradient' ? `url(#${gradientId})` : getThemeColor(series.color || color)}
53
+ d={line<T>({
54
+ x: (d) => context.xScale(context.xAccessor(d)),
55
+ y: (d) => context.yScale(series.accessor?.(d[series.name]) || d[series.name]),
56
+ curve,
57
+ })(context.data)}
58
+ />
59
+ {/if}
60
+ {/each}
61
+ {/if}
62
+
63
+ <style>.line {
64
+ fill: none;
65
+ stroke-width: 2;
66
+ }</style>
@@ -0,0 +1,34 @@
1
+ import type { ChartContext } from '../ChartRoot/ChartContext.svelte.js';
2
+ import type { ChartData } from '../types.js';
3
+ import { type __LineChartProps } from './LineChart.svelte';
4
+ type PathElement = SvelteHTMLElements['path'];
5
+ export interface LineChartInnerProps<T extends ChartData> extends __LineChartProps, Omit<PathElement, 'color' | 'type'> {
6
+ context: ChartContext<T>;
7
+ /** z-index of the line */
8
+ zIndex?: number;
9
+ }
10
+ import type { SvelteHTMLElements } from 'svelte/elements';
11
+ declare function $$render<T extends ChartData>(): {
12
+ props: LineChartInnerProps<T>;
13
+ exports: {};
14
+ bindings: "";
15
+ slots: {};
16
+ events: {};
17
+ };
18
+ declare class __sveltets_Render<T extends ChartData> {
19
+ props(): ReturnType<typeof $$render<T>>['props'];
20
+ events(): ReturnType<typeof $$render<T>>['events'];
21
+ slots(): ReturnType<typeof $$render<T>>['slots'];
22
+ bindings(): "";
23
+ exports(): {};
24
+ }
25
+ interface $$IsomorphicComponent {
26
+ new <T extends ChartData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
27
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
28
+ } & ReturnType<__sveltets_Render<T>['exports']>;
29
+ <T extends ChartData>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
30
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
31
+ }
32
+ declare const LineChartInner: $$IsomorphicComponent;
33
+ type LineChartInner<T extends ChartData> = InstanceType<typeof LineChartInner<T>>;
34
+ export default LineChartInner;
@@ -0,0 +1,33 @@
1
+ <script lang="ts" module>
2
+ import type { MantineColor } from '../../MantineProvider/theme.types.js';
3
+ import type { ChartRootProps } from '../ChartRoot/ChartRoot.svelte';
4
+ import type { ChartData } from '../types.js';
5
+
6
+ export interface LineChartGradientStop {
7
+ offset: number;
8
+ color: MantineColor;
9
+ }
10
+
11
+ export interface __ScatterChartProps {
12
+ /** Color of the dots */
13
+ color?: MantineColor;
14
+
15
+ /** Size of the dots. 4.5 by default. */
16
+ dotSize?: number;
17
+ }
18
+
19
+ export interface ScatterChartProps<T extends ChartData> extends __ScatterChartProps, Omit<ChartRootProps<T>, 'children'> {}
20
+ </script>
21
+
22
+ <script lang="ts" generics="T extends ChartData">
23
+ import ChartRoot from '../ChartRoot/ChartRoot.svelte';
24
+ import ScatterChartInner from './ScatterChartInner.svelte';
25
+
26
+ let { color, dotSize = 4.5, ...props }: ScatterChartProps<T> = $props();
27
+ </script>
28
+
29
+ <ChartRoot {...props}>
30
+ {#snippet children(context)}
31
+ <ScatterChartInner {context} {color} {dotSize} />
32
+ {/snippet}
33
+ </ChartRoot>
@@ -0,0 +1,39 @@
1
+ import type { MantineColor } from '../../MantineProvider/theme.types.js';
2
+ import type { ChartRootProps } from '../ChartRoot/ChartRoot.svelte';
3
+ import type { ChartData } from '../types.js';
4
+ export interface LineChartGradientStop {
5
+ offset: number;
6
+ color: MantineColor;
7
+ }
8
+ export interface __ScatterChartProps {
9
+ /** Color of the dots */
10
+ color?: MantineColor;
11
+ /** Size of the dots. 4.5 by default. */
12
+ dotSize?: number;
13
+ }
14
+ export interface ScatterChartProps<T extends ChartData> extends __ScatterChartProps, Omit<ChartRootProps<T>, 'children'> {
15
+ }
16
+ declare function $$render<T extends ChartData>(): {
17
+ props: ScatterChartProps<T>;
18
+ exports: {};
19
+ bindings: "";
20
+ slots: {};
21
+ events: {};
22
+ };
23
+ declare class __sveltets_Render<T extends ChartData> {
24
+ props(): ReturnType<typeof $$render<T>>['props'];
25
+ events(): ReturnType<typeof $$render<T>>['events'];
26
+ slots(): ReturnType<typeof $$render<T>>['slots'];
27
+ bindings(): "";
28
+ exports(): {};
29
+ }
30
+ interface $$IsomorphicComponent {
31
+ new <T extends ChartData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
32
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
33
+ } & ReturnType<__sveltets_Render<T>['exports']>;
34
+ <T extends ChartData>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
35
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
36
+ }
37
+ declare const ScatterChart: $$IsomorphicComponent;
38
+ type ScatterChart<T extends ChartData> = InstanceType<typeof ScatterChart<T>>;
39
+ export default ScatterChart;