Skip to content

Commit

Permalink
Remove dataset manipulation workarount for chart.js < 3.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
porst17 committed Aug 30, 2021
1 parent 7020fc1 commit efd072f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
Expand Down
20 changes: 4 additions & 16 deletions src/ts/charts/solar-emissivity-vs-temperature.ts
Expand Up @@ -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] =
Expand Down
20 changes: 4 additions & 16 deletions src/ts/charts/temperature-vs-time.ts
Expand Up @@ -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,
Expand Down

0 comments on commit efd072f

Please sign in to comment.