| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- /**
- * DevExtreme (viz/sparklines/base_sparkline.js)
- * Version: 19.1.16
- * Build date: Tue Oct 18 2022
- *
- * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
- * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
- */
- "use strict";
- var eventsEngine = require("../../events/core/events_engine");
- var domAdapter = require("../../core/dom_adapter");
- var ready = require("../../core/utils/ready_callbacks").add;
- var isFunction = require("../../core/utils/type").isFunction;
- var BaseWidget = require("../core/base_widget");
- var extend = require("../../core/utils/extend").extend;
- var DEFAULT_LINE_SPACING = 2;
- var DEFAULT_EVENTS_DELAY = 100;
- var eventUtils = require("../../events/utils");
- var translator2DModule = require("../translators/translator2d");
- var _extend = extend;
- var _noop = require("../../core/utils/common").noop;
- function generateDefaultCustomizeTooltipCallback(fontOptions, rtlEnabled) {
- var lineSpacing = fontOptions.lineSpacing;
- var lineHeight = (void 0 !== lineSpacing && null !== lineSpacing ? lineSpacing : DEFAULT_LINE_SPACING) + fontOptions.size;
- return function(customizeObject) {
- var html = "";
- var vt = customizeObject.valueText;
- for (var i = 0; i < vt.length; i += 2) {
- html += "<tr><td>" + vt[i] + "</td><td style='width: 15px'></td><td style='text-align: " + (rtlEnabled ? "left" : "right") + "'>" + vt[i + 1] + "</td></tr>"
- }
- return {
- html: "<table style='border-spacing:0px; line-height: " + lineHeight + "px'>" + html + "</table>"
- }
- }
- }
- function generateCustomizeTooltipCallback(customizeTooltip, fontOptions, rtlEnabled) {
- var defaultCustomizeTooltip = generateDefaultCustomizeTooltipCallback(fontOptions, rtlEnabled);
- if (isFunction(customizeTooltip)) {
- return function(customizeObject) {
- var res = customizeTooltip.call(customizeObject, customizeObject);
- if (!("html" in res) && !("text" in res)) {
- _extend(res, defaultCustomizeTooltip.call(customizeObject, customizeObject))
- }
- return res
- }
- } else {
- return defaultCustomizeTooltip
- }
- }
- function createAxis(isHorizontal) {
- var translator = new translator2DModule.Translator2D({}, {}, {
- shiftZeroValue: !isHorizontal,
- isHorizontal: !!isHorizontal
- });
- return {
- getTranslator: function() {
- return translator
- },
- update: function(range, canvas, options) {
- translator.update(range, canvas, options)
- },
- getVisibleArea: function() {
- var visibleArea = translator.getCanvasVisibleArea();
- return [visibleArea.min, visibleArea.max]
- },
- visualRange: _noop,
- calculateInterval: _noop,
- getMarginOptions: function() {
- return {}
- }
- }
- }
- var BaseSparkline = BaseWidget.inherit({
- _getLayoutItems: _noop,
- _useLinks: false,
- _themeDependentChanges: ["OPTIONS"],
- _initCore: function() {
- var that = this;
- that._tooltipTracker = that._renderer.root;
- that._tooltipTracker.attr({
- "pointer-events": "visible"
- });
- that._createHtmlElements();
- that._initTooltipEvents();
- that._argumentAxis = createAxis(true);
- that._valueAxis = createAxis()
- },
- _getDefaultSize: function() {
- return this._defaultSize
- },
- _disposeCore: function() {
- this._disposeWidgetElements();
- this._disposeTooltipEvents();
- this._ranges = null
- },
- _optionChangesOrder: ["OPTIONS"],
- _change_OPTIONS: function() {
- this._prepareOptions();
- this._change(["UPDATE"])
- },
- _customChangesOrder: ["UPDATE"],
- _change_UPDATE: function() {
- this._update()
- },
- _update: function() {
- var that = this;
- if (that._tooltipShown) {
- that._tooltipShown = false;
- that._tooltip.hide()
- }
- that._cleanWidgetElements();
- that._updateWidgetElements();
- that._drawWidgetElements()
- },
- _updateWidgetElements: function() {
- var canvas = this._getCorrectCanvas();
- this._updateRange();
- this._argumentAxis.update(this._ranges.arg, canvas, this._getStick());
- this._valueAxis.update(this._ranges.val, canvas)
- },
- _getStick: function() {},
- _applySize: function(rect) {
- this._allOptions.size = {
- width: rect[2] - rect[0],
- height: rect[3] - rect[1]
- };
- this._change(["UPDATE"])
- },
- _setupResizeHandler: _noop,
- _prepareOptions: function() {
- return _extend(true, {}, this._themeManager.theme(), this.option())
- },
- _getTooltipCoords: function() {
- var canvas = this._canvas;
- var rootOffset = this._renderer.getRootOffset();
- return {
- x: canvas.width / 2 + rootOffset.left,
- y: canvas.height / 2 + rootOffset.top
- }
- },
- _initTooltipEvents: function() {
- var that = this;
- var data = {
- widget: that
- };
- that._showTooltipCallback = function() {
- var tooltip;
- if (!that._tooltipShown) {
- that._tooltipShown = true;
- tooltip = that._getTooltip();
- tooltip.isEnabled() && that._tooltip.show(that._getTooltipData(), that._getTooltipCoords(), {})
- }
- };
- that._hideTooltipCallback = function() {
- that._hideTooltipTimeout = null;
- if (that._tooltipShown) {
- that._tooltipShown = false;
- that._tooltip.hide()
- }
- };
- that._disposeCallbacks = function() {
- that = that._showTooltipCallback = that._hideTooltipCallback = that._disposeCallbacks = null
- };
- that._tooltipTracker.on(mouseEvents, data).on(touchEvents, data);
- that._tooltipTracker.on(menuEvents)
- },
- _stopCurrentHandling: function() {
- this._hideTooltip()
- },
- _disposeTooltipEvents: function() {
- var that = this;
- clearTimeout(that._hideTooltipTimeout);
- that._tooltipTracker.off();
- that._disposeCallbacks()
- },
- _getTooltip: function() {
- var that = this;
- if (!that._tooltip) {
- _initTooltip.apply(this, arguments);
- that._setTooltipRendererOptions(that._tooltipRendererOptions);
- that._tooltipRendererOptions = null;
- that._setTooltipOptions()
- }
- return that._tooltip
- }
- });
- var menuEvents = {
- "contextmenu.sparkline-tooltip": function(event) {
- if (eventUtils.isTouchEvent(event) || eventUtils.isPointerEvent(event)) {
- event.preventDefault()
- }
- },
- "MSHoldVisual.sparkline-tooltip": function(event) {
- event.preventDefault()
- }
- };
- var mouseEvents = {
- "mouseover.sparkline-tooltip": function(event) {
- isPointerDownCalled = false;
- var widget = event.data.widget;
- widget._x = event.pageX;
- widget._y = event.pageY;
- widget._tooltipTracker.off(mouseMoveEvents).on(mouseMoveEvents, event.data);
- widget._showTooltip()
- },
- "mouseout.sparkline-tooltip": function(event) {
- if (isPointerDownCalled) {
- return
- }
- var widget = event.data.widget;
- widget._tooltipTracker.off(mouseMoveEvents);
- widget._hideTooltip(DEFAULT_EVENTS_DELAY)
- }
- };
- var mouseMoveEvents = {
- "mousemove.sparkline-tooltip": function(event) {
- var widget = event.data.widget;
- widget._x = event.pageX;
- widget._y = event.pageY;
- widget._showTooltip()
- }
- };
- var active_touch_tooltip_widget = null;
- var touchStartTooltipProcessing = function(event) {
- var widget = active_touch_tooltip_widget;
- if (widget && widget !== event.data.widget) {
- widget._hideTooltip(DEFAULT_EVENTS_DELAY)
- }
- widget = active_touch_tooltip_widget = event.data.widget;
- widget._showTooltip();
- widget._touch = true
- };
- var touchStartDocumentProcessing = function() {
- var widget = active_touch_tooltip_widget;
- if (widget) {
- if (!widget._touch) {
- widget._hideTooltip(DEFAULT_EVENTS_DELAY);
- active_touch_tooltip_widget = null
- }
- widget._touch = null
- }
- };
- var touchEndDocumentProcessing = function() {
- var widget = active_touch_tooltip_widget;
- if (widget) {
- widget._hideTooltip(DEFAULT_EVENTS_DELAY);
- active_touch_tooltip_widget = null
- }
- };
- var isPointerDownCalled = false;
- var touchEvents = {
- "pointerdown.sparkline-tooltip": touchStartTooltipProcessing,
- "touchstart.sparkline-tooltip": touchStartTooltipProcessing
- };
- ready(function() {
- eventsEngine.subscribeGlobal(domAdapter.getDocument(), {
- "pointerdown.sparkline-tooltip": function() {
- isPointerDownCalled = true;
- touchStartDocumentProcessing()
- },
- "touchstart.sparkline-tooltip": touchStartDocumentProcessing,
- "pointerup.sparkline-tooltip": touchEndDocumentProcessing,
- "touchend.sparkline-tooltip": touchEndDocumentProcessing
- })
- });
- module.exports = BaseSparkline;
- BaseSparkline.addPlugin(require("../core/tooltip").plugin);
- var _initTooltip = BaseSparkline.prototype._initTooltip;
- BaseSparkline.prototype._initTooltip = _noop;
- var _disposeTooltip = BaseSparkline.prototype._disposeTooltip;
- BaseSparkline.prototype._disposeTooltip = function() {
- if (this._tooltip) {
- _disposeTooltip.apply(this, arguments)
- }
- };
- BaseSparkline.prototype._setTooltipRendererOptions = function() {
- var options = this._getRendererOptions();
- if (this._tooltip) {
- this._tooltip.setRendererOptions(options)
- } else {
- this._tooltipRendererOptions = options
- }
- };
- BaseSparkline.prototype._setTooltipOptions = function() {
- var tooltip = this._tooltip;
- var options = tooltip && this._getOption("tooltip");
- tooltip && tooltip.update(_extend({}, options, {
- customizeTooltip: generateCustomizeTooltipCallback(options.customizeTooltip, options.font, this.option("rtlEnabled")),
- enabled: options.enabled && this._isTooltipEnabled()
- }))
- };
- BaseSparkline.prototype._showTooltip = function() {
- var that = this;
- clearTimeout(that._hideTooltipTimeout);
- that._hideTooltipTimeout = null;
- that._showTooltipCallback()
- };
- BaseSparkline.prototype._hideTooltip = function(delay) {
- var that = this;
- clearTimeout(that._hideTooltipTimeout);
- if (delay) {
- that._hideTooltipTimeout = setTimeout(that._hideTooltipCallback, delay)
- } else {
- that._hideTooltipCallback()
- }
- };
- var exportPlugin = extend(true, {}, require("../core/export").plugin, {
- init: _noop,
- dispose: _noop,
- customize: null,
- members: {
- _getExportMenuOptions: null
- }
- });
- BaseSparkline.addPlugin(exportPlugin);
|