awing-library 2.1.2-stable.40 → 2.1.2-stable.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../../src/AWING/Chart/BarLine/component.tsx"],"names":[],"mappings":"AAwBA,OAAO,wBAAwB,CAAC;AAOhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAmB7C,QAAA,MAAM,gBAAgB,UAAW,iBAAiB,4CAqUjD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../../src/AWING/Chart/BarLine/component.tsx"],"names":[],"mappings":"AAwBA,OAAO,wBAAwB,CAAC;AAOhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAmB7C,QAAA,MAAM,gBAAgB,UAAW,iBAAiB,4CAiVjD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -9,7 +9,7 @@ import { alpha, styled } from "@mui/material/styles";
9
9
  import { BarController, BarElement, CategoryScale, Chart, Legend, LineController, LineElement, LinearScale, PointElement, TimeScale, Tooltip } from "chart.js";
10
10
  import "chartjs-adapter-moment";
11
11
  import { updateObjectFields } from "../../../Helpers/collection.js";
12
- import { roundDecimalNumber } from "../../../Helpers/number.js";
12
+ import { formatNumberByLocale, roundDecimalNumber } from "../../../Helpers/number.js";
13
13
  import { useRef, useState } from "react";
14
14
  import { Chart as external_react_chartjs_2_Chart } from "react-chartjs-2";
15
15
  import { useTranslation } from "react-i18next";
@@ -21,7 +21,7 @@ import { exportToExcel, exportToPDF, exportToPNG, labelCallback, titleCallback }
21
21
  Chart.register(LinearScale, CategoryScale, BarElement, PointElement, LineElement, Legend, Tooltip, LineController, BarController, TimeScale);
