@progress/kendo-charts 2.1.0 → 2.2.0-dev.202401301155

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.
@@ -26,6 +26,15 @@ var DonutPlotArea = (function (PiePlotArea) {
26
26
  this.appendChart(donutChart);
27
27
  };
28
28
 
29
+ // These were overriden in the Pie, so revert to original behavior
30
+ DonutPlotArea.prototype.getPointBelow = function getPointBelow (point) {
31
+ return this._getNextPoint(point, this._pointsByVertical, -1);
32
+ };
33
+
34
+ DonutPlotArea.prototype.getPointAbove = function getPointAbove (point) {
35
+ return this._getNextPoint(point, this._pointsByVertical, 1);
36
+ };
37
+
29
38
  return DonutPlotArea;
30
39
  }(PiePlotArea));
31
40
 
@@ -49,8 +49,12 @@ var FunnelPlotArea = (function (PlotAreaBase) {
49
49
  return this.pointsBySeriesIndex(basePoint.series.index);
50
50
  };
51
51
 
52
- FunnelPlotArea.prototype._pointsByHorizontal = function _pointsByHorizontal (basePoint) {
53
- return [basePoint];
52
+ FunnelPlotArea.prototype.getPointToTheRight = function getPointToTheRight (point) {
53
+ return this.getPointBelow(point);
54
+ };
55
+
56
+ FunnelPlotArea.prototype.getPointToTheLeft = function getPointToTheLeft (point) {
57
+ return this.getPointAbove(point);
54
58
  };
55
59
 
56
60
  return FunnelPlotArea;
@@ -34,6 +34,14 @@ var PiePlotArea = (function (PlotAreaBase) {
34
34
  append(this.options.legend.data, chart.legendItems);
35
35
  };
36
36
 
37
+ PiePlotArea.prototype.getPointBelow = function getPointBelow (point) {
38
+ return this.getPointToTheRight(point);
39
+ };
40
+
41
+ PiePlotArea.prototype.getPointAbove = function getPointAbove (point) {
42
+ return this.getPointToTheLeft(point);
43
+ };
44
+
37
45
  return PiePlotArea;
38
46
  }(PlotAreaBase));
39
47
 
@@ -1,10 +1,11 @@
1
1
  import { drawing } from '@progress/kendo-drawing';
2
- import { deepExtend, addClass, setDefaultOptions } from '../common';
2
+ import { deepExtend, addClass, setDefaultOptions, getSpacing } from '../common';
3
3
  import { calculateSankey } from './calculation';
4
4
  import { Node, resolveNodeOptions } from './node';
5
5
  import { Link, resolveLinkOptions } from './link';
6
6
  import { Label, resolveLabelOptions } from './label';
7
- import { LEFT } from '../common/constants';
7
+ import { Title } from './title';
8
+ import { CENTER, LEFT, TOP } from '../common/constants';
8
9
  import Box from '../core/box';
9
10
  import rectToBox from '../core/utils/rect-to-box';
10
11
  import { Observable } from '../common/observable';
@@ -205,12 +206,25 @@ export var Sankey = (function (Observable) {
205
206
  this.visual = this._render();
206
207
  };
207
208
 
209
+ Sankey.prototype.titleHeight = function titleHeight (title, totalWidth) {
210
+ if (!title.visible || !title.text) {
211
+ return 0;
212
+ }
213
+
214
+ var titleElement = new Title(deepExtend({}, { totalWidth: totalWidth }, title));
215
+ var titleVisual = titleElement.exportVisual();
216
+ return titleVisual.chartElement.box.height();
217
+ };
218
+
208
219
  Sankey.prototype.calculateSankey = function calculateSankey$1 (options) {
220
+ var title = this.options.title;
221
+ var titleHeight = this.titleHeight(title, options.width);
222
+
209
223
  var ref = this.options;
210
224
  var nodes = ref.nodes;
211
225
  var labels = ref.labels;
212
226
  var nodesColors = ref.nodesColors;
213
- var calculatedNodes = calculateSankey(options).nodes;
227
+ var calculatedNodes = calculateSankey(Object.assign({}, options, {offsetX: 0, offsetY: titleHeight})).nodes;
214
228
  var box = new Box();
215
229
 
216
230
  calculatedNodes.forEach(function (nodeEl, i) {
@@ -231,6 +245,9 @@ export var Sankey = (function (Observable) {
231
245
  var width = box.width() > options.width ? offsetX + options.width - (box.width() - options.width) : options.width;
232
246
  var height = box.height() > options.height ? offsetY + options.height - (box.height() - options.height) : options.height;
233
247
 
248
+ height -= titleHeight;
249
+ offsetY += title.position === TOP ? titleHeight : 0;
250
+
234
251
  return calculateSankey(Object.assign({}, options, {width: width, height: height, offsetX: offsetX, offsetY: offsetY}));
235
252
  };
236
253
 
@@ -241,16 +258,23 @@ export var Sankey = (function (Observable) {
241
258
  var nodesOptions = ref.nodes;
242
259
  var linkOptions = ref.links;
243
260
  var nodesColors = ref.nodesColors;
261
+ var title = ref.title;
244
262
  var ref$1 = this.size;
245
263
  var width = ref$1.width;
246
264
  var height = ref$1.height;
247
- var calcOptions = Object.assign({}, data, {width: width, height: height, nodesOptions: nodesOptions});
265
+ var calcOptions = Object.assign({}, data, {width: width, height: height, nodesOptions: nodesOptions, title: title});
248
266
  var ref$2 = this.calculateSankey(calcOptions);
249
267
  var nodes = ref$2.nodes;
250
268
  var links = ref$2.links;
251
269
 
252
270
  var visual = new drawing.Group();
253
271
 
272
+ if (title.visible && title.text) {
273
+ var titleElement = new Title(deepExtend({}, { wrapWidth: width, wrapHeight: height }, title));
274
+ var titleVisual = titleElement.exportVisual();
275
+ visual.append(titleVisual);
276
+ }
277
+
254
278
  var visualNodes = new Map();
255
279
 
256
280
  nodes.forEach(function (node, i) {
@@ -341,5 +365,16 @@ setDefaultOptions(Sankey, {
341
365
  opacity: 0.8,
342
366
  inactiveOpacity: 0.2
343
367
  }
344
- }
368
+ },
369
+ title: {
370
+ visible: true,
371
+ position: TOP,
372
+ align: CENTER,
373
+ opacity: 1,
374
+ border: {
375
+ width: 0
376
+ },
377
+ margin: getSpacing(5),
378
+ padding: getSpacing(5)
379
+ },
345
380
  });
@@ -0,0 +1,47 @@
1
+ import { SankeyElement } from "./element";
2
+ import { Title as CoreTitle } from "../core";
3
+ import Box from "../core/box";
4
+ import { deepExtend } from "../common";
5
+ import { BOTTOM } from "../common/constants";
6
+ import { getSpacing } from "../common";
7
+
8
+ export var Title = (function (SankeyElement) {
9
+ function Title () {
10
+ SankeyElement.apply(this, arguments);
11
+ }
12
+
13
+ if ( SankeyElement ) Title.__proto__ = SankeyElement;
14
+ Title.prototype = Object.create( SankeyElement && SankeyElement.prototype );
15
+ Title.prototype.constructor = Title;
16
+
17
+ Title.prototype.getElement = function getElement () {
18
+ var options = deepExtend({}, this.options, this.options.title);
19
+ var wrapWidth = options.wrapWidth;
20
+ var wrapHeight = options.wrapHeight;
21
+ var text = options.text;
22
+ var border = options.border;
23
+ var padding = getSpacing(options.padding);
24
+ var margin = getSpacing(options.margin);
25
+
26
+ if (!options.visible || !text) {
27
+ return null;
28
+ }
29
+
30
+ var title = CoreTitle.buildTitle(text, options);
31
+ var titleSizeBox = title.children[0].container.box;
32
+ var totalTitleHeight = margin.top + border.width + padding.top + titleSizeBox.height() + padding.bottom + border.width + margin.bottom;
33
+ var offsetTop = options.position === BOTTOM ? wrapHeight - totalTitleHeight : 0;
34
+ var titleRect = new Box(0, offsetTop, wrapWidth, offsetTop + totalTitleHeight);
35
+
36
+ title.reflow(titleRect);
37
+
38
+ title.renderVisual();
39
+ return title.visual;
40
+ };
41
+
42
+ Title.prototype.createElement = function createElement () {
43
+ return this.getElement();
44
+ };
45
+
46
+ return Title;
47
+ }(SankeyElement));
@@ -17,6 +17,15 @@ class DonutPlotArea extends PiePlotArea {
17
17
 
18
18
  this.appendChart(donutChart);
19
19
  }
20
+
21
+ // These were overriden in the Pie, so revert to original behavior
22
+ getPointBelow(point) {
23
+ return this._getNextPoint(point, this._pointsByVertical, -1);
24
+ }
25
+
26
+ getPointAbove(point) {
27
+ return this._getNextPoint(point, this._pointsByVertical, 1);
28
+ }
20
29
  }
21
30
 
22
31
  export default DonutPlotArea;
@@ -41,8 +41,12 @@ class FunnelPlotArea extends PlotAreaBase {
41
41
  return this.pointsBySeriesIndex(basePoint.series.index);
42
42
  }
43
43
 
44
- _pointsByHorizontal(basePoint) {
45
- return [basePoint];
44
+ getPointToTheRight(point) {
45
+ return this.getPointBelow(point);
46
+ }
47
+
48
+ getPointToTheLeft(point) {
49
+ return this.getPointAbove(point);
46
50
  }
47
51
  }
48
52
 
@@ -25,6 +25,14 @@ class PiePlotArea extends PlotAreaBase {
25
25
  super.appendChart(chart, pane);
26
26
  append(this.options.legend.data, chart.legendItems);
27
27
  }
28
+
29
+ getPointBelow(point) {
30
+ return this.getPointToTheRight(point);
31
+ }
32
+
33
+ getPointAbove(point) {
34
+ return this.getPointToTheLeft(point);
35
+ }
28
36
  }
29
37
 
30
38
  export default PiePlotArea;
@@ -1,10 +1,11 @@
1
1
  import { drawing } from '@progress/kendo-drawing';
2
- import { deepExtend, addClass, setDefaultOptions } from '../common';
2
+ import { deepExtend, addClass, setDefaultOptions, getSpacing } from '../common';
3
3
  import { calculateSankey } from './calculation';
4
4
  import { Node, resolveNodeOptions } from './node';
5
5
  import { Link, resolveLinkOptions } from './link';
6
6
  import { Label, resolveLabelOptions } from './label';
7
- import { LEFT } from '../common/constants';
7
+ import { Title } from './title';
8
+ import { CENTER, LEFT, TOP } from '../common/constants';
8
9
  import Box from '../core/box';
9
10
  import rectToBox from '../core/utils/rect-to-box';
10
11
  import { Observable } from '../common/observable';
@@ -190,9 +191,22 @@ export class Sankey extends Observable {
190
191
  this.visual = this._render();
191
192
  }
192
193
 
194
+ titleHeight(title, totalWidth) {
195
+ if (!title.visible || !title.text) {
196
+ return 0;
197
+ }
198
+
199
+ const titleElement = new Title(deepExtend({}, { totalWidth }, title));
200
+ const titleVisual = titleElement.exportVisual();
201
+ return titleVisual.chartElement.box.height();
202
+ }
203
+
193
204
  calculateSankey(options) {
205
+ const title = this.options.title;
206
+ const titleHeight = this.titleHeight(title, options.width);
207
+
194
208
  const { nodes, labels, nodesColors } = this.options;
195
- const calculatedNodes = calculateSankey(options).nodes;
209
+ const calculatedNodes = calculateSankey(Object.assign({}, options, {offsetX: 0, offsetY: titleHeight})).nodes;
196
210
  const box = new Box();
197
211
 
198
212
  calculatedNodes.forEach((nodeEl, i) => {
@@ -208,22 +222,31 @@ export class Sankey extends Observable {
208
222
  });
209
223
 
210
224
  const offsetX = box.x1 < 0 ? -box.x1 : 0;
211
- const offsetY = box.y1 < 0 ? -box.y1 : 0;
225
+ let offsetY = box.y1 < 0 ? -box.y1 : 0;
212
226
 
213
227
  const width = box.width() > options.width ? offsetX + options.width - (box.width() - options.width) : options.width;
214
- const height = box.height() > options.height ? offsetY + options.height - (box.height() - options.height) : options.height;
228
+ let height = box.height() > options.height ? offsetY + options.height - (box.height() - options.height) : options.height;
229
+
230
+ height -= titleHeight;
231
+ offsetY += title.position === TOP ? titleHeight : 0;
215
232
 
216
233
  return calculateSankey(Object.assign({}, options, {width, height, offsetX, offsetY}));
217
234
  }
218
235
 
219
236
  _render() {
220
- const { data, labels: labelOptions, nodes: nodesOptions, links: linkOptions, nodesColors } = this.options;
237
+ const { data, labels: labelOptions, nodes: nodesOptions, links: linkOptions, nodesColors, title } = this.options;
221
238
  const { width, height } = this.size;
222
- const calcOptions = Object.assign({}, data, {width, height, nodesOptions});
239
+ const calcOptions = Object.assign({}, data, {width, height, nodesOptions, title});
223
240
  let { nodes, links } = this.calculateSankey(calcOptions);
224
241
 
225
242
  const visual = new drawing.Group();
226
243
 
244
+ if (title.visible && title.text) {
245
+ const titleElement = new Title(deepExtend({}, { wrapWidth: width, wrapHeight: height }, title));
246
+ const titleVisual = titleElement.exportVisual();
247
+ visual.append(titleVisual);
248
+ }
249
+
227
250
  const visualNodes = new Map();
228
251
 
229
252
  nodes.forEach((node, i) => {
@@ -311,5 +334,16 @@ setDefaultOptions(Sankey, {
311
334
  opacity: 0.8,
312
335
  inactiveOpacity: 0.2
313
336
  }
314
- }
337
+ },
338
+ title: {
339
+ visible: true,
340
+ position: TOP,
341
+ align: CENTER,
342
+ opacity: 1,
343
+ border: {
344
+ width: 0
345
+ },
346
+ margin: getSpacing(5),
347
+ padding: getSpacing(5)
348
+ },
315
349
  });
@@ -0,0 +1,34 @@
1
+ import { SankeyElement } from "./element";
2
+ import { Title as CoreTitle } from "../core";
3
+ import Box from "../core/box";
4
+ import { deepExtend } from "../common";
5
+ import { BOTTOM } from "../common/constants";
6
+ import { getSpacing } from "../common";
7
+
8
+ export class Title extends SankeyElement {
9
+ getElement() {
10
+ const options = deepExtend({}, this.options, this.options.title);
11
+ const { wrapWidth, wrapHeight, text, border } = options;
12
+ const padding = getSpacing(options.padding);
13
+ const margin = getSpacing(options.margin);
14
+
15
+ if (!options.visible || !text) {
16
+ return null;
17
+ }
18
+
19
+ const title = CoreTitle.buildTitle(text, options);
20
+ const titleSizeBox = title.children[0].container.box;
21
+ const totalTitleHeight = margin.top + border.width + padding.top + titleSizeBox.height() + padding.bottom + border.width + margin.bottom;
22
+ const offsetTop = options.position === BOTTOM ? wrapHeight - totalTitleHeight : 0;
23
+ const titleRect = new Box(0, offsetTop, wrapWidth, offsetTop + totalTitleHeight);
24
+
25
+ title.reflow(titleRect);
26
+
27
+ title.renderVisual();
28
+ return title.visual;
29
+ }
30
+
31
+ createElement() {
32
+ return this.getElement();
33
+ }
34
+ }