@communitiesuk/svelte-component-library 0.1.19-beta.16 → 0.1.19-beta.18

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 (37) hide show
  1. package/README.md +7 -0
  2. package/dist/components/data-vis/axis/Axis.svelte +25 -43
  3. package/dist/components/data-vis/axis/Axis.svelte.d.ts +6 -6
  4. package/dist/components/data-vis/axis/Ticks.svelte +63 -92
  5. package/dist/components/data-vis/axis/Ticks.svelte.d.ts +7 -9
  6. package/dist/components/data-vis/line-chart/LineChart.svelte +51 -21
  7. package/dist/components/data-vis/line-chart/LineChart.svelte.d.ts +15 -7
  8. package/dist/components/data-vis/line-chart/ValueLabel.svelte +10 -21
  9. package/dist/components/data-vis/line-chart/ValueLabel.svelte.d.ts +0 -2
  10. package/dist/components/data-vis/position-chart/PositionChart.svelte +398 -1007
  11. package/dist/components/data-vis/position-chart/PositionChart.svelte.d.ts +17 -35
  12. package/dist/components/data-vis/position-chart/PositionChartAxis.svelte +21 -41
  13. package/dist/components/data-vis/position-chart/PositionChartAxis.svelte.d.ts +0 -2
  14. package/dist/components/ui/BasicMultiSelect.svelte +185 -0
  15. package/dist/components/ui/BasicMultiSelect.svelte.d.ts +8 -0
  16. package/dist/components/ui/Card.svelte +0 -8
  17. package/dist/components/ui/Card.svelte.d.ts +0 -2
  18. package/dist/components/ui/ChartExporter.svelte +142 -0
  19. package/dist/components/ui/ChartExporter.svelte.d.ts +16 -0
  20. package/dist/components/ui/CheckBox.svelte +1 -2
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.js +2 -1
  23. package/package.json +3 -2
  24. package/dist/components/data-vis/histogram/Histogram.svelte +0 -335
  25. package/dist/components/data-vis/histogram/Histogram.svelte.d.ts +0 -49
  26. package/dist/components/data-vis/position-chart/assignBinColors.d.ts +0 -1
  27. package/dist/components/data-vis/position-chart/assignBinColors.js +0 -13
  28. package/dist/components/data-vis/position-chart/createEqualWidthBins.d.ts +0 -12
  29. package/dist/components/data-vis/position-chart/createEqualWidthBins.js +0 -42
  30. package/dist/components/data-vis/position-chart/getColorsForValues.d.ts +0 -1
  31. package/dist/components/data-vis/position-chart/getColorsForValues.js +0 -16
  32. package/dist/components/data-vis/position-chart/interpolateColors.d.ts +0 -1
  33. package/dist/components/data-vis/position-chart/interpolateColors.js +0 -68
  34. package/dist/components/data-vis/position-chart/splitGroupsAndAverages.d.ts +0 -4
  35. package/dist/components/data-vis/position-chart/splitGroupsAndAverages.js +0 -20
  36. package/dist/server/lastUpdated.d.ts +0 -1
  37. package/dist/server/lastUpdated.js +0 -10
