layerchart 0.2.0 → 0.2.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.
package/components/AxisX.svelte
CHANGED
|
@@ -6,17 +6,24 @@
|
|
|
6
6
|
import { getContext } from 'svelte';
|
|
7
7
|
import { extent } from 'd3-array';
|
|
8
8
|
import Line from './Line.svelte';
|
|
9
|
+
import { isScaleBand } from '../utils/scales';
|
|
9
10
|
const context = getContext('LayerCake');
|
|
10
|
-
const { data, xGet, yGet, config } = context;
|
|
11
|
-
export let offsetX =
|
|
12
|
-
export let offsetY =
|
|
13
|
-
function getOffset(value, offset) {
|
|
11
|
+
const { data, xGet, yGet, xScale, yScale, config } = context;
|
|
12
|
+
export let offsetX = undefined;
|
|
13
|
+
export let offsetY = undefined;
|
|
14
|
+
function getOffset(value, offset, scale) {
|
|
14
15
|
if (typeof offset === 'function') {
|
|
15
16
|
return offset(value, context);
|
|
16
17
|
}
|
|
17
|
-
else {
|
|
18
|
+
else if (offset != null) {
|
|
18
19
|
return offset;
|
|
19
20
|
}
|
|
21
|
+
else if (isScaleBand(scale)) {
|
|
22
|
+
return scale.bandwidth() / 2;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
20
27
|
}
|
|
21
28
|
$: points = $data.flatMap((d) => {
|
|
22
29
|
if (Array.isArray($config.x)) {
|
|
@@ -26,10 +33,10 @@ $: points = $data.flatMap((d) => {
|
|
|
26
33
|
*/
|
|
27
34
|
const [xMin, xMax] = extent($xGet(d));
|
|
28
35
|
return {
|
|
29
|
-
x1: xMin + getOffset(xMin, offsetX),
|
|
30
|
-
y1: $yGet(d) + getOffset($yGet(d), offsetY),
|
|
31
|
-
x2: xMax + getOffset(xMax, offsetX),
|
|
32
|
-
y2: $yGet(d) + getOffset($yGet(d), offsetY)
|
|
36
|
+
x1: xMin + getOffset(xMin, offsetX, $xScale),
|
|
37
|
+
y1: $yGet(d) + getOffset($yGet(d), offsetY, $yScale),
|
|
38
|
+
x2: xMax + getOffset(xMax, offsetX, $xScale),
|
|
39
|
+
y2: $yGet(d) + getOffset($yGet(d), offsetY, $yScale)
|
|
33
40
|
};
|
|
34
41
|
}
|
|
35
42
|
else if (Array.isArray($config.y)) {
|
|
@@ -39,10 +46,10 @@ $: points = $data.flatMap((d) => {
|
|
|
39
46
|
*/
|
|
40
47
|
const [yMin, yMax] = extent($yGet(d));
|
|
41
48
|
return {
|
|
42
|
-
x1: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
43
|
-
y1: yMin + getOffset(yMin, offsetY),
|
|
44
|
-
x2: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
45
|
-
y2: yMax + getOffset(yMax, offsetY)
|
|
49
|
+
x1: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
50
|
+
y1: yMin + getOffset(yMin, offsetY, $yScale),
|
|
51
|
+
x2: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
52
|
+
y2: yMax + getOffset(yMax, offsetY, $yScale)
|
|
46
53
|
};
|
|
47
54
|
}
|
|
48
55
|
else {
|
|
@@ -52,10 +59,10 @@ $: points = $data.flatMap((d) => {
|
|
|
52
59
|
*/
|
|
53
60
|
// Not really supported (nothing to connect...)
|
|
54
61
|
return {
|
|
55
|
-
x1: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
56
|
-
y1: $yGet(d) + getOffset($yGet(d), offsetY),
|
|
57
|
-
x2: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
58
|
-
y2: $yGet(d) + getOffset($yGet(d), offsetY)
|
|
62
|
+
x1: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
63
|
+
y1: $yGet(d) + getOffset($yGet(d), offsetY, $yScale),
|
|
64
|
+
x2: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
65
|
+
y2: $yGet(d) + getOffset($yGet(d), offsetY, $yScale)
|
|
59
66
|
};
|
|
60
67
|
}
|
|
61
68
|
});
|
package/components/Points.svelte
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
<script >import { getContext } from 'svelte';
|
|
2
2
|
import Circle from './Circle.svelte';
|
|
3
|
+
import { isScaleBand } from '../utils/scales';
|
|
3
4
|
const context = getContext('LayerCake');
|
|
4
|
-
const { data, xGet, yGet, config } = context;
|
|
5
|
+
const { data, xGet, yGet, xScale, yScale, config } = context;
|
|
5
6
|
export let r = 5;
|
|
6
|
-
export let offsetX =
|
|
7
|
-
export let offsetY =
|
|
8
|
-
function getOffset(value, offset) {
|
|
7
|
+
export let offsetX = undefined;
|
|
8
|
+
export let offsetY = undefined;
|
|
9
|
+
function getOffset(value, offset, scale) {
|
|
9
10
|
if (typeof offset === 'function') {
|
|
10
11
|
return offset(value, context);
|
|
11
12
|
}
|
|
12
|
-
else {
|
|
13
|
+
else if (offset != null) {
|
|
13
14
|
return offset;
|
|
14
15
|
}
|
|
16
|
+
else if (isScaleBand(scale)) {
|
|
17
|
+
return scale.bandwidth() / 2;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
15
22
|
}
|
|
16
23
|
$: points = $data.flatMap((d) => {
|
|
17
24
|
if (Array.isArray($config.x)) {
|
|
@@ -21,8 +28,8 @@ $: points = $data.flatMap((d) => {
|
|
|
21
28
|
*/
|
|
22
29
|
return $xGet(d).map((x) => {
|
|
23
30
|
return {
|
|
24
|
-
x: x + getOffset(x, offsetX),
|
|
25
|
-
y: $yGet(d) + getOffset($yGet(d), offsetY)
|
|
31
|
+
x: x + getOffset(x, offsetX, $xScale),
|
|
32
|
+
y: $yGet(d) + getOffset($yGet(d), offsetY, $yScale)
|
|
26
33
|
};
|
|
27
34
|
});
|
|
28
35
|
}
|
|
@@ -33,8 +40,8 @@ $: points = $data.flatMap((d) => {
|
|
|
33
40
|
*/
|
|
34
41
|
return $yGet(d).map((y) => {
|
|
35
42
|
return {
|
|
36
|
-
x: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
37
|
-
y: y + getOffset(y, offsetY)
|
|
43
|
+
x: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
44
|
+
y: y + getOffset(y, offsetY, $yScale)
|
|
38
45
|
};
|
|
39
46
|
});
|
|
40
47
|
}
|
|
@@ -44,8 +51,8 @@ $: points = $data.flatMap((d) => {
|
|
|
44
51
|
y="prop2"
|
|
45
52
|
*/
|
|
46
53
|
return {
|
|
47
|
-
x: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
48
|
-
y: $yGet(d) + getOffset($yGet(d), offsetY)
|
|
54
|
+
x: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
55
|
+
y: $yGet(d) + getOffset($yGet(d), offsetY, $yScale)
|
|
49
56
|
};
|
|
50
57
|
}
|
|
51
58
|
});
|
package/components/Text.svelte
CHANGED
|
@@ -119,7 +119,9 @@ function isValidXOrY(xOrY) {
|
|
|
119
119
|
}
|
|
120
120
|
</script>
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
<!-- overflow: visible; allow contents to be shown outside element -->
|
|
123
|
+
<!-- paint-order: stroke; support stroke outlining text -->
|
|
124
|
+
<svg x={dx} y={dy} style="overflow: visible; paint-order: stroke;">
|
|
123
125
|
{#if isValidXOrY(x) && isValidXOrY(y)}
|
|
124
126
|
<text {x} {y} {transform} text-anchor={textAnchor} {...$$restProps}>
|
|
125
127
|
{#each wordsByLines as line, index}
|
package/package.json
CHANGED