@progress/kendo-charts 2.4.0-dev.202405201104 → 2.4.0-dev.202405211537

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.
@@ -251,7 +251,7 @@ var LegendItem = (function (BoxElement) {
251
251
 
252
252
  if (this.options.visible) {
253
253
  var accessibilityOptions = deepExtend({
254
- ariaLabel: options.text
254
+ ariaLabel: options.accessibility.ariaLabel !== undefined ? options.accessibility.ariaLabel : options.text
255
255
  }, options.accessibility);
256
256
 
257
257
  addAccessibilityAttributesToVisual(this.visual, accessibilityOptions);
@@ -64,6 +64,11 @@ setDefaultOptions(Legend, {
64
64
  },
65
65
  position: BOTTOM,
66
66
  align: CENTER,
67
+ accessibility: {
68
+ role: 'presentation',
69
+ ariaLabel: null,
70
+ ariaRoleDescription: null
71
+ },
67
72
  border: {
68
73
  width: 0
69
74
  }
@@ -2,6 +2,82 @@ import { drawing } from '@progress/kendo-drawing';
2
2
  import { SankeyElement } from './element';
3
3
  import { deepExtend } from '../common';
4
4
  import { defined } from '../drawing-utils';
5
+ import { ARIA_ACTIVE_DESCENDANT } from '../common/constants';
6
+
7
+ var distanceToLine = function (line, point) {
8
+ var ref = line[0];
9
+ var x1 = ref[0];
10
+ var y1 = ref[1];
11
+ var ref$1 = line[1];
12
+ var x2 = ref$1[0];
13
+ var y2 = ref$1[1];
14
+ var x3 = point[0];
15
+ var y3 = point[1];
16
+
17
+ return Math.abs((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / Math.sqrt(Math.pow( (x2 - x1), 2 ) + Math.pow( (y2 - y1), 2 ));
18
+ };
19
+
20
+ var bezierPoint = function (p1, p2, p3, p4, t) {
21
+ var t1 = 1 - t;
22
+ var t1t1 = t1 * t1;
23
+ var tt = t * t;
24
+ return (p1 * t1t1 * t1) + (3 * p2 * t * t1t1) + (3 * p3 * tt * t1) + (p4 * tt * t);
25
+ };
26
+
27
+ var angelBetweenTwoLines = function (line1, line2) {
28
+ var ref = line1[0];
29
+ var x1 = ref[0];
30
+ var y1 = ref[1];
31
+ var ref$1 = line1[1];
32
+ var x2 = ref$1[0];
33
+ var y2 = ref$1[1];
34
+ var ref$2 = line2[0];
35
+ var x3 = ref$2[0];
36
+ var y3 = ref$2[1];
37
+ var ref$3 = line2[1];
38
+ var x4 = ref$3[0];
39
+ var y4 = ref$3[1];
40
+
41
+ var a1 = Math.atan2(y2 - y1, x2 - x1);
42
+ var a2 = Math.atan2(y4 - y3, x4 - x3);
43
+
44
+ return Math.abs(a1 - a2);
45
+ };
46
+
47
+ var calculateControlPointsOffsetX = function (link) {
48
+ var x0 = link.x0;
49
+ var x1 = link.x1;
50
+ var y0 = link.y0;
51
+ var y1 = link.y1;
52
+ var xC = (x0 + x1) / 2;
53
+
54
+ var width = link.width;
55
+ var halfWidth = width / 2;
56
+
57
+ // upper curve, t = 0.5
58
+ var upperCurveMiddleLine = [[(x0 + xC) / 2, y0 - halfWidth], [(x1 + xC) / 2, y1 - halfWidth]];
59
+
60
+ // for lower curve, bezier-point at t = 0.5
61
+ // for the case t = 0.5, the bezier-point is the middle point of the curve. => ((y0 + halfWidth) + (y1 + halfWidth)) / 2
62
+ var lowerCurveMiddlePoint = [xC, bezierPoint(y0 + halfWidth, y0 + halfWidth, y1 + halfWidth, y1 + halfWidth, 0.5)];
63
+
64
+ // The actual width of the link at its middle point as can be seen on the screen.
65
+ var actualWidth = distanceToLine(upperCurveMiddleLine, lowerCurveMiddlePoint);
66
+
67
+ var upperNarrowness = (width - actualWidth) / 2;
68
+
69
+ // The line `upperCurveMiddleLine` shows the upper border of the link.
70
+ // Assumption 1: Translated to the left to the desired link width and the translate value will be the `offset`.
71
+ // Assumption 2: The translate value is a hypotenuse of a triangle.
72
+ var alpha = angelBetweenTwoLines(upperCurveMiddleLine, [[x0, y0 - halfWidth], [xC, y0 - halfWidth]]);
73
+ var a = upperNarrowness;
74
+ var b = Math.sin(alpha) * a;
75
+ var offset = Math.sqrt(a * a + b * b);
76
+ // Another option is to assume the triangle is isosceles
77
+ // => offset = Math.sqrt(2) * upperNarrowness;
78
+
79
+ return y0 - y1 > 0 ? (-1) * offset : offset;
80
+ };
5
81
 
6
82
  export var Link = (function (SankeyElement) {
7
83
  function Link () {
@@ -24,18 +100,80 @@ export var Link = (function (SankeyElement) {
24
100
  .moveTo(x0, y0).curveTo([xC, y0], [xC, y1], [x1, y1]);
25
101
  };
26
102
 
103
+ Link.prototype.getLabelText = function getLabelText (options) {
104
+ var labelTemplate = options.labels.ariaTemplate;
105
+
106
+ if (labelTemplate) {
107
+ return labelTemplate({ link: options.link });
108
+ }
109
+ };
110
+
27
111
  Link.prototype.visualOptions = function visualOptions () {
28
112
  var options = this.options;
29
113
  var link = this.options.link;
114
+ var ariaLabel = this.getLabelText(options);
115
+
30
116
  return {
31
117
  stroke: {
32
118
  width: options.link.width,
33
119
  color: link.color || options.color,
34
120
  opacity: defined(link.opacity) ? link.opacity : options.opacity
35
- }
121
+ },
122
+ role: 'graphics-symbol',
123
+ ariaRoleDescription: 'Link',
124
+ ariaLabel: ariaLabel
36
125
  };
37
126
  };
38
127
 
128
+ Link.prototype.createFocusHighlight = function createFocusHighlight () {
129
+ if (!this.options.navigatable) {
130
+ return;
131
+ }
132
+ var link = this.options.link;
133
+ var x0 = link.x0;
134
+ var x1 = link.x1;
135
+ var y0 = link.y0;
136
+ var y1 = link.y1;
137
+ var xC = (x0 + x1) / 2;
138
+ var halfWidth = link.width / 2;
139
+
140
+ var offset = calculateControlPointsOffsetX(link);
141
+
142
+ this._highlight = new drawing.Path({ stroke: this.options.focusHighlight, visible: false })
143
+ .moveTo(x0, y0 + halfWidth)
144
+ .lineTo(x0, y0 - halfWidth)
145
+ .curveTo([xC + offset, y0 - halfWidth], [xC + offset, y1 - halfWidth], [x1, y1 - halfWidth])
146
+ .lineTo(x1, y1 + halfWidth)
147
+ .curveTo([xC - offset, y1 + halfWidth], [xC - offset, y0 + halfWidth], [x0, y0 + halfWidth]);
148
+ };
149
+
150
+ Link.prototype.focus = function focus (options) {
151
+ if (this._highlight) {
152
+ var ref = options || {};
153
+ var highlight = ref.highlight; if ( highlight === void 0 ) highlight = true;
154
+ if (highlight) {
155
+ this._highlight.options.set('visible', true);
156
+ }
157
+ var id = (this.options.link.sourceId) + "->" + (this.options.link.targetId);
158
+ this.visual.options.set('id', id);
159
+
160
+ if (this.options.root()) {
161
+ this.options.root().setAttribute(ARIA_ACTIVE_DESCENDANT, id);
162
+ }
163
+ }
164
+ };
165
+
166
+ Link.prototype.blur = function blur () {
167
+ if (this._highlight) {
168
+ this._highlight.options.set('visible', false);
169
+ this.visual.options.set('id', '');
170
+
171
+ if (this.options.root()) {
172
+ this.options.root().removeAttribute(ARIA_ACTIVE_DESCENDANT);
173
+ }
174
+ }
175
+ };
176
+
39
177
  return Link;
40
178
  }(SankeyElement));
41
179
 
@@ -1,6 +1,7 @@
1
1
  import { geometry, drawing } from '@progress/kendo-drawing';
2
2
  import { SankeyElement } from './element';
3
3
  import { deepExtend } from '../common';
4
+ import { ARIA_ACTIVE_DESCENDANT } from '../common/constants';
4
5
 
5
6
  export var Node = (function (SankeyElement) {
6
7
  function Node () {
@@ -12,15 +13,25 @@ export var Node = (function (SankeyElement) {
12
13
  Node.prototype.constructor = Node;
13
14
 
14
15
  Node.prototype.getElement = function getElement () {
15
- var options = this.options;
16
- var node = options.node;
17
- var rect = new geometry.Rect([node.x0, node.y0], [node.x1 - node.x0, node.y1 - node.y0]);
16
+ return drawing.Path.fromRect(this.getRect(), this.visualOptions());
17
+ };
18
+
19
+ Node.prototype.getRect = function getRect () {
20
+ var node = this.options.node;
21
+ return new geometry.Rect([node.x0, node.y0], [node.x1 - node.x0, node.y1 - node.y0]);
22
+ };
18
23
 
19
- return drawing.Path.fromRect(rect, this.visualOptions());
24
+ Node.prototype.getLabelText = function getLabelText (options) {
25
+ var labelTemplate = options.labels.ariaTemplate;
26
+
27
+ if (labelTemplate) {
28
+ return labelTemplate({ node: options.node });
29
+ }
20
30
  };
21
31
 
22
32
  Node.prototype.visualOptions = function visualOptions () {
23
33
  var options = deepExtend({}, this.options, this.options.node);
34
+ var ariaLabel = this.getLabelText(options);
24
35
 
25
36
  return {
26
37
  fill: {
@@ -31,10 +42,50 @@ export var Node = (function (SankeyElement) {
31
42
  className: 'k-sankey-node',
32
43
  role: 'graphics-symbol',
33
44
  ariaRoleDescription: 'Node',
34
- ariaLabel: options.node.label.text
45
+ ariaLabel: ariaLabel
35
46
  };
36
47
  };
37
48
 
49
+ Node.prototype.createFocusHighlight = function createFocusHighlight () {
50
+ if (!this.options.navigatable) {
51
+ return;
52
+ }
53
+
54
+ this._highlight = new drawing.Path.fromRect(this.getRect(), {
55
+ stroke: this.options.focusHighlight,
56
+ visible: false
57
+ });
58
+
59
+ return this._highlight;
60
+ };
61
+
62
+ Node.prototype.focus = function focus (options) {
63
+ if (this._highlight) {
64
+ var ref = options || {};
65
+ var highlight = ref.highlight; if ( highlight === void 0 ) highlight = true;
66
+ if (highlight) {
67
+ this._highlight.options.set('visible', true);
68
+ }
69
+ var id = this.options.node.id;
70
+ this.visual.options.set('id', id);
71
+
72
+ if (this.options.root()) {
73
+ this.options.root().setAttribute(ARIA_ACTIVE_DESCENDANT, id);
74
+ }
75
+ }
76
+ };
77
+
78
+ Node.prototype.blur = function blur () {
79
+ if (this._highlight) {
80
+ this._highlight.options.set('visible', false);
81
+ this.visual.options.set('id', '');
82
+
83
+ if (this.options.root()) {
84
+ this.options.root().removeAttribute(ARIA_ACTIVE_DESCENDANT);
85
+ }
86
+ }
87
+ };
88
+
38
89
  return Node;
39
90
  }(SankeyElement));
40
91