@rokkit/chart 1.0.0-next.144 → 1.0.0-next.146
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/chart",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.146",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Data-driven chart components",
|
|
6
6
|
"repository": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@rokkit/core": "
|
|
42
|
-
"@rokkit/data": "
|
|
43
|
-
"@rokkit/states": "
|
|
41
|
+
"@rokkit/core": "latest",
|
|
42
|
+
"@rokkit/data": "latest",
|
|
43
|
+
"@rokkit/states": "latest",
|
|
44
44
|
"d3-array": "^3.2.4",
|
|
45
45
|
"d3-format": "^3.1.2",
|
|
46
46
|
"d3-axis": "^3.0.0",
|
|
@@ -157,7 +157,12 @@ function yPositionPassthrough(scale, value) {
|
|
|
157
157
|
export function createYAxis(scales, dimensions, options) {
|
|
158
158
|
if (!scales.y) return { ticks: [] }
|
|
159
159
|
const { tickCount, formatter, label } = parseAxisOptions(options)
|
|
160
|
-
const ticks = mapTicks(
|
|
160
|
+
const ticks = mapTicks(
|
|
161
|
+
scales.y,
|
|
162
|
+
resolveYTicks(scales.y, tickCount),
|
|
163
|
+
formatter,
|
|
164
|
+
yPositionPassthrough
|
|
165
|
+
)
|
|
161
166
|
return {
|
|
162
167
|
ticks,
|
|
163
168
|
label,
|
|
@@ -114,7 +114,18 @@ function buildGroupBar(item, scales, ctx) {
|
|
|
114
114
|
* @returns {BarData|null}
|
|
115
115
|
*/
|
|
116
116
|
function buildOneGroupBar(scales, ctx) {
|
|
117
|
-
const {
|
|
117
|
+
const {
|
|
118
|
+
groupItems,
|
|
119
|
+
groupField,
|
|
120
|
+
group,
|
|
121
|
+
i,
|
|
122
|
+
yField,
|
|
123
|
+
colorField,
|
|
124
|
+
barWidth,
|
|
125
|
+
padding,
|
|
126
|
+
dimensions,
|
|
127
|
+
xPos
|
|
128
|
+
} = ctx
|
|
118
129
|
const item = groupItems.find((d) => d[groupField] === group)
|
|
119
130
|
if (!item) return null
|
|
120
131
|
const barX = xPos + i * (barWidth + padding)
|
|
@@ -152,8 +163,10 @@ function parseGroupedBarsConfig(fields, options) {
|
|
|
152
163
|
export function createGroupedBars(data, fields, scales, options) {
|
|
153
164
|
if (!data || !data.length || !fields.group) return { groups: [], bars: [] }
|
|
154
165
|
|
|
155
|
-
const { xField, yField, groupField, colorField, dimensions, padding } =
|
|
156
|
-
|
|
166
|
+
const { xField, yField, groupField, colorField, dimensions, padding } = parseGroupedBarsConfig(
|
|
167
|
+
fields,
|
|
168
|
+
options
|
|
169
|
+
)
|
|
157
170
|
|
|
158
171
|
const groups = [...new SvelteSet(data.map((d) => d[groupField]))]
|
|
159
172
|
const xValues = [...new SvelteSet(data.map((d) => d[xField]))]
|
|
@@ -167,7 +180,18 @@ export function createGroupedBars(data, fields, scales, options) {
|
|
|
167
180
|
const groupItems = data.filter((d) => d[xField] === xValue)
|
|
168
181
|
const xPos = xScale(xValue)
|
|
169
182
|
groups.forEach((group, i) => {
|
|
170
|
-
const ctx = {
|
|
183
|
+
const ctx = {
|
|
184
|
+
groupItems,
|
|
185
|
+
groupField,
|
|
186
|
+
group,
|
|
187
|
+
i,
|
|
188
|
+
yField,
|
|
189
|
+
colorField,
|
|
190
|
+
barWidth,
|
|
191
|
+
padding,
|
|
192
|
+
dimensions,
|
|
193
|
+
xPos
|
|
194
|
+
}
|
|
171
195
|
const bar = buildOneGroupBar(scales, ctx)
|
|
172
196
|
if (bar) bars.push(bar)
|
|
173
197
|
})
|
package/src/lib/context.js
CHANGED
|
@@ -33,10 +33,8 @@ function createDimensionsStore(config) {
|
|
|
33
33
|
*/
|
|
34
34
|
function createInnerDimensions(dimensions) {
|
|
35
35
|
return derived(dimensions, ($d) => ({
|
|
36
|
-
width:
|
|
37
|
-
|
|
38
|
-
height:
|
|
39
|
-
$d.height - $d.margin.top - $d.margin.bottom - $d.padding.top - $d.padding.bottom
|
|
36
|
+
width: $d.width - $d.margin.left - $d.margin.right - $d.padding.left - $d.padding.right,
|
|
37
|
+
height: $d.height - $d.margin.top - $d.margin.bottom - $d.padding.top - $d.padding.bottom
|
|
40
38
|
}))
|
|
41
39
|
}
|
|
42
40
|
|
package/src/lib/scales.svelte.js
CHANGED
|
@@ -74,7 +74,10 @@ export function createScales(data, dimensions, options) {
|
|
|
74
74
|
|
|
75
75
|
return {
|
|
76
76
|
xScale: buildXScale(xValues, dimensions, padding),
|
|
77
|
-
yScale: scaleLinear()
|
|
77
|
+
yScale: scaleLinear()
|
|
78
|
+
.domain([0, max(yValues) * 1.1])
|
|
79
|
+
.nice()
|
|
80
|
+
.range([dimensions.innerHeight, 0]),
|
|
78
81
|
colorScale
|
|
79
82
|
}
|
|
80
83
|
}
|
package/src/lib/utils.js
CHANGED
|
@@ -111,10 +111,7 @@ export function formatTooltipContent(d, options = {}) {
|
|
|
111
111
|
const { xKey, yKey, xFormat, yFormat } = options
|
|
112
112
|
|
|
113
113
|
if (xKey && yKey) {
|
|
114
|
-
return [
|
|
115
|
-
formatField(xKey, d[xKey], xFormat),
|
|
116
|
-
formatField(yKey, d[yKey], yFormat)
|
|
117
|
-
].join('<br>')
|
|
114
|
+
return [formatField(xKey, d[xKey], xFormat), formatField(yKey, d[yKey], yFormat)].join('<br>')
|
|
118
115
|
}
|
|
119
116
|
|
|
120
117
|
return Object.entries(d)
|