@datarailsshared/dr_renderer 1.4.128 → 1.4.130
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
@@ -483,10 +483,22 @@ function DrGaugeChart(pivotData, opts, isDynamicGoal) {
|
|
483
483
|
gauge: { thickness },
|
484
484
|
} = options;
|
485
485
|
|
486
|
+
// If goal is not positive in percentage mode, scale segments by the current needle magnitude
|
487
|
+
const scaleBase = !isAbsoluteValue && (!helpers.isNumber(goalValue) || goalValue === 0)
|
488
|
+
? (helpers.isNumber(this.value) && Math.abs(this.value)) || 1
|
489
|
+
: goalValue;
|
490
|
+
|
486
491
|
const bands = segments.map((item) => {
|
492
|
+
const fromValue = isAbsoluteValue ? item.from : (item.from * scaleBase) / 100;
|
493
|
+
const toValue = isAbsoluteValue ? item.to : (item.to * scaleBase) / 100;
|
494
|
+
|
495
|
+
// Ensure a valid interval for Highcharts plotBands even when goal is negative
|
496
|
+
const normalizedFrom = Math.min(fromValue, toValue);
|
497
|
+
const normalizedTo = Math.max(fromValue, toValue);
|
498
|
+
|
487
499
|
return {
|
488
|
-
from:
|
489
|
-
to:
|
500
|
+
from: normalizedFrom,
|
501
|
+
to: normalizedTo,
|
490
502
|
color: item.color,
|
491
503
|
thickness: thickness,
|
492
504
|
title: item.title,
|
@@ -634,10 +646,10 @@ function DrGaugeChart(pivotData, opts, isDynamicGoal) {
|
|
634
646
|
this.options = this.mergeOptions(opts.chartOptions);
|
635
647
|
this.aggregation = DrGaugeChart.getAggregation(pivotData, opts.chartOptions);
|
636
648
|
this.format = this.aggregation.widget_values_format;
|
649
|
+
this.value = DrGaugeChart.getValue(pivotData, opts, isDynamicGoal);
|
637
650
|
this.setGoal(pivotData, opts);
|
638
651
|
this.plotBands = this.createPlotBands(this.options);
|
639
652
|
this.ticks = this.createTicks(this.plotBands, this.options);
|
640
|
-
this.value = DrGaugeChart.getValue(pivotData, opts, isDynamicGoal);
|
641
653
|
this.max = this.ticks[this.ticks.length - 1];
|
642
654
|
this.min = this.ticks[0];
|
643
655
|
}
|
@@ -6657,7 +6657,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
6657
6657
|
element_type: 'checkbox',
|
6658
6658
|
value_name: 'dislay_empty_values',
|
6659
6659
|
element_label: 'Display empty values',
|
6660
|
-
default_value:
|
6660
|
+
default_value: false
|
6661
6661
|
},
|
6662
6662
|
]
|
6663
6663
|
},
|
@@ -6685,7 +6685,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
6685
6685
|
element_type: 'checkbox',
|
6686
6686
|
value_name: 'dislay_empty_values',
|
6687
6687
|
element_label: 'Display empty values',
|
6688
|
-
default_value:
|
6688
|
+
default_value: false
|
6689
6689
|
},
|
6690
6690
|
{
|
6691
6691
|
element_type: 'devider',
|
@@ -310,6 +310,93 @@ describe("DrGaugeChart", () => {
|
|
310
310
|
},
|
311
311
|
]);
|
312
312
|
});
|
313
|
+
|
314
|
+
it("scales by needle magnitude when goal is 0 in percentage mode", () => {
|
315
|
+
chart.value = 250;
|
316
|
+
expect(
|
317
|
+
chart.createPlotBands({
|
318
|
+
isAbsoluteValue: false,
|
319
|
+
gauge: { thickness: 10 },
|
320
|
+
goal: { value: 0 },
|
321
|
+
segments: [
|
322
|
+
{ from: 0, to: 50, color: "red", title: "Title 1" },
|
323
|
+
{ from: 50, to: 100, color: "blue", title: "Title 2" },
|
324
|
+
],
|
325
|
+
})
|
326
|
+
).toEqual([
|
327
|
+
{ from: 0, to: 125, color: "red", thickness: 10, title: "Title 1" },
|
328
|
+
{ from: 125, to: 250, color: "blue", thickness: 10, title: "Title 2" },
|
329
|
+
]);
|
330
|
+
});
|
331
|
+
|
332
|
+
it("scales by absolute needle magnitude when goal is not a number", () => {
|
333
|
+
const featureSpy = jest
|
334
|
+
.spyOn(DrGaugeChart.highchartsRenderer, "hasFeature")
|
335
|
+
.mockReturnValue(true);
|
336
|
+
|
337
|
+
chart.value = -300;
|
338
|
+
const res = chart.createPlotBands({
|
339
|
+
isAbsoluteValue: false,
|
340
|
+
gauge: { thickness: 8 },
|
341
|
+
goal: { value: undefined },
|
342
|
+
segments: [
|
343
|
+
{ from: 0, to: 50, color: "#1", title: "A" },
|
344
|
+
{ from: 50, to: 100, color: "#2", title: "B" },
|
345
|
+
],
|
346
|
+
});
|
347
|
+
|
348
|
+
expect(res).toEqual([
|
349
|
+
{ from: 0, to: 150, color: "#1", thickness: 8, title: "A" },
|
350
|
+
{ from: 150, to: 300, color: "#2", thickness: 8, title: "B" },
|
351
|
+
]);
|
352
|
+
|
353
|
+
featureSpy.mockRestore();
|
354
|
+
});
|
355
|
+
|
356
|
+
it("normalizes bands when goal is negative in percentage mode", () => {
|
357
|
+
const res = chart.createPlotBands({
|
358
|
+
isAbsoluteValue: false,
|
359
|
+
gauge: { thickness: 12 },
|
360
|
+
goal: { value: -1000 },
|
361
|
+
segments: [
|
362
|
+
{ from: 0, to: 50, color: "r", title: "S1" },
|
363
|
+
{ from: 50, to: 100, color: "b", title: "S2" },
|
364
|
+
],
|
365
|
+
});
|
366
|
+
|
367
|
+
expect(res[0].from).toBe(-500);
|
368
|
+
expect(Math.abs(res[0].to)).toBe(0);
|
369
|
+
expect(res[0].color).toBe("r");
|
370
|
+
expect(res[0].thickness).toBe(12);
|
371
|
+
expect(res[0].title).toBe("S1");
|
372
|
+
|
373
|
+
expect(res[1]).toEqual({ from: -1000, to: -500, color: "b", thickness: 12, title: "S2" });
|
374
|
+
});
|
375
|
+
|
376
|
+
it("does not clamp last segment when dynamic goal feature is enabled", () => {
|
377
|
+
const featureSpy = jest
|
378
|
+
.spyOn(DrGaugeChart.highchartsRenderer, "hasFeature")
|
379
|
+
.mockReturnValue(true);
|
380
|
+
|
381
|
+
const res = chart.createPlotBands({
|
382
|
+
isAbsoluteValue: true,
|
383
|
+
gauge: { thickness: 10 },
|
384
|
+
goal: { value: 1800 },
|
385
|
+
segments: [
|
386
|
+
{ from: 100, to: 200, color: "red", title: "Title 1" },
|
387
|
+
{ from: 200, to: 400, color: "blue", title: "Title 2" },
|
388
|
+
{ from: 400, to: 800, color: "green", title: "Title 3" },
|
389
|
+
],
|
390
|
+
});
|
391
|
+
|
392
|
+
expect(res).toEqual([
|
393
|
+
{ from: 100, to: 200, color: "red", thickness: 10, title: "Title 1" },
|
394
|
+
{ from: 200, to: 400, color: "blue", thickness: 10, title: "Title 2" },
|
395
|
+
{ from: 400, to: 800, color: "green", thickness: 10, title: "Title 3" },
|
396
|
+
]);
|
397
|
+
|
398
|
+
featureSpy.mockRestore();
|
399
|
+
});
|
313
400
|
});
|
314
401
|
|
315
402
|
describe("createTicks", () => {
|