MCPcopy Create free account
hub / github.com/dataease/SQLBot / getPieOptions

Function getPieOptions

g2-ssr/charts/pie.js:3–54  ·  view source on GitHub ↗
(baseOptions, axis, data)

Source from the content-addressed store, hash-verified

1const { checkIsPercent, formatNumber, getAxesWithFilter } = require('./utils')
2
3function getPieOptions(baseOptions, axis, data) {
4
5 const { y, series } = getAxesWithFilter(axis)
6
7 if (series.length === 0 || y.length === 0) {
8 return
9 }
10
11 const _data = checkIsPercent(y, data)
12
13 return {
14 ...baseOptions,
15 type: 'interval',
16 coordinate: { type: 'theta', outerRadius: 0.8 },
17 transform: [{ type: 'stackY' }],
18 data: _data.data,
19 encode: {
20 y: y[0].value,
21 color: series[0].value,
22 },
23 scale: {
24 x: {
25 nice: true,
26 },
27 y: {
28 type: 'linear',
29 },
30 },
31 legend: {
32 color: { position: 'bottom', layout: { justifyContent: 'center' } },
33 },
34 labels: [
35 {
36 position: 'spider',
37 text: (data) =>
38 `${data[series[0].value]}: ${formatNumber(data[y[0].value])}${_data.isPercent ? '%' : ''}`,
39 },
40 ],
41 tooltip: {
42 title: (data) => data[series[0].value],
43 items: [
44 (data) => {
45 return {
46 name: y[0].name,
47 value: `${formatNumber(data[y[0].value])}${_data.isPercent ? '%' : ''}`,
48 }
49 },
50 ],
51 },
52 }
53
54}
55
56module.exports = { getPieOptions }

Callers 1

getOptionsFunction · 0.85

Calls 3

getAxesWithFilterFunction · 0.70
checkIsPercentFunction · 0.70
formatNumberFunction · 0.70

Tested by

no test coverage detected