Skip to content

Commit 9c39627

Browse files
authored
Merge pull request #89 from sgratzl/release/v4.2.6
Release v4.2.6
2 parents 19bd88e + ffdfff6 commit 9c39627

File tree

8 files changed

+790
-559
lines changed

8 files changed

+790
-559
lines changed

.yarn/releases/yarn-3.6.3.cjs renamed to .yarn/releases/yarn-3.6.4.cjs

Lines changed: 131 additions & 131 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ packageExtensions:
33
dependencies:
44
eslint-import-resolver-node: "*"
55

6-
yarnPath: .yarn/releases/yarn-3.6.3.cjs
6+
yarnPath: .yarn/releases/yarn-3.6.4.cjs

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "chartjs-chart-graph",
33
"description": "Chart.js module for charting graphs",
4-
"version": "4.2.5",
4+
"version": "4.2.6",
55
"author": {
66
"name": "Samuel Gratzl",
77
"email": "sam@sgratzl.com",
@@ -54,8 +54,8 @@
5454
"last 2 Firefox versions"
5555
],
5656
"dependencies": {
57-
"@types/d3-force": "^3.0.5",
58-
"@types/d3-hierarchy": "^3.1.3",
57+
"@types/d3-force": "^3.0.6",
58+
"@types/d3-hierarchy": "^3.1.4",
5959
"d3-dispatch": "^3.0.1",
6060
"d3-force": "^3.0.0",
6161
"d3-hierarchy": "^3.1.2",
@@ -64,23 +64,23 @@
6464
},
6565
"devDependencies": {
6666
"@chiogen/rollup-plugin-terser": "^7.1.3",
67-
"@rollup/plugin-commonjs": "^25.0.4",
68-
"@rollup/plugin-node-resolve": "^15.2.1",
69-
"@rollup/plugin-replace": "^5.0.2",
70-
"@rollup/plugin-typescript": "^11.1.3",
67+
"@rollup/plugin-commonjs": "^25.0.5",
68+
"@rollup/plugin-node-resolve": "^15.2.3",
69+
"@rollup/plugin-replace": "^5.0.3",
70+
"@rollup/plugin-typescript": "^11.1.5",
7171
"@types/jest": "^29.5.5",
7272
"@types/jest-image-snapshot": "^6.2.1",
73-
"@types/node": "^20.6.2",
74-
"@types/seedrandom": "^3.0.5",
75-
"@typescript-eslint/eslint-plugin": "^6.7.0",
76-
"@typescript-eslint/parser": "^6.7.0",
73+
"@types/node": "^20.8.3",
74+
"@types/seedrandom": "^3.0.6",
75+
"@typescript-eslint/eslint-plugin": "^6.7.4",
76+
"@typescript-eslint/parser": "^6.7.4",
7777
"@yarnpkg/sdks": "^2.7.1",
7878
"canvas": "^2.11.2",
7979
"canvas-5-polyfill": "^0.1.5",
8080
"chart.js": "^4.4.0",
8181
"chartjs-plugin-datalabels": "^2.2.0",
8282
"chartjs-plugin-zoom": "^2.0.1",
83-
"eslint": "^8.49.0",
83+
"eslint": "^8.51.0",
8484
"eslint-config-airbnb-typescript": "^17.1.0",
8585
"eslint-config-prettier": "^9.0.0",
8686
"eslint-config-react-app": "^7.0.1",
@@ -94,18 +94,18 @@
9494
"jest-environment-jsdom": "^29.7.0",
9595
"jest-image-snapshot": "^6.2.0",
9696
"prettier": "^3.0.3",
97-
"rimraf": "^5.0.1",
98-
"rollup": "~3.29.2",
97+
"rimraf": "^5.0.5",
98+
"rollup": "~4.0.2",
9999
"rollup-plugin-cleanup": "^3.2.1",
100-
"rollup-plugin-dts": "^6.0.2",
100+
"rollup-plugin-dts": "^6.1.0",
101101
"seedrandom": "^3.0.5",
102102
"ts-jest": "^29.1.1",
103103
"tslib": "^2.6.2",
104-
"typedoc": "^0.25.1",
104+
"typedoc": "^0.25.2",
105105
"typedoc-plugin-markdown": "^4.0.0-next.16",
106106
"typedoc-vitepress-theme": "^1.0.0-next.3",
107107
"typescript": "^5.2.2",
108-
"vitepress": "^1.0.0-rc.14",
108+
"vitepress": "^1.0.0-rc.20",
109109
"vue": "^3.3.4",
110110
"vue-chartjs": "^5.2.0"
111111
},
@@ -134,5 +134,5 @@
134134
"docs:build": "yarn run docs:api && vitepress build docs",
135135
"docs:preview": "vitepress preview docs"
136136
},
137-
"packageManager": "yarn@3.6.3"
137+
"packageManager": "yarn@3.6.4"
138138
}

