Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gauge): 仪表盘支持自定义指示器 indicator (#2892)
* feat(gauge): 仪表盘支持自定义指针 * docs(gauge): 添加自定义仪表盘指示器的文档 & demo * docs(gauge): 丰富自定义仪表盘指示器 demo
- Loading branch information
Showing
16 changed files
with
274 additions
and
17 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
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,4 @@ | ||
--- | ||
title: Label | ||
order: 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,4 @@ | ||
--- | ||
title: 数据标签 - Label | ||
order: 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 |
---|---|---|
@@ -1 +1 @@ | ||
`markdown:docs/api/plots/gauge.en.md` | ||
`markdown:docs/api/plots/gauge.en.md` |
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,57 @@ | ||
import { Gauge, G2 } from '@antv/g2plot'; | ||
|
||
const { registerShape, Util } = G2; | ||
|
||
// 自定义 Shape 部分 | ||
registerShape('point', 'custom-gauge-indicator', { | ||
draw(cfg, container) { | ||
// 使用 customInfo 传递参数 | ||
const { indicator, defaultColor } = cfg.customInfo; | ||
const { pointer } = indicator; | ||
|
||
const group = container.addGroup(); | ||
// 获取极坐标系下画布中心点 | ||
const center = this.parsePoint({ x: 0, y: 0 }); | ||
// 绘制指针 | ||
if (pointer) { | ||
const { startAngle, endAngle } = Util.getAngle(cfg, this.coordinate); | ||
const radius = this.coordinate.getRadius(); | ||
const midAngle = (startAngle + endAngle) / 2; | ||
const { x: x1, y: y1 } = Util.polarToCartesian(center.x, center.y, radius / 15, midAngle + 1 / Math.PI); | ||
const { x: x2, y: y2 } = Util.polarToCartesian(center.x, center.y, radius / 15, midAngle - 1 / Math.PI); | ||
const { x, y } = Util.polarToCartesian(center.x, center.y, radius * 0.65, midAngle); | ||
|
||
const path = [['M', center.x, center.y], ['L', x1, y1], ['L', x, y], ['L', x2, y2], ['Z']]; | ||
// pointer | ||
group.addShape('path', { | ||
name: 'pointer', | ||
attrs: { | ||
path, | ||
fill: defaultColor, | ||
...pointer.style, | ||
}, | ||
}); | ||
} | ||
|
||
return group; | ||
}, | ||
}); | ||
|
||
const gauge = new Gauge('container', { | ||
percent: 0.78, | ||
range: { | ||
color: '#30BF78', | ||
}, | ||
indicator: { | ||
shape: 'custom-gauge-indicator', | ||
pointer: { | ||
style: { | ||
stroke: '#D0D0D0', | ||
lineWidth: 1, | ||
fill: '#D0D0D0', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
gauge.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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Gauge, G2 } from '@antv/g2plot'; | ||
|
||
const { registerShape, Util } = G2; | ||
|
||
// 自定义 Shape 部分 | ||
registerShape('point', 'custom-gauge-indicator2', { | ||
draw(cfg, container) { | ||
// 使用 customInfo 传递参数 | ||
const { indicator, defaultColor } = cfg.customInfo; | ||
const { pointer, pin } = indicator; | ||
|
||
const group = container.addGroup(); | ||
// 获取极坐标系下画布中心点 | ||
const center = this.parsePoint({ x: 0, y: 0 }); | ||
// 绘制指针 | ||
if (pointer) { | ||
const { startAngle, endAngle } = Util.getAngle(cfg, this.coordinate); | ||
const radius = this.coordinate.getRadius(); | ||
const midAngle = (startAngle + endAngle) / 2; | ||
const { x: x1, y: y1 } = Util.polarToCartesian(center.x, center.y, radius / 15, midAngle + 1 / Math.PI); | ||
const { x: x2, y: y2 } = Util.polarToCartesian(center.x, center.y, radius / 15, midAngle - 1 / Math.PI); | ||
const { x, y } = Util.polarToCartesian(center.x, center.y, radius * 0.65, midAngle); | ||
const { x: x0, y: y0 } = Util.polarToCartesian(center.x, center.y, radius * 0.1, midAngle + Math.PI); | ||
|
||
const path = [['M', x0, y0], ['L', x1, y1], ['L', x, y], ['L', x2, y2], ['Z']]; | ||
// pointer | ||
group.addShape('path', { | ||
name: 'pointer', | ||
attrs: { | ||
path, | ||
fill: defaultColor, | ||
...pointer.style, | ||
}, | ||
}); | ||
} | ||
|
||
if (pin) { | ||
const pinStyle = pin.style || {}; | ||
const { lineWidth = 2, fill = defaultColor, stroke = defaultColor } = pinStyle; | ||
const r = 6; | ||
group.addShape('circle', { | ||
name: 'pin-outer', | ||
attrs: { | ||
x: center.x, | ||
y: center.y, | ||
...pin.style, | ||
fill: 'transparent', | ||
r: r * 1.5, | ||
lineWidth, | ||
stroke: stroke, | ||
}, | ||
}); | ||
|
||
group.addShape('circle', { | ||
name: 'pin-inner', | ||
attrs: { | ||
x: center.x, | ||
y: center.y, | ||
r, | ||
stroke: 'transparent', | ||
fill, | ||
}, | ||
}); | ||
} | ||
|
||
return group; | ||
}, | ||
}); | ||
|
||
const gauge = new Gauge('container', { | ||
percent: 0.78, | ||
range: { | ||
color: '#30BF78', | ||
}, | ||
indicator: { | ||
shape: 'custom-gauge-indicator2', | ||
pointer: { | ||
style: { | ||
stroke: '#D0D0D0', | ||
lineWidth: 1, | ||
fill: '#D0D0D0', | ||
}, | ||
}, | ||
pin: { | ||
style: { | ||
lineWidth: 2, | ||
stroke: '#D0D0D0', | ||
fill: '#D0D0D0', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
gauge.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
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,57 @@ | ||
import { Gauge, G2 } from '@antv/g2plot'; | ||
|
||
const { registerShape, Util } = G2; | ||
|
||
// 自定义 Shape 部分 | ||
registerShape('point', 'triangle-gauge-indicator', { | ||
draw(cfg, container) { | ||
// 使用 customInfo 传递参数 | ||
const { indicator, defaultColor } = cfg.customInfo; | ||
const { pointer } = indicator; | ||
|
||
const group = container.addGroup(); | ||
|
||
// 获取极坐标系下画布中心点 | ||
const center = this.parsePoint({ x: 0, y: 0 }); | ||
// 绘制指针 | ||
if (pointer) { | ||
const { startAngle, endAngle } = Util.getAngle(cfg, this.coordinate); | ||
const radius = this.coordinate.getRadius(); | ||
const midAngle = (startAngle + endAngle) / 2; | ||
|
||
const { x: x1, y: y1 } = Util.polarToCartesian(center.x, center.y, radius * 0.52, midAngle + Math.PI / 30); | ||
const { x: x2, y: y2 } = Util.polarToCartesian(center.x, center.y, radius * 0.52, midAngle - Math.PI / 30); | ||
const { x, y } = Util.polarToCartesian(center.x, center.y, radius * 0.6, midAngle); | ||
|
||
const path = [['M', x1, y1], ['L', x, y], ['L', x2, y2], ['Z']]; | ||
// pointer | ||
group.addShape('path', { | ||
name: 'pointer', | ||
attrs: { | ||
path, | ||
fill: defaultColor, | ||
...pointer.style, | ||
}, | ||
}); | ||
} | ||
|
||
return group; | ||
}, | ||
}); | ||
|
||
const gauge = new Gauge('container', { | ||
percent: 0.48, | ||
range: { | ||
color: '#30BF78', | ||
}, | ||
indicator: { | ||
shape: 'triangle-gauge-indicator', | ||
pointer: { | ||
style: { | ||
fill: '#30BF78', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
gauge.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
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
File renamed without changes.
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