-
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.
- Loading branch information
Showing
14 changed files
with
291 additions
and
6 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,68 @@ | ||
import { Gauge } from '@antv/g2plot'; | ||
|
||
const ticks = [0, 1 / 3, 2 / 3, 1]; | ||
const color = ['#F4664A', '#FAAD14', '#30BF78']; | ||
const gauge = new Gauge('container', { | ||
percent: 0, | ||
innerRadius: 0.75, | ||
type: 'meter', | ||
// 自定义 meter 总步数 以及 step 占比 | ||
meter: { | ||
steps: 50, | ||
stepRatio: 0.6, | ||
}, | ||
range: { | ||
ticks: [0, 1], | ||
color: ['l(0) 0:#F4664A 0.5:#FAAD14 1:#30BF78'], | ||
}, | ||
indicator: { | ||
pointer: { | ||
style: { | ||
stroke: '#D0D0D0', | ||
}, | ||
}, | ||
pin: { | ||
style: { | ||
stroke: '#D0D0D0', | ||
}, | ||
}, | ||
}, | ||
statistic: { | ||
title: { | ||
formatter: ({ percent }) => { | ||
if (percent < ticks[1]) { | ||
return '差'; | ||
} | ||
if (percent < ticks[2]) { | ||
return '中'; | ||
} | ||
return '优'; | ||
}, | ||
style: ({ percent }) => { | ||
return { | ||
fontSize: '36px', | ||
lineHeight: 1, | ||
color: percent < ticks[1] ? color[0] : percent < ticks[2] ? color[1] : color[2], | ||
}; | ||
}, | ||
}, | ||
content: { | ||
offsetY: 36, | ||
style: { | ||
fontSize: '24px', | ||
color: '#4B535E', | ||
}, | ||
formatter: () => '系统表现', | ||
}, | ||
}, | ||
}); | ||
|
||
gauge.render(); | ||
let data = 0.7; | ||
const interval = setInterval(() => { | ||
if (data >= 1.5) { | ||
clearInterval(interval); | ||
} | ||
data += 0.005; | ||
gauge.changeData(data > 1 ? data - 1 : data); | ||
}, 100); |
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,33 @@ | ||
import { Gauge } from '@antv/g2plot'; | ||
|
||
const gauge = new Gauge('container', { | ||
percent: 0.75, | ||
type: 'meter', | ||
innerRadius: 0.75, | ||
range: { | ||
ticks: [0, 1 / 3, 2 / 3, 1], | ||
color: ['#F4664A', '#FAAD14', '#30BF78'], | ||
}, | ||
indicator: { | ||
pointer: { | ||
style: { | ||
stroke: '#D0D0D0', | ||
}, | ||
}, | ||
pin: { | ||
style: { | ||
stroke: '#D0D0D0', | ||
}, | ||
}, | ||
}, | ||
statistic: { | ||
content: { | ||
style: { | ||
fontSize: '36px', | ||
lineHeight: '36px', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
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
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,60 @@ | ||
import { registerShape, Types, Util } from '@antv/g2'; | ||
import { getSectorPath } from '@antv/g2/lib/util/graphics'; | ||
|
||
// 自定义Shape 部分 | ||
registerShape('interval', 'meter-gauge', { | ||
draw(cfg: Types.ShapeInfo, container) { | ||
// 使用 customInfo 传递参数 | ||
const { steps: STEP = 50, stepRatio = 0.5 } = cfg.customInfo; | ||
|
||
const total = this.coordinate.endAngle - this.coordinate.startAngle; | ||
let interval = total / STEP; | ||
let gap = 0; | ||
|
||
/** | ||
* 1: interval : gap = stepRatio : (1 - stepRatio) | ||
* 2: interval * STEP + stepRatio * (STEP - 1) = total | ||
*/ | ||
if (stepRatio >= 0 && stepRatio < 1) { | ||
interval = total / (((1 - stepRatio) / stepRatio) * (STEP - 1) + STEP); | ||
gap = (interval * (1 - stepRatio)) / stepRatio; | ||
} | ||
|
||
const group = container.addGroup(); | ||
// 绘制 gap | ||
if (gap > 0) { | ||
const center = this.coordinate.getCenter(); | ||
const radius = this.coordinate.getRadius(); | ||
const { startAngle, endAngle } = Util.getAngle(cfg, this.coordinate); | ||
for (let i = startAngle, j = 0; i < endAngle; j++) { | ||
if (j % 2) { | ||
const path = getSectorPath( | ||
center.x, | ||
center.y, | ||
radius, | ||
i, | ||
Math.min(i + gap, endAngle), | ||
radius * this.coordinate.innerRadius | ||
); | ||
group.addShape('path', { | ||
name: 'meter-gauge-mask', | ||
attrs: { | ||
path, | ||
fill: cfg.color, | ||
stroke: cfg.color, | ||
lineWidth: 0.5, | ||
}, | ||
// mask 不需要捕捉事件 | ||
capture: false, | ||
}); | ||
|
||
i += gap; | ||
} else { | ||
i += interval; | ||
} | ||
} | ||
} | ||
|
||
return group; | ||
}, | ||
}); |
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