@communitiesuk/svelte-component-library 0.1.19-beta.15 → 0.1.19-beta.16
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/data-vis/axis/Axis.svelte +7 -1
- package/dist/components/data-vis/axis/Axis.svelte.d.ts +1 -0
- package/dist/components/data-vis/axis/Ticks.svelte +26 -5
- package/dist/components/data-vis/axis/Ticks.svelte.d.ts +2 -0
- package/dist/components/data-vis/histogram/Histogram.svelte +80 -48
- package/dist/components/data-vis/histogram/Histogram.svelte.d.ts +4 -2
- package/package.json +1 -1
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
paddingBottom = 100,
|
|
41
41
|
paddingLeft = 0,
|
|
42
42
|
paddingRight = 0,
|
|
43
|
+
tickStrokeWidth = 2,
|
|
44
|
+
axisStrokeWidth = 2,
|
|
43
45
|
|
|
44
46
|
labelFormatter = undefined as LabelFormatter | undefined,
|
|
45
47
|
|
|
@@ -53,6 +55,7 @@
|
|
|
53
55
|
range = undefined as [number, number] | undefined,
|
|
54
56
|
fontSize = 19,
|
|
55
57
|
polarity = "standard" as Polarity,
|
|
58
|
+
gridlines = false,
|
|
56
59
|
}: {
|
|
57
60
|
chartHeight?: number;
|
|
58
61
|
chartWidth?: number;
|
|
@@ -74,6 +77,7 @@
|
|
|
74
77
|
range?: [number, number];
|
|
75
78
|
fontSize?: number;
|
|
76
79
|
polarity?: Polarity;
|
|
80
|
+
gridlines?: Boolean;
|
|
77
81
|
} = $props();
|
|
78
82
|
|
|
79
83
|
// --- Helpers to compute default domain/range when not supplied ---
|
|
@@ -136,7 +140,7 @@
|
|
|
136
140
|
x2={orientation.axis === "x" ? chartWidth : 0}
|
|
137
141
|
y2={orientation.axis === "y" ? chartHeight : 0}
|
|
138
142
|
stroke="darkgrey"
|
|
139
|
-
stroke-width=
|
|
143
|
+
stroke-width={axisStrokeWidth}
|
|
140
144
|
></line>
|
|
141
145
|
{#if values}
|
|
142
146
|
{#key numberOfTicks}
|
|
@@ -153,6 +157,8 @@
|
|
|
153
157
|
{labelFormatter}
|
|
154
158
|
{fontSize}
|
|
155
159
|
{polarity}
|
|
160
|
+
{tickStrokeWidth}
|
|
161
|
+
{gridlines}
|
|
156
162
|
/>
|
|
157
163
|
{/key}
|
|
158
164
|
{/if}
|
|
@@ -26,6 +26,7 @@ type $$ComponentProps = {
|
|
|
26
26
|
range?: [number, number];
|
|
27
27
|
fontSize?: number;
|
|
28
28
|
polarity?: Polarity;
|
|
29
|
+
gridlines?: Boolean;
|
|
29
30
|
};
|
|
30
31
|
declare const Axis: import("svelte").Component<$$ComponentProps, {}, "ticksArray" | "chartWidth">;
|
|
31
32
|
type Axis = ReturnType<typeof Axis>;
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
axisFunction,
|
|
20
20
|
values,
|
|
21
21
|
numberOfTicks,
|
|
22
|
+
tickStrokeWidth,
|
|
22
23
|
floor,
|
|
23
24
|
ceiling,
|
|
24
25
|
orientation,
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
fontSize = 19,
|
|
27
28
|
clamp = false,
|
|
28
29
|
polarity = "standard",
|
|
30
|
+
gridlines = false,
|
|
29
31
|
}: {
|
|
30
32
|
ticksArray?: number[];
|
|
31
33
|
chartWidth: number;
|
|
@@ -33,6 +35,8 @@
|
|
|
33
35
|
axisFunction: any;
|
|
34
36
|
values: number[];
|
|
35
37
|
numberOfTicks?: number;
|
|
38
|
+
tickStrokeWidth?: number;
|
|
39
|
+
|
|
36
40
|
floor?: number | null;
|
|
37
41
|
ceiling?: number | null;
|
|
38
42
|
orientation: Orientation;
|
|
@@ -45,6 +49,7 @@
|
|
|
45
49
|
fontSize?: number;
|
|
46
50
|
clamp: boolean;
|
|
47
51
|
polarity: Polarity;
|
|
52
|
+
gridlines: boolean;
|
|
48
53
|
} = $props();
|
|
49
54
|
|
|
50
55
|
// Axis value helper
|
|
@@ -92,10 +97,26 @@
|
|
|
92
97
|
const chosen = normalizedSteps.find(
|
|
93
98
|
(step) => step >= normalizedStep.toNumber(),
|
|
94
99
|
);
|
|
95
|
-
const optimalStep = new Decimal(chosen ?? 10).div(stepPower);
|
|
96
100
|
|
|
97
|
-
|
|
98
|
-
|
|
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
|
+
}
|
|
99
120
|
|
|
100
121
|
const ticks: number[] = [];
|
|
101
122
|
for (let i = scaleMin; i.lte(scaleMax); i = i.plus(optimalStep)) {
|
|
@@ -155,13 +176,13 @@
|
|
|
155
176
|
<path
|
|
156
177
|
d={orientation.axis === "y"
|
|
157
178
|
? orientation.position === "left"
|
|
158
|
-
?
|
|
179
|
+
? `M0 0 l${gridlines ? chartWidth : -8} 0`
|
|
159
180
|
: "M0 0 l8 0"
|
|
160
181
|
: orientation.position === "top"
|
|
161
182
|
? "M0 0 l0 -8"
|
|
162
183
|
: "M0 0 l0 8"}
|
|
163
184
|
stroke="darkgrey"
|
|
164
|
-
stroke-width=
|
|
185
|
+
stroke-width={tickStrokeWidth}
|
|
165
186
|
></path>
|
|
166
187
|
<text
|
|
167
188
|
transform="translate(
|
|
@@ -12,6 +12,7 @@ type $$ComponentProps = {
|
|
|
12
12
|
axisFunction: any;
|
|
13
13
|
values: number[];
|
|
14
14
|
numberOfTicks?: number;
|
|
15
|
+
tickStrokeWidth?: number;
|
|
15
16
|
floor?: number | null;
|
|
16
17
|
ceiling?: number | null;
|
|
17
18
|
orientation: Orientation;
|
|
@@ -19,6 +20,7 @@ type $$ComponentProps = {
|
|
|
19
20
|
fontSize?: number;
|
|
20
21
|
clamp: boolean;
|
|
21
22
|
polarity: Polarity;
|
|
23
|
+
gridlines: boolean;
|
|
22
24
|
};
|
|
23
25
|
declare const Ticks: import("svelte").Component<$$ComponentProps, {}, "ticksArray">;
|
|
24
26
|
type Ticks = ReturnType<typeof Ticks>;
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
color = "grey",
|
|
7
7
|
highlightColor = "black",
|
|
8
8
|
highlightValue = undefined,
|
|
9
|
-
|
|
9
|
+
showXAxis = true,
|
|
10
|
+
showYAxis = true,
|
|
10
11
|
showArrows = true,
|
|
11
12
|
midColor = "#DDDDDD",
|
|
12
13
|
startColor = "#B70000",
|
|
@@ -175,17 +176,23 @@
|
|
|
175
176
|
</script>
|
|
176
177
|
|
|
177
178
|
{#key containerWidth}
|
|
178
|
-
<div
|
|
179
|
-
class="scale-container"
|
|
180
|
-
bind:clientWidth={containerWidth}
|
|
181
|
-
style="height={height * 2}"
|
|
182
|
-
>
|
|
179
|
+
<div class="scale-container" bind:clientWidth={containerWidth}>
|
|
183
180
|
<svg
|
|
184
|
-
class="chart-container"
|
|
185
181
|
width={containerWidth - padding}
|
|
186
|
-
{height}
|
|
182
|
+
height={height + (annotationText ? 25 : 0) + (showXAxis ? 25 : 0)}
|
|
187
183
|
transform="translate({padding / 2},0)"
|
|
188
184
|
>
|
|
185
|
+
<g transform="translate({xScale(highlightValue)},0)">
|
|
186
|
+
<text
|
|
187
|
+
fill="#555555"
|
|
188
|
+
font-size="0.8em"
|
|
189
|
+
text-anchor="middle"
|
|
190
|
+
dominant-baseline="hanging"
|
|
191
|
+
>
|
|
192
|
+
<tspan x="0" dy="0">{annotationText}</tspan>
|
|
193
|
+
<tspan x="0" dy="12">▼</tspan>
|
|
194
|
+
</text>
|
|
195
|
+
</g>
|
|
189
196
|
<defs>
|
|
190
197
|
<marker
|
|
191
198
|
id="arrow-down"
|
|
@@ -201,34 +208,42 @@
|
|
|
201
208
|
<path d="M 0 0 L 6 3 L 0 6 z"></path>
|
|
202
209
|
</marker>
|
|
203
210
|
</defs>
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
211
|
+
|
|
212
|
+
<g transform="translate(0,{annotationText ? 25 : 0})">
|
|
213
|
+
<g>
|
|
214
|
+
{#if showXAxis}
|
|
215
|
+
<Axis
|
|
216
|
+
bind:ticksArray={xTicks}
|
|
217
|
+
chartHeight={height}
|
|
218
|
+
chartWidth={containerWidth - padding}
|
|
219
|
+
orientation={{ axis: "x", position: "bottom" }}
|
|
220
|
+
domain={[xTickMin, xTickMax]}
|
|
221
|
+
range={useRange}
|
|
222
|
+
values={dist}
|
|
223
|
+
fontSize={14}
|
|
224
|
+
{floor}
|
|
225
|
+
{ceiling}
|
|
226
|
+
{labelFormatter}
|
|
227
|
+
numberOfTicks={2}
|
|
228
|
+
></Axis>
|
|
229
|
+
{/if}
|
|
230
|
+
{#if showYAxis}
|
|
231
|
+
<Axis
|
|
232
|
+
bind:ticksArray={yTicks}
|
|
233
|
+
chartHeight={height}
|
|
234
|
+
chartWidth={containerWidth - padding}
|
|
235
|
+
orientation={{ axis: "y", position: "left" }}
|
|
236
|
+
domain={[0, yTickMax]}
|
|
237
|
+
range={[height, 0]}
|
|
238
|
+
values={[...dist, 0]}
|
|
239
|
+
fontSize={0}
|
|
240
|
+
numberOfTicks={5}
|
|
241
|
+
tickStrokeWidth={0.25}
|
|
242
|
+
axisStrokeWidth={0}
|
|
243
|
+
gridlines={true}
|
|
244
|
+
></Axis>
|
|
245
|
+
{/if}
|
|
246
|
+
</g>
|
|
232
247
|
{#each bins as bin, i}
|
|
233
248
|
{#key bin.x0}
|
|
234
249
|
<rect
|
|
@@ -264,19 +279,8 @@
|
|
|
264
279
|
height={yScale(bins[highlightIndex].count)}
|
|
265
280
|
fill={interpolatedColors[highlightIndex]}
|
|
266
281
|
stroke={highlightColor}
|
|
267
|
-
stroke-width={
|
|
282
|
+
stroke-width={0}
|
|
268
283
|
></rect>
|
|
269
|
-
|
|
270
|
-
<g
|
|
271
|
-
transform="translate({xScale(highlightValue)},{height -
|
|
272
|
-
yScale(bins[highlightIndex].count) -
|
|
273
|
-
15})"
|
|
274
|
-
>
|
|
275
|
-
<text fill="#555555" font-size="0.8em" text-anchor="middle">
|
|
276
|
-
<tspan x="0" dy="0">{annotationText}</tspan>
|
|
277
|
-
<tspan x="0" dy="12">▼</tspan>
|
|
278
|
-
</text>
|
|
279
|
-
</g>
|
|
280
284
|
{/key}
|
|
281
285
|
{/if}
|
|
282
286
|
</g>
|
|
@@ -295,6 +299,34 @@
|
|
|
295
299
|
</div>
|
|
296
300
|
{/key}
|
|
297
301
|
|
|
302
|
+
<g style="display: 'none'">
|
|
303
|
+
<Axis
|
|
304
|
+
bind:ticksArray={xTicks}
|
|
305
|
+
chartHeight={height}
|
|
306
|
+
chartWidth={containerWidth - padding}
|
|
307
|
+
orientation={{ axis: "x", position: "bottom" }}
|
|
308
|
+
domain={[xTickMin, xTickMax]}
|
|
309
|
+
range={useRange}
|
|
310
|
+
values={dist}
|
|
311
|
+
fontSize={14}
|
|
312
|
+
{floor}
|
|
313
|
+
{ceiling}
|
|
314
|
+
{labelFormatter}
|
|
315
|
+
></Axis>
|
|
316
|
+
<Axis
|
|
317
|
+
bind:ticksArray={yTicks}
|
|
318
|
+
chartHeight={height}
|
|
319
|
+
chartWidth={containerWidth - padding}
|
|
320
|
+
orientation={{ axis: "y", position: "left" }}
|
|
321
|
+
domain={[0, yTickMax]}
|
|
322
|
+
range={[height, 0]}
|
|
323
|
+
values={dist}
|
|
324
|
+
fontSize={0}
|
|
325
|
+
{floor}
|
|
326
|
+
{ceiling}
|
|
327
|
+
></Axis>
|
|
328
|
+
</g>
|
|
329
|
+
|
|
298
330
|
<style>
|
|
299
331
|
.scale-container svg {
|
|
300
332
|
overflow: visible;
|
|
@@ -10,7 +10,8 @@ declare const Histogram: import("svelte").Component<{
|
|
|
10
10
|
color?: string;
|
|
11
11
|
highlightColor?: string;
|
|
12
12
|
highlightValue?: any;
|
|
13
|
-
|
|
13
|
+
showXAxis?: boolean;
|
|
14
|
+
showYAxis?: boolean;
|
|
14
15
|
showArrows?: boolean;
|
|
15
16
|
midColor?: string;
|
|
16
17
|
startColor?: string;
|
|
@@ -31,7 +32,8 @@ type $$ComponentProps = {
|
|
|
31
32
|
color?: string;
|
|
32
33
|
highlightColor?: string;
|
|
33
34
|
highlightValue?: any;
|
|
34
|
-
|
|
35
|
+
showXAxis?: boolean;
|
|
36
|
+
showYAxis?: boolean;
|
|
35
37
|
showArrows?: boolean;
|
|
36
38
|
midColor?: string;
|
|
37
39
|
startColor?: string;
|