@rokkit/chart 1.0.0-next.56 → 1.0.0-next.58
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 +6 -6
- package/src/lib/chart.js +3 -7
- package/src/lib/color.js +2 -6
- package/src/lib/funnel.js +3 -8
- package/src/lib/geom.js +2 -13
- package/src/lib/heatmap.js +1 -3
- package/src/lib/pattern.js +3 -9
- package/src/lib/rollup.js +1 -7
- package/src/lib/store.js +3 -10
- package/src/lib/summary.js +1 -3
- package/src/lib/utils.js +2 -7
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.58",
|
|
4
4
|
"description": "Components for making interactive charts.",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"typescript": "^5.2.2",
|
|
24
24
|
"vite": "^4.5.0",
|
|
25
25
|
"vitest": "~0.34.6",
|
|
26
|
-
"shared-config": "1.0.0-next.
|
|
26
|
+
"shared-config": "1.0.0-next.58"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"d3-array": "^3.2.4",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"date-fns": "^2.30.0",
|
|
36
36
|
"ramda": "^0.29.1",
|
|
37
37
|
"yootils": "^0.3.1",
|
|
38
|
-
"@rokkit/atoms": "1.0.0-next.
|
|
39
|
-
"@rokkit/molecules": "1.0.0-next.
|
|
40
|
-
"@rokkit/core": "1.0.0-next.
|
|
41
|
-
"@rokkit/stores": "1.0.0-next.
|
|
38
|
+
"@rokkit/atoms": "1.0.0-next.58",
|
|
39
|
+
"@rokkit/molecules": "1.0.0-next.58",
|
|
40
|
+
"@rokkit/core": "1.0.0-next.58",
|
|
41
|
+
"@rokkit/stores": "1.0.0-next.58"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"src/**/*.js",
|
package/src/lib/chart.js
CHANGED
|
@@ -52,8 +52,7 @@ export class ChartBrewer {
|
|
|
52
52
|
fill: [...new Set(this.data.map((item) => item[this.fill]))]
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
let xOffset =
|
|
56
|
-
max(this.scaleValues.y.map((value) => value.toString().length)) * 10
|
|
55
|
+
let xOffset = max(this.scaleValues.y.map((value) => value.toString().length)) * 10
|
|
57
56
|
let yOffset = 20
|
|
58
57
|
|
|
59
58
|
this.margin = {
|
|
@@ -158,9 +157,7 @@ export class ChartBrewer {
|
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
// The maximum width of a violin must be x.bandwidth = the width dedicated to a group
|
|
161
|
-
var xNum = scaleLinear()
|
|
162
|
-
.range([0, this.axis.x.scale.bandwidth()])
|
|
163
|
-
.domain([0, maxNum])
|
|
160
|
+
var xNum = scaleLinear().range([0, this.axis.x.scale.bandwidth()]).domain([0, maxNum])
|
|
164
161
|
|
|
165
162
|
let result = area()
|
|
166
163
|
.x0(xNum(0))
|
|
@@ -179,8 +176,7 @@ export class ChartBrewer {
|
|
|
179
176
|
}
|
|
180
177
|
|
|
181
178
|
function tickValues(scale, whichAxis, params) {
|
|
182
|
-
let { values, count } =
|
|
183
|
-
whichAxis in params.ticks ? params.ticks[whichAxis] : {}
|
|
179
|
+
let { values, count } = whichAxis in params.ticks ? params.ticks[whichAxis] : {}
|
|
184
180
|
values =
|
|
185
181
|
Array.isArray(values) && values.length > 2
|
|
186
182
|
? values
|
package/src/lib/color.js
CHANGED
|
@@ -19,12 +19,8 @@ export class ColorBrewer {
|
|
|
19
19
|
|
|
20
20
|
mix(fill, stroke, contrast) {
|
|
21
21
|
this.fill = Object.keys(this.grayscale).includes(fill) ? fill : this.fill
|
|
22
|
-
this.stroke = Object.keys(this.grayscale).includes(stroke)
|
|
23
|
-
|
|
24
|
-
: this.stroke
|
|
25
|
-
this.contrast = Object.keys(this.grayscale).includes(contrast)
|
|
26
|
-
? contrast
|
|
27
|
-
: this.contrast
|
|
22
|
+
this.stroke = Object.keys(this.grayscale).includes(stroke) ? stroke : this.stroke
|
|
23
|
+
this.contrast = Object.keys(this.grayscale).includes(contrast) ? contrast : this.contrast
|
|
28
24
|
|
|
29
25
|
return this
|
|
30
26
|
}
|
package/src/lib/funnel.js
CHANGED
|
@@ -48,9 +48,7 @@ function determineLayout(uniques, aes) {
|
|
|
48
48
|
vertical = false
|
|
49
49
|
console.warn('Assuming horizontal layout because stat is count')
|
|
50
50
|
} else {
|
|
51
|
-
console.error(
|
|
52
|
-
'Cannot plot without at least one axis having numeric values'
|
|
53
|
-
)
|
|
51
|
+
console.error('Cannot plot without at least one axis having numeric values')
|
|
54
52
|
return null
|
|
55
53
|
}
|
|
56
54
|
}
|
|
@@ -77,9 +75,7 @@ export function convertToPhases(input, aes) {
|
|
|
77
75
|
const summary = summarize(input, by, value, aes.stat)
|
|
78
76
|
const phases = nest()
|
|
79
77
|
.key((d) => d[key])
|
|
80
|
-
.rollup((rows) =>
|
|
81
|
-
'fill' in aes ? fillMissing(uniques.fill, rows, key, aes) : rows
|
|
82
|
-
)
|
|
78
|
+
.rollup((rows) => ('fill' in aes ? fillMissing(uniques.fill, rows, key, aes) : rows))
|
|
83
79
|
.entries(summary)
|
|
84
80
|
|
|
85
81
|
return { phases, uniques, vertical }
|
|
@@ -214,8 +210,7 @@ function calculatePosition(input, aes, row, stat, index, midpoint) {
|
|
|
214
210
|
export function funnel(input, aes, width, height) {
|
|
215
211
|
let data = convertToPhases(input, aes)
|
|
216
212
|
data = mirror(data, aes)
|
|
217
|
-
const curve =
|
|
218
|
-
aes.curve === 'basis' ? curveBasis : data.vertical ? curveBumpY : curveBumpX
|
|
213
|
+
const curve = aes.curve === 'basis' ? curveBasis : data.vertical ? curveBumpY : curveBumpX
|
|
219
214
|
|
|
220
215
|
if ('fill' in aes) {
|
|
221
216
|
let stats = flatten(data.stats.map((phase) => phase.value))
|
package/src/lib/geom.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
sum,
|
|
3
|
-
min,
|
|
4
|
-
max,
|
|
5
|
-
mean,
|
|
6
|
-
mode,
|
|
7
|
-
median,
|
|
8
|
-
deviation,
|
|
9
|
-
variance,
|
|
10
|
-
flatRollup
|
|
11
|
-
} from 'd3-array'
|
|
1
|
+
import { sum, min, max, mean, mode, median, deviation, variance, flatRollup } from 'd3-array'
|
|
12
2
|
|
|
13
3
|
const summaries = {
|
|
14
4
|
identity: (value) => value,
|
|
@@ -31,8 +21,7 @@ const summaries = {
|
|
|
31
21
|
*/
|
|
32
22
|
export function rollup(stat) {
|
|
33
23
|
if (typeof stat === 'function') return stat
|
|
34
|
-
if (typeof stat !== 'string')
|
|
35
|
-
throw new TypeError('stat must be a string or function')
|
|
24
|
+
if (typeof stat !== 'string') throw new TypeError('stat must be a string or function')
|
|
36
25
|
if (!(stat in summaries)) throw new TypeError('Unknown stat: ' + stat)
|
|
37
26
|
|
|
38
27
|
return summaries[stat]
|
package/src/lib/heatmap.js
CHANGED
|
@@ -20,9 +20,7 @@ export function summarize(data, dateField = 'date', valueField) {
|
|
|
20
20
|
const nested = nest()
|
|
21
21
|
.key((d) => format(new Date(d[dateField]), DATE_FORMAT))
|
|
22
22
|
.rollup((d) =>
|
|
23
|
-
valueField
|
|
24
|
-
? d.map((value) => value[valueField]).reduce((a, b) => a + b, 0)
|
|
25
|
-
: d.length
|
|
23
|
+
valueField ? d.map((value) => value[valueField]).reduce((a, b) => a + b, 0) : d.length
|
|
26
24
|
)
|
|
27
25
|
.entries(data)
|
|
28
26
|
|
package/src/lib/pattern.js
CHANGED
|
@@ -60,10 +60,7 @@ export const builtIn = [
|
|
|
60
60
|
},
|
|
61
61
|
|
|
62
62
|
{
|
|
63
|
-
path:
|
|
64
|
-
'M5 1 A6 6 0 0 0 5 9' +
|
|
65
|
-
'A6 6 0 0 0 5 1' +
|
|
66
|
-
'M1 5A6 6 0 0 0 9 5A6 6 0 0 0 1 5',
|
|
63
|
+
path: 'M5 1 A6 6 0 0 0 5 9' + 'A6 6 0 0 0 5 1' + 'M1 5A6 6 0 0 0 9 5A6 6 0 0 0 1 5',
|
|
67
64
|
minAngle: 0,
|
|
68
65
|
maxAngle: 90
|
|
69
66
|
},
|
|
@@ -87,8 +84,7 @@ export const builtIn = [
|
|
|
87
84
|
maxAngle: 90
|
|
88
85
|
},
|
|
89
86
|
{
|
|
90
|
-
path:
|
|
91
|
-
'M5 0L6 4L10 5L6 6L5 10L4 6L0 5L4 4Z' + 'M2 1V3M1 2H3' + 'M8 9V7M9 8H7',
|
|
87
|
+
path: 'M5 0L6 4L10 5L6 6L5 10L4 6L0 5L4 4Z' + 'M2 1V3M1 2H3' + 'M8 9V7M9 8H7',
|
|
92
88
|
minAngle: 0,
|
|
93
89
|
maxAngle: 90
|
|
94
90
|
},
|
|
@@ -145,9 +141,7 @@ export class PatternBrewer {
|
|
|
145
141
|
count = clamp(count, 1, 15)
|
|
146
142
|
this.paths = this.paths.map((path) => ({
|
|
147
143
|
...path,
|
|
148
|
-
angles: [...Array(count).keys()].map(
|
|
149
|
-
(i) => (i * (path.maxAngle - path.minAngle)) / count
|
|
150
|
-
)
|
|
144
|
+
angles: [...Array(count).keys()].map((i) => (i * (path.maxAngle - path.minAngle)) / count)
|
|
151
145
|
}))
|
|
152
146
|
return this
|
|
153
147
|
}
|
package/src/lib/rollup.js
CHANGED
|
@@ -29,13 +29,7 @@ function slidingWindowForNumbers(values, size, step, offset = 0, fmt = 0) {
|
|
|
29
29
|
return result
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function slidingWindowForDates(
|
|
33
|
-
values,
|
|
34
|
-
size,
|
|
35
|
-
step,
|
|
36
|
-
offset = {},
|
|
37
|
-
fmt = 'yyyy-MM-dd'
|
|
38
|
-
) {
|
|
32
|
+
function slidingWindowForDates(values, size, step, offset = {}, fmt = 'yyyy-MM-dd') {
|
|
39
33
|
const largest = max(values)
|
|
40
34
|
let current = new Date(format(min(values), fmt))
|
|
41
35
|
let blocks = []
|
package/src/lib/store.js
CHANGED
|
@@ -12,12 +12,8 @@ import { tweened, cubicOut } from 'svelte/motion'
|
|
|
12
12
|
export function animatedChart(input, key, valueFields = [], previous = []) {
|
|
13
13
|
const previousKeys = new Set(previous.map((item) => item[key]))
|
|
14
14
|
const currentKeys = new Set(input.map((item) => item[key]))
|
|
15
|
-
const toAdd = new Set(
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
const toRemove = new Set(
|
|
19
|
-
[...previousKeys].filter((key) => !currentKeys.has(key))
|
|
20
|
-
)
|
|
15
|
+
const toAdd = new Set([...currentKeys].filter((key) => !previousKeys.has(key)))
|
|
16
|
+
const toRemove = new Set([...previousKeys].filter((key) => !currentKeys.has(key)))
|
|
21
17
|
|
|
22
18
|
let data = input
|
|
23
19
|
.filter((item) => toAdd.has(item[key]))
|
|
@@ -25,10 +21,7 @@ export function animatedChart(input, key, valueFields = [], previous = []) {
|
|
|
25
21
|
let el = { ...item }
|
|
26
22
|
valueFields.forEach(
|
|
27
23
|
({ field, initialValue, attrs }) =>
|
|
28
|
-
(el[field] =
|
|
29
|
-
typeof initialValue === 'function'
|
|
30
|
-
? initialValue(el, attrs)
|
|
31
|
-
: initialValue)
|
|
24
|
+
(el[field] = typeof initialValue === 'function' ? initialValue(el, attrs) : initialValue)
|
|
32
25
|
)
|
|
33
26
|
return el
|
|
34
27
|
})
|
package/src/lib/summary.js
CHANGED
|
@@ -20,9 +20,7 @@ export function summarize(data, by, attr, stat = 'count') {
|
|
|
20
20
|
.key((d) => by.map((f) => d[f]).join('|'))
|
|
21
21
|
.rollup((rows) => {
|
|
22
22
|
let agg = pick(by, rows[0])
|
|
23
|
-
stats.map(
|
|
24
|
-
(stat) => (agg[stat] = aggregate[stat](rows.map((d) => d[attr])))
|
|
25
|
-
)
|
|
23
|
+
stats.map((stat) => (agg[stat] = aggregate[stat](rows.map((d) => d[attr]))))
|
|
26
24
|
return [agg]
|
|
27
25
|
})
|
|
28
26
|
.entries(data)
|
package/src/lib/utils.js
CHANGED
|
@@ -127,9 +127,7 @@ export function aggregate(data, x, y) {
|
|
|
127
127
|
* @returns
|
|
128
128
|
*/
|
|
129
129
|
export function getPaletteForValues(values, palette, fallback) {
|
|
130
|
-
return values.map((_, index) =>
|
|
131
|
-
index < palette.length ? palette[index] : fallback
|
|
132
|
-
)
|
|
130
|
+
return values.map((_, index) => (index < palette.length ? palette[index] : fallback))
|
|
133
131
|
}
|
|
134
132
|
|
|
135
133
|
/**
|
|
@@ -156,8 +154,5 @@ export function toNested(data, key, label) {
|
|
|
156
154
|
* @returns {Object} with keys as items in a and values as items in b
|
|
157
155
|
*/
|
|
158
156
|
export function repeatAcross(b, a) {
|
|
159
|
-
return a.reduce(
|
|
160
|
-
(acc, item, index) => ({ ...acc, [item]: b[index % b.length] }),
|
|
161
|
-
{}
|
|
162
|
-
)
|
|
157
|
+
return a.reduce((acc, item, index) => ({ ...acc, [item]: b[index % b.length] }), {})
|
|
163
158
|
}
|