(baseOptions, axis, data)
| 1 | const { checkIsPercent, formatNumber, getAxesWithFilter } = require('./utils') |
| 2 | |
| 3 | function 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 | |
| 56 | module.exports = { getPieOptions } |
no test coverage detected