@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.
@@ -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] ?? '');