-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(line): add style, tooltip options
- Loading branch information
Showing
7 changed files
with
159 additions
and
60 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,63 @@ | ||
import { Line } from '../../../../src'; | ||
import { partySupport } from '../../../data/party-support'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('line', () => { | ||
it('x*y and style', () => { | ||
const line = new Line(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: partySupport.filter((o) => ['FF'].includes(o.type)), | ||
xField: 'date', | ||
yField: 'value', | ||
lineStyle: { | ||
lineDash: [2, 2], | ||
}, | ||
appendPadding: 10, | ||
}); | ||
|
||
line.render(); | ||
|
||
const geometry = line.chart.geometries[0]; | ||
const elements = geometry.elements; | ||
expect(elements[0].shape.attr('lineDash')).toEqual([2, 2]); | ||
|
||
line.update({ | ||
...line.options, | ||
lineStyle: (color: string) => { | ||
return { lineDash: [4, 4] }; | ||
}, | ||
}); | ||
expect(line.chart.geometries[0].elements[0].shape.attr('lineDash')).toEqual([4, 4]); | ||
}); | ||
|
||
it('x*y*color and style', () => { | ||
const line = new Line(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: partySupport.filter((o) => ['FF', 'Lab'].includes(o.type)), | ||
xField: 'date', | ||
yField: 'value', | ||
seriesField: 'type', | ||
lineStyle: { | ||
lineDash: [2, 2], | ||
}, | ||
appendPadding: 10, | ||
}); | ||
|
||
line.render(); | ||
|
||
const geometry = line.chart.geometries[0]; | ||
const elements = geometry.elements; | ||
expect(elements[0].shape.attr('lineDash')).toEqual([2, 2]); | ||
|
||
line.update({ | ||
...line.options, | ||
lineStyle: (color: string) => { | ||
if (color === 'FF') return { lineDash: [4, 4] }; | ||
}, | ||
}); | ||
expect(line.chart.geometries[0].elements[0].shape.attr('lineDash')).toEqual([4, 4]); | ||
expect(line.chart.geometries[0].elements[1].shape.attr('lineDash')).toEqual(undefined); | ||
}); | ||
}); |
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,53 @@ | ||
import { Line } from '../../../../src'; | ||
import { partySupport } from '../../../data/party-support'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('line', () => { | ||
it('x*y and tooltip', () => { | ||
const line = new Line(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: partySupport.filter((o) => ['FF'].includes(o.type)), | ||
xField: 'date', | ||
yField: 'value', | ||
appendPadding: 10, | ||
tooltip: { | ||
title: 'hello wold', | ||
}, | ||
}); | ||
|
||
line.render(); | ||
// @ts-ignore | ||
expect(line.chart.options.tooltip.title).toBe('hello wold'); | ||
|
||
line.update({ | ||
...line.options, | ||
tooltip: false, | ||
}); | ||
// @ts-ignore | ||
expect(line.chart.options.tooltip).toBe(false); | ||
expect(line.chart.getComponents().find((co) => co.type === 'tooltip')).toBe(undefined); | ||
}); | ||
|
||
it('x*y*color and toolip', () => { | ||
const line = new Line(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: partySupport.filter((o) => ['FF', 'Lab'].includes(o.type)), | ||
xField: 'date', | ||
yField: 'value', | ||
seriesField: 'type', | ||
appendPadding: 10, | ||
tooltip: { | ||
shared: true, | ||
showCrosshairs: true, | ||
}, | ||
}); | ||
|
||
line.render(); | ||
// @ts-ignore | ||
expect(line.chart.options.tooltip.shared).toBe(true); | ||
// @ts-ignore | ||
expect(line.chart.options.tooltip.showCrosshairs).toBe(true); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
/** G shape style 配置, 按道理应该从 G 中引入 */ | ||
export type ShapeStyle = Readonly<{ | ||
fill?: string; | ||
stroke?: string; | ||
lineWidth?: number; | ||
lineDash?: number[]; | ||
opacity?: number; | ||
fillOpacity?: number; | ||
strokeOpacity?: number; | ||
readonly fill?: string; | ||
readonly stroke?: string; | ||
readonly lineWidth?: number; | ||
readonly lineDash?: number[]; | ||
readonly opacity?: number; | ||
readonly fillOpacity?: number; | ||
readonly strokeOpacity?: number; | ||
}>; |
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 |
---|---|---|
@@ -1,43 +1,3 @@ | ||
export type Tooltip = { | ||
/** 是否展示 */ | ||
visible?: boolean; | ||
import { TooltipOption } from '@antv/g2/lib/interface'; | ||
|
||
/** 设置 tooltip 内容字段,默认为[ xField, yField, colorField] */ | ||
fields?: string[]; | ||
|
||
/** 是否跟随 */ | ||
shared?: boolean; | ||
|
||
/** 是否 title */ | ||
showTitle?: boolean; | ||
|
||
/** 是否展示 */ | ||
titleField?: string; | ||
|
||
/** 是否展示十字辅助线 */ | ||
showCrosshairs?: boolean; | ||
|
||
/** 十字辅助线 */ | ||
crosshairs?: object; | ||
|
||
/** 距离鼠标位置偏移值 */ | ||
offset?: number; | ||
|
||
/** 是否展示 markers */ | ||
showMarkers?: boolean; | ||
|
||
/** 配置 tooltip 样式 */ | ||
domStyles?: { | ||
'g2-tooltip'?: any; | ||
'g2-tooltip-title'?: any; | ||
'g2-tooltip-list'?: any; | ||
'g2-tooltip-marker'?: any; | ||
'g2-tooltip-value'?: any; | ||
}; | ||
|
||
/** 是否展示 */ | ||
follow?: boolean; | ||
|
||
/** 自定义 */ | ||
htmlContent?: (...args: any[]) => string; | ||
}; | ||
export type Tooltip = TooltipOption; |