@progress/kendo-charts 2.3.0-dev.202402161236 → 2.3.0-dev.202402161315

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { drawing } from '@progress/kendo-drawing';
1
+ import { geometry, drawing } from '@progress/kendo-drawing';
2
2
  import { deepExtend, addClass, setDefaultOptions } from '../common';
3
3
  import { calculateSankey } from './calculation';
4
4
  import { Node, resolveNodeOptions } from './node';
@@ -10,6 +10,7 @@ import Box from '../core/box';
10
10
  import rectToBox from '../core/utils/rect-to-box';
11
11
  import { Observable } from '../common/observable';
12
12
  import { Legend } from './legend';
13
+ import { defined } from '../drawing-utils';
13
14
 
14
15
  var LINK = 'link';
15
16
  var NODE = 'node';
@@ -257,17 +258,15 @@ export var Sankey = (function (Observable) {
257
258
  return legendVisual.chartElement.box;
258
259
  };
259
260
 
260
- Sankey.prototype.calculateSankey = function calculateSankey$1 (options) {
261
- var ref = this.options;
262
- var title = ref.title;
263
- var legend = ref.legend;
264
- var data = ref.data;
265
- var ref$1 = this.options;
266
- var nodes = ref$1.nodes;
267
- var labels = ref$1.labels;
268
- var nodesColors = ref$1.nodesColors;
269
-
270
- var sankeyBox = new Box(0, 0, options.width, options.height);
261
+ Sankey.prototype.calculateSankey = function calculateSankey$1 (calcOptions, sankeyOptions) {
262
+ var title = sankeyOptions.title;
263
+ var legend = sankeyOptions.legend;
264
+ var data = sankeyOptions.data;
265
+ var nodes = sankeyOptions.nodes;
266
+ var labels = sankeyOptions.labels;
267
+ var nodesColors = sankeyOptions.nodesColors;
268
+
269
+ var sankeyBox = new Box(0, 0, calcOptions.width, calcOptions.height);
271
270
  var titleBox = this.titleBox(title, sankeyBox);
272
271
 
273
272
  var legendArea = sankeyBox.clone();
@@ -276,10 +275,10 @@ export var Sankey = (function (Observable) {
276
275
  var titleHeight = titleBox.height();
277
276
  if (title.position === TOP) {
278
277
  sankeyBox.unpad({ top: titleHeight });
279
- legendArea = new Box(0, titleHeight, options.width, options.height);
278
+ legendArea = new Box(0, titleHeight, calcOptions.width, calcOptions.height);
280
279
  } else {
281
280
  sankeyBox.shrink(0, titleHeight);
282
- legendArea = new Box(0, 0, options.width, options.height - titleHeight);
281
+ legendArea = new Box(0, 0, calcOptions.width, calcOptions.height - titleHeight);
283
282
  }
284
283
  }
285
284
 
@@ -303,7 +302,7 @@ export var Sankey = (function (Observable) {
303
302
  }
304
303
  }
305
304
 
306
- var calculatedNodes = calculateSankey(Object.assign({}, options, {offsetX: sankeyBox.x1, offsetY: sankeyBox.y1, width: sankeyBox.x2, height: sankeyBox.y2})).nodes;
305
+ var calculatedNodes = calculateSankey(Object.assign({}, calcOptions, {offsetX: sankeyBox.x1, offsetY: sankeyBox.y1, width: sankeyBox.x2, height: sankeyBox.y2})).nodes;
307
306
  var box = new Box();
308
307
 
309
308
  calculatedNodes.forEach(function (nodeEl, i) {
@@ -311,7 +310,7 @@ export var Sankey = (function (Observable) {
311
310
  var nodeInstance = new Node(nodeOps);
312
311
  box.wrap(rectToBox(nodeInstance.exportVisual().rawBBox()));
313
312
 
314
- var labelInstance = new Label(deepExtend({ node: nodeEl, totalWidth: options.width }, labels));
313
+ var labelInstance = new Label(deepExtend({ node: nodeEl, totalWidth: calcOptions.width }, labels));
315
314
  var labelVisual = labelInstance.exportVisual();
316
315
  if (labelVisual) {
317
316
  box.wrap(rectToBox(labelVisual.rawBBox()));
@@ -325,33 +324,38 @@ export var Sankey = (function (Observable) {
325
324
  var height = box.height() > sankeyBox.y2 ? offsetY + sankeyBox.y2 - (box.height() - sankeyBox.y2) : sankeyBox.y2;
326
325
 
327
326
  return {
328
- sankey: calculateSankey(Object.assign({}, options, {offsetX: offsetX, offsetY: offsetY, width: width, height: height})),
327
+ sankey: calculateSankey(Object.assign({}, calcOptions, {offsetX: offsetX, offsetY: offsetY, width: width, height: height})),
329
328
  legendBox: legendBox,
330
329
  titleBox: titleBox
331
330
  };
332
331
  };
333
332
 
334
- Sankey.prototype._render = function _render () {
335
- var ref = this.options;
336
- var data = ref.data;
337
- var labelOptions = ref.labels;
338
- var nodesOptions = ref.nodes;
339
- var linkOptions = ref.links;
340
- var nodesColors = ref.nodesColors;
341
- var title = ref.title;
342
- var legend = ref.legend;
343
- var ref$1 = this.size;
344
- var width = ref$1.width;
345
- var height = ref$1.height;
333
+ Sankey.prototype._render = function _render (options, context) {
334
+ var sankeyOptions = options || this.options;
335
+ var sankeyContext = context || this;
336
+
337
+ var data = sankeyOptions.data;
338
+ var labelOptions = sankeyOptions.labels;
339
+ var nodesOptions = sankeyOptions.nodes;
340
+ var linkOptions = sankeyOptions.links;
341
+ var nodesColors = sankeyOptions.nodesColors;
342
+ var title = sankeyOptions.title;
343
+ var legend = sankeyOptions.legend;
344
+ var ref = sankeyContext.size;
345
+ var width = ref.width;
346
+ var height = ref.height;
347
+
346
348
  var calcOptions = Object.assign({}, data, {width: width, height: height, nodesOptions: nodesOptions, title: title, legend: legend});
347
- var ref$2 = this.calculateSankey(calcOptions);
348
- var sankey = ref$2.sankey;
349
- var titleBox = ref$2.titleBox;
350
- var legendBox = ref$2.legendBox;
349
+ var ref$1 = this.calculateSankey(calcOptions, sankeyOptions);
350
+ var sankey = ref$1.sankey;
351
+ var titleBox = ref$1.titleBox;
352
+ var legendBox = ref$1.legendBox;
351
353
  var nodes = sankey.nodes;
352
354
  var links = sankey.links;
353
355
 
354
- var visual = new drawing.Group();
356
+ var visual = new drawing.Group({
357
+ clip: drawing.Path.fromRect(new geometry.Rect([0, 0], [width, height]))
358
+ });
355
359
 
356
360
  if (titleBox) {
357
361
  var titleElement = new Title(Object.assign({}, title, {drawingRect: titleBox}));
@@ -366,6 +370,7 @@ export var Sankey = (function (Observable) {
366
370
  }
367
371
 
368
372
  var visualNodes = new Map();
373
+ sankeyContext.nodesVisuals = visualNodes;
369
374
 
370
375
  nodes.forEach(function (node, i) {
371
376
  var nodeOps = resolveNodeOptions(node, nodesOptions, nodesColors, i);
@@ -388,6 +393,7 @@ export var Sankey = (function (Observable) {
388
393
  var sortedLinks = links.slice().sort(function (a, b) { return b.value - a.value; });
389
394
 
390
395
  var linksVisuals = [];
396
+ sankeyContext.linksVisuals = linksVisuals;
391
397
 
392
398
  sortedLinks.forEach(function (link) {
393
399
  var source = link.source;
@@ -412,9 +418,6 @@ export var Sankey = (function (Observable) {
412
418
  visual.append(linkVisual);
413
419
  });
414
420
 
415
- this.linksVisuals = linksVisuals;
416
- this.nodesVisuals = visualNodes;
417
-
418
421
  nodes.forEach(function (node) {
419
422
  var textOps = resolveLabelOptions(node, labelOptions, width);
420
423
  var labelInstance = new Label(textOps);
@@ -428,8 +431,18 @@ export var Sankey = (function (Observable) {
428
431
  return visual;
429
432
  };
430
433
 
431
- Sankey.prototype.exportVisual = function exportVisual () {
432
- return this._render();
434
+ Sankey.prototype.exportVisual = function exportVisual (exportOptions) {
435
+ var options = (exportOptions && exportOptions.options) ?
436
+ deepExtend({}, this.options, exportOptions.options) : this.options;
437
+
438
+ var context = {
439
+ size: {
440
+ width: defined(exportOptions && exportOptions.width) ? exportOptions.width : this.size.width,
441
+ height: defined(exportOptions && exportOptions.height) ? exportOptions.height : this.size.height
442
+ }
443
+ };
444
+
445
+ return this._render(options, context);
433
446
  };
434
447
 
435
448
  Sankey.prototype._setOptions = function _setOptions (options) {
@@ -1,4 +1,4 @@
1
- import { drawing } from '@progress/kendo-drawing';
1
+ import { geometry, drawing } from '@progress/kendo-drawing';
2
2
  import { deepExtend, addClass, setDefaultOptions } from '../common';
3
3
  import { calculateSankey } from './calculation';
4
4
  import { Node, resolveNodeOptions } from './node';
@@ -10,6 +10,7 @@ import Box from '../core/box';
10
10
  import rectToBox from '../core/utils/rect-to-box';
11
11
  import { Observable } from '../common/observable';
12
12
  import { Legend } from './legend';
13
+ import { defined } from '../drawing-utils';
13
14
 
14
15
  const LINK = 'link';
15
16
  const NODE = 'node';
@@ -242,11 +243,10 @@ export class Sankey extends Observable {
242
243
  return legendVisual.chartElement.box;
243
244
  }
244
245
 
245
- calculateSankey(options) {
246
- const { title, legend, data } = this.options;
247
- const { nodes, labels, nodesColors } = this.options;
246
+ calculateSankey(calcOptions, sankeyOptions) {
247
+ const { title, legend, data, nodes, labels, nodesColors } = sankeyOptions;
248
248
 
249
- const sankeyBox = new Box(0, 0, options.width, options.height);
249
+ const sankeyBox = new Box(0, 0, calcOptions.width, calcOptions.height);
250
250
  const titleBox = this.titleBox(title, sankeyBox);
251
251
 
252
252
  let legendArea = sankeyBox.clone();
@@ -255,10 +255,10 @@ export class Sankey extends Observable {
255
255
  const titleHeight = titleBox.height();
256
256
  if (title.position === TOP) {
257
257
  sankeyBox.unpad({ top: titleHeight });
258
- legendArea = new Box(0, titleHeight, options.width, options.height);
258
+ legendArea = new Box(0, titleHeight, calcOptions.width, calcOptions.height);
259
259
  } else {
260
260
  sankeyBox.shrink(0, titleHeight);
261
- legendArea = new Box(0, 0, options.width, options.height - titleHeight);
261
+ legendArea = new Box(0, 0, calcOptions.width, calcOptions.height - titleHeight);
262
262
  }
263
263
  }
264
264
 
@@ -282,7 +282,7 @@ export class Sankey extends Observable {
282
282
  }
283
283
  }
284
284
 
285
- const calculatedNodes = calculateSankey(Object.assign({}, options, {offsetX: sankeyBox.x1, offsetY: sankeyBox.y1, width: sankeyBox.x2, height: sankeyBox.y2})).nodes;
285
+ const calculatedNodes = calculateSankey(Object.assign({}, calcOptions, {offsetX: sankeyBox.x1, offsetY: sankeyBox.y1, width: sankeyBox.x2, height: sankeyBox.y2})).nodes;
286
286
  const box = new Box();
287
287
 
288
288
  calculatedNodes.forEach((nodeEl, i) => {
@@ -290,7 +290,7 @@ export class Sankey extends Observable {
290
290
  const nodeInstance = new Node(nodeOps);
291
291
  box.wrap(rectToBox(nodeInstance.exportVisual().rawBBox()));
292
292
 
293
- const labelInstance = new Label(deepExtend({ node: nodeEl, totalWidth: options.width }, labels));
293
+ const labelInstance = new Label(deepExtend({ node: nodeEl, totalWidth: calcOptions.width }, labels));
294
294
  const labelVisual = labelInstance.exportVisual();
295
295
  if (labelVisual) {
296
296
  box.wrap(rectToBox(labelVisual.rawBBox()));
@@ -304,20 +304,26 @@ export class Sankey extends Observable {
304
304
  let height = box.height() > sankeyBox.y2 ? offsetY + sankeyBox.y2 - (box.height() - sankeyBox.y2) : sankeyBox.y2;
305
305
 
306
306
  return {
307
- sankey: calculateSankey(Object.assign({}, options, {offsetX, offsetY, width, height})),
307
+ sankey: calculateSankey(Object.assign({}, calcOptions, {offsetX, offsetY, width, height})),
308
308
  legendBox,
309
309
  titleBox
310
310
  };
311
311
  }
312
312
 
313
- _render() {
314
- const { data, labels: labelOptions, nodes: nodesOptions, links: linkOptions, nodesColors, title, legend } = this.options;
315
- const { width, height } = this.size;
313
+ _render(options, context) {
314
+ const sankeyOptions = options || this.options;
315
+ const sankeyContext = context || this;
316
+
317
+ const { data, labels: labelOptions, nodes: nodesOptions, links: linkOptions, nodesColors, title, legend } = sankeyOptions;
318
+ const { width, height } = sankeyContext.size;
319
+
316
320
  const calcOptions = Object.assign({}, data, {width, height, nodesOptions, title, legend});
317
- const { sankey, titleBox, legendBox } = this.calculateSankey(calcOptions);
321
+ const { sankey, titleBox, legendBox } = this.calculateSankey(calcOptions, sankeyOptions);
318
322
  const { nodes, links } = sankey;
319
323
 
320
- const visual = new drawing.Group();
324
+ const visual = new drawing.Group({
325
+ clip: drawing.Path.fromRect(new geometry.Rect([0, 0], [width, height]))
326
+ });
321
327
 
322
328
  if (titleBox) {
323
329
  const titleElement = new Title(Object.assign({}, title, {drawingRect: titleBox}));
@@ -332,6 +338,7 @@ export class Sankey extends Observable {
332
338
  }
333
339
 
334
340
  const visualNodes = new Map();
341
+ sankeyContext.nodesVisuals = visualNodes;
335
342
 
336
343
  nodes.forEach((node, i) => {
337
344
  const nodeOps = resolveNodeOptions(node, nodesOptions, nodesColors, i);
@@ -354,6 +361,7 @@ export class Sankey extends Observable {
354
361
  const sortedLinks = links.slice().sort((a, b) => b.value - a.value);
355
362
 
356
363
  const linksVisuals = [];
364
+ sankeyContext.linksVisuals = linksVisuals;
357
365
 
358
366
  sortedLinks.forEach(link => {
359
367
  const { source, target } = link;
@@ -377,9 +385,6 @@ export class Sankey extends Observable {
377
385
  visual.append(linkVisual);
378
386
  });
379
387
 
380
- this.linksVisuals = linksVisuals;
381
- this.nodesVisuals = visualNodes;
382
-
383
388
  nodes.forEach((node) => {
384
389
  const textOps = resolveLabelOptions(node, labelOptions, width);
385
390
  const labelInstance = new Label(textOps);
@@ -393,8 +398,18 @@ export class Sankey extends Observable {
393
398
  return visual;
394
399
  }
395
400
 
396
- exportVisual() {
397
- return this._render();
401
+ exportVisual(exportOptions) {
402
+ const options = (exportOptions && exportOptions.options) ?
403
+ deepExtend({}, this.options, exportOptions.options) : this.options;
404
+
405
+ const context = {
406
+ size: {
407
+ width: defined(exportOptions && exportOptions.width) ? exportOptions.width : this.size.width,
408
+ height: defined(exportOptions && exportOptions.height) ? exportOptions.height : this.size.height
409
+ }
410
+ };
411
+
412
+ return this._render(options, context);
398
413
  }
399
414
 
400
415
  _setOptions(options) {