22
22
  const BarLineComponent = (props)=>{
23
23
  const { optionsDefault, dataExportExcel } = props;
24
- const { t } = useTranslation();
24
+ const { t, i18n } = useTranslation();
25
25
  const chartRef = useRef(null);
26
26
  const containerRef = useRef(null);
27
27
  const [anchorEl, setAnchorEl] = useState(null);
@@ -33,6 +33,7 @@ const BarLineComponent = (props)=>{
33
33
  setAnchorEl(null);
34
34
  };
35
35
  const titleCallbackBound = (tooltipItems)=>titleCallback(tooltipItems, t);
36
+ const labelCallbackBound = (tooltipItem)=>labelCallback(tooltipItem, (n)=>formatNumberByLocale(n, i18n.language));
36
37
  const { width = 'auto', height = 350, timeline = TimelineType.Day, optionCustom = {}, dataChart, type, enableExport = {
37
38
  png: true,
38
39
  pdf: true,
@@ -56,7 +57,7 @@ const BarLineComponent = (props)=>{
56
57
  bodySpacing: 8,
57
58
  callbacks: {
58
59
  title: titleCallbackBound,
59
- label: labelCallback
60
+ label: labelCallbackBound
60
61
  },
61
62
  titleColor: '#212121',
62
63
  bodyFont: {
@@ -125,7 +126,7 @@ const BarLineComponent = (props)=>{
125
126
  stepSize: 10,
126
127
  maxTicksLimit: 6,
127
128
  callback (tickValue) {
128
- return roundDecimalNumber(tickValue);
129
+ return formatNumberByLocale(Number(tickValue));
129
130
  }
130
131
  },
131
132
  title: {
@@ -147,7 +148,10 @@ const BarLineComponent = (props)=>{
147
148
  },
148
149
  ticks: {
149
150
  minRotation: 0,
150
- maxTicksLimit: 6
151
+ maxTicksLimit: 6,
152
+ callback (tickValue) {
153
+ return roundDecimalNumber(Number(tickValue));
154
+ }
151
155
  },
152
156
  title: {
153
157
  display: true,
@@ -318,7 +322,11 @@ const BarLineComponent = (props)=>{
318
322
  ref: chartRef,
319
323
  data: chartData,
320
324
  type: type,
321
- options: updateObjectFields(options, optionCustom),
325
+ options: (()=>{
326
+ const finalOpts = updateObjectFields(options, optionCustom);
327
+ if (finalOpts?.plugins?.tooltip?.callbacks) finalOpts.plugins.tooltip.callbacks.label = labelCallbackBound;
328
+ return finalOpts;
329
+ })(),
322
330
  plugins: [
323
331
  htmlLegendPlugin
324
332
  ]
@@ -2,7 +2,7 @@ import { Chart as ChartJS, ChartTypeRegistry, TooltipItem } from 'chart.js';
2
2
  import { DataSet } from '../../../Utils/exportFile';
3
3
  export declare const getOrCreateLegendList: (id: string) => HTMLUListElement;
4
4
  export declare const titleCallback: (tooltipItems: TooltipItem<keyof ChartTypeRegistry>[], t: any) => string;
5
- export declare const labelCallback: (tooltipItem: TooltipItem<keyof ChartTypeRegistry>) => string;
5
+ export declare const labelCallback: (tooltipItem: TooltipItem<keyof ChartTypeRegistry>, formatValue?: (n: number) => string) => string;
6
6
  export declare const exportToPNG: (element: HTMLElement, nameFile?: string) => void;
7
7
  export declare const exportToJPG: (chartRef: ChartJS<keyof ChartTypeRegistry>, nameFile?: string) => void;
8
8
  export declare const exportToPDF: (element: HTMLElement, nameFile?: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/AWING/Chart/BarLine/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAuB,MAAM,kBAAkB,CAAC;AAEhE,eAAO,MAAM,qBAAqB,OAAQ,MAAM,qBAe/C,CAAC;AAEF,eAAO,MAAM,aAAa,iBAAkB,WAAW,CAAC,MAAM,iBAAiB,CAAC,EAAE,KAAK,GAAG,WAUzF,CAAC;AAEF,eAAO,MAAM,aAAa,gBAAiB,WAAW,CAAC,MAAM,iBAAiB,CAAC,WAO9E,CAAC;AAGF,eAAO,MAAM,WAAW,YAAa,WAAW,aAAa,MAAM,SAQlE,CAAC;AAGF,eAAO,MAAM,WAAW,aAAc,OAAO,CAAC,MAAM,iBAAiB,CAAC,aAAa,MAAM,SAUxF,CAAC;AAGF,eAAO,MAAM,WAAW,YAAa,WAAW,aAAa,MAAM,SAuClE,CAAC;AAGF,eAAO,MAAM,YAAY,aAAoB,OAAO,CAAC,MAAM,iBAAiB,CAAC,kBA8D5E,CAAC;AAGF,eAAO,MAAM,aAAa,eAAgB,OAAO,EAAE,aAAa,MAAM,SAOrE,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/AWING/Chart/BarLine/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5E,OAAO,EAAE,OAAO,EAAuB,MAAM,kBAAkB,CAAC;AAEhE,eAAO,MAAM,qBAAqB,OAAQ,MAAM,qBAe/C,CAAC;AAEF,eAAO,MAAM,aAAa,iBAAkB,WAAW,CAAC,MAAM,iBAAiB,CAAC,EAAE,KAAK,GAAG,WAUzF,CAAC;AAEF,eAAO,MAAM,aAAa,gBACT,WAAW,CAAC,MAAM,iBAAiB,CAAC,gBACnC,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,WAUtC,CAAC;AAGF,eAAO,MAAM,WAAW,YAAa,WAAW,aAAa,MAAM,SAQlE,CAAC;AAGF,eAAO,MAAM,WAAW,aAAc,OAAO,CAAC,MAAM,iBAAiB,CAAC,aAAa,MAAM,SAUxF,CAAC;AAGF,eAAO,MAAM,WAAW,YAAa,WAAW,aAAa,MAAM,SAuClE,CAAC;AAGF,eAAO,MAAM,YAAY,aAAoB,OAAO,CAAC,MAAM,iBAAiB,CAAC,kBA8D5E,CAAC;AAGF,eAAO,MAAM,aAAa,eAAgB,OAAO,EAAE,aAAa,MAAM,SAOrE,CAAC"}
@@ -3,6 +3,7 @@ import html2canvas from "html2canvas";
3
3
  import jspdf from "jspdf";
4
4
  import moment from "moment";
5
5
  import pizzip from "pizzip";
6
+ import { roundDecimalNumber } from "../../../Helpers/number.js";
6
7
  import { downloadWithDataSet } from "../../../Utils/exportFile.js";
7
8
  const getOrCreateLegendList = (id)=>{
8
9
  const legendContainer = document.getElementById(id);
@@ -29,10 +30,12 @@ const titleCallback = (tooltipItems, t)=>{
29
30
  return t('Common.Day') + ': ' + timeText;
30
31
  }
31
32
  };
32
- const labelCallback = (tooltipItem)=>{
33
+ const labelCallback = (tooltipItem, formatValue)=>{
33
34
  let labels = tooltipItem.dataset.label || '';
34
35
  if (labels) labels = labels.split(' ').slice(0, -1).join(' ');
35
- labels += ': ' + tooltipItem.formattedValue;
36
+ const raw = tooltipItem.raw;
37
+ const numValue = 'object' == typeof raw && null !== raw ? raw.y ?? NaN : Number(raw);
38
+ labels += ': ' + (formatValue ? formatValue(numValue) : roundDecimalNumber(numValue) ?? tooltipItem.formattedValue);
36
39
  return ' ' + labels;
37
40
  };
38
41
  const exportToPNG = (element, nameFile)=>{
@@ -1 +1 @@
1
- {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/Helpers/number.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,yBAAyB;AACzB,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAE9D,wBAAgB,oBAAoB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAgBpG;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,GAAG,iBAS7C;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,GAAG,gBASxC"}
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/Helpers/number.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,yBAAyB;AACzB,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAE9D,wBAAgB,oBAAoB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAgBpG;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,GAAG,iBAI7C;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,GAAG,gBASxC"}
@@ -15,10 +15,8 @@ function formatNumberByLocale(value, lang, locale) {
15
15
  }
16
16
  function roundDecimalNumber(number) {
17
17
  if ('number' != typeof number) return null;
18
- let str = JSON.stringify(Math.round(1000000 * number) / 1000000);
19
- let signIndex = str.indexOf('.');
20
- if (-1 === signIndex) return str.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
21
- return str.slice(0, signIndex).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') + str.slice(signIndex);
18
+ const rounded = Math.round(1000000 * number) / 1000000;
19
+ return formatNumberByLocale(rounded);
22
20
  }
23
21
  function WMAPEcalculator(data) {
24
22
  if (!(data.length > 0)) return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awing-library",
3
- "version": "2.1.2-stable.40",
3
+ "version": "2.1.2-stable.41",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {