chartjs / chartjs/chartjs-plugin-zoom

Breaking change in fixRange method

Open
#928 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
623
Forks
331
Avg merge
7h 5m
Merged PRs (30d)
7

Description

When running this code:
`function fixRange(range, {min, max, minLimit, maxLimit}, originalLimits) {
const offset = (range - max + min) / 2;
min -= offset;
max += offset;
const origMin = originalLimits.min.options ?? originalLimits.min.scale;
const origMax = originalLimits.max.options ?? originalLimits.max.scale;
const epsilon = range / 1e6;
if (helpers.almostEquals(min, origMin, epsilon)) {
min = origMin;
}
if (helpers.almostEquals(max, origMax, epsilon)) {
max = origMax;
}
if (min < minLimit) {
min = minLimit;
max = Math.min(minLimit + range, maxLimit);
} else if (max > maxLimit) {
max = maxLimit;
min = Math.max(maxLimit - range, minLimit);
}
return {min, max};
}`

originalLimits.min.options is a object, causing the helpers.almostEquals() to throw a exception.

My code is made for version V2.0.1 and did work perfectly then, but does not work for V2.1.0 or V2.2.0.
Any breaking changes in the code implementation since then?

This is my implementation of ChartJs

`chart = new Chart($('#uicabbd488c7ab04e589f591f67ebbfcd4c')[0], {
type: 'line',


data:{
datasets: datasets,
},

options:{
responsive: true,
maintainAspectRatio: false,
parsing: {
xAxisKey: 'd',
yAxisKey: 'v'
},

scales: {
x: {
min: minDateTime,
max: maxDateTime,
type: 'time',
time: {
displayFormats:{

day: 'DD/MM',

hour: 'DD/MM - HH:mm',

minute: 'HH:mm',

second: 'HH:mm:ss',
}
},
ticks: {
major: {
enabled: true,
},
color: (context) => context.tick && context.tick.major && '#FF0000',
font: function (context) {
if (context.tick && context.tick.major) {
return {
weight: 'bold'
};
}
}
}

},
},


plugins:{
legend: {
onClick:(ev, legendItem, legend) => {
let graph;
EachGraph(g => {
if(g.index == legendItem.datasetIndex)
graph = g;
})
setDataSetVisibility(graph.id, null);
},
display: true,
position: 'top'
},
title:{
display: false,
},
zoom:
{
limits:{
x:{
}
},
pan: {
enabled: true,
mode: 'x',
onPanComplete: afterChartMove,
},
zoom: {

wheel: {
enabled: true,
},
pinch: {
enabled: true,
},
mode: 'x',
onZoomComplete: afterChartMove,
onZoomStart: (args)=>{
var range = args.chart.scales.x.max - args.chart.scales.x.min;

if(0 > args.event.deltaY && 60000 >= range)
return false;

if(args.event.deltaY > 0 && range >= 31622400000)
return false;

return true;
}
},
},

},
},
});
}`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.