@progress/kendo-charts
Version:
Kendo UI platform-independent Charts library
108 lines (89 loc) • 3.41 kB
JavaScript
import { geometry, drawing } from '@progress/kendo-drawing';
import { SankeyElement } from './element';
import { deepExtend } from '../common';
import { ARIA_ACTIVE_DESCENDANT } from '../common/constants';
export var Node = (function (SankeyElement) {
function Node () {
SankeyElement.apply(this, arguments);
}
if ( SankeyElement ) Node.__proto__ = SankeyElement;
Node.prototype = Object.create( SankeyElement && SankeyElement.prototype );
Node.prototype.constructor = Node;
Node.prototype.getElement = function getElement () {
return drawing.Path.fromRect(this.getRect(), this.visualOptions());
};
Node.prototype.getRect = function getRect () {
var node = this.options.node;
return new geometry.Rect([node.x0, node.y0], [node.x1 - node.x0, node.y1 - node.y0]);
};
Node.prototype.getLabelText = function getLabelText (options) {
var labelTemplate = options.labels.ariaTemplate;
if (labelTemplate) {
return labelTemplate({ node: options.node });
}
};
Node.prototype.visualOptions = function visualOptions () {
var options = deepExtend({}, this.options, this.options.node);
var ariaLabel = this.getLabelText(options);
return {
fill: {
color: options.color,
opacity: options.opacity
},
stroke: { width: 0 },
className: 'k-sankey-node',
role: 'graphics-symbol',
ariaRoleDescription: 'Node',
ariaLabel: ariaLabel
};
};
Node.prototype.createFocusHighlight = function createFocusHighlight () {
if (!this.options.navigatable) {
return;
}
this._highlight = drawing.Path.fromRect(this.getRect(), {
stroke: this.options.focusHighlight.border,
visible: false
});
return this._highlight;
};
Node.prototype.focus = function focus (options) {
if (this._highlight) {
var ref = options || {};
var highlight = ref.highlight; if ( highlight === void 0 ) highlight = true;
if (highlight) {
this._highlight.options.set('visible', true);
}
var id = this.options.node.id;
this.visual.options.set('id', id);
if (this.options.root()) {
this.options.root().setAttribute(ARIA_ACTIVE_DESCENDANT, id);
}
}
};
Node.prototype.blur = function blur () {
if (this._highlight) {
this._highlight.options.set('visible', false);
this.visual.options.set('id', '');
if (this.options.root()) {
this.options.root().removeAttribute(ARIA_ACTIVE_DESCENDANT);
}
}
};
return Node;
}(SankeyElement));
var nodeColor = function (node, nodeColors, index) { return node.color || nodeColors[index % nodeColors.length]; };
export var resolveNodeOptions = function (node, options, nodeColors, index) {
var nodeOptions = deepExtend({}, options, options.node);
return deepExtend({},
{ color: nodeColor(node, nodeColors, index) },
nodeOptions,
{ node: node },
{
visual: node.visual,
opacity: node.opacity,
offset: node.offset,
color: node.color
}
);
};