-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 双轴图新增 slider * feat: 补充 slider 单测 * fix: ci * fix: isBetween 移入 number 中 * fix: reolve conversation * docs: 补充文档 * fix: confict Co-authored-by: liufu.lf <liufu.lf@antfin.com>
- Loading branch information
Showing
12 changed files
with
384 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { DualAxes } from '../../../../src'; | ||
import { delay } from '../../../utils/delay'; | ||
import { PV_DATA_MULTI, UV_DATA_MULTI, uvBillData, transformData } from '../../../data/pv-uv'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('slider', () => { | ||
it('type cat', async () => { | ||
const dualAxes = new DualAxes(createDiv('test DualAxes doubal line'), { | ||
data: [PV_DATA_MULTI, UV_DATA_MULTI], | ||
xField: 'date', | ||
yField: ['pv', 'uv'], | ||
limitInPlot: false, | ||
meta: { | ||
date: { | ||
sync: false, | ||
}, | ||
}, | ||
slider: { | ||
start: 0, | ||
end: 0.5, | ||
}, | ||
padding: [20, 40, 60, 40], | ||
geometryOptions: [ | ||
{ | ||
geometry: 'column', | ||
seriesField: 'site', | ||
isStack: true, | ||
}, | ||
{ | ||
geometry: 'line', | ||
seriesField: 'site', | ||
isStack: true, | ||
}, | ||
], | ||
}); | ||
|
||
dualAxes.render(); | ||
expect(dualAxes.chart.views[0].getOptions().slider).toEqual({ | ||
start: 0, | ||
end: 0.5, | ||
}); | ||
await delay(500); | ||
// 需要去重, 存在双轴数据 | ||
expect(Array.from(new Set(dualAxes.chart.views[0].filterData(PV_DATA_MULTI).map((item) => item.date)))).toEqual([ | ||
'0601', | ||
'0602', | ||
'0603', | ||
'0604', | ||
'0605', | ||
]); | ||
expect(dualAxes.chart.getController('slider')).toBeDefined(); | ||
expect(dualAxes.chart.views[0].getController('slider').getComponents().length).toBe(1); | ||
expect(dualAxes.chart.views[1].getController('slider').getComponents().length).toBe(0); | ||
const [slider] = dualAxes.chart.views[0].getComponents().filter((co) => co.type === 'slider'); | ||
expect(slider.component.get('minText')).toBe('0601'); | ||
dualAxes.update({ | ||
slider: { | ||
start: 0, | ||
end: 1, | ||
}, | ||
}); | ||
expect(dualAxes.chart.views[0].getOptions().slider).toEqual({ | ||
start: 0, | ||
end: 1, | ||
}); | ||
expect(Array.from(new Set(dualAxes.chart.views[0].filterData(PV_DATA_MULTI).map((item) => item.date)))).toEqual([ | ||
'0601', | ||
'0602', | ||
'0603', | ||
'0604', | ||
'0605', | ||
'0606', | ||
'0607', | ||
'0608', | ||
'0609', | ||
]); | ||
dualAxes.destroy(); | ||
}); | ||
it('type time', async () => { | ||
const dualAxes = new DualAxes(createDiv('test DualAxes doubal line'), { | ||
data: [uvBillData, transformData], | ||
xField: 'time', | ||
yField: ['value', 'count'], | ||
geometryOptions: [ | ||
{ | ||
geometry: 'line', | ||
seriesField: 'type', | ||
lineStyle: { | ||
lineWidth: 3, | ||
lineDash: [5, 5], | ||
}, | ||
smooth: true, | ||
}, | ||
{ | ||
geometry: 'line', | ||
seriesField: 'name', | ||
point: {}, | ||
}, | ||
], | ||
limitInPlot: false, | ||
meta: { | ||
time: { | ||
type: 'time', | ||
sync: false, | ||
}, | ||
}, | ||
slider: { | ||
start: 0, | ||
end: 1, | ||
}, | ||
padding: [20, 40, 60, 40], | ||
}); | ||
|
||
dualAxes.render(); | ||
expect(dualAxes.chart.views[0].getOptions().slider).toEqual({ | ||
start: 0, | ||
end: 1, | ||
}); | ||
expect(dualAxes.chart.getController('slider')).toBeDefined(); | ||
expect(dualAxes.chart.views[0].getController('slider').getComponents().length).toBe(1); | ||
expect(dualAxes.chart.views[1].getController('slider').getComponents().length).toBe(0); | ||
const [slider] = dualAxes.chart.views[0].getComponents().filter((co) => co.type === 'slider'); | ||
expect(slider.component.get('minText')).toBe('2019-03'); | ||
dualAxes.update({ | ||
meta: { | ||
time: { | ||
type: 'timeCat', | ||
sync: false, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(dualAxes.chart.views[0].getOptions().slider).toEqual({ | ||
start: 0, | ||
end: 1, | ||
}); | ||
expect(dualAxes.chart.getController('slider')).toBeDefined(); | ||
dualAxes.changeData([uvBillData.slice(2, 8), transformData.slice(2, 8)]); | ||
const [changedSlider] = dualAxes.chart.views[0].getComponents().filter((co) => co.type === 'slider'); | ||
expect(changedSlider.component.get('minText')).toBe('2019-05'); | ||
dualAxes.update({ | ||
slider: false, | ||
}); | ||
await delay(500); | ||
expect(dualAxes.chart.views[0].getController('slider').getComponents().length).toBe(0); | ||
dualAxes.destroy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { isBetween } from '../../../src/utils'; | ||
|
||
describe('isBetween', () => { | ||
it('isBetween', () => { | ||
expect(isBetween(2, 1, 3)).toBeTruthy(); | ||
expect(isBetween(2, 3, 1)).toBeTruthy(); | ||
expect(isBetween(1, 3, 1)).toBeTruthy(); | ||
expect(isBetween(3, 3, 1)).toBeTruthy(); | ||
expect(isBetween(0, 3, 1)).toBeFalsy(); | ||
expect(isBetween(5, 3, 1)).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { DualAxes } from '@antv/g2plot'; | ||
|
||
const data = [ | ||
{ time: '2020-08-20', consumeTime: 10868, completeTime: 649.483 }, | ||
{ time: '2020-08-21', consumeTime: 8786, completeTime: 1053.7 }, | ||
{ time: '2020-08-22', consumeTime: 10824, completeTime: 679.817 }, | ||
{ time: '2020-08-23', consumeTime: 7860, completeTime: 638.117 }, | ||
{ time: '2020-08-24', consumeTime: 13253, completeTime: 843.3 }, | ||
{ time: '2020-08-25', consumeTime: 17015, completeTime: 1092.983 }, | ||
{ time: '2020-08-26', consumeTime: 19298, completeTime: 1036.317 }, | ||
{ time: '2020-08-27', consumeTime: 13937, completeTime: 1031.9 }, | ||
{ time: '2020-08-28', consumeTime: 11541, completeTime: 803.467 }, | ||
{ time: '2020-08-29', consumeTime: 15244, completeTime: 830.733 }, | ||
{ time: '2020-08-30', consumeTime: 14247, completeTime: 709.867 }, | ||
{ time: '2020-08-31', consumeTime: 9402, completeTime: 665.233 }, | ||
{ time: '2020-09-01', consumeTime: 10440, completeTime: 696.367 }, | ||
{ time: '2020-09-02', consumeTime: 9345, completeTime: 692.867 }, | ||
{ time: '2020-09-03', consumeTime: 18459, completeTime: 936.017 }, | ||
{ time: '2020-09-04', consumeTime: 9763, completeTime: 782.867 }, | ||
{ time: '2020-09-05', consumeTime: 11074, completeTime: 653.8 }, | ||
{ time: '2020-09-06', consumeTime: 11770, completeTime: 856.683 }, | ||
{ time: '2020-09-07', consumeTime: 12206, completeTime: 777.15 }, | ||
{ time: '2020-09-08', consumeTime: 11434, completeTime: 773.283 }, | ||
{ time: '2020-09-09', consumeTime: 16218, completeTime: 833.3 }, | ||
{ time: '2020-09-10', consumeTime: 11914, completeTime: 793.517 }, | ||
{ time: '2020-09-11', consumeTime: 16781, completeTime: 894.45 }, | ||
{ time: '2020-09-12', consumeTime: 10555, completeTime: 725.55 }, | ||
{ time: '2020-09-13', consumeTime: 10899, completeTime: 709.967 }, | ||
{ time: '2020-09-14', consumeTime: 10713, completeTime: 787.6 }, | ||
{ time: '2020-09-15', consumeTime: 0, completeTime: 644.183 }, | ||
{ time: '2020-09-16', consumeTime: 0, completeTime: 1066.65 }, | ||
{ time: '2020-09-17', consumeTime: 20357, completeTime: 932.45 }, | ||
{ time: '2020-09-18', consumeTime: 10424, completeTime: 753.583 }, | ||
]; | ||
|
||
const dualAxes = new DualAxes('container', { | ||
data: [data, data], | ||
xField: 'time', | ||
yField: ['consumeTime', 'completeTime'], | ||
limitInPlot: false, | ||
padding: [10, 20, 80, 30], // 需要设置底部 padding 值,同 css | ||
slider: {}, | ||
meta: { | ||
time: { | ||
sync: false, // 开启之后 slider 无法重绘 | ||
}, | ||
}, | ||
geometryOptions: [ | ||
{ | ||
geometry: 'column', | ||
}, | ||
{ | ||
geometry: 'line', | ||
}, | ||
], | ||
}); | ||
|
||
dualAxes.render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ export const AXIS_META_CONFIG_KEYS = [ | |
'exponent', | ||
// time 类型的格式化 | ||
'mask', | ||
// 是否同步 | ||
'sync', | ||
]; | ||
|
||
/** | ||
|
Oops, something went wrong.