Skip to content

Commit 75e79e5

Browse files
committed
fix parser
1 parent 41444ab commit 75e79e5

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

src/dataParser.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ describe('dataParser', () => {
195195
expect(pluginData.links[1].color).toBe('#00FF00');
196196
expect(pluginData.links[2].color).toBe('#0000FF');
197197

198-
// Check display names include color column
199-
expect(displayNames).toHaveLength(4);
200-
expect(displayNames).toEqual(['source', 'destination', 'color', 'value']);
198+
// Check display names exclude color column
199+
expect(displayNames).toHaveLength(3);
200+
expect(displayNames).toEqual(['source', 'destination', 'value']);
201201
});
202202

203203
it('should parse 4-column data with color column detected by value pattern', () => {

src/dataParser.ts

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -135,40 +135,17 @@ export function parseData(data: { series: any[] }, options: { valueField: any },
135135
return [{ links: [], nodes: [] }, [], [], null, fixColor];
136136
}
137137

138-
// Helper to detect if a field is a color column
139-
const isColorColumn = (field: Field<any, Vector<any>>): boolean => {
140-
const fieldName = getFieldDisplayName(field).toLowerCase();
138+
// If we have 4 columns, the 3rd column (index 2) is the color column
139+
const hasColorColumn = numFields === 4;
140+
const colorFieldIndex = hasColorColumn ? 2 : -1;
141141

142-
// Check if field name suggests it's a color
143-
if (fieldName === 'color' || fieldName === 'colour') {
144-
return true;
145-
}
146-
147-
// Check if field type is string and values look like colors
148-
if (field.type === 'string' && field.values.length > 0) {
149-
const sampleValue = field.values.get(0);
150-
if (sampleValue) {
151-
const colorPattern = /^(#[0-9a-fA-F]{3,8}|rgb|hsl|[a-z\-]+)$/i;
152-
return colorPattern.test(String(sampleValue).trim());
153-
}
154-
}
155-
156-
return false;
157-
};
158-
159-
// Detect if we have a color column
160-
let colorFieldIndex = -1;
161-
if (numFields === 4) {
162-
// Check the third column (index 2) for color
163-
if (isColorColumn(allData[2])) {
164-
colorFieldIndex = 2;
165-
}
166-
}
167-
168-
// get display names
142+
// get display names (exclude color column if present)
169143
let displayNames: string[] = [];
170-
allData.forEach((field: Field<any, Vector<any>>) => {
171-
displayNames.push(getFieldDisplayName(field));
144+
allData.forEach((field: Field<any, Vector<any>>, index: number) => {
145+
// Skip the color column in display names
146+
if (index !== colorFieldIndex) {
147+
displayNames.push(getFieldDisplayName(field));
148+
}
172149
});
173150

174151
// Find value field (should be the numeric field, typically the 3rd column)

0 commit comments

Comments
 (0)