fix
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 18s
Docker Build & Deploy / Deploy to Production (push) Successful in 6s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 18s
Docker Build & Deploy / Deploy to Production (push) Successful in 6s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
This commit is contained in:
@@ -459,24 +459,26 @@ const calculateChartHeight = (budgets) => {
|
|||||||
|
|
||||||
const varianceLabelPlugin = {
|
const varianceLabelPlugin = {
|
||||||
id: 'variance-label-plugin',
|
id: 'variance-label-plugin',
|
||||||
afterDatasetsDraw: (chart) => {
|
afterDraw: (chart) => {
|
||||||
const dataset = chart.data?.datasets?.[0]
|
const dataset = chart.data?.datasets?.[0]
|
||||||
const metaData = dataset?._meta
|
const metaData = dataset?._meta
|
||||||
if (!dataset || !metaData) {
|
if (!dataset || !metaData || !chart.chartArea) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const meta = chart.getDatasetMeta(0)
|
const meta = chart.getDatasetMeta(0)
|
||||||
if (!meta?.data) {
|
if (!meta?.data || meta.data.length === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { ctx, chartArea } = chart
|
const { ctx, chartArea } = chart
|
||||||
const fontFamily = '"PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif'
|
const fontFamily = '"PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif'
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.font = `12px ${fontFamily}`
|
ctx.font = `bold 11px ${fontFamily}`
|
||||||
ctx.textBaseline = 'middle'
|
ctx.textBaseline = 'middle'
|
||||||
|
|
||||||
|
const padding = 6
|
||||||
|
|
||||||
meta.data.forEach((bar, index) => {
|
meta.data.forEach((bar, index) => {
|
||||||
const item = metaData[index]
|
const item = metaData[index]
|
||||||
if (!item || item.value === 0) {
|
if (!item || item.value === 0) {
|
||||||
@@ -485,26 +487,22 @@ const varianceLabelPlugin = {
|
|||||||
|
|
||||||
const label = formatVarianceLabelValue(item.value)
|
const label = formatVarianceLabelValue(item.value)
|
||||||
const textWidth = ctx.measureText(label).width
|
const textWidth = ctx.measureText(label).width
|
||||||
const position = bar.tooltipPosition ? bar.tooltipPosition() : { x: bar.x, y: bar.y }
|
|
||||||
const offset = 8
|
|
||||||
const isPositive = item.value > 0
|
const isPositive = item.value > 0
|
||||||
ctx.fillStyle = getVarianceLabelColor(item.value)
|
const y = bar.y
|
||||||
let x = position.x + (isPositive ? offset : -offset)
|
let x
|
||||||
const y = position.y
|
|
||||||
|
|
||||||
if (chartArea) {
|
if (isPositive) {
|
||||||
const rightLimit = chartArea.right - 4
|
x = Math.max(bar.x, bar.base) + padding
|
||||||
const leftLimit = chartArea.left + 4
|
ctx.textAlign = 'left'
|
||||||
if (isPositive && x + textWidth > rightLimit) {
|
if (x + textWidth > chartArea.right - 4) {
|
||||||
x = rightLimit - textWidth
|
x = chartArea.right - textWidth - 4
|
||||||
}
|
|
||||||
if (!isPositive && x - textWidth < leftLimit) {
|
|
||||||
x = leftLimit + textWidth
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
x = Math.max(bar.base, chartArea.left) + padding
|
||||||
|
ctx.textAlign = 'left'
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.textAlign = isPositive ? 'left' : 'right'
|
ctx.fillStyle = getVarianceLabelColor(item.value)
|
||||||
|
|
||||||
ctx.fillText(label, x, y)
|
ctx.fillText(label, x, y)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user