@datarailsshared/dr_renderer 1.2.456 → 1.2.459
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,3 +1,4 @@
|
|
1
|
+
const _ = require('lodash');
|
1
2
|
const { DrChartTooltip } = require("../dr_chart_tooltip");
|
2
3
|
const helpers = require("../dr-renderer-helpers");
|
3
4
|
|
@@ -91,9 +92,10 @@ function DrGaugeChart(pivotData, opts) {
|
|
91
92
|
gauge: { thickness },
|
92
93
|
} = options;
|
93
94
|
|
94
|
-
const bands = segments.map((item) => {
|
95
|
+
const bands = segments.map((item, index) => {
|
96
|
+
const itemFrom = !!index ? item.from - 1 : item.from;
|
95
97
|
return {
|
96
|
-
from: isAbsoluteValue ?
|
98
|
+
from: isAbsoluteValue ? itemFrom : (itemFrom * goalValue) / 100,
|
97
99
|
to: isAbsoluteValue ? item.to : (item.to * goalValue) / 100,
|
98
100
|
color: item.color,
|
99
101
|
thickness: thickness,
|
@@ -101,15 +103,14 @@ function DrGaugeChart(pivotData, opts) {
|
|
101
103
|
};
|
102
104
|
});
|
103
105
|
|
104
|
-
// clamp
|
105
|
-
bands[0].from = 0;
|
106
|
+
// clamp last segment
|
106
107
|
bands[bands.length - 1].to = Math.max(bands[bands.length - 1].to, goalValue);
|
107
108
|
|
108
109
|
return bands;
|
109
110
|
};
|
110
111
|
|
111
112
|
this.createTicks = function (plotBands, options) {
|
112
|
-
return
|
113
|
+
return _.uniq([plotBands[0].from || 0, ...plotBands.map((b) => b.to), options.goal.value]).sort((a, b) => a - b);
|
113
114
|
};
|
114
115
|
|
115
116
|
this.mergeOptions = function (options) {
|
@@ -122,7 +123,7 @@ function DrGaugeChart(pivotData, opts) {
|
|
122
123
|
|
123
124
|
this.getAngleForValue = function (
|
124
125
|
value,
|
125
|
-
min =
|
126
|
+
min = this.min,
|
126
127
|
max = this.max,
|
127
128
|
startAngle = this.options.gauge.startAngle,
|
128
129
|
endAngle = this.options.gauge.endAngle
|
@@ -196,10 +197,10 @@ function DrGaugeChart(pivotData, opts) {
|
|
196
197
|
this.getValue = function (pivotData, opts) {
|
197
198
|
const lineSeries = this.ptCreateBasicLineSeries(pivotData, null, true, null, null, opts, {});
|
198
199
|
|
199
|
-
let total = lineSeries
|
200
|
+
let total = _.flatten(lineSeries
|
200
201
|
.map((s) => s.data.map((v) => v))
|
201
|
-
.filter((v) => !isNaN(v))
|
202
|
-
|
202
|
+
.filter((v) => !_.isNaN(v))
|
203
|
+
);
|
203
204
|
|
204
205
|
let aggfunc = (a, b) => a + b;
|
205
206
|
let base = 0;
|
@@ -496,7 +497,7 @@ function DrGaugeChart(pivotData, opts) {
|
|
496
497
|
|
497
498
|
// the value axis
|
498
499
|
yAxis: {
|
499
|
-
min:
|
500
|
+
min: this.min,
|
500
501
|
max: this.max,
|
501
502
|
tickPositions: this.ticks,
|
502
503
|
tickPosition: "inside",
|
@@ -558,6 +559,7 @@ function DrGaugeChart(pivotData, opts) {
|
|
558
559
|
this.ticks = this.createTicks(this.plotBands, this.options);
|
559
560
|
this.value = this.getValue(pivotData, opts);
|
560
561
|
this.max = this.ticks[this.ticks.length - 1];
|
562
|
+
this.min = this.ticks[0];
|
561
563
|
}
|
562
564
|
|
563
565
|
module.exports = { DrGaugeChart, GAUGE_OPTIONS_DEFAULT };
|
@@ -186,7 +186,7 @@ describe("DrGaugeChart", () => {
|
|
186
186
|
]);
|
187
187
|
});
|
188
188
|
|
189
|
-
it("should clamp values (
|
189
|
+
it("should clamp values (max of goal and last segment)", () => {
|
190
190
|
expect(
|
191
191
|
chart.createPlotBands({
|
192
192
|
isAbsoluteValue: true,
|
@@ -219,7 +219,7 @@ describe("DrGaugeChart", () => {
|
|
219
219
|
})
|
220
220
|
).toEqual([
|
221
221
|
{
|
222
|
-
from:
|
222
|
+
from: 100,
|
223
223
|
to: 200,
|
224
224
|
color: "red",
|
225
225
|
thickness: 10,
|