package/README.md CHANGED
@@ -103,6 +103,13 @@ Make sure you are on your main development branch you want to release (e.g., `ma
103
103
 
104
104
  Use the `npm version` command to update `package.json` and `package-lock.json`, create a commit, and create an annotated Git tag. Choose **one** of the following based on [Semantic Versioning (SemVer)](https://semver.org/):
105
105
 
106
+
107
+ - **Pre-Release:**
108
+
109
+ ```bash
110
+ npm version prerelease --preid=alpha
111
+ ```
112
+
106
113
  - **Patch Release (Bug fixes, tiny changes - e.g., 1.0.0 → 1.0.1):**
107
114
 
108
115
  ```bash
@@ -7,41 +7,34 @@
7
7
  import Ticks from "./Ticks.svelte";
8
8
 
9
9
  type AxisName = "x" | "y";
10
- type Polarity = "standard" | "reverse";
11
-
12
10
  type AxisPosition = "bottom" | "top" | "left" | "right";
13
11
  type Orientation = { axis: AxisName; position: AxisPosition };
14
12
  type AxisProjector = (value: number) => number;
15
- type LabelFormatter = (
16
- tick: number,
17
- index: number,
18
- numberOfTicks: number,
19
- values: number[],
20
- ) => string | number;
13
+ type LabelFormatter = (tick: number, index: number) => string | number;
14
+ type Polarity = "standard" | "reverse";
21
15
 
22
16
  let {
23
17
  chartHeight = 100,
24
18
  chartWidth = $bindable<number>(200),
25
19
 
26
- numberOfTicks = 2,
20
+ numberOfTicks = undefined as number | undefined,
27
21
 
28
22
  // Bindable, but avoid binding undefined – initialize as [] for safety
29
23
  ticksArray = $bindable<number[]>([]),
30
24
 
31
25
  // Values to derive ticks/domain from if ticksArray not provided
32
- values = undefined as number[] | undefined,
26
+ min = undefined as number | undefined,
27
+ max = undefined as number | undefined,
33
28
 
34
29
  orientation = { axis: "x", position: "bottom" } as Orientation,
35
30
 
36
- floor = null,
37
- ceiling = null,
31
+ floor = undefined as number | undefined,
32
+ ceiling = undefined as number | undefined,
38
33
 
39
34
  paddingTop = 100,
40
35
  paddingBottom = 100,
41
36
  paddingLeft = 0,
42
37
  paddingRight = 0,
43
- tickStrokeWidth = 2,
44
- axisStrokeWidth = 2,
45
38
 
46
39
  labelFormatter = undefined as LabelFormatter | undefined,
47
40
 
@@ -54,17 +47,18 @@
54
47
  domain = undefined as [number, number] | undefined,
55
48
  range = undefined as [number, number] | undefined,
56
49
  fontSize = 19,
57
- polarity = "standard" as Polarity,
58
- gridlines = false,
50
+ polarity = "standard",
59
51
  }: {
60
52
  chartHeight?: number;
61
53
  chartWidth?: number;
62
54
  numberOfTicks?: number;
63
55
  ticksArray?: number[];
64
- values?: number[];
56
+ min?: number;
57
+ max?: number;
58
+
65
59
  orientation?: Orientation;
66
- floor?: number | null;
67
- ceiling?: number | null;
60
+ floor?: number;
61
+ ceiling?: number;
68
62
  paddingTop?: number;
69
63
  paddingBottom?: number;
70
64
  paddingLeft?: number;
@@ -77,7 +71,6 @@
77
71
  range?: [number, number];
78
72
  fontSize?: number;
79
73
  polarity?: Polarity;
80
- gridlines?: Boolean;
81
74
  } = $props();
82
75
 
83
76
  // --- Helpers to compute default domain/range when not supplied ---
@@ -85,7 +78,8 @@
85
78
  const innerHeight = $derived(Math.max(0, chartHeight));
86
79
 
87
80
  function computeDefaultDomain(): [number, number] {
88
- const arr = (ticksArray && ticksArray.length ? ticksArray : values) ?? [];
81
+ const arr =
82
+ (ticksArray && ticksArray.length ? ticksArray : [min, max]) ?? [];
89
83
  const dMin =
90
84
  floor ?? (arr.length ? arr.reduce((a, b) => (a < b ? a : b)) : 0);
91
85
  const dMax =
@@ -109,23 +103,12 @@
109
103
  const useDomain = domain ?? computeDefaultDomain();
110
104
  base.domain(useDomain);
111
105
 
112
- let useRange = range ?? computeDefaultRange(innerWidth, innerHeight);
113
- if (polarity === "reverse") {
114
- useRange = [...useRange].reverse();
115
- }
116
- base.range([...useRange]);
106
+ const useRange = range ?? computeDefaultRange(innerWidth, innerHeight);
107
+ base.range(useRange);
117
108
 
118
109
  return base;
119
110
  });
120
-
121
- const axisFunction: AxisProjector = (v) => {
122
- const s = resolvedScale();
123
- const r = s.range();
124
- const lo = Math.min(r[0], r[1]);
125
- const hi = Math.max(r[0], r[1]);
126
- const px = s(v);
127
- return Math.max(lo, Math.min(hi, px));
128
- };
111
+ const axisFunction: AxisProjector = $derived((v: number) => resolvedScale(v));
129
112
  </script>
130
113
 
131
114
  <g
@@ -135,21 +118,22 @@
135
118
  : chartWidth},{orientation.position === 'bottom' ? chartHeight : 0})"
136
119
  >
137
120
  <line
138
- x1={0}
121
+ x1={range[0]}
139
122
  y1="0"
