UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

340 lines (277 loc) 11.3 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var kendoCharts = require('@progress/kendo-charts'); require('./kendo.dataviz.core.js'); require('./kendo.dataviz.themes.js'); require('@progress/kendo-charts/dist/es/core-export.js'); require('./html-sdnHcjkh.js'); require('./kendo.popup.js'); require('./kendo.core.js'); require('./kendo.licensing.js'); require('@progress/kendo-licensing'); require('./kendo.icons.js'); require('./kendo.html.icon.js'); require('./kendo.html.base.js'); require('@progress/kendo-svg-icons'); require('@progress/kendo-drawing'); require('./kendo.color.js'); (function($) { var kendo = window.kendo; var Widget = kendo.ui.Widget; var encode = kendo.htmlEncode; var styleAttr = '__style'; var tooltipContentWrapStyle = `${styleAttr}="display: flex; align-items: center;"`; var space = 3; var TootipText = (text) => `<span ${styleAttr}="margin: 0 ${space}px">${text}</span>`; var Square = (color) => `<div ${styleAttr}="width: 15px; height: 15px; background-color: ${color}; display: inline-flex; margin-left: ${space}px"></div>`; var TooltipTemplates = { node: function({ dataItem, value }) { const { color, label } = dataItem; return ( `<div ${tooltipContentWrapStyle}> ${Square(color)} ${TootipText(encode(label.text))} ${TootipText(value)} </div>` ); }, link: function({ dataItem, value, rtl }) { const { source, target } = dataItem; return ( `<div ${tooltipContentWrapStyle}> ${Square(source.color)} ${TootipText(encode(source.label.text))} ${TootipText(kendo.ui.icon({ icon: rtl ? "arrow-left" : "arrow-right" }))} ${Square(target.color)} ${TootipText(encode(target.label.text))} ${TootipText(value)} </div>` ); } }; var SankeyTooltip = Widget.extend({ init: function(element, options) { this.options = options; Widget.fn.init.call(this, element); if (options.rtl) { this.element.addClass('k-rtl'); } this.element.addClass('k-tooltip k-chart-tooltip k-chart-shared-tooltip') .append('<div class="k-tooltip-content"></div>'); }, size: function() { return { width: this.element.outerWidth(), height: this.element.outerHeight() }; }, setContent: function(content) { this.element.find('.k-tooltip-content').html(content); this.element.find(`[${styleAttr}]`).each((i, el) => { el.getAttribute(styleAttr) .split(';') .filter(s => s !== '') .forEach(s => { const parts = s.split(':'); el.style[parts[0].trim()] = parts[1].trim(); }); el.removeAttribute(styleAttr); }); }, setPosition: function(popupAlign, popupOffset, offsetOption) { const size = this.size(); const offset = { ...popupOffset }; offset.left += (popupAlign.horizontal === 'left') ? offsetOption : (-1 * offsetOption); if (popupAlign.horizontal === 'right') { offset.left -= size.width; } if (popupAlign.vertical === 'bottom') { offset.top -= size.height + offsetOption; } else { offset.top += offsetOption; } this.element.css(offset); }, show: function() { this.element.show(); }, hide: function() { this.element.hide(); }, destroy: function() { this.element.remove(); } }); kendo.deepExtend(kendo.dataviz, { SankeyTooltip: { Tooltip: SankeyTooltip, ContentTemplates: TooltipTemplates } }); })(window.kendo.jQuery); const __meta__ = { id: "dataviz.sankey", name: "Sankey", category: "dataviz", description: "The Sankey widget uses modern browser technologies to render high-quality data visualizations in the browser.", depends: [ "data", "userevents", "drawing", "dataviz.core", "dataviz.themes" ], features: [{ id: "dataviz.sankey-pdf-export", name: "PDF export", description: "Export Sankey as PDF", depends: [ "pdf" ] }] }; (function($) { window.kendo.dataviz = window.kendo.dataviz || {}; const kendo = window.kendo; const template = kendo.template; const Widget = kendo.ui.Widget; const dataviz = kendo.dataviz; const encode = kendo.htmlEncode; const isRtl = kendo.support.isRtl; const NODE_CLICK = "nodeClick"; const LINK_CLICK = "linkClick"; const NODE_ENTER = "nodeEnter"; const NODE_LEAVE = "nodeLeave"; const LINK_ENTER = "linkEnter"; const LINK_LEAVE = "linkLeave"; const TOOLTIP_SHOW = "tooltipShow"; const TOOLTIP_HIDE = "tooltipHide"; const NODE = 'node'; const { Tooltip, ContentTemplates } = dataviz.SankeyTooltip; const Sankey = Widget.extend({ init: function(element, userOptions) { kendo.destroy(element); $(element).empty(); this.options = kendo.deepExtend({}, this.options, userOptions, { rtl: isRtl(element) }); this._parseAriaLabelTemplates(this.options); Widget.fn.init.call(this, element); this.wrapper = this.element; this._initSankey(); this._attachEvents(); kendo.notify(this, dataviz.ui); if (this._showWatermarkOverlay) { this._showWatermarkOverlay(this.wrapper[0]); } }, setOptions: function(options) { var currentOptions = this.options; this.events.forEach(eventName => { if (currentOptions[eventName]) { this.unbind(eventName, currentOptions[eventName]); } }); const resultOptions = kendo.deepExtend(options, { rtl: isRtl(this.element) }); this._parseAriaLabelTemplates(resultOptions); this._instance.setOptions(resultOptions); this.bind(this.events, this._instance.options); }, _initSankey: function() { const themeOptions = this._getThemeOptions(this.options); this._createSankey(this.options, themeOptions); this.options = this._instance.options; }, _createSankey: function(options, themeOptions) { this._instance = new kendoCharts.Sankey(this.element[0], options, themeOptions); }, _getThemeOptions: function(options) { var themeName = (options || {}).theme; if (themeName && dataviz.SASS_THEMES.indexOf(themeName.toLowerCase()) !== -1) { this.element.addClass("k-chart"); const theme = kendoCharts.sankeyTheme(this.element[0]); this.element.removeClass("k-chart"); return theme; } if (kendoCharts.defined(themeName)) { var themes = dataviz.ui.themes || {}; var theme = themes[themeName] || themes[themeName.toLowerCase()] || {}; const chartTheme = theme.chart || {}; const { seriesColors: nodeColors, axisDefaults, seriesDefaults, legend, title } = chartTheme; const { line: links, labels } = axisDefaults; const strokeColor = seriesDefaults.labels.background; return { nodeColors, links, labels: { ...labels, stroke: { color: strokeColor } }, legend, title }; } }, _parseAriaLabelTemplates: function(options) { const { nodes, links } = options; if (nodes && nodes.labels && nodes.labels.ariaTemplate) { nodes.labels.ariaTemplate = template(nodes.labels.ariaTemplate); } if (links && links.labels && links.labels.ariaTemplate) { links.labels.ariaTemplate = template(links.labels.ariaTemplate); } }, _attachEvents: function() { this.events.forEach(eventName => { this._instance.bind(eventName, event => { if (this._events[eventName]) { this._events[eventName].forEach(handler => handler.call(undefined, event)); } }); }); this._instance.bind(TOOLTIP_SHOW, this.tooltipShow.bind(this)); this._instance.bind(TOOLTIP_HIDE, this.tooltipHide.bind(this)); }, tooltipShow: function(e) { const { tooltip, rtl } = this.options; const { nodeTemplate, linkTemplate, offset } = tooltip; if (!this._tooltip) { const doc = this.element[0].ownerDocument; this._tooltip = new Tooltip(doc.createElement('div'), { rtl }); const { appendTo = doc.body } = this.options.tooltip; this._tooltip.element.appendTo($(appendTo)); } const currentTemplate = template((e.targetType === NODE ? nodeTemplate : linkTemplate) || ContentTemplates[e.targetType]); const value = encode(kendo.format(this.options.messages.tooltipUnits, kendoCharts.defined(e.nodeValue) ? e.nodeValue : e.dataItem.value)); this._tooltip.setContent(currentTemplate({ dataItem: e.dataItem, value, rtl })); this._tooltip.setPosition(e.tooltipData.popupAlign, e.tooltipData.popupOffset, offset); this._tooltip.show(); }, tooltipHide: function() { if (this._tooltip) { this._tooltip.destroy(); this._tooltip = null; } }, exportVisual: function(exportOptions) { return this._instance.exportVisual(exportOptions); }, destroy: function() { Widget.fn.destroy.call(this); this.tooltipHide(); this._instance.destroy(); this._instance = null; }, events: [ NODE_CLICK, LINK_CLICK, NODE_ENTER, NODE_LEAVE, LINK_ENTER, LINK_LEAVE ], options: { name: "Sankey", theme: "default", tooltip: { offset: 12 }, messages: { tooltipUnits: "({0} Units)" } } }); dataviz.ExportMixin.extend(Sankey.fn); if (kendo.PDFMixin) { kendo.PDFMixin.extend(Sankey.fn); } dataviz.ui.plugin(Sankey); kendo.deepExtend(dataviz, { Sankey: Sankey, createSankeyData: kendoCharts.createSankeyData }); })(window.kendo.jQuery); var kendo$1 = kendo; exports.__meta__ = __meta__; exports.default = kendo$1;