UNPKG

@lowcodeunit/lcu-charts-common

Version:

A Charting and Graphing Library based on and influenced by Ngx-charts

1,021 lines (1,009 loc) 595 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/animations'), require('@angular/cdk/portal'), require('rxjs'), require('rxjs/operators'), require('d3-selection'), require('d3-brush'), require('d3-scale'), require('@angular/platform-browser'), require('d3-shape'), require('d3-array'), require('d3-interpolate'), require('d3-format'), require('@lcu/common'), require('d3-time-format'), require('d3-color')) : typeof define === 'function' && define.amd ? define('@lowcodeunit/lcu-charts-common', ['exports', '@angular/core', '@angular/common', '@angular/animations', '@angular/cdk/portal', 'rxjs', 'rxjs/operators', 'd3-selection', 'd3-brush', 'd3-scale', '@angular/platform-browser', 'd3-shape', 'd3-array', 'd3-interpolate', 'd3-format', '@lcu/common', 'd3-time-format', 'd3-color'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.lowcodeunit = global.lowcodeunit || {}, global.lowcodeunit['lcu-charts-common'] = {}), global.ng.core, global.ng.common, global.ng.animations, global.ng.cdk.portal, global.rxjs, global.rxjs.operators, global.d3Selection, global.d3Brush, global.d3Scale, global.ng.platformBrowser, global.d3Shape, global.d3Array, global.d3Interpolate, global.d3Format, global.common$1, global.d3TimeFormat, global.d3_color)); }(this, (function (exports, core, common, animations, portal, rxjs, operators, d3Selection, d3Brush, d3Scale, platformBrowser, d3Shape, d3Array, d3Interpolate, d3Format, common$1, d3TimeFormat, d3_color) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function () { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); }; } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } var __createBinding = Object.create ? (function (o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } }); }) : (function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; }); function __exportStar(m, o) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } /** @deprecated */ function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /** @deprecated */ function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } function __spreadArray(to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i]; return to; } function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; } ; var __setModuleDefault = Object.create ? (function (o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function (o, v) { o["default"] = v; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } function __classPrivateFieldGet(receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); } function __classPrivateFieldSet(receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; } function isViewContainerRef(x) { return x.element; } /** * Injection service is a helper to append components * dynamically to a known location in the DOM, most * noteably for dialogs/tooltips appending to body. * * @export */ var InjectionService = /** @class */ (function () { function InjectionService(applicationRef, componentFactoryResolver, injector) { this.applicationRef = applicationRef; this.componentFactoryResolver = componentFactoryResolver; this.injector = injector; } /** * Sets a default global root view container. This is useful for * things like ngUpgrade that doesn't have a ApplicationRef root. * * @param container */ InjectionService.setGlobalRootViewContainer = function (container) { InjectionService.globalRootViewContainer = container; }; /** * Gets the root view container to inject the component to. * * @memberOf InjectionService */ InjectionService.prototype.getRootViewContainer = function () { if (this._container) return this._container; if (InjectionService.globalRootViewContainer) return InjectionService.globalRootViewContainer; if (this.applicationRef.components.length) return this.applicationRef.components[0]; throw new Error('View Container not found! ngUpgrade needs to manually set this via setRootViewContainer or setGlobalRootViewContainer.'); }; /** * Overrides the default root view container. This is useful for * things like ngUpgrade that doesn't have a ApplicationRef root. * * @param container * * @memberOf InjectionService */ InjectionService.prototype.setRootViewContainer = function (container) { this._container = container; }; /** * Gets the html element for a component ref. * * @param componentRef * * @memberOf InjectionService */ InjectionService.prototype.getComponentRootNode = function (component) { if (isViewContainerRef(component)) { return component.element.nativeElement; } if (component.hostView && component.hostView.rootNodes.length > 0) { return component.hostView.rootNodes[0]; } // the top most component root node has no `hostView` return component.location.nativeElement; }; /** * Gets the root component container html element. * * @memberOf InjectionService */ InjectionService.prototype.getRootViewContainerNode = function (component) { return this.getComponentRootNode(component); }; /** * Projects the bindings onto the component * * @param component * @param options * * @memberOf InjectionService */ InjectionService.prototype.projectComponentBindings = function (component, bindings) { var e_1, _a, e_2, _b; if (bindings) { if (bindings.inputs !== undefined) { var bindingKeys = Object.getOwnPropertyNames(bindings.inputs); try { for (var bindingKeys_1 = __values(bindingKeys), bindingKeys_1_1 = bindingKeys_1.next(); !bindingKeys_1_1.done; bindingKeys_1_1 = bindingKeys_1.next()) { var bindingName = bindingKeys_1_1.value; component.instance[bindingName] = bindings.inputs[bindingName]; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (bindingKeys_1_1 && !bindingKeys_1_1.done && (_a = bindingKeys_1.return)) _a.call(bindingKeys_1); } finally { if (e_1) throw e_1.error; } } } if (bindings.outputs !== undefined) { var eventKeys = Object.getOwnPropertyNames(bindings.outputs); try { for (var eventKeys_1 = __values(eventKeys), eventKeys_1_1 = eventKeys_1.next(); !eventKeys_1_1.done; eventKeys_1_1 = eventKeys_1.next()) { var eventName = eventKeys_1_1.value; component.instance[eventName] = bindings.outputs[eventName]; } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (eventKeys_1_1 && !eventKeys_1_1.done && (_b = eventKeys_1.return)) _b.call(eventKeys_1); } finally { if (e_2) throw e_2.error; } } } } return component; }; /** * Appends a component to a adjacent location * * @param componentClass * @param [options={}] * @param [location] * * @memberOf InjectionService */ InjectionService.prototype.appendComponent = function (componentClass, bindings, location) { if (bindings === void 0) { bindings = {}; } if (!location) location = this.getRootViewContainer(); var appendLocation = this.getComponentRootNode(location); var portalHost = new portal.DomPortalHost(appendLocation, this.componentFactoryResolver, this.applicationRef, this.injector); var portal$1 = new portal.ComponentPortal(componentClass); var componentRef = portalHost.attach(portal$1); this.projectComponentBindings(componentRef, bindings); return componentRef; }; return InjectionService; }()); InjectionService.globalRootViewContainer = null; InjectionService.decorators = [ { type: core.Injectable } ]; InjectionService.ctorParameters = function () { return [ { type: core.ApplicationRef }, { type: core.ComponentFactoryResolver }, { type: core.Injector } ]; }; /** * Throttle a function * */ function throttle(func, wait, options) { options = options || {}; var context; var args; var result; var timeout = null; var previous = 0; function later() { previous = options.leading === false ? 0 : +new Date(); timeout = null; result = func.apply(context, args); } return function () { var now = +new Date(); if (!previous && options.leading === false) { previous = now; } var remaining = wait - (now - previous); context = this; args = arguments; if (remaining <= 0) { clearTimeout(timeout); timeout = null; previous = now; result = func.apply(context, args); } else if (!timeout && options.trailing !== false) { timeout = setTimeout(later, remaining); } return result; }; } /** * Throttle decorator * * class MyClass { * throttleable(10) * myFn() { ... } * } */ function throttleable(duration, options) { return function innerDecorator(target, key, descriptor) { return { configurable: true, enumerable: descriptor.enumerable, get: function getter() { Object.defineProperty(this, key, { configurable: true, enumerable: descriptor.enumerable, value: throttle(descriptor.value, duration, options) }); return this[key]; } }; }; } var PlacementTypes; (function (PlacementTypes) { PlacementTypes[PlacementTypes["top"] = 'top'] = "top"; PlacementTypes[PlacementTypes["bottom"] = 'bottom'] = "bottom"; PlacementTypes[PlacementTypes["left"] = 'left'] = "left"; PlacementTypes[PlacementTypes["right"] = 'right'] = "right"; })(PlacementTypes || (PlacementTypes = {})); var caretOffset = 7; function verticalPosition(elDimensions, popoverDimensions, alignment) { if (alignment === 'top') { return elDimensions.top - caretOffset; } if (alignment === 'bottom') { return elDimensions.top + elDimensions.height - popoverDimensions.height + caretOffset; } if (alignment === 'center') { return elDimensions.top + elDimensions.height / 2 - popoverDimensions.height / 2; } return undefined; } function horizontalPosition(elDimensions, popoverDimensions, alignment) { if (alignment === 'left') { return elDimensions.left - caretOffset; } if (alignment === 'right') { return elDimensions.left + elDimensions.width - popoverDimensions.width + caretOffset; } if (alignment === 'center') { return elDimensions.left + elDimensions.width / 2 - popoverDimensions.width / 2; } return undefined; } /** * Position helper for the popover directive. * * @export */ var PositionHelper = /** @class */ (function () { function PositionHelper() { } /** * Calculate vertical alignment position * * @memberOf PositionHelper */ PositionHelper.calculateVerticalAlignment = function (elDimensions, popoverDimensions, alignment) { var result = verticalPosition(elDimensions, popoverDimensions, alignment); if (result + popoverDimensions.height > window.innerHeight) { result = window.innerHeight - popoverDimensions.height; } return result; }; /** * Calculate vertical caret position * * @memberOf PositionHelper */ PositionHelper.calculateVerticalCaret = function (elDimensions, popoverDimensions, caretDimensions, alignment) { var result; if (alignment === 'top') { result = elDimensions.height / 2 - caretDimensions.height / 2 + caretOffset; } if (alignment === 'bottom') { result = popoverDimensions.height - elDimensions.height / 2 - caretDimensions.height / 2 - caretOffset; } if (alignment === 'center') { result = popoverDimensions.height / 2 - caretDimensions.height / 2; } var popoverPosition = verticalPosition(elDimensions, popoverDimensions, alignment); if (popoverPosition + popoverDimensions.height > window.innerHeight) { result += popoverPosition + popoverDimensions.height - window.innerHeight; } return result; }; /** * Calculate horz alignment position * * @memberOf PositionHelper */ PositionHelper.calculateHorizontalAlignment = function (elDimensions, popoverDimensions, alignment) { var result = horizontalPosition(elDimensions, popoverDimensions, alignment); if (result + popoverDimensions.width > window.innerWidth) { result = window.innerWidth - popoverDimensions.width; } return result; }; /** * Calculate horz caret position * * @memberOf PositionHelper */ PositionHelper.calculateHorizontalCaret = function (elDimensions, popoverDimensions, caretDimensions, alignment) { var result; if (alignment === 'left') { result = elDimensions.width / 2 - caretDimensions.width / 2 + caretOffset; } if (alignment === 'right') { result = popoverDimensions.width - elDimensions.width / 2 - caretDimensions.width / 2 - caretOffset; } if (alignment === 'center') { result = popoverDimensions.width / 2 - caretDimensions.width / 2; } var popoverPosition = horizontalPosition(elDimensions, popoverDimensions, alignment); if (popoverPosition + popoverDimensions.width > window.innerWidth) { result += popoverPosition + popoverDimensions.width - window.innerWidth; } return result; }; /** * Checks if the element's position should be flipped * * @memberOf PositionHelper */ PositionHelper.shouldFlip = function (elDimensions, popoverDimensions, placement, spacing) { var flip = false; if (placement === 'right') { if (elDimensions.left + elDimensions.width + popoverDimensions.width + spacing > window.innerWidth) { flip = true; } } if (placement === 'left') { if (elDimensions.left - popoverDimensions.width - spacing < 0) { flip = true; } } if (placement === 'top') { if (elDimensions.top - popoverDimensions.height - spacing < 0) { flip = true; } } if (placement === 'bottom') { if (elDimensions.top + elDimensions.height + popoverDimensions.height + spacing > window.innerHeight) { flip = true; } } return flip; }; /** * Position caret * * @memberOf PositionHelper */ PositionHelper.positionCaret = function (placement, elmDim, hostDim, caretDimensions, alignment) { var top = 0; var left = 0; if (placement === PlacementTypes.right) { left = -7; top = PositionHelper.calculateVerticalCaret(hostDim, elmDim, caretDimensions, alignment); } else if (placement === PlacementTypes.left) { left = elmDim.width; top = PositionHelper.calculateVerticalCaret(hostDim, elmDim, caretDimensions, alignment); } else if (placement === PlacementTypes.top) { top = elmDim.height; left = PositionHelper.calculateHorizontalCaret(hostDim, elmDim, caretDimensions, alignment); } else if (placement === PlacementTypes.bottom) { top = -7; left = PositionHelper.calculateHorizontalCaret(hostDim, elmDim, caretDimensions, alignment); } return { top: top, left: left }; }; /** * Position content * * @memberOf PositionHelper */ PositionHelper.positionContent = function (placement, elmDim, hostDim, spacing, alignment) { var top = 0; var left = 0; if (placement === PlacementTypes.right) { left = hostDim.left + hostDim.width + spacing; top = PositionHelper.calculateVerticalAlignment(hostDim, elmDim, alignment); } else if (placement === PlacementTypes.left) { left = hostDim.left - elmDim.width - spacing; top = PositionHelper.calculateVerticalAlignment(hostDim, elmDim, alignment); } else if (placement === PlacementTypes.top) { top = hostDim.top - elmDim.height - spacing; left = PositionHelper.calculateHorizontalAlignment(hostDim, elmDim, alignment); } else if (placement === PlacementTypes.bottom) { top = hostDim.top + hostDim.height + spacing; left = PositionHelper.calculateHorizontalAlignment(hostDim, elmDim, alignment); } return { top: top, left: left }; }; /** * Determine placement based on flip * * @memberOf PositionHelper */ PositionHelper.determinePlacement = function (placement, elmDim, hostDim, spacing) { var shouldFlip = PositionHelper.shouldFlip(hostDim, elmDim, placement, spacing); if (shouldFlip) { if (placement === PlacementTypes.right) { return PlacementTypes.left; } else if (placement === PlacementTypes.left) { return PlacementTypes.right; } else if (placement === PlacementTypes.top) { return PlacementTypes.bottom; } else if (placement === PlacementTypes.bottom) { return PlacementTypes.top; } } return placement; }; return PositionHelper; }()); var TooltipContentComponent = /** @class */ (function () { function TooltipContentComponent(element, renderer) { this.element = element; this.renderer = renderer; } Object.defineProperty(TooltipContentComponent.prototype, "cssClasses", { get: function () { var clz = 'lcu-charts-tooltip-content'; clz += " position-" + this.placement; clz += " type-" + this.type; clz += " " + this.cssClass; return clz; }, enumerable: false, configurable: true }); TooltipContentComponent.prototype.ngAfterViewInit = function () { setTimeout(this.position.bind(this)); }; TooltipContentComponent.prototype.position = function () { var _this = this; var nativeElm = this.element.nativeElement; var hostDim = this.host.nativeElement.getBoundingClientRect(); // if no dims were found, never show if (!hostDim.height && !hostDim.width) return; var elmDim = nativeElm.getBoundingClientRect(); this.checkFlip(hostDim, elmDim); this.positionContent(nativeElm, hostDim, elmDim); if (this.showCaret) { this.positionCaret(hostDim, elmDim); } // animate its entry setTimeout(function () { return _this.renderer.addClass(nativeElm, 'animate'); }, 1); }; TooltipContentComponent.prototype.positionContent = function (nativeElm, hostDim, elmDim) { var _a = PositionHelper.positionContent(this.placement, elmDim, hostDim, this.spacing, this.alignment), top = _a.top, left = _a.left; this.renderer.setStyle(nativeElm, 'top', top + "px"); this.renderer.setStyle(nativeElm, 'left', left + "px"); }; TooltipContentComponent.prototype.positionCaret = function (hostDim, elmDim) { var caretElm = this.caretElm.nativeElement; var caretDimensions = caretElm.getBoundingClientRect(); var _a = PositionHelper.positionCaret(this.placement, elmDim, hostDim, caretDimensions, this.alignment), top = _a.top, left = _a.left; this.renderer.setStyle(caretElm, 'top', top + "px"); this.renderer.setStyle(caretElm, 'left', left + "px"); }; TooltipContentComponent.prototype.checkFlip = function (hostDim, elmDim) { this.placement = PositionHelper.determinePlacement(this.placement, elmDim, hostDim, this.spacing); }; TooltipContentComponent.prototype.onWindowResize = function () { this.position(); }; return TooltipContentComponent; }()); TooltipContentComponent.decorators = [ { type: core.Component, args: [{ selector: 'lcu-tooltip-content', template: "\n <div>\n <span #caretElm [hidden]=\"!showCaret\" class=\"tooltip-caret position-{{ this.placement }}\"> </span>\n <div class=\"tooltip-content\">\n <span *ngIf=\"!title\">\n <ng-template [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"{ model: context }\"> </ng-template>\n </span>\n <span *ngIf=\"title\" [innerHTML]=\"title\"> </span>\n </div>\n </div>\n ", encapsulation: core.ViewEncapsulation.None, styles: [".lcu-charts-tooltip-content{position:fixed;border-radius:3px;z-index:5000;display:block;font-weight:400;opacity:0;pointer-events:none!important}.lcu-charts-tooltip-content.type-popover{background:#fff;color:#060709;border:1px solid #72809b;box-shadow:0 1px 3px 0 rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 2px 1px -1px rgba(0,0,0,.12);font-size:13px;padding:4px}.lcu-charts-tooltip-content.type-popover .tooltip-caret{position:absolute;z-index:5001;width:0;height:0}.lcu-charts-tooltip-content.type-popover .tooltip-caret.position-left{border-top:7px solid transparent;border-bottom:7px solid transparent;border-left:7px solid #fff}.lcu-charts-tooltip-content.type-popover .tooltip-caret.position-top{border-left:7px solid transparent;border-right:7px solid transparent;border-top:7px solid #fff}.lcu-charts-tooltip-content.type-popover .tooltip-caret.position-right{border-top:7px solid transparent;border-bottom:7px solid transparent;border-right:7px solid #fff}.lcu-charts-tooltip-content.type-popover .tooltip-caret.position-bottom{border-left:7px solid transparent;border-right:7px solid transparent;border-bottom:7px solid #fff}.lcu-charts-tooltip-content.type-tooltip{color:#fff;background:rgba(0,0,0,.75);font-size:12px;padding:0 10px;text-align:center;pointer-events:auto}.lcu-charts-tooltip-content.type-tooltip .tooltip-caret.position-left{border-top:7px solid transparent;border-bottom:7px solid transparent;border-left:7px solid rgba(0,0,0,.75)}.lcu-charts-tooltip-content.type-tooltip .tooltip-caret.position-top{border-left:7px solid transparent;border-right:7px solid transparent;border-top:7px solid rgba(0,0,0,.75)}.lcu-charts-tooltip-content.type-tooltip .tooltip-caret.position-right{border-top:7px solid transparent;border-bottom:7px solid transparent;border-right:7px solid rgba(0,0,0,.75)}.lcu-charts-tooltip-content.type-tooltip .tooltip-caret.position-bottom{border-left:7px solid transparent;border-right:7px solid transparent;border-bottom:7px solid rgba(0,0,0,.75)}.lcu-charts-tooltip-content .tooltip-label{display:block;line-height:1em;padding:8px 5px 5px;font-size:1em}.lcu-charts-tooltip-content .tooltip-val{display:block;font-size:1.3em;line-height:1em;padding:0 5px 8px}.lcu-charts-tooltip-content .tooltip-caret{position:absolute;z-index:5001;width:0;height:0}.lcu-charts-tooltip-content.position-right{transform:translate3d(10px,0,0)}.lcu-charts-tooltip-content.position-left{transform:translate3d(-10px,0,0)}.lcu-charts-tooltip-content.position-top{transform:translate3d(0,-10px,0)}.lcu-charts-tooltip-content.position-bottom{transform:translate3d(0,10px,0)}.lcu-charts-tooltip-content.animate{opacity:1;transition:opacity .3s,transform .3s;transform:translateZ(0);pointer-events:auto}.area-tooltip-container{padding:5px 0;pointer-events:none}.tooltip-item{text-align:left;line-height:1.2em;padding:5px 0}.tooltip-item .tooltip-item-color{display:inline-block;height:12px;width:12px;margin-right:5px;color:#5b646b;border-radius:3px}"] },] } ]; TooltipContentComponent.ctorParameters = function () { return [ { type: core.ElementRef }, { type: core.Renderer2 } ]; }; TooltipContentComponent.propDecorators = { host: [{ type: core.Input }], showCaret: [{ type: core.Input }], type: [{ type: core.Input }], placement: [{ type: core.Input }], alignment: [{ type: core.Input }], spacing: [{ type: core.Input }], cssClass: [{ type: core.Input }], title: [{ type: core.Input }], template: [{ type: core.Input }], context: [{ type: core.Input }], caretElm: [{ type: core.ViewChild, args: ['caretElm',] }], cssClasses: [{ type: core.HostBinding, args: ['class',] }], onWindowResize: [{ type: core.HostListener, args: ['window:resize',] }] }; __decorate([ throttleable(100) ], TooltipContentComponent.prototype, "onWindowResize", null); var InjectionRegisteryService = /** @class */ (function () { function InjectionRegisteryService(injectionService) { this.injectionService = injectionService; this.defaults = {}; this.components = new Map(); } InjectionRegisteryService.prototype.getByType = function (type) { if (type === void 0) { type = this.type; } return this.components.get(type); }; InjectionRegisteryService.prototype.create = function (bindings) { return this.createByType(this.type, bindings); }; InjectionRegisteryService.prototype.createByType = function (type, bindings) { bindings = this.assignDefaults(bindings); var component = this.injectComponent(type, bindings); this.register(type, component); return component; }; InjectionRegisteryService.prototype.destroy = function (instance) { var compsByType = this.components.get(instance.componentType); if (compsByType && compsByType.length) { var idx = compsByType.indexOf(instance); if (idx > -1) { var component = compsByType[idx]; component.destroy(); compsByType.splice(idx, 1); } } }; InjectionRegisteryService.prototype.destroyAll = function () { this.destroyByType(this.type); }; InjectionRegisteryService.prototype.destroyByType = function (type) { var comps = this.components.get(type); if (comps && comps.length) { var i = comps.length - 1; while (i >= 0) { this.destroy(comps[i--]); } } }; InjectionRegisteryService.prototype.injectComponent = function (type, bindings) { return this.injectionService.appendComponent(type, bindings); }; InjectionRegisteryService.prototype.assignDefaults = function (bindings) { var inputs = Object.assign({}, this.defaults.inputs); var outputs = Object.assign({}, this.defaults.outputs); if (!bindings.inputs && !bindings.outputs) { bindings = { inputs: bindings }; } if (inputs) { bindings.inputs = Object.assign(Object.assign({}, inputs), bindings.inputs); } if (outputs) { bindings.outputs = Object.assign(Object.assign({}, outputs), bindings.outputs); } return bindings; }; InjectionRegisteryService.prototype.register = function (type, component) { if (!this.components.has(type)) { this.components.set(type, []); } var types = this.components.get(type); types.push(component); }; return InjectionRegisteryService; }()); var TooltipService = /** @class */ (function (_super) { __extends(TooltipService, _super); function TooltipService(injectionService) { var _this = _super.call(this, injectionService) || this; _this.type = TooltipContentComponent; return _this; } return TooltipService; }(InjectionRegisteryService)); TooltipService.decorators = [ { type: core.Injectable } ]; TooltipService.ctorParameters = function () { return [ { type: InjectionService } ]; }; var ChartComponent = /** @class */ (function () { function ChartComponent() { this.showLegend = false; this.animations = true; this.legendLabelClick = new core.EventEmitter(); this.legendLabelActivate = new core.EventEmitter(); this.legendLabelDeactivate = new core.EventEmitter(); } ChartComponent.prototype.ngOnChanges = function (changes) { this.update(); }; ChartComponent.prototype.update = function () { var legendColumns = 0; if (this.showLegend) { this.legendType = this.getLegendType(); if (!this.legendOptions || this.legendOptions.position === 'right') { if (this.legendType === 'scaleLegend') { legendColumns = 1; } else { legendColumns = 2; } } } var chartColumns = 12 - legendColumns; this.chartWidth = Math.floor((this.view[0] * chartColumns) / 12.0); this.legendWidth = !this.legendOptions || this.legendOptions.position === 'right' ? Math.floor((this.view[0] * legendColumns) / 12.0) : this.chartWidth; }; ChartComponent.prototype.getLegendType = function () { if (this.legendOptions.scaleType === 'linear') { return 'scaleLegend'; } else { return 'legend'; } }; return ChartComponent; }()); ChartComponent.decorators = [ { type: core.Component, args: [{ providers: [TooltipService], selector: 'lcu-charts-chart', template: "\n <div class=\"lcu-charts-outer\" [style.width.px]=\"view[0]\" [@animationState]=\"'active'\" [@.disabled]=\"!animations\">\n <svg class=\"lcu-charts\" [attr.width]=\"chartWidth\" [attr.height]=\"view[1]\">\n <ng-content></ng-content>\n </svg>\n <lcu-charts-scale-legend\n *ngIf=\"showLegend && legendType === 'scaleLegend'\"\n class=\"chart-legend\"\n [horizontal]=\"legendOptions && legendOptions.position === 'below'\"\n [valueRange]=\"legendOptions.domain\"\n [colors]=\"legendOptions.colors\"\n [height]=\"view[1]\"\n [width]=\"legendWidth\"\n >\n </lcu-charts-scale-legend>\n <lcu-charts-legend\n *ngIf=\"showLegend && legendType === 'legend'\"\n class=\"chart-legend\"\n [horizontal]=\"legendOptions && legendOptions.position === 'below'\"\n [data]=\"legendOptions.domain\"\n [title]=\"legendOptions.title\"\n [colors]=\"legendOptions.colors\"\n [height]=\"view[1]\"\n [width]=\"legendWidth\"\n [activeEntries]=\"activeEntries\"\n (labelClick)=\"legendLabelClick.emit($event)\"\n (labelActivate)=\"legendLabelActivate.emit($event)\"\n (labelDeactivate)=\"legendLabelDeactivate.emit($event)\"\n >\n </lcu-charts-legend>\n </div>\n ", changeDetection: core.ChangeDetectionStrategy.OnPush, animations: [ animations.trigger('animationState', [ animations.transition(':enter', [animations.style({ opacity: 0 }), animations.animate('500ms 100ms', animations.style({ opacity: 1 }))]) ]) ] },] } ]; ChartComponent.propDecorators = { view: [{ type: core.Input }], showLegend: [{ type: core.Input }], legendOptions: [{ type: core.Input }], data: [{ type: core.Input }], legendData: [{ type: core.Input }], legendType: [{ type: core.Input }], colors: [{ type: core.Input }], activeEntries: [{ type: core.Input }], animations: [{ type: core.Input }], legendLabelClick: [{ type: core.Output }], legendLabelActivate: [{ type: core.Output }], legendLabelDeactivate: [{ type: core.Output }] }; /** * Visibility Observer */ var VisibilityObserver = /** @class */ (function () { function VisibilityObserver(element, zone) { this.element = element; this.zone = zone; this.visible = new core.EventEmitter(); this.isVisible = false; this.runCheck(); } VisibilityObserver.prototype.destroy = function () { clearTimeout(this.timeout); }; VisibilityObserver.prototype.onVisibilityChange = function () { var _this = this; // trigger zone recalc for columns this.zone.run(function () { _this.isVisible = true; _this.visible.emit(true); }); }; VisibilityObserver.prototype.runCheck = function () { var _this = this; var check = function () { if (!_this.element) { return; } // https://davidwalsh.name/offsetheight-visibility var _a = _this.element.nativeElement, offsetHeight = _a.offsetHeight, offsetWidth = _a.offsetWidth; if (offsetHeight && offsetWidth) { clearTimeout(_this.timeout); _this.onVisibilityChange(); } else { clearTim