@datarailsshared/dr_renderer 1.5.190 → 1.5.196

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.5.190",
3
+ "version": "1.5.196",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -18,6 +18,7 @@
18
18
  "test": "jest --coverage",
19
19
  "build:types": "npx tsc --build --verbose",
20
20
  "build:types:clean": "npx tsc --build --clean",
21
+ "build": "npm run build:types:clean && npm run build:types",
21
22
  "watch": "npm run watch:types",
22
23
  "watch:types": "npx tsc --build --watch"
23
24
  },
@@ -1,6 +1,7 @@
1
1
  const _ = require('lodash');
2
2
  const { DrChartTooltip } = require("../dr_chart_tooltip");
3
3
  const helpers = require("../dr-renderer-helpers");
4
+ const DataFormatter = require("../dataformatter");
4
5
 
5
6
  /**
6
7
  * @typedef {Object} DrGaugeChartInstance
@@ -81,36 +82,16 @@ function DrGaugeChart(pivotData, opts, isDynamicGoal) {
81
82
  return DrGaugeChart.highchartsRenderer.ptCreateElementAndDraw(this.configChart(), opts);
82
83
  };
83
84
 
84
- this.formatValue = function (data_type, number_format, value, widget_values_format) {
85
- return DrGaugeChart.highchartsRenderer.formatValue(data_type, number_format, value, widget_values_format);
86
- };
87
-
88
85
  this.getDefaultValueForChart = function (type, existing_options) {
89
86
  return DrGaugeChart.highchartsRenderer.getDefaultValueForChart(type, existing_options);
90
87
  };
91
88
 
92
- this.ptCreateBasicLineSeries = function (pivotData, colors, onlyNumbers, isUniqueVals, additionOptions, opts, chartOptions) {
93
- return DrGaugeChart.highchartsRenderer.ptCreateBasicLineSeries(
94
- pivotData,
95
- colors,
96
- onlyNumbers,
97
- isUniqueVals,
98
- additionOptions,
99
- opts,
100
- chartOptions
101
- );
102
- };
103
-
104
- this.getSingleValueAgg = function (opts, aggfunc, base) {
105
- return DrGaugeChart.highchartsRenderer.getSingleValueAgg(opts, aggfunc, base);
106
- };
107
-
108
89
  this.isLeftQuarter = function (value, max = this.max, min = this.min) {
109
90
  return (value - min) < (max - min) / 2;
110
91
  };
111
92
 
112
93
  this.createTicks = function(plotBands, options) {
113
- return DrGaugeChart.createTicks(plotBands, options);
94
+ return DrGaugeChart.createTicks(plotBands, options, this.format);
114
95
  }
115
96
 
116
97
  this.mergeOptions = function (options) {
@@ -139,7 +120,7 @@ function DrGaugeChart(pivotData, opts, isDynamicGoal) {
139
120
  };
140
121
 
141
122
  this.formatValue = function (value, format = this.format) {
142
- return helpers.isNumber(value) ? DrGaugeChart.highchartsRenderer.formatValue("n", format, value).value : value;
123
+ return helpers.isNumber(value) ? DataFormatter.formatValue("n", format, value).value : value;
143
124
  };
144
125
 
145
126
  this.toPercent = function (value) {
@@ -685,10 +666,33 @@ function DrGaugeChart(pivotData, opts, isDynamicGoal) {
685
666
  this.min = this.ticks[0];
686
667
  }
687
668
 
688
- DrGaugeChart.createTicks = function (plotBands, options) {
669
+ /**
670
+ * Creates a sorted, deduplicated array of tick values from plot band boundaries and the goal.
671
+ * When a number format is provided, ticks that are nearly equal to the goal due to
672
+ * floating-point drift and format identically are snapped to the exact goal value
673
+ * before deduplication, preventing overlapping labels.
674
+ * @param {Array<{from?: number, to: number}>} plotBands - The plot band definitions
675
+ * @param {{goal: {value: number}}} options - Chart options containing the goal
676
+ * @param {string} [format] - Optional number format string (e.g. "#,###.00") used to detect visually identical ticks
677
+ * @returns {number[]} Sorted, unique tick values
678
+ */
679
+ DrGaugeChart.createTicks = function (plotBands, options, format) {
689
680
  const goal = options.goal.value;
690
681
  const ticks = [plotBands[0].from || 0, ...plotBands.map((b) => b.to)];
691
682
 
683
+ // Snap ticks that are nearly equal to goal (floating-point drift from
684
+ // percentage-to-absolute scaling) and format identically to the exact goal value
685
+ if (helpers.isNumber(goal) && format) {
686
+ const fmt = (v) => DataFormatter.formatValue("n", format, v).value;
687
+ const formattedGoal = fmt(goal);
688
+ const epsilon = Math.abs(goal) * 1e-10 || 1e-10;
689
+ for (let i = 0; i < ticks.length; i++) {
690
+ if (ticks[i] !== goal && Math.abs(ticks[i] - goal) < epsilon && fmt(ticks[i]) === formattedGoal) {
691
+ ticks[i] = goal;
692
+ }
693
+ }
694
+ }
695
+
692
696
  if (!DrGaugeChart.dynamicGoalFeatureEnabled() || goal < Math.max(...ticks) && goal > Math.min(...ticks)) {
693
697
  ticks.push(options.goal.value);
694
698
  }
@@ -81,8 +81,6 @@ export class GraphTableRenderer {
81
81
  * This includes:
82
82
  * - Destroying the Highcharts instance (if exists)
83
83
  * - Calling destroy on table result (freeze panes observers, Handsontable instances, etc.)
84
- * - Disposing the pivot model
85
- * - Resetting internal state
86
84
  * @returns {void}
87
85
  */
88
86
  destroy(): void;