layerchart 0.35.0 → 0.36.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.
|
@@ -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>
|