-
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.
* test: 添加双轴图的单测和文档,并修改贴图的默认值 * docs: 添加pattern精选案例 * docs: 修改pattern的文档 Co-authored-by: 酥云 <lisuwen.lsw@antgroup.com>
- Loading branch information
Showing
28 changed files
with
1,046 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { DualAxes } from '../../../../src'; | ||
import { PV_DATA, UV_DATA } from '../../../data/pv-uv'; | ||
import { createDiv } from '../../../utils/dom'; | ||
import { MultipleData } from '../../../data/common'; | ||
|
||
describe('dual-axes: pattern', () => { | ||
it('column pattern: obj', () => { | ||
const dualAxes = new DualAxes(createDiv(), { | ||
width: 400, | ||
height: 500, | ||
data: [PV_DATA, UV_DATA], | ||
xField: 'date', | ||
yField: ['pv', 'uv'], | ||
geometryOptions: [ | ||
{ | ||
geometry: 'column', | ||
pattern: { | ||
type: 'dot', | ||
}, | ||
}, | ||
{ | ||
geometry: 'line', | ||
}, | ||
], | ||
}); | ||
|
||
dualAxes.render(); | ||
|
||
const [leftView] = dualAxes.chart.views; | ||
expect(leftView.geometries[0].elements[0].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
expect(leftView.geometries[0].elements[1].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
expect(leftView.geometries[0].elements[2].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
|
||
dualAxes.destroy(); | ||
}); | ||
|
||
it('column pattern: callback', () => { | ||
const dualAxes = new DualAxes(createDiv(), { | ||
width: 400, | ||
height: 500, | ||
data: [PV_DATA, UV_DATA], | ||
xField: 'date', | ||
yField: ['pv', 'uv'], | ||
geometryOptions: [ | ||
{ | ||
geometry: 'column', | ||
pattern: ({ pv }) => { | ||
if (pv > 630000) { | ||
return { type: 'line' }; | ||
} | ||
}, | ||
}, | ||
{ | ||
geometry: 'line', | ||
}, | ||
], | ||
}); | ||
|
||
dualAxes.render(); | ||
|
||
const [leftView] = dualAxes.chart.views; | ||
expect(leftView.geometries[0].elements[3].shape.attr('fill') instanceof CanvasPattern).toEqual(false); | ||
expect(leftView.geometries[0].elements[4].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
expect(leftView.geometries[0].elements[5].shape.attr('fill') instanceof CanvasPattern).toEqual(false); | ||
|
||
dualAxes.destroy(); | ||
}); | ||
|
||
it('stack column pattern: obj', () => { | ||
const dualAxes = new DualAxes(createDiv('stack column and stack line'), { | ||
height: 500, | ||
data: [MultipleData, MultipleData], | ||
xField: 'month', | ||
yField: ['value', 'value'], | ||
geometryOptions: [ | ||
{ | ||
geometry: 'column', | ||
isGroup: true, | ||
isStack: true, | ||
seriesField: 'type', | ||
groupField: 'name', | ||
pattern: { | ||
type: 'line', | ||
}, | ||
}, | ||
{ | ||
geometry: 'line', | ||
seriesField: 'type', | ||
smooth: true, | ||
isGroup: true, | ||
isStack: true, | ||
groupField: 'name', | ||
}, | ||
], | ||
tooltip: false, | ||
}); | ||
|
||
dualAxes.render(); | ||
|
||
const [leftView] = dualAxes.chart.views; | ||
expect(leftView.geometries[0].elements[0].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
expect(leftView.geometries[0].elements[1].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
expect(leftView.geometries[0].elements[2].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
|
||
dualAxes.destroy(); | ||
}); | ||
|
||
it('stack column pattern: callback', () => { | ||
const dualAxes = new DualAxes(createDiv('stack column and stack line'), { | ||
height: 500, | ||
data: [MultipleData, MultipleData], | ||
xField: 'month', | ||
yField: ['value', 'value'], | ||
geometryOptions: [ | ||
{ | ||
geometry: 'column', | ||
isGroup: true, | ||
isStack: true, | ||
seriesField: 'type', | ||
groupField: 'name', | ||
pattern: ({ type }) => { | ||
if (type === '语文') { | ||
return { | ||
type: 'line', | ||
}; | ||
} | ||
}, | ||
}, | ||
{ | ||
geometry: 'line', | ||
seriesField: 'type', | ||
smooth: true, | ||
isGroup: true, | ||
isStack: true, | ||
groupField: 'name', | ||
}, | ||
], | ||
tooltip: false, | ||
}); | ||
|
||
dualAxes.render(); | ||
|
||
const [leftView] = dualAxes.chart.views; | ||
expect(leftView.geometries[0].elements[0].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
expect(leftView.geometries[0].elements[1].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
expect(leftView.geometries[0].elements[2].shape.attr('fill') instanceof CanvasPattern).toEqual(true); | ||
expect(leftView.geometries[0].elements[3].shape.attr('fill') instanceof CanvasPattern).toEqual(false); | ||
expect(leftView.geometries[0].elements[4].shape.attr('fill') instanceof CanvasPattern).toEqual(false); | ||
|
||
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
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
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,81 @@ | ||
import { Area } from '@antv/g2plot'; | ||
|
||
const data = [ | ||
{ country: 'Asia', year: '1750', value: 502 }, | ||
{ country: 'Asia', year: '1800', value: 635 }, | ||
{ country: 'Asia', year: '1850', value: 809 }, | ||
{ country: 'Asia', year: '1900', value: 5268 }, | ||
{ country: 'Asia', year: '1950', value: 4400 }, | ||
{ country: 'Asia', year: '1999', value: 3634 }, | ||
{ country: 'Asia', year: '2050', value: 947 }, | ||
{ country: 'Africa', year: '1750', value: 106 }, | ||
{ country: 'Africa', year: '1800', value: 107 }, | ||
{ country: 'Africa', year: '1850', value: 111 }, | ||
{ country: 'Africa', year: '1900', value: 1766 }, | ||
{ country: 'Africa', year: '1950', value: 221 }, | ||
{ country: 'Africa', year: '1999', value: 767 }, | ||
{ country: 'Africa', year: '2050', value: 133 }, | ||
{ country: 'Europe', year: '1750', value: 163 }, | ||
{ country: 'Europe', year: '1800', value: 203 }, | ||
{ country: 'Europe', year: '1850', value: 276 }, | ||
{ country: 'Europe', year: '1900', value: 628 }, | ||
{ country: 'Europe', year: '1950', value: 547 }, | ||
{ country: 'Europe', year: '1999', value: 729 }, | ||
{ country: 'Europe', year: '2050', value: 408 }, | ||
{ country: 'Oceania', year: '1750', value: 200 }, | ||
{ country: 'Oceania', year: '1800', value: 200 }, | ||
{ country: 'Oceania', year: '1850', value: 200 }, | ||
{ country: 'Oceania', year: '1900', value: 460 }, | ||
{ country: 'Oceania', year: '1950', value: 230 }, | ||
{ country: 'Oceania', year: '1999', value: 300 }, | ||
{ country: 'Oceania', year: '2050', value: 300 }, | ||
]; | ||
|
||
const pattern = ({ country }) => { | ||
if (country === 'Asia') { | ||
return { | ||
type: 'line', | ||
cfg: { | ||
lineWidth: 10, | ||
strokeOpacity: 0.6, | ||
}, | ||
}; | ||
} else if (country === 'Europe') { | ||
return { | ||
type: 'dot', | ||
cfg: { | ||
size: 10, | ||
padding: 5, | ||
fill: '#fff', | ||
fillOpacity: 0.8, | ||
}, | ||
}; | ||
} | ||
}; | ||
|
||
const area = new Area('container', { | ||
data, | ||
xField: 'year', | ||
yField: 'value', | ||
seriesField: 'country', | ||
color: ['#82d1de', '#cb302d', '#e3ca8c'], | ||
areaStyle: { | ||
fillOpacity: 0.7, | ||
}, | ||
meta: { | ||
year: { | ||
nice: true, | ||
range: [0, 1], | ||
}, | ||
}, | ||
smooth: true, | ||
yAxis: { | ||
label: { | ||
formatter: (value) => { | ||
return value * 100; | ||
}, | ||
}, | ||
}, | ||
pattern, | ||
}); | ||
area.render(); |
Oops, something went wrong.