From e0239151f6e05b7de8bf93942015ea3d74ff1a3a Mon Sep 17 00:00:00 2001 From: inter Date: Mon, 8 Sep 2025 16:35:28 +0800 Subject: [PATCH] Add File --- g2-ssr/charts/pie.js | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 g2-ssr/charts/pie.js diff --git a/g2-ssr/charts/pie.js b/g2-ssr/charts/pie.js new file mode 100644 index 0000000..eb52534 --- /dev/null +++ b/g2-ssr/charts/pie.js @@ -0,0 +1,53 @@ +const {checkIsPercent} = require("./utils"); + +function getPieOptions(baseOptions, axis, data) { + + const y = axis.filter((item) => item.type === 'y') + const series = axis.filter((item) => item.type === 'series') + + if (series.length === 0 || y.length === 0) { + return + } + + const _data = checkIsPercent(y[0], data) + + return { + ...baseOptions, + type: 'interval', + coordinate: {type: 'theta', outerRadius: 0.8}, + transform: [{type: 'stackY'}], + data: _data.data, + encode: { + y: y[0].value, + color: series[0].value, + }, + legend: { + color: {position: 'bottom', layout: {justifyContent: 'center'}}, + }, + labels: [ + { + position: 'outside', + text: (data) => + `${data[series[0].value]}: ${data[y[0].value]}${_data.isPercent ? '%' : ''}`, + transform: [ + { type: 'exceedAdjust' }, + { type: 'overlapHide' }, + ], + }, + ], + tooltip: { + title: (data) => data[series[0].value], + items: [ + (data) => { + return { + name: y[0].name, + value: `${data[y[0].value]}${_data.isPercent ? '%' : ''}`, + } + }, + ], + }, + } + +} + +module.exports = {getPieOptions}