@opendata-ai/openchart-engine 6.13.0 → 6.15.1
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/dist/index.js +190 -81
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/encoding-sugar.test.ts +3 -2
- package/src/charts/bar/compute.ts +28 -5
- package/src/charts/bar/index.ts +3 -0
- package/src/charts/bar/labels.ts +31 -13
- package/src/charts/column/index.ts +3 -0
- package/src/charts/column/labels.ts +35 -13
- package/src/charts/dot/index.ts +10 -1
- package/src/charts/dot/labels.ts +37 -6
- package/src/charts/line/area.ts +12 -4
- package/src/charts/line/compute.ts +7 -2
- package/src/charts/line/index.ts +33 -2
- package/src/compile.ts +1 -0
- package/src/compiler/validate.ts +1 -1
- package/src/layout/axes.ts +2 -2
- package/src/layout/scales.ts +15 -12
- package/src/legend/compute.ts +2 -4
- package/src/tooltips/compute.ts +29 -1
package/src/tooltips/compute.ts
CHANGED
|
@@ -84,12 +84,25 @@ function buildFields(row: DataRow, encoding: Encoding, color?: string): TooltipF
|
|
|
84
84
|
|
|
85
85
|
const fields: TooltipField[] = [];
|
|
86
86
|
|
|
87
|
+
// Color/series field (e.g. "Source: Coal") so the user knows which series
|
|
88
|
+
if (encoding.color && 'field' in encoding.color) {
|
|
89
|
+
fields.push({
|
|
90
|
+
label: resolveLabel(encoding.color),
|
|
91
|
+
value: formatValue(
|
|
92
|
+
row[encoding.color.field],
|
|
93
|
+
encoding.color.type,
|
|
94
|
+
resolveFormat(encoding.color),
|
|
95
|
+
),
|
|
96
|
+
color,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
87
100
|
// Y-axis value (the "main" value in most charts)
|
|
88
101
|
if (encoding.y) {
|
|
89
102
|
fields.push({
|
|
90
103
|
label: resolveLabel(encoding.y),
|
|
91
104
|
value: formatValue(row[encoding.y.field], encoding.y.type, resolveFormat(encoding.y)),
|
|
92
|
-
color,
|
|
105
|
+
color: encoding.color ? undefined : color,
|
|
93
106
|
});
|
|
94
107
|
}
|
|
95
108
|
|
|
@@ -138,6 +151,21 @@ function getTooltipTitle(row: DataRow, encoding: Encoding): string | undefined {
|
|
|
138
151
|
return String(row[encoding.y.field] ?? '');
|
|
139
152
|
}
|
|
140
153
|
|
|
154
|
+
// For scatter/bubble (both axes quantitative), find a name-like string field
|
|
155
|
+
// in the data row that isn't already used by an encoding channel
|
|
156
|
+
if (encoding.x?.type === 'quantitative' && encoding.y?.type === 'quantitative') {
|
|
157
|
+
const encodedFields = new Set(
|
|
158
|
+
[encoding.x, encoding.y, encoding.color, encoding.size, encoding.detail]
|
|
159
|
+
.filter((ch): ch is EncodingChannel => !!ch && 'field' in ch)
|
|
160
|
+
.map((ch) => ch.field),
|
|
161
|
+
);
|
|
162
|
+
for (const [key, value] of Object.entries(row)) {
|
|
163
|
+
if (!encodedFields.has(key) && typeof value === 'string') {
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
141
169
|
// For color-encoded series, use the series name (skip conditional defs)
|
|
142
170
|
if (encoding.color && 'field' in encoding.color) {
|
|
143
171
|
return String(row[encoding.color.field] ?? '');
|