140
- x2={orientation.axis === "x" ? chartWidth : 0}
123
+ x2={orientation.axis === "x" ? range[1] : 0}
141
124
  y2={orientation.axis === "y" ? chartHeight : 0}
142
- stroke="darkgrey"
143
- stroke-width={axisStrokeWidth}
125
+ stroke="grey"
126
+ stroke-width="2px"
144
127
  ></line>
145
- {#if values}
128
+ {#if ticksArray || (min && max)}
146
129
  {#key numberOfTicks}
147
130
  <Ticks
148
131
  bind:ticksArray
149
132
  {chartWidth}
150
133
  {chartHeight}
151
134
  {axisFunction}
152
- {values}
135
+ {min}
136
+ {max}
153
137
  {numberOfTicks}
154
138
  {orientation}
155
139
  {floor}
@@ -157,8 +141,6 @@
157
141
  {labelFormatter}
158
142
  {fontSize}
159
143
  {polarity}
160
- {tickStrokeWidth}
161
- {gridlines}
162
144
  />
163
145
  {/key}
164
146
  {/if}
@@ -1,21 +1,22 @@
1
1
  import { type ScaleContinuousNumeric } from "d3-scale";
2
2
  type AxisName = "x" | "y";
3
- type Polarity = "standard" | "reverse";
4
3
  type AxisPosition = "bottom" | "top" | "left" | "right";
5
4
  type Orientation = {
6
5
  axis: AxisName;
7
6
  position: AxisPosition;
8
7
  };
9
- type LabelFormatter = (tick: number, index: number, numberOfTicks: number, values: number[]) => string | number;
8
+ type LabelFormatter = (tick: number, index: number) => string | number;
9
+ type Polarity = "standard" | "reverse";
10
10
  type $$ComponentProps = {
11
11
  chartHeight?: number;
12
12
  chartWidth?: number;
13
13
  numberOfTicks?: number;
14
14
  ticksArray?: number[];
15
- values?: number[];
15
+ min?: number;
16
+ max?: number;
16
17
  orientation?: Orientation;
17
- floor?: number | null;
18
- ceiling?: number | null;
18
+ floor?: number;
19
+ ceiling?: number;
19
20
  paddingTop?: number;
20
21
  paddingBottom?: number;
21
22
  paddingLeft?: number;
@@ -26,7 +27,6 @@ type $$ComponentProps = {
26
27
  range?: [number, number];
27
28
  fontSize?: number;
28
29
  polarity?: Polarity;
29
- gridlines?: Boolean;
30
30
  };
31
31
  declare const Axis: import("svelte").Component<$$ComponentProps, {}, "ticksArray" | "chartWidth">;
32
32
  type Axis = ReturnType<typeof Axis>;
@@ -3,91 +3,76 @@
3
3
 
4
4
  // Types
5
5
  type Axis = "x" | "y";
6
- type Polarity = "standard" | "reverse";
7
6
  type Position = "left" | "right" | "top" | "bottom";
8
7
 
9
8
  interface Orientation {
10
9
  axis: Axis;
11
10
  position: Position;
12
11
  }
12
+ type Polarity = "standard" | "reverse";
13
13
 
14
- // Props with defaults
14
+ // Props with defaults (Svelte 5 runes)
15
15
  let {
16
16
  ticksArray = $bindable<number[]>(),
17
17
  chartWidth,
18
18
  chartHeight,
19
19
  axisFunction,
20
- values,
20
+ min,
21
+ max,
21
22
  numberOfTicks,
22
- tickStrokeWidth,
23
23
  floor,
24
24
  ceiling,
25
25
  orientation,
26
26
  labelFormatter,
27
27
  fontSize = 19,
28
- clamp = false,
29
28
  polarity = "standard",
30
- gridlines = false,
31
29
  }: {
32
- ticksArray?: number[];
30
+ ticksArray?: number[]; // bindable
33
31
  chartWidth: number;
34
32
  chartHeight: number;
35
33
  axisFunction: any;
36
- values: number[];
34
+ min: number;
35
+ max: number;
37
36
  numberOfTicks?: number;
38
- tickStrokeWidth?: number;
39
-
40
- floor?: number | null;
41
- ceiling?: number | null;
37
+ floor?: number;
38
+ ceiling?: number;
42
39
  orientation: Orientation;
43
- labelFormatter?: (
44
- tick: number,
45
- index: number,
46
- numberOfTicks: number,
47
- values: number[],
48
- ) => string;
40
+ labelFormatter?: (tick: number, index: number) => string;
49
41
  fontSize?: number;
50
- clamp: boolean;
51
- polarity: Polarity;
52
- gridlines: boolean;
42
+ polarity?: Polarity;
53
43
  } = $props();
54
-
55
- // Axis value helper
56
44
  function axisValue(fn: any, tick: number): number {
45
+ // Try single-call first: axisFunction(tick)
57
46
  try {
58
47
  const v = fn(tick);
59
48
  if (typeof v === "number") return v;
60
- } catch {}
49
+ } catch {
50
+ // ignore
51
+ }
52
+
53
+ // Fallback: axisFunction()(tick)
61
54
  const inner = fn();
62
55
  return inner(tick);
63
56
  }
64
57
 
65
- // Generate ticks safely
66
58
  function generateTicks(
67
- data: number[],
59
+ min: number,
60
+ max: number,
68
61
  numTicks: number,
69
- floorVal?: number | null,
70
- ceilingVal?: number | null,
62
+ floorVal?: number,
63
+ ceilingVal?: number,
71
64
  ): number[] {
72
- if (!data || data.length === 0) return [];
73
-
74
- const dataMin = Decimal.min(...data);
75
- const dataMax = Decimal.max(...data);
65
+ let minVal =
66
+ floorVal !== undefined ? new Decimal(floorVal) : new Decimal(min);
76
67
 
77
- const minVal = floorVal != null ? new Decimal(floorVal) : dataMin;
78
- const maxVal = ceilingVal != null ? new Decimal(ceilingVal) : dataMax;
68
+ let maxVal =
69
+ ceilingVal !== undefined ? new Decimal(ceilingVal) : new Decimal(max);
79
70
 
80
71
  const rangeVal = maxVal.minus(minVal);
81
-
82
- // Ensure at least 2 ticks
83
- const stepCount = Math.max(2, numTicks - 1);
84
- const roughStep = rangeVal.div(stepCount);
85
-
72
+ const roughStep = rangeVal.div(numTicks - 1);
86
73
  const normalizedSteps = [
87
- 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1, 2, 2.5, 3, 4, 5, 6, 8, 10, 12, 15,
88
- 25, 30, 35, 40, 45,
74
+ 1, 2, 2.5, 3, 4, 5, 6, 8, 10, 12, 15, 25, 30, 35, 40, 45,
89
75
  ];
90
-
91
76
  const stepPower = Decimal.pow(
92
77
  10,
93
78
  -Math.floor(Math.log10(roughStep.toNumber())),
@@ -97,26 +82,10 @@
97
82
  const chosen = normalizedSteps.find(
98
83
  (step) => step >= normalizedStep.toNumber(),
99
84
  );
85
+ const optimalStep = new Decimal(chosen ?? 10).div(stepPower);
100
86
 
101
- let chosenIdx = normalizedSteps.findIndex(
102
- (step) => step >= normalizedStep.toNumber(),
103
- );
104
-
105
- let optimalStep: Decimal;
106
- let scaleMin: Decimal;
107
- let scaleMax: Decimal;
108
-
109
- for (let i = chosenIdx; i >= 0; i--) {
110
- optimalStep = new Decimal(normalizedSteps[i]).div(stepPower);
111
- scaleMin = minVal.div(optimalStep).floor().mul(optimalStep);
112
- scaleMax = maxVal.div(optimalStep).ceil().mul(optimalStep);
113
-
114
- const axisRange = scaleMax.minus(scaleMin);
115
- const dataRange = maxVal.minus(minVal);
116
- const paddingRatio = axisRange.minus(dataRange).div(axisRange).toNumber();
117
-
118
- if (paddingRatio <= 0.3) break;
119
- }
87
+ const scaleMin = minVal.div(optimalStep).floor().mul(optimalStep);
88
+ const scaleMax = maxVal.div(optimalStep).ceil().mul(optimalStep);
120
89
 
121
90
  const ticks: number[] = [];
122
91
  for (let i = scaleMin; i.lte(scaleMax); i = i.plus(optimalStep)) {
@@ -125,47 +94,51 @@
125
94
  return ticks;
126
95
  }
127
96
 
128
- // Default label generator
97
+ // Default label when no labelFormatter is supplied
129
98
  function defaultLabel(tick: number): string {
130
99
  return String(tick);
131
100
  }
132
101
 
133
- // Compute number of ticks
134
102
  function tickCount(w: number, h: number): number {
135
- const rawTicks = orientation.axis === "y" ? h / 50 : w / 50;
136
- return Math.max(2, Math.floor(rawTicks));
103
+ // Keep behavior aligned with your original code.
104
+ const tickNum = orientation.axis === "y" ? h / 50 : w / 50;
105
+ return tickNum;
137
106
  }
138
-
139
- // Clamp ticks safely
140
107
  function clampTickEnds(
141
108
  ticks: number[],
142
- floorVal?: number | null,
143
- ceilingVal?: number | null,
109
+ floor?: number,
110
+ ceiling?: number,
144
111
  ): number[] {
145
112
  if (!ticks || ticks.length === 0) return ticks;
113
+
146
114
  const out = ticks.slice();
147
115
 
148
- if (floorVal != null && out[0] < floorVal) {
149
- out[0] = floorVal;
116
+ if (floor !== undefined && out[0] <= floor) {
117
+ out[0] = floor;
150
118
  }
151
- if (ceilingVal != null && out[out.length - 1] > ceilingVal) {
152
- out[out.length - 1] = ceilingVal;
119
+ if (ceiling !== undefined && out[out.length - 1] >= ceiling) {
120
+ out[out.length - 1] = ceiling;
153
121
  }
154
122
  return out;
155
123
  }
156
124
 
157
- // Compute derived ticks
158
- const computedTickCount = numberOfTicks ?? tickCount(chartWidth, chartHeight);
125
+ // Compute ticks
126
+ let computedTickCount = $derived(
127
+ numberOfTicks ?? tickCount(chartWidth, chartHeight),
128
+ );
129
+
130
+ let rawTicks = $derived(
131
+ generateTicks(min, max, computedTickCount, floor, ceiling),
132
+ );
159
133
 
160
- let derivedTicks = $derived(() => {
161
- const ticks = generateTicks(values, computedTickCount, floor, ceiling);
162
- return clamp ? clampTickEnds(ticks, floor, ceiling) : ticks;
163
- });
134
+ let ticksOrdered = $derived(
135
+ polarity === "standard" ? rawTicks : rawTicks.reverse(),
136
+ );
164
137
 
165
- ticksArray = derivedTicks();
138
+ ticksArray = ticksOrdered;
166
139
  </script>
167
140
 
168
- {#if axisFunction && ticksArray?.length && orientation.axis && orientation.position}
141
+ {#if axisFunction && ticksArray && orientation.axis && orientation.position}
169
142
  {#each ticksArray as tick, index}
170
143
  <g
171
144
  transform="translate(
@@ -176,13 +149,13 @@
176
149
  <path
177
150
  d={orientation.axis === "y"
178
151
  ? orientation.position === "left"
179
- ? `M0 0 l${gridlines ? chartWidth : -8} 0`
180
- : "M0 0 l8 0"
152
+ ? "M0 -1 l-8 0"
153
+ : "M0 -1 l8 0"
181
154
  : orientation.position === "top"
182
- ? "M0 0 l0 -8"
183
- : "M0 0 l0 8"}
184
- stroke="darkgrey"
185
- stroke-width={tickStrokeWidth}
155
+ ? "M0 -1 l0 -8"
156
+ : "M0 -1 l0 8"}
157
+ stroke="grey"
158
+ stroke-width="2px"
186
159
  ></path>
187
160
  <text
188
161
  transform="translate(
@@ -195,7 +168,7 @@
195
168
  ? 5
196
169
  : orientation.position === 'top'
197
170
  ? -10
198
- : 23}
171
+ : fontSize * 1.4}
199
172
  )"
200
173
  font-size={fontSize}
201
174
  text-anchor={orientation.axis === "x"
@@ -203,11 +176,9 @@
203
176
  : orientation.position === "left"
204
177
  ? "end"
205
178
  : "start"}
206
- fill="#666666"
179
+ fill="grey"
207
180
  >
208
- {labelFormatter
209
- ? labelFormatter(tick, index, ticksArray.length, values)
210
- : defaultLabel(tick)}
181
+ {labelFormatter ? labelFormatter(tick, index) : defaultLabel(tick)}
211
182
  </text>
212
183
  </g>
213
184
  {/each}
@@ -1,26 +1,24 @@
1
1
  type Axis = "x" | "y";
2
- type Polarity = "standard" | "reverse";
3
2
  type Position = "left" | "right" | "top" | "bottom";
4
3
  interface Orientation {
5
4
  axis: Axis;
6
5
  position: Position;
7
6
  }
7
+ type Polarity = "standard" | "reverse";
8
8
  type $$ComponentProps = {
9
9
  ticksArray?: number[];
10
10
  chartWidth: number;
11
11
  chartHeight: number;
12
12
  axisFunction: any;
13
- values: number[];
13
+ min: number;
14
+ max: number;
14
15
  numberOfTicks?: number;
15
- tickStrokeWidth?: number;
16
- floor?: number | null;
17
- ceiling?: number | null;
16
+ floor?: number;
17
+ ceiling?: number;
18
18
  orientation: Orientation;
19
- labelFormatter?: (tick: number, index: number, numberOfTicks: number, values: number[]) => string;
19
+ labelFormatter?: (tick: number, index: number) => string;
20
20
  fontSize?: number;
21
- clamp: boolean;
22
- polarity: Polarity;
23
- gridlines: boolean;
21
+ polarity?: Polarity;
24
22
  };
25
23
  declare const Ticks: import("svelte").Component<$$ComponentProps, {}, "ticksArray">;
26
24
  type Ticks = ReturnType<typeof Ticks>;
@@ -8,6 +8,7 @@
8
8
  import { highlight } from "./../../../utils/syntax-highlighting/shikiHighlight";
9
9
  import Lines from "./Lines.svelte";
10
10
  import ValueLabel from "./ValueLabel.svelte";
11
+ import Axis from "../axis/Axis.svelte";
11
12
 
12
13
  let {
13
14
  series,
@@ -15,17 +16,18 @@
15
16
  x,
16
17
  lineChartData,
17
18
 
18
- xFunction = (number) => {
19
- return scaleLinear()
20
- .domain([2015, 2022])
21
- .range([0, svgWidth - paddingLeft - paddingRight])(number);
19
+ xScale = (number) => {
20
+ return scaleLinear().domain([xTickMin, xTickMax]).range([0, chartWidth])(
21
+ number,
22
+ );
22
23
  },
23
- yFunction = (number) => {
24
- return scaleLinear()
25
- .domain([0, 100])
26
- .range([svgHeight - paddingTop - paddingBottom, 0])(number);
24
+ yScale = (number) => {
25
+ return scaleLinear().domain([yTickMin, yTickMax]).range([chartHeight, 0])(
26
+ number,
27
+ );
27
28
  },
28
- lineFunction = line()
29
+
30
+ lineScale = line()
29
31
  .x((d) => xFunction(d[x]))
30
32
  .y((d) => yFunction(d[y]))
31
33
  .curve(curveLinear),
@@ -108,6 +110,10 @@
108
110
  paddingBottom = 50,
109
111
  paddingLeft = 50,
110
112
  paddingRight = 150,
113
+ xFloor = undefined,
114
+ xCeiling = undefined,
115
+ yFloor = undefined,
116
+ yCeiling = undefined,
111
117
  activeMarkerId = undefined,
112
118
  chartBackgroundColor = "#f5f5f5",
113
119
  seriesLabels = $bindable(false),
@@ -157,6 +163,18 @@
157
163
  },
158
164
  } = $props();
159
165
 
166
+ let xTicks = $state([]);
167
+ let yTicks = $state([]);
168
+
169
+ const xTickMin = $derived(xTicks.length ? Math.min(...xTicks) : undefined);
170
+ const xTickMax = $derived(xTicks.length ? Math.max(...xTicks) : undefined);
171
+ const yTickMin = $derived(yTicks.length ? Math.min(...yTicks) : undefined);
172
+ const yTickMax = $derived(yTicks.length ? Math.max(...yTicks) : undefined);
173
+
174
+ let xFunction = $derived((value) => xScale(value));
175
+ let yFunction = $derived((value) => yScale(value));
176
+ let lineFunction = $derived((value) => lineScale(value));
177
+
160
178
  const colorValues = Array.isArray(colors) ? colors : Object.values(colors);
161
179
  const lineColorMap = {};
162
180
 
@@ -197,7 +215,7 @@
197
215
  let chartHeight = $derived(svgHeight - paddingTop - paddingBottom);
198
216
  let areaFunction = $derived(
199
217
  area()
200
- .y0((d) => yFunction(0))
218
+ .y0((d) => yFunction(yTickMin))
201
219
  .x((d) => xFunction(d.x))
202
220
  .y1((d) => yFunction(d.y))
203
221
  .curve(curveLinear),
@@ -292,17 +310,29 @@
292
310
  >
293
311
  {#if svgWidth}
294
312
  <g transform="translate({paddingLeft},{paddingTop})">
295
- <g data-role="y-axis">
296
- <path d="M0 0 l0 {chartHeight}" stroke="black" stroke-width="2px"
297
- ></path>
298
- </g>
299
- <g data-role="x-axis">
300
- <path
301
- d="M0 {chartHeight} l{chartWidth} 0"
302
- stroke="black"
303
- stroke-width="2px"
304
- ></path>
305
- </g>
313
+ <Axis
314
+ bind:ticksArray={yTicks}
315
+ {chartHeight}
316
+ {chartWidth}
317
+ orientation={{ axis: "y", position: "left" }}
318
+ range={[chartHeight, 0]}
319
+ domain={[yTickMin, yTickMax]}
320
+ values={lineChartData.lines.flatMap((l) => l.data.map((d) => d[y]))}
321
+ ceiling={yCeiling ?? yTickMax}
322
+ floor={yFloor ?? yTickMin}
323
+ ></Axis>
324
+ <!--X axis-->
325
+ <Axis
326
+ bind:ticksArray={xTicks}
327
+ {chartWidth}
328
+ {chartHeight}
329
+ orientation={{ axis: "x", position: "bottom" }}
330
+ values={lineChartData.lines.flatMap((l) => l.data.map((d) => d[x]))}
331
+ range={[0, chartWidth]}
332
+ domain={[xTickMin, xTickMax]}
333
+ ceiling={xCeiling ?? xTickMax}
334
+ floor={xFloor ?? xTickMin}
335
+ ></Axis>
306
336
  <g data-role="lines-group">
307
337
  <Lines
308
338
  {tieredDataObject}
@@ -8,9 +8,9 @@ declare const LineChart: import("svelte").Component<{
8
8
  y: any;
9
9
  x: any;
10
10
  lineChartData: any;
11
- xFunction?: Function;
12
- yFunction?: Function;
13
- lineFunction?: any;
11
+ xScale?: Function;
12
+ yScale?: Function;
13
+ lineScale?: any;
14
14
  labelText?: Function;
15
15
  onClickSeries?: Function;
16
16
  onMouseLeaveSeries?: Function;
@@ -34,6 +34,10 @@ declare const LineChart: import("svelte").Component<{
34
34
  paddingBottom?: number;
35
35
  paddingLeft?: number;
36
36
  paddingRight?: number;
37
+ xFloor?: any;
38
+ xCeiling?: any;
39
+ yFloor?: any;
40
+ yCeiling?: any;
37
41
  activeMarkerId?: any;
38
42
  chartBackgroundColor?: string;
39
43
  seriesLabels?: boolean;
@@ -44,15 +48,15 @@ declare const LineChart: import("svelte").Component<{
44
48
  basicLineParams?: Record<string, any>;
45
49
  colorLineParams?: Function;
46
50
  colors?: Record<string, any>;
47
- }, {}, "container" | "clickedSeries" | "hoveredSeries" | "clickedTier" | "hoveredTier" | "svgWidth" | "seriesLabels">;
51
+ }, {}, "clickedSeries" | "hoveredSeries" | "clickedTier" | "hoveredTier" | "svgWidth" | "container" | "seriesLabels">;
48
52
  type $$ComponentProps = {
49
53
  series: any;
50
54
  y: any;
51
55
  x: any;
52
56
  lineChartData: any;
53
- xFunction?: Function;
54
- yFunction?: Function;
55
- lineFunction?: any;
57
+ xScale?: Function;
58
+ yScale?: Function;
59
+ lineScale?: any;
56
60
  labelText?: Function;
57
61
  onClickSeries?: Function;
58
62
  onMouseLeaveSeries?: Function;
@@ -76,6 +80,10 @@ type $$ComponentProps = {
76
80
  paddingBottom?: number;
77
81
  paddingLeft?: number;
78
82
  paddingRight?: number;
83
+ xFloor?: any;
84
+ xCeiling?: any;
85
+ yFloor?: any;
86
+ yCeiling?: any;
79
87
  activeMarkerId?: any;
80
88
  chartBackgroundColor?: string;
81
89
  seriesLabels?: boolean;