@rokkit/chart 1.0.0-next.94 → 1.0.0-next.95
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/brewer.js +1 -1
- package/src/lib/chart.js +2 -2
- package/src/lib/grid.js +14 -4
- package/src/lib/plots.js +6 -5
- package/src/lib/swatch.js +1 -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.95",
|
|
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.4.4",
|
|
23
23
|
"vite": "^5.2.8",
|
|
24
24
|
"vitest": "~1.4.0",
|
|
25
|
-
"shared-config": "1.0.0-next.
|
|
25
|
+
"shared-config": "1.0.0-next.95"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@observablehq/plot": "^0.6.14",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"date-fns": "^3.6.0",
|
|
36
36
|
"ramda": "^0.29.1",
|
|
37
37
|
"yootils": "^0.3.1",
|
|
38
|
-
"@rokkit/atoms": "1.0.0-next.
|
|
39
|
-
"@rokkit/core": "1.0.0-next.
|
|
40
|
-
"@rokkit/
|
|
41
|
-
"@rokkit/
|
|
38
|
+
"@rokkit/atoms": "1.0.0-next.95",
|
|
39
|
+
"@rokkit/core": "1.0.0-next.95",
|
|
40
|
+
"@rokkit/molecules": "1.0.0-next.95",
|
|
41
|
+
"@rokkit/stores": "1.0.0-next.95"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"src/**/*.js",
|
package/src/lib/brewer.js
CHANGED
package/src/lib/chart.js
CHANGED
|
@@ -101,7 +101,7 @@ class Chart {
|
|
|
101
101
|
y: [this.height - this.padding - this.margin.bottom, this.margin.top + this.padding]
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
const scale = {
|
|
105
105
|
x: getScale(this.domain.x, this.range.x, this.spacing),
|
|
106
106
|
y: getScale(this.domain.y, this.range.y, this.spacing)
|
|
107
107
|
}
|
|
@@ -180,7 +180,7 @@ class Chart {
|
|
|
180
180
|
|
|
181
181
|
ticks = scale.domain()
|
|
182
182
|
if (count < scale.domain().length) {
|
|
183
|
-
|
|
183
|
+
const diff = scale.domain().length - count
|
|
184
184
|
ticks = ticks.filter((d, i) => i % diff === 0)
|
|
185
185
|
}
|
|
186
186
|
}
|
package/src/lib/grid.js
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @typedef SwatchGrid
|
|
10
|
-
* @property {number}
|
|
11
|
-
* @property {number}
|
|
10
|
+
* @property {number} width
|
|
11
|
+
* @property {number} height
|
|
12
12
|
* @property {GridPoint[]} data
|
|
13
13
|
*/
|
|
14
|
+
|
|
14
15
|
/**
|
|
15
16
|
* Calculates a grid of centres to fit a list of items of `size` within the number of `columns` and `rows`.
|
|
16
17
|
*
|
|
@@ -47,8 +48,16 @@ export function swatchGrid(count, size, pad = 0, columns = 0, rows = 0) {
|
|
|
47
48
|
return { width, height, data }
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Spreads values as patterns with colors from a palette
|
|
53
|
+
*
|
|
54
|
+
* @param {number[]} values
|
|
55
|
+
* @param {string[]} patterns
|
|
56
|
+
* @param {string[]} palette
|
|
57
|
+
* @returns {Record<number, { id: string, pattern: string, color: string }>}
|
|
58
|
+
*/
|
|
50
59
|
export function spreadValuesAsPatterns(values, patterns, palette) {
|
|
51
|
-
values
|
|
60
|
+
const result = values
|
|
52
61
|
.map((value, index) => ({
|
|
53
62
|
pattern: patterns[index % patterns.length],
|
|
54
63
|
color: palette[index % palette.length],
|
|
@@ -58,11 +67,12 @@ export function spreadValuesAsPatterns(values, patterns, palette) {
|
|
|
58
67
|
(acc, { value, pattern, color }) => ({
|
|
59
68
|
...acc,
|
|
60
69
|
[value]: {
|
|
61
|
-
id: pattern
|
|
70
|
+
id: `${pattern}_${color}`,
|
|
62
71
|
pattern,
|
|
63
72
|
color
|
|
64
73
|
}
|
|
65
74
|
}),
|
|
66
75
|
{}
|
|
67
76
|
)
|
|
77
|
+
return result
|
|
68
78
|
}
|
package/src/lib/plots.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// skipcq: JS-C1003 - Importing all plots from observablehq/plot
|
|
1
2
|
import * as Plot from '@observablehq/plot'
|
|
2
3
|
|
|
3
4
|
export function plotter(node, options) {
|
|
@@ -15,11 +16,11 @@ export function plotter(node, options) {
|
|
|
15
16
|
render()
|
|
16
17
|
|
|
17
18
|
return {
|
|
18
|
-
update: (
|
|
19
|
-
data =
|
|
20
|
-
aes =
|
|
21
|
-
type =
|
|
22
|
-
opts =
|
|
19
|
+
update: (input) => {
|
|
20
|
+
data = input.data
|
|
21
|
+
aes = input.aes
|
|
22
|
+
type = input.type
|
|
23
|
+
opts = input.opts
|
|
23
24
|
render()
|
|
24
25
|
}
|
|
25
26
|
}
|