Skip to content

Commit

Permalink
Feature/number chart (#13)
Browse files Browse the repository at this point in the history
* fix: fix pie's precision error

* chore: release to 1.1.17
  • Loading branch information
ranglang committed Sep 6, 2023
1 parent f749014 commit 2bed021
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.18",
"version": "1.1.19",
"description": "my apitable widget chart",
"engines": {
"node": ">=8.x"
Expand Down
13 changes: 7 additions & 6 deletions src/model/echarts_pie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { EchartsBase } from './echarts_base';
import { ChartType, StackType } from './interface';
import { Strings, t } from '../i18n';
import { sortBy } from '../sortBy';
import { maxRenderNum, processChartData, processRecords } from '../helper';
import { METRICS_TYPES } from '../const';
import { getNumberBaseFieldPrecision, maxRenderNum, processChartData, processRecords } from '../helper';

export class EchartsPie extends EchartsBase {
type = ChartType.EchartsPie;
Expand Down Expand Up @@ -70,6 +69,8 @@ export class EchartsPie extends EchartsBase {
const { showDataTips } = chartStyle;
const color = { color: this.theme === 'dark' ? '#fff' : '#333' };

const fieldPrecision = getNumberBaseFieldPrecision(metricsField);

// Distinguish between normal configuration and series configuration.
const dataSum = data.reduce((pre, cur) => pre = this.add(pre, cur.value), 0);
// const dataSum = data.reduce((pre, cur) => pre += cur.value, 0);
Expand Down Expand Up @@ -107,7 +108,7 @@ export class EchartsPie extends EchartsBase {
// const totalContent = Math.round(params.value / (params.percent / 100));
// console.log(totalContent, params.value / (params.percent / 100));
// return `{a|${t(Strings.total)}}\n{b|${totalContent}}`;
return `{a|${t(Strings.total)}}\n{b|${dataSum}}`;
return `{a|${t(Strings.total)}}\n{b|${dataSum.toFixed(fieldPrecision)}}`;
},
// formatter: () => {
// const precision = guessNumberFieldPrecision(data.map(item => item.value).filter(Boolean));
Expand Down Expand Up @@ -144,15 +145,15 @@ export class EchartsPie extends EchartsBase {
* @param {Object} param Configuration parameter objects.
* @property {Record[]} param.records
* @property {Field[]} param.fields
* @property {} param.chartStructure
* @property {} param.chartStructure
*/
getChartOptions({ records, fields, chartStructure, chartStyle }: {
records: Record[];
fields: Field[];
chartStructure: any,
chartStyle: any,
}) {
// Statistic field id, type of statistic specified field (sum, average),
// Statistic field id, type of statistic specified field (sum, average),
// type of statistic value, whether to cut multi-selected values, date formatting.
const { dimension, metrics, metricsType, isSplitMultipleValue, isFormatDatetime: _isFormatDatetime, datetimeFormatter } = chartStructure;
const { isCountNullValue } = chartStyle;
Expand Down Expand Up @@ -209,4 +210,4 @@ export class EchartsPie extends EchartsBase {
}
return options;
}
}
}

0 comments on commit 2bed021

Please sign in to comment.