Skip to content

Commit

Permalink
fix: 双轴图 point 颜色映射错误和参数丢失 (#1823)
Browse files Browse the repository at this point in the history
* fix: 双轴图 point 颜色映射错误和参数丢失

* fix: conversation

* fix: test

Co-authored-by: liufu.lf <liufu.lf@antfin.com>
  • Loading branch information
lxfu1 and liufu.lf authored Oct 30, 2020
1 parent 07ae1d0 commit a1c7d52
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
89 changes: 89 additions & 0 deletions __tests__/unit/plots/dual-axes/point-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { DualAxes } from '../../../../src';
import { PV_DATA_MULTI, UV_DATA_MULTI } from '../../../data/pv-uv';
import { createDiv } from '../../../utils/dom';

describe('point', () => {
it('point style', () => {
const dualAxes = new DualAxes(createDiv('test DualAxes point'), {
width: 400,
height: 500,
data: [PV_DATA_MULTI, UV_DATA_MULTI],
xField: 'date',
yField: ['pv', 'uv'],
geometryOptions: [
{
geometry: 'column',
seriesField: 'site',
isStack: true,
},
{
geometry: 'line',
seriesField: 'site',
isStack: true,
point: {
style: () => ({ fill: 'red' }),
},
},
],
});

dualAxes.render();

const element = dualAxes.chart.views[1].geometries[1].elements[0];
expect(element.getModel().shape).toBe('circle');
expect(element.getData().site).toBeDefined();
expect(element.getModel().style.fill).toBe('red');
});
it('point false', () => {
const dualAxes = new DualAxes(createDiv('test DualAxes point false'), {
width: 400,
height: 500,
data: [PV_DATA_MULTI, UV_DATA_MULTI],
xField: 'date',
yField: ['pv', 'uv'],
geometryOptions: [
{
geometry: 'column',
seriesField: 'site',
isStack: true,
},
{
geometry: 'line',
seriesField: 'site',
isStack: true,
point: false,
},
],
});

dualAxes.render();
const element = dualAxes.chart.views[1].geometries[1];
expect(element).toBeUndefined();
});

it('point undefined', () => {
const dualAxes = new DualAxes(createDiv('test DualAxes point undefined'), {
width: 400,
height: 500,
data: [PV_DATA_MULTI, UV_DATA_MULTI],
xField: 'date',
yField: ['pv', 'uv'],
geometryOptions: [
{
geometry: 'column',
seriesField: 'site',
isStack: true,
},
{
geometry: 'line',
seriesField: 'site',
isStack: true,
},
],
});

dualAxes.render();
const element = dualAxes.chart.views[1].geometries[1];
expect(element).toBeUndefined();
});
});
9 changes: 7 additions & 2 deletions src/plots/dual-axes/util/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function drawSingleGeometry<O extends { xField: string; yField: string; g
): Params<O> {
const { options, chart } = params;
const { geometryOption, yField } = options;
const { isStack } = geometryOption;
const { isStack, color } = geometryOption;

const FIELD_KEY = ['xField', 'yField'];
if (isLine(geometryOption)) {
Expand All @@ -37,7 +37,12 @@ export function drawSingleGeometry<O extends { xField: string; yField: string; g
deepMix({}, params, {
options: {
...pick(options, FIELD_KEY),
point: geometryOption.point,
...geometryOption,
point: geometryOption?.point && {
color,
shape: 'circle',
...geometryOption?.point,
},
},
})
);
Expand Down

0 comments on commit a1c7d52

Please sign in to comment.