samples/tree.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script src=" https://cdn.jsdelivr.net/npm/chart.js@~4.3.0"></script>
5+
<script src="../build/index.umd.js"></script>
6+
</head>
7+
8+
<body>
9+
<div style="width: 75%">
10+
<canvas id="canvas"></canvas>
11+
</div>
12+
<button id="destroy">Destroy</button>
13+
<script>
14+
const chart = new Chart(document.getElementById('canvas').getContext('2d'), {
15+
type: 'forceDirectedGraph',
16+
data: {
17+
labels: [],
18+
datasets: [
19+
{
20+
pointBackgroundColor: 'steelblue',
21+
pointRadius: 5,
22+
data: [],
23+
edges: [],
24+
},
25+
],
26+
},
27+
options: {
28+
legend: {
29+
display: false,
30+
},
31+
},
32+
});
33+
const destroy = document.getElementById('destroy');
34+
destroy.onclick = () => {
35+
chart.destroy();
36+
console.log('ddd');
37+
};
38+
</script>
39+
</body>
40+
</html>

src/controllers/DendrogramController.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export class DendrogramController extends GraphController {
3939
*/
4040
declare options: { tree: ITreeOptions };
4141

42+
private _animTimer: number = -1;
43+
4244
/**
4345
* @hidden
4446
*/
@@ -49,6 +51,14 @@ export class DendrogramController extends GraphController {
4951
super.updateEdgeElement(line, index, properties, mode);
5052
}
5153

54+
_destroy() {
55+
if (this._animTimer >= 0) {
56+
cancelAnimationFrame(this._animTimer);
57+
}
58+
this._animTimer = -2;
59+
return super._destroy();
60+
}
61+
5262
/**
5363
* @hidden
5464
*/
@@ -125,7 +135,14 @@ export class DendrogramController extends GraphController {
125135

126136
layout(root).each((orientation[options.orientation] || orientation.horizontal) as any);
127137

128-
requestAnimationFrame(() => this.chart.update());
138+
const chart = this.chart;
139+
if (this._animTimer !== -2) {
140+
this._animTimer = requestAnimationFrame(() => {
141+
if (chart.canvas) {
142+
chart.update();
143+
}
144+
});
145+
}
129146
}
130147

131148
static readonly id: string = 'dendrogram';

src/controllers/ForceDirectedGraphController.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,26 @@ export class ForceDirectedGraphController extends GraphController {
162162
*/
163163
private readonly _simulation: Simulation<SimulationNodeDatum, undefined>;
164164

165+
private _animTimer: number = -1;
166+
165167
constructor(chart: Chart, datasetIndex: number) {
166168
super(chart, datasetIndex);
167169
this._simulation = forceSimulation()
168170
.on('tick', () => {
169-
this._copyPosition();
170-
this.chart.render();
171+
if (this.chart.canvas && this._animTimer !== -2) {
172+
this._copyPosition();
173+
this.chart.render();
174+
} else {
175+
this._simulation.stop();
176+
}
171177
})
172178
.on('end', () => {
173-
this._copyPosition();
174-
this.chart.render();
175-
// trigger a full update
176-
this.chart.update('default');
179+
if (this.chart.canvas && this._animTimer !== -2) {
180+
this._copyPosition();
181+
this.chart.render();
182+
// trigger a full update
183+
this.chart.update('default');
184+
}
177185
});
178186
const sim = this.options.simulation;
179187

@@ -203,6 +211,14 @@ export class ForceDirectedGraphController extends GraphController {
203211
this._simulation.stop();
204212
}
205213

214+
_destroy() {
215+
if (this._animTimer >= 0) {
216+
cancelAnimationFrame(this._animTimer);
217+
}
218+
this._animTimer = -2;
219+
return super._destroy();
220+
}
221+
206222
/**
207223
* @hidden
208224
*/
@@ -324,10 +340,15 @@ export class ForceDirectedGraphController extends GraphController {
324340
this._copyPosition();
325341
if (this.options.simulation.autoRestart) {
326342
this._simulation.restart();
327-
} else {
328-
requestAnimationFrame(() => this.chart.update());
343+
} else if (this.chart.canvas != null && this._animTimer !== -2) {
344+
const chart = this.chart;
345+
this._animTimer = requestAnimationFrame(() => {
346+
if (chart.canvas) {
347+
chart.update();
348+
}
349+
});
329350
}
330-
} else if (this.options.simulation.autoRestart) {
351+
} else if (this.options.simulation.autoRestart && this.chart.canvas != null && this._animTimer !== -2) {
331352
this._simulation.alpha(1).restart();
332353
}
333354
}

src/controllers/GraphController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ export class GraphController extends ScatterController {
199199
/**
200200
* @hidden
201201
*/
202-
destroy(): void {
203-
(ScatterController.prototype as any).destroy.call(this);
202+
_destroy(): void {
203+
(ScatterController.prototype as any)._destroy.call(this);
204204
if (this._edges) {
205205
unlistenArrayEvents(this._edges, this._edgeListener);
206206
}

0 commit comments

Comments
 (0)