diff --git a/package.json b/package.json index 665cd78..70d149a 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "canvas": "^2.11.2", "canvas-5-polyfill": "^0.1.5", "chart.js": "^4.4.4", + "chartjs-plugin-datalabels": "^2.2.0", "eslint": "^9.11.1", "eslint-plugin-prettier": "^5.2.1", "jest-image-snapshot": "^6.4.0", diff --git a/src/controllers/DendrogramController.ts b/src/controllers/DendrogramController.ts index 7343bee..e5a5664 100644 --- a/src/controllers/DendrogramController.ts +++ b/src/controllers/DendrogramController.ts @@ -44,9 +44,8 @@ export class DendrogramController extends GraphController { /** * @hidden */ - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + updateEdgeElement(line: EdgeLine, index: number, properties: any, mode: UpdateMode): void { - // eslint-disable-next-line no-param-reassign properties._orientation = this.options.tree.orientation; super.updateEdgeElement(line, index, properties, mode); } @@ -62,10 +61,9 @@ export class DendrogramController extends GraphController { /** * @hidden */ - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + updateElement(point: Element, index: number, properties: any, mode: UpdateMode): void { if (index != null) { - // eslint-disable-next-line no-param-reassign properties.angle = (this.getParsed(index) as { angle: number }).angle; } super.updateElement(point, index, properties, mode); @@ -112,23 +110,20 @@ export class DendrogramController extends GraphController { const orientation = { horizontal: (d: { x: number; y: number; data: { x: number; y: number } }) => { - // eslint-disable-next-line no-param-reassign d.data.x = d.y - 1; - // eslint-disable-next-line no-param-reassign + d.data.y = -d.x + 1; }, vertical: (d: { x: number; y: number; data: { x: number; y: number } }) => { - // eslint-disable-next-line no-param-reassign d.data.x = d.x - 1; - // eslint-disable-next-line no-param-reassign + d.data.y = -d.y + 1; }, radial: (d: { x: number; y: number; data: { x: number; y: number; angle?: number } }) => { - // eslint-disable-next-line no-param-reassign d.data.x = Math.cos(d.x) * d.y; - // eslint-disable-next-line no-param-reassign + d.data.y = Math.sin(d.x) * d.y; - // eslint-disable-next-line no-param-reassign + d.data.angle = d.y === 0 ? Number.NaN : d.x; }, }; diff --git a/src/controllers/ForceDirectedGraphController.ts b/src/controllers/ForceDirectedGraphController.ts index 6556780..62dd5af 100644 --- a/src/controllers/ForceDirectedGraphController.ts +++ b/src/controllers/ForceDirectedGraphController.ts @@ -258,9 +258,8 @@ export class ForceDirectedGraphController extends GraphController { nodes.forEach((node) => { if (node._sim) { - // eslint-disable-next-line no-param-reassign node.x = rescaleX(node._sim.x ?? 0); - // eslint-disable-next-line no-param-reassign + node.y = rescaleY(node._sim.y ?? 0); } }); @@ -284,7 +283,7 @@ export class ForceDirectedGraphController extends GraphController { const nodes = (this._cachedMeta._parsed as ITreeSimNode[]).map((node, i) => { const simNode: ITreeSimNode['_sim'] = { ...node }; simNode.index = i; - // eslint-disable-next-line no-param-reassign + node._sim = simNode; if (!node.reset) { return simNode; @@ -308,7 +307,7 @@ export class ForceDirectedGraphController extends GraphController { const nodes = (meta._parsed as ITreeSimNode[]).map((node, i) => { const simNode: ITreeSimNode['_sim'] = { ...node }; simNode.index = i; - // eslint-disable-next-line no-param-reassign + node._sim = simNode; if (simNode.x === null) { delete simNode.x; @@ -317,7 +316,6 @@ export class ForceDirectedGraphController extends GraphController { delete simNode.y; } if (simNode.x == null && simNode.y == null) { - // eslint-disable-next-line no-param-reassign node.reset = true; } return simNode; diff --git a/src/controllers/GraphController.ts b/src/controllers/GraphController.ts index 3e568cd..e967c07 100644 --- a/src/controllers/GraphController.ts +++ b/src/controllers/GraphController.ts @@ -234,7 +234,7 @@ export class GraphController extends ScatterController { this.getDataset = () => { return new Proxy(dataset, { get(obj: any, prop: string) { - return prop === 'data' ? obj.edges ?? [] : obj[prop]; + return prop === 'data' ? (obj.edges ?? []) : obj[prop]; }, }); }; @@ -259,8 +259,8 @@ export class GraphController extends ScatterController { }; function copyPoint(point: { x: number; y: number; angle?: number }) { - const x = reset ? base.x : xScale?.getPixelForValue(point.x, 0) ?? 0; - const y = reset ? base.y : yScale?.getPixelForValue(point.y, 0) ?? 0; + const x = reset ? base.x : (xScale?.getPixelForValue(point.x, 0) ?? 0); + const y = reset ? base.y : (yScale?.getPixelForValue(point.y, 0) ?? 0); return { x, y, @@ -301,7 +301,7 @@ export class GraphController extends ScatterController { /** * @hidden */ - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + updateEdgeElement(edge: EdgeLine, index: number, properties: any, mode: UpdateMode): void { super.updateElement(edge as unknown as Element, index, properties, mode); } @@ -309,12 +309,12 @@ export class GraphController extends ScatterController { /** * @hidden */ - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + updateElement(point: Element, index: number, properties: any, mode: UpdateMode): void { if (mode === 'reset') { // start in center also in x const { xScale } = this._cachedMeta; - // eslint-disable-next-line no-param-reassign + properties.x = xScale?.getBasePixel() ?? 0; } super.updateElement(point, index, properties, mode); @@ -345,7 +345,6 @@ export class GraphController extends ScatterController { return index; } - // eslint-disable-next-line no-console console.warn('cannot resolve edge ref', ref); return -1; } @@ -501,7 +500,6 @@ export class GraphController extends ScatterController { meta.edges = metaData; for (let i = 0; i < edges.length; i += 1) { - // eslint-disable-next-line new-cap metaData[i] = new this.edgeElementType(); } } @@ -515,7 +513,6 @@ export class GraphController extends ScatterController { const metaData = meta.edges || (meta.edges = []); for (let i = 0; i < edges.length; i += 1) { - // eslint-disable-next-line new-cap metaData[i] = metaData[i] || new this.edgeElementType(); } if (edges.length < metaData.length) { @@ -549,7 +546,6 @@ export class GraphController extends ScatterController { _insertEdgeElements(start: number, count: number): void { const elements = []; for (let i = 0; i < count; i += 1) { - // eslint-disable-next-line new-cap elements.push(new this.edgeElementType()); } (this._cachedMeta as unknown as IExtendedChartMeta).edges.splice(start, 0, ...elements); @@ -557,17 +553,14 @@ export class GraphController extends ScatterController { this._scheduleResyncLayout(); } - // eslint-disable-next-line class-methods-use-this reLayout(): void { // hook } - // eslint-disable-next-line class-methods-use-this resetLayout(): void { // hook } - // eslint-disable-next-line class-methods-use-this stopLayout(): void { // hook } @@ -585,7 +578,6 @@ export class GraphController extends ScatterController { }); } - // eslint-disable-next-line class-methods-use-this resyncLayout(): void { // hook } diff --git a/yarn.lock b/yarn.lock index d505661..4dd5194 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2231,6 +2231,7 @@ __metadata: canvas: "npm:^2.11.2" canvas-5-polyfill: "npm:^0.1.5" chart.js: "npm:^4.4.4" + chartjs-plugin-datalabels: "npm:^2.2.0" d3-dispatch: "npm:^3.0.1" d3-force: "npm:^3.0.0" d3-hierarchy: "npm:^3.1.2" @@ -2262,6 +2263,15 @@ __metadata: languageName: unknown linkType: soft +"chartjs-plugin-datalabels@npm:^2.2.0": + version: 2.2.0 + resolution: "chartjs-plugin-datalabels@npm:2.2.0" + peerDependencies: + chart.js: ">=3.0.0" + checksum: 10c0/de4855a795e4eef34869a16db1a8a0f905b6dfed0258c733338f472625361eb56fb899214b18651c1c1064cd343a78285ba576576693a40ec51285a84f022ea0 + languageName: node + linkType: hard + "check-error@npm:^2.1.1": version: 2.1.1 resolution: "check-error@npm:2.1.1"