Skip to content

Commit fcfd781

Browse files
committed
Remove legacy code
1 parent 273039c commit fcfd781

File tree

1 file changed

+30
-43
lines changed

1 file changed

+30
-43
lines changed

src/controller.js

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,11 @@ export default class SankeyController extends DatasetController {
8181
* @return {Array<SankeyParsedData>}
8282
*/
8383
parseObjectData(meta, data, start, count) {
84-
// https://github.com/chartjs/Chart.js/pull/8379
85-
if (count === 0) {
86-
return [];
87-
}
88-
const me = this;
8984
const {xScale, yScale} = meta;
9085
const parsed = []; /* Array<SankeyParsedData> */
91-
const nodes = me._nodes = buildNodesFromRawData(data);
86+
const nodes = this._nodes = buildNodesFromRawData(data);
9287
/* getDataset() => SankeyControllerDatasetOptions */
93-
const {column, priority, size} = me.getDataset();
88+
const {column, priority, size} = this.getDataset();
9489
if (priority) {
9590
for (const node of nodes.values()) {
9691
if (node.key in priority) {
@@ -109,8 +104,8 @@ export default class SankeyController extends DatasetController {
109104

110105
const {maxX, maxY} = layout(nodes, data, !!priority, validateSizeValue(size));
111106

112-
me._maxX = maxX;
113-
me._maxY = maxY;
107+
this._maxX = maxX;
108+
this._maxY = maxY;
114109

115110
for (let i = 0, ilen = data.length; i < ilen; ++i) {
116111
const dataPoint = data[i];
@@ -134,18 +129,16 @@ export default class SankeyController extends DatasetController {
134129
}
135130

136131
getMinMax(scale) {
137-
const me = this;
138132
return {
139133
min: 0,
140-
max: scale === this._cachedMeta.xScale ? this._maxX : me._maxY
134+
max: scale === this._cachedMeta.xScale ? this._maxX : this._maxY
141135
};
142136
}
143137

144138
update(mode) {
145-
const me = this;
146-
const meta = me._cachedMeta;
139+
const {data} = this._cachedMeta;
147140

148-
me.updateElements(meta.data, 0, meta.data.length, mode);
141+
this.updateElements(data, 0, data.length, mode);
149142
}
150143

151144
/**
@@ -155,20 +148,19 @@ export default class SankeyController extends DatasetController {
155148
* @param {"resize" | "reset" | "none" | "hide" | "show" | "normal" | "active"} mode
156149
*/
157150
updateElements(elems, start, count, mode) {
158-
const me = this;
159-
const {xScale, yScale} = me._cachedMeta;
160-
const firstOpts = me.resolveDataElementOptions(start, mode);
161-
const sharedOptions = me.getSharedOptions(mode, elems[start], firstOpts);
162-
const dataset = me.getDataset();
151+
const {xScale, yScale} = this._cachedMeta;
152+
const firstOpts = this.resolveDataElementOptions(start, mode);
153+
const sharedOptions = this.getSharedOptions(mode, elems[start], firstOpts);
154+
const dataset = this.getDataset();
163155
const borderWidth = valueOrDefault(dataset.borderWidth, 1) / 2 + 0.5;
164156
const nodeWidth = valueOrDefault(dataset.nodeWidth, 10);
165157

166158
for (let i = start; i < start + count; i++) {
167159
/* getParsed(idx: number) => SankeyParsedData */
168-
const parsed = me.getParsed(i);
160+
const parsed = this.getParsed(i);
169161
const custom = parsed._custom;
170162
const y = yScale.getPixelForValue(parsed.y);
171-
me.updateElement(
163+
this.updateElement(
172164
elems[i],
173165
i,
174166
{
@@ -180,27 +172,26 @@ export default class SankeyController extends DatasetController {
180172
to: custom.to,
181173
progress: mode === 'reset' ? 0 : 1,
182174
height: Math.abs(yScale.getPixelForValue(parsed.y + custom.height) - y),
183-
options: me.resolveDataElementOptions(i, mode)
175+
options: this.resolveDataElementOptions(i, mode)
184176
},
185177
mode);
186178
}
187179

188-
me.updateSharedOptions(sharedOptions, mode);
180+
this.updateSharedOptions(sharedOptions, mode);
189181
}
190182

191183
_drawLabels() {
192-
const me = this;
193-
const ctx = me._ctx;
194-
const nodes = me._nodes || new Map();
195-
const dataset = me.getDataset(); /* SankeyControllerDatasetOptions */
184+
const ctx = this._ctx;
185+
const nodes = this._nodes || new Map();
186+
const dataset = this.getDataset(); /* SankeyControllerDatasetOptions */
196187
const size = validateSizeValue(dataset.size);
197188
const borderWidth = valueOrDefault(dataset.borderWidth, 1);
198189
const nodeWidth = valueOrDefault(dataset.nodeWidth, 10);
199190
const labels = dataset.labels;
200-
const {xScale, yScale} = me._cachedMeta;
191+
const {xScale, yScale} = this._cachedMeta;
201192

202193
ctx.save();
203-
const chartArea = me.chart.chartArea;
194+
const chartArea = this.chart.chartArea;
204195
for (const node of nodes.values()) {
205196
const x = xScale.getPixelForValue(node.x);
206197
const y = yScale.getPixelForValue(node.y);
@@ -232,13 +223,12 @@ export default class SankeyController extends DatasetController {
232223
* @private
233224
*/
234225
_drawLabel(label, y, height, ctx, textX) {
235-
const me = this;
236-
const font = toFont(me.options.font, me.chart.options.font);
226+
const font = toFont(this.options.font, this.chart.options.font);
237227
const lines = isNullOrUndef(label) ? [] : toTextLines(label);
238228
const linesLength = lines.length;
239229
const middle = y + height / 2;
240230
const textHeight = font.lineHeight;
241-
const padding = valueOrDefault(me.options.padding, textHeight / 2);
231+
const padding = valueOrDefault(this.options.padding, textHeight / 2);
242232

243233
ctx.font = font.string;
244234

@@ -253,12 +243,11 @@ export default class SankeyController extends DatasetController {
253243
}
254244

255245
_drawNodes() {
256-
const me = this;
257-
const ctx = me._ctx;
258-
const nodes = me._nodes || new Map();
259-
const dataset = me.getDataset(); /* SankeyControllerDatasetOptions */
246+
const ctx = this._ctx;
247+
const nodes = this._nodes || new Map();
248+
const dataset = this.getDataset(); /* SankeyControllerDatasetOptions */
260249
const size = validateSizeValue(dataset.size);
261-
const {xScale, yScale} = me._cachedMeta;
250+
const {xScale, yScale} = this._cachedMeta;
262251
const borderWidth = valueOrDefault(dataset.borderWidth, 1);
263252
const nodeWidth = valueOrDefault(dataset.nodeWidth, 10);
264253

@@ -285,9 +274,8 @@ export default class SankeyController extends DatasetController {
285274
* That's where the drawing process happens
286275
*/
287276
draw() {
288-
const me = this;
289-
const ctx = me._ctx;
290-
const data = me.getMeta().data || []; /* Array<Flow> */
277+
const ctx = this._ctx;
278+
const data = this.getMeta().data || []; /* Array<Flow> */
291279

292280
for (let i = 0, ilen = data.length; i < ilen; ++i) {
293281
const flow = data[i]; /* Flow at index i */
@@ -296,15 +284,15 @@ export default class SankeyController extends DatasetController {
296284
}
297285

298286
/* draw SankeyNodes on the canvas */
299-
me._drawNodes();
287+
this._drawNodes();
300288

301289
/* draw Flow elements on the canvas */
302290
for (let i = 0, ilen = data.length; i < ilen; ++i) {
303291
data[i].draw(ctx);
304292
}
305293

306294
/* draw labels (for SankeyNodes) on the canvas */
307-
me._drawLabels();
295+
this._drawLabels();
308296
}
309297
}
310298

@@ -355,7 +343,6 @@ SankeyController.overrides = {
355343
intersect: true
356344
},
357345
datasets: {
358-
color: () => '#efefef',
359346
clip: false,
360347
parsing: true
361348
},

0 commit comments

Comments
 (0)