@rokkit/chart 1.0.0-next.62 → 1.0.0-next.64
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/package.json +7 -7
- package/src/chart/AxisGrid.svelte +2 -14
- package/src/chart/FacetGrid.svelte +1 -3
- package/src/chart/Swatch.svelte +3 -11
- package/src/chart/SwatchGrid.svelte +0 -1
- package/src/chart/TexturedShape.svelte +2 -9
- package/src/chart/TimelapseChart.svelte +2 -8
- package/src/elements/Bar.svelte +1 -7
- package/src/elements/ColorRamp.svelte +1 -3
- package/src/elements/ContinuousLegend.svelte +1 -3
- package/src/elements/DiscreteLegend.svelte +2 -4
- package/src/elements/Tooltip.svelte +1 -5
- package/src/lib/chart.js +2 -2
- package/src/plots/BarPlot.svelte +1 -5
- package/src/plots/FunnelPlot.svelte +1 -7
- package/src/plots/HeatMapCalendar.svelte +3 -11
- package/src/plots/LinePlot.svelte +1 -4
- package/src/plots/ScatterPlot.svelte +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/chart",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.64",
|
|
4
4
|
"description": "Components for making interactive charts.",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"typescript": "^5.3.3",
|
|
23
23
|
"vite": "^5.0.11",
|
|
24
24
|
"vitest": "~1.1.3",
|
|
25
|
-
"shared-config": "1.0.0-next.
|
|
25
|
+
"shared-config": "1.0.0-next.64"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"d3-array": "^3.2.4",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"d3-interpolate": "^3.0.1",
|
|
32
32
|
"d3-scale": "^4.0.2",
|
|
33
33
|
"d3-shape": "^3.2.0",
|
|
34
|
-
"date-fns": "^3.
|
|
34
|
+
"date-fns": "^3.2.0",
|
|
35
35
|
"ramda": "^0.29.1",
|
|
36
36
|
"yootils": "^0.3.1",
|
|
37
|
-
"@rokkit/atoms": "1.0.0-next.
|
|
38
|
-
"@rokkit/core": "1.0.0-next.
|
|
39
|
-
"@rokkit/molecules": "1.0.0-next.
|
|
40
|
-
"@rokkit/stores": "1.0.0-next.
|
|
37
|
+
"@rokkit/atoms": "1.0.0-next.64",
|
|
38
|
+
"@rokkit/core": "1.0.0-next.64",
|
|
39
|
+
"@rokkit/molecules": "1.0.0-next.64",
|
|
40
|
+
"@rokkit/stores": "1.0.0-next.64"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"src/**/*.js",
|
|
@@ -14,21 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
<g class="grid">
|
|
16
16
|
{#each $chart.axis.x.ticks as tick}
|
|
17
|
-
<line
|
|
18
|
-
x1={tick.position}
|
|
19
|
-
x2={tick.position}
|
|
20
|
-
y1={yRange[0]}
|
|
21
|
-
y2={yRange[1]}
|
|
22
|
-
opacity={opacityV}
|
|
23
|
-
/>
|
|
17
|
+
<line x1={tick.position} x2={tick.position} y1={yRange[0]} y2={yRange[1]} opacity={opacityV} />
|
|
24
18
|
{/each}
|
|
25
19
|
{#each $chart.axis.y.ticks as tick}
|
|
26
|
-
<line
|
|
27
|
-
y1={tick.position}
|
|
28
|
-
y2={tick.position}
|
|
29
|
-
x1={xRange[0]}
|
|
30
|
-
x2={xRange[1]}
|
|
31
|
-
opacity={opacityH}
|
|
32
|
-
/>
|
|
20
|
+
<line y1={tick.position} y2={tick.position} x1={xRange[0]} x2={xRange[1]} opacity={opacityH} />
|
|
33
21
|
{/each}
|
|
34
22
|
</g>
|
|
@@ -23,9 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
<div class="flex flex-row">
|
|
25
25
|
{#each colValues as colItem}
|
|
26
|
-
{@const dataFilteredByCol = dataFilteredByRow.filter(
|
|
27
|
-
(d) => d[col] === colItem
|
|
28
|
-
)}
|
|
26
|
+
{@const dataFilteredByCol = dataFilteredByRow.filter((d) => d[col] === colItem)}
|
|
29
27
|
|
|
30
28
|
<Chart data={dataFilteredByCol} {x} {y}>
|
|
31
29
|
<Axis name="x" count={7} gap={10}>
|
package/src/chart/Swatch.svelte
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { swatch } from '../lib/utils'
|
|
5
5
|
import { clamp } from 'yootils'
|
|
6
|
-
import {Symbol, DefinePatterns} from '@rokkit/molecules'
|
|
6
|
+
import { Symbol, DefinePatterns } from '@rokkit/molecules'
|
|
7
7
|
|
|
8
8
|
const dispatch = createEventDispatcher()
|
|
9
9
|
|
|
@@ -29,11 +29,7 @@
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function swapType(inputType) {
|
|
32
|
-
return inputType === 'square'
|
|
33
|
-
? 'circle'
|
|
34
|
-
: inputType === 'circle'
|
|
35
|
-
? 'square'
|
|
36
|
-
: type
|
|
32
|
+
return inputType === 'square' ? 'circle' : inputType === 'circle' ? 'square' : type
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
function click(index) {
|
|
@@ -63,11 +59,7 @@
|
|
|
63
59
|
{#if label}
|
|
64
60
|
<span class="py-2">{label}</span>
|
|
65
61
|
{/if}
|
|
66
|
-
<svg
|
|
67
|
-
viewBox="0 0 {grid.width} {grid.height}"
|
|
68
|
-
width="100%"
|
|
69
|
-
class="cursor-pointer"
|
|
70
|
-
>
|
|
62
|
+
<svg viewBox="0 0 {grid.width} {grid.height}" width="100%" class="cursor-pointer">
|
|
71
63
|
{#if label}
|
|
72
64
|
<title>A swatch with label {label}</title>
|
|
73
65
|
{/if}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {Symbol} from '@rokkit/molecules'
|
|
2
|
+
import { Symbol } from '@rokkit/molecules'
|
|
3
3
|
import Texture from './Texture.svelte'
|
|
4
4
|
|
|
5
5
|
export let pattern
|
|
@@ -11,14 +11,7 @@
|
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
13
|
<svg viewBox="0 0 {size} {size}">
|
|
14
|
-
<Symbol
|
|
15
|
-
x={size / 2}
|
|
16
|
-
y={size / 2}
|
|
17
|
-
{size}
|
|
18
|
-
fill={pattern.fillUrl || fill}
|
|
19
|
-
{stroke}
|
|
20
|
-
{shape}
|
|
21
|
-
/>
|
|
14
|
+
<Symbol x={size / 2} y={size / 2} {size} fill={pattern.fillUrl || fill} {stroke} {shape} />
|
|
22
15
|
{#if pattern}
|
|
23
16
|
<defs>
|
|
24
17
|
<Texture {...pattern} />
|
|
@@ -40,9 +40,7 @@
|
|
|
40
40
|
const values = uniques(data, attr)
|
|
41
41
|
const groups = slidingWindow(values, size, step, offset).map((x) => ({
|
|
42
42
|
...x,
|
|
43
|
-
data: data.filter(
|
|
44
|
-
(y) => y.Petal_Length >= x.lowerBound && y.Petal_Length < x.upperBound
|
|
45
|
-
)
|
|
43
|
+
data: data.filter((y) => y.Petal_Length >= x.lowerBound && y.Petal_Length < x.upperBound)
|
|
46
44
|
}))
|
|
47
45
|
|
|
48
46
|
return groups
|
|
@@ -60,10 +58,7 @@
|
|
|
60
58
|
function switchChart(index) {
|
|
61
59
|
let chart = {}
|
|
62
60
|
if (index != null) {
|
|
63
|
-
chart = brewer()
|
|
64
|
-
.chart(phased.data[index].data, x, y)
|
|
65
|
-
.use(theme)
|
|
66
|
-
.computeAxis()
|
|
61
|
+
chart = brewer().chart(phased.data[index].data, x, y).use(theme).computeAxis()
|
|
67
62
|
chart.axis = axis
|
|
68
63
|
// chart.margin = { left: 40, right: 10, top: 10, bottom: 30 }
|
|
69
64
|
}
|
|
@@ -74,7 +69,6 @@
|
|
|
74
69
|
$: phased = timed(data, x, y, time)
|
|
75
70
|
$: $chart = switchChart(current)
|
|
76
71
|
|
|
77
|
-
|
|
78
72
|
// setup chart attributes that do not change over time
|
|
79
73
|
// get scales for x & y
|
|
80
74
|
// set margins
|
package/src/elements/Bar.svelte
CHANGED
|
@@ -26,10 +26,4 @@
|
|
|
26
26
|
<rect x={$scales.x(0)} {y} {width} {height} {fill} opacity={0.5} />
|
|
27
27
|
<rect x={$scales.x(0)} {y} width={5} {height} {fill} />
|
|
28
28
|
<Label x={width} y={y + textHeight + 8} anchor={textAnchor} label={name} />
|
|
29
|
-
<Label
|
|
30
|
-
x={width}
|
|
31
|
-
y={y + height - 14}
|
|
32
|
-
anchor={textAnchor}
|
|
33
|
-
label={formattedValue}
|
|
34
|
-
small
|
|
35
|
-
/>
|
|
29
|
+
<Label x={width} y={y + height - 14} anchor={textAnchor} label={formattedValue} small />
|
|
@@ -14,9 +14,7 @@
|
|
|
14
14
|
.range([x, x + width])
|
|
15
15
|
.domain(scale.domain())
|
|
16
16
|
$: scalePercent = scaleLinear().range([0, 100]).domain(scale.domain())
|
|
17
|
-
$: ticks = scale.ticks
|
|
18
|
-
.apply(scale, [tickCount])
|
|
19
|
-
.map((d) => ({ x: scaleTicks(d), value: d }))
|
|
17
|
+
$: ticks = scale.ticks.apply(scale, [tickCount]).map((d) => ({ x: scaleTicks(d), value: d }))
|
|
20
18
|
|
|
21
19
|
$: colors = ticks.map(({ value }) => ({
|
|
22
20
|
color: scale(value),
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
$: scaleTicks = scaleLinear()
|
|
14
14
|
.range([x, x + 100])
|
|
15
15
|
.domain(scale.domain())
|
|
16
|
-
$: ticks = scale.ticks
|
|
17
|
-
.apply(scale, [tickCount])
|
|
18
|
-
.map((d) => ({ x: scaleTicks(d), label: d }))
|
|
16
|
+
$: ticks = scale.ticks.apply(scale, [tickCount]).map((d) => ({ x: scaleTicks(d), label: d }))
|
|
19
17
|
|
|
20
18
|
$: colors = scale.range()
|
|
21
19
|
$: id = uniqueId('legend-')
|
|
@@ -13,10 +13,8 @@
|
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
15
|
{#each ticks as tick, i}
|
|
16
|
-
<text
|
|
17
|
-
|
|
18
|
-
y={y + size / 2}
|
|
19
|
-
font-size={textSize}>{tick}</text
|
|
16
|
+
<text x={x + padding + i * sizeWithSpace + size / 2} y={y + size / 2} font-size={textSize}
|
|
17
|
+
>{tick}</text
|
|
20
18
|
>
|
|
21
19
|
<rect
|
|
22
20
|
x={x + padding + i * sizeWithSpace}
|
package/src/lib/chart.js
CHANGED
|
@@ -181,8 +181,8 @@ function tickValues(scale, whichAxis, params) {
|
|
|
181
181
|
Array.isArray(values) && values.length > 2
|
|
182
182
|
? values
|
|
183
183
|
: scale.ticks
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
? scale.ticks.apply(scale, [count])
|
|
185
|
+
: scale.domain()
|
|
186
186
|
const ticks = values.map((label) => ({ label, position: scale(label) }))
|
|
187
187
|
|
|
188
188
|
return ticks
|
package/src/plots/BarPlot.svelte
CHANGED
|
@@ -15,9 +15,7 @@
|
|
|
15
15
|
x: $chart.flipCoords ? $chart.scale.x(0) : $chart.scale.x(d.x),
|
|
16
16
|
y: $chart.flipCoords ? $chart.scale.y(d.y) : $chart.scale.y(d.y),
|
|
17
17
|
y0: $chart.scale.y(0),
|
|
18
|
-
width: $chart.flipCoords
|
|
19
|
-
? $chart.scale.x(d.x) - $chart.scale.x(0)
|
|
20
|
-
: $chart.scale.x.bandwidth(),
|
|
18
|
+
width: $chart.flipCoords ? $chart.scale.x(d.x) - $chart.scale.x(0) : $chart.scale.x.bandwidth(),
|
|
21
19
|
height: $chart.flipCoords
|
|
22
20
|
? $chart.scale.y.bandwidth()
|
|
23
21
|
: $chart.scale.y(0) - $chart.scale.y(d.y),
|
|
@@ -31,8 +29,6 @@
|
|
|
31
29
|
text: $chart.flipCoords ? d.y + ' (' + d.x + ')' : d.x + ' (' + d.y + ')'
|
|
32
30
|
}
|
|
33
31
|
}))
|
|
34
|
-
|
|
35
|
-
|
|
36
32
|
</script>
|
|
37
33
|
|
|
38
34
|
{#each data as { x, y, width, height, fill, label }}
|
|
@@ -20,13 +20,7 @@
|
|
|
20
20
|
{/each}
|
|
21
21
|
{#each data.labels as label, index}
|
|
22
22
|
{#if index < data.labels.length - 1}
|
|
23
|
-
<line
|
|
24
|
-
x1={label.x1}
|
|
25
|
-
x2={label.x2}
|
|
26
|
-
y1={label.y1}
|
|
27
|
-
y2={label.y2}
|
|
28
|
-
stroke="currentColor"
|
|
29
|
-
/>
|
|
23
|
+
<line x1={label.x1} x2={label.x2} y1={label.y1} y2={label.y2} stroke="currentColor" />
|
|
30
24
|
{/if}
|
|
31
25
|
<text x={label.x} y={label.y} fill="currentColor">{label.label}</text>
|
|
32
26
|
{/each}
|
|
@@ -31,17 +31,13 @@
|
|
|
31
31
|
function hideToolTip() {
|
|
32
32
|
tooltip = null
|
|
33
33
|
}
|
|
34
|
-
$: scale = scaleLinear()
|
|
35
|
-
.domain([0, maximum])
|
|
36
|
-
.range(colors)
|
|
37
|
-
.interpolate(interpolateHsl)
|
|
34
|
+
$: scale = scaleLinear().domain([0, maximum]).range(colors).interpolate(interpolateHsl)
|
|
38
35
|
|
|
39
36
|
$: legendHeight = 2 * size + space * 3
|
|
40
37
|
$: sizeWithSpace = size + space
|
|
41
38
|
$: summary = summarize(data, dateField, valueField)
|
|
42
39
|
$: datamap = heatmap(summary, months)
|
|
43
|
-
$: width =
|
|
44
|
-
datamap.numberOfWeeks * sizeWithSpace + dayLabelWidth + 2 * padding - space
|
|
40
|
+
$: width = datamap.numberOfWeeks * sizeWithSpace + dayLabelWidth + 2 * padding - space
|
|
45
41
|
$: height = 7 * sizeWithSpace + labelHeight + 2 * padding + legendHeight
|
|
46
42
|
</script>
|
|
47
43
|
|
|
@@ -76,11 +72,7 @@
|
|
|
76
72
|
{#each datamap.weekdays as name, i}
|
|
77
73
|
<text
|
|
78
74
|
x={padding + dayLabelWidth - 2 * space}
|
|
79
|
-
y={padding +
|
|
80
|
-
legendHeight +
|
|
81
|
-
i * sizeWithSpace +
|
|
82
|
-
labelHeight +
|
|
83
|
-
(size - labelHeight) / 2}
|
|
75
|
+
y={padding + legendHeight + i * sizeWithSpace + labelHeight + (size - labelHeight) / 2}
|
|
84
76
|
text-anchor="end"
|
|
85
77
|
font-size={labelHeight}>{name}</text
|
|
86
78
|
>
|
|
@@ -15,9 +15,7 @@
|
|
|
15
15
|
x: $chart.flipCoords ? $chart.scale.x(0) : $chart.scale.x(d.x),
|
|
16
16
|
y: $chart.flipCoords ? $chart.scale.y(d.y) : $chart.scale.y(d.y),
|
|
17
17
|
y0: $chart.scale.y(0),
|
|
18
|
-
width: $chart.flipCoords
|
|
19
|
-
? $chart.scale.x(d.x) - $chart.scale.x(0)
|
|
20
|
-
: $chart.scale.x.bandwidth(),
|
|
18
|
+
width: $chart.flipCoords ? $chart.scale.x(d.x) - $chart.scale.x(0) : $chart.scale.x.bandwidth(),
|
|
21
19
|
height: $chart.flipCoords
|
|
22
20
|
? $chart.scale.y.bandwidth()
|
|
23
21
|
: $chart.scale.y(0) - $chart.scale.y(d.y),
|
|
@@ -31,7 +29,6 @@
|
|
|
31
29
|
text: $chart.flipCoords ? d.y + ' (' + d.x + ')' : d.x + ' (' + d.y + ')'
|
|
32
30
|
}
|
|
33
31
|
}))
|
|
34
|
-
|
|
35
32
|
</script>
|
|
36
33
|
|
|
37
34
|
{#each data as { x1, y1, x2, y2, color, label }}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { clamp } from 'yootils'
|
|
3
|
-
import {Symbol} from '@rokkit/molecules'
|
|
3
|
+
import { Symbol } from '@rokkit/molecules'
|
|
4
4
|
import { getContext } from 'svelte'
|
|
5
5
|
|
|
6
6
|
const chart = getContext('chart')
|
|
@@ -18,9 +18,7 @@
|
|
|
18
18
|
{#if $chart.data}
|
|
19
19
|
{#each $chart.data as d}
|
|
20
20
|
<Symbol
|
|
21
|
-
x={$chart.axis.x.scale(d[$chart.x]) -
|
|
22
|
-
offset +
|
|
23
|
-
Math.random() * jitterWidth}
|
|
21
|
+
x={$chart.axis.x.scale(d[$chart.x]) - offset + Math.random() * jitterWidth}
|
|
24
22
|
y={$chart.axis.y.scale(d[$chart.y])}
|
|
25
23
|
{fill}
|
|
26
24
|
{stroke}
|