Autoscale considers new ChartJS format, data reloads onzoom and onpan
This commit is contained in:
@ -14,9 +14,13 @@ Here is a list of what has been done :
|
|||||||
- Renamed or moved all needed parameters in the ChartJS configuration.
|
- Renamed or moved all needed parameters in the ChartJS configuration.
|
||||||
- Changed all `xAxes` and `yAxes` references to `x` and `y`.
|
- Changed all `xAxes` and `yAxes` references to `x` and `y`.
|
||||||
- Adapted `afterBuildTicks` callbacks with the new signature (only `axis` is given)
|
- Adapted `afterBuildTicks` callbacks with the new signature (only `axis` is given)
|
||||||
|
- Changed all references to `ticks.max|min` : these two properties are one step higher, at the level of the axis, not the ticks
|
||||||
|
|
||||||
Here is a list of what needs to be done :
|
Here is a list of what needs to be done :
|
||||||
- Change the implementation of the callback located in `options.scales.x.ticks` at chart creation in the Chart class, so it considers that the label is a timestamp. Reference : https://www.chartjs.org/docs/latest/axes/labelling.html#creating-custom-tick-formats
|
- Change the implementation of the callback located in `options.scales.x.ticks` at chart creation in the Chart class, so it considers that the label is a timestamp. Reference : https://www.chartjs.org/docs/latest/axes/labelling.html#creating-custom-tick-formats
|
||||||
|
- Labels of the x axis are not displayed in the desired format, and do not rescale properly on zooming/dezooming. There can be too much labels, that make them rotate and invisible.
|
||||||
|
- The cursor now also displays when the click ends, which is not the same behavior as before.
|
||||||
|
- Make the zoom type toggle work again.
|
||||||
|
|
||||||
|
|
||||||
**Summary**
|
**Summary**
|
||||||
|
@ -601,8 +601,8 @@ let graphs = (function (){
|
|||||||
* @returns If the minimun y-value of all the curves of the charts is greater than the maximum y-value (same)
|
* @returns If the minimun y-value of all the curves of the charts is greater than the maximum y-value (same)
|
||||||
*/
|
*/
|
||||||
function autoScale(chart) {
|
function autoScale(chart) {
|
||||||
axis = chart.options.scales.y;
|
ay = chart.options.scales.y;
|
||||||
tax = chart.options.scales.x.ticks;
|
ax = chart.options.scales.x;
|
||||||
datasets = chart.data.datasets;
|
datasets = chart.data.datasets;
|
||||||
let max = -1e99;
|
let max = -1e99;
|
||||||
let min = 1e99;
|
let min = 1e99;
|
||||||
@ -613,8 +613,8 @@ let graphs = (function (){
|
|||||||
for (let i = 0; i < datasets.length; i++){
|
for (let i = 0; i < datasets.length; i++){
|
||||||
ds = datasets[i];
|
ds = datasets[i];
|
||||||
if (ds.borderWidth == 1) continue;
|
if (ds.borderWidth == 1) continue;
|
||||||
let lmax = maxAr(ds.data, tax.min, tax.max);
|
let lmax = maxAr(ds.data, ax.min, ax.max);
|
||||||
let lmin = minAr(ds.data, tax.min, tax.max);
|
let lmin = minAr(ds.data, ax.min, ax.max);
|
||||||
if(lmax > max)
|
if(lmax > max)
|
||||||
max = lmax;
|
max = lmax;
|
||||||
if(lmin < min)
|
if(lmin < min)
|
||||||
@ -648,8 +648,8 @@ let graphs = (function (){
|
|||||||
}
|
}
|
||||||
extraMin = Math.min(min - ystep * 0.5, extraMin);
|
extraMin = Math.min(min - ystep * 0.5, extraMin);
|
||||||
extraMax = Math.max(max + ystep * 0.5, extraMax);
|
extraMax = Math.max(max + ystep * 0.5, extraMax);
|
||||||
if (min >= axis.ticks.min && axis.ticks.min >= extraMin &&
|
if (min >= ay.min && ay.min >= extraMin &&
|
||||||
max <= axis.ticks.max && axis.ticks.max <= extraMax) {
|
max <= ay.max && ay.max <= extraMax) {
|
||||||
//console.log('NOCHANGE', max, axis.ticks.max, extraMax)
|
//console.log('NOCHANGE', max, axis.ticks.max, extraMax)
|
||||||
return; // do not yet change
|
return; // do not yet change
|
||||||
}
|
}
|
||||||
@ -658,8 +658,8 @@ let graphs = (function (){
|
|||||||
min = extraMin;
|
min = extraMin;
|
||||||
max = extraMax;
|
max = extraMax;
|
||||||
}
|
}
|
||||||
axis.min = axis.ticks.min = min;
|
ay.min = min;
|
||||||
axis.max = axis.ticks.max = max;
|
ay.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -788,8 +788,8 @@ let graphs = (function (){
|
|||||||
* @returns When data is received (no need to autoScale and update as it is done in reloadData)
|
* @returns When data is received (no need to autoScale and update as it is done in reloadData)
|
||||||
*/
|
*/
|
||||||
function checkReload(graph){
|
function checkReload(graph){
|
||||||
let tk = graph.chart.options.scales.x.ticks;
|
let ax = graph.chart.options.scales.x;
|
||||||
let xmin = tk.min, xmax = tk.max;
|
let xmin = ax.min, xmax = ax.max;
|
||||||
/*
|
/*
|
||||||
if (xmax < now()-100000) { // was 100000 = 100sec
|
if (xmax < now()-100000) { // was 100000 = 100sec
|
||||||
if (liveMode) console.log('UPDATES OFF?')
|
if (liveMode) console.log('UPDATES OFF?')
|
||||||
@ -828,7 +828,6 @@ let graphs = (function (){
|
|||||||
* @param {*} graph - The graph Object on which the zoom callback has to be called
|
* @param {*} graph - The graph Object on which the zoom callback has to be called
|
||||||
*/
|
*/
|
||||||
function zoomCallback(graph){
|
function zoomCallback(graph){
|
||||||
console.log(graph.chart)
|
|
||||||
let a, min, max;
|
let a, min, max;
|
||||||
if (currentZoomMode == 'y') {
|
if (currentZoomMode == 'y') {
|
||||||
a = graph.chart.options.scales.y;
|
a = graph.chart.options.scales.y;
|
||||||
|
Reference in New Issue
Block a user