-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 新增基本直方图 * test: 增加测试用例 1. 增加测试用例 2. 调整引入结构 3. merge了v2最新代码 * feat: 增加基本直方图 1. 引入dataset处理数据 2. 增加更多test测试 * feat: 增加支持层叠直方图 1. 增加层叠(堆叠直方图) 2 .增加测试用例 * feat(v2): 新增层叠直方图和配置 1. 调整之前color的问题 2. 完善直方图 3 .新增test测试用例
- Loading branch information
Showing
9 changed files
with
376 additions
and
42 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,64 @@ | ||
import { Histogram } from '../../../../src'; | ||
import { histogramData } from '../../../data/histogram-data'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('Histogram: axis', () => { | ||
it('xAxis', () => { | ||
const histogram = new Histogram(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
appendPadding: 10, | ||
data: histogramData, | ||
binField: 'value', | ||
binWidth: 2, | ||
meta: { | ||
count: { | ||
min: 0, | ||
max: 20, | ||
}, | ||
}, | ||
xAxis: { | ||
label: { | ||
style: { | ||
fill: 'red', | ||
}, | ||
}, | ||
}, | ||
}); | ||
histogram.render(); | ||
|
||
const geometry = histogram.chart.geometries[0]; | ||
|
||
expect(geometry.scales.count.min).toBe(0); | ||
expect(geometry.scales.count.max).toBe(20); | ||
|
||
// @ts-ignore | ||
expect(histogram.chart.options.axes.range.label.style.fill).toBe('red'); | ||
}); | ||
|
||
it('yAxis', () => { | ||
const histogram = new Histogram(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
appendPadding: 10, | ||
data: histogramData, | ||
binField: 'value', | ||
binWidth: 2, | ||
yAxis: { | ||
nice: true, | ||
label: { | ||
style: { | ||
fill: 'red', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
histogram.render(); | ||
|
||
// @ts-ignore | ||
expect(histogram.chart.options.axes.count.nice).toBe(true); | ||
// @ts-ignore | ||
expect(histogram.chart.options.axes.count.label.style.fill).toBe('red'); | ||
}); | ||
}); |
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,61 @@ | ||
import { Histogram } from '../../../../src'; | ||
import { histogramData } from '../../../data/histogram-data'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('Histogram: label', () => { | ||
const histogram = new Histogram(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
appendPadding: 10, | ||
data: histogramData, | ||
binField: 'value', | ||
binWidth: 2, | ||
}); | ||
|
||
histogram.render(); | ||
|
||
it('position: top', () => { | ||
histogram.update({ | ||
...histogram.options, | ||
label: { | ||
position: 'top', | ||
}, | ||
}); | ||
const geometry = histogram.chart.geometries[0]; | ||
|
||
// @ts-ignore | ||
expect(geometry.labelOption.cfg).toEqual({ | ||
position: 'top', | ||
}); | ||
}); | ||
|
||
it('position: middle', () => { | ||
histogram.update({ | ||
...histogram.options, | ||
label: { | ||
position: 'middle', | ||
}, | ||
}); | ||
const geometry = histogram.chart.geometries[0]; | ||
|
||
// @ts-ignore | ||
expect(geometry.labelOption.cfg).toEqual({ | ||
position: 'middle', | ||
}); | ||
}); | ||
|
||
it('position: bottom', () => { | ||
histogram.update({ | ||
...histogram.options, | ||
label: { | ||
position: 'bottom', | ||
}, | ||
}); | ||
const geometry = histogram.chart.geometries[0]; | ||
|
||
// @ts-ignore | ||
expect(geometry.labelOption.cfg).toEqual({ | ||
position: 'bottom', | ||
}); | ||
}); | ||
}); |
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,50 @@ | ||
import { Histogram } from '../../../../src'; | ||
import { histogramData } from '../../../data/histogram-data'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('Histogram: style', () => { | ||
it('style', () => { | ||
const histogram = new Histogram(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
appendPadding: 10, | ||
data: histogramData, | ||
binField: 'value', | ||
binWidth: 2, | ||
columnStyle: { | ||
stroke: 'black', | ||
lineWidth: 2, | ||
}, | ||
}); | ||
histogram.render(); | ||
|
||
const geometry = histogram.chart.geometries[0]; | ||
const elements = geometry.elements; | ||
expect(elements[0].shape.attr('stroke')).toBe('black'); | ||
expect(elements[0].shape.attr('lineWidth')).toBe(2); | ||
}); | ||
|
||
it('style callback', () => { | ||
const histogram = new Histogram(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
appendPadding: 10, | ||
data: histogramData, | ||
binField: 'value', | ||
binWidth: 2, | ||
columnStyle: (x, y) => { | ||
return { | ||
stroke: 'black', | ||
lineWidth: 2, | ||
}; | ||
}, | ||
}); | ||
|
||
histogram.render(); | ||
|
||
const geometry = histogram.chart.geometries[0]; | ||
const elements = geometry.elements; | ||
expect(elements[0].shape.attr('stroke')).toBe('black'); | ||
expect(elements[0].shape.attr('lineWidth')).toBe(2); | ||
}); | ||
}); |
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,31 @@ | ||
import { Histogram } from '../../../../src'; | ||
import { histogramData } from '../../../data/histogram-data'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('Histogram:tooltip', () => { | ||
const histogram = new Histogram(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
appendPadding: 10, | ||
data: histogramData, | ||
binField: 'value', | ||
binWidth: 2, | ||
tooltip: { | ||
title: 'hello wold!', | ||
}, | ||
}); | ||
|
||
histogram.render(); | ||
|
||
it('tooltip', () => { | ||
// @ts-ignore | ||
expect(histogram.chart.options.tooltip.title).toBe('hello wold!'); | ||
histogram.update({ | ||
...histogram.options, | ||
tooltip: false, | ||
}); | ||
// @ts-ignore | ||
expect(histogram.chart.options.tooltip).toBe(false); | ||
expect(histogram.chart.getComponents().find((co) => co.type === 'tooltip')).toBe(undefined); | ||
}); | ||
}); |
Oops, something went wrong.