From efd072f10a1e3440d9274739580b74fc8673cb01 Mon Sep 17 00:00:00 2001 From: Christian Stussak Date: Mon, 30 Aug 2021 09:36:54 +0200 Subject: [PATCH] Remove dataset manipulation workarount for chart.js < 3.5.1 https://github.com/chartjs/Chart.js/issues/9511 https://github.com/chartjs/Chart.js/pull/9525 --- package-lock.json | 6 +++--- package.json | 2 +- .../charts/solar-emissivity-vs-temperature.ts | 20 ++++--------------- src/ts/charts/temperature-vs-time.ts | 20 ++++--------------- 4 files changed, 12 insertions(+), 36 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7da0433..58d9b28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2267,9 +2267,9 @@ } }, "chart.js": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-3.3.2.tgz", - "integrity": "sha512-H0hSO7xqTIrwxoACqnSoNromEMfXvfuVnrbuSt2TuXfBDDofbnto4zuZlRtRvC73/b37q3wGAWZyUU41QPvNbA==" + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-3.5.1.tgz", + "integrity": "sha512-m5kzt72I1WQ9LILwQC4syla/LD/N413RYv2Dx2nnTkRS9iv/ey1xLTt0DnPc/eWV4zI+BgEgDYBIzbQhZHc/PQ==" }, "chokidar": { "version": "3.5.1", diff --git a/package.json b/package.json index 81ffc19..82a7040 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@imaginary-maths/box-model": "^0.5.0", "@svgdotjs/svg.js": "^3.0.16", "@tweenjs/tween.js": "^18.6.4", - "chart.js": "^3.3.2", + "chart.js": "^3.5.1", "document-ready": "^2.0.2", "lodash": "^4.17.21", "reseter.css": "^2.0.0" diff --git a/src/ts/charts/solar-emissivity-vs-temperature.ts b/src/ts/charts/solar-emissivity-vs-temperature.ts index 0570503..e3e5ce2 100644 --- a/src/ts/charts/solar-emissivity-vs-temperature.ts +++ b/src/ts/charts/solar-emissivity-vs-temperature.ts @@ -109,22 +109,10 @@ export default class SolarEmissivityVsTemperatureChart implements Chart { const { year: maxYear } = last(newDataPoints) ?? last(data0) ?? { year: -1 }; const minYear = maxYear - numYears + 1; - if (true) { - // to be used as long as there is no fix for the Chart.js bug - while (first(data0)?.year < minYear) data0.shift(); - if (first(newDataPoints)?.year < minYear) { - const newDataPointsClone = [...newDataPoints]; - while (first(newDataPointsClone)?.year < minYear) - newDataPointsClone.shift(); - data0.push(...newDataPointsClone); - } else { - data0.push(...newDataPoints); - } - } else { - data0.push(...newDataPoints); - const idx = data0.findIndex(({ year }) => year >= minYear); - data0.splice(0, idx); - } + + data0.push(...newDataPoints); + const idx = data0.findIndex(({ year }) => year >= minYear); + data0.splice(0, idx); const data1 = this.chart.config.data.datasets[1].data; data1[0] = diff --git a/src/ts/charts/temperature-vs-time.ts b/src/ts/charts/temperature-vs-time.ts index 9b47ff1..4683f1e 100644 --- a/src/ts/charts/temperature-vs-time.ts +++ b/src/ts/charts/temperature-vs-time.ts @@ -97,22 +97,10 @@ export default class TemperatureVsTimeChart implements Chart { const newDataPoints = newResults.map(createDataPoint); const { x: maxYear } = last(newDataPoints) ?? last(data) ?? { x: -1 }; const minYear = maxYear - numYears + 1; - if (true) { - // to be used as long as there is no fix for the Chart.js bug - while (first(data)?.x < minYear) data.shift(); - if (first(newDataPoints)?.x < minYear) { - const newDataPointsClone = [...newDataPoints]; - while (first(newDataPointsClone)?.x < minYear) - newDataPointsClone.shift(); - data.push(...newDataPointsClone); - } else { - data.push(...newDataPoints); - } - } else { - data.push(...newDataPoints); - const idx = data.findIndex(({ x }) => x >= minYear); - data.splice(0, idx); - } + + data.push(...newDataPoints); + const idx = data.findIndex(({ x }) => x >= minYear); + data.splice(0, idx); Object.assign(this.chart.config.options.scales.x, { min: minYear,