@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
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { scaleBand, scaleLinear } from 'd3-scale'
|
|
2
|
-
import { min, max } from 'd3-array'
|
|
3
|
-
import { ascending, quantile } from 'd3-array'
|
|
4
|
-
import { nest } from 'd3-collection'
|
|
5
|
-
import { omit, filter } from 'ramda'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Generates a unique id from current timestamp
|
|
9
|
-
*
|
|
10
|
-
* @returns {String} timestamp based unique id
|
|
11
|
-
*/
|
|
12
|
-
export function uniqueId(prefix = '') {
|
|
13
|
-
return prefix + Date.now().toString(36)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Capitalizes the first letter of input string
|
|
18
|
-
*
|
|
19
|
-
* @param {String} str
|
|
20
|
-
* @returns {String}
|
|
21
|
-
*/
|
|
22
|
-
export function initCap(str) {
|
|
23
|
-
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Removes undefined and null values from the input object.
|
|
28
|
-
*
|
|
29
|
-
* @param {Object} obj
|
|
30
|
-
* @returns {Object}
|
|
31
|
-
*/
|
|
32
|
-
export function compact(obj) {
|
|
33
|
-
return filter((x) => x !== undefined && x !== null, obj)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Converts an input number into it's hexadecimal representation, with optional left padded zeroes based on the `size`
|
|
38
|
-
*
|
|
39
|
-
* @param {number} value
|
|
40
|
-
* @param {number} size
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
export function toHexString(value, size = 2) {
|
|
44
|
-
return value.toString(16).padStart(size, '0')
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Calculates a grid of centres to fit a list of items of `size` within the number of `columns` and `rows`.
|
|
49
|
-
*
|
|
50
|
-
* - Attempts to find a best fit square if both columns and rows are not specified
|
|
51
|
-
* - Value in columns is prioritized over rows for recalculating the grid
|
|
52
|
-
* - Supports padding between the items
|
|
53
|
-
*
|
|
54
|
-
* @param {number} count
|
|
55
|
-
* @param {number} size
|
|
56
|
-
* @param {number} pad
|
|
57
|
-
* @param {number} columns
|
|
58
|
-
* @param {number} rows
|
|
59
|
-
* @returns
|
|
60
|
-
*/
|
|
61
|
-
export function swatch(count, size, pad = 0, columns, rows) {
|
|
62
|
-
if (columns > 0) {
|
|
63
|
-
rows = Math.ceil(count / columns)
|
|
64
|
-
} else if (rows > 0) {
|
|
65
|
-
columns = Math.ceil(count / rows)
|
|
66
|
-
} else {
|
|
67
|
-
columns = Math.ceil(Math.sqrt(count))
|
|
68
|
-
rows = Math.ceil(count / columns)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const width = (size + pad) * columns + pad
|
|
72
|
-
const height = (size + pad) * rows + pad
|
|
73
|
-
const data = [...Array(count).keys()].map((index) => ({
|
|
74
|
-
cx: (size + pad) / 2 + (index % columns) * (size + pad),
|
|
75
|
-
cy: (size + pad) / 2 + Math.floor(index / columns) * (size + pad),
|
|
76
|
-
r: size / 2
|
|
77
|
-
}))
|
|
78
|
-
|
|
79
|
-
return { width, height, data }
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get a scale function mapping the values between a range of lower and upper values
|
|
83
|
-
*
|
|
84
|
-
* @param {array} values
|
|
85
|
-
* @param {array[2]} bounds
|
|
86
|
-
* @param {number} buffer
|
|
87
|
-
* @returns
|
|
88
|
-
*/
|
|
89
|
-
export function getScale(values, bounds, buffer = 0) {
|
|
90
|
-
if (values.some(isNaN)) {
|
|
91
|
-
return scaleBand().range(bounds).domain(values).padding(0.5)
|
|
92
|
-
} else {
|
|
93
|
-
// ensure that all numeric values are converted to numbers so that d3 min/max provide correct results
|
|
94
|
-
values = values.map((n) => +n)
|
|
95
|
-
|
|
96
|
-
let minValue = min(values)
|
|
97
|
-
let maxValue = max(values)
|
|
98
|
-
|
|
99
|
-
if (minValue < 0 && maxValue > 0) {
|
|
100
|
-
maxValue = max([-1 * minValue, maxValue])
|
|
101
|
-
minValue = -1 * maxValue
|
|
102
|
-
}
|
|
103
|
-
const margin = (maxValue - minValue) * buffer
|
|
104
|
-
return scaleLinear()
|
|
105
|
-
.domain([minValue - margin, maxValue + margin])
|
|
106
|
-
.range(bounds)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Obtain the scale function for the `x` and `y` fields in the data set.
|
|
111
|
-
*
|
|
112
|
-
* @param {array<dict>} data
|
|
113
|
-
* @param {string} x
|
|
114
|
-
* @param {string} y
|
|
115
|
-
* @param {number} width
|
|
116
|
-
* @param {number} height
|
|
117
|
-
* @returns
|
|
118
|
-
*/
|
|
119
|
-
export function getScales(data, x, y, width, height) {
|
|
120
|
-
const xValues = [...new Set(data.map((item) => item[x]))]
|
|
121
|
-
const yValues = [...new Set(data.map((item) => item[y]))]
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
scaleX: getScale(xValues, [0, width]),
|
|
125
|
-
scaleY: getScale(yValues, [height, 0], 0.1)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Summarize `data` by fields `x` and `y` and return a nested array with
|
|
131
|
-
* key as unique `x` values and value as statistical summaries of `y` values
|
|
132
|
-
*
|
|
133
|
-
* @param {*} data
|
|
134
|
-
* @param {*} x
|
|
135
|
-
* @param {*} y
|
|
136
|
-
* @returns
|
|
137
|
-
*/
|
|
138
|
-
export function aggregate(data, x, y) {
|
|
139
|
-
const summary = nest()
|
|
140
|
-
.key((d) => d[x])
|
|
141
|
-
.rollup((d) => {
|
|
142
|
-
let values = d.map((g) => g[y]).sort(ascending)
|
|
143
|
-
let q1 = quantile(values, 0.25)
|
|
144
|
-
let q3 = quantile(values, 0.75)
|
|
145
|
-
let median = quantile(values, 0.5)
|
|
146
|
-
let interQuantileRange = q3 - q1
|
|
147
|
-
let min = q1 - 1.5 * interQuantileRange
|
|
148
|
-
let max = q3 + 1.5 * interQuantileRange
|
|
149
|
-
return { q1, q3, median, interQuantileRange, min, max }
|
|
150
|
-
})
|
|
151
|
-
.entries(data)
|
|
152
|
-
return summary
|
|
153
|
-
}
|
|
154
|
-
export function getPaletteForValues(values, { palette, fallback }) {
|
|
155
|
-
return values.map((value, index) =>
|
|
156
|
-
index < palette.length ? palette[index] : fallback
|
|
157
|
-
)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function toNested(data, key, label) {
|
|
161
|
-
return nest()
|
|
162
|
-
.key((d) => d[key])
|
|
163
|
-
.rollup((values) => values.map((value) => omit([key], value)))
|
|
164
|
-
.entries(data.sort((a, b) => ascending(a[label], b[label])))
|
|
165
|
-
}
|
package/src/constants.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export const __muted__ = {
|
|
2
|
-
color: '#eeeeee',
|
|
3
|
-
fill: 'empty',
|
|
4
|
-
shape: 'circle'
|
|
5
|
-
}
|
|
6
|
-
export const __colors__ = [
|
|
7
|
-
'#FFDE6B',
|
|
8
|
-
'#EF89EE',
|
|
9
|
-
'#F79F1E',
|
|
10
|
-
'#02B8FF',
|
|
11
|
-
'#9F84EC',
|
|
12
|
-
'#15CBC4',
|
|
13
|
-
'#0092FD',
|
|
14
|
-
'#F63A57',
|
|
15
|
-
'#A2CB39',
|
|
16
|
-
'#FF6E2F',
|
|
17
|
-
'#FEB8B9',
|
|
18
|
-
'#af7aa1',
|
|
19
|
-
'#7EFFF5'
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
export const __patterns__ = {
|
|
23
|
-
A: 'M0 5A6 6 0 0 0 10 5',
|
|
24
|
-
B: 'M0 10L10 0',
|
|
25
|
-
C: 'M0 0A10 10 0 0 0 10 10',
|
|
26
|
-
D: 'M0 0L10 10',
|
|
27
|
-
E: 'M10 5A6 6 0 0 0 0 5',
|
|
28
|
-
F: 'M10 10A10 10 0 0 0 0 0',
|
|
29
|
-
G: 'M0 0L10 10ZM10 0L0 10Z',
|
|
30
|
-
H: 'M1 1L9 1L9 9L1 9Z',
|
|
31
|
-
I: 'M4 0L4 10M6 10L6 0M0 4L10 4M10 6L0 6',
|
|
32
|
-
J: 'M0 2L8 10M2 0L10 8M0 8L8 0M2 10L10 2',
|
|
33
|
-
K: 'M5 1A 4 4 0 0 0 9 5A4 4 0 0 0 5 9A4 4 0 0 0 1 5A4 4 0 0 0 5 1',
|
|
34
|
-
L: 'M1 3L7 9M3 1L9 7M1 7L7 1M3 9L9 3',
|
|
35
|
-
M: 'M2 2A4 4 0 0 0 8 2A4 4 0 0 0 8 8A4 4 0 0 0 2 8A4 4 0 0 0 2 2',
|
|
36
|
-
N: 'M0 0A5 5 0 0 0 10 0A5 5 0 0 0 10 10A5 5 0 0 0 0 10A5 5 0 0 0 0 0',
|
|
37
|
-
O: 'M5 2A 3 3 0 0 0 8 5A3 3 0 0 0 5 8A3 3 0 0 0 2 5A3 3 0 0 0 5 2',
|
|
38
|
-
P: 'M2 5L5 2L8 5L5 8Z',
|
|
39
|
-
Q: 'M3 5A2 2 0 0 0 7 5A2 2 0 0 0 3 5M1 5L9 5M5 1L5 9',
|
|
40
|
-
R: 'M2 8L8 2ZM1.5 3.5L3.5 1.5ZM6.5 8.5L8.5 6.5ZM0 0L10 10Z',
|
|
41
|
-
S:
|
|
42
|
-
'M2 8L8 2ZM1.5 3.5L3.5 1.5Z' +
|
|
43
|
-
'M6.5 8.5L8.5 6.5Z' +
|
|
44
|
-
'M2 2L8 8M1.5 6.5L3.5 8.5' +
|
|
45
|
-
'M6.5 1.5L8.5 3.5',
|
|
46
|
-
T:
|
|
47
|
-
'M5 1 A6 6 0 0 0 5 9' +
|
|
48
|
-
'A6 6 0 0 0 5 1' +
|
|
49
|
-
'M1 5A6 6 0 0 0 9 5A6 6 0 0 0 1 5',
|
|
50
|
-
U:
|
|
51
|
-
'M1.5 5A1 1 0 0 0 3.5 5A1 1 0 0 0 1.5 5' +
|
|
52
|
-
'M6.5 5A1 1 0 0 0 8.5 5A1 1 0 0 0 6.5 5' +
|
|
53
|
-
'M5 1.5A1 1 0 0 0 5 3.5A1 1 0 0 0 5 1.5' +
|
|
54
|
-
'M5 6.5A1 1 0 0 0 5 8.5A1 1 0 0 0 5 6.5',
|
|
55
|
-
V:
|
|
56
|
-
'M1.5 2.5A1 1 0 0 0 3.5 2.5A1 1 0 0 0 1.5 2.5' +
|
|
57
|
-
'M6.5 2.5A1 1 0 0 0 8.5 2.5A1 1 0 0 0 6.5 2.5' +
|
|
58
|
-
'M2.5 6.5A1 1 0 0 0 2.5 8.5A1 1 0 0 0 2.5 6.5' +
|
|
59
|
-
'M7.5 6.5A1 1 0 0 0 7.5 8.5A1 1 0 0 0 7.5 6.5' +
|
|
60
|
-
'M3.5 5A1 1 0 0 0 6.5 5A1 1 0 0 0 3.5 5',
|
|
61
|
-
W: 'M5 0L6 4L10 5L6 6L5 10L4 6L0 5L4 4Z' + 'M2 1V3M1 2H3' + 'M8 9V7M9 8H7',
|
|
62
|
-
X: 'M5 2L2.5 9L8.8 4.6L1.2 4.6L7.5 9Z',
|
|
63
|
-
Y: 'M0 5A5 5 0 0 0 5 0' + 'M5 10A5 5 0 0 0 0 5' + 'M5 10A5 5 0 0 0 5 0',
|
|
64
|
-
Z: 'M0 0L10 10M5 0L10 5M0 5 L5 10',
|
|
65
|
-
Z1: 'M0 0L10 10M3 0L10 7M0 7 L3 10'
|
|
66
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import PatternMask from './PatternMask.svelte'
|
|
3
|
-
const size = 10
|
|
4
|
-
|
|
5
|
-
export let thickness = 0.5
|
|
6
|
-
export let patterns
|
|
7
|
-
</script>
|
|
8
|
-
|
|
9
|
-
<defs>
|
|
10
|
-
{#each patterns as pattern}
|
|
11
|
-
<PatternMask {...pattern} {thickness} {size} />
|
|
12
|
-
{/each}
|
|
13
|
-
</defs>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export let id
|
|
3
|
-
// export let fill
|
|
4
|
-
export let path
|
|
5
|
-
// export let contrast
|
|
6
|
-
export let thickness = 0.5
|
|
7
|
-
export let patternUnits = 'userSpaceOnUse'
|
|
8
|
-
export let size = 10
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<pattern id="p-{id}" {patternUnits} width={size} height={size}>
|
|
12
|
-
{#if path}
|
|
13
|
-
<path d={path} fill="none" stroke="white" stroke-width={thickness} />
|
|
14
|
-
<!-- {:else}
|
|
15
|
-
<rect width={size} height={size} {fill} /> -->
|
|
16
|
-
{/if}
|
|
17
|
-
</pattern>
|
|
18
|
-
<mask {id}>
|
|
19
|
-
<rect x="0" y="0" width="100%" height="100%" fill="url(#p-{id})" />
|
|
20
|
-
</mask>
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
// import { namedShapes } from '../lib/shape'
|
|
3
|
-
import { swatchStore } from '../swatch'
|
|
4
|
-
|
|
5
|
-
export let x = 0
|
|
6
|
-
export let y = 0
|
|
7
|
-
export let size = 10
|
|
8
|
-
export let fill = 'none'
|
|
9
|
-
export let stroke = 'currentColor'
|
|
10
|
-
export let thickness = 0.5
|
|
11
|
-
|
|
12
|
-
export let name = 'circle'
|
|
13
|
-
// export let shape = null
|
|
14
|
-
|
|
15
|
-
$: x = x - size / 2
|
|
16
|
-
$: y = y - size / 2
|
|
17
|
-
|
|
18
|
-
$: d = $swatchStore['shapes'][name](size)
|
|
19
|
-
// typeof shape === 'function'
|
|
20
|
-
// ? shape(size)
|
|
21
|
-
// : (shape || name) in namedShapes
|
|
22
|
-
// ? namedShapes[shape || name](size)
|
|
23
|
-
// : namedShapes.circle(size)
|
|
24
|
-
</script>
|
|
25
|
-
|
|
26
|
-
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
27
|
-
<path
|
|
28
|
-
{d}
|
|
29
|
-
{fill}
|
|
30
|
-
{stroke}
|
|
31
|
-
transform="translate({x},{y})"
|
|
32
|
-
stroke-width={thickness}
|
|
33
|
-
fill-rule="evenodd"
|
|
34
|
-
on:click
|
|
35
|
-
on:mouseover
|
|
36
|
-
on:mouseleave
|
|
37
|
-
on:focus
|
|
38
|
-
/>
|
package/src/funnel.svelte
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
<!-- <script context="module">
|
|
2
|
-
/**
|
|
3
|
-
* @type {import('@sveltejs/kit').Load}
|
|
4
|
-
*/
|
|
5
|
-
export async function load({ page, fetch, session, stuff }) {
|
|
6
|
-
const url = '/api/data/funnel'
|
|
7
|
-
const response = await fetch(url)
|
|
8
|
-
|
|
9
|
-
if (response.ok) {
|
|
10
|
-
let result = await response.json()
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
props: { data: result }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
status: response.status,
|
|
19
|
-
error: new Error(`Could not load ${url}`)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
</script> -->
|
|
23
|
-
|
|
24
|
-
<script>
|
|
25
|
-
import { FunnelPlot, Chart } from '@rokkit/chart'
|
|
26
|
-
export let data
|
|
27
|
-
|
|
28
|
-
// let names = ['one', 'two', 'three'] // each one is a separate segment. max of Combined value at each stage is overall height/width
|
|
29
|
-
// let groups = ['a', 'b', 'c'] // each group should have a value. individual values are used for each band height
|
|
30
|
-
</script>
|
|
31
|
-
|
|
32
|
-
<h1>Funnel</h1>
|
|
33
|
-
<Chart {data} width={1200}>
|
|
34
|
-
<FunnelPlot x="stage" y="count" fill="client" stat="sum" />
|
|
35
|
-
</Chart>
|
package/src/geom.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
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
|
-
// }
|
package/src/lib/shapes.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const names = [
|
|
2
|
-
'circle',
|
|
3
|
-
'square',
|
|
4
|
-
'triangle',
|
|
5
|
-
'diamond',
|
|
6
|
-
'star',
|
|
7
|
-
'rhombus',
|
|
8
|
-
'heart'
|
|
9
|
-
]
|
|
10
|
-
const data = {
|
|
11
|
-
square: ['M', 1, 1, 'L', 9, 1, 'L', 9, 9, 'L', 1, 9, 'Z'],
|
|
12
|
-
circle: [
|
|
13
|
-
['M', 0, 5],
|
|
14
|
-
['A', 5, 5, 0, 0, 0, 10, 5],
|
|
15
|
-
['A', 5, 5, 0, 0, 0, 0, 5]
|
|
16
|
-
],
|
|
17
|
-
triangle: ['M', 5, 0, 'L', 10, 10, 'L', 0, 10, 'Z'],
|
|
18
|
-
diamond: [
|
|
19
|
-
['M', 5, 0],
|
|
20
|
-
['A', 7, 7, 0, 0, 0, 10, 5],
|
|
21
|
-
['A', 7, 7, 0, 0, 0, 5, 10],
|
|
22
|
-
['A', 7, 7, 0, 0, 0, 0, 5],
|
|
23
|
-
['A', 7, 7, 0, 0, 0, 5, 0]
|
|
24
|
-
],
|
|
25
|
-
rhombus: ['M', 0, 5, 'L', 5, 0, 'L', 10, 5, 'L', 5, 10, 'Z'],
|
|
26
|
-
heart: [
|
|
27
|
-
['M', 9, 5],
|
|
28
|
-
['A', 0.8, 0.8, 0, 0, 0, 5, 2],
|
|
29
|
-
['A', 0.8, 0.8, 0, 0, 0, 1, 5],
|
|
30
|
-
['L', 5, 9],
|
|
31
|
-
['L', 9, 5]
|
|
32
|
-
],
|
|
33
|
-
star: [
|
|
34
|
-
['M', 4.80001, 0],
|
|
35
|
-
['L', 5.92258, 3.45491],
|
|
36
|
-
['H', 9.55529],
|
|
37
|
-
['L', 6.61637, 5.59017],
|
|
38
|
-
['L', 7.73894, 9.04509],
|
|
39
|
-
['L', 4.80001, 6.90983],
|
|
40
|
-
['L', 1.86108, 9.04509],
|
|
41
|
-
['L', 2.98365, 5.59017],
|
|
42
|
-
['L', 0.0447266, 3.45491],
|
|
43
|
-
['H', 3.67744],
|
|
44
|
-
['L', 4.80001, 0],
|
|
45
|
-
['Z']
|
|
46
|
-
]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function scaledPath(size, x) {
|
|
50
|
-
if (Array.isArray(x)) return x.map((x) => scaledPath(size, x)).join(' ')
|
|
51
|
-
return typeof size === 'number' ? x * size : x
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const shapes = names.map((name) => ({
|
|
55
|
-
name,
|
|
56
|
-
path: (s) => scaledPath(s, data[name])
|
|
57
|
-
}))
|
|
58
|
-
|
|
59
|
-
export const namedShapes = {
|
|
60
|
-
square: (s) =>
|
|
61
|
-
`M${0.1 * s} 0` +
|
|
62
|
-
`A${0.1 * s} ${0.1 * s} 0 0 0 0 ${0.1 * s}V${0.9 * s}` +
|
|
63
|
-
`A${0.1 * s} ${0.1 * s} 0 0 0 ${0.1 * s} ${s}H${0.9 * s}` +
|
|
64
|
-
`A${0.1 * s} ${0.1 * s} 0 0 0 ${s} ${0.9 * s}V${0.1 * s}` +
|
|
65
|
-
`A${0.1 * s} ${0.1 * s} 0 0 0 ${0.9 * s} 0Z`,
|
|
66
|
-
circle: (s) =>
|
|
67
|
-
`M0 ${0.5 * s}` +
|
|
68
|
-
`A${0.5 * s} ${0.5 * s} 0 0 0 ${s} ${0.5 * s}` +
|
|
69
|
-
`A${0.5 * s} ${0.5 * s} 0 0 0 0 ${0.5 * s}`,
|
|
70
|
-
diamond: (s) =>
|
|
71
|
-
`M${0.5 * s} 0` +
|
|
72
|
-
`A${0.6 * s} ${0.6 * s} 0 0 0 ${s} ${0.5 * s}` +
|
|
73
|
-
`A${0.6 * s} ${0.6 * s} 0 0 0 ${0.5 * s} ${s}` +
|
|
74
|
-
`A${0.6 * s} ${0.6 * s} 0 0 0 0 ${0.5 * s}` +
|
|
75
|
-
`A${0.6 * s} ${0.6 * s} 0 0 0 ${0.5 * s} 0`,
|
|
76
|
-
triangle: (s) =>
|
|
77
|
-
`M${0.5 * s} ${0.0866 * s}L0 ${0.9234 * s}L${s} ${0.9234 * s}Z`,
|
|
78
|
-
rhombus: (s) =>
|
|
79
|
-
`M${0.5 * s} 0` +
|
|
80
|
-
`L${s} ${0.5 * s}` +
|
|
81
|
-
`L${0.5 * s} ${s}` +
|
|
82
|
-
`L0 ${0.5 * s}Z`,
|
|
83
|
-
star: (s) =>
|
|
84
|
-
`M${0.5 * s} ${0.05 * s}` +
|
|
85
|
-
`L${0.606 * s} ${0.36 * s}` +
|
|
86
|
-
`L${s} ${0.36 * s}` +
|
|
87
|
-
`L${0.685 * s} ${0.59 * s}` +
|
|
88
|
-
`L${0.81 * s} ${0.95 * s}` +
|
|
89
|
-
`L${0.5 * s} ${0.725 * s}` +
|
|
90
|
-
`L${0.19 * s} ${0.95 * s}` +
|
|
91
|
-
`L${0.315 * s} ${0.59 * s}` +
|
|
92
|
-
`L0 ${0.36 * s}` +
|
|
93
|
-
`L${0.394 * s} ${0.36 * s}Z`,
|
|
94
|
-
heart: (s) =>
|
|
95
|
-
`M${0.9 * s} ${0.5 * s}` +
|
|
96
|
-
`A${0.08 * s} ${0.08 * s} 0 0 0 ${0.5 * s} ${0.2 * s}` +
|
|
97
|
-
`A${0.08 * s} ${0.08 * s} 0 0 0 ${0.1 * s} ${0.5 * s}` +
|
|
98
|
-
`L${0.5 * s} ${0.9 * s}` +
|
|
99
|
-
`L${0.9 * s} ${0.5 * s}`,
|
|
100
|
-
shurikan: (s) =>
|
|
101
|
-
`M${0.3 * s} ${0.1 * s}L${0.5 * s} 0L${0.7 * s} ${0.1 * s}` +
|
|
102
|
-
`A ${0.05 * s} ${0.05 * s} 0 0 0 ${0.9 * s} ${0.35 * s}` +
|
|
103
|
-
`L${s} ${0.5 * s}L${0.9 * s} ${0.7 * s}` +
|
|
104
|
-
`A ${0.05 * s} ${0.05 * s} 0 0 0 ${0.7 * s} ${0.9 * s}` +
|
|
105
|
-
`L${0.5 * s} ${s}L${0.3 * s} ${0.9 * s}` +
|
|
106
|
-
`A${0.05 * s} ${0.05 * s} 0 0 0 ${0.1 * s} ${0.7 * s}` +
|
|
107
|
-
`L0 ${0.5 * s}L${0.1 * s} ${0.3 * s}` +
|
|
108
|
-
`A${0.05 * s} ${0.05 * s} 0 0 0 ${0.3 * s} ${0.1 * s}` +
|
|
109
|
-
`M${0.4 * s} ${0.5 * s}` +
|
|
110
|
-
`A${0.1 * s} ${0.1 * s} 0 0 0 ${0.6 * s} ${0.5 * s}` +
|
|
111
|
-
`A${0.1 * s} ${0.1 * s} 0 0 0 ${0.4 * s} ${0.5 * s}`,
|
|
112
|
-
crosshair: (s) =>
|
|
113
|
-
`M${0.2 * s} ${0.5 * s}` +
|
|
114
|
-
`A${0.3 * s} ${0.3 * s} 0 0 0 ${0.8 * s} ${0.5 * s}` +
|
|
115
|
-
`A${0.3 * s} ${0.3 * s} 0 0 0 ${0.2 * s} ${0.5 * s}` +
|
|
116
|
-
`M0 ${0.5 * s}` +
|
|
117
|
-
`L${s} ${0.5 * s}` +
|
|
118
|
-
`M${0.5 * s} 0` +
|
|
119
|
-
`L${0.5 * s} ${s}`,
|
|
120
|
-
crossboats: (s) =>
|
|
121
|
-
`M0 ${0.5 * s}` +
|
|
122
|
-
`A${0.6 * s} ${0.4 * s} 0 0 0 ${s} ${0.5 * s}` +
|
|
123
|
-
`A${0.6 * s} ${0.4 * s} 0 0 0 0 ${0.5 * s}` +
|
|
124
|
-
`M${0.5 * s} 0` +
|
|
125
|
-
`A${0.4 * s} ${0.6 * s} 0 0 0 ${0.5 * s} ${s}` +
|
|
126
|
-
`A${0.4 * s} ${0.6 * s} 0 0 0 ${0.5 * s} 0`,
|
|
127
|
-
curvedrhombus: (s) =>
|
|
128
|
-
`M${0.1 * s} ${0.1 * s}` +
|
|
129
|
-
`A${0.5 * s} ${0.5 * s} 0 0 0 ${0.9 * s} ${0.1 * s}` +
|
|
130
|
-
`A${0.5 * s} ${0.5 * s} 0 0 0 ${0.9 * s} ${0.9 * s}` +
|
|
131
|
-
`A${0.5 * s} ${0.5 * s} 0 0 0 ${0.1 * s} ${0.9 * s}` +
|
|
132
|
-
`A${0.5 * s} ${0.5 * s} 0 0 0 ${0.1 * s} ${0.1 * s}`,
|
|
133
|
-
fourflags: (s) =>
|
|
134
|
-
`M${0.5 * s} ${0.3 * s}` +
|
|
135
|
-
`A${0.2 * s} ${0.1 * s} 0 0 0 ${0.5 * s} ${0.1 * s}` +
|
|
136
|
-
`L${0.5 * s} ${0.9 * s}` +
|
|
137
|
-
`M${0.5 * s} ${0.7 * s}` +
|
|
138
|
-
`A${0.2 * s} ${0.1 * s} 0 0 0 ${0.5 * s} ${0.9 * s}` +
|
|
139
|
-
`M${0.3 * s} ${0.5 * s}` +
|
|
140
|
-
`A${0.1 * s} ${0.2 * s} 0 0 0 ${0.1 * s} ${0.5 * s}` +
|
|
141
|
-
`L${0.9 * s} ${0.5 * s}` +
|
|
142
|
-
`M${0.7 * s} ${0.5 * s}` +
|
|
143
|
-
`A${0.1 * s} ${0.2 * s} 0 0 0 ${0.9 * s} ${0.5 * s}`
|
|
144
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import { colorBrewer } from '../lib/colors'
|
|
4
|
-
|
|
5
|
-
let chart = getContext('chart')
|
|
6
|
-
|
|
7
|
-
export let size = $chart.height / 128
|
|
8
|
-
|
|
9
|
-
$: colors = colorBrewer($chart.data.map((d) => d.fill))
|
|
10
|
-
$: points = $chart.data.map((d) => ({
|
|
11
|
-
cx: $chart.scale.x(d.x),
|
|
12
|
-
cy: $chart.scale.y(d.y),
|
|
13
|
-
fill: colors[d.fill]
|
|
14
|
-
}))
|
|
15
|
-
// support shapes and sizes for scatter
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
{#each points as { cx, cy, fill }}
|
|
19
|
-
<circle {cx} {cy} r={size} {fill} fill-opacity="0.5" />
|
|
20
|
-
{/each}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|