@progress/kendo-charts
Version:
Kendo UI platform-independent Charts library
88 lines (73 loc) • 2.57 kB
JavaScript
import { default as ChartLegend } from "../chart/legend/legend";
import { SankeyElement } from "./element";
import { setDefaultOptions } from '../common';
import { BOTTOM, CENTER, LEFT, POINTER, RIGHT } from "../common/constants";
import { AREA } from "../chart/constants";
var sortData = function (a, b) {
if (a.node.x0 - b.node.x0 !== 0) {
return a.node.x0 - b.node.x0;
}
return a.node.y0 - b.node.y0;
};
var sortDataRTL = function (a, b) {
if (a.node.x1 - b.node.x1 !== 0) {
return a.node.x1 - b.node.x1;
}
return b.node.y0 - a.node.y0;
};
var sort = function (rtl) { return (rtl ? sortDataRTL : sortData); };
export var Legend = (function (SankeyElement) {
function Legend () {
SankeyElement.apply(this, arguments);
}
if ( SankeyElement ) Legend.__proto__ = SankeyElement;
Legend.prototype = Object.create( SankeyElement && SankeyElement.prototype );
Legend.prototype.constructor = Legend;
Legend.prototype.getElement = function getElement () {
var options = this.options;
var drawingRect = options.drawingRect;
var rtl = options.rtl;
var nodes = options.nodes; if ( nodes === void 0 ) nodes = [];
var item = options.item;
var position = options.position;
if (options.visible === false || !nodes.length) {
return null;
}
var data = nodes.map(function (node) { return ({
text: (node.label && node.label.text) || '',
area: {
background: item.areaBackground !== undefined ? item.areaBackground : node.color,
opacity: item.areaOpacity !== undefined ? item.areaOpacity : node.opacity
},
node: node
}); });
data.sort(sort(rtl));
var reverse = rtl && position !== LEFT && position !== RIGHT;
var legend = new ChartLegend(Object.assign({}, options, {data: data, reverse: reverse}), { rtl: rtl });
legend.reflow(drawingRect);
legend.renderVisual();
return legend.visual;
};
Legend.prototype.createElement = function createElement () {
return this.getElement();
};
return Legend;
}(SankeyElement));
setDefaultOptions(Legend, {
markers: { visible: false },
item: {
type: AREA,
cursor: POINTER,
opacity: 1
},
position: BOTTOM,
align: CENTER,
accessibility: {
role: 'presentation',
ariaLabel: null,
ariaRoleDescription: null
},
border: {
width: 0
}
});