Skip to content

Commit

Permalink
fix(line): fix error when color field is cat (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc authored Sep 24, 2020
1 parent 2fb8628 commit 157f9ce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 2 additions & 4 deletions __tests__/unit/adaptor/geometries/base-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ describe('adaptor - geometry', () => {
},
},
});
expect(plot.chart.geometries[0].getAttribute('color').getFields()).toEqual(['date', 'value']);
expect(plot.chart.geometries[0].getAttribute('color').getFields()).toEqual(['value']);

expect(plot.chart.geometries[0].getAttribute('color').values).toEqual([]);
expect(plot.chart.geometries[0].getAttribute('color').callback).toBeDefined();

expect(p).toEqual({
date: '25/01/2018',
value: 1800,
});
});
Expand Down Expand Up @@ -124,13 +123,12 @@ describe('adaptor - geometry', () => {
},
},
});
expect(plot.chart.geometries[0].getAttribute('color').getFields()).toEqual(['type', 'date', 'value']);
expect(plot.chart.geometries[0].getAttribute('color').getFields()).toEqual(['type', 'value']);

expect(plot.chart.geometries[0].getAttribute('color').values).toEqual([]);
expect(plot.chart.geometries[0].getAttribute('color').callback).toBeDefined();

expect(p).toEqual({
date: '25/01/2018',
type: 'Ind/Oth',
value: 1800,
});
Expand Down
3 changes: 2 additions & 1 deletion src/adaptor/geometries/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export function geometry<O extends GeometryOptions>(params: Params<O>): Params<O
if (isString(color)) {
colorField ? geometry.color(colorField, color) : geometry.color(color);
} else if (isFunction(color)) {
const mappingFields = getMappingField(options, 'color');
// 对于单折线图的特殊处理,如果 x 轴是分类 scale,会导致映射错误
const mappingFields = getMappingField(options, 'color').filter((f: string) => f !== xField);
geometry.color(mappingFields.join('*'), getMappingFunction(mappingFields, color));
} else {
colorField && geometry.color(colorField, color);
Expand Down

0 comments on commit 157f9ce

Please sign in to comment.