chart y-axis labels are now using the same formatting as the legend values
Costa Tsaousis (ktsaou) committed
Feb 5, 2017 at 23:47 UTC
9dd721207fd2200f740b7a5dfd2f73d4148a4f5e
2 files changed
+28
-25
web/dashboard.js
+27
-24
@@ -2247,8 +2247,16 @@ var NETDATA = window.NETDATA || {};
2247
return ret;
2248
};
2249
2250
- this.legendFormatValueChartDecimals = -1;
2250
+ var __legendFormatValueChartDecimalsLastMin = undefined;
2251
+ var __legendFormatValueChartDecimalsLastMax = undefined;
2252
+ var __legendFormatValueChartDecimals = -1;
2253
this.legendFormatValueDecimalsFromMinMax = function(min, max) {
2254
+ if(min === __legendFormatValueChartDecimalsLastMin && max === __legendFormatValueChartDecimalsLastMax)
2255
+ return;
2256
+
2257
+ __legendFormatValueChartDecimalsLastMin = min;
2258
+ __legendFormatValueChartDecimalsLastMax = max;
2259
+
2260
var delta;
2261
2262
if(min === max)
@@ -2256,11 +2264,11 @@ var NETDATA = window.NETDATA || {};
2264
else
2265
delta = Math.abs(max - min);
2266
2259
- if(delta > 1000) this.legendFormatValueChartDecimals = 0;
2260
- else if(delta > 10 ) this.legendFormatValueChartDecimals = 1;
2261
- else if(delta > 1 ) this.legendFormatValueChartDecimals = 2;
2262
- else if(delta > 0.1 ) this.legendFormatValueChartDecimals = 3;
2263
- else this.legendFormatValueChartDecimals = 4;
2267
+ if(delta > 1000) __legendFormatValueChartDecimals = 0;
2268
+ else if(delta > 10 ) __legendFormatValueChartDecimals = 1;
2269
+ else if(delta > 1 ) __legendFormatValueChartDecimals = 2;
2270
+ else if(delta > 0.1 ) __legendFormatValueChartDecimals = 3;
2271
+ else __legendFormatValueChartDecimals = 4;
2272
};
2273
2274
this.legendFormatValue = function(value) {
@@ -2272,7 +2280,7 @@ var NETDATA = window.NETDATA || {};
2280
dmin = dmax = this.value_decimal_detail;
2281
}
2282
2275
- if(this.legendFormatValueChartDecimals < 0) {
2283
+ if(__legendFormatValueChartDecimals < 0) {
2284
dmin = 0;
2285
var abs = value;
2286
if(abs > 1000) dmax = 0;
@@ -2282,7 +2290,7 @@ var NETDATA = window.NETDATA || {};
2290
else dmax = 4;
2291
}
2292
else {
2285
- dmin = dmax = this.legendFormatValueChartDecimals;
2293
+ dmin = dmax = __legendFormatValueChartDecimals;
2294
}
2295
2296
return value.toLocaleString(undefined, {
@@ -4425,7 +4433,7 @@ var NETDATA = window.NETDATA || {};
4433
|| 2,
4434
4435
valueFormatter: self.data('dygraph-valueformatter')
4428
- || function(x){ return x.toFixed(2); },
4436
+ || undefined,
4437
4438
highlightCircleSize: self.data('dygraph-highlightcirclesize')
4439
|| highlightCircleSize,
@@ -4440,6 +4448,7 @@ var NETDATA = window.NETDATA || {};
4448
|| undefined,
4449
4450
visibility: state.dimensions_visibility.selected2BooleanArray(state.data.dimension_names),
4451
+
4452
axes: {
4453
x: {
4454
pixelsPerLabel: 50,
@@ -4447,25 +4456,19 @@ var NETDATA = window.NETDATA || {};
4456
axisLabelFormatter: function (d, gran) {
4457
void(gran);
4458
return NETDATA.zeropad(d.getHours()) + ":" + NETDATA.zeropad(d.getMinutes()) + ":" + NETDATA.zeropad(d.getSeconds());
4450
- },
4451
- valueFormatter: function (ms) {
4452
- void(ms);
4453
- //var d = new Date(ms);
4454
- //return d.toLocaleDateString() + ' ' + d.toLocaleTimeString();
4455
-
4456
- // no need to return anything here
4457
- return ' ';
4458
-
4459
}
4460
},
4461
y: {
4462
pixelsPerLabel: 15,
4463
- valueFormatter: function (x) {
4464
- // we format legends with the state object
4465
- // no need to do anything here
4466
- // return (Math.round(x*100) / 100).toLocaleString();
4467
- // return state.legendFormatValue(x);
4468
- return x;
4463
+ axisLabelFormatter: function (y) {
4464
+
4465
+ // unfortunately, we have to call this every single time
4466
+ state.legendFormatValueDecimalsFromMinMax(
4467
+ this.axes_[0].extremeRange[0],
4468
+ this.axes_[0].extremeRange[1]
4469
+ );
4470
+
4471
+ return state.legendFormatValue(y);
4472
}
4473
}
4474
},
web/index.html
+1
-1
@@ -3312,4 +3312,4 @@
3312
</div>
3313
</body>
3314
</html>
3315
-<script type="text/javascript" src="dashboard.js?v20170205-28"></script>
3315
+<script type="text/javascript" src="dashboard.js?v20170205-37"></script>