layerchart 0.35.0 → 0.36.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.
|
@@ -30,9 +30,16 @@ const { width, height } = getContext('LayerCake');
|
|
|
30
30
|
const canvas = getContext('canvas');
|
|
31
31
|
const geo = geoContext();
|
|
32
32
|
$: geoPath = geoCurvePath($geo, curve);
|
|
33
|
+
const DEFAULT_FILL = 'rgb(0, 0, 0)';
|
|
33
34
|
$: renderContext = canvas ? 'canvas' : 'svg';
|
|
34
35
|
$: ctx = canvas?.ctx;
|
|
35
36
|
$: if (renderContext === 'canvas' && $ctx) {
|
|
37
|
+
let computedStyles = {};
|
|
38
|
+
// Transfer classes defined on <GeoPath> to <canvas> to enable window.getComputedStyle() retrieval (Tailwind classes, etc)
|
|
39
|
+
if ($$props.class) {
|
|
40
|
+
$ctx.canvas.classList.add(...$$props.class.split(' '));
|
|
41
|
+
computedStyles = window.getComputedStyle($ctx.canvas);
|
|
42
|
+
}
|
|
36
43
|
// console.count('render');
|
|
37
44
|
scaleCanvas($ctx, $width, $height);
|
|
38
45
|
$ctx.clearRect(0, 0, $width, $height);
|
|
@@ -45,10 +52,13 @@ $: if (renderContext === 'canvas' && $ctx) {
|
|
|
45
52
|
// Set the context here since setting it in `$: geoPath` is a circular reference
|
|
46
53
|
geoPath = geoCurvePath($geo, curve, $ctx);
|
|
47
54
|
geoPath(geojson);
|
|
48
|
-
$ctx.fillStyle =
|
|
55
|
+
$ctx.fillStyle =
|
|
56
|
+
fill ??
|
|
57
|
+
(computedStyles.fill !== DEFAULT_FILL ? computedStyles.fill : undefined) ??
|
|
58
|
+
'transparent';
|
|
49
59
|
$ctx.fill();
|
|
50
60
|
$ctx.lineWidth = strokeWidth;
|
|
51
|
-
$ctx.strokeStyle = stroke;
|
|
61
|
+
$ctx.strokeStyle = stroke ?? computedStyles.stroke;
|
|
52
62
|
$ctx.stroke();
|
|
53
63
|
}
|
|
54
64
|
}
|
|
@@ -15,9 +15,12 @@ $: [x, y] = $geo([long, lat]) ?? [0, 0];
|
|
|
15
15
|
$: renderContext = canvas ? 'canvas' : 'svg';
|
|
16
16
|
$: ctx = canvas?.ctx;
|
|
17
17
|
$: if (renderContext === 'canvas' && $ctx) {
|
|
18
|
-
// console.count('render');
|
|
19
18
|
scaleCanvas($ctx, $width, $height);
|
|
20
19
|
$ctx.clearRect(0, 0, $width, $height);
|
|
20
|
+
// Transfer classes defined on <GeoPoint> to <canvas> to enable window.getComputedStyle() retrieval (Tailwind classes, etc)
|
|
21
|
+
if ($$props.class) {
|
|
22
|
+
$ctx.canvas.classList.add(...$$props.class.split(' '));
|
|
23
|
+
}
|
|
21
24
|
render($ctx, { x, y });
|
|
22
25
|
}
|
|
23
26
|
</script>
|
|
@@ -9,6 +9,8 @@ import Rect from './Rect.svelte';
|
|
|
9
9
|
import { tooltipContext } from './TooltipContext.svelte';
|
|
10
10
|
const { flatData, x, xDomain, xScale, xRange, xGet, y, yDomain, yScale, yRange, yGet, rGet, config, } = getContext('LayerCake');
|
|
11
11
|
const tooltip = tooltipContext();
|
|
12
|
+
/** Highlight specific data (annotate), espect uses tooltip data */
|
|
13
|
+
export let data = undefined;
|
|
12
14
|
export let axis = undefined;
|
|
13
15
|
/** Show points and pass props to Circles */
|
|
14
16
|
export let points = false;
|
|
@@ -27,10 +29,11 @@ let _area = {
|
|
|
27
29
|
width: 0,
|
|
28
30
|
height: 0,
|
|
29
31
|
};
|
|
30
|
-
$:
|
|
31
|
-
|
|
32
|
+
$: highlightData = data ?? $tooltip.data;
|
|
33
|
+
$: if (highlightData) {
|
|
34
|
+
let xCoord = $xGet(highlightData);
|
|
32
35
|
let xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
|
|
33
|
-
let yCoord = $yGet(
|
|
36
|
+
let yCoord = $yGet(highlightData);
|
|
34
37
|
let yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
|
|
35
38
|
// Reset lines
|
|
36
39
|
_lines = [];
|
|
@@ -73,7 +76,7 @@ $: if ($tooltip.data) {
|
|
|
73
76
|
}
|
|
74
77
|
else {
|
|
75
78
|
// Find width to next data point
|
|
76
|
-
const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(
|
|
79
|
+
const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(highlightData)));
|
|
77
80
|
const isLastPoint = index + 1 === $flatData.length;
|
|
78
81
|
const nextDataPoint = isLastPoint ? max($xDomain) : $x($flatData[index + 1]);
|
|
79
82
|
_area.width = ($xScale(nextDataPoint) ?? 0) - (xCoord ?? 0);
|
|
@@ -121,7 +124,7 @@ $: if ($tooltip.data) {
|
|
|
121
124
|
}
|
|
122
125
|
else {
|
|
123
126
|
// Find width to next data point
|
|
124
|
-
const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(
|
|
127
|
+
const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(highlightData)));
|
|
125
128
|
const isLastPoint = index + 1 === $flatData.length;
|
|
126
129
|
const nextDataPoint = isLastPoint ? max($yDomain) : $x($flatData[index + 1]);
|
|
127
130
|
_area.height = ($yScale(nextDataPoint) ?? 0) - (yCoord ?? 0);
|
|
@@ -139,12 +142,12 @@ $: if ($tooltip.data) {
|
|
|
139
142
|
// `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
|
|
140
143
|
_points = xCoord.filter(notNull).map((xItem, i) => ({
|
|
141
144
|
x: xItem + xOffset,
|
|
142
|
-
y: $yGet(
|
|
145
|
+
y: $yGet(highlightData) + yOffset,
|
|
143
146
|
}));
|
|
144
147
|
}
|
|
145
|
-
else if (Array.isArray(
|
|
148
|
+
else if (Array.isArray(highlightData)) {
|
|
146
149
|
// Stack series
|
|
147
|
-
_points =
|
|
150
|
+
_points = highlightData.map((yValue, i) => ({
|
|
148
151
|
x: xCoord + xOffset,
|
|
149
152
|
y: $yScale(yValue) + yOffset,
|
|
150
153
|
}));
|
|
@@ -153,14 +156,14 @@ $: if ($tooltip.data) {
|
|
|
153
156
|
_points = [
|
|
154
157
|
{
|
|
155
158
|
x: xCoord + xOffset,
|
|
156
|
-
y: $yGet(
|
|
159
|
+
y: $yGet(highlightData) + yOffset,
|
|
157
160
|
},
|
|
158
161
|
];
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
164
|
</script>
|
|
162
165
|
|
|
163
|
-
{#if
|
|
166
|
+
{#if highlightData}
|
|
164
167
|
{#if area}
|
|
165
168
|
<slot name="area" area={_area}>
|
|
166
169
|
<Rect
|
|
@@ -186,7 +189,7 @@ $: if ($tooltip.data) {
|
|
|
186
189
|
stroke={typeof bar === 'object' ? bar.stroke : null}
|
|
187
190
|
strokeWidth={typeof bar === 'object' ? bar.strokeWidth : null}
|
|
188
191
|
radius={typeof bar === 'object' ? bar.radius : null}
|
|
189
|
-
bar={
|
|
192
|
+
bar={highlightData}
|
|
190
193
|
class={cls(!bar.fill && 'fill-primary', typeof bar === 'object' ? bar.class : null)}
|
|
191
194
|
on:click
|
|
192
195
|
/>
|
|
@@ -216,7 +219,7 @@ $: if ($tooltip.data) {
|
|
|
216
219
|
<slot name="points" points={_points}>
|
|
217
220
|
{#each _points as point}
|
|
218
221
|
<!-- TODO: Improve color with stacked data -->
|
|
219
|
-
{@const fill = $config.r ? $rGet(
|
|
222
|
+
{@const fill = $config.r ? $rGet(highlightData) : null}
|
|
220
223
|
<Circle
|
|
221
224
|
spring
|
|
222
225
|
cx={point.x}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
|
+
/** Highlight specific data (annotate), espect uses tooltip data */ data?: any;
|
|
4
5
|
axis?: 'x' | 'y' | 'both' | 'none' | undefined;
|
|
5
6
|
/** Show points and pass props to Circles */ points?: boolean | Partial<{
|
|
6
7
|
[x: string]: any;
|