@rokkit/chart 1.0.0-next.36 → 1.0.0-next.38
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 +12 -10
- package/src/chart/Chart.svelte +1 -1
- package/src/chart/FacetGrid.svelte +6 -6
- package/src/chart/Swatch.svelte +2 -3
- package/src/chart/TexturedShape.svelte +1 -1
- package/src/chart/TimelapseChart.svelte +2 -2
- package/src/elements/ColorRamp.svelte +1 -1
- package/src/elements/ContinuousLegend.svelte +1 -1
- package/src/index.js +1 -2
- package/src/lib/axis.js +8 -6
- package/src/{components/lib → lib}/chart.js +12 -0
- package/src/lib/color.js +59 -0
- package/src/lib/constants.js +41 -0
- package/src/lib/geom.js +106 -0
- package/src/lib/index.js +0 -0
- package/src/lib/{colors.js → palette.js} +3 -3
- package/src/{components/lib → lib}/pattern.js +4 -6
- package/src/lib/shape.js +46 -0
- package/src/{swatch.js → lib/swatch.js} +4 -4
- package/src/lib/utils.js +6 -0
- package/src/plots/BarPlot.svelte +1 -1
- package/src/plots/FunnelPlot.svelte +2 -3
- package/src/plots/HeatMapCalendar.svelte +1 -1
- package/src/plots/LinePlot.svelte +1 -1
- package/src/plots/Plot.svelte +1 -1
- package/src/plots/ScatterPlot.svelte +1 -1
- package/src/chart/Symbol.svelte +0 -40
- package/src/chart.js +0 -11
- package/src/components/index.js +0 -2
- package/src/components/lib/color.js +0 -327
- package/src/components/lib/index.js +0 -19
- package/src/components/lib/shape.js +0 -199
- package/src/components/lib/timer.js +0 -41
- package/src/components/lib/utils.js +0 -165
- package/src/constants.js +0 -66
- package/src/elements/PatternDefs.svelte +0 -13
- package/src/elements/PatternMask.svelte +0 -20
- package/src/elements/Symbol.svelte +0 -38
- package/src/funnel.svelte +0 -35
- package/src/geom.js +0 -105
- package/src/lib/shapes.js +0 -144
- package/src/plots/old_ScatterPlot.svelte +0 -20
- /package/src/chart/{Grid.svelte → AxisGrid.svelte} +0 -0
- /package/src/{components/lib → lib}/funnel.js +0 -0
- /package/src/{plots → lib}/heatmap.js +0 -0
- /package/src/{lookup.js → lib/lookup.js} +0 -0
- /package/src/{components/lib → lib}/rollup.js +0 -0
- /package/src/{components → lib}/store.js +0 -0
- /package/src/{components/lib → lib}/summary.js +0 -0
- /package/src/{components/lib → lib}/theme.js +0 -0
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.38",
|
|
4
4
|
"description": "Components for making interactive charts.",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,35 +13,37 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@sveltejs/vite-plugin-svelte": "^2.4.
|
|
16
|
+
"@sveltejs/vite-plugin-svelte": "^2.4.3",
|
|
17
17
|
"@testing-library/svelte": "^4.0.3",
|
|
18
18
|
"@vitest/coverage-v8": "^0.33.0",
|
|
19
19
|
"@vitest/ui": "~0.33.0",
|
|
20
20
|
"js-yaml": "^4.1.0",
|
|
21
21
|
"jsdom": "^22.1.0",
|
|
22
|
-
"svelte": "^4.
|
|
22
|
+
"svelte": "^4.1.1",
|
|
23
23
|
"typescript": "^5.1.6",
|
|
24
|
-
"vite": "^4.4.
|
|
24
|
+
"vite": "^4.4.7",
|
|
25
25
|
"vitest": "~0.33.0",
|
|
26
|
-
"shared-config": "1.0.0-next.
|
|
26
|
+
"shared-config": "1.0.0-next.38"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"d3-array": "^3.2.4",
|
|
30
30
|
"d3-collection": "^1.0.7",
|
|
31
|
+
"d3-format": "^3.1.0",
|
|
32
|
+
"d3-interpolate": "^3.0.1",
|
|
31
33
|
"d3-scale": "^4.0.2",
|
|
32
34
|
"d3-shape": "^3.2.0",
|
|
33
35
|
"date-fns": "^2.30.0",
|
|
34
36
|
"ramda": "^0.29.0",
|
|
35
|
-
"rokkit": "latest",
|
|
36
37
|
"yootils": "^0.3.1",
|
|
37
|
-
"@rokkit/
|
|
38
|
+
"@rokkit/atoms": "1.0.0-next.38",
|
|
39
|
+
"@rokkit/core": "1.0.0-next.38",
|
|
40
|
+
"@rokkit/molecules": "1.0.0-next.38",
|
|
41
|
+
"@rokkit/stores": "1.0.0-next.38"
|
|
38
42
|
},
|
|
39
43
|
"files": [
|
|
40
44
|
"src/**/*.js",
|
|
41
45
|
"src/**/*.svelte",
|
|
42
|
-
"!
|
|
43
|
-
"!src/mocks",
|
|
44
|
-
"!src/**/*.spec.js"
|
|
46
|
+
"!spec"
|
|
45
47
|
],
|
|
46
48
|
"exports": {
|
|
47
49
|
"./src": "./src",
|
package/src/chart/Chart.svelte
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import Chart from './Chart.svelte'
|
|
3
3
|
import AxisGrid from './AxisGrid.svelte'
|
|
4
4
|
import Axis from './Axis.svelte'
|
|
5
|
-
import AxisTicks from './AxisTicks.svelte'
|
|
6
|
-
import AxisLabels from './AxisLabels.svelte'
|
|
5
|
+
// import AxisTicks from './AxisTicks.svelte'
|
|
6
|
+
// import AxisLabels from './AxisLabels.svelte'
|
|
7
7
|
|
|
8
8
|
export let data
|
|
9
9
|
export let row
|
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
|
|
30
30
|
<Chart data={dataFilteredByCol} {x} {y}>
|
|
31
31
|
<Axis name="x" count={7} gap={10}>
|
|
32
|
-
<AxisTicks side="bottom">
|
|
32
|
+
<!-- <AxisTicks side="bottom">
|
|
33
33
|
{#if labels.x}
|
|
34
34
|
<AxisLabels angle={-60} />
|
|
35
35
|
{/if}
|
|
36
|
-
</AxisTicks>
|
|
36
|
+
</AxisTicks> -->
|
|
37
37
|
</Axis>
|
|
38
38
|
<Axis name="y" gap={10}>
|
|
39
|
-
<AxisTicks side="left">
|
|
39
|
+
<!-- <AxisTicks side="left">
|
|
40
40
|
{#if labels.y}
|
|
41
41
|
<AxisLabels />
|
|
42
42
|
{/if}
|
|
43
|
-
</AxisTicks>
|
|
43
|
+
</AxisTicks> -->
|
|
44
44
|
<AxisGrid />
|
|
45
45
|
</Axis>
|
|
46
46
|
<svelte:component this={plot} />
|
package/src/chart/Swatch.svelte
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { swatch } from '../lib/utils'
|
|
5
5
|
import { clamp } from 'yootils'
|
|
6
|
-
import Symbol from '
|
|
7
|
-
import PatternDefs from './PatternDefs.svelte'
|
|
6
|
+
import {Symbol, DefinePatterns} from '@rokkit/molecules'
|
|
8
7
|
|
|
9
8
|
const dispatch = createEventDispatcher()
|
|
10
9
|
|
|
@@ -88,6 +87,6 @@
|
|
|
88
87
|
on:focus={forwardEvent('focus', i + start)}
|
|
89
88
|
/>
|
|
90
89
|
{/each}
|
|
91
|
-
<
|
|
90
|
+
<DefinePatterns patterns={items} />
|
|
92
91
|
</svg>
|
|
93
92
|
</div>
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
import { writable } from 'svelte/store'
|
|
4
4
|
import { slidingWindow, uniques, brewer } from '../lib'
|
|
5
5
|
|
|
6
|
-
import Grid from './
|
|
6
|
+
import Grid from './AxisGrid.svelte'
|
|
7
7
|
import Axis from './Axis.svelte'
|
|
8
8
|
import BoxPlot from '../plots/BoxPlot.svelte'
|
|
9
9
|
import ViolinPlot from '../plots/ViolinPlot.svelte'
|
|
10
|
-
import ScatterPlot from '../plots/
|
|
10
|
+
import ScatterPlot from '../plots/ScatterPlot.svelte'
|
|
11
11
|
|
|
12
12
|
let chart = writable({})
|
|
13
13
|
let axis
|
package/src/index.js
CHANGED
|
@@ -12,5 +12,4 @@ export { default as BarPlot } from './plots/BarPlot.svelte'
|
|
|
12
12
|
export { default as LinePlot } from './plots/LinePlot.svelte'
|
|
13
13
|
export { default as BoxPlot } from './plots/BoxPlot.svelte'
|
|
14
14
|
export { default as ViolinPlot } from './plots/ViolinPlot.svelte'
|
|
15
|
-
export
|
|
16
|
-
export * from './components/lib'
|
|
15
|
+
export * from './lib'
|
package/src/lib/axis.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
function getOrigin(scale, axis) {
|
|
2
|
+
const origin = scale[axis].ticks
|
|
3
|
+
? scale(Math.max(0, Math.min(...scale[axis].domain())))
|
|
4
|
+
: scale[axis].range()[0]
|
|
5
|
+
return origin
|
|
6
|
+
}
|
|
1
7
|
export function axis(scale) {
|
|
2
8
|
const origin = {
|
|
3
|
-
x: scale
|
|
4
|
-
|
|
5
|
-
: scale.x.range()[0],
|
|
6
|
-
y: scale.y.ticks
|
|
7
|
-
? scale.y(Math.max(0, Math.min(...scale.y.domain())))
|
|
8
|
-
: scale.y.range()[0]
|
|
9
|
+
x: getOrigin(scale, 'x'),
|
|
10
|
+
y: getOrigin(scale, 'y')
|
|
9
11
|
}
|
|
10
12
|
const ticks = {
|
|
11
13
|
x: axisTicks(scale.x, { axis: 'x', origin }),
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// export function scales(data, aes, opts) {
|
|
2
|
+
// const { x, y } = aes
|
|
3
|
+
// const { width, height, flipCoords } = {
|
|
4
|
+
// width: 800,
|
|
5
|
+
// height: 600,
|
|
6
|
+
// flipCoords: false,
|
|
7
|
+
// ...opts
|
|
8
|
+
// }
|
|
9
|
+
|
|
10
|
+
// return { x, y, width, height, flipCoords }
|
|
11
|
+
// }
|
|
12
|
+
|
|
1
13
|
import { nest } from 'd3-collection'
|
|
2
14
|
import { max, quantile, ascending, bin } from 'd3-array'
|
|
3
15
|
import { scaleLinear } from 'd3-scale'
|
package/src/lib/color.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { palette } from './constants'
|
|
2
|
+
|
|
3
|
+
export class ColorBrewer {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.colors = ['blue', 'pink', 'teal', 'indigo', 'purple', 'amber', 'rose']
|
|
6
|
+
this.palette = palette
|
|
7
|
+
this.grayscale = this.palette['trueGray']
|
|
8
|
+
this.fill = 100
|
|
9
|
+
this.stroke = 600
|
|
10
|
+
this.contrast = 600
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
dark() {
|
|
14
|
+
this.fill = 500
|
|
15
|
+
this.stroke = 700
|
|
16
|
+
this.contrast = 100
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
mix(fill, stroke, contrast) {
|
|
21
|
+
this.fill = Object.keys(this.grayscale).includes(fill) ? fill : this.fill
|
|
22
|
+
this.stroke = Object.keys(this.grayscale).includes(stroke)
|
|
23
|
+
? stroke
|
|
24
|
+
: this.stroke
|
|
25
|
+
this.contrast = Object.keys(this.grayscale).includes(contrast)
|
|
26
|
+
? contrast
|
|
27
|
+
: this.contrast
|
|
28
|
+
|
|
29
|
+
return this
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
swatch(colors) {
|
|
33
|
+
this.palette = colors
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
filter(colors) {
|
|
38
|
+
this.colors = colors
|
|
39
|
+
return this
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
gray() {
|
|
43
|
+
return {
|
|
44
|
+
fill: this.grayscale[this.fill],
|
|
45
|
+
stroke: this.grayscale[this.stroke],
|
|
46
|
+
contrast: this.grayscale[this.contrast]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
brew() {
|
|
51
|
+
const palette = this.colors.map((color) => ({
|
|
52
|
+
fill: this.palette[color][this.fill],
|
|
53
|
+
stroke: this.palette[color][this.stroke],
|
|
54
|
+
contrast: this.palette[color][this.contrast]
|
|
55
|
+
}))
|
|
56
|
+
|
|
57
|
+
return palette
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import patterns__ from './patterns.json'
|
|
2
|
+
import __palette from './palette.json'
|
|
3
|
+
|
|
4
|
+
export const __patterns__ = patterns__
|
|
5
|
+
export const palette = __palette
|
|
6
|
+
export const __muted__ = {
|
|
7
|
+
color: '#eeeeee',
|
|
8
|
+
fill: 'empty',
|
|
9
|
+
shape: 'circle'
|
|
10
|
+
}
|
|
11
|
+
export const __colors__ = [
|
|
12
|
+
'#FFDE6B',
|
|
13
|
+
'#EF89EE',
|
|
14
|
+
'#F79F1E',
|
|
15
|
+
'#02B8FF',
|
|
16
|
+
'#9F84EC',
|
|
17
|
+
'#15CBC4',
|
|
18
|
+
'#0092FD',
|
|
19
|
+
'#F63A57',
|
|
20
|
+
'#A2CB39',
|
|
21
|
+
'#FF6E2F',
|
|
22
|
+
'#FEB8B9',
|
|
23
|
+
'#af7aa1',
|
|
24
|
+
'#7EFFF5'
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
export const colors = [
|
|
28
|
+
'#FFDE6B',
|
|
29
|
+
'#EF89EE',
|
|
30
|
+
'#F79F1E',
|
|
31
|
+
'#02B8FF',
|
|
32
|
+
'#9F84EC',
|
|
33
|
+
'#15CBC4',
|
|
34
|
+
'#0092FD',
|
|
35
|
+
'#F63A57',
|
|
36
|
+
'#A2CB39',
|
|
37
|
+
'#FF6E2F',
|
|
38
|
+
'#FEB8B9',
|
|
39
|
+
'#af7aa1',
|
|
40
|
+
'#7EFFF5'
|
|
41
|
+
]
|
package/src/lib/geom.js
CHANGED
|
@@ -1,3 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sum,
|
|
3
|
+
min,
|
|
4
|
+
max,
|
|
5
|
+
mean,
|
|
6
|
+
mode,
|
|
7
|
+
median,
|
|
8
|
+
deviation,
|
|
9
|
+
variance,
|
|
10
|
+
flatRollup
|
|
11
|
+
} from 'd3-array'
|
|
12
|
+
|
|
13
|
+
const summaries = {
|
|
14
|
+
identity: (value) => value,
|
|
15
|
+
count: (values) => values.length,
|
|
16
|
+
sum: (values) => sum(values),
|
|
17
|
+
min: (values) => min(values),
|
|
18
|
+
max: (values) => max(values),
|
|
19
|
+
mean: (values) => mean(values),
|
|
20
|
+
median: (values) => median(values),
|
|
21
|
+
mode: (values) => mode(values),
|
|
22
|
+
variance: (values) => variance(values),
|
|
23
|
+
deviation: (values) => deviation(values)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns an aggregator function for an input string or function.
|
|
28
|
+
*
|
|
29
|
+
* @param {string|function} stat
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export function rollup(stat) {
|
|
33
|
+
if (typeof stat === 'function') return stat
|
|
34
|
+
if (typeof stat !== 'string')
|
|
35
|
+
throw new TypeError('stat must be a string or function')
|
|
36
|
+
if (!(stat in summaries)) throw new TypeError('Unknown stat: ' + stat)
|
|
37
|
+
|
|
38
|
+
return summaries[stat]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Aesthetics for a chart.
|
|
43
|
+
*
|
|
44
|
+
* @typedef Aesthetics
|
|
45
|
+
* @property {string} x
|
|
46
|
+
* @property {string} y
|
|
47
|
+
* @property {string} [fill]
|
|
48
|
+
* @property {string} [size]
|
|
49
|
+
* @property {string} [color]
|
|
50
|
+
* @property {string} [shape]
|
|
51
|
+
* @property {string} [pattern]
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {Array<any>} data
|
|
57
|
+
* @param {Aesthetics} aes
|
|
58
|
+
* @param {function|string} stat
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
export function aggregate(data, aes, stat = 'identity') {
|
|
62
|
+
const agg = rollup(stat)
|
|
63
|
+
const keys = ['color', 'fill', 'pattern', 'shape', 'size'].filter((k) =>
|
|
64
|
+
Object.keys(aes).includes(k)
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
let groups = keys.map((k) => (d) => d[aes[k]])
|
|
68
|
+
|
|
69
|
+
return flatRollup(
|
|
70
|
+
data,
|
|
71
|
+
(v) => agg(v.map((d) => d[aes.y])),
|
|
72
|
+
(d) => d[aes.x],
|
|
73
|
+
...groups
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// export function geomBars(chart, aes) {
|
|
78
|
+
// const { x, y, fill, color, pattern } = { ...aes, ...chart.aes }
|
|
79
|
+
// return aggregate(chart.data, { x, y, fill, color, pattern })
|
|
80
|
+
// }
|
|
81
|
+
|
|
82
|
+
// export function geomLines(chart, aes) {
|
|
83
|
+
// const { x, y, color } = { ...aes, ...chart.aes }
|
|
84
|
+
// return aggregate(chart.data, { x, y, color })
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
// export function geomViolin(chart, aes) {
|
|
88
|
+
// const { x, y, fill, color, pattern } = { ...aes, ...chart.aes }
|
|
89
|
+
// return { x, y, fill, color, pattern, ...opts }
|
|
90
|
+
// }
|
|
91
|
+
|
|
92
|
+
// export function geomArea(chart, aes) {
|
|
93
|
+
// const { x, y, fill, color, pattern } = { ...aes, ...chart.aes }
|
|
94
|
+
// return { x, y, fill, color, pattern, ...opts }
|
|
95
|
+
// }
|
|
96
|
+
|
|
97
|
+
// export function geomTrend(chart, aes) {
|
|
98
|
+
// const { x, y, fill, color, pattern } = { ...aes, ...chart.aes }
|
|
99
|
+
// return { x, y, fill, color, pattern, ...opts }
|
|
100
|
+
// }
|
|
101
|
+
|
|
102
|
+
// export function geomPoints(chart, aes) {
|
|
103
|
+
// const { x, y, fill, color, shape, size } = { ...aes, ...chart.aes }
|
|
104
|
+
// return { x, y, fill, color, shape, size, ...opts }
|
|
105
|
+
// }
|
|
106
|
+
|
|
1
107
|
// export function violin(data, mapping) {}
|
|
2
108
|
// export function bar(data, mapping) {}
|
|
3
109
|
// export function scatter(data, mapping) {}
|
package/src/lib/index.js
ADDED
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// import { writable } from 'svelte/store'
|
|
2
|
-
import { repeatAcross } from '
|
|
2
|
+
import { repeatAcross } from './utils'
|
|
3
3
|
|
|
4
4
|
const palette = [
|
|
5
5
|
'#FFDE6B',
|
|
@@ -18,8 +18,8 @@ const palette = [
|
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
export class Palette {
|
|
21
|
-
constructor(
|
|
22
|
-
this.colors =
|
|
21
|
+
constructor(palette) {
|
|
22
|
+
this.colors = palette
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
set colors(value) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { clamp } from 'yootils'
|
|
2
2
|
import { ColorBrewer } from './color'
|
|
3
|
-
import { toHexString, uniqueId } from './utils'
|
|
3
|
+
import { toHexString, uniqueId, addToArray, toArray } from './utils'
|
|
4
4
|
|
|
5
5
|
export const builtIn = [
|
|
6
6
|
{ path: 'M0 5A6 6 0 0 0 10 5', minAngle: 0, maxAngle: 90 },
|
|
@@ -125,20 +125,18 @@ export class PatternBrewer {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
add(path) {
|
|
128
|
-
|
|
129
|
-
this.paths = [...this.paths, ...paths]
|
|
130
|
-
|
|
128
|
+
this.paths = addToArray(this.pathc, path)
|
|
131
129
|
return this
|
|
132
130
|
}
|
|
133
131
|
|
|
134
132
|
filter(indices) {
|
|
135
|
-
indices =
|
|
133
|
+
indices = toArray(indices)
|
|
136
134
|
this.indices = indices.filter((i) => i >= 0 && i < this.paths.length)
|
|
137
135
|
return this
|
|
138
136
|
}
|
|
139
137
|
|
|
140
138
|
colors(shades, repeat = false) {
|
|
141
|
-
this.shades =
|
|
139
|
+
this.shades = toArray(shades)
|
|
142
140
|
this.repeat = repeat
|
|
143
141
|
return this
|
|
144
142
|
}
|
package/src/lib/shape.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ColorBrewer } from './color'
|
|
2
|
+
import { symbols } from '@rokkit/atoms/symbols'
|
|
3
|
+
import { addToArray, toArray } from './utils'
|
|
4
|
+
export class ShapeBrewer {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.shapes = Object.keys(symbols)
|
|
7
|
+
this.repeat = false
|
|
8
|
+
this.keys = Object.keys(this.shapes)
|
|
9
|
+
this.gray = new ColorBrewer().gray()
|
|
10
|
+
this.shades = []
|
|
11
|
+
this.repeat = false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
clear() {
|
|
15
|
+
this.shapes = []
|
|
16
|
+
return this
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
add(shape) {
|
|
20
|
+
this.shapes = addToArray(this.shapes, shape)
|
|
21
|
+
|
|
22
|
+
return this
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
filter(keys) {
|
|
26
|
+
this.keys = toArray(keys).filter((key) => key in this.shapes)
|
|
27
|
+
|
|
28
|
+
return this
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
colors(shades, repeat = false) {
|
|
32
|
+
this.shades = toArray(shades)
|
|
33
|
+
this.repeat = repeat
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
brew() {
|
|
38
|
+
return this.keys
|
|
39
|
+
.map((i) => this.shapes[i])
|
|
40
|
+
.map((shape, i) => {
|
|
41
|
+
return i < this.shades.length || this.repeat
|
|
42
|
+
? { shape, ...this.shades[i % this.shades.length] }
|
|
43
|
+
: { shape, ...this.gray }
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -5,7 +5,7 @@ import { writable } from 'svelte/store'
|
|
|
5
5
|
export const swatchStore = writable({})
|
|
6
6
|
|
|
7
7
|
// A set of 7 should be sufficient
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
8
|
+
// set of patterns
|
|
9
|
+
// set of shapes
|
|
10
|
+
// set of colors
|
|
11
|
+
// fill, stroke, text
|
package/src/lib/utils.js
CHANGED
|
@@ -4,6 +4,12 @@ import { ascending, quantile } from 'd3-array'
|
|
|
4
4
|
import { nest } from 'd3-collection'
|
|
5
5
|
import { omit } from 'ramda'
|
|
6
6
|
|
|
7
|
+
export function toArray(value) {
|
|
8
|
+
return Array.isArray(value) ? value : [value]
|
|
9
|
+
}
|
|
10
|
+
export function addToArray(array, value) {
|
|
11
|
+
return [...array, ...toArray(value)]
|
|
12
|
+
}
|
|
7
13
|
/**
|
|
8
14
|
* Calculates a grid of centres to fit a list of items of `size` within the number of `columns` and `rows`.
|
|
9
15
|
*
|
package/src/plots/BarPlot.svelte
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { getContext } from 'svelte'
|
|
3
|
-
import { compact } from '
|
|
4
|
-
import { funnel } from '../
|
|
3
|
+
import { compact } from '@rokkit/core'
|
|
4
|
+
import { funnel } from '../lib/funnel'
|
|
5
5
|
|
|
6
6
|
const chart = getContext('chart')
|
|
7
7
|
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
|
|
14
14
|
$: aes = { ...$chart.aes, ...compact({ x, y, fill, stat, curve }) }
|
|
15
15
|
$: data = funnel($chart.data, aes, $chart.width, $chart.height)
|
|
16
|
-
|
|
17
16
|
</script>
|
|
18
17
|
|
|
19
18
|
{#each data.stats as stat, i}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { summarize, heatmap } from '
|
|
2
|
+
import { summarize, heatmap } from '../lib/heatmap'
|
|
3
3
|
import { interpolateHsl } from 'd3-interpolate'
|
|
4
4
|
import { scaleLinear } from 'd3-scale'
|
|
5
5
|
// import ContinuousLegend from '../elements/ContinuousLegend.svelte'
|
package/src/plots/Plot.svelte
CHANGED
package/src/chart/Symbol.svelte
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { namedShapes } from '../components/lib/shape'
|
|
3
|
-
|
|
4
|
-
export let x = 0
|
|
5
|
-
export let y = 0
|
|
6
|
-
export let size = 10
|
|
7
|
-
export let fill = 'none'
|
|
8
|
-
export let stroke = 'currentColor'
|
|
9
|
-
export let thickness = 0.5
|
|
10
|
-
|
|
11
|
-
export let name = null
|
|
12
|
-
export let shape = null
|
|
13
|
-
|
|
14
|
-
$: x = x - size / 2
|
|
15
|
-
$: y = y - size / 2
|
|
16
|
-
|
|
17
|
-
$: d =
|
|
18
|
-
typeof shape === 'function'
|
|
19
|
-
? shape(size)
|
|
20
|
-
: (shape || name) in namedShapes
|
|
21
|
-
? namedShapes[shape || name](size)
|
|
22
|
-
: namedShapes.circle(size)
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
26
|
-
<path
|
|
27
|
-
{d}
|
|
28
|
-
{fill}
|
|
29
|
-
{stroke}
|
|
30
|
-
transform="translate({x},{y})"
|
|
31
|
-
stroke-width={thickness}
|
|
32
|
-
fill-rule="evenodd"
|
|
33
|
-
on:click
|
|
34
|
-
on:mouseover
|
|
35
|
-
on:mouseleave
|
|
36
|
-
on:focus
|
|
37
|
-
role="option"
|
|
38
|
-
aria-selected={false}
|
|
39
|
-
tabindex="0"
|
|
40
|
-
/>
|
package/src/chart.js
DELETED
package/src/components/index.js
DELETED