@hestia-earth/ui-components 0.32.63 → 0.32.64

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,12 +1,13 @@
1
+ import Chart from 'chart.js';
1
2
  import { ChartPlugin } from './models';
2
3
  export declare const defaultBarDrawSettings: {
3
- xPosFn: (x: number, index: number, width: number) => number;
4
- yPosFn: (y: number, index: number) => number;
5
- colorFn: (m: any, index: number) => string;
4
+ xPosFn: (x: number, index: number, width: number, chart: Chart) => number;
5
+ yPosFn: (y: number, index: number, height: number, chart: Chart) => number;
6
+ colorFn: (m: any, index: number, chart: Chart) => string;
6
7
  textFn: (m: {
7
8
  label: string;
8
9
  data: number;
9
- }, index: number) => string | [string, string];
10
+ }, index: number, chart: Chart) => string | [string, string];
10
11
  font: string;
11
12
  maxWidth: number;
12
13
  };
@@ -1059,21 +1059,22 @@ function isMouseInsideCircle(event, circleCenter, circleRadius) {
1059
1059
  }
1060
1060
 
1061
1061
  const defaultBarDrawSettings = {
1062
- xPosFn: (x, index, width) => x + 10,
1063
- yPosFn: (y, index) => y + 3,
1064
- colorFn: (m, index) => 'black',
1065
- textFn: (m, index) => `${m.label} - ${toPrecision(m.data)} kg`,
1062
+ xPosFn: (x, index, width, chart) => x + 10,
1063
+ yPosFn: (y, index, height, chart) => y + 3,
1064
+ colorFn: (m, index, chart) => 'black',
1065
+ textFn: (m, index, chart) => `${m.label} - ${toPrecision(m.data)} kg`,
1066
1066
  font: '14px Lato',
1067
1067
  maxWidth: 90
1068
1068
  };
1069
1069
  const afterBarDrawPlugin = settings => ({
1070
- afterDraw: chart => {
1070
+ afterDraw: (chart) => {
1071
1071
  if (!chart.data.datasets?.length) {
1072
1072
  return;
1073
1073
  }
1074
1074
  const { xPosFn, yPosFn, colorFn, textFn, maxWidth, font } = { ...defaultBarDrawSettings, ...(settings ?? {}) };
1075
1075
  const { ctx } = chart;
1076
1076
  ctx.save();
1077
+ const height = chart.chartArea.bottom - chart.chartArea.top;
1077
1078
  const width = chart.chartArea.right - chart.chartArea.left;
1078
1079
  chart
1079
1080
  .getDatasetMeta(0)
@@ -1086,11 +1087,11 @@ const afterBarDrawPlugin = settings => ({
1086
1087
  if (typeof data !== 'number') {
1087
1088
  return;
1088
1089
  }
1089
- const xPos = xPosFn(x, index, width);
1090
- const yPos = yPosFn(y, index);
1091
- const text = textFn({ label, data }, index);
1090
+ const xPos = xPosFn(x, index, width, chart);
1091
+ const yPos = yPosFn(y, index, height, chart);
1092
+ const text = textFn({ label, data }, index, chart);
1092
1093
  ctx.font = font;
1093
- ctx.fillStyle = colorFn(_view, index);
1094
+ ctx.fillStyle = colorFn(_view, index, chart);
1094
1095
  if (Array.isArray(text)) {
1095
1096
  ctx.fillText(text[0], xPos, yPos - 5, maxWidth);
1096
1097
  ctx.fillText(text[1], xPos, yPos + 5, maxWidth);