@rokkit/chart 1.0.0-next.87 → 1.0.0-next.88
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 +11 -6
- package/src/Chart.svelte +67 -0
- package/src/PatternDefs.svelte +14 -0
- package/src/Symbol.svelte +17 -0
- package/src/{chart/Texture.svelte → Texture.svelte} +3 -3
- package/src/elements/Bar.svelte +2 -2
- package/src/elements/ContinuousLegend.svelte +3 -2
- package/src/elements/DefinePatterns.svelte +22 -0
- package/src/elements/DiscreteLegend.svelte +1 -1
- package/src/elements/Label.svelte +7 -5
- package/src/elements/SymbolGrid.svelte +23 -0
- package/src/elements/index.js +6 -0
- package/src/index.js +5 -15
- package/src/lib/brewer.js +17 -0
- package/src/lib/chart.js +179 -160
- package/src/lib/grid.js +68 -0
- package/src/lib/index.js +4 -0
- package/src/lib/palette.js +279 -28
- package/src/lib/plots.js +23 -0
- package/src/lib/swatch.js +24 -8
- package/src/lib/ticks.js +19 -0
- package/src/patterns/Brick.svelte +17 -0
- package/src/patterns/Circles.svelte +18 -0
- package/src/patterns/CrossHatch.svelte +14 -0
- package/src/patterns/CurvedWave.svelte +9 -0
- package/src/patterns/Dots.svelte +19 -0
- package/src/patterns/OutlineCircles.svelte +15 -0
- package/src/patterns/Texture.svelte +20 -0
- package/src/patterns/Tile.svelte +17 -0
- package/src/patterns/Triangles.svelte +15 -0
- package/src/patterns/Waves.svelte +13 -0
- package/src/patterns/constants.js +43 -0
- package/src/patterns/index.js +13 -0
- package/src/patterns/paths/NamedPattern.svelte +12 -0
- package/src/patterns/paths/constants.js +7 -0
- package/src/patterns/templates/Circles.svelte +18 -0
- package/src/patterns/templates/Lines.svelte +17 -0
- package/src/patterns/templates/Path.svelte +17 -0
- package/src/patterns/templates/index.js +3 -0
- package/src/plots/Plot.svelte +36 -21
- package/src/plots/index.js +1 -10
- package/src/symbols/Circle.svelte +22 -0
- package/src/symbols/Shape.svelte +31 -0
- package/src/symbols/Square.svelte +27 -0
- package/src/symbols/Triangle.svelte +24 -0
- package/src/symbols/constants/index.js +7 -0
- package/src/symbols/index.js +13 -0
- package/src/chart/Axis.svelte +0 -81
- package/src/chart/AxisGrid.svelte +0 -22
- package/src/chart/Chart.svelte +0 -40
- package/src/chart/FacetGrid.svelte +0 -49
- package/src/chart/Legend.svelte +0 -16
- package/src/chart/Swatch.svelte +0 -84
- package/src/chart/SwatchButton.svelte +0 -29
- package/src/chart/SwatchGrid.svelte +0 -53
- package/src/chart/TexturedShape.svelte +0 -20
- package/src/chart/TimelapseChart.svelte +0 -90
- package/src/chart/Timer.svelte +0 -27
- package/src/elements/Tooltip.svelte +0 -19
- package/src/lib/axis.js +0 -77
- package/src/lib/color.js +0 -55
- package/src/lib/constants.js +0 -41
- package/src/lib/funnel.js +0 -230
- package/src/lib/geom.js +0 -99
- package/src/lib/heatmap.js +0 -68
- package/src/lib/lookup.js +0 -29
- package/src/lib/pattern.js +0 -182
- package/src/lib/rollup.js +0 -49
- package/src/lib/shape.js +0 -46
- package/src/lib/store.js +0 -63
- package/src/lib/summary.js +0 -28
- package/src/lib/theme.js +0 -31
- package/src/lib/utils.js +0 -158
- package/src/plots/BarPlot.svelte +0 -51
- package/src/plots/BarPlot2.svelte +0 -34
- package/src/plots/BoxPlot.svelte +0 -54
- package/src/plots/FunnelPlot.svelte +0 -26
- package/src/plots/HeatMapCalendar.svelte +0 -121
- package/src/plots/LinePlot.svelte +0 -51
- package/src/plots/RankBarPlot.svelte +0 -38
- package/src/plots/ScatterPlot.svelte +0 -28
- package/src/plots/ViolinPlot.svelte +0 -10
package/src/plots/BoxPlot.svelte
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
|
|
4
|
-
let chart = getContext('chart')
|
|
5
|
-
|
|
6
|
-
export let whisker = true
|
|
7
|
-
export let boxWidth = 150
|
|
8
|
-
export let stroke = 'green'
|
|
9
|
-
export let fill = '#69b3a2' // fixed color or attribute to be used for color
|
|
10
|
-
export let scaleFill = () => fill // defaults to fill color
|
|
11
|
-
|
|
12
|
-
$: data = $chart.summary()
|
|
13
|
-
</script>
|
|
14
|
-
|
|
15
|
-
{#each data as { key, value }}
|
|
16
|
-
<rect
|
|
17
|
-
width={boxWidth}
|
|
18
|
-
height={$chart.axis.y.scale(value.q1) - $chart.axis.y.scale(value.q3)}
|
|
19
|
-
x={$chart.axis.x.scale(key) - boxWidth / 2}
|
|
20
|
-
y={$chart.axis.y.scale(value.q3)}
|
|
21
|
-
fill={scaleFill(value[fill])}
|
|
22
|
-
{stroke}
|
|
23
|
-
/>
|
|
24
|
-
<line
|
|
25
|
-
x1={$chart.axis.x.scale(key) - boxWidth / 2}
|
|
26
|
-
x2={$chart.axis.x.scale(key) + boxWidth / 2}
|
|
27
|
-
y1={$chart.axis.y.scale(value.median)}
|
|
28
|
-
y2={$chart.axis.y.scale(value.median)}
|
|
29
|
-
{stroke}
|
|
30
|
-
/>
|
|
31
|
-
<line
|
|
32
|
-
x1={$chart.axis.x.scale(key)}
|
|
33
|
-
x2={$chart.axis.x.scale(key)}
|
|
34
|
-
y1={$chart.axis.y.scale(value.min)}
|
|
35
|
-
y2={$chart.axis.y.scale(value.max)}
|
|
36
|
-
{stroke}
|
|
37
|
-
/>
|
|
38
|
-
{#if whisker}
|
|
39
|
-
<line
|
|
40
|
-
x1={$chart.axis.x.scale(key) - boxWidth / 8}
|
|
41
|
-
x2={$chart.axis.x.scale(key) + boxWidth / 8}
|
|
42
|
-
y1={$chart.axis.y.scale(value.min)}
|
|
43
|
-
y2={$chart.axis.y.scale(value.min)}
|
|
44
|
-
{stroke}
|
|
45
|
-
/>
|
|
46
|
-
<line
|
|
47
|
-
x1={$chart.axis.x.scale(key) - boxWidth / 8}
|
|
48
|
-
x2={$chart.axis.x.scale(key) + boxWidth / 8}
|
|
49
|
-
y1={$chart.axis.y.scale(value.max)}
|
|
50
|
-
y2={$chart.axis.y.scale(value.max)}
|
|
51
|
-
{stroke}
|
|
52
|
-
/>
|
|
53
|
-
{/if}
|
|
54
|
-
{/each}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import { compact } from '@rokkit/core'
|
|
4
|
-
import { funnel } from '../lib/funnel'
|
|
5
|
-
|
|
6
|
-
const chart = getContext('chart')
|
|
7
|
-
|
|
8
|
-
export let x
|
|
9
|
-
export let y
|
|
10
|
-
export let fill
|
|
11
|
-
export let curve = 'bump'
|
|
12
|
-
export let stat = 'count'
|
|
13
|
-
|
|
14
|
-
$: aes = { ...$chart.aes, ...compact({ x, y, fill, stat, curve }) }
|
|
15
|
-
$: data = funnel($chart.data, aes, $chart.width, $chart.height)
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
{#each data.stats as stat, i}
|
|
19
|
-
<path d={data.path(stat.value)} fill={$chart.theme.colors[i]} />
|
|
20
|
-
{/each}
|
|
21
|
-
{#each data.labels as label, index}
|
|
22
|
-
{#if index < data.labels.length - 1}
|
|
23
|
-
<line x1={label.x1} x2={label.x2} y1={label.y1} y2={label.y2} stroke="currentColor" />
|
|
24
|
-
{/if}
|
|
25
|
-
<text x={label.x} y={label.y} fill="currentColor">{label.label}</text>
|
|
26
|
-
{/each}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { summarize, heatmap } from '../lib/heatmap'
|
|
3
|
-
import { interpolateHsl } from 'd3-interpolate'
|
|
4
|
-
import { scaleLinear } from 'd3-scale'
|
|
5
|
-
// import ContinuousLegend from '../elements/ContinuousLegend.svelte'
|
|
6
|
-
import DiscreteLegend from '../elements/DiscreteLegend.svelte'
|
|
7
|
-
import ColorRamp from '../elements/ColorRamp.svelte'
|
|
8
|
-
|
|
9
|
-
const dayLabelWidth = 20
|
|
10
|
-
const labelHeight = 6
|
|
11
|
-
|
|
12
|
-
export let data
|
|
13
|
-
export let dateField = 'date'
|
|
14
|
-
export let valueField = null
|
|
15
|
-
export let months = 12
|
|
16
|
-
export let colors = ['transparent', '#FB8C00']
|
|
17
|
-
export let padding = 8
|
|
18
|
-
export let space = 2
|
|
19
|
-
export let size = 10
|
|
20
|
-
export let maximum = 10
|
|
21
|
-
export let tickCount = 5
|
|
22
|
-
export let discreteLegend = false
|
|
23
|
-
|
|
24
|
-
export let tooltipText = (d) => `${d.date} => ${d.value}`
|
|
25
|
-
|
|
26
|
-
let tooltip = null
|
|
27
|
-
|
|
28
|
-
function showToolTip(event, d) {
|
|
29
|
-
tooltip = d
|
|
30
|
-
}
|
|
31
|
-
function hideToolTip() {
|
|
32
|
-
tooltip = null
|
|
33
|
-
}
|
|
34
|
-
$: scale = scaleLinear().domain([0, maximum]).range(colors).interpolate(interpolateHsl)
|
|
35
|
-
|
|
36
|
-
$: legendHeight = 2 * size + space * 3
|
|
37
|
-
$: sizeWithSpace = size + space
|
|
38
|
-
$: summary = summarize(data, dateField, valueField)
|
|
39
|
-
$: datamap = heatmap(summary, months)
|
|
40
|
-
$: width = datamap.numberOfWeeks * sizeWithSpace + dayLabelWidth + 2 * padding - space
|
|
41
|
-
$: height = 7 * sizeWithSpace + labelHeight + 2 * padding + legendHeight
|
|
42
|
-
</script>
|
|
43
|
-
|
|
44
|
-
<div>
|
|
45
|
-
<svg class="chart" viewBox="0 0 {width} {height}">
|
|
46
|
-
{#if tooltip}
|
|
47
|
-
<text
|
|
48
|
-
x={padding + dayLabelWidth}
|
|
49
|
-
y={padding + legendHeight - labelHeight}
|
|
50
|
-
text-anchor="start"
|
|
51
|
-
font-size={labelHeight}
|
|
52
|
-
>
|
|
53
|
-
{tooltipText(tooltip)}
|
|
54
|
-
</text>
|
|
55
|
-
{/if}
|
|
56
|
-
{#if discreteLegend}
|
|
57
|
-
<DiscreteLegend
|
|
58
|
-
{scale}
|
|
59
|
-
x={width - (tickCount + 1) * sizeWithSpace - padding - space}
|
|
60
|
-
y={padding}
|
|
61
|
-
{tickCount}
|
|
62
|
-
/>
|
|
63
|
-
{:else}
|
|
64
|
-
<ColorRamp {scale} x={width - 100 - padding} y={padding} {tickCount} />
|
|
65
|
-
<!-- <ContinuousLegend
|
|
66
|
-
{scale}
|
|
67
|
-
x={width - 100 - padding}
|
|
68
|
-
y={padding}
|
|
69
|
-
{tickCount}
|
|
70
|
-
/> -->
|
|
71
|
-
{/if}
|
|
72
|
-
{#each datamap.weekdays as name, i}
|
|
73
|
-
<text
|
|
74
|
-
x={padding + dayLabelWidth - 2 * space}
|
|
75
|
-
y={padding + legendHeight + i * sizeWithSpace + labelHeight + (size - labelHeight) / 2}
|
|
76
|
-
text-anchor="end"
|
|
77
|
-
font-size={labelHeight}>{name}</text
|
|
78
|
-
>
|
|
79
|
-
{/each}
|
|
80
|
-
|
|
81
|
-
{#each datamap.grid as d}
|
|
82
|
-
<rect
|
|
83
|
-
x={d.x * sizeWithSpace + padding + dayLabelWidth}
|
|
84
|
-
y={d.y * sizeWithSpace + padding + legendHeight}
|
|
85
|
-
width={size}
|
|
86
|
-
height={size}
|
|
87
|
-
fill={scale(d.value)}
|
|
88
|
-
rx="1"
|
|
89
|
-
ry="1"
|
|
90
|
-
on:mouseover={(e) => showToolTip(e, d)}
|
|
91
|
-
on:focus={(e) => showToolTip(e, d)}
|
|
92
|
-
on:blur={hideToolTip}
|
|
93
|
-
on:mouseout={hideToolTip}
|
|
94
|
-
/>
|
|
95
|
-
{/each}
|
|
96
|
-
|
|
97
|
-
{#each Object.keys(datamap.months) as name}
|
|
98
|
-
<text
|
|
99
|
-
x={padding + dayLabelWidth + datamap.months[name] * sizeWithSpace}
|
|
100
|
-
y={padding + legendHeight + 7 * sizeWithSpace + 3 * space}
|
|
101
|
-
text-anchor="start"
|
|
102
|
-
font-size={labelHeight}
|
|
103
|
-
fill="currentColor">{name}</text
|
|
104
|
-
>
|
|
105
|
-
{/each}
|
|
106
|
-
</svg>
|
|
107
|
-
</div>
|
|
108
|
-
|
|
109
|
-
<style>
|
|
110
|
-
div {
|
|
111
|
-
position: relative;
|
|
112
|
-
}
|
|
113
|
-
rect {
|
|
114
|
-
stroke: currentColor;
|
|
115
|
-
stroke-width: 0.5;
|
|
116
|
-
stroke-opacity: 0.1;
|
|
117
|
-
}
|
|
118
|
-
text {
|
|
119
|
-
fill: currentColor;
|
|
120
|
-
}
|
|
121
|
-
</style>
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import { colorBrewer } from '../lib/palette'
|
|
4
|
-
|
|
5
|
-
let chart = getContext('chart')
|
|
6
|
-
|
|
7
|
-
export let labels = false
|
|
8
|
-
export let fontSize = $chart.height / 32
|
|
9
|
-
// export let color = 'white'
|
|
10
|
-
|
|
11
|
-
$: colors = colorBrewer($chart.data.map((d) => d.color))
|
|
12
|
-
// export let limit = 8
|
|
13
|
-
|
|
14
|
-
$: data = $chart.data.map((d) => ({
|
|
15
|
-
x: $chart.flipCoords ? $chart.scale.x(0) : $chart.scale.x(d.x),
|
|
16
|
-
y: $chart.flipCoords ? $chart.scale.y(d.y) : $chart.scale.y(d.y),
|
|
17
|
-
y0: $chart.scale.y(0),
|
|
18
|
-
width: $chart.flipCoords ? $chart.scale.x(d.x) - $chart.scale.x(0) : $chart.scale.x.bandwidth(),
|
|
19
|
-
height: $chart.flipCoords
|
|
20
|
-
? $chart.scale.y.bandwidth()
|
|
21
|
-
: $chart.scale.y(0) - $chart.scale.y(d.y),
|
|
22
|
-
color: colors[d.color],
|
|
23
|
-
label: {
|
|
24
|
-
x: $chart.flipCoords
|
|
25
|
-
? $chart.scale.x(d.x) - $chart.scale.x(0) - 10
|
|
26
|
-
: $chart.scale.x.bandwidth() / 2,
|
|
27
|
-
y: $chart.flipCoords ? $chart.scale.y.bandwidth() / 2 : 10,
|
|
28
|
-
angle: $chart.flipCoords ? 0 : -90,
|
|
29
|
-
text: $chart.flipCoords ? d.y + ' (' + d.x + ')' : d.x + ' (' + d.y + ')'
|
|
30
|
-
}
|
|
31
|
-
}))
|
|
32
|
-
</script>
|
|
33
|
-
|
|
34
|
-
{#each data as { x1, y1, x2, y2, color, label }}
|
|
35
|
-
<line {x1} {y1} {x2} {y2} stroke={color} />
|
|
36
|
-
{#if labels}
|
|
37
|
-
{@const tx = x1 + label.x}
|
|
38
|
-
{@const ty = y1 + label.y}
|
|
39
|
-
<text
|
|
40
|
-
x={tx}
|
|
41
|
-
y={ty}
|
|
42
|
-
transform="rotate({label.angle},{tx},{ty})"
|
|
43
|
-
font-size={fontSize}
|
|
44
|
-
text-anchor="end"
|
|
45
|
-
alignment-baseline="middle"
|
|
46
|
-
fill={color}
|
|
47
|
-
>
|
|
48
|
-
{label.text}
|
|
49
|
-
</text>
|
|
50
|
-
{/if}
|
|
51
|
-
{/each}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import Bar from '../elements/Bar.svelte'
|
|
3
|
-
import { max } from 'd3-array'
|
|
4
|
-
import { writable } from 'svelte/store'
|
|
5
|
-
import { tweened } from 'svelte/motion'
|
|
6
|
-
import { scaleLinear } from 'd3-scale'
|
|
7
|
-
|
|
8
|
-
export let data
|
|
9
|
-
export let colors
|
|
10
|
-
export let width = 800
|
|
11
|
-
export let limit = 8
|
|
12
|
-
export let duration = 300
|
|
13
|
-
const h = 50
|
|
14
|
-
let height
|
|
15
|
-
const pad = 5
|
|
16
|
-
|
|
17
|
-
const xMax = tweened(null, { duration })
|
|
18
|
-
const scales = writable({})
|
|
19
|
-
|
|
20
|
-
$: xMax.set(max(data.map((d) => d.value)))
|
|
21
|
-
$: height = pad + (h + pad) * limit
|
|
22
|
-
$: scales.set({
|
|
23
|
-
x: scaleLinear()
|
|
24
|
-
.domain([0, $xMax])
|
|
25
|
-
.range([10, width - 10]),
|
|
26
|
-
y: scaleLinear().domain([0, limit]).range([0, height])
|
|
27
|
-
})
|
|
28
|
-
</script>
|
|
29
|
-
|
|
30
|
-
<svg viewBox="0 0 {width} {height}">
|
|
31
|
-
{#if Array.isArray(data)}
|
|
32
|
-
{#each data as item}
|
|
33
|
-
{#if item.rank < limit}
|
|
34
|
-
<Bar {...item} fill={colors[item.name]} {scales} />
|
|
35
|
-
{/if}
|
|
36
|
-
{/each}
|
|
37
|
-
{/if}
|
|
38
|
-
</svg>
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { clamp } from 'yootils'
|
|
3
|
-
import { Symbol } from '@rokkit/molecules'
|
|
4
|
-
import { getContext } from 'svelte'
|
|
5
|
-
|
|
6
|
-
const chart = getContext('chart')
|
|
7
|
-
|
|
8
|
-
export let size = 8
|
|
9
|
-
export let fill = '#c0c0c0'
|
|
10
|
-
export let stroke = '#3c3c3c'
|
|
11
|
-
export let jitterWidth = 50
|
|
12
|
-
export let offset
|
|
13
|
-
|
|
14
|
-
$: jitterWidth = clamp(jitterWidth, 0, 100 / 2)
|
|
15
|
-
$: offset = clamp(offset | (jitterWidth / 2), 0, 100)
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
{#if $chart.data}
|
|
19
|
-
{#each $chart.data as d}
|
|
20
|
-
<Symbol
|
|
21
|
-
x={$chart.axis.x.scale(d[$chart.x]) - offset + Math.random() * jitterWidth}
|
|
22
|
-
y={$chart.axis.y.scale(d[$chart.y])}
|
|
23
|
-
{fill}
|
|
24
|
-
{stroke}
|
|
25
|
-
{size}
|
|
26
|
-
/>
|
|
27
|
-
{/each}
|
|
28
|
-
{/if}
|