dashboard_widget.js
2 years ago
dashboard_widget.js.map
2 years ago
download.js
2 years ago
download.js.map
2 years ago
index.es.aa861507.js
2 years ago
index.es.aa861507.js.map
2 years ago
index.js
2 years ago
index.js.map
2 years ago
layout.js
2 years ago
layout.js.map
2 years ago
purify.2550ab20.js
2 years ago
purify.2550ab20.js.map
2 years ago
settings.js
2 years ago
settings.js.map
2 years ago
dashboard_widget.js
20615 lines
| 1 | // modules are defined as an array |
| 2 | // [ module function, map of requires ] |
| 3 | // |
| 4 | // map of requires is short require name -> numeric require |
| 5 | // |
| 6 | // anything defined in a previous bundle is accessed via the |
| 7 | // orig method which is the require for previous bundles |
| 8 | |
| 9 | (function (modules, entry, mainEntry, parcelRequireName, globalName) { |
| 10 | /* eslint-disable no-undef */ |
| 11 | var globalObject = |
| 12 | typeof globalThis !== 'undefined' |
| 13 | ? globalThis |
| 14 | : typeof self !== 'undefined' |
| 15 | ? self |
| 16 | : typeof window !== 'undefined' |
| 17 | ? window |
| 18 | : typeof global !== 'undefined' |
| 19 | ? global |
| 20 | : {}; |
| 21 | /* eslint-enable no-undef */ |
| 22 | |
| 23 | // Save the require from previous bundle to this closure if any |
| 24 | var previousRequire = |
| 25 | typeof globalObject[parcelRequireName] === 'function' && |
| 26 | globalObject[parcelRequireName]; |
| 27 | |
| 28 | var cache = previousRequire.cache || {}; |
| 29 | // Do not use `require` to prevent Webpack from trying to bundle this call |
| 30 | var nodeRequire = |
| 31 | typeof module !== 'undefined' && |
| 32 | typeof module.require === 'function' && |
| 33 | module.require.bind(module); |
| 34 | |
| 35 | function newRequire(name, jumped) { |
| 36 | if (!cache[name]) { |
| 37 | if (!modules[name]) { |
| 38 | // if we cannot find the module within our internal map or |
| 39 | // cache jump to the current global require ie. the last bundle |
| 40 | // that was added to the page. |
| 41 | var currentRequire = |
| 42 | typeof globalObject[parcelRequireName] === 'function' && |
| 43 | globalObject[parcelRequireName]; |
| 44 | if (!jumped && currentRequire) { |
| 45 | return currentRequire(name, true); |
| 46 | } |
| 47 | |
| 48 | // If there are other bundles on this page the require from the |
| 49 | // previous one is saved to 'previousRequire'. Repeat this as |
| 50 | // many times as there are bundles until the module is found or |
| 51 | // we exhaust the require chain. |
| 52 | if (previousRequire) { |
| 53 | return previousRequire(name, true); |
| 54 | } |
| 55 | |
| 56 | // Try the node require function if it exists. |
| 57 | if (nodeRequire && typeof name === 'string') { |
| 58 | return nodeRequire(name); |
| 59 | } |
| 60 | |
| 61 | var err = new Error("Cannot find module '" + name + "'"); |
| 62 | err.code = 'MODULE_NOT_FOUND'; |
| 63 | throw err; |
| 64 | } |
| 65 | |
| 66 | localRequire.resolve = resolve; |
| 67 | localRequire.cache = {}; |
| 68 | |
| 69 | var module = (cache[name] = new newRequire.Module(name)); |
| 70 | |
| 71 | modules[name][0].call( |
| 72 | module.exports, |
| 73 | localRequire, |
| 74 | module, |
| 75 | module.exports, |
| 76 | this |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | return cache[name].exports; |
| 81 | |
| 82 | function localRequire(x) { |
| 83 | var res = localRequire.resolve(x); |
| 84 | return res === false ? {} : newRequire(res); |
| 85 | } |
| 86 | |
| 87 | function resolve(x) { |
| 88 | var id = modules[name][1][x]; |
| 89 | return id != null ? id : x; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | function Module(moduleName) { |
| 94 | this.id = moduleName; |
| 95 | this.bundle = newRequire; |
| 96 | this.exports = {}; |
| 97 | } |
| 98 | |
| 99 | newRequire.isParcelRequire = true; |
| 100 | newRequire.Module = Module; |
| 101 | newRequire.modules = modules; |
| 102 | newRequire.cache = cache; |
| 103 | newRequire.parent = previousRequire; |
| 104 | newRequire.register = function (id, exports) { |
| 105 | modules[id] = [ |
| 106 | function (require, module) { |
| 107 | module.exports = exports; |
| 108 | }, |
| 109 | {}, |
| 110 | ]; |
| 111 | }; |
| 112 | |
| 113 | Object.defineProperty(newRequire, 'root', { |
| 114 | get: function () { |
| 115 | return globalObject[parcelRequireName]; |
| 116 | }, |
| 117 | }); |
| 118 | |
| 119 | globalObject[parcelRequireName] = newRequire; |
| 120 | |
| 121 | for (var i = 0; i < entry.length; i++) { |
| 122 | newRequire(entry[i]); |
| 123 | } |
| 124 | |
| 125 | if (mainEntry) { |
| 126 | // Expose entry point to Node, AMD or browser globals |
| 127 | // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js |
| 128 | var mainExports = newRequire(mainEntry); |
| 129 | |
| 130 | // CommonJS |
| 131 | if (typeof exports === 'object' && typeof module !== 'undefined') { |
| 132 | module.exports = mainExports; |
| 133 | |
| 134 | // RequireJS |
| 135 | } else if (typeof define === 'function' && define.amd) { |
| 136 | define(function () { |
| 137 | return mainExports; |
| 138 | }); |
| 139 | |
| 140 | // <script> |
| 141 | } else if (globalName) { |
| 142 | this[globalName] = mainExports; |
| 143 | } |
| 144 | } |
| 145 | })({"kILFo":[function(require,module,exports) { |
| 146 | var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); |
| 147 | var _stimulus = require("@hotwired/stimulus"); |
| 148 | var _chartController = require("./controllers/chart_controller"); |
| 149 | var _chartControllerDefault = parcelHelpers.interopDefault(_chartController); |
| 150 | window.Stimulus = (0, _stimulus.Application).start(); |
| 151 | Stimulus.register("chart", (0, _chartControllerDefault.default)); |
| 152 | |
| 153 | },{"@hotwired/stimulus":"27q4D","./controllers/chart_controller":"irT0c","@parcel/transformer-js/src/esmodule-helpers.js":"jIm8e"}],"27q4D":[function(require,module,exports) { |
| 154 | var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); |
| 155 | parcelHelpers.defineInteropFlag(exports); |
| 156 | parcelHelpers.export(exports, "Application", function() { |
| 157 | return Application; |
| 158 | }); |
| 159 | parcelHelpers.export(exports, "AttributeObserver", function() { |
| 160 | return AttributeObserver; |
| 161 | }); |
| 162 | parcelHelpers.export(exports, "Context", function() { |
| 163 | return Context; |
| 164 | }); |
| 165 | parcelHelpers.export(exports, "Controller", function() { |
| 166 | return Controller; |
| 167 | }); |
| 168 | parcelHelpers.export(exports, "ElementObserver", function() { |
| 169 | return ElementObserver; |
| 170 | }); |
| 171 | parcelHelpers.export(exports, "IndexedMultimap", function() { |
| 172 | return IndexedMultimap; |
| 173 | }); |
| 174 | parcelHelpers.export(exports, "Multimap", function() { |
| 175 | return Multimap; |
| 176 | }); |
| 177 | parcelHelpers.export(exports, "StringMapObserver", function() { |
| 178 | return StringMapObserver; |
| 179 | }); |
| 180 | parcelHelpers.export(exports, "TokenListObserver", function() { |
| 181 | return TokenListObserver; |
| 182 | }); |
| 183 | parcelHelpers.export(exports, "ValueListObserver", function() { |
| 184 | return ValueListObserver; |
| 185 | }); |
| 186 | parcelHelpers.export(exports, "add", function() { |
| 187 | return add; |
| 188 | }); |
| 189 | parcelHelpers.export(exports, "defaultSchema", function() { |
| 190 | return defaultSchema; |
| 191 | }); |
| 192 | parcelHelpers.export(exports, "del", function() { |
| 193 | return del; |
| 194 | }); |
| 195 | parcelHelpers.export(exports, "fetch", function() { |
| 196 | return fetch; |
| 197 | }); |
| 198 | parcelHelpers.export(exports, "prune", function() { |
| 199 | return prune; |
| 200 | }); |
| 201 | var _asyncToGeneratorJs = require("@swc/helpers/lib/_async_to_generator.js"); |
| 202 | var _asyncToGeneratorJsDefault = parcelHelpers.interopDefault(_asyncToGeneratorJs); |
| 203 | var _classCallCheckJs = require("@swc/helpers/lib/_class_call_check.js"); |
| 204 | var _classCallCheckJsDefault = parcelHelpers.interopDefault(_classCallCheckJs); |
| 205 | var _createClassJs = require("@swc/helpers/lib/_create_class.js"); |
| 206 | var _createClassJsDefault = parcelHelpers.interopDefault(_createClassJs); |
| 207 | var _definePropertyJs = require("@swc/helpers/lib/_define_property.js"); |
| 208 | var _definePropertyJsDefault = parcelHelpers.interopDefault(_definePropertyJs); |
| 209 | var _getJs = require("@swc/helpers/lib/_get.js"); |
| 210 | var _getJsDefault = parcelHelpers.interopDefault(_getJs); |
| 211 | var _getPrototypeOfJs = require("@swc/helpers/lib/_get_prototype_of.js"); |
| 212 | var _getPrototypeOfJsDefault = parcelHelpers.interopDefault(_getPrototypeOfJs); |
| 213 | var _inheritsJs = require("@swc/helpers/lib/_inherits.js"); |
| 214 | var _inheritsJsDefault = parcelHelpers.interopDefault(_inheritsJs); |
| 215 | var _slicedToArrayJs = require("@swc/helpers/lib/_sliced_to_array.js"); |
| 216 | var _slicedToArrayJsDefault = parcelHelpers.interopDefault(_slicedToArrayJs); |
| 217 | var _toConsumableArrayJs = require("@swc/helpers/lib/_to_consumable_array.js"); |
| 218 | var _toConsumableArrayJsDefault = parcelHelpers.interopDefault(_toConsumableArrayJs); |
| 219 | var _typeOfJs = require("@swc/helpers/lib/_type_of.js"); |
| 220 | var _typeOfJsDefault = parcelHelpers.interopDefault(_typeOfJs); |
| 221 | var _createSuperJs = require("@swc/helpers/lib/_create_super.js"); |
| 222 | var _createSuperJsDefault = parcelHelpers.interopDefault(_createSuperJs); |
| 223 | var _regeneratorRuntime = require("regenerator-runtime"); |
| 224 | var _regeneratorRuntimeDefault = parcelHelpers.interopDefault(_regeneratorRuntime); |
| 225 | /* |
| 226 | Stimulus 3.0.1 |
| 227 | Copyright © 2021 Basecamp, LLC |
| 228 | */ var EventListener = /*#__PURE__*/ function() { |
| 229 | "use strict"; |
| 230 | function EventListener(eventTarget, eventName, eventOptions) { |
| 231 | (0, _classCallCheckJsDefault.default)(this, EventListener); |
| 232 | this.eventTarget = eventTarget; |
| 233 | this.eventName = eventName; |
| 234 | this.eventOptions = eventOptions; |
| 235 | this.unorderedBindings = new Set(); |
| 236 | } |
| 237 | (0, _createClassJsDefault.default)(EventListener, [ |
| 238 | { |
| 239 | key: "connect", |
| 240 | value: function connect() { |
| 241 | this.eventTarget.addEventListener(this.eventName, this, this.eventOptions); |
| 242 | } |
| 243 | }, |
| 244 | { |
| 245 | key: "disconnect", |
| 246 | value: function disconnect() { |
| 247 | this.eventTarget.removeEventListener(this.eventName, this, this.eventOptions); |
| 248 | } |
| 249 | }, |
| 250 | { |
| 251 | key: "bindingConnected", |
| 252 | value: function bindingConnected(binding) { |
| 253 | this.unorderedBindings.add(binding); |
| 254 | } |
| 255 | }, |
| 256 | { |
| 257 | key: "bindingDisconnected", |
| 258 | value: function bindingDisconnected(binding) { |
| 259 | this.unorderedBindings.delete(binding); |
| 260 | } |
| 261 | }, |
| 262 | { |
| 263 | key: "handleEvent", |
| 264 | value: function handleEvent(event) { |
| 265 | var extendedEvent = extendEvent(event); |
| 266 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 267 | try { |
| 268 | for(var _iterator = this.bindings[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 269 | var binding = _step.value; |
| 270 | if (extendedEvent.immediatePropagationStopped) break; |
| 271 | else binding.handleEvent(extendedEvent); |
| 272 | } |
| 273 | } catch (err) { |
| 274 | _didIteratorError = true; |
| 275 | _iteratorError = err; |
| 276 | } finally{ |
| 277 | try { |
| 278 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 279 | _iterator.return(); |
| 280 | } |
| 281 | } finally{ |
| 282 | if (_didIteratorError) { |
| 283 | throw _iteratorError; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | }, |
| 289 | { |
| 290 | key: "bindings", |
| 291 | get: function get() { |
| 292 | return Array.from(this.unorderedBindings).sort(function(left, right) { |
| 293 | var leftIndex = left.index, rightIndex = right.index; |
| 294 | return leftIndex < rightIndex ? -1 : leftIndex > rightIndex ? 1 : 0; |
| 295 | }); |
| 296 | } |
| 297 | } |
| 298 | ]); |
| 299 | return EventListener; |
| 300 | }(); |
| 301 | function extendEvent(event) { |
| 302 | if ("immediatePropagationStopped" in event) return event; |
| 303 | else { |
| 304 | var stopImmediatePropagation = event.stopImmediatePropagation; |
| 305 | return Object.assign(event, { |
| 306 | immediatePropagationStopped: false, |
| 307 | stopImmediatePropagation: function() { |
| 308 | this.immediatePropagationStopped = true; |
| 309 | stopImmediatePropagation.call(this); |
| 310 | } |
| 311 | }); |
| 312 | } |
| 313 | } |
| 314 | var Dispatcher = /*#__PURE__*/ function() { |
| 315 | "use strict"; |
| 316 | function Dispatcher(application) { |
| 317 | (0, _classCallCheckJsDefault.default)(this, Dispatcher); |
| 318 | this.application = application; |
| 319 | this.eventListenerMaps = new Map; |
| 320 | this.started = false; |
| 321 | } |
| 322 | (0, _createClassJsDefault.default)(Dispatcher, [ |
| 323 | { |
| 324 | key: "start", |
| 325 | value: function start() { |
| 326 | if (!this.started) { |
| 327 | this.started = true; |
| 328 | this.eventListeners.forEach(function(eventListener) { |
| 329 | return eventListener.connect(); |
| 330 | }); |
| 331 | } |
| 332 | } |
| 333 | }, |
| 334 | { |
| 335 | key: "stop", |
| 336 | value: function stop() { |
| 337 | if (this.started) { |
| 338 | this.started = false; |
| 339 | this.eventListeners.forEach(function(eventListener) { |
| 340 | return eventListener.disconnect(); |
| 341 | }); |
| 342 | } |
| 343 | } |
| 344 | }, |
| 345 | { |
| 346 | key: "eventListeners", |
| 347 | get: function get() { |
| 348 | return Array.from(this.eventListenerMaps.values()).reduce(function(listeners, map) { |
| 349 | return listeners.concat(Array.from(map.values())); |
| 350 | }, []); |
| 351 | } |
| 352 | }, |
| 353 | { |
| 354 | key: "bindingConnected", |
| 355 | value: function bindingConnected(binding) { |
| 356 | this.fetchEventListenerForBinding(binding).bindingConnected(binding); |
| 357 | } |
| 358 | }, |
| 359 | { |
| 360 | key: "bindingDisconnected", |
| 361 | value: function bindingDisconnected(binding) { |
| 362 | this.fetchEventListenerForBinding(binding).bindingDisconnected(binding); |
| 363 | } |
| 364 | }, |
| 365 | { |
| 366 | key: "handleError", |
| 367 | value: function handleError(error1, message) { |
| 368 | var detail = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}; |
| 369 | this.application.handleError(error1, "Error ".concat(message), detail); |
| 370 | } |
| 371 | }, |
| 372 | { |
| 373 | key: "fetchEventListenerForBinding", |
| 374 | value: function fetchEventListenerForBinding(binding) { |
| 375 | var eventTarget = binding.eventTarget, eventName = binding.eventName, eventOptions = binding.eventOptions; |
| 376 | return this.fetchEventListener(eventTarget, eventName, eventOptions); |
| 377 | } |
| 378 | }, |
| 379 | { |
| 380 | key: "fetchEventListener", |
| 381 | value: function fetchEventListener(eventTarget, eventName, eventOptions) { |
| 382 | var eventListenerMap = this.fetchEventListenerMapForEventTarget(eventTarget); |
| 383 | var cacheKey = this.cacheKey(eventName, eventOptions); |
| 384 | var eventListener = eventListenerMap.get(cacheKey); |
| 385 | if (!eventListener) { |
| 386 | eventListener = this.createEventListener(eventTarget, eventName, eventOptions); |
| 387 | eventListenerMap.set(cacheKey, eventListener); |
| 388 | } |
| 389 | return eventListener; |
| 390 | } |
| 391 | }, |
| 392 | { |
| 393 | key: "createEventListener", |
| 394 | value: function createEventListener(eventTarget, eventName, eventOptions) { |
| 395 | var eventListener = new EventListener(eventTarget, eventName, eventOptions); |
| 396 | if (this.started) eventListener.connect(); |
| 397 | return eventListener; |
| 398 | } |
| 399 | }, |
| 400 | { |
| 401 | key: "fetchEventListenerMapForEventTarget", |
| 402 | value: function fetchEventListenerMapForEventTarget(eventTarget) { |
| 403 | var eventListenerMap = this.eventListenerMaps.get(eventTarget); |
| 404 | if (!eventListenerMap) { |
| 405 | eventListenerMap = new Map; |
| 406 | this.eventListenerMaps.set(eventTarget, eventListenerMap); |
| 407 | } |
| 408 | return eventListenerMap; |
| 409 | } |
| 410 | }, |
| 411 | { |
| 412 | key: "cacheKey", |
| 413 | value: function cacheKey(eventName, eventOptions) { |
| 414 | var parts = [ |
| 415 | eventName |
| 416 | ]; |
| 417 | Object.keys(eventOptions).sort().forEach(function(key) { |
| 418 | parts.push("".concat(eventOptions[key] ? "" : "!").concat(key)); |
| 419 | }); |
| 420 | return parts.join(":"); |
| 421 | } |
| 422 | } |
| 423 | ]); |
| 424 | return Dispatcher; |
| 425 | }(); |
| 426 | var descriptorPattern = /^((.+?)(@(window|document))?->)?(.+?)(#([^:]+?))(:(.+))?$/; |
| 427 | function parseActionDescriptorString(descriptorString) { |
| 428 | var source = descriptorString.trim(); |
| 429 | var matches = source.match(descriptorPattern) || []; |
| 430 | return { |
| 431 | eventTarget: parseEventTarget(matches[4]), |
| 432 | eventName: matches[2], |
| 433 | eventOptions: matches[9] ? parseEventOptions(matches[9]) : {}, |
| 434 | identifier: matches[5], |
| 435 | methodName: matches[7] |
| 436 | }; |
| 437 | } |
| 438 | function parseEventTarget(eventTargetName) { |
| 439 | if (eventTargetName == "window") return window; |
| 440 | else if (eventTargetName == "document") return document; |
| 441 | } |
| 442 | function parseEventOptions(eventOptions) { |
| 443 | return eventOptions.split(":").reduce(function(options, token) { |
| 444 | return Object.assign(options, (0, _definePropertyJsDefault.default)({}, token.replace(/^!/, ""), !/^!/.test(token))); |
| 445 | }, {}); |
| 446 | } |
| 447 | function stringifyEventTarget(eventTarget) { |
| 448 | if (eventTarget == window) return "window"; |
| 449 | else if (eventTarget == document) return "document"; |
| 450 | } |
| 451 | function camelize(value) { |
| 452 | return value.replace(/(?:[_-])([a-z0-9])/g, function(_, char) { |
| 453 | return char.toUpperCase(); |
| 454 | }); |
| 455 | } |
| 456 | function capitalize(value) { |
| 457 | return value.charAt(0).toUpperCase() + value.slice(1); |
| 458 | } |
| 459 | function dasherize(value) { |
| 460 | return value.replace(/([A-Z])/g, function(_, char) { |
| 461 | return "-".concat(char.toLowerCase()); |
| 462 | }); |
| 463 | } |
| 464 | function tokenize(value) { |
| 465 | return value.match(/[^\s]+/g) || []; |
| 466 | } |
| 467 | var Action = /*#__PURE__*/ function() { |
| 468 | "use strict"; |
| 469 | function Action(element, index, descriptor) { |
| 470 | (0, _classCallCheckJsDefault.default)(this, Action); |
| 471 | this.element = element; |
| 472 | this.index = index; |
| 473 | this.eventTarget = descriptor.eventTarget || element; |
| 474 | this.eventName = descriptor.eventName || getDefaultEventNameForElement(element) || error("missing event name"); |
| 475 | this.eventOptions = descriptor.eventOptions || {}; |
| 476 | this.identifier = descriptor.identifier || error("missing identifier"); |
| 477 | this.methodName = descriptor.methodName || error("missing method name"); |
| 478 | } |
| 479 | (0, _createClassJsDefault.default)(Action, [ |
| 480 | { |
| 481 | key: "toString", |
| 482 | value: function toString() { |
| 483 | var eventNameSuffix = this.eventTargetName ? "@".concat(this.eventTargetName) : ""; |
| 484 | return "".concat(this.eventName).concat(eventNameSuffix, "->").concat(this.identifier, "#").concat(this.methodName); |
| 485 | } |
| 486 | }, |
| 487 | { |
| 488 | key: "params", |
| 489 | get: function get() { |
| 490 | if (this.eventTarget instanceof Element) return this.getParamsFromEventTargetAttributes(this.eventTarget); |
| 491 | else return {}; |
| 492 | } |
| 493 | }, |
| 494 | { |
| 495 | key: "getParamsFromEventTargetAttributes", |
| 496 | value: function getParamsFromEventTargetAttributes(eventTarget) { |
| 497 | var params = {}; |
| 498 | var pattern = new RegExp("^data-".concat(this.identifier, "-(.+)-param$")); |
| 499 | var attributes = Array.from(eventTarget.attributes); |
| 500 | attributes.forEach(function(param) { |
| 501 | var name = param.name, value = param.value; |
| 502 | var match = name.match(pattern); |
| 503 | var key = match && match[1]; |
| 504 | if (key) Object.assign(params, (0, _definePropertyJsDefault.default)({}, camelize(key), typecast(value))); |
| 505 | }); |
| 506 | return params; |
| 507 | } |
| 508 | }, |
| 509 | { |
| 510 | key: "eventTargetName", |
| 511 | get: function get() { |
| 512 | return stringifyEventTarget(this.eventTarget); |
| 513 | } |
| 514 | } |
| 515 | ], [ |
| 516 | { |
| 517 | key: "forToken", |
| 518 | value: function forToken(token) { |
| 519 | return new this(token.element, token.index, parseActionDescriptorString(token.content)); |
| 520 | } |
| 521 | } |
| 522 | ]); |
| 523 | return Action; |
| 524 | }(); |
| 525 | var defaultEventNames = { |
| 526 | "a": function(e) { |
| 527 | return "click"; |
| 528 | }, |
| 529 | "button": function(e) { |
| 530 | return "click"; |
| 531 | }, |
| 532 | "form": function(e) { |
| 533 | return "submit"; |
| 534 | }, |
| 535 | "details": function(e) { |
| 536 | return "toggle"; |
| 537 | }, |
| 538 | "input": function(e) { |
| 539 | return e.getAttribute("type") == "submit" ? "click" : "input"; |
| 540 | }, |
| 541 | "select": function(e) { |
| 542 | return "change"; |
| 543 | }, |
| 544 | "textarea": function(e) { |
| 545 | return "input"; |
| 546 | } |
| 547 | }; |
| 548 | function getDefaultEventNameForElement(element) { |
| 549 | var tagName = element.tagName.toLowerCase(); |
| 550 | if (tagName in defaultEventNames) return defaultEventNames[tagName](element); |
| 551 | } |
| 552 | function error(message) { |
| 553 | throw new Error(message); |
| 554 | } |
| 555 | function typecast(value) { |
| 556 | try { |
| 557 | return JSON.parse(value); |
| 558 | } catch (o_O) { |
| 559 | return value; |
| 560 | } |
| 561 | } |
| 562 | var Binding = /*#__PURE__*/ function() { |
| 563 | "use strict"; |
| 564 | function Binding(context, action) { |
| 565 | (0, _classCallCheckJsDefault.default)(this, Binding); |
| 566 | this.context = context; |
| 567 | this.action = action; |
| 568 | } |
| 569 | (0, _createClassJsDefault.default)(Binding, [ |
| 570 | { |
| 571 | key: "index", |
| 572 | get: function get() { |
| 573 | return this.action.index; |
| 574 | } |
| 575 | }, |
| 576 | { |
| 577 | key: "eventTarget", |
| 578 | get: function get() { |
| 579 | return this.action.eventTarget; |
| 580 | } |
| 581 | }, |
| 582 | { |
| 583 | key: "eventOptions", |
| 584 | get: function get() { |
| 585 | return this.action.eventOptions; |
| 586 | } |
| 587 | }, |
| 588 | { |
| 589 | key: "identifier", |
| 590 | get: function get() { |
| 591 | return this.context.identifier; |
| 592 | } |
| 593 | }, |
| 594 | { |
| 595 | key: "handleEvent", |
| 596 | value: function handleEvent(event) { |
| 597 | if (this.willBeInvokedByEvent(event)) this.invokeWithEvent(event); |
| 598 | } |
| 599 | }, |
| 600 | { |
| 601 | key: "eventName", |
| 602 | get: function get() { |
| 603 | return this.action.eventName; |
| 604 | } |
| 605 | }, |
| 606 | { |
| 607 | key: "method", |
| 608 | get: function get() { |
| 609 | var method = this.controller[this.methodName]; |
| 610 | if (typeof method == "function") return method; |
| 611 | throw new Error('Action "'.concat(this.action, '" references undefined method "').concat(this.methodName, '"')); |
| 612 | } |
| 613 | }, |
| 614 | { |
| 615 | key: "invokeWithEvent", |
| 616 | value: function invokeWithEvent(event) { |
| 617 | var target = event.target, currentTarget = event.currentTarget; |
| 618 | try { |
| 619 | var params = this.action.params; |
| 620 | var actionEvent = Object.assign(event, { |
| 621 | params: params |
| 622 | }); |
| 623 | this.method.call(this.controller, actionEvent); |
| 624 | this.context.logDebugActivity(this.methodName, { |
| 625 | event: event, |
| 626 | target: target, |
| 627 | currentTarget: currentTarget, |
| 628 | action: this.methodName |
| 629 | }); |
| 630 | } catch (error2) { |
| 631 | var ref = this, identifier = ref.identifier, controller = ref.controller, element = ref.element, index = ref.index; |
| 632 | var detail = { |
| 633 | identifier: identifier, |
| 634 | controller: controller, |
| 635 | element: element, |
| 636 | index: index, |
| 637 | event: event |
| 638 | }; |
| 639 | this.context.handleError(error2, 'invoking action "'.concat(this.action, '"'), detail); |
| 640 | } |
| 641 | } |
| 642 | }, |
| 643 | { |
| 644 | key: "willBeInvokedByEvent", |
| 645 | value: function willBeInvokedByEvent(event) { |
| 646 | var eventTarget = event.target; |
| 647 | if (this.element === eventTarget) return true; |
| 648 | else if (eventTarget instanceof Element && this.element.contains(eventTarget)) return this.scope.containsElement(eventTarget); |
| 649 | else return this.scope.containsElement(this.action.element); |
| 650 | } |
| 651 | }, |
| 652 | { |
| 653 | key: "controller", |
| 654 | get: function get() { |
| 655 | return this.context.controller; |
| 656 | } |
| 657 | }, |
| 658 | { |
| 659 | key: "methodName", |
| 660 | get: function get() { |
| 661 | return this.action.methodName; |
| 662 | } |
| 663 | }, |
| 664 | { |
| 665 | key: "element", |
| 666 | get: function get() { |
| 667 | return this.scope.element; |
| 668 | } |
| 669 | }, |
| 670 | { |
| 671 | key: "scope", |
| 672 | get: function get() { |
| 673 | return this.context.scope; |
| 674 | } |
| 675 | } |
| 676 | ]); |
| 677 | return Binding; |
| 678 | }(); |
| 679 | var ElementObserver = /*#__PURE__*/ function() { |
| 680 | "use strict"; |
| 681 | function ElementObserver(element, delegate) { |
| 682 | var _this = this; |
| 683 | (0, _classCallCheckJsDefault.default)(this, ElementObserver); |
| 684 | this.mutationObserverInit = { |
| 685 | attributes: true, |
| 686 | childList: true, |
| 687 | subtree: true |
| 688 | }; |
| 689 | this.element = element; |
| 690 | this.started = false; |
| 691 | this.delegate = delegate; |
| 692 | this.elements = new Set; |
| 693 | this.mutationObserver = new MutationObserver(function(mutations) { |
| 694 | return _this.processMutations(mutations); |
| 695 | }); |
| 696 | } |
| 697 | (0, _createClassJsDefault.default)(ElementObserver, [ |
| 698 | { |
| 699 | key: "start", |
| 700 | value: function start() { |
| 701 | if (!this.started) { |
| 702 | this.started = true; |
| 703 | this.mutationObserver.observe(this.element, this.mutationObserverInit); |
| 704 | this.refresh(); |
| 705 | } |
| 706 | } |
| 707 | }, |
| 708 | { |
| 709 | key: "pause", |
| 710 | value: function pause(callback) { |
| 711 | if (this.started) { |
| 712 | this.mutationObserver.disconnect(); |
| 713 | this.started = false; |
| 714 | } |
| 715 | callback(); |
| 716 | if (!this.started) { |
| 717 | this.mutationObserver.observe(this.element, this.mutationObserverInit); |
| 718 | this.started = true; |
| 719 | } |
| 720 | } |
| 721 | }, |
| 722 | { |
| 723 | key: "stop", |
| 724 | value: function stop() { |
| 725 | if (this.started) { |
| 726 | this.mutationObserver.takeRecords(); |
| 727 | this.mutationObserver.disconnect(); |
| 728 | this.started = false; |
| 729 | } |
| 730 | } |
| 731 | }, |
| 732 | { |
| 733 | key: "refresh", |
| 734 | value: function refresh() { |
| 735 | if (this.started) { |
| 736 | var matches = new Set(this.matchElementsInTree()); |
| 737 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 738 | try { |
| 739 | for(var _iterator = Array.from(this.elements)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 740 | var element = _step.value; |
| 741 | if (!matches.has(element)) this.removeElement(element); |
| 742 | } |
| 743 | } catch (err) { |
| 744 | _didIteratorError = true; |
| 745 | _iteratorError = err; |
| 746 | } finally{ |
| 747 | try { |
| 748 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 749 | _iterator.return(); |
| 750 | } |
| 751 | } finally{ |
| 752 | if (_didIteratorError) { |
| 753 | throw _iteratorError; |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; |
| 758 | try { |
| 759 | for(var _iterator1 = Array.from(matches)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ |
| 760 | var element1 = _step1.value; |
| 761 | this.addElement(element1); |
| 762 | } |
| 763 | } catch (err) { |
| 764 | _didIteratorError1 = true; |
| 765 | _iteratorError1 = err; |
| 766 | } finally{ |
| 767 | try { |
| 768 | if (!_iteratorNormalCompletion1 && _iterator1.return != null) { |
| 769 | _iterator1.return(); |
| 770 | } |
| 771 | } finally{ |
| 772 | if (_didIteratorError1) { |
| 773 | throw _iteratorError1; |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | }, |
| 780 | { |
| 781 | key: "processMutations", |
| 782 | value: function processMutations(mutations) { |
| 783 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 784 | if (this.started) try { |
| 785 | for(var _iterator = mutations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 786 | var mutation = _step.value; |
| 787 | this.processMutation(mutation); |
| 788 | } |
| 789 | } catch (err) { |
| 790 | _didIteratorError = true; |
| 791 | _iteratorError = err; |
| 792 | } finally{ |
| 793 | try { |
| 794 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 795 | _iterator.return(); |
| 796 | } |
| 797 | } finally{ |
| 798 | if (_didIteratorError) { |
| 799 | throw _iteratorError; |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | }, |
| 805 | { |
| 806 | key: "processMutation", |
| 807 | value: function processMutation(mutation) { |
| 808 | if (mutation.type == "attributes") this.processAttributeChange(mutation.target, mutation.attributeName); |
| 809 | else if (mutation.type == "childList") { |
| 810 | this.processRemovedNodes(mutation.removedNodes); |
| 811 | this.processAddedNodes(mutation.addedNodes); |
| 812 | } |
| 813 | } |
| 814 | }, |
| 815 | { |
| 816 | key: "processAttributeChange", |
| 817 | value: function processAttributeChange(node, attributeName) { |
| 818 | var element = node; |
| 819 | if (this.elements.has(element)) { |
| 820 | if (this.delegate.elementAttributeChanged && this.matchElement(element)) this.delegate.elementAttributeChanged(element, attributeName); |
| 821 | else this.removeElement(element); |
| 822 | } else if (this.matchElement(element)) this.addElement(element); |
| 823 | } |
| 824 | }, |
| 825 | { |
| 826 | key: "processRemovedNodes", |
| 827 | value: function processRemovedNodes(nodes) { |
| 828 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 829 | try { |
| 830 | for(var _iterator = Array.from(nodes)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 831 | var node = _step.value; |
| 832 | var element = this.elementFromNode(node); |
| 833 | if (element) this.processTree(element, this.removeElement); |
| 834 | } |
| 835 | } catch (err) { |
| 836 | _didIteratorError = true; |
| 837 | _iteratorError = err; |
| 838 | } finally{ |
| 839 | try { |
| 840 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 841 | _iterator.return(); |
| 842 | } |
| 843 | } finally{ |
| 844 | if (_didIteratorError) { |
| 845 | throw _iteratorError; |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | } |
| 850 | }, |
| 851 | { |
| 852 | key: "processAddedNodes", |
| 853 | value: function processAddedNodes(nodes) { |
| 854 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 855 | try { |
| 856 | for(var _iterator = Array.from(nodes)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 857 | var node = _step.value; |
| 858 | var element = this.elementFromNode(node); |
| 859 | if (element && this.elementIsActive(element)) this.processTree(element, this.addElement); |
| 860 | } |
| 861 | } catch (err) { |
| 862 | _didIteratorError = true; |
| 863 | _iteratorError = err; |
| 864 | } finally{ |
| 865 | try { |
| 866 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 867 | _iterator.return(); |
| 868 | } |
| 869 | } finally{ |
| 870 | if (_didIteratorError) { |
| 871 | throw _iteratorError; |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | } |
| 876 | }, |
| 877 | { |
| 878 | key: "matchElement", |
| 879 | value: function matchElement(element) { |
| 880 | return this.delegate.matchElement(element); |
| 881 | } |
| 882 | }, |
| 883 | { |
| 884 | key: "matchElementsInTree", |
| 885 | value: function matchElementsInTree() { |
| 886 | var tree = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.element; |
| 887 | return this.delegate.matchElementsInTree(tree); |
| 888 | } |
| 889 | }, |
| 890 | { |
| 891 | key: "processTree", |
| 892 | value: function processTree(tree, processor) { |
| 893 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 894 | try { |
| 895 | for(var _iterator = this.matchElementsInTree(tree)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 896 | var element = _step.value; |
| 897 | processor.call(this, element); |
| 898 | } |
| 899 | } catch (err) { |
| 900 | _didIteratorError = true; |
| 901 | _iteratorError = err; |
| 902 | } finally{ |
| 903 | try { |
| 904 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 905 | _iterator.return(); |
| 906 | } |
| 907 | } finally{ |
| 908 | if (_didIteratorError) { |
| 909 | throw _iteratorError; |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | }, |
| 915 | { |
| 916 | key: "elementFromNode", |
| 917 | value: function elementFromNode(node) { |
| 918 | if (node.nodeType == Node.ELEMENT_NODE) return node; |
| 919 | } |
| 920 | }, |
| 921 | { |
| 922 | key: "elementIsActive", |
| 923 | value: function elementIsActive(element) { |
| 924 | if (element.isConnected != this.element.isConnected) return false; |
| 925 | else return this.element.contains(element); |
| 926 | } |
| 927 | }, |
| 928 | { |
| 929 | key: "addElement", |
| 930 | value: function addElement(element) { |
| 931 | if (!this.elements.has(element)) { |
| 932 | if (this.elementIsActive(element)) { |
| 933 | this.elements.add(element); |
| 934 | if (this.delegate.elementMatched) this.delegate.elementMatched(element); |
| 935 | } |
| 936 | } |
| 937 | } |
| 938 | }, |
| 939 | { |
| 940 | key: "removeElement", |
| 941 | value: function removeElement(element) { |
| 942 | if (this.elements.has(element)) { |
| 943 | this.elements.delete(element); |
| 944 | if (this.delegate.elementUnmatched) this.delegate.elementUnmatched(element); |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | ]); |
| 949 | return ElementObserver; |
| 950 | }(); |
| 951 | var AttributeObserver = /*#__PURE__*/ function() { |
| 952 | "use strict"; |
| 953 | function AttributeObserver(element, attributeName, delegate) { |
| 954 | (0, _classCallCheckJsDefault.default)(this, AttributeObserver); |
| 955 | this.attributeName = attributeName; |
| 956 | this.delegate = delegate; |
| 957 | this.elementObserver = new ElementObserver(element, this); |
| 958 | } |
| 959 | (0, _createClassJsDefault.default)(AttributeObserver, [ |
| 960 | { |
| 961 | key: "element", |
| 962 | get: function get() { |
| 963 | return this.elementObserver.element; |
| 964 | } |
| 965 | }, |
| 966 | { |
| 967 | key: "selector", |
| 968 | get: function get() { |
| 969 | return "[".concat(this.attributeName, "]"); |
| 970 | } |
| 971 | }, |
| 972 | { |
| 973 | key: "start", |
| 974 | value: function start() { |
| 975 | this.elementObserver.start(); |
| 976 | } |
| 977 | }, |
| 978 | { |
| 979 | key: "pause", |
| 980 | value: function pause(callback) { |
| 981 | this.elementObserver.pause(callback); |
| 982 | } |
| 983 | }, |
| 984 | { |
| 985 | key: "stop", |
| 986 | value: function stop() { |
| 987 | this.elementObserver.stop(); |
| 988 | } |
| 989 | }, |
| 990 | { |
| 991 | key: "refresh", |
| 992 | value: function refresh() { |
| 993 | this.elementObserver.refresh(); |
| 994 | } |
| 995 | }, |
| 996 | { |
| 997 | key: "started", |
| 998 | get: function get() { |
| 999 | return this.elementObserver.started; |
| 1000 | } |
| 1001 | }, |
| 1002 | { |
| 1003 | key: "matchElement", |
| 1004 | value: function matchElement(element) { |
| 1005 | return element.hasAttribute(this.attributeName); |
| 1006 | } |
| 1007 | }, |
| 1008 | { |
| 1009 | key: "matchElementsInTree", |
| 1010 | value: function matchElementsInTree(tree) { |
| 1011 | var match = this.matchElement(tree) ? [ |
| 1012 | tree |
| 1013 | ] : []; |
| 1014 | var matches = Array.from(tree.querySelectorAll(this.selector)); |
| 1015 | return match.concat(matches); |
| 1016 | } |
| 1017 | }, |
| 1018 | { |
| 1019 | key: "elementMatched", |
| 1020 | value: function elementMatched(element) { |
| 1021 | if (this.delegate.elementMatchedAttribute) this.delegate.elementMatchedAttribute(element, this.attributeName); |
| 1022 | } |
| 1023 | }, |
| 1024 | { |
| 1025 | key: "elementUnmatched", |
| 1026 | value: function elementUnmatched(element) { |
| 1027 | if (this.delegate.elementUnmatchedAttribute) this.delegate.elementUnmatchedAttribute(element, this.attributeName); |
| 1028 | } |
| 1029 | }, |
| 1030 | { |
| 1031 | key: "elementAttributeChanged", |
| 1032 | value: function elementAttributeChanged(element, attributeName) { |
| 1033 | if (this.delegate.elementAttributeValueChanged && this.attributeName == attributeName) this.delegate.elementAttributeValueChanged(element, attributeName); |
| 1034 | } |
| 1035 | } |
| 1036 | ]); |
| 1037 | return AttributeObserver; |
| 1038 | }(); |
| 1039 | var StringMapObserver = /*#__PURE__*/ function() { |
| 1040 | "use strict"; |
| 1041 | function StringMapObserver(element, delegate) { |
| 1042 | var _this = this; |
| 1043 | (0, _classCallCheckJsDefault.default)(this, StringMapObserver); |
| 1044 | this.element = element; |
| 1045 | this.delegate = delegate; |
| 1046 | this.started = false; |
| 1047 | this.stringMap = new Map; |
| 1048 | this.mutationObserver = new MutationObserver(function(mutations) { |
| 1049 | return _this.processMutations(mutations); |
| 1050 | }); |
| 1051 | } |
| 1052 | (0, _createClassJsDefault.default)(StringMapObserver, [ |
| 1053 | { |
| 1054 | key: "start", |
| 1055 | value: function start() { |
| 1056 | if (!this.started) { |
| 1057 | this.started = true; |
| 1058 | this.mutationObserver.observe(this.element, { |
| 1059 | attributes: true, |
| 1060 | attributeOldValue: true |
| 1061 | }); |
| 1062 | this.refresh(); |
| 1063 | } |
| 1064 | } |
| 1065 | }, |
| 1066 | { |
| 1067 | key: "stop", |
| 1068 | value: function stop() { |
| 1069 | if (this.started) { |
| 1070 | this.mutationObserver.takeRecords(); |
| 1071 | this.mutationObserver.disconnect(); |
| 1072 | this.started = false; |
| 1073 | } |
| 1074 | } |
| 1075 | }, |
| 1076 | { |
| 1077 | key: "refresh", |
| 1078 | value: function refresh() { |
| 1079 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 1080 | if (this.started) try { |
| 1081 | for(var _iterator = this.knownAttributeNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 1082 | var attributeName = _step.value; |
| 1083 | this.refreshAttribute(attributeName, null); |
| 1084 | } |
| 1085 | } catch (err) { |
| 1086 | _didIteratorError = true; |
| 1087 | _iteratorError = err; |
| 1088 | } finally{ |
| 1089 | try { |
| 1090 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 1091 | _iterator.return(); |
| 1092 | } |
| 1093 | } finally{ |
| 1094 | if (_didIteratorError) { |
| 1095 | throw _iteratorError; |
| 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | }, |
| 1101 | { |
| 1102 | key: "processMutations", |
| 1103 | value: function processMutations(mutations) { |
| 1104 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 1105 | if (this.started) try { |
| 1106 | for(var _iterator = mutations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 1107 | var mutation = _step.value; |
| 1108 | this.processMutation(mutation); |
| 1109 | } |
| 1110 | } catch (err) { |
| 1111 | _didIteratorError = true; |
| 1112 | _iteratorError = err; |
| 1113 | } finally{ |
| 1114 | try { |
| 1115 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 1116 | _iterator.return(); |
| 1117 | } |
| 1118 | } finally{ |
| 1119 | if (_didIteratorError) { |
| 1120 | throw _iteratorError; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | }, |
| 1126 | { |
| 1127 | key: "processMutation", |
| 1128 | value: function processMutation(mutation) { |
| 1129 | var attributeName = mutation.attributeName; |
| 1130 | if (attributeName) this.refreshAttribute(attributeName, mutation.oldValue); |
| 1131 | } |
| 1132 | }, |
| 1133 | { |
| 1134 | key: "refreshAttribute", |
| 1135 | value: function refreshAttribute(attributeName, oldValue) { |
| 1136 | var key = this.delegate.getStringMapKeyForAttribute(attributeName); |
| 1137 | if (key != null) { |
| 1138 | if (!this.stringMap.has(attributeName)) this.stringMapKeyAdded(key, attributeName); |
| 1139 | var value = this.element.getAttribute(attributeName); |
| 1140 | if (this.stringMap.get(attributeName) != value) this.stringMapValueChanged(value, key, oldValue); |
| 1141 | if (value == null) { |
| 1142 | var _$oldValue = this.stringMap.get(attributeName); |
| 1143 | this.stringMap.delete(attributeName); |
| 1144 | if (_$oldValue) this.stringMapKeyRemoved(key, attributeName, _$oldValue); |
| 1145 | } else this.stringMap.set(attributeName, value); |
| 1146 | } |
| 1147 | } |
| 1148 | }, |
| 1149 | { |
| 1150 | key: "stringMapKeyAdded", |
| 1151 | value: function stringMapKeyAdded(key, attributeName) { |
| 1152 | if (this.delegate.stringMapKeyAdded) this.delegate.stringMapKeyAdded(key, attributeName); |
| 1153 | } |
| 1154 | }, |
| 1155 | { |
| 1156 | key: "stringMapValueChanged", |
| 1157 | value: function stringMapValueChanged(value, key, oldValue) { |
| 1158 | if (this.delegate.stringMapValueChanged) this.delegate.stringMapValueChanged(value, key, oldValue); |
| 1159 | } |
| 1160 | }, |
| 1161 | { |
| 1162 | key: "stringMapKeyRemoved", |
| 1163 | value: function stringMapKeyRemoved(key, attributeName, oldValue) { |
| 1164 | if (this.delegate.stringMapKeyRemoved) this.delegate.stringMapKeyRemoved(key, attributeName, oldValue); |
| 1165 | } |
| 1166 | }, |
| 1167 | { |
| 1168 | key: "knownAttributeNames", |
| 1169 | get: function get() { |
| 1170 | return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames))); |
| 1171 | } |
| 1172 | }, |
| 1173 | { |
| 1174 | key: "currentAttributeNames", |
| 1175 | get: function get() { |
| 1176 | return Array.from(this.element.attributes).map(function(attribute) { |
| 1177 | return attribute.name; |
| 1178 | }); |
| 1179 | } |
| 1180 | }, |
| 1181 | { |
| 1182 | key: "recordedAttributeNames", |
| 1183 | get: function get() { |
| 1184 | return Array.from(this.stringMap.keys()); |
| 1185 | } |
| 1186 | } |
| 1187 | ]); |
| 1188 | return StringMapObserver; |
| 1189 | }(); |
| 1190 | function add(map, key, value) { |
| 1191 | fetch(map, key).add(value); |
| 1192 | } |
| 1193 | function del(map, key, value) { |
| 1194 | fetch(map, key).delete(value); |
| 1195 | prune(map, key); |
| 1196 | } |
| 1197 | function fetch(map, key) { |
| 1198 | var values = map.get(key); |
| 1199 | if (!values) { |
| 1200 | values = new Set(); |
| 1201 | map.set(key, values); |
| 1202 | } |
| 1203 | return values; |
| 1204 | } |
| 1205 | function prune(map, key) { |
| 1206 | var values = map.get(key); |
| 1207 | if (values != null && values.size == 0) map.delete(key); |
| 1208 | } |
| 1209 | var Multimap = /*#__PURE__*/ function() { |
| 1210 | "use strict"; |
| 1211 | function Multimap() { |
| 1212 | (0, _classCallCheckJsDefault.default)(this, Multimap); |
| 1213 | this.valuesByKey = new Map(); |
| 1214 | } |
| 1215 | (0, _createClassJsDefault.default)(Multimap, [ |
| 1216 | { |
| 1217 | key: "keys", |
| 1218 | get: function get() { |
| 1219 | return Array.from(this.valuesByKey.keys()); |
| 1220 | } |
| 1221 | }, |
| 1222 | { |
| 1223 | key: "values", |
| 1224 | get: function get() { |
| 1225 | var sets = Array.from(this.valuesByKey.values()); |
| 1226 | return sets.reduce(function(values, set) { |
| 1227 | return values.concat(Array.from(set)); |
| 1228 | }, []); |
| 1229 | } |
| 1230 | }, |
| 1231 | { |
| 1232 | key: "size", |
| 1233 | get: function get() { |
| 1234 | var sets = Array.from(this.valuesByKey.values()); |
| 1235 | return sets.reduce(function(size, set) { |
| 1236 | return size + set.size; |
| 1237 | }, 0); |
| 1238 | } |
| 1239 | }, |
| 1240 | { |
| 1241 | key: "add", |
| 1242 | value: function add1(key, value) { |
| 1243 | add(this.valuesByKey, key, value); |
| 1244 | } |
| 1245 | }, |
| 1246 | { |
| 1247 | key: "delete", |
| 1248 | value: function _delete(key, value) { |
| 1249 | del(this.valuesByKey, key, value); |
| 1250 | } |
| 1251 | }, |
| 1252 | { |
| 1253 | key: "has", |
| 1254 | value: function has(key, value) { |
| 1255 | var values = this.valuesByKey.get(key); |
| 1256 | return values != null && values.has(value); |
| 1257 | } |
| 1258 | }, |
| 1259 | { |
| 1260 | key: "hasKey", |
| 1261 | value: function hasKey(key) { |
| 1262 | return this.valuesByKey.has(key); |
| 1263 | } |
| 1264 | }, |
| 1265 | { |
| 1266 | key: "hasValue", |
| 1267 | value: function hasValue(value) { |
| 1268 | var sets = Array.from(this.valuesByKey.values()); |
| 1269 | return sets.some(function(set) { |
| 1270 | return set.has(value); |
| 1271 | }); |
| 1272 | } |
| 1273 | }, |
| 1274 | { |
| 1275 | key: "getValuesForKey", |
| 1276 | value: function getValuesForKey(key) { |
| 1277 | var values = this.valuesByKey.get(key); |
| 1278 | return values ? Array.from(values) : []; |
| 1279 | } |
| 1280 | }, |
| 1281 | { |
| 1282 | key: "getKeysForValue", |
| 1283 | value: function getKeysForValue(value) { |
| 1284 | return Array.from(this.valuesByKey).filter(function(param) { |
| 1285 | var _param = (0, _slicedToArrayJsDefault.default)(param, 2), key = _param[0], values = _param[1]; |
| 1286 | return values.has(value); |
| 1287 | }).map(function(param) { |
| 1288 | var _param = (0, _slicedToArrayJsDefault.default)(param, 2), key = _param[0], values = _param[1]; |
| 1289 | return key; |
| 1290 | }); |
| 1291 | } |
| 1292 | } |
| 1293 | ]); |
| 1294 | return Multimap; |
| 1295 | }(); |
| 1296 | var IndexedMultimap = /*#__PURE__*/ function(Multimap) { |
| 1297 | "use strict"; |
| 1298 | (0, _inheritsJsDefault.default)(IndexedMultimap, Multimap); |
| 1299 | var _super = (0, _createSuperJsDefault.default)(IndexedMultimap); |
| 1300 | function IndexedMultimap() { |
| 1301 | (0, _classCallCheckJsDefault.default)(this, IndexedMultimap); |
| 1302 | var _this; |
| 1303 | _this = _super.call(this); |
| 1304 | _this.keysByValue = new Map; |
| 1305 | return _this; |
| 1306 | } |
| 1307 | (0, _createClassJsDefault.default)(IndexedMultimap, [ |
| 1308 | { |
| 1309 | key: "values", |
| 1310 | get: function get() { |
| 1311 | return Array.from(this.keysByValue.keys()); |
| 1312 | } |
| 1313 | }, |
| 1314 | { |
| 1315 | key: "add", |
| 1316 | value: function add1(key, value) { |
| 1317 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(IndexedMultimap.prototype), "add", this).call(this, key, value); |
| 1318 | add(this.keysByValue, value, key); |
| 1319 | } |
| 1320 | }, |
| 1321 | { |
| 1322 | key: "delete", |
| 1323 | value: function _delete(key, value) { |
| 1324 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(IndexedMultimap.prototype), "delete", this).call(this, key, value); |
| 1325 | del(this.keysByValue, value, key); |
| 1326 | } |
| 1327 | }, |
| 1328 | { |
| 1329 | key: "hasValue", |
| 1330 | value: function hasValue(value) { |
| 1331 | return this.keysByValue.has(value); |
| 1332 | } |
| 1333 | }, |
| 1334 | { |
| 1335 | key: "getKeysForValue", |
| 1336 | value: function getKeysForValue(value) { |
| 1337 | var set = this.keysByValue.get(value); |
| 1338 | return set ? Array.from(set) : []; |
| 1339 | } |
| 1340 | } |
| 1341 | ]); |
| 1342 | return IndexedMultimap; |
| 1343 | }(Multimap); |
| 1344 | var TokenListObserver = /*#__PURE__*/ function() { |
| 1345 | "use strict"; |
| 1346 | function TokenListObserver(element, attributeName, delegate) { |
| 1347 | (0, _classCallCheckJsDefault.default)(this, TokenListObserver); |
| 1348 | this.attributeObserver = new AttributeObserver(element, attributeName, this); |
| 1349 | this.delegate = delegate; |
| 1350 | this.tokensByElement = new Multimap; |
| 1351 | } |
| 1352 | (0, _createClassJsDefault.default)(TokenListObserver, [ |
| 1353 | { |
| 1354 | key: "started", |
| 1355 | get: function get() { |
| 1356 | return this.attributeObserver.started; |
| 1357 | } |
| 1358 | }, |
| 1359 | { |
| 1360 | key: "start", |
| 1361 | value: function start() { |
| 1362 | this.attributeObserver.start(); |
| 1363 | } |
| 1364 | }, |
| 1365 | { |
| 1366 | key: "pause", |
| 1367 | value: function pause(callback) { |
| 1368 | this.attributeObserver.pause(callback); |
| 1369 | } |
| 1370 | }, |
| 1371 | { |
| 1372 | key: "stop", |
| 1373 | value: function stop() { |
| 1374 | this.attributeObserver.stop(); |
| 1375 | } |
| 1376 | }, |
| 1377 | { |
| 1378 | key: "refresh", |
| 1379 | value: function refresh() { |
| 1380 | this.attributeObserver.refresh(); |
| 1381 | } |
| 1382 | }, |
| 1383 | { |
| 1384 | key: "element", |
| 1385 | get: function get() { |
| 1386 | return this.attributeObserver.element; |
| 1387 | } |
| 1388 | }, |
| 1389 | { |
| 1390 | key: "attributeName", |
| 1391 | get: function get() { |
| 1392 | return this.attributeObserver.attributeName; |
| 1393 | } |
| 1394 | }, |
| 1395 | { |
| 1396 | key: "elementMatchedAttribute", |
| 1397 | value: function elementMatchedAttribute(element) { |
| 1398 | this.tokensMatched(this.readTokensForElement(element)); |
| 1399 | } |
| 1400 | }, |
| 1401 | { |
| 1402 | key: "elementAttributeValueChanged", |
| 1403 | value: function elementAttributeValueChanged(element) { |
| 1404 | var ref = (0, _slicedToArrayJsDefault.default)(this.refreshTokensForElement(element), 2), unmatchedTokens = ref[0], matchedTokens = ref[1]; |
| 1405 | this.tokensUnmatched(unmatchedTokens); |
| 1406 | this.tokensMatched(matchedTokens); |
| 1407 | } |
| 1408 | }, |
| 1409 | { |
| 1410 | key: "elementUnmatchedAttribute", |
| 1411 | value: function elementUnmatchedAttribute(element) { |
| 1412 | this.tokensUnmatched(this.tokensByElement.getValuesForKey(element)); |
| 1413 | } |
| 1414 | }, |
| 1415 | { |
| 1416 | key: "tokensMatched", |
| 1417 | value: function tokensMatched(tokens) { |
| 1418 | var _this = this; |
| 1419 | tokens.forEach(function(token) { |
| 1420 | return _this.tokenMatched(token); |
| 1421 | }); |
| 1422 | } |
| 1423 | }, |
| 1424 | { |
| 1425 | key: "tokensUnmatched", |
| 1426 | value: function tokensUnmatched(tokens) { |
| 1427 | var _this = this; |
| 1428 | tokens.forEach(function(token) { |
| 1429 | return _this.tokenUnmatched(token); |
| 1430 | }); |
| 1431 | } |
| 1432 | }, |
| 1433 | { |
| 1434 | key: "tokenMatched", |
| 1435 | value: function tokenMatched(token) { |
| 1436 | this.delegate.tokenMatched(token); |
| 1437 | this.tokensByElement.add(token.element, token); |
| 1438 | } |
| 1439 | }, |
| 1440 | { |
| 1441 | key: "tokenUnmatched", |
| 1442 | value: function tokenUnmatched(token) { |
| 1443 | this.delegate.tokenUnmatched(token); |
| 1444 | this.tokensByElement.delete(token.element, token); |
| 1445 | } |
| 1446 | }, |
| 1447 | { |
| 1448 | key: "refreshTokensForElement", |
| 1449 | value: function refreshTokensForElement(element) { |
| 1450 | var previousTokens = this.tokensByElement.getValuesForKey(element); |
| 1451 | var currentTokens = this.readTokensForElement(element); |
| 1452 | var firstDifferingIndex = zip(previousTokens, currentTokens).findIndex(function(param) { |
| 1453 | var _param = (0, _slicedToArrayJsDefault.default)(param, 2), previousToken = _param[0], currentToken = _param[1]; |
| 1454 | return !tokensAreEqual(previousToken, currentToken); |
| 1455 | }); |
| 1456 | if (firstDifferingIndex == -1) return [ |
| 1457 | [], |
| 1458 | [] |
| 1459 | ]; |
| 1460 | else return [ |
| 1461 | previousTokens.slice(firstDifferingIndex), |
| 1462 | currentTokens.slice(firstDifferingIndex) |
| 1463 | ]; |
| 1464 | } |
| 1465 | }, |
| 1466 | { |
| 1467 | key: "readTokensForElement", |
| 1468 | value: function readTokensForElement(element) { |
| 1469 | var attributeName = this.attributeName; |
| 1470 | var tokenString = element.getAttribute(attributeName) || ""; |
| 1471 | return parseTokenString(tokenString, element, attributeName); |
| 1472 | } |
| 1473 | } |
| 1474 | ]); |
| 1475 | return TokenListObserver; |
| 1476 | }(); |
| 1477 | function parseTokenString(tokenString, element, attributeName) { |
| 1478 | return tokenString.trim().split(/\s+/).filter(function(content) { |
| 1479 | return content.length; |
| 1480 | }).map(function(content, index) { |
| 1481 | return { |
| 1482 | element: element, |
| 1483 | attributeName: attributeName, |
| 1484 | content: content, |
| 1485 | index: index |
| 1486 | }; |
| 1487 | }); |
| 1488 | } |
| 1489 | function zip(left, right) { |
| 1490 | var length = Math.max(left.length, right.length); |
| 1491 | return Array.from({ |
| 1492 | length: length |
| 1493 | }, function(_, index) { |
| 1494 | return [ |
| 1495 | left[index], |
| 1496 | right[index] |
| 1497 | ]; |
| 1498 | }); |
| 1499 | } |
| 1500 | function tokensAreEqual(left, right) { |
| 1501 | return left && right && left.index == right.index && left.content == right.content; |
| 1502 | } |
| 1503 | var ValueListObserver = /*#__PURE__*/ function() { |
| 1504 | "use strict"; |
| 1505 | function ValueListObserver(element, attributeName, delegate) { |
| 1506 | (0, _classCallCheckJsDefault.default)(this, ValueListObserver); |
| 1507 | this.tokenListObserver = new TokenListObserver(element, attributeName, this); |
| 1508 | this.delegate = delegate; |
| 1509 | this.parseResultsByToken = new WeakMap; |
| 1510 | this.valuesByTokenByElement = new WeakMap; |
| 1511 | } |
| 1512 | (0, _createClassJsDefault.default)(ValueListObserver, [ |
| 1513 | { |
| 1514 | key: "started", |
| 1515 | get: function get() { |
| 1516 | return this.tokenListObserver.started; |
| 1517 | } |
| 1518 | }, |
| 1519 | { |
| 1520 | key: "start", |
| 1521 | value: function start() { |
| 1522 | this.tokenListObserver.start(); |
| 1523 | } |
| 1524 | }, |
| 1525 | { |
| 1526 | key: "stop", |
| 1527 | value: function stop() { |
| 1528 | this.tokenListObserver.stop(); |
| 1529 | } |
| 1530 | }, |
| 1531 | { |
| 1532 | key: "refresh", |
| 1533 | value: function refresh() { |
| 1534 | this.tokenListObserver.refresh(); |
| 1535 | } |
| 1536 | }, |
| 1537 | { |
| 1538 | key: "element", |
| 1539 | get: function get() { |
| 1540 | return this.tokenListObserver.element; |
| 1541 | } |
| 1542 | }, |
| 1543 | { |
| 1544 | key: "attributeName", |
| 1545 | get: function get() { |
| 1546 | return this.tokenListObserver.attributeName; |
| 1547 | } |
| 1548 | }, |
| 1549 | { |
| 1550 | key: "tokenMatched", |
| 1551 | value: function tokenMatched(token) { |
| 1552 | var element = token.element; |
| 1553 | var value = this.fetchParseResultForToken(token).value; |
| 1554 | if (value) { |
| 1555 | this.fetchValuesByTokenForElement(element).set(token, value); |
| 1556 | this.delegate.elementMatchedValue(element, value); |
| 1557 | } |
| 1558 | } |
| 1559 | }, |
| 1560 | { |
| 1561 | key: "tokenUnmatched", |
| 1562 | value: function tokenUnmatched(token) { |
| 1563 | var element = token.element; |
| 1564 | var value = this.fetchParseResultForToken(token).value; |
| 1565 | if (value) { |
| 1566 | this.fetchValuesByTokenForElement(element).delete(token); |
| 1567 | this.delegate.elementUnmatchedValue(element, value); |
| 1568 | } |
| 1569 | } |
| 1570 | }, |
| 1571 | { |
| 1572 | key: "fetchParseResultForToken", |
| 1573 | value: function fetchParseResultForToken(token) { |
| 1574 | var parseResult = this.parseResultsByToken.get(token); |
| 1575 | if (!parseResult) { |
| 1576 | parseResult = this.parseToken(token); |
| 1577 | this.parseResultsByToken.set(token, parseResult); |
| 1578 | } |
| 1579 | return parseResult; |
| 1580 | } |
| 1581 | }, |
| 1582 | { |
| 1583 | key: "fetchValuesByTokenForElement", |
| 1584 | value: function fetchValuesByTokenForElement(element) { |
| 1585 | var valuesByToken = this.valuesByTokenByElement.get(element); |
| 1586 | if (!valuesByToken) { |
| 1587 | valuesByToken = new Map; |
| 1588 | this.valuesByTokenByElement.set(element, valuesByToken); |
| 1589 | } |
| 1590 | return valuesByToken; |
| 1591 | } |
| 1592 | }, |
| 1593 | { |
| 1594 | key: "parseToken", |
| 1595 | value: function parseToken(token) { |
| 1596 | try { |
| 1597 | var value = this.delegate.parseValueForToken(token); |
| 1598 | return { |
| 1599 | value: value |
| 1600 | }; |
| 1601 | } catch (error3) { |
| 1602 | return { |
| 1603 | error: error3 |
| 1604 | }; |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | ]); |
| 1609 | return ValueListObserver; |
| 1610 | }(); |
| 1611 | var BindingObserver = /*#__PURE__*/ function() { |
| 1612 | "use strict"; |
| 1613 | function BindingObserver(context, delegate) { |
| 1614 | (0, _classCallCheckJsDefault.default)(this, BindingObserver); |
| 1615 | this.context = context; |
| 1616 | this.delegate = delegate; |
| 1617 | this.bindingsByAction = new Map; |
| 1618 | } |
| 1619 | (0, _createClassJsDefault.default)(BindingObserver, [ |
| 1620 | { |
| 1621 | key: "start", |
| 1622 | value: function start() { |
| 1623 | if (!this.valueListObserver) { |
| 1624 | this.valueListObserver = new ValueListObserver(this.element, this.actionAttribute, this); |
| 1625 | this.valueListObserver.start(); |
| 1626 | } |
| 1627 | } |
| 1628 | }, |
| 1629 | { |
| 1630 | key: "stop", |
| 1631 | value: function stop() { |
| 1632 | if (this.valueListObserver) { |
| 1633 | this.valueListObserver.stop(); |
| 1634 | delete this.valueListObserver; |
| 1635 | this.disconnectAllActions(); |
| 1636 | } |
| 1637 | } |
| 1638 | }, |
| 1639 | { |
| 1640 | key: "element", |
| 1641 | get: function get() { |
| 1642 | return this.context.element; |
| 1643 | } |
| 1644 | }, |
| 1645 | { |
| 1646 | key: "identifier", |
| 1647 | get: function get() { |
| 1648 | return this.context.identifier; |
| 1649 | } |
| 1650 | }, |
| 1651 | { |
| 1652 | key: "actionAttribute", |
| 1653 | get: function get() { |
| 1654 | return this.schema.actionAttribute; |
| 1655 | } |
| 1656 | }, |
| 1657 | { |
| 1658 | key: "schema", |
| 1659 | get: function get() { |
| 1660 | return this.context.schema; |
| 1661 | } |
| 1662 | }, |
| 1663 | { |
| 1664 | key: "bindings", |
| 1665 | get: function get() { |
| 1666 | return Array.from(this.bindingsByAction.values()); |
| 1667 | } |
| 1668 | }, |
| 1669 | { |
| 1670 | key: "connectAction", |
| 1671 | value: function connectAction(action) { |
| 1672 | var binding = new Binding(this.context, action); |
| 1673 | this.bindingsByAction.set(action, binding); |
| 1674 | this.delegate.bindingConnected(binding); |
| 1675 | } |
| 1676 | }, |
| 1677 | { |
| 1678 | key: "disconnectAction", |
| 1679 | value: function disconnectAction(action) { |
| 1680 | var binding = this.bindingsByAction.get(action); |
| 1681 | if (binding) { |
| 1682 | this.bindingsByAction.delete(action); |
| 1683 | this.delegate.bindingDisconnected(binding); |
| 1684 | } |
| 1685 | } |
| 1686 | }, |
| 1687 | { |
| 1688 | key: "disconnectAllActions", |
| 1689 | value: function disconnectAllActions() { |
| 1690 | var _this = this; |
| 1691 | this.bindings.forEach(function(binding) { |
| 1692 | return _this.delegate.bindingDisconnected(binding); |
| 1693 | }); |
| 1694 | this.bindingsByAction.clear(); |
| 1695 | } |
| 1696 | }, |
| 1697 | { |
| 1698 | key: "parseValueForToken", |
| 1699 | value: function parseValueForToken(token) { |
| 1700 | var action = Action.forToken(token); |
| 1701 | if (action.identifier == this.identifier) return action; |
| 1702 | } |
| 1703 | }, |
| 1704 | { |
| 1705 | key: "elementMatchedValue", |
| 1706 | value: function elementMatchedValue(element, action) { |
| 1707 | this.connectAction(action); |
| 1708 | } |
| 1709 | }, |
| 1710 | { |
| 1711 | key: "elementUnmatchedValue", |
| 1712 | value: function elementUnmatchedValue(element, action) { |
| 1713 | this.disconnectAction(action); |
| 1714 | } |
| 1715 | } |
| 1716 | ]); |
| 1717 | return BindingObserver; |
| 1718 | }(); |
| 1719 | var ValueObserver = /*#__PURE__*/ function() { |
| 1720 | "use strict"; |
| 1721 | function ValueObserver(context, receiver) { |
| 1722 | (0, _classCallCheckJsDefault.default)(this, ValueObserver); |
| 1723 | this.context = context; |
| 1724 | this.receiver = receiver; |
| 1725 | this.stringMapObserver = new StringMapObserver(this.element, this); |
| 1726 | this.valueDescriptorMap = this.controller.valueDescriptorMap; |
| 1727 | this.invokeChangedCallbacksForDefaultValues(); |
| 1728 | } |
| 1729 | (0, _createClassJsDefault.default)(ValueObserver, [ |
| 1730 | { |
| 1731 | key: "start", |
| 1732 | value: function start() { |
| 1733 | this.stringMapObserver.start(); |
| 1734 | } |
| 1735 | }, |
| 1736 | { |
| 1737 | key: "stop", |
| 1738 | value: function stop() { |
| 1739 | this.stringMapObserver.stop(); |
| 1740 | } |
| 1741 | }, |
| 1742 | { |
| 1743 | key: "element", |
| 1744 | get: function get() { |
| 1745 | return this.context.element; |
| 1746 | } |
| 1747 | }, |
| 1748 | { |
| 1749 | key: "controller", |
| 1750 | get: function get() { |
| 1751 | return this.context.controller; |
| 1752 | } |
| 1753 | }, |
| 1754 | { |
| 1755 | key: "getStringMapKeyForAttribute", |
| 1756 | value: function getStringMapKeyForAttribute(attributeName) { |
| 1757 | if (attributeName in this.valueDescriptorMap) return this.valueDescriptorMap[attributeName].name; |
| 1758 | } |
| 1759 | }, |
| 1760 | { |
| 1761 | key: "stringMapKeyAdded", |
| 1762 | value: function stringMapKeyAdded(key, attributeName) { |
| 1763 | var descriptor = this.valueDescriptorMap[attributeName]; |
| 1764 | if (!this.hasValue(key)) this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), descriptor.writer(descriptor.defaultValue)); |
| 1765 | } |
| 1766 | }, |
| 1767 | { |
| 1768 | key: "stringMapValueChanged", |
| 1769 | value: function stringMapValueChanged(value, name, oldValue) { |
| 1770 | var descriptor = this.valueDescriptorNameMap[name]; |
| 1771 | if (value === null) return; |
| 1772 | if (oldValue === null) oldValue = descriptor.writer(descriptor.defaultValue); |
| 1773 | this.invokeChangedCallback(name, value, oldValue); |
| 1774 | } |
| 1775 | }, |
| 1776 | { |
| 1777 | key: "stringMapKeyRemoved", |
| 1778 | value: function stringMapKeyRemoved(key, attributeName, oldValue) { |
| 1779 | var descriptor = this.valueDescriptorNameMap[key]; |
| 1780 | if (this.hasValue(key)) this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), oldValue); |
| 1781 | else this.invokeChangedCallback(key, descriptor.writer(descriptor.defaultValue), oldValue); |
| 1782 | } |
| 1783 | }, |
| 1784 | { |
| 1785 | key: "invokeChangedCallbacksForDefaultValues", |
| 1786 | value: function invokeChangedCallbacksForDefaultValues() { |
| 1787 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 1788 | try { |
| 1789 | for(var _iterator = this.valueDescriptors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 1790 | var _value = _step.value, key = _value.key, name = _value.name, defaultValue = _value.defaultValue, writer = _value.writer; |
| 1791 | if (defaultValue != undefined && !this.controller.data.has(key)) this.invokeChangedCallback(name, writer(defaultValue), undefined); |
| 1792 | } |
| 1793 | } catch (err) { |
| 1794 | _didIteratorError = true; |
| 1795 | _iteratorError = err; |
| 1796 | } finally{ |
| 1797 | try { |
| 1798 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 1799 | _iterator.return(); |
| 1800 | } |
| 1801 | } finally{ |
| 1802 | if (_didIteratorError) { |
| 1803 | throw _iteratorError; |
| 1804 | } |
| 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | }, |
| 1809 | { |
| 1810 | key: "invokeChangedCallback", |
| 1811 | value: function invokeChangedCallback(name, rawValue, rawOldValue) { |
| 1812 | var changedMethodName = "".concat(name, "Changed"); |
| 1813 | var changedMethod = this.receiver[changedMethodName]; |
| 1814 | if (typeof changedMethod == "function") { |
| 1815 | var descriptor = this.valueDescriptorNameMap[name]; |
| 1816 | var value = descriptor.reader(rawValue); |
| 1817 | var oldValue = rawOldValue; |
| 1818 | if (rawOldValue) oldValue = descriptor.reader(rawOldValue); |
| 1819 | changedMethod.call(this.receiver, value, oldValue); |
| 1820 | } |
| 1821 | } |
| 1822 | }, |
| 1823 | { |
| 1824 | key: "valueDescriptors", |
| 1825 | get: function get() { |
| 1826 | var valueDescriptorMap = this.valueDescriptorMap; |
| 1827 | return Object.keys(valueDescriptorMap).map(function(key) { |
| 1828 | return valueDescriptorMap[key]; |
| 1829 | }); |
| 1830 | } |
| 1831 | }, |
| 1832 | { |
| 1833 | key: "valueDescriptorNameMap", |
| 1834 | get: function get() { |
| 1835 | var _this = this; |
| 1836 | var descriptors = {}; |
| 1837 | Object.keys(this.valueDescriptorMap).forEach(function(key) { |
| 1838 | var descriptor = _this.valueDescriptorMap[key]; |
| 1839 | descriptors[descriptor.name] = descriptor; |
| 1840 | }); |
| 1841 | return descriptors; |
| 1842 | } |
| 1843 | }, |
| 1844 | { |
| 1845 | key: "hasValue", |
| 1846 | value: function hasValue(attributeName) { |
| 1847 | var descriptor = this.valueDescriptorNameMap[attributeName]; |
| 1848 | var hasMethodName = "has".concat(capitalize(descriptor.name)); |
| 1849 | return this.receiver[hasMethodName]; |
| 1850 | } |
| 1851 | } |
| 1852 | ]); |
| 1853 | return ValueObserver; |
| 1854 | }(); |
| 1855 | var TargetObserver = /*#__PURE__*/ function() { |
| 1856 | "use strict"; |
| 1857 | function TargetObserver(context, delegate) { |
| 1858 | (0, _classCallCheckJsDefault.default)(this, TargetObserver); |
| 1859 | this.context = context; |
| 1860 | this.delegate = delegate; |
| 1861 | this.targetsByName = new Multimap; |
| 1862 | } |
| 1863 | (0, _createClassJsDefault.default)(TargetObserver, [ |
| 1864 | { |
| 1865 | key: "start", |
| 1866 | value: function start() { |
| 1867 | if (!this.tokenListObserver) { |
| 1868 | this.tokenListObserver = new TokenListObserver(this.element, this.attributeName, this); |
| 1869 | this.tokenListObserver.start(); |
| 1870 | } |
| 1871 | } |
| 1872 | }, |
| 1873 | { |
| 1874 | key: "stop", |
| 1875 | value: function stop() { |
| 1876 | if (this.tokenListObserver) { |
| 1877 | this.disconnectAllTargets(); |
| 1878 | this.tokenListObserver.stop(); |
| 1879 | delete this.tokenListObserver; |
| 1880 | } |
| 1881 | } |
| 1882 | }, |
| 1883 | { |
| 1884 | key: "tokenMatched", |
| 1885 | value: function tokenMatched(param) { |
| 1886 | var element = param.element, name = param.content; |
| 1887 | if (this.scope.containsElement(element)) this.connectTarget(element, name); |
| 1888 | } |
| 1889 | }, |
| 1890 | { |
| 1891 | key: "tokenUnmatched", |
| 1892 | value: function tokenUnmatched(param) { |
| 1893 | var element = param.element, name = param.content; |
| 1894 | this.disconnectTarget(element, name); |
| 1895 | } |
| 1896 | }, |
| 1897 | { |
| 1898 | key: "connectTarget", |
| 1899 | value: function connectTarget(element, name) { |
| 1900 | var _a; |
| 1901 | if (!this.targetsByName.has(name, element)) { |
| 1902 | var _this = this; |
| 1903 | this.targetsByName.add(name, element); |
| 1904 | (_a = this.tokenListObserver) === null || _a === void 0 || _a.pause(function() { |
| 1905 | return _this.delegate.targetConnected(element, name); |
| 1906 | }); |
| 1907 | } |
| 1908 | } |
| 1909 | }, |
| 1910 | { |
| 1911 | key: "disconnectTarget", |
| 1912 | value: function disconnectTarget(element, name) { |
| 1913 | var _a; |
| 1914 | if (this.targetsByName.has(name, element)) { |
| 1915 | var _this = this; |
| 1916 | this.targetsByName.delete(name, element); |
| 1917 | (_a = this.tokenListObserver) === null || _a === void 0 || _a.pause(function() { |
| 1918 | return _this.delegate.targetDisconnected(element, name); |
| 1919 | }); |
| 1920 | } |
| 1921 | } |
| 1922 | }, |
| 1923 | { |
| 1924 | key: "disconnectAllTargets", |
| 1925 | value: function disconnectAllTargets() { |
| 1926 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined, _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined; |
| 1927 | try { |
| 1928 | for(var _iterator = this.targetsByName.keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion2 = (_step = _iterator.next()).done); _iteratorNormalCompletion2 = true){ |
| 1929 | var name = _step.value; |
| 1930 | try { |
| 1931 | for(var _iterator2 = this.targetsByName.getValuesForKey(name)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion = true){ |
| 1932 | var element = _step2.value; |
| 1933 | this.disconnectTarget(element, name); |
| 1934 | } |
| 1935 | } catch (err) { |
| 1936 | _didIteratorError = true; |
| 1937 | _iteratorError = err; |
| 1938 | } finally{ |
| 1939 | try { |
| 1940 | if (!_iteratorNormalCompletion && _iterator2.return != null) { |
| 1941 | _iterator2.return(); |
| 1942 | } |
| 1943 | } finally{ |
| 1944 | if (_didIteratorError) { |
| 1945 | throw _iteratorError; |
| 1946 | } |
| 1947 | } |
| 1948 | } |
| 1949 | } |
| 1950 | } catch (err) { |
| 1951 | _didIteratorError2 = true; |
| 1952 | _iteratorError2 = err; |
| 1953 | } finally{ |
| 1954 | try { |
| 1955 | if (!_iteratorNormalCompletion2 && _iterator.return != null) { |
| 1956 | _iterator.return(); |
| 1957 | } |
| 1958 | } finally{ |
| 1959 | if (_didIteratorError2) { |
| 1960 | throw _iteratorError2; |
| 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | } |
| 1965 | }, |
| 1966 | { |
| 1967 | key: "attributeName", |
| 1968 | get: function get() { |
| 1969 | return "data-".concat(this.context.identifier, "-target"); |
| 1970 | } |
| 1971 | }, |
| 1972 | { |
| 1973 | key: "element", |
| 1974 | get: function get() { |
| 1975 | return this.context.element; |
| 1976 | } |
| 1977 | }, |
| 1978 | { |
| 1979 | key: "scope", |
| 1980 | get: function get() { |
| 1981 | return this.context.scope; |
| 1982 | } |
| 1983 | } |
| 1984 | ]); |
| 1985 | return TargetObserver; |
| 1986 | }(); |
| 1987 | var Context = /*#__PURE__*/ function() { |
| 1988 | "use strict"; |
| 1989 | function Context(module, scope) { |
| 1990 | var _this = this; |
| 1991 | (0, _classCallCheckJsDefault.default)(this, Context); |
| 1992 | this.logDebugActivity = function(functionName) { |
| 1993 | var detail = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; |
| 1994 | var identifier = _this.identifier, controller = _this.controller, element = _this.element; |
| 1995 | detail = Object.assign({ |
| 1996 | identifier: identifier, |
| 1997 | controller: controller, |
| 1998 | element: element |
| 1999 | }, detail); |
| 2000 | _this.application.logDebugActivity(_this.identifier, functionName, detail); |
| 2001 | }; |
| 2002 | this.module = module; |
| 2003 | this.scope = scope; |
| 2004 | this.controller = new module.controllerConstructor(this); |
| 2005 | this.bindingObserver = new BindingObserver(this, this.dispatcher); |
| 2006 | this.valueObserver = new ValueObserver(this, this.controller); |
| 2007 | this.targetObserver = new TargetObserver(this, this); |
| 2008 | try { |
| 2009 | this.controller.initialize(); |
| 2010 | this.logDebugActivity("initialize"); |
| 2011 | } catch (error4) { |
| 2012 | this.handleError(error4, "initializing controller"); |
| 2013 | } |
| 2014 | } |
| 2015 | (0, _createClassJsDefault.default)(Context, [ |
| 2016 | { |
| 2017 | key: "connect", |
| 2018 | value: function connect() { |
| 2019 | this.bindingObserver.start(); |
| 2020 | this.valueObserver.start(); |
| 2021 | this.targetObserver.start(); |
| 2022 | try { |
| 2023 | this.controller.connect(); |
| 2024 | this.logDebugActivity("connect"); |
| 2025 | } catch (error5) { |
| 2026 | this.handleError(error5, "connecting controller"); |
| 2027 | } |
| 2028 | } |
| 2029 | }, |
| 2030 | { |
| 2031 | key: "disconnect", |
| 2032 | value: function disconnect() { |
| 2033 | try { |
| 2034 | this.controller.disconnect(); |
| 2035 | this.logDebugActivity("disconnect"); |
| 2036 | } catch (error6) { |
| 2037 | this.handleError(error6, "disconnecting controller"); |
| 2038 | } |
| 2039 | this.targetObserver.stop(); |
| 2040 | this.valueObserver.stop(); |
| 2041 | this.bindingObserver.stop(); |
| 2042 | } |
| 2043 | }, |
| 2044 | { |
| 2045 | key: "application", |
| 2046 | get: function get() { |
| 2047 | return this.module.application; |
| 2048 | } |
| 2049 | }, |
| 2050 | { |
| 2051 | key: "identifier", |
| 2052 | get: function get() { |
| 2053 | return this.module.identifier; |
| 2054 | } |
| 2055 | }, |
| 2056 | { |
| 2057 | key: "schema", |
| 2058 | get: function get() { |
| 2059 | return this.application.schema; |
| 2060 | } |
| 2061 | }, |
| 2062 | { |
| 2063 | key: "dispatcher", |
| 2064 | get: function get() { |
| 2065 | return this.application.dispatcher; |
| 2066 | } |
| 2067 | }, |
| 2068 | { |
| 2069 | key: "element", |
| 2070 | get: function get() { |
| 2071 | return this.scope.element; |
| 2072 | } |
| 2073 | }, |
| 2074 | { |
| 2075 | key: "parentElement", |
| 2076 | get: function get() { |
| 2077 | return this.element.parentElement; |
| 2078 | } |
| 2079 | }, |
| 2080 | { |
| 2081 | key: "handleError", |
| 2082 | value: function handleError(error7, message) { |
| 2083 | var detail = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}; |
| 2084 | var ref = this, identifier = ref.identifier, controller = ref.controller, element = ref.element; |
| 2085 | detail = Object.assign({ |
| 2086 | identifier: identifier, |
| 2087 | controller: controller, |
| 2088 | element: element |
| 2089 | }, detail); |
| 2090 | this.application.handleError(error7, "Error ".concat(message), detail); |
| 2091 | } |
| 2092 | }, |
| 2093 | { |
| 2094 | key: "targetConnected", |
| 2095 | value: function targetConnected(element, name) { |
| 2096 | this.invokeControllerMethod("".concat(name, "TargetConnected"), element); |
| 2097 | } |
| 2098 | }, |
| 2099 | { |
| 2100 | key: "targetDisconnected", |
| 2101 | value: function targetDisconnected(element, name) { |
| 2102 | this.invokeControllerMethod("".concat(name, "TargetDisconnected"), element); |
| 2103 | } |
| 2104 | }, |
| 2105 | { |
| 2106 | key: "invokeControllerMethod", |
| 2107 | value: function invokeControllerMethod(methodName) { |
| 2108 | for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){ |
| 2109 | args[_key - 1] = arguments[_key]; |
| 2110 | } |
| 2111 | var _controller; |
| 2112 | var controller = this.controller; |
| 2113 | if (typeof controller[methodName] == "function") (_controller = controller)[methodName].apply(_controller, (0, _toConsumableArrayJsDefault.default)(args)); |
| 2114 | } |
| 2115 | } |
| 2116 | ]); |
| 2117 | return Context; |
| 2118 | }(); |
| 2119 | function readInheritableStaticArrayValues(constructor1, propertyName) { |
| 2120 | var ancestors = getAncestorsForConstructor(constructor1); |
| 2121 | return Array.from(ancestors.reduce(function(values, constructor) { |
| 2122 | getOwnStaticArrayValues(constructor, propertyName).forEach(function(name) { |
| 2123 | return values.add(name); |
| 2124 | }); |
| 2125 | return values; |
| 2126 | }, new Set)); |
| 2127 | } |
| 2128 | function readInheritableStaticObjectPairs(constructor2, propertyName) { |
| 2129 | var ancestors = getAncestorsForConstructor(constructor2); |
| 2130 | return ancestors.reduce(function(pairs, constructor) { |
| 2131 | var _pairs; |
| 2132 | (_pairs = pairs).push.apply(_pairs, (0, _toConsumableArrayJsDefault.default)(getOwnStaticObjectPairs(constructor, propertyName))); |
| 2133 | return pairs; |
| 2134 | }, []); |
| 2135 | } |
| 2136 | function getAncestorsForConstructor(constructor) { |
| 2137 | var ancestors = []; |
| 2138 | while(constructor){ |
| 2139 | ancestors.push(constructor); |
| 2140 | constructor = Object.getPrototypeOf(constructor); |
| 2141 | } |
| 2142 | return ancestors.reverse(); |
| 2143 | } |
| 2144 | function getOwnStaticArrayValues(constructor, propertyName) { |
| 2145 | var definition = constructor[propertyName]; |
| 2146 | return Array.isArray(definition) ? definition : []; |
| 2147 | } |
| 2148 | function getOwnStaticObjectPairs(constructor, propertyName) { |
| 2149 | var definition = constructor[propertyName]; |
| 2150 | return definition ? Object.keys(definition).map(function(key) { |
| 2151 | return [ |
| 2152 | key, |
| 2153 | definition[key] |
| 2154 | ]; |
| 2155 | }) : []; |
| 2156 | } |
| 2157 | function bless(constructor) { |
| 2158 | return shadow(constructor, getBlessedProperties(constructor)); |
| 2159 | } |
| 2160 | function shadow(constructor, properties) { |
| 2161 | var shadowConstructor = extend(constructor); |
| 2162 | var shadowProperties = getShadowProperties(constructor.prototype, properties); |
| 2163 | Object.defineProperties(shadowConstructor.prototype, shadowProperties); |
| 2164 | return shadowConstructor; |
| 2165 | } |
| 2166 | function getBlessedProperties(constructor) { |
| 2167 | var blessings = readInheritableStaticArrayValues(constructor, "blessings"); |
| 2168 | return blessings.reduce(function(blessedProperties, blessing) { |
| 2169 | var properties = blessing(constructor); |
| 2170 | for(var key in properties){ |
| 2171 | var descriptor = blessedProperties[key] || {}; |
| 2172 | blessedProperties[key] = Object.assign(descriptor, properties[key]); |
| 2173 | } |
| 2174 | return blessedProperties; |
| 2175 | }, {}); |
| 2176 | } |
| 2177 | function getShadowProperties(prototype, properties) { |
| 2178 | return getOwnKeys(properties).reduce(function(shadowProperties, key) { |
| 2179 | var descriptor = getShadowedDescriptor(prototype, properties, key); |
| 2180 | if (descriptor) Object.assign(shadowProperties, (0, _definePropertyJsDefault.default)({}, key, descriptor)); |
| 2181 | return shadowProperties; |
| 2182 | }, {}); |
| 2183 | } |
| 2184 | function getShadowedDescriptor(prototype, properties, key) { |
| 2185 | var shadowingDescriptor = Object.getOwnPropertyDescriptor(prototype, key); |
| 2186 | var shadowedByValue = shadowingDescriptor && "value" in shadowingDescriptor; |
| 2187 | if (!shadowedByValue) { |
| 2188 | var descriptor = Object.getOwnPropertyDescriptor(properties, key).value; |
| 2189 | if (shadowingDescriptor) { |
| 2190 | descriptor.get = shadowingDescriptor.get || descriptor.get; |
| 2191 | descriptor.set = shadowingDescriptor.set || descriptor.set; |
| 2192 | } |
| 2193 | return descriptor; |
| 2194 | } |
| 2195 | } |
| 2196 | var getOwnKeys = function() { |
| 2197 | if (typeof Object.getOwnPropertySymbols == "function") return function(object) { |
| 2198 | return (0, _toConsumableArrayJsDefault.default)(Object.getOwnPropertyNames(object)).concat((0, _toConsumableArrayJsDefault.default)(Object.getOwnPropertySymbols(object))); |
| 2199 | }; |
| 2200 | else return Object.getOwnPropertyNames; |
| 2201 | }(); |
| 2202 | var extend = function _target() { |
| 2203 | function extendWithReflect(constructor) { |
| 2204 | function extended() { |
| 2205 | return Reflect.construct(constructor, arguments, this instanceof extended ? this.constructor : void 0); |
| 2206 | } |
| 2207 | extended.prototype = Object.create(constructor.prototype, { |
| 2208 | constructor: { |
| 2209 | value: extended |
| 2210 | } |
| 2211 | }); |
| 2212 | Reflect.setPrototypeOf(extended, constructor); |
| 2213 | return extended; |
| 2214 | } |
| 2215 | function testReflectExtension() { |
| 2216 | var a = function a() { |
| 2217 | this.a.call(this); |
| 2218 | }; |
| 2219 | var b = extendWithReflect(a); |
| 2220 | b.prototype.a = function() {}; |
| 2221 | return new b; |
| 2222 | } |
| 2223 | try { |
| 2224 | testReflectExtension(); |
| 2225 | return extendWithReflect; |
| 2226 | } catch (error) { |
| 2227 | return function(constructor3) { |
| 2228 | return /*#__PURE__*/ function(constructor) { |
| 2229 | "use strict"; |
| 2230 | (0, _inheritsJsDefault.default)(extended, constructor); |
| 2231 | var _super = (0, _createSuperJsDefault.default)(extended); |
| 2232 | function extended() { |
| 2233 | (0, _classCallCheckJsDefault.default)(this, extended); |
| 2234 | return _super.apply(this, arguments); |
| 2235 | } |
| 2236 | return extended; |
| 2237 | }(constructor3); |
| 2238 | }; |
| 2239 | } |
| 2240 | }(); |
| 2241 | function blessDefinition(definition) { |
| 2242 | return { |
| 2243 | identifier: definition.identifier, |
| 2244 | controllerConstructor: bless(definition.controllerConstructor) |
| 2245 | }; |
| 2246 | } |
| 2247 | var Module = /*#__PURE__*/ function() { |
| 2248 | "use strict"; |
| 2249 | function Module(application, definition) { |
| 2250 | (0, _classCallCheckJsDefault.default)(this, Module); |
| 2251 | this.application = application; |
| 2252 | this.definition = blessDefinition(definition); |
| 2253 | this.contextsByScope = new WeakMap; |
| 2254 | this.connectedContexts = new Set; |
| 2255 | } |
| 2256 | (0, _createClassJsDefault.default)(Module, [ |
| 2257 | { |
| 2258 | key: "identifier", |
| 2259 | get: function get() { |
| 2260 | return this.definition.identifier; |
| 2261 | } |
| 2262 | }, |
| 2263 | { |
| 2264 | key: "controllerConstructor", |
| 2265 | get: function get() { |
| 2266 | return this.definition.controllerConstructor; |
| 2267 | } |
| 2268 | }, |
| 2269 | { |
| 2270 | key: "contexts", |
| 2271 | get: function get() { |
| 2272 | return Array.from(this.connectedContexts); |
| 2273 | } |
| 2274 | }, |
| 2275 | { |
| 2276 | key: "connectContextForScope", |
| 2277 | value: function connectContextForScope(scope) { |
| 2278 | var context = this.fetchContextForScope(scope); |
| 2279 | this.connectedContexts.add(context); |
| 2280 | context.connect(); |
| 2281 | } |
| 2282 | }, |
| 2283 | { |
| 2284 | key: "disconnectContextForScope", |
| 2285 | value: function disconnectContextForScope(scope) { |
| 2286 | var context = this.contextsByScope.get(scope); |
| 2287 | if (context) { |
| 2288 | this.connectedContexts.delete(context); |
| 2289 | context.disconnect(); |
| 2290 | } |
| 2291 | } |
| 2292 | }, |
| 2293 | { |
| 2294 | key: "fetchContextForScope", |
| 2295 | value: function fetchContextForScope(scope) { |
| 2296 | var context = this.contextsByScope.get(scope); |
| 2297 | if (!context) { |
| 2298 | context = new Context(this, scope); |
| 2299 | this.contextsByScope.set(scope, context); |
| 2300 | } |
| 2301 | return context; |
| 2302 | } |
| 2303 | } |
| 2304 | ]); |
| 2305 | return Module; |
| 2306 | }(); |
| 2307 | var ClassMap = /*#__PURE__*/ function() { |
| 2308 | "use strict"; |
| 2309 | function ClassMap(scope) { |
| 2310 | (0, _classCallCheckJsDefault.default)(this, ClassMap); |
| 2311 | this.scope = scope; |
| 2312 | } |
| 2313 | (0, _createClassJsDefault.default)(ClassMap, [ |
| 2314 | { |
| 2315 | key: "has", |
| 2316 | value: function has(name) { |
| 2317 | return this.data.has(this.getDataKey(name)); |
| 2318 | } |
| 2319 | }, |
| 2320 | { |
| 2321 | key: "get", |
| 2322 | value: function get(name) { |
| 2323 | return this.getAll(name)[0]; |
| 2324 | } |
| 2325 | }, |
| 2326 | { |
| 2327 | key: "getAll", |
| 2328 | value: function getAll(name) { |
| 2329 | var tokenString = this.data.get(this.getDataKey(name)) || ""; |
| 2330 | return tokenize(tokenString); |
| 2331 | } |
| 2332 | }, |
| 2333 | { |
| 2334 | key: "getAttributeName", |
| 2335 | value: function getAttributeName(name) { |
| 2336 | return this.data.getAttributeNameForKey(this.getDataKey(name)); |
| 2337 | } |
| 2338 | }, |
| 2339 | { |
| 2340 | key: "getDataKey", |
| 2341 | value: function getDataKey(name) { |
| 2342 | return "".concat(name, "-class"); |
| 2343 | } |
| 2344 | }, |
| 2345 | { |
| 2346 | key: "data", |
| 2347 | get: function get() { |
| 2348 | return this.scope.data; |
| 2349 | } |
| 2350 | } |
| 2351 | ]); |
| 2352 | return ClassMap; |
| 2353 | }(); |
| 2354 | var DataMap = /*#__PURE__*/ function() { |
| 2355 | "use strict"; |
| 2356 | function DataMap(scope) { |
| 2357 | (0, _classCallCheckJsDefault.default)(this, DataMap); |
| 2358 | this.scope = scope; |
| 2359 | } |
| 2360 | (0, _createClassJsDefault.default)(DataMap, [ |
| 2361 | { |
| 2362 | key: "element", |
| 2363 | get: function get() { |
| 2364 | return this.scope.element; |
| 2365 | } |
| 2366 | }, |
| 2367 | { |
| 2368 | key: "identifier", |
| 2369 | get: function get() { |
| 2370 | return this.scope.identifier; |
| 2371 | } |
| 2372 | }, |
| 2373 | { |
| 2374 | key: "get", |
| 2375 | value: function get(key) { |
| 2376 | var name = this.getAttributeNameForKey(key); |
| 2377 | return this.element.getAttribute(name); |
| 2378 | } |
| 2379 | }, |
| 2380 | { |
| 2381 | key: "set", |
| 2382 | value: function set(key, value) { |
| 2383 | var name = this.getAttributeNameForKey(key); |
| 2384 | this.element.setAttribute(name, value); |
| 2385 | return this.get(key); |
| 2386 | } |
| 2387 | }, |
| 2388 | { |
| 2389 | key: "has", |
| 2390 | value: function has(key) { |
| 2391 | var name = this.getAttributeNameForKey(key); |
| 2392 | return this.element.hasAttribute(name); |
| 2393 | } |
| 2394 | }, |
| 2395 | { |
| 2396 | key: "delete", |
| 2397 | value: function _delete(key) { |
| 2398 | if (this.has(key)) { |
| 2399 | var name = this.getAttributeNameForKey(key); |
| 2400 | this.element.removeAttribute(name); |
| 2401 | return true; |
| 2402 | } else return false; |
| 2403 | } |
| 2404 | }, |
| 2405 | { |
| 2406 | key: "getAttributeNameForKey", |
| 2407 | value: function getAttributeNameForKey(key) { |
| 2408 | return "data-".concat(this.identifier, "-").concat(dasherize(key)); |
| 2409 | } |
| 2410 | } |
| 2411 | ]); |
| 2412 | return DataMap; |
| 2413 | }(); |
| 2414 | var Guide = /*#__PURE__*/ function() { |
| 2415 | "use strict"; |
| 2416 | function Guide(logger) { |
| 2417 | (0, _classCallCheckJsDefault.default)(this, Guide); |
| 2418 | this.warnedKeysByObject = new WeakMap; |
| 2419 | this.logger = logger; |
| 2420 | } |
| 2421 | (0, _createClassJsDefault.default)(Guide, [ |
| 2422 | { |
| 2423 | key: "warn", |
| 2424 | value: function warn(object, key, message) { |
| 2425 | var warnedKeys = this.warnedKeysByObject.get(object); |
| 2426 | if (!warnedKeys) { |
| 2427 | warnedKeys = new Set; |
| 2428 | this.warnedKeysByObject.set(object, warnedKeys); |
| 2429 | } |
| 2430 | if (!warnedKeys.has(key)) { |
| 2431 | warnedKeys.add(key); |
| 2432 | this.logger.warn(message, object); |
| 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | ]); |
| 2437 | return Guide; |
| 2438 | }(); |
| 2439 | function attributeValueContainsToken(attributeName, token) { |
| 2440 | return "[".concat(attributeName, '~="').concat(token, '"]'); |
| 2441 | } |
| 2442 | var TargetSet = /*#__PURE__*/ function() { |
| 2443 | "use strict"; |
| 2444 | function TargetSet(scope) { |
| 2445 | (0, _classCallCheckJsDefault.default)(this, TargetSet); |
| 2446 | this.scope = scope; |
| 2447 | } |
| 2448 | (0, _createClassJsDefault.default)(TargetSet, [ |
| 2449 | { |
| 2450 | key: "element", |
| 2451 | get: function get() { |
| 2452 | return this.scope.element; |
| 2453 | } |
| 2454 | }, |
| 2455 | { |
| 2456 | key: "identifier", |
| 2457 | get: function get() { |
| 2458 | return this.scope.identifier; |
| 2459 | } |
| 2460 | }, |
| 2461 | { |
| 2462 | key: "schema", |
| 2463 | get: function get() { |
| 2464 | return this.scope.schema; |
| 2465 | } |
| 2466 | }, |
| 2467 | { |
| 2468 | key: "has", |
| 2469 | value: function has(targetName) { |
| 2470 | return this.find(targetName) != null; |
| 2471 | } |
| 2472 | }, |
| 2473 | { |
| 2474 | key: "find", |
| 2475 | value: function find() { |
| 2476 | for(var _len = arguments.length, targetNames = new Array(_len), _key = 0; _key < _len; _key++){ |
| 2477 | targetNames[_key] = arguments[_key]; |
| 2478 | } |
| 2479 | var _this = this; |
| 2480 | return targetNames.reduce(function(target, targetName) { |
| 2481 | return target || _this.findTarget(targetName) || _this.findLegacyTarget(targetName); |
| 2482 | }, undefined); |
| 2483 | } |
| 2484 | }, |
| 2485 | { |
| 2486 | key: "findAll", |
| 2487 | value: function findAll() { |
| 2488 | for(var _len = arguments.length, targetNames = new Array(_len), _key = 0; _key < _len; _key++){ |
| 2489 | targetNames[_key] = arguments[_key]; |
| 2490 | } |
| 2491 | var _this = this; |
| 2492 | return targetNames.reduce(function(targets, targetName) { |
| 2493 | return (0, _toConsumableArrayJsDefault.default)(targets).concat((0, _toConsumableArrayJsDefault.default)(_this.findAllTargets(targetName)), (0, _toConsumableArrayJsDefault.default)(_this.findAllLegacyTargets(targetName))); |
| 2494 | }, []); |
| 2495 | } |
| 2496 | }, |
| 2497 | { |
| 2498 | key: "findTarget", |
| 2499 | value: function findTarget(targetName) { |
| 2500 | var selector = this.getSelectorForTargetName(targetName); |
| 2501 | return this.scope.findElement(selector); |
| 2502 | } |
| 2503 | }, |
| 2504 | { |
| 2505 | key: "findAllTargets", |
| 2506 | value: function findAllTargets(targetName) { |
| 2507 | var selector = this.getSelectorForTargetName(targetName); |
| 2508 | return this.scope.findAllElements(selector); |
| 2509 | } |
| 2510 | }, |
| 2511 | { |
| 2512 | key: "getSelectorForTargetName", |
| 2513 | value: function getSelectorForTargetName(targetName) { |
| 2514 | var attributeName = this.schema.targetAttributeForScope(this.identifier); |
| 2515 | return attributeValueContainsToken(attributeName, targetName); |
| 2516 | } |
| 2517 | }, |
| 2518 | { |
| 2519 | key: "findLegacyTarget", |
| 2520 | value: function findLegacyTarget(targetName) { |
| 2521 | var selector = this.getLegacySelectorForTargetName(targetName); |
| 2522 | return this.deprecate(this.scope.findElement(selector), targetName); |
| 2523 | } |
| 2524 | }, |
| 2525 | { |
| 2526 | key: "findAllLegacyTargets", |
| 2527 | value: function findAllLegacyTargets(targetName) { |
| 2528 | var _this = this; |
| 2529 | var selector = this.getLegacySelectorForTargetName(targetName); |
| 2530 | return this.scope.findAllElements(selector).map(function(element) { |
| 2531 | return _this.deprecate(element, targetName); |
| 2532 | }); |
| 2533 | } |
| 2534 | }, |
| 2535 | { |
| 2536 | key: "getLegacySelectorForTargetName", |
| 2537 | value: function getLegacySelectorForTargetName(targetName) { |
| 2538 | var targetDescriptor = "".concat(this.identifier, ".").concat(targetName); |
| 2539 | return attributeValueContainsToken(this.schema.targetAttribute, targetDescriptor); |
| 2540 | } |
| 2541 | }, |
| 2542 | { |
| 2543 | key: "deprecate", |
| 2544 | value: function deprecate(element, targetName) { |
| 2545 | if (element) { |
| 2546 | var identifier = this.identifier; |
| 2547 | var attributeName = this.schema.targetAttribute; |
| 2548 | var revisedAttributeName = this.schema.targetAttributeForScope(identifier); |
| 2549 | this.guide.warn(element, "target:".concat(targetName), "Please replace ".concat(attributeName, '="').concat(identifier, ".").concat(targetName, '" with ').concat(revisedAttributeName, '="').concat(targetName, '". ') + "The ".concat(attributeName, " attribute is deprecated and will be removed in a future version of Stimulus.")); |
| 2550 | } |
| 2551 | return element; |
| 2552 | } |
| 2553 | }, |
| 2554 | { |
| 2555 | key: "guide", |
| 2556 | get: function get() { |
| 2557 | return this.scope.guide; |
| 2558 | } |
| 2559 | } |
| 2560 | ]); |
| 2561 | return TargetSet; |
| 2562 | }(); |
| 2563 | var Scope = /*#__PURE__*/ function() { |
| 2564 | "use strict"; |
| 2565 | function Scope(schema, element2, identifier, logger) { |
| 2566 | var _this = this; |
| 2567 | (0, _classCallCheckJsDefault.default)(this, Scope); |
| 2568 | this.targets = new TargetSet(this); |
| 2569 | this.classes = new ClassMap(this); |
| 2570 | this.data = new DataMap(this); |
| 2571 | this.containsElement = function(element) { |
| 2572 | return element.closest(_this.controllerSelector) === _this.element; |
| 2573 | }; |
| 2574 | this.schema = schema; |
| 2575 | this.element = element2; |
| 2576 | this.identifier = identifier; |
| 2577 | this.guide = new Guide(logger); |
| 2578 | } |
| 2579 | (0, _createClassJsDefault.default)(Scope, [ |
| 2580 | { |
| 2581 | key: "findElement", |
| 2582 | value: function findElement(selector) { |
| 2583 | return this.element.matches(selector) ? this.element : this.queryElements(selector).find(this.containsElement); |
| 2584 | } |
| 2585 | }, |
| 2586 | { |
| 2587 | key: "findAllElements", |
| 2588 | value: function findAllElements(selector) { |
| 2589 | return (0, _toConsumableArrayJsDefault.default)(this.element.matches(selector) ? [ |
| 2590 | this.element |
| 2591 | ] : []).concat((0, _toConsumableArrayJsDefault.default)(this.queryElements(selector).filter(this.containsElement))); |
| 2592 | } |
| 2593 | }, |
| 2594 | { |
| 2595 | key: "queryElements", |
| 2596 | value: function queryElements(selector) { |
| 2597 | return Array.from(this.element.querySelectorAll(selector)); |
| 2598 | } |
| 2599 | }, |
| 2600 | { |
| 2601 | key: "controllerSelector", |
| 2602 | get: function get() { |
| 2603 | return attributeValueContainsToken(this.schema.controllerAttribute, this.identifier); |
| 2604 | } |
| 2605 | } |
| 2606 | ]); |
| 2607 | return Scope; |
| 2608 | }(); |
| 2609 | var ScopeObserver = /*#__PURE__*/ function() { |
| 2610 | "use strict"; |
| 2611 | function ScopeObserver(element, schema, delegate) { |
| 2612 | (0, _classCallCheckJsDefault.default)(this, ScopeObserver); |
| 2613 | this.element = element; |
| 2614 | this.schema = schema; |
| 2615 | this.delegate = delegate; |
| 2616 | this.valueListObserver = new ValueListObserver(this.element, this.controllerAttribute, this); |
| 2617 | this.scopesByIdentifierByElement = new WeakMap; |
| 2618 | this.scopeReferenceCounts = new WeakMap; |
| 2619 | } |
| 2620 | (0, _createClassJsDefault.default)(ScopeObserver, [ |
| 2621 | { |
| 2622 | key: "start", |
| 2623 | value: function start() { |
| 2624 | this.valueListObserver.start(); |
| 2625 | } |
| 2626 | }, |
| 2627 | { |
| 2628 | key: "stop", |
| 2629 | value: function stop() { |
| 2630 | this.valueListObserver.stop(); |
| 2631 | } |
| 2632 | }, |
| 2633 | { |
| 2634 | key: "controllerAttribute", |
| 2635 | get: function get() { |
| 2636 | return this.schema.controllerAttribute; |
| 2637 | } |
| 2638 | }, |
| 2639 | { |
| 2640 | key: "parseValueForToken", |
| 2641 | value: function parseValueForToken(token) { |
| 2642 | var element = token.element, identifier = token.content; |
| 2643 | var scopesByIdentifier = this.fetchScopesByIdentifierForElement(element); |
| 2644 | var scope = scopesByIdentifier.get(identifier); |
| 2645 | if (!scope) { |
| 2646 | scope = this.delegate.createScopeForElementAndIdentifier(element, identifier); |
| 2647 | scopesByIdentifier.set(identifier, scope); |
| 2648 | } |
| 2649 | return scope; |
| 2650 | } |
| 2651 | }, |
| 2652 | { |
| 2653 | key: "elementMatchedValue", |
| 2654 | value: function elementMatchedValue(element, value) { |
| 2655 | var referenceCount = (this.scopeReferenceCounts.get(value) || 0) + 1; |
| 2656 | this.scopeReferenceCounts.set(value, referenceCount); |
| 2657 | if (referenceCount == 1) this.delegate.scopeConnected(value); |
| 2658 | } |
| 2659 | }, |
| 2660 | { |
| 2661 | key: "elementUnmatchedValue", |
| 2662 | value: function elementUnmatchedValue(element, value) { |
| 2663 | var referenceCount = this.scopeReferenceCounts.get(value); |
| 2664 | if (referenceCount) { |
| 2665 | this.scopeReferenceCounts.set(value, referenceCount - 1); |
| 2666 | if (referenceCount == 1) this.delegate.scopeDisconnected(value); |
| 2667 | } |
| 2668 | } |
| 2669 | }, |
| 2670 | { |
| 2671 | key: "fetchScopesByIdentifierForElement", |
| 2672 | value: function fetchScopesByIdentifierForElement(element) { |
| 2673 | var scopesByIdentifier = this.scopesByIdentifierByElement.get(element); |
| 2674 | if (!scopesByIdentifier) { |
| 2675 | scopesByIdentifier = new Map; |
| 2676 | this.scopesByIdentifierByElement.set(element, scopesByIdentifier); |
| 2677 | } |
| 2678 | return scopesByIdentifier; |
| 2679 | } |
| 2680 | } |
| 2681 | ]); |
| 2682 | return ScopeObserver; |
| 2683 | }(); |
| 2684 | var Router = /*#__PURE__*/ function() { |
| 2685 | "use strict"; |
| 2686 | function Router(application) { |
| 2687 | (0, _classCallCheckJsDefault.default)(this, Router); |
| 2688 | this.application = application; |
| 2689 | this.scopeObserver = new ScopeObserver(this.element, this.schema, this); |
| 2690 | this.scopesByIdentifier = new Multimap; |
| 2691 | this.modulesByIdentifier = new Map; |
| 2692 | } |
| 2693 | (0, _createClassJsDefault.default)(Router, [ |
| 2694 | { |
| 2695 | key: "element", |
| 2696 | get: function get() { |
| 2697 | return this.application.element; |
| 2698 | } |
| 2699 | }, |
| 2700 | { |
| 2701 | key: "schema", |
| 2702 | get: function get() { |
| 2703 | return this.application.schema; |
| 2704 | } |
| 2705 | }, |
| 2706 | { |
| 2707 | key: "logger", |
| 2708 | get: function get() { |
| 2709 | return this.application.logger; |
| 2710 | } |
| 2711 | }, |
| 2712 | { |
| 2713 | key: "controllerAttribute", |
| 2714 | get: function get() { |
| 2715 | return this.schema.controllerAttribute; |
| 2716 | } |
| 2717 | }, |
| 2718 | { |
| 2719 | key: "modules", |
| 2720 | get: function get() { |
| 2721 | return Array.from(this.modulesByIdentifier.values()); |
| 2722 | } |
| 2723 | }, |
| 2724 | { |
| 2725 | key: "contexts", |
| 2726 | get: function get() { |
| 2727 | return this.modules.reduce(function(contexts, module) { |
| 2728 | return contexts.concat(module.contexts); |
| 2729 | }, []); |
| 2730 | } |
| 2731 | }, |
| 2732 | { |
| 2733 | key: "start", |
| 2734 | value: function start() { |
| 2735 | this.scopeObserver.start(); |
| 2736 | } |
| 2737 | }, |
| 2738 | { |
| 2739 | key: "stop", |
| 2740 | value: function stop() { |
| 2741 | this.scopeObserver.stop(); |
| 2742 | } |
| 2743 | }, |
| 2744 | { |
| 2745 | key: "loadDefinition", |
| 2746 | value: function loadDefinition(definition) { |
| 2747 | this.unloadIdentifier(definition.identifier); |
| 2748 | var module = new Module(this.application, definition); |
| 2749 | this.connectModule(module); |
| 2750 | } |
| 2751 | }, |
| 2752 | { |
| 2753 | key: "unloadIdentifier", |
| 2754 | value: function unloadIdentifier(identifier) { |
| 2755 | var module = this.modulesByIdentifier.get(identifier); |
| 2756 | if (module) this.disconnectModule(module); |
| 2757 | } |
| 2758 | }, |
| 2759 | { |
| 2760 | key: "getContextForElementAndIdentifier", |
| 2761 | value: function getContextForElementAndIdentifier(element, identifier) { |
| 2762 | var module = this.modulesByIdentifier.get(identifier); |
| 2763 | if (module) return module.contexts.find(function(context) { |
| 2764 | return context.element == element; |
| 2765 | }); |
| 2766 | } |
| 2767 | }, |
| 2768 | { |
| 2769 | key: "handleError", |
| 2770 | value: function handleError(error8, message, detail) { |
| 2771 | this.application.handleError(error8, message, detail); |
| 2772 | } |
| 2773 | }, |
| 2774 | { |
| 2775 | key: "createScopeForElementAndIdentifier", |
| 2776 | value: function createScopeForElementAndIdentifier(element, identifier) { |
| 2777 | return new Scope(this.schema, element, identifier, this.logger); |
| 2778 | } |
| 2779 | }, |
| 2780 | { |
| 2781 | key: "scopeConnected", |
| 2782 | value: function scopeConnected(scope) { |
| 2783 | this.scopesByIdentifier.add(scope.identifier, scope); |
| 2784 | var module = this.modulesByIdentifier.get(scope.identifier); |
| 2785 | if (module) module.connectContextForScope(scope); |
| 2786 | } |
| 2787 | }, |
| 2788 | { |
| 2789 | key: "scopeDisconnected", |
| 2790 | value: function scopeDisconnected(scope) { |
| 2791 | this.scopesByIdentifier.delete(scope.identifier, scope); |
| 2792 | var module = this.modulesByIdentifier.get(scope.identifier); |
| 2793 | if (module) module.disconnectContextForScope(scope); |
| 2794 | } |
| 2795 | }, |
| 2796 | { |
| 2797 | key: "connectModule", |
| 2798 | value: function connectModule(module) { |
| 2799 | this.modulesByIdentifier.set(module.identifier, module); |
| 2800 | var scopes = this.scopesByIdentifier.getValuesForKey(module.identifier); |
| 2801 | scopes.forEach(function(scope) { |
| 2802 | return module.connectContextForScope(scope); |
| 2803 | }); |
| 2804 | } |
| 2805 | }, |
| 2806 | { |
| 2807 | key: "disconnectModule", |
| 2808 | value: function disconnectModule(module) { |
| 2809 | this.modulesByIdentifier.delete(module.identifier); |
| 2810 | var scopes = this.scopesByIdentifier.getValuesForKey(module.identifier); |
| 2811 | scopes.forEach(function(scope) { |
| 2812 | return module.disconnectContextForScope(scope); |
| 2813 | }); |
| 2814 | } |
| 2815 | } |
| 2816 | ]); |
| 2817 | return Router; |
| 2818 | }(); |
| 2819 | var defaultSchema = { |
| 2820 | controllerAttribute: "data-controller", |
| 2821 | actionAttribute: "data-action", |
| 2822 | targetAttribute: "data-target", |
| 2823 | targetAttributeForScope: function(identifier) { |
| 2824 | return "data-".concat(identifier, "-target"); |
| 2825 | } |
| 2826 | }; |
| 2827 | var Application = /*#__PURE__*/ function() { |
| 2828 | "use strict"; |
| 2829 | function Application() { |
| 2830 | var element = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : document.documentElement, schema = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : defaultSchema; |
| 2831 | var _this = this; |
| 2832 | (0, _classCallCheckJsDefault.default)(this, Application); |
| 2833 | this.logger = console; |
| 2834 | this.debug = false; |
| 2835 | this.logDebugActivity = function(identifier, functionName) { |
| 2836 | var detail = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}; |
| 2837 | if (_this.debug) _this.logFormattedMessage(identifier, functionName, detail); |
| 2838 | }; |
| 2839 | this.element = element; |
| 2840 | this.schema = schema; |
| 2841 | this.dispatcher = new Dispatcher(this); |
| 2842 | this.router = new Router(this); |
| 2843 | } |
| 2844 | (0, _createClassJsDefault.default)(Application, [ |
| 2845 | { |
| 2846 | key: "start", |
| 2847 | value: function start() { |
| 2848 | var _this = this; |
| 2849 | return (0, _asyncToGeneratorJsDefault.default)((0, _regeneratorRuntimeDefault.default).mark(function _callee() { |
| 2850 | return (0, _regeneratorRuntimeDefault.default).wrap(function _callee$(_ctx) { |
| 2851 | while(1)switch(_ctx.prev = _ctx.next){ |
| 2852 | case 0: |
| 2853 | _ctx.next = 2; |
| 2854 | return domReady(); |
| 2855 | case 2: |
| 2856 | _this.logDebugActivity("application", "starting"); |
| 2857 | _this.dispatcher.start(); |
| 2858 | _this.router.start(); |
| 2859 | _this.logDebugActivity("application", "start"); |
| 2860 | case 6: |
| 2861 | case "end": |
| 2862 | return _ctx.stop(); |
| 2863 | } |
| 2864 | }, _callee); |
| 2865 | }))(); |
| 2866 | } |
| 2867 | }, |
| 2868 | { |
| 2869 | key: "stop", |
| 2870 | value: function stop() { |
| 2871 | this.logDebugActivity("application", "stopping"); |
| 2872 | this.dispatcher.stop(); |
| 2873 | this.router.stop(); |
| 2874 | this.logDebugActivity("application", "stop"); |
| 2875 | } |
| 2876 | }, |
| 2877 | { |
| 2878 | key: "register", |
| 2879 | value: function register(identifier, controllerConstructor) { |
| 2880 | if (controllerConstructor.shouldLoad) this.load({ |
| 2881 | identifier: identifier, |
| 2882 | controllerConstructor: controllerConstructor |
| 2883 | }); |
| 2884 | } |
| 2885 | }, |
| 2886 | { |
| 2887 | key: "load", |
| 2888 | value: function load(head) { |
| 2889 | for(var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){ |
| 2890 | rest[_key - 1] = arguments[_key]; |
| 2891 | } |
| 2892 | var _this = this; |
| 2893 | var definitions = Array.isArray(head) ? head : [ |
| 2894 | head |
| 2895 | ].concat((0, _toConsumableArrayJsDefault.default)(rest)); |
| 2896 | definitions.forEach(function(definition) { |
| 2897 | return _this.router.loadDefinition(definition); |
| 2898 | }); |
| 2899 | } |
| 2900 | }, |
| 2901 | { |
| 2902 | key: "unload", |
| 2903 | value: function unload(head) { |
| 2904 | for(var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){ |
| 2905 | rest[_key - 1] = arguments[_key]; |
| 2906 | } |
| 2907 | var _this = this; |
| 2908 | var identifiers = Array.isArray(head) ? head : [ |
| 2909 | head |
| 2910 | ].concat((0, _toConsumableArrayJsDefault.default)(rest)); |
| 2911 | identifiers.forEach(function(identifier) { |
| 2912 | return _this.router.unloadIdentifier(identifier); |
| 2913 | }); |
| 2914 | } |
| 2915 | }, |
| 2916 | { |
| 2917 | key: "controllers", |
| 2918 | get: function get() { |
| 2919 | return this.router.contexts.map(function(context) { |
| 2920 | return context.controller; |
| 2921 | }); |
| 2922 | } |
| 2923 | }, |
| 2924 | { |
| 2925 | key: "getControllerForElementAndIdentifier", |
| 2926 | value: function getControllerForElementAndIdentifier(element, identifier) { |
| 2927 | var context = this.router.getContextForElementAndIdentifier(element, identifier); |
| 2928 | return context ? context.controller : null; |
| 2929 | } |
| 2930 | }, |
| 2931 | { |
| 2932 | key: "handleError", |
| 2933 | value: function handleError(error9, message, detail) { |
| 2934 | var _a; |
| 2935 | this.logger.error("%s\n\n%o\n\n%o", message, error9, detail); |
| 2936 | (_a = window.onerror) === null || _a === void 0 || _a.call(window, message, "", 0, 0, error9); |
| 2937 | } |
| 2938 | }, |
| 2939 | { |
| 2940 | key: "logFormattedMessage", |
| 2941 | value: function logFormattedMessage(identifier, functionName) { |
| 2942 | var detail = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}; |
| 2943 | detail = Object.assign({ |
| 2944 | application: this |
| 2945 | }, detail); |
| 2946 | this.logger.groupCollapsed("".concat(identifier, " #").concat(functionName)); |
| 2947 | this.logger.log("details:", Object.assign({}, detail)); |
| 2948 | this.logger.groupEnd(); |
| 2949 | } |
| 2950 | } |
| 2951 | ], [ |
| 2952 | { |
| 2953 | key: "start", |
| 2954 | value: function start(element, schema) { |
| 2955 | var application = new Application(element, schema); |
| 2956 | application.start(); |
| 2957 | return application; |
| 2958 | } |
| 2959 | } |
| 2960 | ]); |
| 2961 | return Application; |
| 2962 | }(); |
| 2963 | function domReady() { |
| 2964 | return new Promise(function(resolve) { |
| 2965 | if (document.readyState == "loading") document.addEventListener("DOMContentLoaded", function() { |
| 2966 | return resolve(); |
| 2967 | }); |
| 2968 | else resolve(); |
| 2969 | }); |
| 2970 | } |
| 2971 | function ClassPropertiesBlessing(constructor) { |
| 2972 | var classes = readInheritableStaticArrayValues(constructor, "classes"); |
| 2973 | return classes.reduce(function(properties, classDefinition) { |
| 2974 | return Object.assign(properties, propertiesForClassDefinition(classDefinition)); |
| 2975 | }, {}); |
| 2976 | } |
| 2977 | function propertiesForClassDefinition(key) { |
| 2978 | var _obj; |
| 2979 | return _obj = {}, (0, _definePropertyJsDefault.default)(_obj, "".concat(key, "Class"), { |
| 2980 | get: function() { |
| 2981 | var classes = this.classes; |
| 2982 | if (classes.has(key)) return classes.get(key); |
| 2983 | else { |
| 2984 | var attribute = classes.getAttributeName(key); |
| 2985 | throw new Error('Missing attribute "'.concat(attribute, '"')); |
| 2986 | } |
| 2987 | } |
| 2988 | }), (0, _definePropertyJsDefault.default)(_obj, "".concat(key, "Classes"), { |
| 2989 | get: function() { |
| 2990 | return this.classes.getAll(key); |
| 2991 | } |
| 2992 | }), (0, _definePropertyJsDefault.default)(_obj, "has".concat(capitalize(key), "Class"), { |
| 2993 | get: function() { |
| 2994 | return this.classes.has(key); |
| 2995 | } |
| 2996 | }), _obj; |
| 2997 | } |
| 2998 | function TargetPropertiesBlessing(constructor) { |
| 2999 | var targets = readInheritableStaticArrayValues(constructor, "targets"); |
| 3000 | return targets.reduce(function(properties, targetDefinition) { |
| 3001 | return Object.assign(properties, propertiesForTargetDefinition(targetDefinition)); |
| 3002 | }, {}); |
| 3003 | } |
| 3004 | function propertiesForTargetDefinition(name) { |
| 3005 | var _obj; |
| 3006 | return _obj = {}, (0, _definePropertyJsDefault.default)(_obj, "".concat(name, "Target"), { |
| 3007 | get: function() { |
| 3008 | var target = this.targets.find(name); |
| 3009 | if (target) return target; |
| 3010 | else throw new Error('Missing target element "'.concat(name, '" for "').concat(this.identifier, '" controller')); |
| 3011 | } |
| 3012 | }), (0, _definePropertyJsDefault.default)(_obj, "".concat(name, "Targets"), { |
| 3013 | get: function() { |
| 3014 | return this.targets.findAll(name); |
| 3015 | } |
| 3016 | }), (0, _definePropertyJsDefault.default)(_obj, "has".concat(capitalize(name), "Target"), { |
| 3017 | get: function() { |
| 3018 | return this.targets.has(name); |
| 3019 | } |
| 3020 | }), _obj; |
| 3021 | } |
| 3022 | function ValuePropertiesBlessing(constructor) { |
| 3023 | var valueDefinitionPairs = readInheritableStaticObjectPairs(constructor, "values"); |
| 3024 | var propertyDescriptorMap = { |
| 3025 | valueDescriptorMap: { |
| 3026 | get: function() { |
| 3027 | var _this = this; |
| 3028 | return valueDefinitionPairs.reduce(function(result, valueDefinitionPair) { |
| 3029 | var valueDescriptor = parseValueDefinitionPair(valueDefinitionPair); |
| 3030 | var attributeName = _this.data.getAttributeNameForKey(valueDescriptor.key); |
| 3031 | return Object.assign(result, (0, _definePropertyJsDefault.default)({}, attributeName, valueDescriptor)); |
| 3032 | }, {}); |
| 3033 | } |
| 3034 | } |
| 3035 | }; |
| 3036 | return valueDefinitionPairs.reduce(function(properties, valueDefinitionPair) { |
| 3037 | return Object.assign(properties, propertiesForValueDefinitionPair(valueDefinitionPair)); |
| 3038 | }, propertyDescriptorMap); |
| 3039 | } |
| 3040 | function propertiesForValueDefinitionPair(valueDefinitionPair) { |
| 3041 | var definition = parseValueDefinitionPair(valueDefinitionPair); |
| 3042 | var key = definition.key, name = definition.name, read = definition.reader, write = definition.writer; |
| 3043 | var _obj; |
| 3044 | return _obj = {}, (0, _definePropertyJsDefault.default)(_obj, name, { |
| 3045 | get: function() { |
| 3046 | var value = this.data.get(key); |
| 3047 | if (value !== null) return read(value); |
| 3048 | else return definition.defaultValue; |
| 3049 | }, |
| 3050 | set: function(value) { |
| 3051 | if (value === undefined) this.data.delete(key); |
| 3052 | else this.data.set(key, write(value)); |
| 3053 | } |
| 3054 | }), (0, _definePropertyJsDefault.default)(_obj, "has".concat(capitalize(name)), { |
| 3055 | get: function() { |
| 3056 | return this.data.has(key) || definition.hasCustomDefaultValue; |
| 3057 | } |
| 3058 | }), _obj; |
| 3059 | } |
| 3060 | function parseValueDefinitionPair(param) { |
| 3061 | var _param = (0, _slicedToArrayJsDefault.default)(param, 2), token = _param[0], typeDefinition = _param[1]; |
| 3062 | return valueDescriptorForTokenAndTypeDefinition(token, typeDefinition); |
| 3063 | } |
| 3064 | function parseValueTypeConstant(constant) { |
| 3065 | switch(constant){ |
| 3066 | case Array: |
| 3067 | return "array"; |
| 3068 | case Boolean: |
| 3069 | return "boolean"; |
| 3070 | case Number: |
| 3071 | return "number"; |
| 3072 | case Object: |
| 3073 | return "object"; |
| 3074 | case String: |
| 3075 | return "string"; |
| 3076 | } |
| 3077 | } |
| 3078 | function parseValueTypeDefault(defaultValue) { |
| 3079 | switch(typeof defaultValue === "undefined" ? "undefined" : (0, _typeOfJsDefault.default)(defaultValue)){ |
| 3080 | case "boolean": |
| 3081 | return "boolean"; |
| 3082 | case "number": |
| 3083 | return "number"; |
| 3084 | case "string": |
| 3085 | return "string"; |
| 3086 | } |
| 3087 | if (Array.isArray(defaultValue)) return "array"; |
| 3088 | if (Object.prototype.toString.call(defaultValue) === "[object Object]") return "object"; |
| 3089 | } |
| 3090 | function parseValueTypeObject(typeObject) { |
| 3091 | var typeFromObject = parseValueTypeConstant(typeObject.type); |
| 3092 | if (typeFromObject) { |
| 3093 | var defaultValueType = parseValueTypeDefault(typeObject.default); |
| 3094 | if (typeFromObject !== defaultValueType) throw new Error('Type "'.concat(typeFromObject, '" must match the type of the default value. Given default value: "').concat(typeObject.default, '" as "').concat(defaultValueType, '"')); |
| 3095 | return typeFromObject; |
| 3096 | } |
| 3097 | } |
| 3098 | function parseValueTypeDefinition(typeDefinition) { |
| 3099 | var typeFromObject = parseValueTypeObject(typeDefinition); |
| 3100 | var typeFromDefaultValue = parseValueTypeDefault(typeDefinition); |
| 3101 | var typeFromConstant = parseValueTypeConstant(typeDefinition); |
| 3102 | var type = typeFromObject || typeFromDefaultValue || typeFromConstant; |
| 3103 | if (type) return type; |
| 3104 | throw new Error('Unknown value type "'.concat(typeDefinition, '"')); |
| 3105 | } |
| 3106 | function defaultValueForDefinition(typeDefinition) { |
| 3107 | var constant = parseValueTypeConstant(typeDefinition); |
| 3108 | if (constant) return defaultValuesByType[constant]; |
| 3109 | var defaultValue = typeDefinition.default; |
| 3110 | if (defaultValue !== undefined) return defaultValue; |
| 3111 | return typeDefinition; |
| 3112 | } |
| 3113 | function valueDescriptorForTokenAndTypeDefinition(token, typeDefinition) { |
| 3114 | var key = "".concat(dasherize(token), "-value"); |
| 3115 | var type = parseValueTypeDefinition(typeDefinition); |
| 3116 | return { |
| 3117 | type: type, |
| 3118 | key: key, |
| 3119 | name: camelize(key), |
| 3120 | get defaultValue () { |
| 3121 | return defaultValueForDefinition(typeDefinition); |
| 3122 | }, |
| 3123 | get hasCustomDefaultValue () { |
| 3124 | return parseValueTypeDefault(typeDefinition) !== undefined; |
| 3125 | }, |
| 3126 | reader: readers[type], |
| 3127 | writer: writers[type] || writers.default |
| 3128 | }; |
| 3129 | } |
| 3130 | var defaultValuesByType = { |
| 3131 | get array () { |
| 3132 | return []; |
| 3133 | }, |
| 3134 | boolean: false, |
| 3135 | number: 0, |
| 3136 | get object () { |
| 3137 | return {}; |
| 3138 | }, |
| 3139 | string: "" |
| 3140 | }; |
| 3141 | var readers = { |
| 3142 | array: function(value) { |
| 3143 | var array = JSON.parse(value); |
| 3144 | if (!Array.isArray(array)) throw new TypeError("Expected array"); |
| 3145 | return array; |
| 3146 | }, |
| 3147 | boolean: function(value) { |
| 3148 | return !(value == "0" || value == "false"); |
| 3149 | }, |
| 3150 | number: function(value) { |
| 3151 | return Number(value); |
| 3152 | }, |
| 3153 | object: function(value) { |
| 3154 | var object = JSON.parse(value); |
| 3155 | if (object === null || typeof object != "object" || Array.isArray(object)) throw new TypeError("Expected object"); |
| 3156 | return object; |
| 3157 | }, |
| 3158 | string: function(value) { |
| 3159 | return value; |
| 3160 | } |
| 3161 | }; |
| 3162 | var writers = { |
| 3163 | default: writeString, |
| 3164 | array: writeJSON, |
| 3165 | object: writeJSON |
| 3166 | }; |
| 3167 | function writeJSON(value) { |
| 3168 | return JSON.stringify(value); |
| 3169 | } |
| 3170 | function writeString(value) { |
| 3171 | return "".concat(value); |
| 3172 | } |
| 3173 | var Controller = /*#__PURE__*/ function() { |
| 3174 | "use strict"; |
| 3175 | function Controller(context) { |
| 3176 | (0, _classCallCheckJsDefault.default)(this, Controller); |
| 3177 | this.context = context; |
| 3178 | } |
| 3179 | (0, _createClassJsDefault.default)(Controller, [ |
| 3180 | { |
| 3181 | key: "application", |
| 3182 | get: function get() { |
| 3183 | return this.context.application; |
| 3184 | } |
| 3185 | }, |
| 3186 | { |
| 3187 | key: "scope", |
| 3188 | get: function get() { |
| 3189 | return this.context.scope; |
| 3190 | } |
| 3191 | }, |
| 3192 | { |
| 3193 | key: "element", |
| 3194 | get: function get() { |
| 3195 | return this.scope.element; |
| 3196 | } |
| 3197 | }, |
| 3198 | { |
| 3199 | key: "identifier", |
| 3200 | get: function get() { |
| 3201 | return this.scope.identifier; |
| 3202 | } |
| 3203 | }, |
| 3204 | { |
| 3205 | key: "targets", |
| 3206 | get: function get() { |
| 3207 | return this.scope.targets; |
| 3208 | } |
| 3209 | }, |
| 3210 | { |
| 3211 | key: "classes", |
| 3212 | get: function get() { |
| 3213 | return this.scope.classes; |
| 3214 | } |
| 3215 | }, |
| 3216 | { |
| 3217 | key: "data", |
| 3218 | get: function get() { |
| 3219 | return this.scope.data; |
| 3220 | } |
| 3221 | }, |
| 3222 | { |
| 3223 | key: "initialize", |
| 3224 | value: function initialize() {} |
| 3225 | }, |
| 3226 | { |
| 3227 | key: "connect", |
| 3228 | value: function connect() {} |
| 3229 | }, |
| 3230 | { |
| 3231 | key: "disconnect", |
| 3232 | value: function disconnect() {} |
| 3233 | }, |
| 3234 | { |
| 3235 | key: "dispatch", |
| 3236 | value: function dispatch(eventName) { |
| 3237 | var ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _target = ref.target, target = _target === void 0 ? this.element : _target, _detail = ref.detail, detail = _detail === void 0 ? {} : _detail, _prefix = ref.prefix, prefix = _prefix === void 0 ? this.identifier : _prefix, _bubbles = ref.bubbles, bubbles = _bubbles === void 0 ? true : _bubbles, _cancelable = ref.cancelable, cancelable = _cancelable === void 0 ? true : _cancelable; |
| 3238 | var type = prefix ? "".concat(prefix, ":").concat(eventName) : eventName; |
| 3239 | var event = new CustomEvent(type, { |
| 3240 | detail: detail, |
| 3241 | bubbles: bubbles, |
| 3242 | cancelable: cancelable |
| 3243 | }); |
| 3244 | target.dispatchEvent(event); |
| 3245 | return event; |
| 3246 | } |
| 3247 | } |
| 3248 | ], [ |
| 3249 | { |
| 3250 | key: "shouldLoad", |
| 3251 | get: function get() { |
| 3252 | return true; |
| 3253 | } |
| 3254 | } |
| 3255 | ]); |
| 3256 | return Controller; |
| 3257 | }(); |
| 3258 | Controller.blessings = [ |
| 3259 | ClassPropertiesBlessing, |
| 3260 | TargetPropertiesBlessing, |
| 3261 | ValuePropertiesBlessing |
| 3262 | ]; |
| 3263 | Controller.targets = []; |
| 3264 | Controller.values = {}; |
| 3265 | |
| 3266 | },{"@swc/helpers/lib/_async_to_generator.js":"fKf1r","@swc/helpers/lib/_class_call_check.js":"gNxF8","@swc/helpers/lib/_create_class.js":"iyoaN","@swc/helpers/lib/_define_property.js":"6IXzf","@swc/helpers/lib/_get.js":"5g4pb","@swc/helpers/lib/_get_prototype_of.js":"7Gb6H","@swc/helpers/lib/_inherits.js":"atvDk","@swc/helpers/lib/_sliced_to_array.js":"4IWLM","@swc/helpers/lib/_to_consumable_array.js":"cccKv","@swc/helpers/lib/_type_of.js":"9FF45","@swc/helpers/lib/_create_super.js":"5rW3S","regenerator-runtime":"7j2bv","@parcel/transformer-js/src/esmodule-helpers.js":"jIm8e"}],"fKf1r":[function(require,module,exports) { |
| 3267 | "use strict"; |
| 3268 | Object.defineProperty(exports, "__esModule", { |
| 3269 | value: true |
| 3270 | }); |
| 3271 | exports.default = _asyncToGenerator; |
| 3272 | function _asyncToGenerator(fn) { |
| 3273 | return function() { |
| 3274 | var self = this, args = arguments; |
| 3275 | return new Promise(function(resolve, reject) { |
| 3276 | var gen = fn.apply(self, args); |
| 3277 | function _next(value) { |
| 3278 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); |
| 3279 | } |
| 3280 | function _throw(err) { |
| 3281 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); |
| 3282 | } |
| 3283 | _next(undefined); |
| 3284 | }); |
| 3285 | }; |
| 3286 | } |
| 3287 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { |
| 3288 | try { |
| 3289 | var info = gen[key](arg); |
| 3290 | var value = info.value; |
| 3291 | } catch (error) { |
| 3292 | reject(error); |
| 3293 | return; |
| 3294 | } |
| 3295 | if (info.done) resolve(value); |
| 3296 | else Promise.resolve(value).then(_next, _throw); |
| 3297 | } |
| 3298 | |
| 3299 | },{}],"gNxF8":[function(require,module,exports) { |
| 3300 | "use strict"; |
| 3301 | Object.defineProperty(exports, "__esModule", { |
| 3302 | value: true |
| 3303 | }); |
| 3304 | exports.default = _classCallCheck; |
| 3305 | function _classCallCheck(instance, Constructor) { |
| 3306 | if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); |
| 3307 | } |
| 3308 | |
| 3309 | },{}],"iyoaN":[function(require,module,exports) { |
| 3310 | "use strict"; |
| 3311 | Object.defineProperty(exports, "__esModule", { |
| 3312 | value: true |
| 3313 | }); |
| 3314 | exports.default = _createClass; |
| 3315 | function _createClass(Constructor, protoProps, staticProps) { |
| 3316 | if (protoProps) _defineProperties(Constructor.prototype, protoProps); |
| 3317 | if (staticProps) _defineProperties(Constructor, staticProps); |
| 3318 | return Constructor; |
| 3319 | } |
| 3320 | function _defineProperties(target, props) { |
| 3321 | for(var i = 0; i < props.length; i++){ |
| 3322 | var descriptor = props[i]; |
| 3323 | descriptor.enumerable = descriptor.enumerable || false; |
| 3324 | descriptor.configurable = true; |
| 3325 | if ("value" in descriptor) descriptor.writable = true; |
| 3326 | Object.defineProperty(target, descriptor.key, descriptor); |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | },{}],"6IXzf":[function(require,module,exports) { |
| 3331 | "use strict"; |
| 3332 | Object.defineProperty(exports, "__esModule", { |
| 3333 | value: true |
| 3334 | }); |
| 3335 | exports.default = _defineProperty; |
| 3336 | function _defineProperty(obj, key, value) { |
| 3337 | if (key in obj) Object.defineProperty(obj, key, { |
| 3338 | value: value, |
| 3339 | enumerable: true, |
| 3340 | configurable: true, |
| 3341 | writable: true |
| 3342 | }); |
| 3343 | else obj[key] = value; |
| 3344 | return obj; |
| 3345 | } |
| 3346 | |
| 3347 | },{}],"5g4pb":[function(require,module,exports) { |
| 3348 | "use strict"; |
| 3349 | Object.defineProperty(exports, "__esModule", { |
| 3350 | value: true |
| 3351 | }); |
| 3352 | exports.default = _get; |
| 3353 | var _superPropBase = _interopRequireDefault(require("./_super_prop_base")); |
| 3354 | function _get(target, property, receiver) { |
| 3355 | return get(target, property, receiver); |
| 3356 | } |
| 3357 | function _interopRequireDefault(obj) { |
| 3358 | return obj && obj.__esModule ? obj : { |
| 3359 | default: obj |
| 3360 | }; |
| 3361 | } |
| 3362 | function get(target1, property1, receiver1) { |
| 3363 | if (typeof Reflect !== "undefined" && Reflect.get) get = Reflect.get; |
| 3364 | else get = function get(target, property, receiver) { |
| 3365 | var base = _superPropBase.default(target, property); |
| 3366 | if (!base) return; |
| 3367 | var desc = Object.getOwnPropertyDescriptor(base, property); |
| 3368 | if (desc.get) return desc.get.call(receiver || target); |
| 3369 | return desc.value; |
| 3370 | }; |
| 3371 | return get(target1, property1, receiver1); |
| 3372 | } |
| 3373 | |
| 3374 | },{"./_super_prop_base":"cT49D"}],"cT49D":[function(require,module,exports) { |
| 3375 | "use strict"; |
| 3376 | Object.defineProperty(exports, "__esModule", { |
| 3377 | value: true |
| 3378 | }); |
| 3379 | exports.default = _superPropBase; |
| 3380 | var _getPrototypeOf = _interopRequireDefault(require("./_get_prototype_of")); |
| 3381 | function _superPropBase(object, property) { |
| 3382 | while(!Object.prototype.hasOwnProperty.call(object, property)){ |
| 3383 | object = _getPrototypeOf.default(object); |
| 3384 | if (object === null) break; |
| 3385 | } |
| 3386 | return object; |
| 3387 | } |
| 3388 | function _interopRequireDefault(obj) { |
| 3389 | return obj && obj.__esModule ? obj : { |
| 3390 | default: obj |
| 3391 | }; |
| 3392 | } |
| 3393 | |
| 3394 | },{"./_get_prototype_of":"7Gb6H"}],"7Gb6H":[function(require,module,exports) { |
| 3395 | "use strict"; |
| 3396 | Object.defineProperty(exports, "__esModule", { |
| 3397 | value: true |
| 3398 | }); |
| 3399 | exports.default = _getPrototypeOf; |
| 3400 | function _getPrototypeOf(o) { |
| 3401 | return getPrototypeOf(o); |
| 3402 | } |
| 3403 | function getPrototypeOf(o1) { |
| 3404 | getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { |
| 3405 | return o.__proto__ || Object.getPrototypeOf(o); |
| 3406 | }; |
| 3407 | return getPrototypeOf(o1); |
| 3408 | } |
| 3409 | |
| 3410 | },{}],"atvDk":[function(require,module,exports) { |
| 3411 | "use strict"; |
| 3412 | Object.defineProperty(exports, "__esModule", { |
| 3413 | value: true |
| 3414 | }); |
| 3415 | exports.default = _inherits; |
| 3416 | var _setPrototypeOf = _interopRequireDefault(require("./_set_prototype_of")); |
| 3417 | function _inherits(subClass, superClass) { |
| 3418 | if (typeof superClass !== "function" && superClass !== null) throw new TypeError("Super expression must either be null or a function"); |
| 3419 | subClass.prototype = Object.create(superClass && superClass.prototype, { |
| 3420 | constructor: { |
| 3421 | value: subClass, |
| 3422 | writable: true, |
| 3423 | configurable: true |
| 3424 | } |
| 3425 | }); |
| 3426 | if (superClass) _setPrototypeOf.default(subClass, superClass); |
| 3427 | } |
| 3428 | function _interopRequireDefault(obj) { |
| 3429 | return obj && obj.__esModule ? obj : { |
| 3430 | default: obj |
| 3431 | }; |
| 3432 | } |
| 3433 | |
| 3434 | },{"./_set_prototype_of":"1rATD"}],"1rATD":[function(require,module,exports) { |
| 3435 | "use strict"; |
| 3436 | Object.defineProperty(exports, "__esModule", { |
| 3437 | value: true |
| 3438 | }); |
| 3439 | exports.default = _setPrototypeOf; |
| 3440 | function _setPrototypeOf(o, p) { |
| 3441 | return setPrototypeOf(o, p); |
| 3442 | } |
| 3443 | function setPrototypeOf(o1, p1) { |
| 3444 | setPrototypeOf = Object.setPrototypeOf || function setPrototypeOf(o, p) { |
| 3445 | o.__proto__ = p; |
| 3446 | return o; |
| 3447 | }; |
| 3448 | return setPrototypeOf(o1, p1); |
| 3449 | } |
| 3450 | |
| 3451 | },{}],"4IWLM":[function(require,module,exports) { |
| 3452 | "use strict"; |
| 3453 | Object.defineProperty(exports, "__esModule", { |
| 3454 | value: true |
| 3455 | }); |
| 3456 | exports.default = _slicedToArray; |
| 3457 | var _arrayWithHoles = _interopRequireDefault(require("./_array_with_holes")); |
| 3458 | var _iterableToArray = _interopRequireDefault(require("./_iterable_to_array")); |
| 3459 | var _nonIterableRest = _interopRequireDefault(require("./_non_iterable_rest")); |
| 3460 | var _unsupportedIterableToArray = _interopRequireDefault(require("./_unsupported_iterable_to_array")); |
| 3461 | function _slicedToArray(arr, i) { |
| 3462 | return _arrayWithHoles.default(arr) || _iterableToArray.default(arr, i) || _unsupportedIterableToArray.default(arr, i) || _nonIterableRest.default(); |
| 3463 | } |
| 3464 | function _interopRequireDefault(obj) { |
| 3465 | return obj && obj.__esModule ? obj : { |
| 3466 | default: obj |
| 3467 | }; |
| 3468 | } |
| 3469 | |
| 3470 | },{"./_array_with_holes":"kAkr9","./_iterable_to_array":"d0B07","./_non_iterable_rest":"bXNgi","./_unsupported_iterable_to_array":"jhPJb"}],"kAkr9":[function(require,module,exports) { |
| 3471 | "use strict"; |
| 3472 | Object.defineProperty(exports, "__esModule", { |
| 3473 | value: true |
| 3474 | }); |
| 3475 | exports.default = _arrayWithHoles; |
| 3476 | function _arrayWithHoles(arr) { |
| 3477 | if (Array.isArray(arr)) return arr; |
| 3478 | } |
| 3479 | |
| 3480 | },{}],"d0B07":[function(require,module,exports) { |
| 3481 | "use strict"; |
| 3482 | Object.defineProperty(exports, "__esModule", { |
| 3483 | value: true |
| 3484 | }); |
| 3485 | exports.default = _iterableToArray; |
| 3486 | function _iterableToArray(iter) { |
| 3487 | if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); |
| 3488 | } |
| 3489 | |
| 3490 | },{}],"bXNgi":[function(require,module,exports) { |
| 3491 | "use strict"; |
| 3492 | Object.defineProperty(exports, "__esModule", { |
| 3493 | value: true |
| 3494 | }); |
| 3495 | exports.default = _nonIterableRest; |
| 3496 | function _nonIterableRest() { |
| 3497 | throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
| 3498 | } |
| 3499 | |
| 3500 | },{}],"jhPJb":[function(require,module,exports) { |
| 3501 | "use strict"; |
| 3502 | Object.defineProperty(exports, "__esModule", { |
| 3503 | value: true |
| 3504 | }); |
| 3505 | exports.default = _unsupportedIterableToArray; |
| 3506 | var _arrayLikeToArray = _interopRequireDefault(require("./_array_like_to_array")); |
| 3507 | function _unsupportedIterableToArray(o, minLen) { |
| 3508 | if (!o) return; |
| 3509 | if (typeof o === "string") return _arrayLikeToArray.default(o, minLen); |
| 3510 | var n = Object.prototype.toString.call(o).slice(8, -1); |
| 3511 | if (n === "Object" && o.constructor) n = o.constructor.name; |
| 3512 | if (n === "Map" || n === "Set") return Array.from(n); |
| 3513 | if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray.default(o, minLen); |
| 3514 | } |
| 3515 | function _interopRequireDefault(obj) { |
| 3516 | return obj && obj.__esModule ? obj : { |
| 3517 | default: obj |
| 3518 | }; |
| 3519 | } |
| 3520 | |
| 3521 | },{"./_array_like_to_array":"4K9fh"}],"4K9fh":[function(require,module,exports) { |
| 3522 | "use strict"; |
| 3523 | Object.defineProperty(exports, "__esModule", { |
| 3524 | value: true |
| 3525 | }); |
| 3526 | exports.default = _arrayLikeToArray; |
| 3527 | function _arrayLikeToArray(arr, len) { |
| 3528 | if (len == null || len > arr.length) len = arr.length; |
| 3529 | for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; |
| 3530 | return arr2; |
| 3531 | } |
| 3532 | |
| 3533 | },{}],"cccKv":[function(require,module,exports) { |
| 3534 | "use strict"; |
| 3535 | Object.defineProperty(exports, "__esModule", { |
| 3536 | value: true |
| 3537 | }); |
| 3538 | exports.default = _toConsumableArray; |
| 3539 | var _arrayWithoutHoles = _interopRequireDefault(require("./_array_without_holes")); |
| 3540 | var _iterableToArray = _interopRequireDefault(require("./_iterable_to_array")); |
| 3541 | var _nonIterableSpread = _interopRequireDefault(require("./_non_iterable_spread")); |
| 3542 | var _unsupportedIterableToArray = _interopRequireDefault(require("./_unsupported_iterable_to_array")); |
| 3543 | function _toConsumableArray(arr) { |
| 3544 | return _arrayWithoutHoles.default(arr) || _iterableToArray.default(arr) || _unsupportedIterableToArray.default(arr) || _nonIterableSpread.default(); |
| 3545 | } |
| 3546 | function _interopRequireDefault(obj) { |
| 3547 | return obj && obj.__esModule ? obj : { |
| 3548 | default: obj |
| 3549 | }; |
| 3550 | } |
| 3551 | |
| 3552 | },{"./_array_without_holes":"26osg","./_iterable_to_array":"d0B07","./_non_iterable_spread":"nlNPL","./_unsupported_iterable_to_array":"jhPJb"}],"26osg":[function(require,module,exports) { |
| 3553 | "use strict"; |
| 3554 | Object.defineProperty(exports, "__esModule", { |
| 3555 | value: true |
| 3556 | }); |
| 3557 | exports.default = _arrayWithoutHoles; |
| 3558 | var _arrayLikeToArray = _interopRequireDefault(require("./_array_like_to_array")); |
| 3559 | function _arrayWithoutHoles(arr) { |
| 3560 | if (Array.isArray(arr)) return _arrayLikeToArray.default(arr); |
| 3561 | } |
| 3562 | function _interopRequireDefault(obj) { |
| 3563 | return obj && obj.__esModule ? obj : { |
| 3564 | default: obj |
| 3565 | }; |
| 3566 | } |
| 3567 | |
| 3568 | },{"./_array_like_to_array":"4K9fh"}],"nlNPL":[function(require,module,exports) { |
| 3569 | "use strict"; |
| 3570 | Object.defineProperty(exports, "__esModule", { |
| 3571 | value: true |
| 3572 | }); |
| 3573 | exports.default = _nonIterableSpread; |
| 3574 | function _nonIterableSpread() { |
| 3575 | throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
| 3576 | } |
| 3577 | |
| 3578 | },{}],"9FF45":[function(require,module,exports) { |
| 3579 | "use strict"; |
| 3580 | Object.defineProperty(exports, "__esModule", { |
| 3581 | value: true |
| 3582 | }); |
| 3583 | exports.default = _typeof; |
| 3584 | function _typeof(obj) { |
| 3585 | "@swc/helpers - typeof"; |
| 3586 | return obj && obj.constructor === Symbol ? "symbol" : typeof obj; |
| 3587 | } |
| 3588 | |
| 3589 | },{}],"5rW3S":[function(require,module,exports) { |
| 3590 | "use strict"; |
| 3591 | Object.defineProperty(exports, "__esModule", { |
| 3592 | value: true |
| 3593 | }); |
| 3594 | exports.default = _createSuper; |
| 3595 | var _isNativeReflectConstruct = _interopRequireDefault(require("./_is_native_reflect_construct")); |
| 3596 | var _getPrototypeOf = _interopRequireDefault(require("./_get_prototype_of")); |
| 3597 | var _possibleConstructorReturn = _interopRequireDefault(require("./_possible_constructor_return")); |
| 3598 | function _createSuper(Derived) { |
| 3599 | var hasNativeReflectConstruct = _isNativeReflectConstruct.default(); |
| 3600 | return function _createSuperInternal() { |
| 3601 | var Super = _getPrototypeOf.default(Derived), result; |
| 3602 | if (hasNativeReflectConstruct) { |
| 3603 | var NewTarget = _getPrototypeOf.default(this).constructor; |
| 3604 | result = Reflect.construct(Super, arguments, NewTarget); |
| 3605 | } else result = Super.apply(this, arguments); |
| 3606 | return _possibleConstructorReturn.default(this, result); |
| 3607 | }; |
| 3608 | } |
| 3609 | function _interopRequireDefault(obj) { |
| 3610 | return obj && obj.__esModule ? obj : { |
| 3611 | default: obj |
| 3612 | }; |
| 3613 | } |
| 3614 | |
| 3615 | },{"./_is_native_reflect_construct":"aPH71","./_get_prototype_of":"7Gb6H","./_possible_constructor_return":"hAvqf"}],"aPH71":[function(require,module,exports) { |
| 3616 | "use strict"; |
| 3617 | Object.defineProperty(exports, "__esModule", { |
| 3618 | value: true |
| 3619 | }); |
| 3620 | exports.default = _isNativeReflectConstruct; |
| 3621 | function _isNativeReflectConstruct() { |
| 3622 | if (typeof Reflect === "undefined" || !Reflect.construct) return false; |
| 3623 | if (Reflect.construct.sham) return false; |
| 3624 | if (typeof Proxy === "function") return true; |
| 3625 | try { |
| 3626 | Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); |
| 3627 | return true; |
| 3628 | } catch (e) { |
| 3629 | return false; |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | },{}],"hAvqf":[function(require,module,exports) { |
| 3634 | "use strict"; |
| 3635 | Object.defineProperty(exports, "__esModule", { |
| 3636 | value: true |
| 3637 | }); |
| 3638 | exports.default = _possibleConstructorReturn; |
| 3639 | var _assertThisInitialized = _interopRequireDefault(require("./_assert_this_initialized")); |
| 3640 | var _typeOf = _interopRequireDefault(require("./_type_of")); |
| 3641 | function _possibleConstructorReturn(self, call) { |
| 3642 | if (call && (_typeOf.default(call) === "object" || typeof call === "function")) return call; |
| 3643 | return _assertThisInitialized.default(self); |
| 3644 | } |
| 3645 | function _interopRequireDefault(obj) { |
| 3646 | return obj && obj.__esModule ? obj : { |
| 3647 | default: obj |
| 3648 | }; |
| 3649 | } |
| 3650 | |
| 3651 | },{"./_assert_this_initialized":"l7nF8","./_type_of":"9FF45"}],"l7nF8":[function(require,module,exports) { |
| 3652 | "use strict"; |
| 3653 | Object.defineProperty(exports, "__esModule", { |
| 3654 | value: true |
| 3655 | }); |
| 3656 | exports.default = _assertThisInitialized; |
| 3657 | function _assertThisInitialized(self) { |
| 3658 | if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); |
| 3659 | return self; |
| 3660 | } |
| 3661 | |
| 3662 | },{}],"7j2bv":[function(require,module,exports) { |
| 3663 | /** |
| 3664 | * Copyright (c) 2014-present, Facebook, Inc. |
| 3665 | * |
| 3666 | * This source code is licensed under the MIT license found in the |
| 3667 | * LICENSE file in the root directory of this source tree. |
| 3668 | */ var runtime = function(exports) { |
| 3669 | "use strict"; |
| 3670 | var Op = Object.prototype; |
| 3671 | var hasOwn = Op.hasOwnProperty; |
| 3672 | var undefined; // More compressible than void 0. |
| 3673 | var $Symbol = typeof Symbol === "function" ? Symbol : {}; |
| 3674 | var iteratorSymbol = $Symbol.iterator || "@@iterator"; |
| 3675 | var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; |
| 3676 | var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; |
| 3677 | function define(obj, key, value) { |
| 3678 | Object.defineProperty(obj, key, { |
| 3679 | value: value, |
| 3680 | enumerable: true, |
| 3681 | configurable: true, |
| 3682 | writable: true |
| 3683 | }); |
| 3684 | return obj[key]; |
| 3685 | } |
| 3686 | try { |
| 3687 | // IE 8 has a broken Object.defineProperty that only works on DOM objects. |
| 3688 | define({}, ""); |
| 3689 | } catch (err1) { |
| 3690 | define = function define(obj, key, value) { |
| 3691 | return obj[key] = value; |
| 3692 | }; |
| 3693 | } |
| 3694 | function wrap(innerFn, outerFn, self, tryLocsList) { |
| 3695 | // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. |
| 3696 | var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; |
| 3697 | var generator = Object.create(protoGenerator.prototype); |
| 3698 | var context = new Context(tryLocsList || []); |
| 3699 | // The ._invoke method unifies the implementations of the .next, |
| 3700 | // .throw, and .return methods. |
| 3701 | generator._invoke = makeInvokeMethod(innerFn, self, context); |
| 3702 | return generator; |
| 3703 | } |
| 3704 | exports.wrap = wrap; |
| 3705 | // Try/catch helper to minimize deoptimizations. Returns a completion |
| 3706 | // record like context.tryEntries[i].completion. This interface could |
| 3707 | // have been (and was previously) designed to take a closure to be |
| 3708 | // invoked without arguments, but in all the cases we care about we |
| 3709 | // already have an existing method we want to call, so there's no need |
| 3710 | // to create a new function object. We can even get away with assuming |
| 3711 | // the method takes exactly one argument, since that happens to be true |
| 3712 | // in every case, so we don't have to touch the arguments object. The |
| 3713 | // only additional allocation required is the completion record, which |
| 3714 | // has a stable shape and so hopefully should be cheap to allocate. |
| 3715 | function tryCatch(fn, obj, arg) { |
| 3716 | try { |
| 3717 | return { |
| 3718 | type: "normal", |
| 3719 | arg: fn.call(obj, arg) |
| 3720 | }; |
| 3721 | } catch (err) { |
| 3722 | return { |
| 3723 | type: "throw", |
| 3724 | arg: err |
| 3725 | }; |
| 3726 | } |
| 3727 | } |
| 3728 | var GenStateSuspendedStart = "suspendedStart"; |
| 3729 | var GenStateSuspendedYield = "suspendedYield"; |
| 3730 | var GenStateExecuting = "executing"; |
| 3731 | var GenStateCompleted = "completed"; |
| 3732 | // Returning this object from the innerFn has the same effect as |
| 3733 | // breaking out of the dispatch switch statement. |
| 3734 | var ContinueSentinel = {}; |
| 3735 | // Dummy constructor functions that we use as the .constructor and |
| 3736 | // .constructor.prototype properties for functions that return Generator |
| 3737 | // objects. For full spec compliance, you may wish to configure your |
| 3738 | // minifier not to mangle the names of these two functions. |
| 3739 | function Generator() {} |
| 3740 | function GeneratorFunction() {} |
| 3741 | function GeneratorFunctionPrototype() {} |
| 3742 | // This is a polyfill for %IteratorPrototype% for environments that |
| 3743 | // don't natively support it. |
| 3744 | var IteratorPrototype = {}; |
| 3745 | define(IteratorPrototype, iteratorSymbol, function() { |
| 3746 | return this; |
| 3747 | }); |
| 3748 | var getProto = Object.getPrototypeOf; |
| 3749 | var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); |
| 3750 | if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) // This environment has a native %IteratorPrototype%; use it instead |
| 3751 | // of the polyfill. |
| 3752 | IteratorPrototype = NativeIteratorPrototype; |
| 3753 | var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); |
| 3754 | GeneratorFunction.prototype = GeneratorFunctionPrototype; |
| 3755 | define(Gp, "constructor", GeneratorFunctionPrototype); |
| 3756 | define(GeneratorFunctionPrototype, "constructor", GeneratorFunction); |
| 3757 | GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); |
| 3758 | // Helper for defining the .next, .throw, and .return methods of the |
| 3759 | // Iterator interface in terms of a single ._invoke method. |
| 3760 | function defineIteratorMethods(prototype) { |
| 3761 | [ |
| 3762 | "next", |
| 3763 | "throw", |
| 3764 | "return" |
| 3765 | ].forEach(function(method) { |
| 3766 | define(prototype, method, function(arg) { |
| 3767 | return this._invoke(method, arg); |
| 3768 | }); |
| 3769 | }); |
| 3770 | } |
| 3771 | exports.isGeneratorFunction = function(genFun) { |
| 3772 | var ctor = typeof genFun === "function" && genFun.constructor; |
| 3773 | return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can |
| 3774 | // do is to check its .name property. |
| 3775 | (ctor.displayName || ctor.name) === "GeneratorFunction" : false; |
| 3776 | }; |
| 3777 | exports.mark = function(genFun) { |
| 3778 | if (Object.setPrototypeOf) Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); |
| 3779 | else { |
| 3780 | genFun.__proto__ = GeneratorFunctionPrototype; |
| 3781 | define(genFun, toStringTagSymbol, "GeneratorFunction"); |
| 3782 | } |
| 3783 | genFun.prototype = Object.create(Gp); |
| 3784 | return genFun; |
| 3785 | }; |
| 3786 | // Within the body of any async function, `await x` is transformed to |
| 3787 | // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test |
| 3788 | // `hasOwn.call(value, "__await")` to determine if the yielded value is |
| 3789 | // meant to be awaited. |
| 3790 | exports.awrap = function(arg) { |
| 3791 | return { |
| 3792 | __await: arg |
| 3793 | }; |
| 3794 | }; |
| 3795 | function AsyncIterator(generator, PromiseImpl) { |
| 3796 | function invoke(method, arg, resolve, reject) { |
| 3797 | var record = tryCatch(generator[method], generator, arg); |
| 3798 | if (record.type === "throw") reject(record.arg); |
| 3799 | else { |
| 3800 | var result = record.arg; |
| 3801 | var value1 = result.value; |
| 3802 | if (value1 && typeof value1 === "object" && hasOwn.call(value1, "__await")) return PromiseImpl.resolve(value1.__await).then(function(value) { |
| 3803 | invoke("next", value, resolve, reject); |
| 3804 | }, function(err) { |
| 3805 | invoke("throw", err, resolve, reject); |
| 3806 | }); |
| 3807 | return PromiseImpl.resolve(value1).then(function(unwrapped) { |
| 3808 | // When a yielded Promise is resolved, its final value becomes |
| 3809 | // the .value of the Promise<{value,done}> result for the |
| 3810 | // current iteration. |
| 3811 | result.value = unwrapped; |
| 3812 | resolve(result); |
| 3813 | }, function(error) { |
| 3814 | // If a rejected Promise was yielded, throw the rejection back |
| 3815 | // into the async generator function so it can be handled there. |
| 3816 | return invoke("throw", error, resolve, reject); |
| 3817 | }); |
| 3818 | } |
| 3819 | } |
| 3820 | var previousPromise; |
| 3821 | function enqueue(method, arg) { |
| 3822 | function callInvokeWithMethodAndArg() { |
| 3823 | return new PromiseImpl(function(resolve, reject) { |
| 3824 | invoke(method, arg, resolve, reject); |
| 3825 | }); |
| 3826 | } |
| 3827 | return previousPromise = // If enqueue has been called before, then we want to wait until |
| 3828 | // all previous Promises have been resolved before calling invoke, |
| 3829 | // so that results are always delivered in the correct order. If |
| 3830 | // enqueue has not been called before, then it is important to |
| 3831 | // call invoke immediately, without waiting on a callback to fire, |
| 3832 | // so that the async generator function has the opportunity to do |
| 3833 | // any necessary setup in a predictable way. This predictability |
| 3834 | // is why the Promise constructor synchronously invokes its |
| 3835 | // executor callback, and why async functions synchronously |
| 3836 | // execute code before the first await. Since we implement simple |
| 3837 | // async functions in terms of async generators, it is especially |
| 3838 | // important to get this right, even though it requires care. |
| 3839 | previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later |
| 3840 | // invocations of the iterator. |
| 3841 | callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); |
| 3842 | } |
| 3843 | // Define the unified helper method that is used to implement .next, |
| 3844 | // .throw, and .return (see defineIteratorMethods). |
| 3845 | this._invoke = enqueue; |
| 3846 | } |
| 3847 | defineIteratorMethods(AsyncIterator.prototype); |
| 3848 | define(AsyncIterator.prototype, asyncIteratorSymbol, function() { |
| 3849 | return this; |
| 3850 | }); |
| 3851 | exports.AsyncIterator = AsyncIterator; |
| 3852 | // Note that simple async functions are implemented on top of |
| 3853 | // AsyncIterator objects; they just return a Promise for the value of |
| 3854 | // the final result produced by the iterator. |
| 3855 | exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) { |
| 3856 | if (PromiseImpl === void 0) PromiseImpl = Promise; |
| 3857 | var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); |
| 3858 | return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator. |
| 3859 | : iter.next().then(function(result) { |
| 3860 | return result.done ? result.value : iter.next(); |
| 3861 | }); |
| 3862 | }; |
| 3863 | function makeInvokeMethod(innerFn, self, context) { |
| 3864 | var state = GenStateSuspendedStart; |
| 3865 | return function invoke(method, arg) { |
| 3866 | if (state === GenStateExecuting) throw new Error("Generator is already running"); |
| 3867 | if (state === GenStateCompleted) { |
| 3868 | if (method === "throw") throw arg; |
| 3869 | // Be forgiving, per 25.3.3.3.3 of the spec: |
| 3870 | // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume |
| 3871 | return doneResult(); |
| 3872 | } |
| 3873 | context.method = method; |
| 3874 | context.arg = arg; |
| 3875 | while(true){ |
| 3876 | var delegate = context.delegate; |
| 3877 | if (delegate) { |
| 3878 | var delegateResult = maybeInvokeDelegate(delegate, context); |
| 3879 | if (delegateResult) { |
| 3880 | if (delegateResult === ContinueSentinel) continue; |
| 3881 | return delegateResult; |
| 3882 | } |
| 3883 | } |
| 3884 | if (context.method === "next") // Setting context._sent for legacy support of Babel's |
| 3885 | // function.sent implementation. |
| 3886 | context.sent = context._sent = context.arg; |
| 3887 | else if (context.method === "throw") { |
| 3888 | if (state === GenStateSuspendedStart) { |
| 3889 | state = GenStateCompleted; |
| 3890 | throw context.arg; |
| 3891 | } |
| 3892 | context.dispatchException(context.arg); |
| 3893 | } else if (context.method === "return") context.abrupt("return", context.arg); |
| 3894 | state = GenStateExecuting; |
| 3895 | var record = tryCatch(innerFn, self, context); |
| 3896 | if (record.type === "normal") { |
| 3897 | // If an exception is thrown from innerFn, we leave state === |
| 3898 | // GenStateExecuting and loop back for another invocation. |
| 3899 | state = context.done ? GenStateCompleted : GenStateSuspendedYield; |
| 3900 | if (record.arg === ContinueSentinel) continue; |
| 3901 | return { |
| 3902 | value: record.arg, |
| 3903 | done: context.done |
| 3904 | }; |
| 3905 | } else if (record.type === "throw") { |
| 3906 | state = GenStateCompleted; |
| 3907 | // Dispatch the exception by looping back around to the |
| 3908 | // context.dispatchException(context.arg) call above. |
| 3909 | context.method = "throw"; |
| 3910 | context.arg = record.arg; |
| 3911 | } |
| 3912 | } |
| 3913 | }; |
| 3914 | } |
| 3915 | // Call delegate.iterator[context.method](context.arg) and handle the |
| 3916 | // result, either by returning a { value, done } result from the |
| 3917 | // delegate iterator, or by modifying context.method and context.arg, |
| 3918 | // setting context.delegate to null, and returning the ContinueSentinel. |
| 3919 | function maybeInvokeDelegate(delegate, context) { |
| 3920 | var method = delegate.iterator[context.method]; |
| 3921 | if (method === undefined) { |
| 3922 | // A .throw or .return when the delegate iterator has no .throw |
| 3923 | // method always terminates the yield* loop. |
| 3924 | context.delegate = null; |
| 3925 | if (context.method === "throw") { |
| 3926 | // Note: ["return"] must be used for ES3 parsing compatibility. |
| 3927 | if (delegate.iterator["return"]) { |
| 3928 | // If the delegate iterator has a return method, give it a |
| 3929 | // chance to clean up. |
| 3930 | context.method = "return"; |
| 3931 | context.arg = undefined; |
| 3932 | maybeInvokeDelegate(delegate, context); |
| 3933 | if (context.method === "throw") // If maybeInvokeDelegate(context) changed context.method from |
| 3934 | // "return" to "throw", let that override the TypeError below. |
| 3935 | return ContinueSentinel; |
| 3936 | } |
| 3937 | context.method = "throw"; |
| 3938 | context.arg = new TypeError("The iterator does not provide a 'throw' method"); |
| 3939 | } |
| 3940 | return ContinueSentinel; |
| 3941 | } |
| 3942 | var record = tryCatch(method, delegate.iterator, context.arg); |
| 3943 | if (record.type === "throw") { |
| 3944 | context.method = "throw"; |
| 3945 | context.arg = record.arg; |
| 3946 | context.delegate = null; |
| 3947 | return ContinueSentinel; |
| 3948 | } |
| 3949 | var info = record.arg; |
| 3950 | if (!info) { |
| 3951 | context.method = "throw"; |
| 3952 | context.arg = new TypeError("iterator result is not an object"); |
| 3953 | context.delegate = null; |
| 3954 | return ContinueSentinel; |
| 3955 | } |
| 3956 | if (info.done) { |
| 3957 | // Assign the result of the finished delegate to the temporary |
| 3958 | // variable specified by delegate.resultName (see delegateYield). |
| 3959 | context[delegate.resultName] = info.value; |
| 3960 | // Resume execution at the desired location (see delegateYield). |
| 3961 | context.next = delegate.nextLoc; |
| 3962 | // If context.method was "throw" but the delegate handled the |
| 3963 | // exception, let the outer generator proceed normally. If |
| 3964 | // context.method was "next", forget context.arg since it has been |
| 3965 | // "consumed" by the delegate iterator. If context.method was |
| 3966 | // "return", allow the original .return call to continue in the |
| 3967 | // outer generator. |
| 3968 | if (context.method !== "return") { |
| 3969 | context.method = "next"; |
| 3970 | context.arg = undefined; |
| 3971 | } |
| 3972 | } else // Re-yield the result returned by the delegate method. |
| 3973 | return info; |
| 3974 | // The delegate iterator is finished, so forget it and continue with |
| 3975 | // the outer generator. |
| 3976 | context.delegate = null; |
| 3977 | return ContinueSentinel; |
| 3978 | } |
| 3979 | // Define Generator.prototype.{next,throw,return} in terms of the |
| 3980 | // unified ._invoke helper method. |
| 3981 | defineIteratorMethods(Gp); |
| 3982 | define(Gp, toStringTagSymbol, "Generator"); |
| 3983 | // A Generator should always return itself as the iterator object when the |
| 3984 | // @@iterator function is called on it. Some browsers' implementations of the |
| 3985 | // iterator prototype chain incorrectly implement this, causing the Generator |
| 3986 | // object to not be returned from this call. This ensures that doesn't happen. |
| 3987 | // See https://github.com/facebook/regenerator/issues/274 for more details. |
| 3988 | define(Gp, iteratorSymbol, function() { |
| 3989 | return this; |
| 3990 | }); |
| 3991 | define(Gp, "toString", function() { |
| 3992 | return "[object Generator]"; |
| 3993 | }); |
| 3994 | function pushTryEntry(locs) { |
| 3995 | var entry = { |
| 3996 | tryLoc: locs[0] |
| 3997 | }; |
| 3998 | if (1 in locs) entry.catchLoc = locs[1]; |
| 3999 | if (2 in locs) { |
| 4000 | entry.finallyLoc = locs[2]; |
| 4001 | entry.afterLoc = locs[3]; |
| 4002 | } |
| 4003 | this.tryEntries.push(entry); |
| 4004 | } |
| 4005 | function resetTryEntry(entry) { |
| 4006 | var record = entry.completion || {}; |
| 4007 | record.type = "normal"; |
| 4008 | delete record.arg; |
| 4009 | entry.completion = record; |
| 4010 | } |
| 4011 | function Context(tryLocsList) { |
| 4012 | // The root entry object (effectively a try statement without a catch |
| 4013 | // or a finally block) gives us a place to store values thrown from |
| 4014 | // locations where there is no enclosing try statement. |
| 4015 | this.tryEntries = [ |
| 4016 | { |
| 4017 | tryLoc: "root" |
| 4018 | } |
| 4019 | ]; |
| 4020 | tryLocsList.forEach(pushTryEntry, this); |
| 4021 | this.reset(true); |
| 4022 | } |
| 4023 | exports.keys = function(object) { |
| 4024 | var keys = []; |
| 4025 | for(var key1 in object)keys.push(key1); |
| 4026 | keys.reverse(); |
| 4027 | // Rather than returning an object with a next method, we keep |
| 4028 | // things simple and return the next function itself. |
| 4029 | return function next() { |
| 4030 | while(keys.length){ |
| 4031 | var key = keys.pop(); |
| 4032 | if (key in object) { |
| 4033 | next.value = key; |
| 4034 | next.done = false; |
| 4035 | return next; |
| 4036 | } |
| 4037 | } |
| 4038 | // To avoid creating an additional object, we just hang the .value |
| 4039 | // and .done properties off the next function object itself. This |
| 4040 | // also ensures that the minifier will not anonymize the function. |
| 4041 | next.done = true; |
| 4042 | return next; |
| 4043 | }; |
| 4044 | }; |
| 4045 | function values(iterable) { |
| 4046 | if (iterable) { |
| 4047 | var iteratorMethod = iterable[iteratorSymbol]; |
| 4048 | if (iteratorMethod) return iteratorMethod.call(iterable); |
| 4049 | if (typeof iterable.next === "function") return iterable; |
| 4050 | if (!isNaN(iterable.length)) { |
| 4051 | var i = -1, next1 = function next() { |
| 4052 | while(++i < iterable.length)if (hasOwn.call(iterable, i)) { |
| 4053 | next.value = iterable[i]; |
| 4054 | next.done = false; |
| 4055 | return next; |
| 4056 | } |
| 4057 | next.value = undefined; |
| 4058 | next.done = true; |
| 4059 | return next; |
| 4060 | }; |
| 4061 | return next1.next = next1; |
| 4062 | } |
| 4063 | } |
| 4064 | // Return an iterator with no values. |
| 4065 | return { |
| 4066 | next: doneResult |
| 4067 | }; |
| 4068 | } |
| 4069 | exports.values = values; |
| 4070 | function doneResult() { |
| 4071 | return { |
| 4072 | value: undefined, |
| 4073 | done: true |
| 4074 | }; |
| 4075 | } |
| 4076 | Context.prototype = { |
| 4077 | constructor: Context, |
| 4078 | reset: function reset(skipTempReset) { |
| 4079 | this.prev = 0; |
| 4080 | this.next = 0; |
| 4081 | // Resetting context._sent for legacy support of Babel's |
| 4082 | // function.sent implementation. |
| 4083 | this.sent = this._sent = undefined; |
| 4084 | this.done = false; |
| 4085 | this.delegate = null; |
| 4086 | this.method = "next"; |
| 4087 | this.arg = undefined; |
| 4088 | this.tryEntries.forEach(resetTryEntry); |
| 4089 | if (!skipTempReset) { |
| 4090 | for(var name in this)// Not sure about the optimal order of these conditions: |
| 4091 | if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) this[name] = undefined; |
| 4092 | } |
| 4093 | }, |
| 4094 | stop: function stop() { |
| 4095 | this.done = true; |
| 4096 | var rootEntry = this.tryEntries[0]; |
| 4097 | var rootRecord = rootEntry.completion; |
| 4098 | if (rootRecord.type === "throw") throw rootRecord.arg; |
| 4099 | return this.rval; |
| 4100 | }, |
| 4101 | dispatchException: function dispatchException(exception) { |
| 4102 | if (this.done) throw exception; |
| 4103 | var context = this; |
| 4104 | function handle(loc, caught) { |
| 4105 | record.type = "throw"; |
| 4106 | record.arg = exception; |
| 4107 | context.next = loc; |
| 4108 | if (caught) { |
| 4109 | // If the dispatched exception was caught by a catch block, |
| 4110 | // then let that catch block handle the exception normally. |
| 4111 | context.method = "next"; |
| 4112 | context.arg = undefined; |
| 4113 | } |
| 4114 | return !!caught; |
| 4115 | } |
| 4116 | for(var i = this.tryEntries.length - 1; i >= 0; --i){ |
| 4117 | var entry = this.tryEntries[i]; |
| 4118 | var record = entry.completion; |
| 4119 | if (entry.tryLoc === "root") // Exception thrown outside of any try block that could handle |
| 4120 | // it, so set the completion value of the entire function to |
| 4121 | // throw the exception. |
| 4122 | return handle("end"); |
| 4123 | if (entry.tryLoc <= this.prev) { |
| 4124 | var hasCatch = hasOwn.call(entry, "catchLoc"); |
| 4125 | var hasFinally = hasOwn.call(entry, "finallyLoc"); |
| 4126 | if (hasCatch && hasFinally) { |
| 4127 | if (this.prev < entry.catchLoc) return handle(entry.catchLoc, true); |
| 4128 | else if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); |
| 4129 | } else if (hasCatch) { |
| 4130 | if (this.prev < entry.catchLoc) return handle(entry.catchLoc, true); |
| 4131 | } else if (hasFinally) { |
| 4132 | if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); |
| 4133 | } else throw new Error("try statement without catch or finally"); |
| 4134 | } |
| 4135 | } |
| 4136 | }, |
| 4137 | abrupt: function abrupt(type, arg) { |
| 4138 | for(var i = this.tryEntries.length - 1; i >= 0; --i){ |
| 4139 | var entry = this.tryEntries[i]; |
| 4140 | if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { |
| 4141 | var finallyEntry = entry; |
| 4142 | break; |
| 4143 | } |
| 4144 | } |
| 4145 | if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) // Ignore the finally entry if control is not jumping to a |
| 4146 | // location outside the try/catch block. |
| 4147 | finallyEntry = null; |
| 4148 | var record = finallyEntry ? finallyEntry.completion : {}; |
| 4149 | record.type = type; |
| 4150 | record.arg = arg; |
| 4151 | if (finallyEntry) { |
| 4152 | this.method = "next"; |
| 4153 | this.next = finallyEntry.finallyLoc; |
| 4154 | return ContinueSentinel; |
| 4155 | } |
| 4156 | return this.complete(record); |
| 4157 | }, |
| 4158 | complete: function complete(record, afterLoc) { |
| 4159 | if (record.type === "throw") throw record.arg; |
| 4160 | if (record.type === "break" || record.type === "continue") this.next = record.arg; |
| 4161 | else if (record.type === "return") { |
| 4162 | this.rval = this.arg = record.arg; |
| 4163 | this.method = "return"; |
| 4164 | this.next = "end"; |
| 4165 | } else if (record.type === "normal" && afterLoc) this.next = afterLoc; |
| 4166 | return ContinueSentinel; |
| 4167 | }, |
| 4168 | finish: function finish(finallyLoc) { |
| 4169 | for(var i = this.tryEntries.length - 1; i >= 0; --i){ |
| 4170 | var entry = this.tryEntries[i]; |
| 4171 | if (entry.finallyLoc === finallyLoc) { |
| 4172 | this.complete(entry.completion, entry.afterLoc); |
| 4173 | resetTryEntry(entry); |
| 4174 | return ContinueSentinel; |
| 4175 | } |
| 4176 | } |
| 4177 | }, |
| 4178 | "catch": function(tryLoc) { |
| 4179 | for(var i = this.tryEntries.length - 1; i >= 0; --i){ |
| 4180 | var entry = this.tryEntries[i]; |
| 4181 | if (entry.tryLoc === tryLoc) { |
| 4182 | var record = entry.completion; |
| 4183 | if (record.type === "throw") { |
| 4184 | var thrown = record.arg; |
| 4185 | resetTryEntry(entry); |
| 4186 | } |
| 4187 | return thrown; |
| 4188 | } |
| 4189 | } |
| 4190 | // The context.catch method must only be called with a location |
| 4191 | // argument that corresponds to a known catch block. |
| 4192 | throw new Error("illegal catch attempt"); |
| 4193 | }, |
| 4194 | delegateYield: function delegateYield(iterable, resultName, nextLoc) { |
| 4195 | this.delegate = { |
| 4196 | iterator: values(iterable), |
| 4197 | resultName: resultName, |
| 4198 | nextLoc: nextLoc |
| 4199 | }; |
| 4200 | if (this.method === "next") // Deliberately forget the last sent value so that we don't |
| 4201 | // accidentally pass it on to the delegate. |
| 4202 | this.arg = undefined; |
| 4203 | return ContinueSentinel; |
| 4204 | } |
| 4205 | }; |
| 4206 | // Regardless of whether this script is executing as a CommonJS module |
| 4207 | // or not, return the runtime object so that we can declare the variable |
| 4208 | // regeneratorRuntime in the outer scope, which allows this module to be |
| 4209 | // injected easily by `bin/regenerator --include-runtime script.js`. |
| 4210 | return exports; |
| 4211 | }(module.exports); |
| 4212 | try { |
| 4213 | regeneratorRuntime = runtime; |
| 4214 | } catch (accidentalStrictMode) { |
| 4215 | // This module should not be running in strict mode, so the above |
| 4216 | // assignment should always work unless something is misconfigured. Just |
| 4217 | // in case runtime.js accidentally runs in strict mode, in modern engines |
| 4218 | // we can explicitly access globalThis. In older engines we can escape |
| 4219 | // strict mode using a global Function call. This could conceivably fail |
| 4220 | // if a Content Security Policy forbids using Function, but in that case |
| 4221 | // the proper solution is to fix the accidental strict mode problem. If |
| 4222 | // you've misconfigured your bundler to force strict mode and applied a |
| 4223 | // CSP to forbid Function, and you're not willing to fix either of those |
| 4224 | // problems, please detail your unique predicament in a GitHub issue. |
| 4225 | if (typeof globalThis === "object") globalThis.regeneratorRuntime = runtime; |
| 4226 | else Function("r", "regeneratorRuntime = r")(runtime); |
| 4227 | } |
| 4228 | |
| 4229 | },{}],"jIm8e":[function(require,module,exports) { |
| 4230 | exports.interopDefault = function(a) { |
| 4231 | return a && a.__esModule ? a : { |
| 4232 | default: a |
| 4233 | }; |
| 4234 | }; |
| 4235 | exports.defineInteropFlag = function(a) { |
| 4236 | Object.defineProperty(a, "__esModule", { |
| 4237 | value: true |
| 4238 | }); |
| 4239 | }; |
| 4240 | exports.exportAll = function(source, dest) { |
| 4241 | Object.keys(source).forEach(function(key) { |
| 4242 | if (key === "default" || key === "__esModule" || dest.hasOwnProperty(key)) return; |
| 4243 | Object.defineProperty(dest, key, { |
| 4244 | enumerable: true, |
| 4245 | get: function get() { |
| 4246 | return source[key]; |
| 4247 | } |
| 4248 | }); |
| 4249 | }); |
| 4250 | return dest; |
| 4251 | }; |
| 4252 | exports.export = function(dest, destName, get) { |
| 4253 | Object.defineProperty(dest, destName, { |
| 4254 | enumerable: true, |
| 4255 | get: get |
| 4256 | }); |
| 4257 | }; |
| 4258 | |
| 4259 | },{}],"irT0c":[function(require,module,exports) { |
| 4260 | var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); |
| 4261 | parcelHelpers.defineInteropFlag(exports); |
| 4262 | parcelHelpers.export(exports, "default", function() { |
| 4263 | return _class; |
| 4264 | }); |
| 4265 | var _assertThisInitializedJs = require("@swc/helpers/lib/_assert_this_initialized.js"); |
| 4266 | var _assertThisInitializedJsDefault = parcelHelpers.interopDefault(_assertThisInitializedJs); |
| 4267 | var _classCallCheckJs = require("@swc/helpers/lib/_class_call_check.js"); |
| 4268 | var _classCallCheckJsDefault = parcelHelpers.interopDefault(_classCallCheckJs); |
| 4269 | var _createClassJs = require("@swc/helpers/lib/_create_class.js"); |
| 4270 | var _createClassJsDefault = parcelHelpers.interopDefault(_createClassJs); |
| 4271 | var _definePropertyJs = require("@swc/helpers/lib/_define_property.js"); |
| 4272 | var _definePropertyJsDefault = parcelHelpers.interopDefault(_definePropertyJs); |
| 4273 | var _inheritsJs = require("@swc/helpers/lib/_inherits.js"); |
| 4274 | var _inheritsJsDefault = parcelHelpers.interopDefault(_inheritsJs); |
| 4275 | var _toConsumableArrayJs = require("@swc/helpers/lib/_to_consumable_array.js"); |
| 4276 | var _toConsumableArrayJsDefault = parcelHelpers.interopDefault(_toConsumableArrayJs); |
| 4277 | var _createSuperJs = require("@swc/helpers/lib/_create_super.js"); |
| 4278 | var _createSuperJsDefault = parcelHelpers.interopDefault(_createSuperJs); |
| 4279 | var _stimulus = require("@hotwired/stimulus"); |
| 4280 | var _corsairPlugin = require("../chart_plugins/corsair_plugin"); |
| 4281 | var _corsairPluginDefault = parcelHelpers.interopDefault(_corsairPlugin); |
| 4282 | var _htmlLegendPlugin = require("../chart_plugins/html_legend_plugin"); |
| 4283 | var _htmlLegendPluginDefault = parcelHelpers.interopDefault(_htmlLegendPlugin); |
| 4284 | var _chartJs = require("chart.js"); |
| 4285 | var _Chart; |
| 4286 | (_Chart = (0, _chartJs.Chart)).register.apply(_Chart, (0, _toConsumableArrayJsDefault.default)((0, _chartJs.registerables))); |
| 4287 | var _class = /*#__PURE__*/ function(Controller) { |
| 4288 | "use strict"; |
| 4289 | (0, _inheritsJsDefault.default)(_class, Controller); |
| 4290 | var _super = (0, _createSuperJsDefault.default)(_class); |
| 4291 | function _class() { |
| 4292 | (0, _classCallCheckJsDefault.default)(this, _class); |
| 4293 | var _this; |
| 4294 | _this = _super.apply(this, arguments); |
| 4295 | (0, _definePropertyJsDefault.default)((0, _assertThisInitializedJsDefault.default)(_this), "currencyTickText", function(value) { |
| 4296 | return _this.formatCurrency(value); |
| 4297 | }); |
| 4298 | return _this; |
| 4299 | } |
| 4300 | (0, _createClassJsDefault.default)(_class, [ |
| 4301 | { |
| 4302 | key: "locale", |
| 4303 | get: function get() { |
| 4304 | try { |
| 4305 | new Intl.NumberFormat(this.localeValue); |
| 4306 | return this.localeValue; |
| 4307 | } catch (e) { |
| 4308 | return "en-US"; |
| 4309 | } |
| 4310 | } |
| 4311 | }, |
| 4312 | { |
| 4313 | key: "isPreview", |
| 4314 | value: function isPreview() { |
| 4315 | return this.previewValue === true; |
| 4316 | } |
| 4317 | }, |
| 4318 | { |
| 4319 | key: "isUsingWooCommerce", |
| 4320 | value: function isUsingWooCommerce() { |
| 4321 | return this.usingWooCommerceValue === true; |
| 4322 | } |
| 4323 | }, |
| 4324 | { |
| 4325 | key: "formatCurrency", |
| 4326 | value: function formatCurrency(value) { |
| 4327 | return new Intl.NumberFormat(this.localeValue, { |
| 4328 | style: "currency", |
| 4329 | currency: this.currencyValue, |
| 4330 | minimumFractionDigits: 0, |
| 4331 | maximumFractionDigits: 0 |
| 4332 | }).format(value); |
| 4333 | } |
| 4334 | }, |
| 4335 | { |
| 4336 | key: "tooltipTitle", |
| 4337 | value: function tooltipTitle(tooltip) { |
| 4338 | var label = JSON.parse(tooltip[0].label); |
| 4339 | return label.tooltipLabel; |
| 4340 | } |
| 4341 | }, |
| 4342 | { |
| 4343 | key: "tooltipLabel", |
| 4344 | value: function tooltipLabel(tooltip) { |
| 4345 | if (typeof tooltip.dataset.tooltipLabel === "function") return tooltip.dataset.tooltipLabel(tooltip); |
| 4346 | return tooltip.dataset.label + ": " + tooltip.formattedValue; |
| 4347 | } |
| 4348 | }, |
| 4349 | { |
| 4350 | key: "tickText", |
| 4351 | value: function tickText(value) { |
| 4352 | var label = JSON.parse(this.getLabelForValue(value)); |
| 4353 | return label.tick; |
| 4354 | } |
| 4355 | }, |
| 4356 | { |
| 4357 | key: "getVisitorsDataset", |
| 4358 | value: function getVisitorsDataset() { |
| 4359 | return { |
| 4360 | id: "visitors", |
| 4361 | label: iawpText.visitors, |
| 4362 | data: this.visitorsValue, |
| 4363 | borderColor: "rgba(246,157,10,1)", |
| 4364 | fill: true, |
| 4365 | backgroundColor: "rgba(246,157,10,0.2)", |
| 4366 | pointBackgroundColor: "rgba(246,157,10,1)", |
| 4367 | tension: 0.4, |
| 4368 | yAxisID: "y", |
| 4369 | hidden: !this.visibleDatasetsValue.includes("visitors") |
| 4370 | }; |
| 4371 | } |
| 4372 | }, |
| 4373 | { |
| 4374 | key: "getViewsDataset", |
| 4375 | value: function getViewsDataset() { |
| 4376 | return { |
| 4377 | id: "views", |
| 4378 | label: iawpText.views, |
| 4379 | data: this.viewsValue, |
| 4380 | borderColor: "rgba(108,70,174,1)", |
| 4381 | fill: true, |
| 4382 | backgroundColor: "rgba(108,70,174,0.2)", |
| 4383 | pointBackgroundColor: "rgba(108,70,174,1)", |
| 4384 | tension: 0.4, |
| 4385 | yAxisID: "y", |
| 4386 | hidden: !this.visibleDatasetsValue.includes("views") |
| 4387 | }; |
| 4388 | } |
| 4389 | }, |
| 4390 | { |
| 4391 | key: "getSessionsDataset", |
| 4392 | value: function getSessionsDataset() { |
| 4393 | if (this.isPreview()) return null; |
| 4394 | return { |
| 4395 | id: "sessions", |
| 4396 | label: iawpText.sessions, |
| 4397 | data: this.sessionsValue, |
| 4398 | borderColor: "rgba(217, 59, 41, 1)", |
| 4399 | fill: true, |
| 4400 | backgroundColor: "rgba(217, 59, 41, 0.2)", |
| 4401 | pointBackgroundColor: "rgba(217, 59, 41, 1)", |
| 4402 | tension: 0.4, |
| 4403 | yAxisID: "y", |
| 4404 | hidden: !this.visibleDatasetsValue.includes("sessions") |
| 4405 | }; |
| 4406 | } |
| 4407 | }, |
| 4408 | { |
| 4409 | key: "getOrdersDataset", |
| 4410 | value: function getOrdersDataset() { |
| 4411 | if (this.isPreview() || !this.isUsingWooCommerce()) return null; |
| 4412 | return { |
| 4413 | id: "orders", |
| 4414 | label: iawpText.orders, |
| 4415 | data: this.woocommerceOrdersValue, |
| 4416 | borderColor: "rgba(35, 125, 68, 1)", |
| 4417 | fill: true, |
| 4418 | backgroundColor: "rgba(35, 125, 68, .2)", |
| 4419 | pointBackgroundColor: "rgba(35, 125, 68, 1)", |
| 4420 | tension: 0.4, |
| 4421 | yAxisID: "y1", |
| 4422 | hidden: !this.visibleDatasetsValue.includes("orders") |
| 4423 | }; |
| 4424 | } |
| 4425 | }, |
| 4426 | { |
| 4427 | key: "getNetSalesDataset", |
| 4428 | value: function getNetSalesDataset() { |
| 4429 | var _this = this; |
| 4430 | if (this.isPreview() || !this.isUsingWooCommerce()) return null; |
| 4431 | return { |
| 4432 | id: "net-sales", |
| 4433 | label: iawpText.netSales, |
| 4434 | data: this.woocommerceNetSalesValue, |
| 4435 | borderColor: "rgba(52, 152, 219, 1)", |
| 4436 | fill: true, |
| 4437 | backgroundColor: "rgba(52, 152, 219, 0.2)", |
| 4438 | pointBackgroundColor: "rgba(52, 152, 219, 1)", |
| 4439 | tension: 0.4, |
| 4440 | yAxisID: "y2", |
| 4441 | tooltipLabel: function(tooltip) { |
| 4442 | return tooltip.dataset.label + ": " + _this.formatCurrency(tooltip.raw); |
| 4443 | }, |
| 4444 | hidden: !this.visibleDatasetsValue.includes("net-sales") |
| 4445 | }; |
| 4446 | } |
| 4447 | }, |
| 4448 | { |
| 4449 | key: "connect", |
| 4450 | value: function connect() { |
| 4451 | (0, _chartJs.Chart).defaults.font.family = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'; |
| 4452 | var element = document.getElementById("myChart"); |
| 4453 | var labels = this.labelsValue; |
| 4454 | var data = { |
| 4455 | labels: labels, |
| 4456 | datasets: [ |
| 4457 | this.getVisitorsDataset(), |
| 4458 | this.getViewsDataset(), |
| 4459 | this.getSessionsDataset(), |
| 4460 | this.getOrdersDataset(), |
| 4461 | this.getNetSalesDataset() |
| 4462 | ].filter(function(dataset) { |
| 4463 | return dataset !== null; |
| 4464 | }) |
| 4465 | }; |
| 4466 | var options = { |
| 4467 | locale: this.locale, |
| 4468 | animation: { |
| 4469 | duration: 0 |
| 4470 | }, |
| 4471 | interaction: { |
| 4472 | intersect: false, |
| 4473 | mode: "index" |
| 4474 | }, |
| 4475 | scales: { |
| 4476 | y: { |
| 4477 | title: { |
| 4478 | text: "".concat(iawpText.visitors, " / ").concat(iawpText.views, " / ").concat(iawpText.sessions), |
| 4479 | display: this.previewValue ? false : true |
| 4480 | }, |
| 4481 | grid: { |
| 4482 | borderColor: "#DEDAE6", |
| 4483 | tickColor: "#DEDAE6", |
| 4484 | display: true, |
| 4485 | drawOnChartArea: true, |
| 4486 | borderDash: [ |
| 4487 | 2, |
| 4488 | 4 |
| 4489 | ] |
| 4490 | }, |
| 4491 | beginAtZero: true, |
| 4492 | suggestedMax: 10, |
| 4493 | // grace: '26%', |
| 4494 | ticks: { |
| 4495 | color: document.body.classList.contains("iawp-dark-mode") ? "#ffffff" : "#6D6A73", |
| 4496 | font: { |
| 4497 | size: 14, |
| 4498 | weight: 400 |
| 4499 | }, |
| 4500 | precision: 0 |
| 4501 | } |
| 4502 | }, |
| 4503 | y1: { |
| 4504 | title: { |
| 4505 | text: iawpText.orders, |
| 4506 | display: true, |
| 4507 | color: "rgba(35, 125, 68, 1)" |
| 4508 | }, |
| 4509 | position: "right", |
| 4510 | display: "auto", |
| 4511 | grid: { |
| 4512 | borderColor: "rgba(35, 125, 68, 1)", |
| 4513 | tickColor: "rgba(35, 125, 68, 1)", |
| 4514 | display: false, |
| 4515 | drawOnChartArea: false, |
| 4516 | borderDash: [ |
| 4517 | 2, |
| 4518 | 4 |
| 4519 | ] |
| 4520 | }, |
| 4521 | beginAtZero: true, |
| 4522 | suggestedMax: 10, |
| 4523 | // grace: '26%', |
| 4524 | ticks: { |
| 4525 | // color: document.body.classList.contains('iawp-dark-mode') ? '#ffffff' : '#6D6A73', |
| 4526 | color: "rgba(35, 125, 68, 1)", |
| 4527 | font: { |
| 4528 | size: 14, |
| 4529 | weight: 400 |
| 4530 | }, |
| 4531 | precision: 0 |
| 4532 | } |
| 4533 | }, |
| 4534 | y2: { |
| 4535 | title: { |
| 4536 | text: iawpText.netSales, |
| 4537 | display: true, |
| 4538 | color: "rgba(52, 152, 219, 1)" |
| 4539 | }, |
| 4540 | position: "right", |
| 4541 | display: "auto", |
| 4542 | grid: { |
| 4543 | borderColor: "rgba(52, 152, 219, 1)", |
| 4544 | tickColor: "rgba(52, 152, 219, 1)", |
| 4545 | display: false, |
| 4546 | drawOnChartArea: false, |
| 4547 | borderDash: [ |
| 4548 | 2, |
| 4549 | 4 |
| 4550 | ] |
| 4551 | }, |
| 4552 | beginAtZero: true, |
| 4553 | suggestedMax: 10, |
| 4554 | // grace: '26%', |
| 4555 | ticks: { |
| 4556 | // color: document.body.classList.contains('iawp-dark-mode') ? '#ffffff' : '#6D6A73', |
| 4557 | color: "rgba(52, 152, 219, 1)", |
| 4558 | font: { |
| 4559 | size: 14, |
| 4560 | weight: 400 |
| 4561 | }, |
| 4562 | precision: 0, |
| 4563 | callback: this.currencyTickText |
| 4564 | } |
| 4565 | }, |
| 4566 | x: { |
| 4567 | grid: { |
| 4568 | borderColor: "#DEDAE6", |
| 4569 | tickColor: "#DEDAE6", |
| 4570 | display: true, |
| 4571 | drawOnChartArea: false |
| 4572 | }, |
| 4573 | ticks: { |
| 4574 | color: document.body.classList.contains("iawp-dark-mode") ? "#ffffff" : "#6D6A73", |
| 4575 | autoSkip: true, |
| 4576 | autoSkipPadding: 16, |
| 4577 | maxRotation: 0, |
| 4578 | // maxTicksLimit: 20, |
| 4579 | font: { |
| 4580 | size: 14, |
| 4581 | weight: 400 |
| 4582 | }, |
| 4583 | callback: this.tickText |
| 4584 | } |
| 4585 | } |
| 4586 | }, |
| 4587 | plugins: { |
| 4588 | mode: String, |
| 4589 | htmlLegend: { |
| 4590 | container: element.parentNode.querySelector(".legend"), |
| 4591 | callback: function callback(visibleDatasets) { |
| 4592 | // Todo - Actually track visible datasets |
| 4593 | document.dispatchEvent(new CustomEvent("iawp:changeVisibleDatasets", { |
| 4594 | detail: { |
| 4595 | visibleDatasets: visibleDatasets |
| 4596 | } |
| 4597 | })); |
| 4598 | } |
| 4599 | }, |
| 4600 | legend: { |
| 4601 | display: false |
| 4602 | }, |
| 4603 | corsair: { |
| 4604 | dash: [ |
| 4605 | 2, |
| 4606 | 4 |
| 4607 | ], |
| 4608 | color: "#777", |
| 4609 | width: 1 |
| 4610 | }, |
| 4611 | tooltip: { |
| 4612 | callbacks: { |
| 4613 | title: this.tooltipTitle, |
| 4614 | label: this.tooltipLabel |
| 4615 | } |
| 4616 | } |
| 4617 | }, |
| 4618 | elements: { |
| 4619 | point: { |
| 4620 | radius: 4 |
| 4621 | } |
| 4622 | } |
| 4623 | }; |
| 4624 | var config = { |
| 4625 | type: "line", |
| 4626 | data: data, |
| 4627 | options: options, |
| 4628 | plugins: [ |
| 4629 | (0, _htmlLegendPluginDefault.default), |
| 4630 | (0, _corsairPluginDefault.default) |
| 4631 | ] |
| 4632 | }; |
| 4633 | window.iawp_chart = new (0, _chartJs.Chart)(element, config); |
| 4634 | } |
| 4635 | } |
| 4636 | ]); |
| 4637 | return _class; |
| 4638 | }((0, _stimulus.Controller)); |
| 4639 | (0, _definePropertyJsDefault.default)(_class, "values", { |
| 4640 | locale: String, |
| 4641 | currency: { |
| 4642 | type: String, |
| 4643 | default: "USD" |
| 4644 | }, |
| 4645 | preview: Boolean, |
| 4646 | usingWooCommerce: Boolean, |
| 4647 | labels: Array, |
| 4648 | views: Array, |
| 4649 | visitors: Array, |
| 4650 | sessions: Array, |
| 4651 | woocommerceOrders: Array, |
| 4652 | woocommerceNetSales: Array, |
| 4653 | visibleDatasets: Array |
| 4654 | }); |
| 4655 | |
| 4656 | },{"@swc/helpers/lib/_assert_this_initialized.js":"l7nF8","@swc/helpers/lib/_class_call_check.js":"gNxF8","@swc/helpers/lib/_create_class.js":"iyoaN","@swc/helpers/lib/_define_property.js":"6IXzf","@swc/helpers/lib/_inherits.js":"atvDk","@swc/helpers/lib/_to_consumable_array.js":"cccKv","@swc/helpers/lib/_create_super.js":"5rW3S","@hotwired/stimulus":"27q4D","../chart_plugins/corsair_plugin":"1DRHy","../chart_plugins/html_legend_plugin":"3Qrst","chart.js":"h4klJ","@parcel/transformer-js/src/esmodule-helpers.js":"jIm8e"}],"1DRHy":[function(require,module,exports) { |
| 4657 | module.exports = { |
| 4658 | id: "corsair", |
| 4659 | beforeInit: function(chart, _, opts) { |
| 4660 | if (opts.disabled) return; |
| 4661 | chart.corsair = { |
| 4662 | x: 0, |
| 4663 | y: 0 |
| 4664 | }; |
| 4665 | }, |
| 4666 | afterEvent: function(chart, evt, opts) { |
| 4667 | if (opts.disabled) return; |
| 4668 | var _chartArea = chart.chartArea, top = _chartArea.top, bottom = _chartArea.bottom, left = _chartArea.left, right = _chartArea.right; |
| 4669 | var _event = evt.event, x = _event.x, y = _event.y; |
| 4670 | if (x < left || x > right || y < top || y > bottom) { |
| 4671 | chart.corsair = { |
| 4672 | x: x, |
| 4673 | y: y, |
| 4674 | draw: false |
| 4675 | }; |
| 4676 | chart.draw(); |
| 4677 | return; |
| 4678 | } |
| 4679 | chart.corsair = { |
| 4680 | x: x, |
| 4681 | y: y, |
| 4682 | draw: true |
| 4683 | }; |
| 4684 | chart.draw(); |
| 4685 | }, |
| 4686 | afterDatasetsDraw: function(chart, _, opts) { |
| 4687 | if (opts.disabled) return; |
| 4688 | var ctx = chart.ctx, _chartArea = chart.chartArea, top = _chartArea.top, bottom = _chartArea.bottom, left = _chartArea.left, right = _chartArea.right; |
| 4689 | var _corsair = chart.corsair, x = _corsair.x, y = _corsair.y, draw = _corsair.draw; |
| 4690 | if (!draw) return; |
| 4691 | // console.log(chart); |
| 4692 | x = chart.tooltip.caretX; |
| 4693 | ctx.lineWidth = opts.width || 0; |
| 4694 | // // Todo - Why does dash fuck up dots? |
| 4695 | ctx.setLineDash(opts.dash || []); |
| 4696 | ctx.strokeStyle = opts.color || "black"; |
| 4697 | ctx.save(); |
| 4698 | ctx.beginPath(); |
| 4699 | ctx.moveTo(x, bottom); |
| 4700 | ctx.lineTo(x, top); |
| 4701 | // Uncomment these 2 lines to add horizontal line |
| 4702 | // ctx.moveTo(left, y); |
| 4703 | // ctx.lineTo(right, y); |
| 4704 | ctx.stroke(); |
| 4705 | ctx.restore(); |
| 4706 | ctx.setLineDash([]); |
| 4707 | } |
| 4708 | }; |
| 4709 | |
| 4710 | },{}],"3Qrst":[function(require,module,exports) { |
| 4711 | module.exports = { |
| 4712 | id: "htmlLegend", |
| 4713 | getLegendContainer: function(options) { |
| 4714 | if (options.container instanceof HTMLElement) return options.container; |
| 4715 | else return document.getElementById(options.containerID); |
| 4716 | }, |
| 4717 | afterUpdate: function(chart, args, options) { |
| 4718 | var legendContainer = this.getLegendContainer(options); |
| 4719 | var legendList = legendContainer.querySelector("ul"); |
| 4720 | // Create a list as needed |
| 4721 | if (!legendList) { |
| 4722 | legendList = document.createElement("ul"); |
| 4723 | legendList.classList.add("legend-list"); |
| 4724 | legendContainer.appendChild(legendList); |
| 4725 | } |
| 4726 | // Remove old legend items |
| 4727 | while(legendList.firstChild)legendList.firstChild.remove(); |
| 4728 | // Reuse the built-in legendItems generator |
| 4729 | var items = chart.options.plugins.legend.labels.generateLabels(chart); |
| 4730 | items.forEach(function(legendData) { |
| 4731 | var id = chart.data.datasets.find(function(dataset) { |
| 4732 | return dataset.label === legendData.text; |
| 4733 | }).id; |
| 4734 | var li = document.createElement("li"); |
| 4735 | li.onclick = function() { |
| 4736 | var type = chart.config.type; |
| 4737 | if (type === "pie" || type === "doughnut") // Pie and doughnut charts only have a single dataset and visibility is per item |
| 4738 | chart.toggleDataVisibility(legendData.index); |
| 4739 | else chart.setDatasetVisibility(legendData.datasetIndex, !chart.isDatasetVisible(legendData.datasetIndex)); |
| 4740 | chart.update(); |
| 4741 | if (typeof options.callback === "function") { |
| 4742 | var visibleDatasets = chart.data.datasets.filter(function(dataset, index) { |
| 4743 | return chart.isDatasetVisible(index); |
| 4744 | }).map(function(dataset) { |
| 4745 | return dataset.id; |
| 4746 | }); |
| 4747 | options.callback(visibleDatasets); |
| 4748 | } |
| 4749 | }; |
| 4750 | li.classList.add("legend-item", "legend-item-for-".concat(id)); |
| 4751 | if (legendData.hidden) li.classList.add("hidden"); |
| 4752 | // Color box |
| 4753 | var boxSpan = document.createElement("span"); |
| 4754 | // Text |
| 4755 | var textContainer = document.createElement("p"); |
| 4756 | textContainer.textContent = legendData.text; |
| 4757 | li.appendChild(boxSpan); |
| 4758 | li.appendChild(textContainer); |
| 4759 | legendList.appendChild(li); |
| 4760 | }); |
| 4761 | } |
| 4762 | }; |
| 4763 | |
| 4764 | },{}],"h4klJ":[function(require,module,exports) { |
| 4765 | var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); |
| 4766 | parcelHelpers.defineInteropFlag(exports); |
| 4767 | parcelHelpers.export(exports, "defaults", function() { |
| 4768 | return 0, _helpersSegmentJs.d; |
| 4769 | }); |
| 4770 | parcelHelpers.export(exports, "Animation", function() { |
| 4771 | return Animation; |
| 4772 | }); |
| 4773 | parcelHelpers.export(exports, "Animations", function() { |
| 4774 | return Animations; |
| 4775 | }); |
| 4776 | parcelHelpers.export(exports, "ArcElement", function() { |
| 4777 | return ArcElement; |
| 4778 | }); |
| 4779 | parcelHelpers.export(exports, "BarController", function() { |
| 4780 | return BarController; |
| 4781 | }); |
| 4782 | parcelHelpers.export(exports, "BarElement", function() { |
| 4783 | return BarElement; |
| 4784 | }); |
| 4785 | parcelHelpers.export(exports, "BasePlatform", function() { |
| 4786 | return BasePlatform; |
| 4787 | }); |
| 4788 | parcelHelpers.export(exports, "BasicPlatform", function() { |
| 4789 | return BasicPlatform; |
| 4790 | }); |
| 4791 | parcelHelpers.export(exports, "BubbleController", function() { |
| 4792 | return BubbleController; |
| 4793 | }); |
| 4794 | parcelHelpers.export(exports, "CategoryScale", function() { |
| 4795 | return CategoryScale; |
| 4796 | }); |
| 4797 | parcelHelpers.export(exports, "Chart", function() { |
| 4798 | return Chart; |
| 4799 | }); |
| 4800 | parcelHelpers.export(exports, "DatasetController", function() { |
| 4801 | return DatasetController; |
| 4802 | }); |
| 4803 | parcelHelpers.export(exports, "Decimation", function() { |
| 4804 | return plugin_decimation; |
| 4805 | }); |
| 4806 | parcelHelpers.export(exports, "DomPlatform", function() { |
| 4807 | return DomPlatform; |
| 4808 | }); |
| 4809 | parcelHelpers.export(exports, "DoughnutController", function() { |
| 4810 | return DoughnutController; |
| 4811 | }); |
| 4812 | parcelHelpers.export(exports, "Element", function() { |
| 4813 | return Element; |
| 4814 | }); |
| 4815 | parcelHelpers.export(exports, "Filler", function() { |
| 4816 | return index; |
| 4817 | }); |
| 4818 | parcelHelpers.export(exports, "Interaction", function() { |
| 4819 | return Interaction; |
| 4820 | }); |
| 4821 | parcelHelpers.export(exports, "Legend", function() { |
| 4822 | return plugin_legend; |
| 4823 | }); |
| 4824 | parcelHelpers.export(exports, "LineController", function() { |
| 4825 | return LineController; |
| 4826 | }); |
| 4827 | parcelHelpers.export(exports, "LineElement", function() { |
| 4828 | return LineElement; |
| 4829 | }); |
| 4830 | parcelHelpers.export(exports, "LinearScale", function() { |
| 4831 | return LinearScale; |
| 4832 | }); |
| 4833 | parcelHelpers.export(exports, "LogarithmicScale", function() { |
| 4834 | return LogarithmicScale; |
| 4835 | }); |
| 4836 | parcelHelpers.export(exports, "PieController", function() { |
| 4837 | return PieController; |
| 4838 | }); |
| 4839 | parcelHelpers.export(exports, "PointElement", function() { |
| 4840 | return PointElement; |
| 4841 | }); |
| 4842 | parcelHelpers.export(exports, "PolarAreaController", function() { |
| 4843 | return PolarAreaController; |
| 4844 | }); |
| 4845 | parcelHelpers.export(exports, "RadarController", function() { |
| 4846 | return RadarController; |
| 4847 | }); |
| 4848 | parcelHelpers.export(exports, "RadialLinearScale", function() { |
| 4849 | return RadialLinearScale; |
| 4850 | }); |
| 4851 | parcelHelpers.export(exports, "Scale", function() { |
| 4852 | return Scale; |
| 4853 | }); |
| 4854 | parcelHelpers.export(exports, "ScatterController", function() { |
| 4855 | return ScatterController; |
| 4856 | }); |
| 4857 | parcelHelpers.export(exports, "SubTitle", function() { |
| 4858 | return plugin_subtitle; |
| 4859 | }); |
| 4860 | parcelHelpers.export(exports, "Ticks", function() { |
| 4861 | return Ticks; |
| 4862 | }); |
| 4863 | parcelHelpers.export(exports, "TimeScale", function() { |
| 4864 | return TimeScale; |
| 4865 | }); |
| 4866 | parcelHelpers.export(exports, "TimeSeriesScale", function() { |
| 4867 | return TimeSeriesScale; |
| 4868 | }); |
| 4869 | parcelHelpers.export(exports, "Title", function() { |
| 4870 | return plugin_title; |
| 4871 | }); |
| 4872 | parcelHelpers.export(exports, "Tooltip", function() { |
| 4873 | return plugin_tooltip; |
| 4874 | }); |
| 4875 | parcelHelpers.export(exports, "_adapters", function() { |
| 4876 | return adapters; |
| 4877 | }); |
| 4878 | parcelHelpers.export(exports, "_detectPlatform", function() { |
| 4879 | return _detectPlatform; |
| 4880 | }); |
| 4881 | parcelHelpers.export(exports, "animator", function() { |
| 4882 | return animator; |
| 4883 | }); |
| 4884 | parcelHelpers.export(exports, "controllers", function() { |
| 4885 | return controllers; |
| 4886 | }); |
| 4887 | parcelHelpers.export(exports, "elements", function() { |
| 4888 | return elements; |
| 4889 | }); |
| 4890 | parcelHelpers.export(exports, "layouts", function() { |
| 4891 | return layouts; |
| 4892 | }); |
| 4893 | parcelHelpers.export(exports, "plugins", function() { |
| 4894 | return plugins; |
| 4895 | }); |
| 4896 | parcelHelpers.export(exports, "registerables", function() { |
| 4897 | return registerables; |
| 4898 | }); |
| 4899 | parcelHelpers.export(exports, "registry", function() { |
| 4900 | return registry; |
| 4901 | }); |
| 4902 | parcelHelpers.export(exports, "scales", function() { |
| 4903 | return scales; |
| 4904 | }); |
| 4905 | var _assertThisInitializedJs = require("@swc/helpers/lib/_assert_this_initialized.js"); |
| 4906 | var _assertThisInitializedJsDefault = parcelHelpers.interopDefault(_assertThisInitializedJs); |
| 4907 | var _classCallCheckJs = require("@swc/helpers/lib/_class_call_check.js"); |
| 4908 | var _classCallCheckJsDefault = parcelHelpers.interopDefault(_classCallCheckJs); |
| 4909 | var _createClassJs = require("@swc/helpers/lib/_create_class.js"); |
| 4910 | var _createClassJsDefault = parcelHelpers.interopDefault(_createClassJs); |
| 4911 | var _definePropertyJs = require("@swc/helpers/lib/_define_property.js"); |
| 4912 | var _definePropertyJsDefault = parcelHelpers.interopDefault(_definePropertyJs); |
| 4913 | var _getJs = require("@swc/helpers/lib/_get.js"); |
| 4914 | var _getJsDefault = parcelHelpers.interopDefault(_getJs); |
| 4915 | var _getPrototypeOfJs = require("@swc/helpers/lib/_get_prototype_of.js"); |
| 4916 | var _getPrototypeOfJsDefault = parcelHelpers.interopDefault(_getPrototypeOfJs); |
| 4917 | var _inheritsJs = require("@swc/helpers/lib/_inherits.js"); |
| 4918 | var _inheritsJsDefault = parcelHelpers.interopDefault(_inheritsJs); |
| 4919 | var _objectSpreadJs = require("@swc/helpers/lib/_object_spread.js"); |
| 4920 | var _objectSpreadJsDefault = parcelHelpers.interopDefault(_objectSpreadJs); |
| 4921 | var _slicedToArrayJs = require("@swc/helpers/lib/_sliced_to_array.js"); |
| 4922 | var _slicedToArrayJsDefault = parcelHelpers.interopDefault(_slicedToArrayJs); |
| 4923 | var _toConsumableArrayJs = require("@swc/helpers/lib/_to_consumable_array.js"); |
| 4924 | var _toConsumableArrayJsDefault = parcelHelpers.interopDefault(_toConsumableArrayJs); |
| 4925 | var _typeOfJs = require("@swc/helpers/lib/_type_of.js"); |
| 4926 | var _typeOfJsDefault = parcelHelpers.interopDefault(_typeOfJs); |
| 4927 | var _wrapNativeSuperJs = require("@swc/helpers/lib/_wrap_native_super.js"); |
| 4928 | var _wrapNativeSuperJsDefault = parcelHelpers.interopDefault(_wrapNativeSuperJs); |
| 4929 | var _createSuperJs = require("@swc/helpers/lib/_create_super.js"); |
| 4930 | var _createSuperJsDefault = parcelHelpers.interopDefault(_createSuperJs); |
| 4931 | /*! |
| 4932 | * Chart.js v3.8.0 |
| 4933 | * https://www.chartjs.org |
| 4934 | * (c) 2022 Chart.js Contributors |
| 4935 | * Released under the MIT License |
| 4936 | */ var _helpersSegmentJs = require("./chunks/helpers.segment.js"); |
| 4937 | var Animator = /*#__PURE__*/ function() { |
| 4938 | "use strict"; |
| 4939 | function Animator() { |
| 4940 | (0, _classCallCheckJsDefault.default)(this, Animator); |
| 4941 | this._request = null; |
| 4942 | this._charts = new Map(); |
| 4943 | this._running = false; |
| 4944 | this._lastDate = undefined; |
| 4945 | } |
| 4946 | (0, _createClassJsDefault.default)(Animator, [ |
| 4947 | { |
| 4948 | key: "_notify", |
| 4949 | value: function _notify(chart, anims, date, type) { |
| 4950 | var callbacks = anims.listeners[type]; |
| 4951 | var numSteps = anims.duration; |
| 4952 | callbacks.forEach(function(fn) { |
| 4953 | return fn({ |
| 4954 | chart: chart, |
| 4955 | initial: anims.initial, |
| 4956 | numSteps: numSteps, |
| 4957 | currentStep: Math.min(date - anims.start, numSteps) |
| 4958 | }); |
| 4959 | }); |
| 4960 | } |
| 4961 | }, |
| 4962 | { |
| 4963 | key: "_refresh", |
| 4964 | value: function _refresh() { |
| 4965 | var _this = this; |
| 4966 | if (this._request) return; |
| 4967 | this._running = true; |
| 4968 | this._request = (0, _helpersSegmentJs.r).call(window, function() { |
| 4969 | _this._update(); |
| 4970 | _this._request = null; |
| 4971 | if (_this._running) _this._refresh(); |
| 4972 | }); |
| 4973 | } |
| 4974 | }, |
| 4975 | { |
| 4976 | key: "_update", |
| 4977 | value: function _update() { |
| 4978 | var date = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : Date.now(); |
| 4979 | var _this = this; |
| 4980 | var remaining = 0; |
| 4981 | this._charts.forEach(function(anims, chart) { |
| 4982 | if (!anims.running || !anims.items.length) return; |
| 4983 | var items = anims.items; |
| 4984 | var i = items.length - 1; |
| 4985 | var draw1 = false; |
| 4986 | var item; |
| 4987 | for(; i >= 0; --i){ |
| 4988 | item = items[i]; |
| 4989 | if (item._active) { |
| 4990 | if (item._total > anims.duration) anims.duration = item._total; |
| 4991 | item.tick(date); |
| 4992 | draw1 = true; |
| 4993 | } else { |
| 4994 | items[i] = items[items.length - 1]; |
| 4995 | items.pop(); |
| 4996 | } |
| 4997 | } |
| 4998 | if (draw1) { |
| 4999 | chart.draw(); |
| 5000 | _this._notify(chart, anims, date, "progress"); |
| 5001 | } |
| 5002 | if (!items.length) { |
| 5003 | anims.running = false; |
| 5004 | _this._notify(chart, anims, date, "complete"); |
| 5005 | anims.initial = false; |
| 5006 | } |
| 5007 | remaining += items.length; |
| 5008 | }); |
| 5009 | this._lastDate = date; |
| 5010 | if (remaining === 0) this._running = false; |
| 5011 | } |
| 5012 | }, |
| 5013 | { |
| 5014 | key: "_getAnims", |
| 5015 | value: function _getAnims(chart) { |
| 5016 | var charts = this._charts; |
| 5017 | var anims = charts.get(chart); |
| 5018 | if (!anims) { |
| 5019 | anims = { |
| 5020 | running: false, |
| 5021 | initial: true, |
| 5022 | items: [], |
| 5023 | listeners: { |
| 5024 | complete: [], |
| 5025 | progress: [] |
| 5026 | } |
| 5027 | }; |
| 5028 | charts.set(chart, anims); |
| 5029 | } |
| 5030 | return anims; |
| 5031 | } |
| 5032 | }, |
| 5033 | { |
| 5034 | key: "listen", |
| 5035 | value: function listen(chart, event, cb) { |
| 5036 | this._getAnims(chart).listeners[event].push(cb); |
| 5037 | } |
| 5038 | }, |
| 5039 | { |
| 5040 | key: "add", |
| 5041 | value: function add(chart, items) { |
| 5042 | var _items; |
| 5043 | if (!items || !items.length) return; |
| 5044 | (_items = this._getAnims(chart).items).push.apply(_items, (0, _toConsumableArrayJsDefault.default)(items)); |
| 5045 | } |
| 5046 | }, |
| 5047 | { |
| 5048 | key: "has", |
| 5049 | value: function has(chart) { |
| 5050 | return this._getAnims(chart).items.length > 0; |
| 5051 | } |
| 5052 | }, |
| 5053 | { |
| 5054 | key: "start", |
| 5055 | value: function start(chart) { |
| 5056 | var anims = this._charts.get(chart); |
| 5057 | if (!anims) return; |
| 5058 | anims.running = true; |
| 5059 | anims.start = Date.now(); |
| 5060 | anims.duration = anims.items.reduce(function(acc, cur) { |
| 5061 | return Math.max(acc, cur._duration); |
| 5062 | }, 0); |
| 5063 | this._refresh(); |
| 5064 | } |
| 5065 | }, |
| 5066 | { |
| 5067 | key: "running", |
| 5068 | value: function running(chart) { |
| 5069 | if (!this._running) return false; |
| 5070 | var anims = this._charts.get(chart); |
| 5071 | if (!anims || !anims.running || !anims.items.length) return false; |
| 5072 | return true; |
| 5073 | } |
| 5074 | }, |
| 5075 | { |
| 5076 | key: "stop", |
| 5077 | value: function stop(chart) { |
| 5078 | var anims = this._charts.get(chart); |
| 5079 | if (!anims || !anims.items.length) return; |
| 5080 | var items = anims.items; |
| 5081 | var i = items.length - 1; |
| 5082 | for(; i >= 0; --i)items[i].cancel(); |
| 5083 | anims.items = []; |
| 5084 | this._notify(chart, anims, Date.now(), "complete"); |
| 5085 | } |
| 5086 | }, |
| 5087 | { |
| 5088 | key: "remove", |
| 5089 | value: function remove(chart) { |
| 5090 | return this._charts.delete(chart); |
| 5091 | } |
| 5092 | } |
| 5093 | ]); |
| 5094 | return Animator; |
| 5095 | }(); |
| 5096 | var animator = new Animator(); |
| 5097 | var transparent = "transparent"; |
| 5098 | var interpolators = { |
| 5099 | boolean: function(from, to, factor) { |
| 5100 | return factor > 0.5 ? to : from; |
| 5101 | }, |
| 5102 | color: function(from, to, factor) { |
| 5103 | var c0 = (0, _helpersSegmentJs.c)(from || transparent); |
| 5104 | var c1 = c0.valid && (0, _helpersSegmentJs.c)(to || transparent); |
| 5105 | return c1 && c1.valid ? c1.mix(c0, factor).hexString() : to; |
| 5106 | }, |
| 5107 | number: function(from, to, factor) { |
| 5108 | return from + (to - from) * factor; |
| 5109 | } |
| 5110 | }; |
| 5111 | var Animation = /*#__PURE__*/ function() { |
| 5112 | "use strict"; |
| 5113 | function Animation(cfg, target, prop, to) { |
| 5114 | (0, _classCallCheckJsDefault.default)(this, Animation); |
| 5115 | var currentValue = target[prop]; |
| 5116 | to = (0, _helpersSegmentJs.a)([ |
| 5117 | cfg.to, |
| 5118 | to, |
| 5119 | currentValue, |
| 5120 | cfg.from |
| 5121 | ]); |
| 5122 | var from = (0, _helpersSegmentJs.a)([ |
| 5123 | cfg.from, |
| 5124 | currentValue, |
| 5125 | to |
| 5126 | ]); |
| 5127 | this._active = true; |
| 5128 | this._fn = cfg.fn || interpolators[cfg.type || (typeof from === "undefined" ? "undefined" : (0, _typeOfJsDefault.default)(from))]; |
| 5129 | this._easing = (0, _helpersSegmentJs.e)[cfg.easing] || (0, _helpersSegmentJs.e).linear; |
| 5130 | this._start = Math.floor(Date.now() + (cfg.delay || 0)); |
| 5131 | this._duration = this._total = Math.floor(cfg.duration); |
| 5132 | this._loop = !!cfg.loop; |
| 5133 | this._target = target; |
| 5134 | this._prop = prop; |
| 5135 | this._from = from; |
| 5136 | this._to = to; |
| 5137 | this._promises = undefined; |
| 5138 | } |
| 5139 | (0, _createClassJsDefault.default)(Animation, [ |
| 5140 | { |
| 5141 | key: "active", |
| 5142 | value: function active() { |
| 5143 | return this._active; |
| 5144 | } |
| 5145 | }, |
| 5146 | { |
| 5147 | key: "update", |
| 5148 | value: function update(cfg, to, date) { |
| 5149 | if (this._active) { |
| 5150 | this._notify(false); |
| 5151 | var currentValue = this._target[this._prop]; |
| 5152 | var elapsed = date - this._start; |
| 5153 | var remain = this._duration - elapsed; |
| 5154 | this._start = date; |
| 5155 | this._duration = Math.floor(Math.max(remain, cfg.duration)); |
| 5156 | this._total += elapsed; |
| 5157 | this._loop = !!cfg.loop; |
| 5158 | this._to = (0, _helpersSegmentJs.a)([ |
| 5159 | cfg.to, |
| 5160 | to, |
| 5161 | currentValue, |
| 5162 | cfg.from |
| 5163 | ]); |
| 5164 | this._from = (0, _helpersSegmentJs.a)([ |
| 5165 | cfg.from, |
| 5166 | currentValue, |
| 5167 | to |
| 5168 | ]); |
| 5169 | } |
| 5170 | } |
| 5171 | }, |
| 5172 | { |
| 5173 | key: "cancel", |
| 5174 | value: function cancel() { |
| 5175 | if (this._active) { |
| 5176 | this.tick(Date.now()); |
| 5177 | this._active = false; |
| 5178 | this._notify(false); |
| 5179 | } |
| 5180 | } |
| 5181 | }, |
| 5182 | { |
| 5183 | key: "tick", |
| 5184 | value: function tick(date) { |
| 5185 | var elapsed = date - this._start; |
| 5186 | var duration = this._duration; |
| 5187 | var prop = this._prop; |
| 5188 | var from = this._from; |
| 5189 | var loop = this._loop; |
| 5190 | var to = this._to; |
| 5191 | var factor; |
| 5192 | this._active = from !== to && (loop || elapsed < duration); |
| 5193 | if (!this._active) { |
| 5194 | this._target[prop] = to; |
| 5195 | this._notify(true); |
| 5196 | return; |
| 5197 | } |
| 5198 | if (elapsed < 0) { |
| 5199 | this._target[prop] = from; |
| 5200 | return; |
| 5201 | } |
| 5202 | factor = elapsed / duration % 2; |
| 5203 | factor = loop && factor > 1 ? 2 - factor : factor; |
| 5204 | factor = this._easing(Math.min(1, Math.max(0, factor))); |
| 5205 | this._target[prop] = this._fn(from, to, factor); |
| 5206 | } |
| 5207 | }, |
| 5208 | { |
| 5209 | key: "wait", |
| 5210 | value: function wait() { |
| 5211 | var promises = this._promises || (this._promises = []); |
| 5212 | return new Promise(function(res, rej) { |
| 5213 | promises.push({ |
| 5214 | res: res, |
| 5215 | rej: rej |
| 5216 | }); |
| 5217 | }); |
| 5218 | } |
| 5219 | }, |
| 5220 | { |
| 5221 | key: "_notify", |
| 5222 | value: function _notify(resolved) { |
| 5223 | var method = resolved ? "res" : "rej"; |
| 5224 | var promises = this._promises || []; |
| 5225 | for(var i = 0; i < promises.length; i++)promises[i][method](); |
| 5226 | } |
| 5227 | } |
| 5228 | ]); |
| 5229 | return Animation; |
| 5230 | }(); |
| 5231 | var numbers = [ |
| 5232 | "x", |
| 5233 | "y", |
| 5234 | "borderWidth", |
| 5235 | "radius", |
| 5236 | "tension" |
| 5237 | ]; |
| 5238 | var colors = [ |
| 5239 | "color", |
| 5240 | "borderColor", |
| 5241 | "backgroundColor" |
| 5242 | ]; |
| 5243 | (0, _helpersSegmentJs.d).set("animation", { |
| 5244 | delay: undefined, |
| 5245 | duration: 1000, |
| 5246 | easing: "easeOutQuart", |
| 5247 | fn: undefined, |
| 5248 | from: undefined, |
| 5249 | loop: undefined, |
| 5250 | to: undefined, |
| 5251 | type: undefined |
| 5252 | }); |
| 5253 | var animationOptions = Object.keys((0, _helpersSegmentJs.d).animation); |
| 5254 | (0, _helpersSegmentJs.d).describe("animation", { |
| 5255 | _fallback: false, |
| 5256 | _indexable: false, |
| 5257 | _scriptable: function(name) { |
| 5258 | return name !== "onProgress" && name !== "onComplete" && name !== "fn"; |
| 5259 | } |
| 5260 | }); |
| 5261 | (0, _helpersSegmentJs.d).set("animations", { |
| 5262 | colors: { |
| 5263 | type: "color", |
| 5264 | properties: colors |
| 5265 | }, |
| 5266 | numbers: { |
| 5267 | type: "number", |
| 5268 | properties: numbers |
| 5269 | } |
| 5270 | }); |
| 5271 | (0, _helpersSegmentJs.d).describe("animations", { |
| 5272 | _fallback: "animation" |
| 5273 | }); |
| 5274 | (0, _helpersSegmentJs.d).set("transitions", { |
| 5275 | active: { |
| 5276 | animation: { |
| 5277 | duration: 400 |
| 5278 | } |
| 5279 | }, |
| 5280 | resize: { |
| 5281 | animation: { |
| 5282 | duration: 0 |
| 5283 | } |
| 5284 | }, |
| 5285 | show: { |
| 5286 | animations: { |
| 5287 | colors: { |
| 5288 | from: "transparent" |
| 5289 | }, |
| 5290 | visible: { |
| 5291 | type: "boolean", |
| 5292 | duration: 0 |
| 5293 | } |
| 5294 | } |
| 5295 | }, |
| 5296 | hide: { |
| 5297 | animations: { |
| 5298 | colors: { |
| 5299 | to: "transparent" |
| 5300 | }, |
| 5301 | visible: { |
| 5302 | type: "boolean", |
| 5303 | easing: "linear", |
| 5304 | fn: function(v) { |
| 5305 | return v | 0; |
| 5306 | } |
| 5307 | } |
| 5308 | } |
| 5309 | } |
| 5310 | }); |
| 5311 | var Animations = /*#__PURE__*/ function() { |
| 5312 | "use strict"; |
| 5313 | function Animations(chart, config) { |
| 5314 | (0, _classCallCheckJsDefault.default)(this, Animations); |
| 5315 | this._chart = chart; |
| 5316 | this._properties = new Map(); |
| 5317 | this.configure(config); |
| 5318 | } |
| 5319 | (0, _createClassJsDefault.default)(Animations, [ |
| 5320 | { |
| 5321 | key: "configure", |
| 5322 | value: function configure(config) { |
| 5323 | if (!(0, _helpersSegmentJs.i)(config)) return; |
| 5324 | var animatedProps = this._properties; |
| 5325 | Object.getOwnPropertyNames(config).forEach(function(key) { |
| 5326 | var cfg = config[key]; |
| 5327 | if (!(0, _helpersSegmentJs.i)(cfg)) return; |
| 5328 | var resolved = {}; |
| 5329 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 5330 | try { |
| 5331 | for(var _iterator = animationOptions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 5332 | var option = _step.value; |
| 5333 | resolved[option] = cfg[option]; |
| 5334 | } |
| 5335 | } catch (err) { |
| 5336 | _didIteratorError = true; |
| 5337 | _iteratorError = err; |
| 5338 | } finally{ |
| 5339 | try { |
| 5340 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 5341 | _iterator.return(); |
| 5342 | } |
| 5343 | } finally{ |
| 5344 | if (_didIteratorError) { |
| 5345 | throw _iteratorError; |
| 5346 | } |
| 5347 | } |
| 5348 | } |
| 5349 | ((0, _helpersSegmentJs.b)(cfg.properties) && cfg.properties || [ |
| 5350 | key |
| 5351 | ]).forEach(function(prop) { |
| 5352 | if (prop === key || !animatedProps.has(prop)) animatedProps.set(prop, resolved); |
| 5353 | }); |
| 5354 | }); |
| 5355 | } |
| 5356 | }, |
| 5357 | { |
| 5358 | key: "_animateOptions", |
| 5359 | value: function _animateOptions(target, values) { |
| 5360 | var newOptions = values.options; |
| 5361 | var options = resolveTargetOptions(target, newOptions); |
| 5362 | if (!options) return []; |
| 5363 | var animations = this._createAnimations(options, newOptions); |
| 5364 | if (newOptions.$shared) awaitAll(target.options.$animations, newOptions).then(function() { |
| 5365 | target.options = newOptions; |
| 5366 | }, function() {}); |
| 5367 | return animations; |
| 5368 | } |
| 5369 | }, |
| 5370 | { |
| 5371 | key: "_createAnimations", |
| 5372 | value: function _createAnimations(target, values) { |
| 5373 | var animatedProps = this._properties; |
| 5374 | var animations = []; |
| 5375 | var running = target.$animations || (target.$animations = {}); |
| 5376 | var props = Object.keys(values); |
| 5377 | var date = Date.now(); |
| 5378 | var i; |
| 5379 | for(i = props.length - 1; i >= 0; --i){ |
| 5380 | var prop = props[i]; |
| 5381 | if (prop.charAt(0) === "$") continue; |
| 5382 | if (prop === "options") { |
| 5383 | var _animations; |
| 5384 | (_animations = animations).push.apply(_animations, (0, _toConsumableArrayJsDefault.default)(this._animateOptions(target, values))); |
| 5385 | continue; |
| 5386 | } |
| 5387 | var value = values[prop]; |
| 5388 | var animation = running[prop]; |
| 5389 | var cfg = animatedProps.get(prop); |
| 5390 | if (animation) { |
| 5391 | if (cfg && animation.active()) { |
| 5392 | animation.update(cfg, value, date); |
| 5393 | continue; |
| 5394 | } else animation.cancel(); |
| 5395 | } |
| 5396 | if (!cfg || !cfg.duration) { |
| 5397 | target[prop] = value; |
| 5398 | continue; |
| 5399 | } |
| 5400 | running[prop] = animation = new Animation(cfg, target, prop, value); |
| 5401 | animations.push(animation); |
| 5402 | } |
| 5403 | return animations; |
| 5404 | } |
| 5405 | }, |
| 5406 | { |
| 5407 | key: "update", |
| 5408 | value: function update(target, values) { |
| 5409 | if (this._properties.size === 0) { |
| 5410 | Object.assign(target, values); |
| 5411 | return; |
| 5412 | } |
| 5413 | var animations = this._createAnimations(target, values); |
| 5414 | if (animations.length) { |
| 5415 | animator.add(this._chart, animations); |
| 5416 | return true; |
| 5417 | } |
| 5418 | } |
| 5419 | } |
| 5420 | ]); |
| 5421 | return Animations; |
| 5422 | }(); |
| 5423 | function awaitAll(animations, properties) { |
| 5424 | var running = []; |
| 5425 | var keys = Object.keys(properties); |
| 5426 | for(var i = 0; i < keys.length; i++){ |
| 5427 | var anim = animations[keys[i]]; |
| 5428 | if (anim && anim.active()) running.push(anim.wait()); |
| 5429 | } |
| 5430 | return Promise.all(running); |
| 5431 | } |
| 5432 | function resolveTargetOptions(target, newOptions) { |
| 5433 | if (!newOptions) return; |
| 5434 | var options = target.options; |
| 5435 | if (!options) { |
| 5436 | target.options = newOptions; |
| 5437 | return; |
| 5438 | } |
| 5439 | if (options.$shared) target.options = options = Object.assign({}, options, { |
| 5440 | $shared: false, |
| 5441 | $animations: {} |
| 5442 | }); |
| 5443 | return options; |
| 5444 | } |
| 5445 | function scaleClip(scale, allowedOverflow) { |
| 5446 | var opts = scale && scale.options || {}; |
| 5447 | var reverse = opts.reverse; |
| 5448 | var min = opts.min === undefined ? allowedOverflow : 0; |
| 5449 | var max = opts.max === undefined ? allowedOverflow : 0; |
| 5450 | return { |
| 5451 | start: reverse ? max : min, |
| 5452 | end: reverse ? min : max |
| 5453 | }; |
| 5454 | } |
| 5455 | function defaultClip(xScale, yScale, allowedOverflow) { |
| 5456 | if (allowedOverflow === false) return false; |
| 5457 | var x = scaleClip(xScale, allowedOverflow); |
| 5458 | var y = scaleClip(yScale, allowedOverflow); |
| 5459 | return { |
| 5460 | top: y.end, |
| 5461 | right: x.end, |
| 5462 | bottom: y.start, |
| 5463 | left: x.start |
| 5464 | }; |
| 5465 | } |
| 5466 | function toClip(value) { |
| 5467 | var t, r, b, l; |
| 5468 | if ((0, _helpersSegmentJs.i)(value)) { |
| 5469 | t = value.top; |
| 5470 | r = value.right; |
| 5471 | b = value.bottom; |
| 5472 | l = value.left; |
| 5473 | } else t = r = b = l = value; |
| 5474 | return { |
| 5475 | top: t, |
| 5476 | right: r, |
| 5477 | bottom: b, |
| 5478 | left: l, |
| 5479 | disabled: value === false |
| 5480 | }; |
| 5481 | } |
| 5482 | function getSortedDatasetIndices(chart, filterVisible) { |
| 5483 | var keys = []; |
| 5484 | var metasets = chart._getSortedDatasetMetas(filterVisible); |
| 5485 | var i, ilen; |
| 5486 | for(i = 0, ilen = metasets.length; i < ilen; ++i)keys.push(metasets[i].index); |
| 5487 | return keys; |
| 5488 | } |
| 5489 | function applyStack(stack, value, dsIndex) { |
| 5490 | var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}; |
| 5491 | var keys = stack.keys; |
| 5492 | var singleMode = options.mode === "single"; |
| 5493 | var i, ilen, datasetIndex, otherValue; |
| 5494 | if (value === null) return; |
| 5495 | for(i = 0, ilen = keys.length; i < ilen; ++i){ |
| 5496 | datasetIndex = +keys[i]; |
| 5497 | if (datasetIndex === dsIndex) { |
| 5498 | if (options.all) continue; |
| 5499 | break; |
| 5500 | } |
| 5501 | otherValue = stack.values[datasetIndex]; |
| 5502 | if ((0, _helpersSegmentJs.g)(otherValue) && (singleMode || value === 0 || (0, _helpersSegmentJs.s)(value) === (0, _helpersSegmentJs.s)(otherValue))) value += otherValue; |
| 5503 | } |
| 5504 | return value; |
| 5505 | } |
| 5506 | function convertObjectDataToArray(data) { |
| 5507 | var keys = Object.keys(data); |
| 5508 | var adata = new Array(keys.length); |
| 5509 | var i, ilen, key; |
| 5510 | for(i = 0, ilen = keys.length; i < ilen; ++i){ |
| 5511 | key = keys[i]; |
| 5512 | adata[i] = { |
| 5513 | x: key, |
| 5514 | y: data[key] |
| 5515 | }; |
| 5516 | } |
| 5517 | return adata; |
| 5518 | } |
| 5519 | function isStacked(scale, meta) { |
| 5520 | var stacked = scale && scale.options.stacked; |
| 5521 | return stacked || stacked === undefined && meta.stack !== undefined; |
| 5522 | } |
| 5523 | function getStackKey(indexScale, valueScale, meta) { |
| 5524 | return "".concat(indexScale.id, ".").concat(valueScale.id, ".").concat(meta.stack || meta.type); |
| 5525 | } |
| 5526 | function getUserBounds(scale) { |
| 5527 | var ref = scale.getUserBounds(), min = ref.min, max = ref.max, minDefined = ref.minDefined, maxDefined = ref.maxDefined; |
| 5528 | return { |
| 5529 | min: minDefined ? min : Number.NEGATIVE_INFINITY, |
| 5530 | max: maxDefined ? max : Number.POSITIVE_INFINITY |
| 5531 | }; |
| 5532 | } |
| 5533 | function getOrCreateStack(stacks, stackKey, indexValue) { |
| 5534 | var subStack = stacks[stackKey] || (stacks[stackKey] = {}); |
| 5535 | return subStack[indexValue] || (subStack[indexValue] = {}); |
| 5536 | } |
| 5537 | function getLastIndexInStack(stack, vScale, positive, type) { |
| 5538 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 5539 | try { |
| 5540 | for(var _iterator = vScale.getMatchingVisibleMetas(type).reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 5541 | var meta = _step.value; |
| 5542 | var value = stack[meta.index]; |
| 5543 | if (positive && value > 0 || !positive && value < 0) return meta.index; |
| 5544 | } |
| 5545 | } catch (err) { |
| 5546 | _didIteratorError = true; |
| 5547 | _iteratorError = err; |
| 5548 | } finally{ |
| 5549 | try { |
| 5550 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 5551 | _iterator.return(); |
| 5552 | } |
| 5553 | } finally{ |
| 5554 | if (_didIteratorError) { |
| 5555 | throw _iteratorError; |
| 5556 | } |
| 5557 | } |
| 5558 | } |
| 5559 | return null; |
| 5560 | } |
| 5561 | function updateStacks(controller, parsed) { |
| 5562 | var chart = controller.chart, meta = controller._cachedMeta; |
| 5563 | var stacks = chart._stacks || (chart._stacks = {}); |
| 5564 | var iScale = meta.iScale, vScale = meta.vScale, datasetIndex = meta.index; |
| 5565 | var iAxis = iScale.axis; |
| 5566 | var vAxis = vScale.axis; |
| 5567 | var key = getStackKey(iScale, vScale, meta); |
| 5568 | var ilen = parsed.length; |
| 5569 | var stack; |
| 5570 | for(var i = 0; i < ilen; ++i){ |
| 5571 | var item = parsed[i]; |
| 5572 | var index1 = item[iAxis], value = item[vAxis]; |
| 5573 | var itemStacks = item._stacks || (item._stacks = {}); |
| 5574 | stack = itemStacks[vAxis] = getOrCreateStack(stacks, key, index1); |
| 5575 | stack[datasetIndex] = value; |
| 5576 | stack._top = getLastIndexInStack(stack, vScale, true, meta.type); |
| 5577 | stack._bottom = getLastIndexInStack(stack, vScale, false, meta.type); |
| 5578 | } |
| 5579 | } |
| 5580 | function getFirstScaleId(chart, axis) { |
| 5581 | var scales1 = chart.scales; |
| 5582 | return Object.keys(scales1).filter(function(key) { |
| 5583 | return scales1[key].axis === axis; |
| 5584 | }).shift(); |
| 5585 | } |
| 5586 | function createDatasetContext(parent, index2) { |
| 5587 | return (0, _helpersSegmentJs.h)(parent, { |
| 5588 | active: false, |
| 5589 | dataset: undefined, |
| 5590 | datasetIndex: index2, |
| 5591 | index: index2, |
| 5592 | mode: "default", |
| 5593 | type: "dataset" |
| 5594 | }); |
| 5595 | } |
| 5596 | function createDataContext(parent, index3, element) { |
| 5597 | return (0, _helpersSegmentJs.h)(parent, { |
| 5598 | active: false, |
| 5599 | dataIndex: index3, |
| 5600 | parsed: undefined, |
| 5601 | raw: undefined, |
| 5602 | element: element, |
| 5603 | index: index3, |
| 5604 | mode: "default", |
| 5605 | type: "data" |
| 5606 | }); |
| 5607 | } |
| 5608 | function clearStacks(meta, items) { |
| 5609 | var datasetIndex = meta.controller.index; |
| 5610 | var axis = meta.vScale && meta.vScale.axis; |
| 5611 | if (!axis) return; |
| 5612 | items = items || meta._parsed; |
| 5613 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 5614 | try { |
| 5615 | for(var _iterator = items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 5616 | var parsed = _step.value; |
| 5617 | var stacks = parsed._stacks; |
| 5618 | if (!stacks || stacks[axis] === undefined || stacks[axis][datasetIndex] === undefined) return; |
| 5619 | delete stacks[axis][datasetIndex]; |
| 5620 | } |
| 5621 | } catch (err) { |
| 5622 | _didIteratorError = true; |
| 5623 | _iteratorError = err; |
| 5624 | } finally{ |
| 5625 | try { |
| 5626 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 5627 | _iterator.return(); |
| 5628 | } |
| 5629 | } finally{ |
| 5630 | if (_didIteratorError) { |
| 5631 | throw _iteratorError; |
| 5632 | } |
| 5633 | } |
| 5634 | } |
| 5635 | } |
| 5636 | var isDirectUpdateMode = function(mode) { |
| 5637 | return mode === "reset" || mode === "none"; |
| 5638 | }; |
| 5639 | var cloneIfNotShared = function(cached, shared) { |
| 5640 | return shared ? cached : Object.assign({}, cached); |
| 5641 | }; |
| 5642 | var createStack = function(canStack, meta, chart) { |
| 5643 | return canStack && !meta.hidden && meta._stacked && { |
| 5644 | keys: getSortedDatasetIndices(chart, true), |
| 5645 | values: null |
| 5646 | }; |
| 5647 | }; |
| 5648 | var DatasetController = /*#__PURE__*/ function() { |
| 5649 | "use strict"; |
| 5650 | function DatasetController(chart, datasetIndex) { |
| 5651 | (0, _classCallCheckJsDefault.default)(this, DatasetController); |
| 5652 | this.chart = chart; |
| 5653 | this._ctx = chart.ctx; |
| 5654 | this.index = datasetIndex; |
| 5655 | this._cachedDataOpts = {}; |
| 5656 | this._cachedMeta = this.getMeta(); |
| 5657 | this._type = this._cachedMeta.type; |
| 5658 | this.options = undefined; |
| 5659 | this._parsing = false; |
| 5660 | this._data = undefined; |
| 5661 | this._objectData = undefined; |
| 5662 | this._sharedOptions = undefined; |
| 5663 | this._drawStart = undefined; |
| 5664 | this._drawCount = undefined; |
| 5665 | this.enableOptionSharing = false; |
| 5666 | this.supportsDecimation = false; |
| 5667 | this.$context = undefined; |
| 5668 | this._syncList = []; |
| 5669 | this.initialize(); |
| 5670 | } |
| 5671 | (0, _createClassJsDefault.default)(DatasetController, [ |
| 5672 | { |
| 5673 | key: "initialize", |
| 5674 | value: function initialize() { |
| 5675 | var meta = this._cachedMeta; |
| 5676 | this.configure(); |
| 5677 | this.linkScales(); |
| 5678 | meta._stacked = isStacked(meta.vScale, meta); |
| 5679 | this.addElements(); |
| 5680 | } |
| 5681 | }, |
| 5682 | { |
| 5683 | key: "updateIndex", |
| 5684 | value: function updateIndex(datasetIndex) { |
| 5685 | if (this.index !== datasetIndex) clearStacks(this._cachedMeta); |
| 5686 | this.index = datasetIndex; |
| 5687 | } |
| 5688 | }, |
| 5689 | { |
| 5690 | key: "linkScales", |
| 5691 | value: function linkScales() { |
| 5692 | var chart = this.chart; |
| 5693 | var meta = this._cachedMeta; |
| 5694 | var dataset = this.getDataset(); |
| 5695 | var chooseId = function(axis, x, y, r) { |
| 5696 | return axis === "x" ? x : axis === "r" ? r : y; |
| 5697 | }; |
| 5698 | var xid = meta.xAxisID = (0, _helpersSegmentJs.v)(dataset.xAxisID, getFirstScaleId(chart, "x")); |
| 5699 | var yid = meta.yAxisID = (0, _helpersSegmentJs.v)(dataset.yAxisID, getFirstScaleId(chart, "y")); |
| 5700 | var rid = meta.rAxisID = (0, _helpersSegmentJs.v)(dataset.rAxisID, getFirstScaleId(chart, "r")); |
| 5701 | var indexAxis = meta.indexAxis; |
| 5702 | var iid = meta.iAxisID = chooseId(indexAxis, xid, yid, rid); |
| 5703 | var vid = meta.vAxisID = chooseId(indexAxis, yid, xid, rid); |
| 5704 | meta.xScale = this.getScaleForId(xid); |
| 5705 | meta.yScale = this.getScaleForId(yid); |
| 5706 | meta.rScale = this.getScaleForId(rid); |
| 5707 | meta.iScale = this.getScaleForId(iid); |
| 5708 | meta.vScale = this.getScaleForId(vid); |
| 5709 | } |
| 5710 | }, |
| 5711 | { |
| 5712 | key: "getDataset", |
| 5713 | value: function getDataset() { |
| 5714 | return this.chart.data.datasets[this.index]; |
| 5715 | } |
| 5716 | }, |
| 5717 | { |
| 5718 | key: "getMeta", |
| 5719 | value: function getMeta() { |
| 5720 | return this.chart.getDatasetMeta(this.index); |
| 5721 | } |
| 5722 | }, |
| 5723 | { |
| 5724 | key: "getScaleForId", |
| 5725 | value: function getScaleForId(scaleID) { |
| 5726 | return this.chart.scales[scaleID]; |
| 5727 | } |
| 5728 | }, |
| 5729 | { |
| 5730 | key: "_getOtherScale", |
| 5731 | value: function _getOtherScale(scale) { |
| 5732 | var meta = this._cachedMeta; |
| 5733 | return scale === meta.iScale ? meta.vScale : meta.iScale; |
| 5734 | } |
| 5735 | }, |
| 5736 | { |
| 5737 | key: "reset", |
| 5738 | value: function reset() { |
| 5739 | this._update("reset"); |
| 5740 | } |
| 5741 | }, |
| 5742 | { |
| 5743 | key: "_destroy", |
| 5744 | value: function _destroy() { |
| 5745 | var meta = this._cachedMeta; |
| 5746 | if (this._data) (0, _helpersSegmentJs.u)(this._data, this); |
| 5747 | if (meta._stacked) clearStacks(meta); |
| 5748 | } |
| 5749 | }, |
| 5750 | { |
| 5751 | key: "_dataCheck", |
| 5752 | value: function _dataCheck() { |
| 5753 | var dataset = this.getDataset(); |
| 5754 | var data = dataset.data || (dataset.data = []); |
| 5755 | var _data = this._data; |
| 5756 | if ((0, _helpersSegmentJs.i)(data)) this._data = convertObjectDataToArray(data); |
| 5757 | else if (_data !== data) { |
| 5758 | if (_data) { |
| 5759 | (0, _helpersSegmentJs.u)(_data, this); |
| 5760 | var meta = this._cachedMeta; |
| 5761 | clearStacks(meta); |
| 5762 | meta._parsed = []; |
| 5763 | } |
| 5764 | if (data && Object.isExtensible(data)) (0, _helpersSegmentJs.l)(data, this); |
| 5765 | this._syncList = []; |
| 5766 | this._data = data; |
| 5767 | } |
| 5768 | } |
| 5769 | }, |
| 5770 | { |
| 5771 | key: "addElements", |
| 5772 | value: function addElements() { |
| 5773 | var meta = this._cachedMeta; |
| 5774 | this._dataCheck(); |
| 5775 | if (this.datasetElementType) meta.dataset = new this.datasetElementType(); |
| 5776 | } |
| 5777 | }, |
| 5778 | { |
| 5779 | key: "buildOrUpdateElements", |
| 5780 | value: function buildOrUpdateElements(resetNewElements) { |
| 5781 | var meta = this._cachedMeta; |
| 5782 | var dataset = this.getDataset(); |
| 5783 | var stackChanged = false; |
| 5784 | this._dataCheck(); |
| 5785 | var oldStacked = meta._stacked; |
| 5786 | meta._stacked = isStacked(meta.vScale, meta); |
| 5787 | if (meta.stack !== dataset.stack) { |
| 5788 | stackChanged = true; |
| 5789 | clearStacks(meta); |
| 5790 | meta.stack = dataset.stack; |
| 5791 | } |
| 5792 | this._resyncElements(resetNewElements); |
| 5793 | if (stackChanged || oldStacked !== meta._stacked) updateStacks(this, meta._parsed); |
| 5794 | } |
| 5795 | }, |
| 5796 | { |
| 5797 | key: "configure", |
| 5798 | value: function configure() { |
| 5799 | var config = this.chart.config; |
| 5800 | var scopeKeys = config.datasetScopeKeys(this._type); |
| 5801 | var scopes = config.getOptionScopes(this.getDataset(), scopeKeys, true); |
| 5802 | this.options = config.createResolver(scopes, this.getContext()); |
| 5803 | this._parsing = this.options.parsing; |
| 5804 | this._cachedDataOpts = {}; |
| 5805 | } |
| 5806 | }, |
| 5807 | { |
| 5808 | key: "parse", |
| 5809 | value: function parse1(start, count) { |
| 5810 | var ref = this, meta = ref._cachedMeta, data = ref._data; |
| 5811 | var iScale = meta.iScale, _stacked = meta._stacked; |
| 5812 | var iAxis = iScale.axis; |
| 5813 | var sorted = start === 0 && count === data.length ? true : meta._sorted; |
| 5814 | var prev = start > 0 && meta._parsed[start - 1]; |
| 5815 | var i, cur, parsed; |
| 5816 | if (this._parsing === false) { |
| 5817 | meta._parsed = data; |
| 5818 | meta._sorted = true; |
| 5819 | parsed = data; |
| 5820 | } else { |
| 5821 | if ((0, _helpersSegmentJs.b)(data[start])) parsed = this.parseArrayData(meta, data, start, count); |
| 5822 | else if ((0, _helpersSegmentJs.i)(data[start])) parsed = this.parseObjectData(meta, data, start, count); |
| 5823 | else parsed = this.parsePrimitiveData(meta, data, start, count); |
| 5824 | var isNotInOrderComparedToPrev = function() { |
| 5825 | return cur[iAxis] === null || prev && cur[iAxis] < prev[iAxis]; |
| 5826 | }; |
| 5827 | for(i = 0; i < count; ++i){ |
| 5828 | meta._parsed[i + start] = cur = parsed[i]; |
| 5829 | if (sorted) { |
| 5830 | if (isNotInOrderComparedToPrev()) sorted = false; |
| 5831 | prev = cur; |
| 5832 | } |
| 5833 | } |
| 5834 | meta._sorted = sorted; |
| 5835 | } |
| 5836 | if (_stacked) updateStacks(this, parsed); |
| 5837 | } |
| 5838 | }, |
| 5839 | { |
| 5840 | key: "parsePrimitiveData", |
| 5841 | value: function parsePrimitiveData(meta, data, start, count) { |
| 5842 | var iScale = meta.iScale, vScale = meta.vScale; |
| 5843 | var iAxis = iScale.axis; |
| 5844 | var vAxis = vScale.axis; |
| 5845 | var labels = iScale.getLabels(); |
| 5846 | var singleScale = iScale === vScale; |
| 5847 | var parsed = new Array(count); |
| 5848 | var i, ilen, index4; |
| 5849 | for(i = 0, ilen = count; i < ilen; ++i){ |
| 5850 | index4 = i + start; |
| 5851 | var _obj; |
| 5852 | parsed[i] = (_obj = {}, (0, _definePropertyJsDefault.default)(_obj, iAxis, singleScale || iScale.parse(labels[index4], index4)), (0, _definePropertyJsDefault.default)(_obj, vAxis, vScale.parse(data[index4], index4)), _obj); |
| 5853 | } |
| 5854 | return parsed; |
| 5855 | } |
| 5856 | }, |
| 5857 | { |
| 5858 | key: "parseArrayData", |
| 5859 | value: function parseArrayData(meta, data, start, count) { |
| 5860 | var xScale = meta.xScale, yScale = meta.yScale; |
| 5861 | var parsed = new Array(count); |
| 5862 | var i, ilen, index5, item; |
| 5863 | for(i = 0, ilen = count; i < ilen; ++i){ |
| 5864 | index5 = i + start; |
| 5865 | item = data[index5]; |
| 5866 | parsed[i] = { |
| 5867 | x: xScale.parse(item[0], index5), |
| 5868 | y: yScale.parse(item[1], index5) |
| 5869 | }; |
| 5870 | } |
| 5871 | return parsed; |
| 5872 | } |
| 5873 | }, |
| 5874 | { |
| 5875 | key: "parseObjectData", |
| 5876 | value: function parseObjectData(meta, data, start, count) { |
| 5877 | var xScale = meta.xScale, yScale = meta.yScale; |
| 5878 | var __parsing = this._parsing, _xAxisKey = __parsing.xAxisKey, xAxisKey = _xAxisKey === void 0 ? "x" : _xAxisKey, _yAxisKey = __parsing.yAxisKey, yAxisKey = _yAxisKey === void 0 ? "y" : _yAxisKey; |
| 5879 | var parsed = new Array(count); |
| 5880 | var i, ilen, index6, item; |
| 5881 | for(i = 0, ilen = count; i < ilen; ++i){ |
| 5882 | index6 = i + start; |
| 5883 | item = data[index6]; |
| 5884 | parsed[i] = { |
| 5885 | x: xScale.parse((0, _helpersSegmentJs.f)(item, xAxisKey), index6), |
| 5886 | y: yScale.parse((0, _helpersSegmentJs.f)(item, yAxisKey), index6) |
| 5887 | }; |
| 5888 | } |
| 5889 | return parsed; |
| 5890 | } |
| 5891 | }, |
| 5892 | { |
| 5893 | key: "getParsed", |
| 5894 | value: function getParsed(index7) { |
| 5895 | return this._cachedMeta._parsed[index7]; |
| 5896 | } |
| 5897 | }, |
| 5898 | { |
| 5899 | key: "getDataElement", |
| 5900 | value: function getDataElement(index8) { |
| 5901 | return this._cachedMeta.data[index8]; |
| 5902 | } |
| 5903 | }, |
| 5904 | { |
| 5905 | key: "applyStack", |
| 5906 | value: function applyStack1(scale, parsed, mode) { |
| 5907 | var chart = this.chart; |
| 5908 | var meta = this._cachedMeta; |
| 5909 | var value = parsed[scale.axis]; |
| 5910 | var stack = { |
| 5911 | keys: getSortedDatasetIndices(chart, true), |
| 5912 | values: parsed._stacks[scale.axis] |
| 5913 | }; |
| 5914 | return applyStack(stack, value, meta.index, { |
| 5915 | mode: mode |
| 5916 | }); |
| 5917 | } |
| 5918 | }, |
| 5919 | { |
| 5920 | key: "updateRangeFromParsed", |
| 5921 | value: function updateRangeFromParsed(range, scale, parsed, stack) { |
| 5922 | var parsedValue = parsed[scale.axis]; |
| 5923 | var value = parsedValue === null ? NaN : parsedValue; |
| 5924 | var values = stack && parsed._stacks[scale.axis]; |
| 5925 | if (stack && values) { |
| 5926 | stack.values = values; |
| 5927 | value = applyStack(stack, parsedValue, this._cachedMeta.index); |
| 5928 | } |
| 5929 | range.min = Math.min(range.min, value); |
| 5930 | range.max = Math.max(range.max, value); |
| 5931 | } |
| 5932 | }, |
| 5933 | { |
| 5934 | key: "getMinMax", |
| 5935 | value: function getMinMax(scale, canStack) { |
| 5936 | var meta = this._cachedMeta; |
| 5937 | var _parsed = meta._parsed; |
| 5938 | var sorted = meta._sorted && scale === meta.iScale; |
| 5939 | var ilen = _parsed.length; |
| 5940 | var otherScale = this._getOtherScale(scale); |
| 5941 | var stack = createStack(canStack, meta, this.chart); |
| 5942 | var range = { |
| 5943 | min: Number.POSITIVE_INFINITY, |
| 5944 | max: Number.NEGATIVE_INFINITY |
| 5945 | }; |
| 5946 | var ref = getUserBounds(otherScale), otherMin = ref.min, otherMax = ref.max; |
| 5947 | var i, parsed; |
| 5948 | function _skip() { |
| 5949 | parsed = _parsed[i]; |
| 5950 | var otherValue = parsed[otherScale.axis]; |
| 5951 | return !(0, _helpersSegmentJs.g)(parsed[scale.axis]) || otherMin > otherValue || otherMax < otherValue; |
| 5952 | } |
| 5953 | for(i = 0; i < ilen; ++i){ |
| 5954 | if (_skip()) continue; |
| 5955 | this.updateRangeFromParsed(range, scale, parsed, stack); |
| 5956 | if (sorted) break; |
| 5957 | } |
| 5958 | if (sorted) for(i = ilen - 1; i >= 0; --i){ |
| 5959 | if (_skip()) continue; |
| 5960 | this.updateRangeFromParsed(range, scale, parsed, stack); |
| 5961 | break; |
| 5962 | } |
| 5963 | return range; |
| 5964 | } |
| 5965 | }, |
| 5966 | { |
| 5967 | key: "getAllParsedValues", |
| 5968 | value: function getAllParsedValues(scale) { |
| 5969 | var parsed = this._cachedMeta._parsed; |
| 5970 | var values = []; |
| 5971 | var i, ilen, value; |
| 5972 | for(i = 0, ilen = parsed.length; i < ilen; ++i){ |
| 5973 | value = parsed[i][scale.axis]; |
| 5974 | if ((0, _helpersSegmentJs.g)(value)) values.push(value); |
| 5975 | } |
| 5976 | return values; |
| 5977 | } |
| 5978 | }, |
| 5979 | { |
| 5980 | key: "getMaxOverflow", |
| 5981 | value: function getMaxOverflow() { |
| 5982 | return false; |
| 5983 | } |
| 5984 | }, |
| 5985 | { |
| 5986 | key: "getLabelAndValue", |
| 5987 | value: function getLabelAndValue(index9) { |
| 5988 | var meta = this._cachedMeta; |
| 5989 | var iScale = meta.iScale; |
| 5990 | var vScale = meta.vScale; |
| 5991 | var parsed = this.getParsed(index9); |
| 5992 | return { |
| 5993 | label: iScale ? "" + iScale.getLabelForValue(parsed[iScale.axis]) : "", |
| 5994 | value: vScale ? "" + vScale.getLabelForValue(parsed[vScale.axis]) : "" |
| 5995 | }; |
| 5996 | } |
| 5997 | }, |
| 5998 | { |
| 5999 | key: "_update", |
| 6000 | value: function _update(mode) { |
| 6001 | var meta = this._cachedMeta; |
| 6002 | this.update(mode || "default"); |
| 6003 | meta._clip = toClip((0, _helpersSegmentJs.v)(this.options.clip, defaultClip(meta.xScale, meta.yScale, this.getMaxOverflow()))); |
| 6004 | } |
| 6005 | }, |
| 6006 | { |
| 6007 | key: "update", |
| 6008 | value: function update(mode) {} |
| 6009 | }, |
| 6010 | { |
| 6011 | key: "draw", |
| 6012 | value: function draw2() { |
| 6013 | var ctx = this._ctx; |
| 6014 | var chart = this.chart; |
| 6015 | var meta = this._cachedMeta; |
| 6016 | var elements1 = meta.data || []; |
| 6017 | var area = chart.chartArea; |
| 6018 | var active = []; |
| 6019 | var start = this._drawStart || 0; |
| 6020 | var count = this._drawCount || elements1.length - start; |
| 6021 | var drawActiveElementsOnTop = this.options.drawActiveElementsOnTop; |
| 6022 | var i; |
| 6023 | if (meta.dataset) meta.dataset.draw(ctx, area, start, count); |
| 6024 | for(i = start; i < start + count; ++i){ |
| 6025 | var element = elements1[i]; |
| 6026 | if (element.hidden) continue; |
| 6027 | if (element.active && drawActiveElementsOnTop) active.push(element); |
| 6028 | else element.draw(ctx, area); |
| 6029 | } |
| 6030 | for(i = 0; i < active.length; ++i)active[i].draw(ctx, area); |
| 6031 | } |
| 6032 | }, |
| 6033 | { |
| 6034 | key: "getStyle", |
| 6035 | value: function getStyle(index10, active) { |
| 6036 | var mode = active ? "active" : "default"; |
| 6037 | return index10 === undefined && this._cachedMeta.dataset ? this.resolveDatasetElementOptions(mode) : this.resolveDataElementOptions(index10 || 0, mode); |
| 6038 | } |
| 6039 | }, |
| 6040 | { |
| 6041 | key: "getContext", |
| 6042 | value: function getContext(index11, active, mode) { |
| 6043 | var dataset = this.getDataset(); |
| 6044 | var context; |
| 6045 | if (index11 >= 0 && index11 < this._cachedMeta.data.length) { |
| 6046 | var element = this._cachedMeta.data[index11]; |
| 6047 | context = element.$context || (element.$context = createDataContext(this.getContext(), index11, element)); |
| 6048 | context.parsed = this.getParsed(index11); |
| 6049 | context.raw = dataset.data[index11]; |
| 6050 | context.index = context.dataIndex = index11; |
| 6051 | } else { |
| 6052 | context = this.$context || (this.$context = createDatasetContext(this.chart.getContext(), this.index)); |
| 6053 | context.dataset = dataset; |
| 6054 | context.index = context.datasetIndex = this.index; |
| 6055 | } |
| 6056 | context.active = !!active; |
| 6057 | context.mode = mode; |
| 6058 | return context; |
| 6059 | } |
| 6060 | }, |
| 6061 | { |
| 6062 | key: "resolveDatasetElementOptions", |
| 6063 | value: function resolveDatasetElementOptions(mode) { |
| 6064 | return this._resolveElementOptions(this.datasetElementType.id, mode); |
| 6065 | } |
| 6066 | }, |
| 6067 | { |
| 6068 | key: "resolveDataElementOptions", |
| 6069 | value: function resolveDataElementOptions(index12, mode) { |
| 6070 | return this._resolveElementOptions(this.dataElementType.id, mode, index12); |
| 6071 | } |
| 6072 | }, |
| 6073 | { |
| 6074 | key: "_resolveElementOptions", |
| 6075 | value: function _resolveElementOptions(elementType) { |
| 6076 | var mode = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "default", index13 = arguments.length > 2 ? arguments[2] : void 0; |
| 6077 | var _this = this; |
| 6078 | var active = mode === "active"; |
| 6079 | var cache = this._cachedDataOpts; |
| 6080 | var cacheKey = elementType + "-" + mode; |
| 6081 | var cached = cache[cacheKey]; |
| 6082 | var sharing = this.enableOptionSharing && (0, _helpersSegmentJs.j)(index13); |
| 6083 | if (cached) return cloneIfNotShared(cached, sharing); |
| 6084 | var config = this.chart.config; |
| 6085 | var scopeKeys = config.datasetElementScopeKeys(this._type, elementType); |
| 6086 | var prefixes = active ? [ |
| 6087 | "".concat(elementType, "Hover"), |
| 6088 | "hover", |
| 6089 | elementType, |
| 6090 | "" |
| 6091 | ] : [ |
| 6092 | elementType, |
| 6093 | "" |
| 6094 | ]; |
| 6095 | var scopes = config.getOptionScopes(this.getDataset(), scopeKeys); |
| 6096 | var names = Object.keys((0, _helpersSegmentJs.d).elements[elementType]); |
| 6097 | var context = function() { |
| 6098 | return _this.getContext(index13, active); |
| 6099 | }; |
| 6100 | var values = config.resolveNamedOptions(scopes, names, context, prefixes); |
| 6101 | if (values.$shared) { |
| 6102 | values.$shared = sharing; |
| 6103 | cache[cacheKey] = Object.freeze(cloneIfNotShared(values, sharing)); |
| 6104 | } |
| 6105 | return values; |
| 6106 | } |
| 6107 | }, |
| 6108 | { |
| 6109 | key: "_resolveAnimations", |
| 6110 | value: function _resolveAnimations(index14, transition, active) { |
| 6111 | var chart = this.chart; |
| 6112 | var cache = this._cachedDataOpts; |
| 6113 | var cacheKey = "animation-".concat(transition); |
| 6114 | var cached = cache[cacheKey]; |
| 6115 | if (cached) return cached; |
| 6116 | var options; |
| 6117 | if (chart.options.animation !== false) { |
| 6118 | var config = this.chart.config; |
| 6119 | var scopeKeys = config.datasetAnimationScopeKeys(this._type, transition); |
| 6120 | var scopes = config.getOptionScopes(this.getDataset(), scopeKeys); |
| 6121 | options = config.createResolver(scopes, this.getContext(index14, active, transition)); |
| 6122 | } |
| 6123 | var animations = new Animations(chart, options && options.animations); |
| 6124 | if (options && options._cacheable) cache[cacheKey] = Object.freeze(animations); |
| 6125 | return animations; |
| 6126 | } |
| 6127 | }, |
| 6128 | { |
| 6129 | key: "getSharedOptions", |
| 6130 | value: function getSharedOptions(options) { |
| 6131 | if (!options.$shared) return; |
| 6132 | return this._sharedOptions || (this._sharedOptions = Object.assign({}, options)); |
| 6133 | } |
| 6134 | }, |
| 6135 | { |
| 6136 | key: "includeOptions", |
| 6137 | value: function includeOptions(mode, sharedOptions) { |
| 6138 | return !sharedOptions || isDirectUpdateMode(mode) || this.chart._animationsDisabled; |
| 6139 | } |
| 6140 | }, |
| 6141 | { |
| 6142 | key: "updateElement", |
| 6143 | value: function updateElement(element, index15, properties, mode) { |
| 6144 | if (isDirectUpdateMode(mode)) Object.assign(element, properties); |
| 6145 | else this._resolveAnimations(index15, mode).update(element, properties); |
| 6146 | } |
| 6147 | }, |
| 6148 | { |
| 6149 | key: "updateSharedOptions", |
| 6150 | value: function updateSharedOptions(sharedOptions, mode, newOptions) { |
| 6151 | if (sharedOptions && !isDirectUpdateMode(mode)) this._resolveAnimations(undefined, mode).update(sharedOptions, newOptions); |
| 6152 | } |
| 6153 | }, |
| 6154 | { |
| 6155 | key: "_setStyle", |
| 6156 | value: function _setStyle(element, index16, mode, active) { |
| 6157 | element.active = active; |
| 6158 | var options = this.getStyle(index16, active); |
| 6159 | this._resolveAnimations(index16, mode, active).update(element, { |
| 6160 | options: !active && this.getSharedOptions(options) || options |
| 6161 | }); |
| 6162 | } |
| 6163 | }, |
| 6164 | { |
| 6165 | key: "removeHoverStyle", |
| 6166 | value: function removeHoverStyle(element, datasetIndex, index17) { |
| 6167 | this._setStyle(element, index17, "active", false); |
| 6168 | } |
| 6169 | }, |
| 6170 | { |
| 6171 | key: "setHoverStyle", |
| 6172 | value: function setHoverStyle(element, datasetIndex, index18) { |
| 6173 | this._setStyle(element, index18, "active", true); |
| 6174 | } |
| 6175 | }, |
| 6176 | { |
| 6177 | key: "_removeDatasetHoverStyle", |
| 6178 | value: function _removeDatasetHoverStyle() { |
| 6179 | var element = this._cachedMeta.dataset; |
| 6180 | if (element) this._setStyle(element, undefined, "active", false); |
| 6181 | } |
| 6182 | }, |
| 6183 | { |
| 6184 | key: "_setDatasetHoverStyle", |
| 6185 | value: function _setDatasetHoverStyle() { |
| 6186 | var element = this._cachedMeta.dataset; |
| 6187 | if (element) this._setStyle(element, undefined, "active", true); |
| 6188 | } |
| 6189 | }, |
| 6190 | { |
| 6191 | key: "_resyncElements", |
| 6192 | value: function _resyncElements(resetNewElements) { |
| 6193 | var data = this._data; |
| 6194 | var elements2 = this._cachedMeta.data; |
| 6195 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 6196 | try { |
| 6197 | for(var _iterator = this._syncList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 6198 | var _value = (0, _slicedToArrayJsDefault.default)(_step.value, 3), method = _value[0], arg1 = _value[1], arg2 = _value[2]; |
| 6199 | this[method](arg1, arg2); |
| 6200 | } |
| 6201 | } catch (err) { |
| 6202 | _didIteratorError = true; |
| 6203 | _iteratorError = err; |
| 6204 | } finally{ |
| 6205 | try { |
| 6206 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 6207 | _iterator.return(); |
| 6208 | } |
| 6209 | } finally{ |
| 6210 | if (_didIteratorError) { |
| 6211 | throw _iteratorError; |
| 6212 | } |
| 6213 | } |
| 6214 | } |
| 6215 | this._syncList = []; |
| 6216 | var numMeta = elements2.length; |
| 6217 | var numData = data.length; |
| 6218 | var count = Math.min(numData, numMeta); |
| 6219 | if (count) this.parse(0, count); |
| 6220 | if (numData > numMeta) this._insertElements(numMeta, numData - numMeta, resetNewElements); |
| 6221 | else if (numData < numMeta) this._removeElements(numData, numMeta - numData); |
| 6222 | } |
| 6223 | }, |
| 6224 | { |
| 6225 | key: "_insertElements", |
| 6226 | value: function _insertElements(start, count) { |
| 6227 | var resetNewElements = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true; |
| 6228 | var meta = this._cachedMeta; |
| 6229 | var data = meta.data; |
| 6230 | var end = start + count; |
| 6231 | var i; |
| 6232 | var move = function(arr) { |
| 6233 | arr.length += count; |
| 6234 | for(i = arr.length - 1; i >= end; i--)arr[i] = arr[i - count]; |
| 6235 | }; |
| 6236 | move(data); |
| 6237 | for(i = start; i < end; ++i)data[i] = new this.dataElementType(); |
| 6238 | if (this._parsing) move(meta._parsed); |
| 6239 | this.parse(start, count); |
| 6240 | if (resetNewElements) this.updateElements(data, start, count, "reset"); |
| 6241 | } |
| 6242 | }, |
| 6243 | { |
| 6244 | key: "updateElements", |
| 6245 | value: function updateElements(element, start, count, mode) {} |
| 6246 | }, |
| 6247 | { |
| 6248 | key: "_removeElements", |
| 6249 | value: function _removeElements(start, count) { |
| 6250 | var meta = this._cachedMeta; |
| 6251 | if (this._parsing) { |
| 6252 | var removed = meta._parsed.splice(start, count); |
| 6253 | if (meta._stacked) clearStacks(meta, removed); |
| 6254 | } |
| 6255 | meta.data.splice(start, count); |
| 6256 | } |
| 6257 | }, |
| 6258 | { |
| 6259 | key: "_sync", |
| 6260 | value: function _sync(args) { |
| 6261 | if (this._parsing) this._syncList.push(args); |
| 6262 | else { |
| 6263 | var _args = (0, _slicedToArrayJsDefault.default)(args, 3), method = _args[0], arg1 = _args[1], arg2 = _args[2]; |
| 6264 | this[method](arg1, arg2); |
| 6265 | } |
| 6266 | this.chart._dataChanges.push([ |
| 6267 | this.index |
| 6268 | ].concat((0, _toConsumableArrayJsDefault.default)(args))); |
| 6269 | } |
| 6270 | }, |
| 6271 | { |
| 6272 | key: "_onDataPush", |
| 6273 | value: function _onDataPush() { |
| 6274 | var count = arguments.length; |
| 6275 | this._sync([ |
| 6276 | "_insertElements", |
| 6277 | this.getDataset().data.length - count, |
| 6278 | count |
| 6279 | ]); |
| 6280 | } |
| 6281 | }, |
| 6282 | { |
| 6283 | key: "_onDataPop", |
| 6284 | value: function _onDataPop() { |
| 6285 | this._sync([ |
| 6286 | "_removeElements", |
| 6287 | this._cachedMeta.data.length - 1, |
| 6288 | 1 |
| 6289 | ]); |
| 6290 | } |
| 6291 | }, |
| 6292 | { |
| 6293 | key: "_onDataShift", |
| 6294 | value: function _onDataShift() { |
| 6295 | this._sync([ |
| 6296 | "_removeElements", |
| 6297 | 0, |
| 6298 | 1 |
| 6299 | ]); |
| 6300 | } |
| 6301 | }, |
| 6302 | { |
| 6303 | key: "_onDataSplice", |
| 6304 | value: function _onDataSplice(start, count) { |
| 6305 | if (count) this._sync([ |
| 6306 | "_removeElements", |
| 6307 | start, |
| 6308 | count |
| 6309 | ]); |
| 6310 | var newCount = arguments.length - 2; |
| 6311 | if (newCount) this._sync([ |
| 6312 | "_insertElements", |
| 6313 | start, |
| 6314 | newCount |
| 6315 | ]); |
| 6316 | } |
| 6317 | }, |
| 6318 | { |
| 6319 | key: "_onDataUnshift", |
| 6320 | value: function _onDataUnshift() { |
| 6321 | this._sync([ |
| 6322 | "_insertElements", |
| 6323 | 0, |
| 6324 | arguments.length |
| 6325 | ]); |
| 6326 | } |
| 6327 | } |
| 6328 | ]); |
| 6329 | return DatasetController; |
| 6330 | }(); |
| 6331 | DatasetController.defaults = {}; |
| 6332 | DatasetController.prototype.datasetElementType = null; |
| 6333 | DatasetController.prototype.dataElementType = null; |
| 6334 | function getAllScaleValues(scale, type) { |
| 6335 | if (!scale._cache.$bar) { |
| 6336 | var visibleMetas = scale.getMatchingVisibleMetas(type); |
| 6337 | var values = []; |
| 6338 | for(var i = 0, ilen = visibleMetas.length; i < ilen; i++)values = values.concat(visibleMetas[i].controller.getAllParsedValues(scale)); |
| 6339 | scale._cache.$bar = (0, _helpersSegmentJs._)(values.sort(function(a, b) { |
| 6340 | return a - b; |
| 6341 | })); |
| 6342 | } |
| 6343 | return scale._cache.$bar; |
| 6344 | } |
| 6345 | function computeMinSampleSize(meta) { |
| 6346 | var scale = meta.iScale; |
| 6347 | var values = getAllScaleValues(scale, meta.type); |
| 6348 | var min = scale._length; |
| 6349 | var i, ilen, curr, prev; |
| 6350 | var updateMinAndPrev = function() { |
| 6351 | if (curr === 32767 || curr === -32768) return; |
| 6352 | if ((0, _helpersSegmentJs.j)(prev)) min = Math.min(min, Math.abs(curr - prev) || min); |
| 6353 | prev = curr; |
| 6354 | }; |
| 6355 | for(i = 0, ilen = values.length; i < ilen; ++i){ |
| 6356 | curr = scale.getPixelForValue(values[i]); |
| 6357 | updateMinAndPrev(); |
| 6358 | } |
| 6359 | prev = undefined; |
| 6360 | for(i = 0, ilen = scale.ticks.length; i < ilen; ++i){ |
| 6361 | curr = scale.getPixelForTick(i); |
| 6362 | updateMinAndPrev(); |
| 6363 | } |
| 6364 | return min; |
| 6365 | } |
| 6366 | function computeFitCategoryTraits(index19, ruler, options, stackCount) { |
| 6367 | var thickness = options.barThickness; |
| 6368 | var size, ratio; |
| 6369 | if ((0, _helpersSegmentJs.k)(thickness)) { |
| 6370 | size = ruler.min * options.categoryPercentage; |
| 6371 | ratio = options.barPercentage; |
| 6372 | } else { |
| 6373 | size = thickness * stackCount; |
| 6374 | ratio = 1; |
| 6375 | } |
| 6376 | return { |
| 6377 | chunk: size / stackCount, |
| 6378 | ratio: ratio, |
| 6379 | start: ruler.pixels[index19] - size / 2 |
| 6380 | }; |
| 6381 | } |
| 6382 | function computeFlexCategoryTraits(index20, ruler, options, stackCount) { |
| 6383 | var pixels = ruler.pixels; |
| 6384 | var curr = pixels[index20]; |
| 6385 | var prev = index20 > 0 ? pixels[index20 - 1] : null; |
| 6386 | var next = index20 < pixels.length - 1 ? pixels[index20 + 1] : null; |
| 6387 | var percent = options.categoryPercentage; |
| 6388 | if (prev === null) prev = curr - (next === null ? ruler.end - ruler.start : next - curr); |
| 6389 | if (next === null) next = curr + curr - prev; |
| 6390 | var start = curr - (curr - Math.min(prev, next)) / 2 * percent; |
| 6391 | var size = Math.abs(next - prev) / 2 * percent; |
| 6392 | return { |
| 6393 | chunk: size / stackCount, |
| 6394 | ratio: options.barPercentage, |
| 6395 | start: start |
| 6396 | }; |
| 6397 | } |
| 6398 | function parseFloatBar(entry, item, vScale, i) { |
| 6399 | var startValue = vScale.parse(entry[0], i); |
| 6400 | var endValue = vScale.parse(entry[1], i); |
| 6401 | var min = Math.min(startValue, endValue); |
| 6402 | var max = Math.max(startValue, endValue); |
| 6403 | var barStart = min; |
| 6404 | var barEnd = max; |
| 6405 | if (Math.abs(min) > Math.abs(max)) { |
| 6406 | barStart = max; |
| 6407 | barEnd = min; |
| 6408 | } |
| 6409 | item[vScale.axis] = barEnd; |
| 6410 | item._custom = { |
| 6411 | barStart: barStart, |
| 6412 | barEnd: barEnd, |
| 6413 | start: startValue, |
| 6414 | end: endValue, |
| 6415 | min: min, |
| 6416 | max: max |
| 6417 | }; |
| 6418 | } |
| 6419 | function parseValue(entry, item, vScale, i) { |
| 6420 | if ((0, _helpersSegmentJs.b)(entry)) parseFloatBar(entry, item, vScale, i); |
| 6421 | else item[vScale.axis] = vScale.parse(entry, i); |
| 6422 | return item; |
| 6423 | } |
| 6424 | function parseArrayOrPrimitive(meta, data, start, count) { |
| 6425 | var iScale = meta.iScale; |
| 6426 | var vScale = meta.vScale; |
| 6427 | var labels = iScale.getLabels(); |
| 6428 | var singleScale = iScale === vScale; |
| 6429 | var parsed = []; |
| 6430 | var i, ilen, item, entry; |
| 6431 | for(i = start, ilen = start + count; i < ilen; ++i){ |
| 6432 | entry = data[i]; |
| 6433 | item = {}; |
| 6434 | item[iScale.axis] = singleScale || iScale.parse(labels[i], i); |
| 6435 | parsed.push(parseValue(entry, item, vScale, i)); |
| 6436 | } |
| 6437 | return parsed; |
| 6438 | } |
| 6439 | function isFloatBar(custom) { |
| 6440 | return custom && custom.barStart !== undefined && custom.barEnd !== undefined; |
| 6441 | } |
| 6442 | function barSign(size, vScale, actualBase) { |
| 6443 | if (size !== 0) return (0, _helpersSegmentJs.s)(size); |
| 6444 | return (vScale.isHorizontal() ? 1 : -1) * (vScale.min >= actualBase ? 1 : -1); |
| 6445 | } |
| 6446 | function borderProps(properties) { |
| 6447 | var reverse, start, end, top, bottom; |
| 6448 | if (properties.horizontal) { |
| 6449 | reverse = properties.base > properties.x; |
| 6450 | start = "left"; |
| 6451 | end = "right"; |
| 6452 | } else { |
| 6453 | reverse = properties.base < properties.y; |
| 6454 | start = "bottom"; |
| 6455 | end = "top"; |
| 6456 | } |
| 6457 | if (reverse) { |
| 6458 | top = "end"; |
| 6459 | bottom = "start"; |
| 6460 | } else { |
| 6461 | top = "start"; |
| 6462 | bottom = "end"; |
| 6463 | } |
| 6464 | return { |
| 6465 | start: start, |
| 6466 | end: end, |
| 6467 | reverse: reverse, |
| 6468 | top: top, |
| 6469 | bottom: bottom |
| 6470 | }; |
| 6471 | } |
| 6472 | function setBorderSkipped(properties, options, stack, index21) { |
| 6473 | var edge = options.borderSkipped; |
| 6474 | var res = {}; |
| 6475 | if (!edge) { |
| 6476 | properties.borderSkipped = res; |
| 6477 | return; |
| 6478 | } |
| 6479 | var ref = borderProps(properties), start = ref.start, end = ref.end, reverse = ref.reverse, top = ref.top, bottom = ref.bottom; |
| 6480 | if (edge === "middle" && stack) { |
| 6481 | properties.enableBorderRadius = true; |
| 6482 | if ((stack._top || 0) === index21) edge = top; |
| 6483 | else if ((stack._bottom || 0) === index21) edge = bottom; |
| 6484 | else { |
| 6485 | res[parseEdge(bottom, start, end, reverse)] = true; |
| 6486 | edge = top; |
| 6487 | } |
| 6488 | } |
| 6489 | res[parseEdge(edge, start, end, reverse)] = true; |
| 6490 | properties.borderSkipped = res; |
| 6491 | } |
| 6492 | function parseEdge(edge, a, b, reverse) { |
| 6493 | if (reverse) { |
| 6494 | edge = swap(edge, a, b); |
| 6495 | edge = startEnd(edge, b, a); |
| 6496 | } else edge = startEnd(edge, a, b); |
| 6497 | return edge; |
| 6498 | } |
| 6499 | function swap(orig, v1, v2) { |
| 6500 | return orig === v1 ? v2 : orig === v2 ? v1 : orig; |
| 6501 | } |
| 6502 | function startEnd(v, start, end) { |
| 6503 | return v === "start" ? start : v === "end" ? end : v; |
| 6504 | } |
| 6505 | function setInflateAmount(properties, param, ratio) { |
| 6506 | var inflateAmount = param.inflateAmount; |
| 6507 | properties.inflateAmount = inflateAmount === "auto" ? ratio === 1 ? 0.33 : 0 : inflateAmount; |
| 6508 | } |
| 6509 | var BarController = /*#__PURE__*/ function(DatasetController) { |
| 6510 | "use strict"; |
| 6511 | (0, _inheritsJsDefault.default)(BarController, DatasetController); |
| 6512 | var _super = (0, _createSuperJsDefault.default)(BarController); |
| 6513 | function BarController() { |
| 6514 | (0, _classCallCheckJsDefault.default)(this, BarController); |
| 6515 | return _super.apply(this, arguments); |
| 6516 | } |
| 6517 | (0, _createClassJsDefault.default)(BarController, [ |
| 6518 | { |
| 6519 | key: "parsePrimitiveData", |
| 6520 | value: function parsePrimitiveData(meta, data, start, count) { |
| 6521 | return parseArrayOrPrimitive(meta, data, start, count); |
| 6522 | } |
| 6523 | }, |
| 6524 | { |
| 6525 | key: "parseArrayData", |
| 6526 | value: function parseArrayData(meta, data, start, count) { |
| 6527 | return parseArrayOrPrimitive(meta, data, start, count); |
| 6528 | } |
| 6529 | }, |
| 6530 | { |
| 6531 | key: "parseObjectData", |
| 6532 | value: function parseObjectData(meta, data, start, count) { |
| 6533 | var iScale = meta.iScale, vScale = meta.vScale; |
| 6534 | var __parsing = this._parsing, _xAxisKey = __parsing.xAxisKey, xAxisKey = _xAxisKey === void 0 ? "x" : _xAxisKey, _yAxisKey = __parsing.yAxisKey, yAxisKey = _yAxisKey === void 0 ? "y" : _yAxisKey; |
| 6535 | var iAxisKey = iScale.axis === "x" ? xAxisKey : yAxisKey; |
| 6536 | var vAxisKey = vScale.axis === "x" ? xAxisKey : yAxisKey; |
| 6537 | var parsed = []; |
| 6538 | var i, ilen, item, obj; |
| 6539 | for(i = start, ilen = start + count; i < ilen; ++i){ |
| 6540 | obj = data[i]; |
| 6541 | item = {}; |
| 6542 | item[iScale.axis] = iScale.parse((0, _helpersSegmentJs.f)(obj, iAxisKey), i); |
| 6543 | parsed.push(parseValue((0, _helpersSegmentJs.f)(obj, vAxisKey), item, vScale, i)); |
| 6544 | } |
| 6545 | return parsed; |
| 6546 | } |
| 6547 | }, |
| 6548 | { |
| 6549 | key: "updateRangeFromParsed", |
| 6550 | value: function updateRangeFromParsed(range, scale, parsed, stack) { |
| 6551 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(BarController.prototype), "updateRangeFromParsed", this).call(this, range, scale, parsed, stack); |
| 6552 | var custom = parsed._custom; |
| 6553 | if (custom && scale === this._cachedMeta.vScale) { |
| 6554 | range.min = Math.min(range.min, custom.min); |
| 6555 | range.max = Math.max(range.max, custom.max); |
| 6556 | } |
| 6557 | } |
| 6558 | }, |
| 6559 | { |
| 6560 | key: "getMaxOverflow", |
| 6561 | value: function getMaxOverflow() { |
| 6562 | return 0; |
| 6563 | } |
| 6564 | }, |
| 6565 | { |
| 6566 | key: "getLabelAndValue", |
| 6567 | value: function getLabelAndValue(index22) { |
| 6568 | var meta = this._cachedMeta; |
| 6569 | var iScale = meta.iScale, vScale = meta.vScale; |
| 6570 | var parsed = this.getParsed(index22); |
| 6571 | var custom = parsed._custom; |
| 6572 | var value = isFloatBar(custom) ? "[" + custom.start + ", " + custom.end + "]" : "" + vScale.getLabelForValue(parsed[vScale.axis]); |
| 6573 | return { |
| 6574 | label: "" + iScale.getLabelForValue(parsed[iScale.axis]), |
| 6575 | value: value |
| 6576 | }; |
| 6577 | } |
| 6578 | }, |
| 6579 | { |
| 6580 | key: "initialize", |
| 6581 | value: function initialize() { |
| 6582 | this.enableOptionSharing = true; |
| 6583 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(BarController.prototype), "initialize", this).call(this); |
| 6584 | var meta = this._cachedMeta; |
| 6585 | meta.stack = this.getDataset().stack; |
| 6586 | } |
| 6587 | }, |
| 6588 | { |
| 6589 | key: "update", |
| 6590 | value: function update(mode) { |
| 6591 | var meta = this._cachedMeta; |
| 6592 | this.updateElements(meta.data, 0, meta.data.length, mode); |
| 6593 | } |
| 6594 | }, |
| 6595 | { |
| 6596 | key: "updateElements", |
| 6597 | value: function updateElements(bars, start, count, mode) { |
| 6598 | var reset = mode === "reset"; |
| 6599 | var ref = this, index23 = ref.index, vScale = ref._cachedMeta.vScale; |
| 6600 | var base = vScale.getBasePixel(); |
| 6601 | var horizontal = vScale.isHorizontal(); |
| 6602 | var ruler = this._getRuler(); |
| 6603 | var firstOpts = this.resolveDataElementOptions(start, mode); |
| 6604 | var sharedOptions = this.getSharedOptions(firstOpts); |
| 6605 | var includeOptions = this.includeOptions(mode, sharedOptions); |
| 6606 | this.updateSharedOptions(sharedOptions, mode, firstOpts); |
| 6607 | for(var i = start; i < start + count; i++){ |
| 6608 | var parsed = this.getParsed(i); |
| 6609 | var vpixels = reset || (0, _helpersSegmentJs.k)(parsed[vScale.axis]) ? { |
| 6610 | base: base, |
| 6611 | head: base |
| 6612 | } : this._calculateBarValuePixels(i); |
| 6613 | var ipixels = this._calculateBarIndexPixels(i, ruler); |
| 6614 | var stack = (parsed._stacks || {})[vScale.axis]; |
| 6615 | var properties = { |
| 6616 | horizontal: horizontal, |
| 6617 | base: vpixels.base, |
| 6618 | enableBorderRadius: !stack || isFloatBar(parsed._custom) || index23 === stack._top || index23 === stack._bottom, |
| 6619 | x: horizontal ? vpixels.head : ipixels.center, |
| 6620 | y: horizontal ? ipixels.center : vpixels.head, |
| 6621 | height: horizontal ? ipixels.size : Math.abs(vpixels.size), |
| 6622 | width: horizontal ? Math.abs(vpixels.size) : ipixels.size |
| 6623 | }; |
| 6624 | if (includeOptions) properties.options = sharedOptions || this.resolveDataElementOptions(i, bars[i].active ? "active" : mode); |
| 6625 | var options = properties.options || bars[i].options; |
| 6626 | setBorderSkipped(properties, options, stack, index23); |
| 6627 | setInflateAmount(properties, options, ruler.ratio); |
| 6628 | this.updateElement(bars[i], i, properties, mode); |
| 6629 | } |
| 6630 | } |
| 6631 | }, |
| 6632 | { |
| 6633 | key: "_getStacks", |
| 6634 | value: function _getStacks(last, dataIndex) { |
| 6635 | var meta = this._cachedMeta; |
| 6636 | var iScale = meta.iScale; |
| 6637 | var metasets = iScale.getMatchingVisibleMetas(this._type); |
| 6638 | var stacked = iScale.options.stacked; |
| 6639 | var ilen = metasets.length; |
| 6640 | var stacks = []; |
| 6641 | var i, item; |
| 6642 | for(i = 0; i < ilen; ++i){ |
| 6643 | item = metasets[i]; |
| 6644 | if (!item.controller.options.grouped) continue; |
| 6645 | if (typeof dataIndex !== "undefined") { |
| 6646 | var val = item.controller.getParsed(dataIndex)[item.controller._cachedMeta.vScale.axis]; |
| 6647 | if ((0, _helpersSegmentJs.k)(val) || isNaN(val)) continue; |
| 6648 | } |
| 6649 | if (stacked === false || stacks.indexOf(item.stack) === -1 || stacked === undefined && item.stack === undefined) stacks.push(item.stack); |
| 6650 | if (item.index === last) break; |
| 6651 | } |
| 6652 | if (!stacks.length) stacks.push(undefined); |
| 6653 | return stacks; |
| 6654 | } |
| 6655 | }, |
| 6656 | { |
| 6657 | key: "_getStackCount", |
| 6658 | value: function _getStackCount(index24) { |
| 6659 | return this._getStacks(undefined, index24).length; |
| 6660 | } |
| 6661 | }, |
| 6662 | { |
| 6663 | key: "_getStackIndex", |
| 6664 | value: function _getStackIndex(datasetIndex, name, dataIndex) { |
| 6665 | var stacks = this._getStacks(datasetIndex, dataIndex); |
| 6666 | var index25 = name !== undefined ? stacks.indexOf(name) : -1; |
| 6667 | return index25 === -1 ? stacks.length - 1 : index25; |
| 6668 | } |
| 6669 | }, |
| 6670 | { |
| 6671 | key: "_getRuler", |
| 6672 | value: function _getRuler() { |
| 6673 | var opts = this.options; |
| 6674 | var meta = this._cachedMeta; |
| 6675 | var iScale = meta.iScale; |
| 6676 | var pixels = []; |
| 6677 | var i, ilen; |
| 6678 | for(i = 0, ilen = meta.data.length; i < ilen; ++i)pixels.push(iScale.getPixelForValue(this.getParsed(i)[iScale.axis], i)); |
| 6679 | var barThickness = opts.barThickness; |
| 6680 | var min = barThickness || computeMinSampleSize(meta); |
| 6681 | return { |
| 6682 | min: min, |
| 6683 | pixels: pixels, |
| 6684 | start: iScale._startPixel, |
| 6685 | end: iScale._endPixel, |
| 6686 | stackCount: this._getStackCount(), |
| 6687 | scale: iScale, |
| 6688 | grouped: opts.grouped, |
| 6689 | ratio: barThickness ? 1 : opts.categoryPercentage * opts.barPercentage |
| 6690 | }; |
| 6691 | } |
| 6692 | }, |
| 6693 | { |
| 6694 | key: "_calculateBarValuePixels", |
| 6695 | value: function _calculateBarValuePixels(index26) { |
| 6696 | var ref = this, __cachedMeta = ref._cachedMeta, vScale = __cachedMeta.vScale, _stacked = __cachedMeta._stacked, _options = ref.options, baseValue = _options.base, minBarLength = _options.minBarLength; |
| 6697 | var actualBase = baseValue || 0; |
| 6698 | var parsed = this.getParsed(index26); |
| 6699 | var custom = parsed._custom; |
| 6700 | var floating = isFloatBar(custom); |
| 6701 | var value = parsed[vScale.axis]; |
| 6702 | var start = 0; |
| 6703 | var length = _stacked ? this.applyStack(vScale, parsed, _stacked) : value; |
| 6704 | var head, size; |
| 6705 | if (length !== value) { |
| 6706 | start = length - value; |
| 6707 | length = value; |
| 6708 | } |
| 6709 | if (floating) { |
| 6710 | value = custom.barStart; |
| 6711 | length = custom.barEnd - custom.barStart; |
| 6712 | if (value !== 0 && (0, _helpersSegmentJs.s)(value) !== (0, _helpersSegmentJs.s)(custom.barEnd)) start = 0; |
| 6713 | start += value; |
| 6714 | } |
| 6715 | var startValue = !(0, _helpersSegmentJs.k)(baseValue) && !floating ? baseValue : start; |
| 6716 | var base = vScale.getPixelForValue(startValue); |
| 6717 | if (this.chart.getDataVisibility(index26)) head = vScale.getPixelForValue(start + length); |
| 6718 | else head = base; |
| 6719 | size = head - base; |
| 6720 | if (Math.abs(size) < minBarLength) { |
| 6721 | size = barSign(size, vScale, actualBase) * minBarLength; |
| 6722 | if (value === actualBase) base -= size / 2; |
| 6723 | var startPixel = vScale.getPixelForDecimal(0); |
| 6724 | var endPixel = vScale.getPixelForDecimal(1); |
| 6725 | var min = Math.min(startPixel, endPixel); |
| 6726 | var max = Math.max(startPixel, endPixel); |
| 6727 | base = Math.max(Math.min(base, max), min); |
| 6728 | head = base + size; |
| 6729 | } |
| 6730 | if (base === vScale.getPixelForValue(actualBase)) { |
| 6731 | var halfGrid = (0, _helpersSegmentJs.s)(size) * vScale.getLineWidthForValue(actualBase) / 2; |
| 6732 | base += halfGrid; |
| 6733 | size -= halfGrid; |
| 6734 | } |
| 6735 | return { |
| 6736 | size: size, |
| 6737 | base: base, |
| 6738 | head: head, |
| 6739 | center: head + size / 2 |
| 6740 | }; |
| 6741 | } |
| 6742 | }, |
| 6743 | { |
| 6744 | key: "_calculateBarIndexPixels", |
| 6745 | value: function _calculateBarIndexPixels(index27, ruler) { |
| 6746 | var scale = ruler.scale; |
| 6747 | var options = this.options; |
| 6748 | var skipNull = options.skipNull; |
| 6749 | var maxBarThickness = (0, _helpersSegmentJs.v)(options.maxBarThickness, Infinity); |
| 6750 | var center, size; |
| 6751 | if (ruler.grouped) { |
| 6752 | var stackCount = skipNull ? this._getStackCount(index27) : ruler.stackCount; |
| 6753 | var range = options.barThickness === "flex" ? computeFlexCategoryTraits(index27, ruler, options, stackCount) : computeFitCategoryTraits(index27, ruler, options, stackCount); |
| 6754 | var stackIndex = this._getStackIndex(this.index, this._cachedMeta.stack, skipNull ? index27 : undefined); |
| 6755 | center = range.start + range.chunk * stackIndex + range.chunk / 2; |
| 6756 | size = Math.min(maxBarThickness, range.chunk * range.ratio); |
| 6757 | } else { |
| 6758 | center = scale.getPixelForValue(this.getParsed(index27)[scale.axis], index27); |
| 6759 | size = Math.min(maxBarThickness, ruler.min * ruler.ratio); |
| 6760 | } |
| 6761 | return { |
| 6762 | base: center - size / 2, |
| 6763 | head: center + size / 2, |
| 6764 | center: center, |
| 6765 | size: size |
| 6766 | }; |
| 6767 | } |
| 6768 | }, |
| 6769 | { |
| 6770 | key: "draw", |
| 6771 | value: function draw2() { |
| 6772 | var meta = this._cachedMeta; |
| 6773 | var vScale = meta.vScale; |
| 6774 | var rects = meta.data; |
| 6775 | var ilen = rects.length; |
| 6776 | var i = 0; |
| 6777 | for(; i < ilen; ++i)if (this.getParsed(i)[vScale.axis] !== null) rects[i].draw(this._ctx); |
| 6778 | } |
| 6779 | } |
| 6780 | ]); |
| 6781 | return BarController; |
| 6782 | }(DatasetController); |
| 6783 | BarController.id = "bar"; |
| 6784 | BarController.defaults = { |
| 6785 | datasetElementType: false, |
| 6786 | dataElementType: "bar", |
| 6787 | categoryPercentage: 0.8, |
| 6788 | barPercentage: 0.9, |
| 6789 | grouped: true, |
| 6790 | animations: { |
| 6791 | numbers: { |
| 6792 | type: "number", |
| 6793 | properties: [ |
| 6794 | "x", |
| 6795 | "y", |
| 6796 | "base", |
| 6797 | "width", |
| 6798 | "height" |
| 6799 | ] |
| 6800 | } |
| 6801 | } |
| 6802 | }; |
| 6803 | BarController.overrides = { |
| 6804 | scales: { |
| 6805 | _index_: { |
| 6806 | type: "category", |
| 6807 | offset: true, |
| 6808 | grid: { |
| 6809 | offset: true |
| 6810 | } |
| 6811 | }, |
| 6812 | _value_: { |
| 6813 | type: "linear", |
| 6814 | beginAtZero: true |
| 6815 | } |
| 6816 | } |
| 6817 | }; |
| 6818 | var BubbleController = /*#__PURE__*/ function(DatasetController) { |
| 6819 | "use strict"; |
| 6820 | (0, _inheritsJsDefault.default)(BubbleController, DatasetController); |
| 6821 | var _super = (0, _createSuperJsDefault.default)(BubbleController); |
| 6822 | function BubbleController() { |
| 6823 | (0, _classCallCheckJsDefault.default)(this, BubbleController); |
| 6824 | return _super.apply(this, arguments); |
| 6825 | } |
| 6826 | (0, _createClassJsDefault.default)(BubbleController, [ |
| 6827 | { |
| 6828 | key: "initialize", |
| 6829 | value: function initialize() { |
| 6830 | this.enableOptionSharing = true; |
| 6831 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(BubbleController.prototype), "initialize", this).call(this); |
| 6832 | } |
| 6833 | }, |
| 6834 | { |
| 6835 | key: "parsePrimitiveData", |
| 6836 | value: function parsePrimitiveData(meta, data, start, count) { |
| 6837 | var parsed = (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(BubbleController.prototype), "parsePrimitiveData", this).call(this, meta, data, start, count); |
| 6838 | for(var i = 0; i < parsed.length; i++)parsed[i]._custom = this.resolveDataElementOptions(i + start).radius; |
| 6839 | return parsed; |
| 6840 | } |
| 6841 | }, |
| 6842 | { |
| 6843 | key: "parseArrayData", |
| 6844 | value: function parseArrayData(meta, data, start, count) { |
| 6845 | var parsed = (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(BubbleController.prototype), "parseArrayData", this).call(this, meta, data, start, count); |
| 6846 | for(var i = 0; i < parsed.length; i++){ |
| 6847 | var item = data[start + i]; |
| 6848 | parsed[i]._custom = (0, _helpersSegmentJs.v)(item[2], this.resolveDataElementOptions(i + start).radius); |
| 6849 | } |
| 6850 | return parsed; |
| 6851 | } |
| 6852 | }, |
| 6853 | { |
| 6854 | key: "parseObjectData", |
| 6855 | value: function parseObjectData(meta, data, start, count) { |
| 6856 | var parsed = (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(BubbleController.prototype), "parseObjectData", this).call(this, meta, data, start, count); |
| 6857 | for(var i = 0; i < parsed.length; i++){ |
| 6858 | var item = data[start + i]; |
| 6859 | parsed[i]._custom = (0, _helpersSegmentJs.v)(item && item.r && +item.r, this.resolveDataElementOptions(i + start).radius); |
| 6860 | } |
| 6861 | return parsed; |
| 6862 | } |
| 6863 | }, |
| 6864 | { |
| 6865 | key: "getMaxOverflow", |
| 6866 | value: function getMaxOverflow() { |
| 6867 | var data = this._cachedMeta.data; |
| 6868 | var max = 0; |
| 6869 | for(var i = data.length - 1; i >= 0; --i)max = Math.max(max, data[i].size(this.resolveDataElementOptions(i)) / 2); |
| 6870 | return max > 0 && max; |
| 6871 | } |
| 6872 | }, |
| 6873 | { |
| 6874 | key: "getLabelAndValue", |
| 6875 | value: function getLabelAndValue(index28) { |
| 6876 | var meta = this._cachedMeta; |
| 6877 | var xScale = meta.xScale, yScale = meta.yScale; |
| 6878 | var parsed = this.getParsed(index28); |
| 6879 | var x = xScale.getLabelForValue(parsed.x); |
| 6880 | var y = yScale.getLabelForValue(parsed.y); |
| 6881 | var r = parsed._custom; |
| 6882 | return { |
| 6883 | label: meta.label, |
| 6884 | value: "(" + x + ", " + y + (r ? ", " + r : "") + ")" |
| 6885 | }; |
| 6886 | } |
| 6887 | }, |
| 6888 | { |
| 6889 | key: "update", |
| 6890 | value: function update(mode) { |
| 6891 | var points = this._cachedMeta.data; |
| 6892 | this.updateElements(points, 0, points.length, mode); |
| 6893 | } |
| 6894 | }, |
| 6895 | { |
| 6896 | key: "updateElements", |
| 6897 | value: function updateElements(points, start, count, mode) { |
| 6898 | var reset = mode === "reset"; |
| 6899 | var __cachedMeta = this._cachedMeta, iScale = __cachedMeta.iScale, vScale = __cachedMeta.vScale; |
| 6900 | var firstOpts = this.resolveDataElementOptions(start, mode); |
| 6901 | var sharedOptions = this.getSharedOptions(firstOpts); |
| 6902 | var includeOptions = this.includeOptions(mode, sharedOptions); |
| 6903 | var iAxis = iScale.axis; |
| 6904 | var vAxis = vScale.axis; |
| 6905 | for(var i = start; i < start + count; i++){ |
| 6906 | var point = points[i]; |
| 6907 | var parsed = !reset && this.getParsed(i); |
| 6908 | var properties = {}; |
| 6909 | var iPixel = properties[iAxis] = reset ? iScale.getPixelForDecimal(0.5) : iScale.getPixelForValue(parsed[iAxis]); |
| 6910 | var vPixel = properties[vAxis] = reset ? vScale.getBasePixel() : vScale.getPixelForValue(parsed[vAxis]); |
| 6911 | properties.skip = isNaN(iPixel) || isNaN(vPixel); |
| 6912 | if (includeOptions) { |
| 6913 | properties.options = this.resolveDataElementOptions(i, point.active ? "active" : mode); |
| 6914 | if (reset) properties.options.radius = 0; |
| 6915 | } |
| 6916 | this.updateElement(point, i, properties, mode); |
| 6917 | } |
| 6918 | this.updateSharedOptions(sharedOptions, mode, firstOpts); |
| 6919 | } |
| 6920 | }, |
| 6921 | { |
| 6922 | key: "resolveDataElementOptions", |
| 6923 | value: function resolveDataElementOptions(index29, mode) { |
| 6924 | var parsed = this.getParsed(index29); |
| 6925 | var values = (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(BubbleController.prototype), "resolveDataElementOptions", this).call(this, index29, mode); |
| 6926 | if (values.$shared) values = Object.assign({}, values, { |
| 6927 | $shared: false |
| 6928 | }); |
| 6929 | var radius = values.radius; |
| 6930 | if (mode !== "active") values.radius = 0; |
| 6931 | values.radius += (0, _helpersSegmentJs.v)(parsed && parsed._custom, radius); |
| 6932 | return values; |
| 6933 | } |
| 6934 | } |
| 6935 | ]); |
| 6936 | return BubbleController; |
| 6937 | }(DatasetController); |
| 6938 | BubbleController.id = "bubble"; |
| 6939 | BubbleController.defaults = { |
| 6940 | datasetElementType: false, |
| 6941 | dataElementType: "point", |
| 6942 | animations: { |
| 6943 | numbers: { |
| 6944 | type: "number", |
| 6945 | properties: [ |
| 6946 | "x", |
| 6947 | "y", |
| 6948 | "borderWidth", |
| 6949 | "radius" |
| 6950 | ] |
| 6951 | } |
| 6952 | } |
| 6953 | }; |
| 6954 | BubbleController.overrides = { |
| 6955 | scales: { |
| 6956 | x: { |
| 6957 | type: "linear" |
| 6958 | }, |
| 6959 | y: { |
| 6960 | type: "linear" |
| 6961 | } |
| 6962 | }, |
| 6963 | plugins: { |
| 6964 | tooltip: { |
| 6965 | callbacks: { |
| 6966 | title: function() { |
| 6967 | return ""; |
| 6968 | } |
| 6969 | } |
| 6970 | } |
| 6971 | } |
| 6972 | }; |
| 6973 | function getRatioAndOffset(rotation, circumference, cutout) { |
| 6974 | var ratioX = 1; |
| 6975 | var ratioY = 1; |
| 6976 | var offsetX = 0; |
| 6977 | var offsetY = 0; |
| 6978 | if (circumference < (0, _helpersSegmentJs.T)) { |
| 6979 | var startAngle = rotation; |
| 6980 | var endAngle = startAngle + circumference; |
| 6981 | var startX = Math.cos(startAngle); |
| 6982 | var startY = Math.sin(startAngle); |
| 6983 | var endX = Math.cos(endAngle); |
| 6984 | var endY = Math.sin(endAngle); |
| 6985 | var calcMax = function(angle, a, b) { |
| 6986 | return (0, _helpersSegmentJs.p)(angle, startAngle, endAngle, true) ? 1 : Math.max(a, a * cutout, b, b * cutout); |
| 6987 | }; |
| 6988 | var calcMin = function(angle, a, b) { |
| 6989 | return (0, _helpersSegmentJs.p)(angle, startAngle, endAngle, true) ? -1 : Math.min(a, a * cutout, b, b * cutout); |
| 6990 | }; |
| 6991 | var maxX = calcMax(0, startX, endX); |
| 6992 | var maxY = calcMax((0, _helpersSegmentJs.H), startY, endY); |
| 6993 | var minX = calcMin((0, _helpersSegmentJs.P), startX, endX); |
| 6994 | var minY = calcMin((0, _helpersSegmentJs.P) + (0, _helpersSegmentJs.H), startY, endY); |
| 6995 | ratioX = (maxX - minX) / 2; |
| 6996 | ratioY = (maxY - minY) / 2; |
| 6997 | offsetX = -(maxX + minX) / 2; |
| 6998 | offsetY = -(maxY + minY) / 2; |
| 6999 | } |
| 7000 | return { |
| 7001 | ratioX: ratioX, |
| 7002 | ratioY: ratioY, |
| 7003 | offsetX: offsetX, |
| 7004 | offsetY: offsetY |
| 7005 | }; |
| 7006 | } |
| 7007 | var DoughnutController = /*#__PURE__*/ function(DatasetController) { |
| 7008 | "use strict"; |
| 7009 | (0, _inheritsJsDefault.default)(DoughnutController, DatasetController); |
| 7010 | var _super = (0, _createSuperJsDefault.default)(DoughnutController); |
| 7011 | function DoughnutController(chart, datasetIndex) { |
| 7012 | (0, _classCallCheckJsDefault.default)(this, DoughnutController); |
| 7013 | var _this; |
| 7014 | _this = _super.call(this, chart, datasetIndex); |
| 7015 | _this.enableOptionSharing = true; |
| 7016 | _this.innerRadius = undefined; |
| 7017 | _this.outerRadius = undefined; |
| 7018 | _this.offsetX = undefined; |
| 7019 | _this.offsetY = undefined; |
| 7020 | return _this; |
| 7021 | } |
| 7022 | (0, _createClassJsDefault.default)(DoughnutController, [ |
| 7023 | { |
| 7024 | key: "linkScales", |
| 7025 | value: function linkScales() {} |
| 7026 | }, |
| 7027 | { |
| 7028 | key: "parse", |
| 7029 | value: function parse1(start, count) { |
| 7030 | var data = this.getDataset().data; |
| 7031 | var meta = this._cachedMeta; |
| 7032 | if (this._parsing === false) meta._parsed = data; |
| 7033 | else { |
| 7034 | var getter = function(i) { |
| 7035 | return +data[i]; |
| 7036 | }; |
| 7037 | if ((0, _helpersSegmentJs.i)(data[start])) { |
| 7038 | var __parsing = this._parsing, _key = __parsing.key, key = _key === void 0 ? "value" : _key; |
| 7039 | getter = function(i) { |
| 7040 | return +(0, _helpersSegmentJs.f)(data[i], key); |
| 7041 | }; |
| 7042 | } |
| 7043 | var i1, ilen; |
| 7044 | for(i1 = start, ilen = start + count; i1 < ilen; ++i1)meta._parsed[i1] = getter(i1); |
| 7045 | } |
| 7046 | } |
| 7047 | }, |
| 7048 | { |
| 7049 | key: "_getRotation", |
| 7050 | value: function _getRotation() { |
| 7051 | return (0, _helpersSegmentJs.t)(this.options.rotation - 90); |
| 7052 | } |
| 7053 | }, |
| 7054 | { |
| 7055 | key: "_getCircumference", |
| 7056 | value: function _getCircumference() { |
| 7057 | return (0, _helpersSegmentJs.t)(this.options.circumference); |
| 7058 | } |
| 7059 | }, |
| 7060 | { |
| 7061 | key: "_getRotationExtents", |
| 7062 | value: function _getRotationExtents() { |
| 7063 | var min = (0, _helpersSegmentJs.T); |
| 7064 | var max = -(0, _helpersSegmentJs.T); |
| 7065 | for(var i = 0; i < this.chart.data.datasets.length; ++i)if (this.chart.isDatasetVisible(i)) { |
| 7066 | var controller = this.chart.getDatasetMeta(i).controller; |
| 7067 | var rotation = controller._getRotation(); |
| 7068 | var circumference = controller._getCircumference(); |
| 7069 | min = Math.min(min, rotation); |
| 7070 | max = Math.max(max, rotation + circumference); |
| 7071 | } |
| 7072 | return { |
| 7073 | rotation: min, |
| 7074 | circumference: max - min |
| 7075 | }; |
| 7076 | } |
| 7077 | }, |
| 7078 | { |
| 7079 | key: "update", |
| 7080 | value: function update(mode) { |
| 7081 | var chart = this.chart; |
| 7082 | var chartArea = chart.chartArea; |
| 7083 | var meta = this._cachedMeta; |
| 7084 | var arcs = meta.data; |
| 7085 | var spacing = this.getMaxBorderWidth() + this.getMaxOffset(arcs) + this.options.spacing; |
| 7086 | var maxSize = Math.max((Math.min(chartArea.width, chartArea.height) - spacing) / 2, 0); |
| 7087 | var cutout = Math.min((0, _helpersSegmentJs.m)(this.options.cutout, maxSize), 1); |
| 7088 | var chartWeight = this._getRingWeight(this.index); |
| 7089 | var ref = this._getRotationExtents(), circumference = ref.circumference, rotation = ref.rotation; |
| 7090 | var ref1 = getRatioAndOffset(rotation, circumference, cutout), ratioX = ref1.ratioX, ratioY = ref1.ratioY, offsetX = ref1.offsetX, offsetY = ref1.offsetY; |
| 7091 | var maxWidth = (chartArea.width - spacing) / ratioX; |
| 7092 | var maxHeight = (chartArea.height - spacing) / ratioY; |
| 7093 | var maxRadius = Math.max(Math.min(maxWidth, maxHeight) / 2, 0); |
| 7094 | var outerRadius = (0, _helpersSegmentJs.n)(this.options.radius, maxRadius); |
| 7095 | var innerRadius = Math.max(outerRadius * cutout, 0); |
| 7096 | var radiusLength = (outerRadius - innerRadius) / this._getVisibleDatasetWeightTotal(); |
| 7097 | this.offsetX = offsetX * outerRadius; |
| 7098 | this.offsetY = offsetY * outerRadius; |
| 7099 | meta.total = this.calculateTotal(); |
| 7100 | this.outerRadius = outerRadius - radiusLength * this._getRingWeightOffset(this.index); |
| 7101 | this.innerRadius = Math.max(this.outerRadius - radiusLength * chartWeight, 0); |
| 7102 | this.updateElements(arcs, 0, arcs.length, mode); |
| 7103 | } |
| 7104 | }, |
| 7105 | { |
| 7106 | key: "_circumference", |
| 7107 | value: function _circumference(i, reset) { |
| 7108 | var opts = this.options; |
| 7109 | var meta = this._cachedMeta; |
| 7110 | var circumference = this._getCircumference(); |
| 7111 | if (reset && opts.animation.animateRotate || !this.chart.getDataVisibility(i) || meta._parsed[i] === null || meta.data[i].hidden) return 0; |
| 7112 | return this.calculateCircumference(meta._parsed[i] * circumference / (0, _helpersSegmentJs.T)); |
| 7113 | } |
| 7114 | }, |
| 7115 | { |
| 7116 | key: "updateElements", |
| 7117 | value: function updateElements(arcs, start, count, mode) { |
| 7118 | var reset = mode === "reset"; |
| 7119 | var chart = this.chart; |
| 7120 | var chartArea = chart.chartArea; |
| 7121 | var opts = chart.options; |
| 7122 | var animationOpts = opts.animation; |
| 7123 | var centerX = (chartArea.left + chartArea.right) / 2; |
| 7124 | var centerY = (chartArea.top + chartArea.bottom) / 2; |
| 7125 | var animateScale = reset && animationOpts.animateScale; |
| 7126 | var innerRadius = animateScale ? 0 : this.innerRadius; |
| 7127 | var outerRadius = animateScale ? 0 : this.outerRadius; |
| 7128 | var firstOpts = this.resolveDataElementOptions(start, mode); |
| 7129 | var sharedOptions = this.getSharedOptions(firstOpts); |
| 7130 | var includeOptions = this.includeOptions(mode, sharedOptions); |
| 7131 | var startAngle = this._getRotation(); |
| 7132 | var i; |
| 7133 | for(i = 0; i < start; ++i)startAngle += this._circumference(i, reset); |
| 7134 | for(i = start; i < start + count; ++i){ |
| 7135 | var circumference = this._circumference(i, reset); |
| 7136 | var arc = arcs[i]; |
| 7137 | var properties = { |
| 7138 | x: centerX + this.offsetX, |
| 7139 | y: centerY + this.offsetY, |
| 7140 | startAngle: startAngle, |
| 7141 | endAngle: startAngle + circumference, |
| 7142 | circumference: circumference, |
| 7143 | outerRadius: outerRadius, |
| 7144 | innerRadius: innerRadius |
| 7145 | }; |
| 7146 | if (includeOptions) properties.options = sharedOptions || this.resolveDataElementOptions(i, arc.active ? "active" : mode); |
| 7147 | startAngle += circumference; |
| 7148 | this.updateElement(arc, i, properties, mode); |
| 7149 | } |
| 7150 | this.updateSharedOptions(sharedOptions, mode, firstOpts); |
| 7151 | } |
| 7152 | }, |
| 7153 | { |
| 7154 | key: "calculateTotal", |
| 7155 | value: function calculateTotal() { |
| 7156 | var meta = this._cachedMeta; |
| 7157 | var metaData = meta.data; |
| 7158 | var total = 0; |
| 7159 | var i; |
| 7160 | for(i = 0; i < metaData.length; i++){ |
| 7161 | var value = meta._parsed[i]; |
| 7162 | if (value !== null && !isNaN(value) && this.chart.getDataVisibility(i) && !metaData[i].hidden) total += Math.abs(value); |
| 7163 | } |
| 7164 | return total; |
| 7165 | } |
| 7166 | }, |
| 7167 | { |
| 7168 | key: "calculateCircumference", |
| 7169 | value: function calculateCircumference(value) { |
| 7170 | var total = this._cachedMeta.total; |
| 7171 | if (total > 0 && !isNaN(value)) return (0, _helpersSegmentJs.T) * (Math.abs(value) / total); |
| 7172 | return 0; |
| 7173 | } |
| 7174 | }, |
| 7175 | { |
| 7176 | key: "getLabelAndValue", |
| 7177 | value: function getLabelAndValue(index30) { |
| 7178 | var meta = this._cachedMeta; |
| 7179 | var chart = this.chart; |
| 7180 | var labels = chart.data.labels || []; |
| 7181 | var value = (0, _helpersSegmentJs.o)(meta._parsed[index30], chart.options.locale); |
| 7182 | return { |
| 7183 | label: labels[index30] || "", |
| 7184 | value: value |
| 7185 | }; |
| 7186 | } |
| 7187 | }, |
| 7188 | { |
| 7189 | key: "getMaxBorderWidth", |
| 7190 | value: function getMaxBorderWidth(arcs) { |
| 7191 | var max = 0; |
| 7192 | var chart = this.chart; |
| 7193 | var i, ilen, meta, controller, options; |
| 7194 | if (!arcs) { |
| 7195 | for(i = 0, ilen = chart.data.datasets.length; i < ilen; ++i)if (chart.isDatasetVisible(i)) { |
| 7196 | meta = chart.getDatasetMeta(i); |
| 7197 | arcs = meta.data; |
| 7198 | controller = meta.controller; |
| 7199 | break; |
| 7200 | } |
| 7201 | } |
| 7202 | if (!arcs) return 0; |
| 7203 | for(i = 0, ilen = arcs.length; i < ilen; ++i){ |
| 7204 | options = controller.resolveDataElementOptions(i); |
| 7205 | if (options.borderAlign !== "inner") max = Math.max(max, options.borderWidth || 0, options.hoverBorderWidth || 0); |
| 7206 | } |
| 7207 | return max; |
| 7208 | } |
| 7209 | }, |
| 7210 | { |
| 7211 | key: "getMaxOffset", |
| 7212 | value: function getMaxOffset(arcs) { |
| 7213 | var max = 0; |
| 7214 | for(var i = 0, ilen = arcs.length; i < ilen; ++i){ |
| 7215 | var options = this.resolveDataElementOptions(i); |
| 7216 | max = Math.max(max, options.offset || 0, options.hoverOffset || 0); |
| 7217 | } |
| 7218 | return max; |
| 7219 | } |
| 7220 | }, |
| 7221 | { |
| 7222 | key: "_getRingWeightOffset", |
| 7223 | value: function _getRingWeightOffset(datasetIndex) { |
| 7224 | var ringWeightOffset = 0; |
| 7225 | for(var i = 0; i < datasetIndex; ++i)if (this.chart.isDatasetVisible(i)) ringWeightOffset += this._getRingWeight(i); |
| 7226 | return ringWeightOffset; |
| 7227 | } |
| 7228 | }, |
| 7229 | { |
| 7230 | key: "_getRingWeight", |
| 7231 | value: function _getRingWeight(datasetIndex) { |
| 7232 | return Math.max((0, _helpersSegmentJs.v)(this.chart.data.datasets[datasetIndex].weight, 1), 0); |
| 7233 | } |
| 7234 | }, |
| 7235 | { |
| 7236 | key: "_getVisibleDatasetWeightTotal", |
| 7237 | value: function _getVisibleDatasetWeightTotal() { |
| 7238 | return this._getRingWeightOffset(this.chart.data.datasets.length) || 1; |
| 7239 | } |
| 7240 | } |
| 7241 | ]); |
| 7242 | return DoughnutController; |
| 7243 | }(DatasetController); |
| 7244 | DoughnutController.id = "doughnut"; |
| 7245 | DoughnutController.defaults = { |
| 7246 | datasetElementType: false, |
| 7247 | dataElementType: "arc", |
| 7248 | animation: { |
| 7249 | animateRotate: true, |
| 7250 | animateScale: false |
| 7251 | }, |
| 7252 | animations: { |
| 7253 | numbers: { |
| 7254 | type: "number", |
| 7255 | properties: [ |
| 7256 | "circumference", |
| 7257 | "endAngle", |
| 7258 | "innerRadius", |
| 7259 | "outerRadius", |
| 7260 | "startAngle", |
| 7261 | "x", |
| 7262 | "y", |
| 7263 | "offset", |
| 7264 | "borderWidth", |
| 7265 | "spacing" |
| 7266 | ] |
| 7267 | } |
| 7268 | }, |
| 7269 | cutout: "50%", |
| 7270 | rotation: 0, |
| 7271 | circumference: 360, |
| 7272 | radius: "100%", |
| 7273 | spacing: 0, |
| 7274 | indexAxis: "r" |
| 7275 | }; |
| 7276 | DoughnutController.descriptors = { |
| 7277 | _scriptable: function(name) { |
| 7278 | return name !== "spacing"; |
| 7279 | }, |
| 7280 | _indexable: function(name) { |
| 7281 | return name !== "spacing"; |
| 7282 | } |
| 7283 | }; |
| 7284 | DoughnutController.overrides = { |
| 7285 | aspectRatio: 1, |
| 7286 | plugins: { |
| 7287 | legend: { |
| 7288 | labels: { |
| 7289 | generateLabels: function(chart) { |
| 7290 | var data = chart.data; |
| 7291 | if (data.labels.length && data.datasets.length) { |
| 7292 | var _options = chart.legend.options, pointStyle = _options.labels.pointStyle; |
| 7293 | return data.labels.map(function(label, i) { |
| 7294 | var meta = chart.getDatasetMeta(0); |
| 7295 | var style = meta.controller.getStyle(i); |
| 7296 | return { |
| 7297 | text: label, |
| 7298 | fillStyle: style.backgroundColor, |
| 7299 | strokeStyle: style.borderColor, |
| 7300 | lineWidth: style.borderWidth, |
| 7301 | pointStyle: pointStyle, |
| 7302 | hidden: !chart.getDataVisibility(i), |
| 7303 | index: i |
| 7304 | }; |
| 7305 | }); |
| 7306 | } |
| 7307 | return []; |
| 7308 | } |
| 7309 | }, |
| 7310 | onClick: function(e, legendItem, legend) { |
| 7311 | legend.chart.toggleDataVisibility(legendItem.index); |
| 7312 | legend.chart.update(); |
| 7313 | } |
| 7314 | }, |
| 7315 | tooltip: { |
| 7316 | callbacks: { |
| 7317 | title: function() { |
| 7318 | return ""; |
| 7319 | }, |
| 7320 | label: function(tooltipItem) { |
| 7321 | var dataLabel = tooltipItem.label; |
| 7322 | var value = ": " + tooltipItem.formattedValue; |
| 7323 | if ((0, _helpersSegmentJs.b)(dataLabel)) { |
| 7324 | dataLabel = dataLabel.slice(); |
| 7325 | dataLabel[0] += value; |
| 7326 | } else dataLabel += value; |
| 7327 | return dataLabel; |
| 7328 | } |
| 7329 | } |
| 7330 | } |
| 7331 | } |
| 7332 | }; |
| 7333 | var LineController = /*#__PURE__*/ function(DatasetController) { |
| 7334 | "use strict"; |
| 7335 | (0, _inheritsJsDefault.default)(LineController, DatasetController); |
| 7336 | var _super = (0, _createSuperJsDefault.default)(LineController); |
| 7337 | function LineController() { |
| 7338 | (0, _classCallCheckJsDefault.default)(this, LineController); |
| 7339 | return _super.apply(this, arguments); |
| 7340 | } |
| 7341 | (0, _createClassJsDefault.default)(LineController, [ |
| 7342 | { |
| 7343 | key: "initialize", |
| 7344 | value: function initialize() { |
| 7345 | this.enableOptionSharing = true; |
| 7346 | this.supportsDecimation = true; |
| 7347 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(LineController.prototype), "initialize", this).call(this); |
| 7348 | } |
| 7349 | }, |
| 7350 | { |
| 7351 | key: "update", |
| 7352 | value: function update(mode) { |
| 7353 | var meta = this._cachedMeta; |
| 7354 | var line = meta.dataset, tmp = meta.data, points = tmp === void 0 ? [] : tmp, _dataset = meta._dataset; |
| 7355 | var animationsDisabled = this.chart._animationsDisabled; |
| 7356 | var ref = getStartAndCountOfVisiblePoints(meta, points, animationsDisabled), start = ref.start, count = ref.count; |
| 7357 | this._drawStart = start; |
| 7358 | this._drawCount = count; |
| 7359 | if (scaleRangesChanged(meta)) { |
| 7360 | start = 0; |
| 7361 | count = points.length; |
| 7362 | } |
| 7363 | line._chart = this.chart; |
| 7364 | line._datasetIndex = this.index; |
| 7365 | line._decimated = !!_dataset._decimated; |
| 7366 | line.points = points; |
| 7367 | var options = this.resolveDatasetElementOptions(mode); |
| 7368 | if (!this.options.showLine) options.borderWidth = 0; |
| 7369 | options.segment = this.options.segment; |
| 7370 | this.updateElement(line, undefined, { |
| 7371 | animated: !animationsDisabled, |
| 7372 | options: options |
| 7373 | }, mode); |
| 7374 | this.updateElements(points, start, count, mode); |
| 7375 | } |
| 7376 | }, |
| 7377 | { |
| 7378 | key: "updateElements", |
| 7379 | value: function updateElements(points, start, count, mode) { |
| 7380 | var reset = mode === "reset"; |
| 7381 | var __cachedMeta = this._cachedMeta, iScale = __cachedMeta.iScale, vScale = __cachedMeta.vScale, _stacked = __cachedMeta._stacked, _dataset = __cachedMeta._dataset; |
| 7382 | var firstOpts = this.resolveDataElementOptions(start, mode); |
| 7383 | var sharedOptions = this.getSharedOptions(firstOpts); |
| 7384 | var includeOptions = this.includeOptions(mode, sharedOptions); |
| 7385 | var iAxis = iScale.axis; |
| 7386 | var vAxis = vScale.axis; |
| 7387 | var _options = this.options, spanGaps = _options.spanGaps, segment = _options.segment; |
| 7388 | var maxGapLength = (0, _helpersSegmentJs.q)(spanGaps) ? spanGaps : Number.POSITIVE_INFINITY; |
| 7389 | var directUpdate = this.chart._animationsDisabled || reset || mode === "none"; |
| 7390 | var prevParsed = start > 0 && this.getParsed(start - 1); |
| 7391 | for(var i = start; i < start + count; ++i){ |
| 7392 | var point = points[i]; |
| 7393 | var parsed = this.getParsed(i); |
| 7394 | var properties = directUpdate ? point : {}; |
| 7395 | var nullData = (0, _helpersSegmentJs.k)(parsed[vAxis]); |
| 7396 | var iPixel = properties[iAxis] = iScale.getPixelForValue(parsed[iAxis], i); |
| 7397 | var vPixel = properties[vAxis] = reset || nullData ? vScale.getBasePixel() : vScale.getPixelForValue(_stacked ? this.applyStack(vScale, parsed, _stacked) : parsed[vAxis], i); |
| 7398 | properties.skip = isNaN(iPixel) || isNaN(vPixel) || nullData; |
| 7399 | properties.stop = i > 0 && Math.abs(parsed[iAxis] - prevParsed[iAxis]) > maxGapLength; |
| 7400 | if (segment) { |
| 7401 | properties.parsed = parsed; |
| 7402 | properties.raw = _dataset.data[i]; |
| 7403 | } |
| 7404 | if (includeOptions) properties.options = sharedOptions || this.resolveDataElementOptions(i, point.active ? "active" : mode); |
| 7405 | if (!directUpdate) this.updateElement(point, i, properties, mode); |
| 7406 | prevParsed = parsed; |
| 7407 | } |
| 7408 | this.updateSharedOptions(sharedOptions, mode, firstOpts); |
| 7409 | } |
| 7410 | }, |
| 7411 | { |
| 7412 | key: "getMaxOverflow", |
| 7413 | value: function getMaxOverflow() { |
| 7414 | var meta = this._cachedMeta; |
| 7415 | var dataset = meta.dataset; |
| 7416 | var border = dataset.options && dataset.options.borderWidth || 0; |
| 7417 | var data = meta.data || []; |
| 7418 | if (!data.length) return border; |
| 7419 | var firstPoint = data[0].size(this.resolveDataElementOptions(0)); |
| 7420 | var lastPoint = data[data.length - 1].size(this.resolveDataElementOptions(data.length - 1)); |
| 7421 | return Math.max(border, firstPoint, lastPoint) / 2; |
| 7422 | } |
| 7423 | }, |
| 7424 | { |
| 7425 | key: "draw", |
| 7426 | value: function draw2() { |
| 7427 | var meta = this._cachedMeta; |
| 7428 | meta.dataset.updateControlPoints(this.chart.chartArea, meta.iScale.axis); |
| 7429 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(LineController.prototype), "draw", this).call(this); |
| 7430 | } |
| 7431 | } |
| 7432 | ]); |
| 7433 | return LineController; |
| 7434 | }(DatasetController); |
| 7435 | LineController.id = "line"; |
| 7436 | LineController.defaults = { |
| 7437 | datasetElementType: "line", |
| 7438 | dataElementType: "point", |
| 7439 | showLine: true, |
| 7440 | spanGaps: false |
| 7441 | }; |
| 7442 | LineController.overrides = { |
| 7443 | scales: { |
| 7444 | _index_: { |
| 7445 | type: "category" |
| 7446 | }, |
| 7447 | _value_: { |
| 7448 | type: "linear" |
| 7449 | } |
| 7450 | } |
| 7451 | }; |
| 7452 | function getStartAndCountOfVisiblePoints(meta, points, animationsDisabled) { |
| 7453 | var pointCount = points.length; |
| 7454 | var start = 0; |
| 7455 | var count = pointCount; |
| 7456 | if (meta._sorted) { |
| 7457 | var iScale = meta.iScale, _parsed = meta._parsed; |
| 7458 | var axis = iScale.axis; |
| 7459 | var ref = iScale.getUserBounds(), min = ref.min, max = ref.max, minDefined = ref.minDefined, maxDefined = ref.maxDefined; |
| 7460 | if (minDefined) start = (0, _helpersSegmentJs.w)(Math.min((0, _helpersSegmentJs.x)(_parsed, iScale.axis, min).lo, animationsDisabled ? pointCount : (0, _helpersSegmentJs.x)(points, axis, iScale.getPixelForValue(min)).lo), 0, pointCount - 1); |
| 7461 | if (maxDefined) count = (0, _helpersSegmentJs.w)(Math.max((0, _helpersSegmentJs.x)(_parsed, iScale.axis, max).hi + 1, animationsDisabled ? 0 : (0, _helpersSegmentJs.x)(points, axis, iScale.getPixelForValue(max)).hi + 1), start, pointCount) - start; |
| 7462 | else count = pointCount - start; |
| 7463 | } |
| 7464 | return { |
| 7465 | start: start, |
| 7466 | count: count |
| 7467 | }; |
| 7468 | } |
| 7469 | function scaleRangesChanged(meta) { |
| 7470 | var xScale = meta.xScale, yScale = meta.yScale, _scaleRanges = meta._scaleRanges; |
| 7471 | var newRanges = { |
| 7472 | xmin: xScale.min, |
| 7473 | xmax: xScale.max, |
| 7474 | ymin: yScale.min, |
| 7475 | ymax: yScale.max |
| 7476 | }; |
| 7477 | if (!_scaleRanges) { |
| 7478 | meta._scaleRanges = newRanges; |
| 7479 | return true; |
| 7480 | } |
| 7481 | var changed = _scaleRanges.xmin !== xScale.min || _scaleRanges.xmax !== xScale.max || _scaleRanges.ymin !== yScale.min || _scaleRanges.ymax !== yScale.max; |
| 7482 | Object.assign(_scaleRanges, newRanges); |
| 7483 | return changed; |
| 7484 | } |
| 7485 | var PolarAreaController = /*#__PURE__*/ function(DatasetController) { |
| 7486 | "use strict"; |
| 7487 | (0, _inheritsJsDefault.default)(PolarAreaController, DatasetController); |
| 7488 | var _super = (0, _createSuperJsDefault.default)(PolarAreaController); |
| 7489 | function PolarAreaController(chart, datasetIndex) { |
| 7490 | (0, _classCallCheckJsDefault.default)(this, PolarAreaController); |
| 7491 | var _this; |
| 7492 | _this = _super.call(this, chart, datasetIndex); |
| 7493 | _this.innerRadius = undefined; |
| 7494 | _this.outerRadius = undefined; |
| 7495 | return _this; |
| 7496 | } |
| 7497 | (0, _createClassJsDefault.default)(PolarAreaController, [ |
| 7498 | { |
| 7499 | key: "getLabelAndValue", |
| 7500 | value: function getLabelAndValue(index31) { |
| 7501 | var meta = this._cachedMeta; |
| 7502 | var chart = this.chart; |
| 7503 | var labels = chart.data.labels || []; |
| 7504 | var value = (0, _helpersSegmentJs.o)(meta._parsed[index31].r, chart.options.locale); |
| 7505 | return { |
| 7506 | label: labels[index31] || "", |
| 7507 | value: value |
| 7508 | }; |
| 7509 | } |
| 7510 | }, |
| 7511 | { |
| 7512 | key: "parseObjectData", |
| 7513 | value: function parseObjectData(meta, data, start, count) { |
| 7514 | return (0, _helpersSegmentJs.y).bind(this)(meta, data, start, count); |
| 7515 | } |
| 7516 | }, |
| 7517 | { |
| 7518 | key: "update", |
| 7519 | value: function update(mode) { |
| 7520 | var arcs = this._cachedMeta.data; |
| 7521 | this._updateRadius(); |
| 7522 | this.updateElements(arcs, 0, arcs.length, mode); |
| 7523 | } |
| 7524 | }, |
| 7525 | { |
| 7526 | key: "getMinMax", |
| 7527 | value: function getMinMax() { |
| 7528 | var _this = this; |
| 7529 | var meta = this._cachedMeta; |
| 7530 | var range = { |
| 7531 | min: Number.POSITIVE_INFINITY, |
| 7532 | max: Number.NEGATIVE_INFINITY |
| 7533 | }; |
| 7534 | meta.data.forEach(function(element, index32) { |
| 7535 | var parsed = _this.getParsed(index32).r; |
| 7536 | if (!isNaN(parsed) && _this.chart.getDataVisibility(index32)) { |
| 7537 | if (parsed < range.min) range.min = parsed; |
| 7538 | if (parsed > range.max) range.max = parsed; |
| 7539 | } |
| 7540 | }); |
| 7541 | return range; |
| 7542 | } |
| 7543 | }, |
| 7544 | { |
| 7545 | key: "_updateRadius", |
| 7546 | value: function _updateRadius() { |
| 7547 | var chart = this.chart; |
| 7548 | var chartArea = chart.chartArea; |
| 7549 | var opts = chart.options; |
| 7550 | var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top); |
| 7551 | var outerRadius = Math.max(minSize / 2, 0); |
| 7552 | var innerRadius = Math.max(opts.cutoutPercentage ? outerRadius / 100 * opts.cutoutPercentage : 1, 0); |
| 7553 | var radiusLength = (outerRadius - innerRadius) / chart.getVisibleDatasetCount(); |
| 7554 | this.outerRadius = outerRadius - radiusLength * this.index; |
| 7555 | this.innerRadius = this.outerRadius - radiusLength; |
| 7556 | } |
| 7557 | }, |
| 7558 | { |
| 7559 | key: "updateElements", |
| 7560 | value: function updateElements(arcs, start, count, mode) { |
| 7561 | var reset = mode === "reset"; |
| 7562 | var chart = this.chart; |
| 7563 | var opts = chart.options; |
| 7564 | var animationOpts = opts.animation; |
| 7565 | var scale = this._cachedMeta.rScale; |
| 7566 | var centerX = scale.xCenter; |
| 7567 | var centerY = scale.yCenter; |
| 7568 | var datasetStartAngle = scale.getIndexAngle(0) - 0.5 * (0, _helpersSegmentJs.P); |
| 7569 | var angle = datasetStartAngle; |
| 7570 | var i; |
| 7571 | var defaultAngle = 360 / this.countVisibleElements(); |
| 7572 | for(i = 0; i < start; ++i)angle += this._computeAngle(i, mode, defaultAngle); |
| 7573 | for(i = start; i < start + count; i++){ |
| 7574 | var arc = arcs[i]; |
| 7575 | var startAngle = angle; |
| 7576 | var endAngle = angle + this._computeAngle(i, mode, defaultAngle); |
| 7577 | var outerRadius = chart.getDataVisibility(i) ? scale.getDistanceFromCenterForValue(this.getParsed(i).r) : 0; |
| 7578 | angle = endAngle; |
| 7579 | if (reset) { |
| 7580 | if (animationOpts.animateScale) outerRadius = 0; |
| 7581 | if (animationOpts.animateRotate) startAngle = endAngle = datasetStartAngle; |
| 7582 | } |
| 7583 | var properties = { |
| 7584 | x: centerX, |
| 7585 | y: centerY, |
| 7586 | innerRadius: 0, |
| 7587 | outerRadius: outerRadius, |
| 7588 | startAngle: startAngle, |
| 7589 | endAngle: endAngle, |
| 7590 | options: this.resolveDataElementOptions(i, arc.active ? "active" : mode) |
| 7591 | }; |
| 7592 | this.updateElement(arc, i, properties, mode); |
| 7593 | } |
| 7594 | } |
| 7595 | }, |
| 7596 | { |
| 7597 | key: "countVisibleElements", |
| 7598 | value: function countVisibleElements() { |
| 7599 | var _this = this; |
| 7600 | var meta = this._cachedMeta; |
| 7601 | var count = 0; |
| 7602 | meta.data.forEach(function(element, index33) { |
| 7603 | if (!isNaN(_this.getParsed(index33).r) && _this.chart.getDataVisibility(index33)) count++; |
| 7604 | }); |
| 7605 | return count; |
| 7606 | } |
| 7607 | }, |
| 7608 | { |
| 7609 | key: "_computeAngle", |
| 7610 | value: function _computeAngle(index34, mode, defaultAngle) { |
| 7611 | return this.chart.getDataVisibility(index34) ? (0, _helpersSegmentJs.t)(this.resolveDataElementOptions(index34, mode).angle || defaultAngle) : 0; |
| 7612 | } |
| 7613 | } |
| 7614 | ]); |
| 7615 | return PolarAreaController; |
| 7616 | }(DatasetController); |
| 7617 | PolarAreaController.id = "polarArea"; |
| 7618 | PolarAreaController.defaults = { |
| 7619 | dataElementType: "arc", |
| 7620 | animation: { |
| 7621 | animateRotate: true, |
| 7622 | animateScale: true |
| 7623 | }, |
| 7624 | animations: { |
| 7625 | numbers: { |
| 7626 | type: "number", |
| 7627 | properties: [ |
| 7628 | "x", |
| 7629 | "y", |
| 7630 | "startAngle", |
| 7631 | "endAngle", |
| 7632 | "innerRadius", |
| 7633 | "outerRadius" |
| 7634 | ] |
| 7635 | } |
| 7636 | }, |
| 7637 | indexAxis: "r", |
| 7638 | startAngle: 0 |
| 7639 | }; |
| 7640 | PolarAreaController.overrides = { |
| 7641 | aspectRatio: 1, |
| 7642 | plugins: { |
| 7643 | legend: { |
| 7644 | labels: { |
| 7645 | generateLabels: function(chart) { |
| 7646 | var data = chart.data; |
| 7647 | if (data.labels.length && data.datasets.length) { |
| 7648 | var _options = chart.legend.options, pointStyle = _options.labels.pointStyle; |
| 7649 | return data.labels.map(function(label, i) { |
| 7650 | var meta = chart.getDatasetMeta(0); |
| 7651 | var style = meta.controller.getStyle(i); |
| 7652 | return { |
| 7653 | text: label, |
| 7654 | fillStyle: style.backgroundColor, |
| 7655 | strokeStyle: style.borderColor, |
| 7656 | lineWidth: style.borderWidth, |
| 7657 | pointStyle: pointStyle, |
| 7658 | hidden: !chart.getDataVisibility(i), |
| 7659 | index: i |
| 7660 | }; |
| 7661 | }); |
| 7662 | } |
| 7663 | return []; |
| 7664 | } |
| 7665 | }, |
| 7666 | onClick: function(e, legendItem, legend) { |
| 7667 | legend.chart.toggleDataVisibility(legendItem.index); |
| 7668 | legend.chart.update(); |
| 7669 | } |
| 7670 | }, |
| 7671 | tooltip: { |
| 7672 | callbacks: { |
| 7673 | title: function() { |
| 7674 | return ""; |
| 7675 | }, |
| 7676 | label: function(context) { |
| 7677 | return context.chart.data.labels[context.dataIndex] + ": " + context.formattedValue; |
| 7678 | } |
| 7679 | } |
| 7680 | } |
| 7681 | }, |
| 7682 | scales: { |
| 7683 | r: { |
| 7684 | type: "radialLinear", |
| 7685 | angleLines: { |
| 7686 | display: false |
| 7687 | }, |
| 7688 | beginAtZero: true, |
| 7689 | grid: { |
| 7690 | circular: true |
| 7691 | }, |
| 7692 | pointLabels: { |
| 7693 | display: false |
| 7694 | }, |
| 7695 | startAngle: 0 |
| 7696 | } |
| 7697 | } |
| 7698 | }; |
| 7699 | var PieController = /*#__PURE__*/ function(DoughnutController) { |
| 7700 | "use strict"; |
| 7701 | (0, _inheritsJsDefault.default)(PieController, DoughnutController); |
| 7702 | var _super = (0, _createSuperJsDefault.default)(PieController); |
| 7703 | function PieController() { |
| 7704 | (0, _classCallCheckJsDefault.default)(this, PieController); |
| 7705 | return _super.apply(this, arguments); |
| 7706 | } |
| 7707 | return PieController; |
| 7708 | }(DoughnutController); |
| 7709 | PieController.id = "pie"; |
| 7710 | PieController.defaults = { |
| 7711 | cutout: 0, |
| 7712 | rotation: 0, |
| 7713 | circumference: 360, |
| 7714 | radius: "100%" |
| 7715 | }; |
| 7716 | var RadarController = /*#__PURE__*/ function(DatasetController) { |
| 7717 | "use strict"; |
| 7718 | (0, _inheritsJsDefault.default)(RadarController, DatasetController); |
| 7719 | var _super = (0, _createSuperJsDefault.default)(RadarController); |
| 7720 | function RadarController() { |
| 7721 | (0, _classCallCheckJsDefault.default)(this, RadarController); |
| 7722 | return _super.apply(this, arguments); |
| 7723 | } |
| 7724 | (0, _createClassJsDefault.default)(RadarController, [ |
| 7725 | { |
| 7726 | key: "getLabelAndValue", |
| 7727 | value: function getLabelAndValue(index35) { |
| 7728 | var vScale = this._cachedMeta.vScale; |
| 7729 | var parsed = this.getParsed(index35); |
| 7730 | return { |
| 7731 | label: vScale.getLabels()[index35], |
| 7732 | value: "" + vScale.getLabelForValue(parsed[vScale.axis]) |
| 7733 | }; |
| 7734 | } |
| 7735 | }, |
| 7736 | { |
| 7737 | key: "parseObjectData", |
| 7738 | value: function parseObjectData(meta, data, start, count) { |
| 7739 | return (0, _helpersSegmentJs.y).bind(this)(meta, data, start, count); |
| 7740 | } |
| 7741 | }, |
| 7742 | { |
| 7743 | key: "update", |
| 7744 | value: function update(mode) { |
| 7745 | var meta = this._cachedMeta; |
| 7746 | var line = meta.dataset; |
| 7747 | var points = meta.data || []; |
| 7748 | var labels = meta.iScale.getLabels(); |
| 7749 | line.points = points; |
| 7750 | if (mode !== "resize") { |
| 7751 | var options = this.resolveDatasetElementOptions(mode); |
| 7752 | if (!this.options.showLine) options.borderWidth = 0; |
| 7753 | var properties = { |
| 7754 | _loop: true, |
| 7755 | _fullLoop: labels.length === points.length, |
| 7756 | options: options |
| 7757 | }; |
| 7758 | this.updateElement(line, undefined, properties, mode); |
| 7759 | } |
| 7760 | this.updateElements(points, 0, points.length, mode); |
| 7761 | } |
| 7762 | }, |
| 7763 | { |
| 7764 | key: "updateElements", |
| 7765 | value: function updateElements(points, start, count, mode) { |
| 7766 | var scale = this._cachedMeta.rScale; |
| 7767 | var reset = mode === "reset"; |
| 7768 | for(var i = start; i < start + count; i++){ |
| 7769 | var point = points[i]; |
| 7770 | var options = this.resolveDataElementOptions(i, point.active ? "active" : mode); |
| 7771 | var pointPosition = scale.getPointPositionForValue(i, this.getParsed(i).r); |
| 7772 | var x = reset ? scale.xCenter : pointPosition.x; |
| 7773 | var y = reset ? scale.yCenter : pointPosition.y; |
| 7774 | var properties = { |
| 7775 | x: x, |
| 7776 | y: y, |
| 7777 | angle: pointPosition.angle, |
| 7778 | skip: isNaN(x) || isNaN(y), |
| 7779 | options: options |
| 7780 | }; |
| 7781 | this.updateElement(point, i, properties, mode); |
| 7782 | } |
| 7783 | } |
| 7784 | } |
| 7785 | ]); |
| 7786 | return RadarController; |
| 7787 | }(DatasetController); |
| 7788 | RadarController.id = "radar"; |
| 7789 | RadarController.defaults = { |
| 7790 | datasetElementType: "line", |
| 7791 | dataElementType: "point", |
| 7792 | indexAxis: "r", |
| 7793 | showLine: true, |
| 7794 | elements: { |
| 7795 | line: { |
| 7796 | fill: "start" |
| 7797 | } |
| 7798 | } |
| 7799 | }; |
| 7800 | RadarController.overrides = { |
| 7801 | aspectRatio: 1, |
| 7802 | scales: { |
| 7803 | r: { |
| 7804 | type: "radialLinear" |
| 7805 | } |
| 7806 | } |
| 7807 | }; |
| 7808 | var ScatterController = /*#__PURE__*/ function(LineController) { |
| 7809 | "use strict"; |
| 7810 | (0, _inheritsJsDefault.default)(ScatterController, LineController); |
| 7811 | var _super = (0, _createSuperJsDefault.default)(ScatterController); |
| 7812 | function ScatterController() { |
| 7813 | (0, _classCallCheckJsDefault.default)(this, ScatterController); |
| 7814 | return _super.apply(this, arguments); |
| 7815 | } |
| 7816 | return ScatterController; |
| 7817 | }(LineController); |
| 7818 | ScatterController.id = "scatter"; |
| 7819 | ScatterController.defaults = { |
| 7820 | showLine: false, |
| 7821 | fill: false |
| 7822 | }; |
| 7823 | ScatterController.overrides = { |
| 7824 | interaction: { |
| 7825 | mode: "point" |
| 7826 | }, |
| 7827 | plugins: { |
| 7828 | tooltip: { |
| 7829 | callbacks: { |
| 7830 | title: function() { |
| 7831 | return ""; |
| 7832 | }, |
| 7833 | label: function(item) { |
| 7834 | return "(" + item.label + ", " + item.formattedValue + ")"; |
| 7835 | } |
| 7836 | } |
| 7837 | } |
| 7838 | }, |
| 7839 | scales: { |
| 7840 | x: { |
| 7841 | type: "linear" |
| 7842 | }, |
| 7843 | y: { |
| 7844 | type: "linear" |
| 7845 | } |
| 7846 | } |
| 7847 | }; |
| 7848 | var controllers = /*#__PURE__*/ Object.freeze({ |
| 7849 | __proto__: null, |
| 7850 | BarController: BarController, |
| 7851 | BubbleController: BubbleController, |
| 7852 | DoughnutController: DoughnutController, |
| 7853 | LineController: LineController, |
| 7854 | PolarAreaController: PolarAreaController, |
| 7855 | PieController: PieController, |
| 7856 | RadarController: RadarController, |
| 7857 | ScatterController: ScatterController |
| 7858 | }); |
| 7859 | function abstract() { |
| 7860 | throw new Error("This method is not implemented: Check that a complete date adapter is provided."); |
| 7861 | } |
| 7862 | var DateAdapter = /*#__PURE__*/ function() { |
| 7863 | "use strict"; |
| 7864 | function DateAdapter(options) { |
| 7865 | (0, _classCallCheckJsDefault.default)(this, DateAdapter); |
| 7866 | this.options = options || {}; |
| 7867 | } |
| 7868 | (0, _createClassJsDefault.default)(DateAdapter, [ |
| 7869 | { |
| 7870 | key: "formats", |
| 7871 | value: function formats() { |
| 7872 | return abstract(); |
| 7873 | } |
| 7874 | }, |
| 7875 | { |
| 7876 | key: "parse", |
| 7877 | value: function parse1(value, format) { |
| 7878 | return abstract(); |
| 7879 | } |
| 7880 | }, |
| 7881 | { |
| 7882 | key: "format", |
| 7883 | value: function format1(timestamp, format) { |
| 7884 | return abstract(); |
| 7885 | } |
| 7886 | }, |
| 7887 | { |
| 7888 | key: "add", |
| 7889 | value: function add(timestamp, amount, unit) { |
| 7890 | return abstract(); |
| 7891 | } |
| 7892 | }, |
| 7893 | { |
| 7894 | key: "diff", |
| 7895 | value: function diff(a, b, unit) { |
| 7896 | return abstract(); |
| 7897 | } |
| 7898 | }, |
| 7899 | { |
| 7900 | key: "startOf", |
| 7901 | value: function startOf(timestamp, unit, weekday) { |
| 7902 | return abstract(); |
| 7903 | } |
| 7904 | }, |
| 7905 | { |
| 7906 | key: "endOf", |
| 7907 | value: function endOf(timestamp, unit) { |
| 7908 | return abstract(); |
| 7909 | } |
| 7910 | } |
| 7911 | ]); |
| 7912 | return DateAdapter; |
| 7913 | }(); |
| 7914 | DateAdapter.override = function(members) { |
| 7915 | Object.assign(DateAdapter.prototype, members); |
| 7916 | }; |
| 7917 | var adapters = { |
| 7918 | _date: DateAdapter |
| 7919 | }; |
| 7920 | function binarySearch(metaset, axis, value, intersect) { |
| 7921 | var controller = metaset.controller, data = metaset.data, _sorted = metaset._sorted; |
| 7922 | var iScale = controller._cachedMeta.iScale; |
| 7923 | if (iScale && axis === iScale.axis && axis !== "r" && _sorted && data.length) { |
| 7924 | var lookupMethod = iScale._reversePixels ? (0, _helpersSegmentJs.A) : (0, _helpersSegmentJs.x); |
| 7925 | if (!intersect) return lookupMethod(data, axis, value); |
| 7926 | else if (controller._sharedOptions) { |
| 7927 | var el = data[0]; |
| 7928 | var range = typeof el.getRange === "function" && el.getRange(axis); |
| 7929 | if (range) { |
| 7930 | var start = lookupMethod(data, axis, value - range); |
| 7931 | var end = lookupMethod(data, axis, value + range); |
| 7932 | return { |
| 7933 | lo: start.lo, |
| 7934 | hi: end.hi |
| 7935 | }; |
| 7936 | } |
| 7937 | } |
| 7938 | } |
| 7939 | return { |
| 7940 | lo: 0, |
| 7941 | hi: data.length - 1 |
| 7942 | }; |
| 7943 | } |
| 7944 | function evaluateInteractionItems(chart, axis, position, handler, intersect) { |
| 7945 | var metasets = chart.getSortedVisibleDatasetMetas(); |
| 7946 | var value = position[axis]; |
| 7947 | for(var i = 0, ilen = metasets.length; i < ilen; ++i){ |
| 7948 | var _i = metasets[i], index36 = _i.index, data = _i.data; |
| 7949 | var ref = binarySearch(metasets[i], axis, value, intersect), lo = ref.lo, hi = ref.hi; |
| 7950 | for(var j = lo; j <= hi; ++j){ |
| 7951 | var element = data[j]; |
| 7952 | if (!element.skip) handler(element, index36, j); |
| 7953 | } |
| 7954 | } |
| 7955 | } |
| 7956 | function getDistanceMetricForAxis(axis) { |
| 7957 | var useX = axis.indexOf("x") !== -1; |
| 7958 | var useY = axis.indexOf("y") !== -1; |
| 7959 | return function(pt1, pt2) { |
| 7960 | var deltaX = useX ? Math.abs(pt1.x - pt2.x) : 0; |
| 7961 | var deltaY = useY ? Math.abs(pt1.y - pt2.y) : 0; |
| 7962 | return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); |
| 7963 | }; |
| 7964 | } |
| 7965 | function getIntersectItems(chart, position, axis, useFinalPosition, includeInvisible) { |
| 7966 | var items = []; |
| 7967 | if (!includeInvisible && !chart.isPointInArea(position)) return items; |
| 7968 | var evaluationFunc = function evaluationFunc(element, datasetIndex, index37) { |
| 7969 | if (!includeInvisible && !(0, _helpersSegmentJs.B)(element, chart.chartArea, 0)) return; |
| 7970 | if (element.inRange(position.x, position.y, useFinalPosition)) items.push({ |
| 7971 | element: element, |
| 7972 | datasetIndex: datasetIndex, |
| 7973 | index: index37 |
| 7974 | }); |
| 7975 | }; |
| 7976 | evaluateInteractionItems(chart, axis, position, evaluationFunc, true); |
| 7977 | return items; |
| 7978 | } |
| 7979 | function getNearestRadialItems(chart, position, axis, useFinalPosition) { |
| 7980 | var items = []; |
| 7981 | function evaluationFunc(element, datasetIndex, index38) { |
| 7982 | var ref = element.getProps([ |
| 7983 | "startAngle", |
| 7984 | "endAngle" |
| 7985 | ], useFinalPosition), startAngle = ref.startAngle, endAngle = ref.endAngle; |
| 7986 | var angle = (0, _helpersSegmentJs.C)(element, { |
| 7987 | x: position.x, |
| 7988 | y: position.y |
| 7989 | }).angle; |
| 7990 | if ((0, _helpersSegmentJs.p)(angle, startAngle, endAngle)) items.push({ |
| 7991 | element: element, |
| 7992 | datasetIndex: datasetIndex, |
| 7993 | index: index38 |
| 7994 | }); |
| 7995 | } |
| 7996 | evaluateInteractionItems(chart, axis, position, evaluationFunc); |
| 7997 | return items; |
| 7998 | } |
| 7999 | function getNearestCartesianItems(chart, position, axis, intersect, useFinalPosition, includeInvisible) { |
| 8000 | var items = []; |
| 8001 | var distanceMetric = getDistanceMetricForAxis(axis); |
| 8002 | var minDistance = Number.POSITIVE_INFINITY; |
| 8003 | function evaluationFunc(element, datasetIndex, index39) { |
| 8004 | var inRange1 = element.inRange(position.x, position.y, useFinalPosition); |
| 8005 | if (intersect && !inRange1) return; |
| 8006 | var center = element.getCenterPoint(useFinalPosition); |
| 8007 | var pointInArea = !!includeInvisible || chart.isPointInArea(center); |
| 8008 | if (!pointInArea && !inRange1) return; |
| 8009 | var distance = distanceMetric(position, center); |
| 8010 | if (distance < minDistance) { |
| 8011 | items = [ |
| 8012 | { |
| 8013 | element: element, |
| 8014 | datasetIndex: datasetIndex, |
| 8015 | index: index39 |
| 8016 | } |
| 8017 | ]; |
| 8018 | minDistance = distance; |
| 8019 | } else if (distance === minDistance) items.push({ |
| 8020 | element: element, |
| 8021 | datasetIndex: datasetIndex, |
| 8022 | index: index39 |
| 8023 | }); |
| 8024 | } |
| 8025 | evaluateInteractionItems(chart, axis, position, evaluationFunc); |
| 8026 | return items; |
| 8027 | } |
| 8028 | function getNearestItems(chart, position, axis, intersect, useFinalPosition, includeInvisible) { |
| 8029 | if (!includeInvisible && !chart.isPointInArea(position)) return []; |
| 8030 | return axis === "r" && !intersect ? getNearestRadialItems(chart, position, axis, useFinalPosition) : getNearestCartesianItems(chart, position, axis, intersect, useFinalPosition, includeInvisible); |
| 8031 | } |
| 8032 | function getAxisItems(chart, position, axis, intersect, useFinalPosition) { |
| 8033 | var items = []; |
| 8034 | var rangeMethod = axis === "x" ? "inXRange" : "inYRange"; |
| 8035 | var intersectsItem = false; |
| 8036 | evaluateInteractionItems(chart, axis, position, function(element, datasetIndex, index40) { |
| 8037 | if (element[rangeMethod](position[axis], useFinalPosition)) { |
| 8038 | items.push({ |
| 8039 | element: element, |
| 8040 | datasetIndex: datasetIndex, |
| 8041 | index: index40 |
| 8042 | }); |
| 8043 | intersectsItem = intersectsItem || element.inRange(position.x, position.y, useFinalPosition); |
| 8044 | } |
| 8045 | }); |
| 8046 | if (intersect && !intersectsItem) return []; |
| 8047 | return items; |
| 8048 | } |
| 8049 | var Interaction = { |
| 8050 | evaluateInteractionItems: evaluateInteractionItems, |
| 8051 | modes: { |
| 8052 | index: function(chart, e, options, useFinalPosition) { |
| 8053 | var position = (0, _helpersSegmentJs.z)(e, chart); |
| 8054 | var axis = options.axis || "x"; |
| 8055 | var includeInvisible = options.includeInvisible || false; |
| 8056 | var items = options.intersect ? getIntersectItems(chart, position, axis, useFinalPosition, includeInvisible) : getNearestItems(chart, position, axis, false, useFinalPosition, includeInvisible); |
| 8057 | var elements3 = []; |
| 8058 | if (!items.length) return []; |
| 8059 | chart.getSortedVisibleDatasetMetas().forEach(function(meta) { |
| 8060 | var index41 = items[0].index; |
| 8061 | var element = meta.data[index41]; |
| 8062 | if (element && !element.skip) elements3.push({ |
| 8063 | element: element, |
| 8064 | datasetIndex: meta.index, |
| 8065 | index: index41 |
| 8066 | }); |
| 8067 | }); |
| 8068 | return elements3; |
| 8069 | }, |
| 8070 | dataset: function(chart, e, options, useFinalPosition) { |
| 8071 | var position = (0, _helpersSegmentJs.z)(e, chart); |
| 8072 | var axis = options.axis || "xy"; |
| 8073 | var includeInvisible = options.includeInvisible || false; |
| 8074 | var items = options.intersect ? getIntersectItems(chart, position, axis, useFinalPosition, includeInvisible) : getNearestItems(chart, position, axis, false, useFinalPosition, includeInvisible); |
| 8075 | if (items.length > 0) { |
| 8076 | var datasetIndex = items[0].datasetIndex; |
| 8077 | var data = chart.getDatasetMeta(datasetIndex).data; |
| 8078 | items = []; |
| 8079 | for(var i = 0; i < data.length; ++i)items.push({ |
| 8080 | element: data[i], |
| 8081 | datasetIndex: datasetIndex, |
| 8082 | index: i |
| 8083 | }); |
| 8084 | } |
| 8085 | return items; |
| 8086 | }, |
| 8087 | point: function(chart, e, options, useFinalPosition) { |
| 8088 | var position = (0, _helpersSegmentJs.z)(e, chart); |
| 8089 | var axis = options.axis || "xy"; |
| 8090 | var includeInvisible = options.includeInvisible || false; |
| 8091 | return getIntersectItems(chart, position, axis, useFinalPosition, includeInvisible); |
| 8092 | }, |
| 8093 | nearest: function(chart, e, options, useFinalPosition) { |
| 8094 | var position = (0, _helpersSegmentJs.z)(e, chart); |
| 8095 | var axis = options.axis || "xy"; |
| 8096 | var includeInvisible = options.includeInvisible || false; |
| 8097 | return getNearestItems(chart, position, axis, options.intersect, useFinalPosition, includeInvisible); |
| 8098 | }, |
| 8099 | x: function(chart, e, options, useFinalPosition) { |
| 8100 | var position = (0, _helpersSegmentJs.z)(e, chart); |
| 8101 | return getAxisItems(chart, position, "x", options.intersect, useFinalPosition); |
| 8102 | }, |
| 8103 | y: function(chart, e, options, useFinalPosition) { |
| 8104 | var position = (0, _helpersSegmentJs.z)(e, chart); |
| 8105 | return getAxisItems(chart, position, "y", options.intersect, useFinalPosition); |
| 8106 | } |
| 8107 | } |
| 8108 | }; |
| 8109 | var STATIC_POSITIONS = [ |
| 8110 | "left", |
| 8111 | "top", |
| 8112 | "right", |
| 8113 | "bottom" |
| 8114 | ]; |
| 8115 | function filterByPosition(array, position) { |
| 8116 | return array.filter(function(v) { |
| 8117 | return v.pos === position; |
| 8118 | }); |
| 8119 | } |
| 8120 | function filterDynamicPositionByAxis(array, axis) { |
| 8121 | return array.filter(function(v) { |
| 8122 | return STATIC_POSITIONS.indexOf(v.pos) === -1 && v.box.axis === axis; |
| 8123 | }); |
| 8124 | } |
| 8125 | function sortByWeight(array, reverse) { |
| 8126 | return array.sort(function(a, b) { |
| 8127 | var v0 = reverse ? b : a; |
| 8128 | var v1 = reverse ? a : b; |
| 8129 | return v0.weight === v1.weight ? v0.index - v1.index : v0.weight - v1.weight; |
| 8130 | }); |
| 8131 | } |
| 8132 | function wrapBoxes(boxes) { |
| 8133 | var layoutBoxes = []; |
| 8134 | var i, ilen, box, pos, stack, stackWeight; |
| 8135 | for(i = 0, ilen = (boxes || []).length; i < ilen; ++i){ |
| 8136 | box = boxes[i]; |
| 8137 | var ref, ref2, ref3; |
| 8138 | ref = box, pos = ref.position, ref2 = ref.options, stack = ref2.stack, ref3 = ref2.stackWeight, stackWeight = ref3 === void 0 ? 1 : ref3, ref2, ref; |
| 8139 | layoutBoxes.push({ |
| 8140 | index: i, |
| 8141 | box: box, |
| 8142 | pos: pos, |
| 8143 | horizontal: box.isHorizontal(), |
| 8144 | weight: box.weight, |
| 8145 | stack: stack && pos + stack, |
| 8146 | stackWeight: stackWeight |
| 8147 | }); |
| 8148 | } |
| 8149 | return layoutBoxes; |
| 8150 | } |
| 8151 | function buildStacks(layouts1) { |
| 8152 | var stacks = {}; |
| 8153 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 8154 | try { |
| 8155 | for(var _iterator = layouts1[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 8156 | var wrap = _step.value; |
| 8157 | var stack = wrap.stack, pos = wrap.pos, stackWeight = wrap.stackWeight; |
| 8158 | if (!stack || !STATIC_POSITIONS.includes(pos)) continue; |
| 8159 | var _stack = stacks[stack] || (stacks[stack] = { |
| 8160 | count: 0, |
| 8161 | placed: 0, |
| 8162 | weight: 0, |
| 8163 | size: 0 |
| 8164 | }); |
| 8165 | _stack.count++; |
| 8166 | _stack.weight += stackWeight; |
| 8167 | } |
| 8168 | } catch (err) { |
| 8169 | _didIteratorError = true; |
| 8170 | _iteratorError = err; |
| 8171 | } finally{ |
| 8172 | try { |
| 8173 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 8174 | _iterator.return(); |
| 8175 | } |
| 8176 | } finally{ |
| 8177 | if (_didIteratorError) { |
| 8178 | throw _iteratorError; |
| 8179 | } |
| 8180 | } |
| 8181 | } |
| 8182 | return stacks; |
| 8183 | } |
| 8184 | function setLayoutDims(layouts2, params) { |
| 8185 | var stacks = buildStacks(layouts2); |
| 8186 | var vBoxMaxWidth = params.vBoxMaxWidth, hBoxMaxHeight = params.hBoxMaxHeight; |
| 8187 | var i, ilen, layout; |
| 8188 | for(i = 0, ilen = layouts2.length; i < ilen; ++i){ |
| 8189 | layout = layouts2[i]; |
| 8190 | var fullSize = layout.box.fullSize; |
| 8191 | var stack = stacks[layout.stack]; |
| 8192 | var factor = stack && layout.stackWeight / stack.weight; |
| 8193 | if (layout.horizontal) { |
| 8194 | layout.width = factor ? factor * vBoxMaxWidth : fullSize && params.availableWidth; |
| 8195 | layout.height = hBoxMaxHeight; |
| 8196 | } else { |
| 8197 | layout.width = vBoxMaxWidth; |
| 8198 | layout.height = factor ? factor * hBoxMaxHeight : fullSize && params.availableHeight; |
| 8199 | } |
| 8200 | } |
| 8201 | return stacks; |
| 8202 | } |
| 8203 | function buildLayoutBoxes(boxes) { |
| 8204 | var layoutBoxes = wrapBoxes(boxes); |
| 8205 | var fullSize = sortByWeight(layoutBoxes.filter(function(wrap) { |
| 8206 | return wrap.box.fullSize; |
| 8207 | }), true); |
| 8208 | var left = sortByWeight(filterByPosition(layoutBoxes, "left"), true); |
| 8209 | var right = sortByWeight(filterByPosition(layoutBoxes, "right")); |
| 8210 | var top = sortByWeight(filterByPosition(layoutBoxes, "top"), true); |
| 8211 | var bottom = sortByWeight(filterByPosition(layoutBoxes, "bottom")); |
| 8212 | var centerHorizontal = filterDynamicPositionByAxis(layoutBoxes, "x"); |
| 8213 | var centerVertical = filterDynamicPositionByAxis(layoutBoxes, "y"); |
| 8214 | return { |
| 8215 | fullSize: fullSize, |
| 8216 | leftAndTop: left.concat(top), |
| 8217 | rightAndBottom: right.concat(centerVertical).concat(bottom).concat(centerHorizontal), |
| 8218 | chartArea: filterByPosition(layoutBoxes, "chartArea"), |
| 8219 | vertical: left.concat(right).concat(centerVertical), |
| 8220 | horizontal: top.concat(bottom).concat(centerHorizontal) |
| 8221 | }; |
| 8222 | } |
| 8223 | function getCombinedMax(maxPadding, chartArea, a, b) { |
| 8224 | return Math.max(maxPadding[a], chartArea[a]) + Math.max(maxPadding[b], chartArea[b]); |
| 8225 | } |
| 8226 | function updateMaxPadding(maxPadding, boxPadding) { |
| 8227 | maxPadding.top = Math.max(maxPadding.top, boxPadding.top); |
| 8228 | maxPadding.left = Math.max(maxPadding.left, boxPadding.left); |
| 8229 | maxPadding.bottom = Math.max(maxPadding.bottom, boxPadding.bottom); |
| 8230 | maxPadding.right = Math.max(maxPadding.right, boxPadding.right); |
| 8231 | } |
| 8232 | function updateDims(chartArea, params, layout, stacks) { |
| 8233 | var pos = layout.pos, box = layout.box; |
| 8234 | var maxPadding = chartArea.maxPadding; |
| 8235 | if (!(0, _helpersSegmentJs.i)(pos)) { |
| 8236 | if (layout.size) chartArea[pos] -= layout.size; |
| 8237 | var stack = stacks[layout.stack] || { |
| 8238 | size: 0, |
| 8239 | count: 1 |
| 8240 | }; |
| 8241 | stack.size = Math.max(stack.size, layout.horizontal ? box.height : box.width); |
| 8242 | layout.size = stack.size / stack.count; |
| 8243 | chartArea[pos] += layout.size; |
| 8244 | } |
| 8245 | if (box.getPadding) updateMaxPadding(maxPadding, box.getPadding()); |
| 8246 | var newWidth = Math.max(0, params.outerWidth - getCombinedMax(maxPadding, chartArea, "left", "right")); |
| 8247 | var newHeight = Math.max(0, params.outerHeight - getCombinedMax(maxPadding, chartArea, "top", "bottom")); |
| 8248 | var widthChanged = newWidth !== chartArea.w; |
| 8249 | var heightChanged = newHeight !== chartArea.h; |
| 8250 | chartArea.w = newWidth; |
| 8251 | chartArea.h = newHeight; |
| 8252 | return layout.horizontal ? { |
| 8253 | same: widthChanged, |
| 8254 | other: heightChanged |
| 8255 | } : { |
| 8256 | same: heightChanged, |
| 8257 | other: widthChanged |
| 8258 | }; |
| 8259 | } |
| 8260 | function handleMaxPadding(chartArea) { |
| 8261 | var maxPadding = chartArea.maxPadding; |
| 8262 | function updatePos(pos) { |
| 8263 | var change = Math.max(maxPadding[pos] - chartArea[pos], 0); |
| 8264 | chartArea[pos] += change; |
| 8265 | return change; |
| 8266 | } |
| 8267 | chartArea.y += updatePos("top"); |
| 8268 | chartArea.x += updatePos("left"); |
| 8269 | updatePos("right"); |
| 8270 | updatePos("bottom"); |
| 8271 | } |
| 8272 | function getMargins(horizontal, chartArea) { |
| 8273 | var maxPadding = chartArea.maxPadding; |
| 8274 | function marginForPositions(positions) { |
| 8275 | var margin = { |
| 8276 | left: 0, |
| 8277 | top: 0, |
| 8278 | right: 0, |
| 8279 | bottom: 0 |
| 8280 | }; |
| 8281 | positions.forEach(function(pos) { |
| 8282 | margin[pos] = Math.max(chartArea[pos], maxPadding[pos]); |
| 8283 | }); |
| 8284 | return margin; |
| 8285 | } |
| 8286 | return horizontal ? marginForPositions([ |
| 8287 | "left", |
| 8288 | "right" |
| 8289 | ]) : marginForPositions([ |
| 8290 | "top", |
| 8291 | "bottom" |
| 8292 | ]); |
| 8293 | } |
| 8294 | function fitBoxes(boxes, chartArea, params, stacks) { |
| 8295 | var refitBoxes = []; |
| 8296 | var i, ilen, layout, box, refit, changed; |
| 8297 | for(i = 0, ilen = boxes.length, refit = 0; i < ilen; ++i){ |
| 8298 | layout = boxes[i]; |
| 8299 | box = layout.box; |
| 8300 | box.update(layout.width || chartArea.w, layout.height || chartArea.h, getMargins(layout.horizontal, chartArea)); |
| 8301 | var ref = updateDims(chartArea, params, layout, stacks), same = ref.same, other = ref.other; |
| 8302 | refit |= same && refitBoxes.length; |
| 8303 | changed = changed || other; |
| 8304 | if (!box.fullSize) refitBoxes.push(layout); |
| 8305 | } |
| 8306 | return refit && fitBoxes(refitBoxes, chartArea, params, stacks) || changed; |
| 8307 | } |
| 8308 | function setBoxDims(box, left, top, width, height) { |
| 8309 | box.top = top; |
| 8310 | box.left = left; |
| 8311 | box.right = left + width; |
| 8312 | box.bottom = top + height; |
| 8313 | box.width = width; |
| 8314 | box.height = height; |
| 8315 | } |
| 8316 | function placeBoxes(boxes, chartArea, params, stacks) { |
| 8317 | var userPadding = params.padding; |
| 8318 | var x = chartArea.x, y = chartArea.y; |
| 8319 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 8320 | try { |
| 8321 | for(var _iterator = boxes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 8322 | var layout = _step.value; |
| 8323 | var box = layout.box; |
| 8324 | var stack = stacks[layout.stack] || { |
| 8325 | count: 1, |
| 8326 | placed: 0, |
| 8327 | weight: 1 |
| 8328 | }; |
| 8329 | var weight = layout.stackWeight / stack.weight || 1; |
| 8330 | if (layout.horizontal) { |
| 8331 | var width = chartArea.w * weight; |
| 8332 | var height = stack.size || box.height; |
| 8333 | if ((0, _helpersSegmentJs.j)(stack.start)) y = stack.start; |
| 8334 | if (box.fullSize) setBoxDims(box, userPadding.left, y, params.outerWidth - userPadding.right - userPadding.left, height); |
| 8335 | else setBoxDims(box, chartArea.left + stack.placed, y, width, height); |
| 8336 | stack.start = y; |
| 8337 | stack.placed += width; |
| 8338 | y = box.bottom; |
| 8339 | } else { |
| 8340 | var height1 = chartArea.h * weight; |
| 8341 | var width1 = stack.size || box.width; |
| 8342 | if ((0, _helpersSegmentJs.j)(stack.start)) x = stack.start; |
| 8343 | if (box.fullSize) setBoxDims(box, x, userPadding.top, width1, params.outerHeight - userPadding.bottom - userPadding.top); |
| 8344 | else setBoxDims(box, x, chartArea.top + stack.placed, width1, height1); |
| 8345 | stack.start = x; |
| 8346 | stack.placed += height1; |
| 8347 | x = box.right; |
| 8348 | } |
| 8349 | } |
| 8350 | } catch (err) { |
| 8351 | _didIteratorError = true; |
| 8352 | _iteratorError = err; |
| 8353 | } finally{ |
| 8354 | try { |
| 8355 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 8356 | _iterator.return(); |
| 8357 | } |
| 8358 | } finally{ |
| 8359 | if (_didIteratorError) { |
| 8360 | throw _iteratorError; |
| 8361 | } |
| 8362 | } |
| 8363 | } |
| 8364 | chartArea.x = x; |
| 8365 | chartArea.y = y; |
| 8366 | } |
| 8367 | (0, _helpersSegmentJs.d).set("layout", { |
| 8368 | autoPadding: true, |
| 8369 | padding: { |
| 8370 | top: 0, |
| 8371 | right: 0, |
| 8372 | bottom: 0, |
| 8373 | left: 0 |
| 8374 | } |
| 8375 | }); |
| 8376 | var layouts = { |
| 8377 | addBox: function(chart, item) { |
| 8378 | if (!chart.boxes) chart.boxes = []; |
| 8379 | item.fullSize = item.fullSize || false; |
| 8380 | item.position = item.position || "top"; |
| 8381 | item.weight = item.weight || 0; |
| 8382 | item._layers = item._layers || function() { |
| 8383 | return [ |
| 8384 | { |
| 8385 | z: 0, |
| 8386 | draw: function(chartArea) { |
| 8387 | item.draw(chartArea); |
| 8388 | } |
| 8389 | } |
| 8390 | ]; |
| 8391 | }; |
| 8392 | chart.boxes.push(item); |
| 8393 | }, |
| 8394 | removeBox: function(chart, layoutItem) { |
| 8395 | var index42 = chart.boxes ? chart.boxes.indexOf(layoutItem) : -1; |
| 8396 | if (index42 !== -1) chart.boxes.splice(index42, 1); |
| 8397 | }, |
| 8398 | configure: function(chart, item, options) { |
| 8399 | item.fullSize = options.fullSize; |
| 8400 | item.position = options.position; |
| 8401 | item.weight = options.weight; |
| 8402 | }, |
| 8403 | update: function(chart, width, height, minPadding) { |
| 8404 | if (!chart) return; |
| 8405 | var padding = (0, _helpersSegmentJs.D)(chart.options.layout.padding); |
| 8406 | var availableWidth = Math.max(width - padding.width, 0); |
| 8407 | var availableHeight = Math.max(height - padding.height, 0); |
| 8408 | var boxes = buildLayoutBoxes(chart.boxes); |
| 8409 | var verticalBoxes = boxes.vertical; |
| 8410 | var horizontalBoxes = boxes.horizontal; |
| 8411 | (0, _helpersSegmentJs.E)(chart.boxes, function(box) { |
| 8412 | if (typeof box.beforeLayout === "function") box.beforeLayout(); |
| 8413 | }); |
| 8414 | var visibleVerticalBoxCount = verticalBoxes.reduce(function(total, wrap) { |
| 8415 | return wrap.box.options && wrap.box.options.display === false ? total : total + 1; |
| 8416 | }, 0) || 1; |
| 8417 | var params = Object.freeze({ |
| 8418 | outerWidth: width, |
| 8419 | outerHeight: height, |
| 8420 | padding: padding, |
| 8421 | availableWidth: availableWidth, |
| 8422 | availableHeight: availableHeight, |
| 8423 | vBoxMaxWidth: availableWidth / 2 / visibleVerticalBoxCount, |
| 8424 | hBoxMaxHeight: availableHeight / 2 |
| 8425 | }); |
| 8426 | var maxPadding = Object.assign({}, padding); |
| 8427 | updateMaxPadding(maxPadding, (0, _helpersSegmentJs.D)(minPadding)); |
| 8428 | var chartArea = Object.assign({ |
| 8429 | maxPadding: maxPadding, |
| 8430 | w: availableWidth, |
| 8431 | h: availableHeight, |
| 8432 | x: padding.left, |
| 8433 | y: padding.top |
| 8434 | }, padding); |
| 8435 | var stacks = setLayoutDims(verticalBoxes.concat(horizontalBoxes), params); |
| 8436 | fitBoxes(boxes.fullSize, chartArea, params, stacks); |
| 8437 | fitBoxes(verticalBoxes, chartArea, params, stacks); |
| 8438 | if (fitBoxes(horizontalBoxes, chartArea, params, stacks)) fitBoxes(verticalBoxes, chartArea, params, stacks); |
| 8439 | handleMaxPadding(chartArea); |
| 8440 | placeBoxes(boxes.leftAndTop, chartArea, params, stacks); |
| 8441 | chartArea.x += chartArea.w; |
| 8442 | chartArea.y += chartArea.h; |
| 8443 | placeBoxes(boxes.rightAndBottom, chartArea, params, stacks); |
| 8444 | chart.chartArea = { |
| 8445 | left: chartArea.left, |
| 8446 | top: chartArea.top, |
| 8447 | right: chartArea.left + chartArea.w, |
| 8448 | bottom: chartArea.top + chartArea.h, |
| 8449 | height: chartArea.h, |
| 8450 | width: chartArea.w |
| 8451 | }; |
| 8452 | (0, _helpersSegmentJs.E)(boxes.chartArea, function(layout) { |
| 8453 | var box = layout.box; |
| 8454 | Object.assign(box, chart.chartArea); |
| 8455 | box.update(chartArea.w, chartArea.h, { |
| 8456 | left: 0, |
| 8457 | top: 0, |
| 8458 | right: 0, |
| 8459 | bottom: 0 |
| 8460 | }); |
| 8461 | }); |
| 8462 | } |
| 8463 | }; |
| 8464 | var BasePlatform = /*#__PURE__*/ function() { |
| 8465 | "use strict"; |
| 8466 | function BasePlatform() { |
| 8467 | (0, _classCallCheckJsDefault.default)(this, BasePlatform); |
| 8468 | } |
| 8469 | (0, _createClassJsDefault.default)(BasePlatform, [ |
| 8470 | { |
| 8471 | key: "acquireContext", |
| 8472 | value: function acquireContext(canvas, aspectRatio) {} |
| 8473 | }, |
| 8474 | { |
| 8475 | key: "releaseContext", |
| 8476 | value: function releaseContext(context) { |
| 8477 | return false; |
| 8478 | } |
| 8479 | }, |
| 8480 | { |
| 8481 | key: "addEventListener", |
| 8482 | value: function addEventListener(chart, type, listener) {} |
| 8483 | }, |
| 8484 | { |
| 8485 | key: "removeEventListener", |
| 8486 | value: function removeEventListener(chart, type, listener) {} |
| 8487 | }, |
| 8488 | { |
| 8489 | key: "getDevicePixelRatio", |
| 8490 | value: function getDevicePixelRatio() { |
| 8491 | return 1; |
| 8492 | } |
| 8493 | }, |
| 8494 | { |
| 8495 | key: "getMaximumSize", |
| 8496 | value: function getMaximumSize(element, width, height, aspectRatio) { |
| 8497 | width = Math.max(0, width || element.width); |
| 8498 | height = height || element.height; |
| 8499 | return { |
| 8500 | width: width, |
| 8501 | height: Math.max(0, aspectRatio ? Math.floor(width / aspectRatio) : height) |
| 8502 | }; |
| 8503 | } |
| 8504 | }, |
| 8505 | { |
| 8506 | key: "isAttached", |
| 8507 | value: function isAttached(canvas) { |
| 8508 | return true; |
| 8509 | } |
| 8510 | }, |
| 8511 | { |
| 8512 | key: "updateConfig", |
| 8513 | value: function updateConfig(config) {} |
| 8514 | } |
| 8515 | ]); |
| 8516 | return BasePlatform; |
| 8517 | }(); |
| 8518 | var BasicPlatform = /*#__PURE__*/ function(BasePlatform) { |
| 8519 | "use strict"; |
| 8520 | (0, _inheritsJsDefault.default)(BasicPlatform, BasePlatform); |
| 8521 | var _super = (0, _createSuperJsDefault.default)(BasicPlatform); |
| 8522 | function BasicPlatform() { |
| 8523 | (0, _classCallCheckJsDefault.default)(this, BasicPlatform); |
| 8524 | return _super.apply(this, arguments); |
| 8525 | } |
| 8526 | (0, _createClassJsDefault.default)(BasicPlatform, [ |
| 8527 | { |
| 8528 | key: "acquireContext", |
| 8529 | value: function acquireContext(item) { |
| 8530 | return item && item.getContext && item.getContext("2d") || null; |
| 8531 | } |
| 8532 | }, |
| 8533 | { |
| 8534 | key: "updateConfig", |
| 8535 | value: function updateConfig(config) { |
| 8536 | config.options.animation = false; |
| 8537 | } |
| 8538 | } |
| 8539 | ]); |
| 8540 | return BasicPlatform; |
| 8541 | }(BasePlatform); |
| 8542 | var EXPANDO_KEY = "$chartjs"; |
| 8543 | var EVENT_TYPES = { |
| 8544 | touchstart: "mousedown", |
| 8545 | touchmove: "mousemove", |
| 8546 | touchend: "mouseup", |
| 8547 | pointerenter: "mouseenter", |
| 8548 | pointerdown: "mousedown", |
| 8549 | pointermove: "mousemove", |
| 8550 | pointerup: "mouseup", |
| 8551 | pointerleave: "mouseout", |
| 8552 | pointerout: "mouseout" |
| 8553 | }; |
| 8554 | var isNullOrEmpty = function(value) { |
| 8555 | return value === null || value === ""; |
| 8556 | }; |
| 8557 | function initCanvas(canvas, aspectRatio) { |
| 8558 | var style = canvas.style; |
| 8559 | var renderHeight = canvas.getAttribute("height"); |
| 8560 | var renderWidth = canvas.getAttribute("width"); |
| 8561 | canvas[EXPANDO_KEY] = { |
| 8562 | initial: { |
| 8563 | height: renderHeight, |
| 8564 | width: renderWidth, |
| 8565 | style: { |
| 8566 | display: style.display, |
| 8567 | height: style.height, |
| 8568 | width: style.width |
| 8569 | } |
| 8570 | } |
| 8571 | }; |
| 8572 | style.display = style.display || "block"; |
| 8573 | style.boxSizing = style.boxSizing || "border-box"; |
| 8574 | if (isNullOrEmpty(renderWidth)) { |
| 8575 | var displayWidth = (0, _helpersSegmentJs.I)(canvas, "width"); |
| 8576 | if (displayWidth !== undefined) canvas.width = displayWidth; |
| 8577 | } |
| 8578 | if (isNullOrEmpty(renderHeight)) { |
| 8579 | if (canvas.style.height === "") canvas.height = canvas.width / (aspectRatio || 2); |
| 8580 | else { |
| 8581 | var displayHeight = (0, _helpersSegmentJs.I)(canvas, "height"); |
| 8582 | if (displayHeight !== undefined) canvas.height = displayHeight; |
| 8583 | } |
| 8584 | } |
| 8585 | return canvas; |
| 8586 | } |
| 8587 | var eventListenerOptions = (0, _helpersSegmentJs.K) ? { |
| 8588 | passive: true |
| 8589 | } : false; |
| 8590 | function addListener(node, type, listener) { |
| 8591 | node.addEventListener(type, listener, eventListenerOptions); |
| 8592 | } |
| 8593 | function removeListener(chart, type, listener) { |
| 8594 | chart.canvas.removeEventListener(type, listener, eventListenerOptions); |
| 8595 | } |
| 8596 | function fromNativeEvent(event, chart) { |
| 8597 | var type = EVENT_TYPES[event.type] || event.type; |
| 8598 | var ref = (0, _helpersSegmentJs.z)(event, chart), x = ref.x, y = ref.y; |
| 8599 | return { |
| 8600 | type: type, |
| 8601 | chart: chart, |
| 8602 | native: event, |
| 8603 | x: x !== undefined ? x : null, |
| 8604 | y: y !== undefined ? y : null |
| 8605 | }; |
| 8606 | } |
| 8607 | function nodeListContains(nodeList, canvas) { |
| 8608 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 8609 | try { |
| 8610 | for(var _iterator = nodeList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 8611 | var node = _step.value; |
| 8612 | if (node === canvas || node.contains(canvas)) return true; |
| 8613 | } |
| 8614 | } catch (err) { |
| 8615 | _didIteratorError = true; |
| 8616 | _iteratorError = err; |
| 8617 | } finally{ |
| 8618 | try { |
| 8619 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 8620 | _iterator.return(); |
| 8621 | } |
| 8622 | } finally{ |
| 8623 | if (_didIteratorError) { |
| 8624 | throw _iteratorError; |
| 8625 | } |
| 8626 | } |
| 8627 | } |
| 8628 | } |
| 8629 | function createAttachObserver(chart, type, listener) { |
| 8630 | var canvas = chart.canvas; |
| 8631 | var observer = new MutationObserver(function(entries) { |
| 8632 | var trigger = false; |
| 8633 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 8634 | try { |
| 8635 | for(var _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 8636 | var entry = _step.value; |
| 8637 | trigger = trigger || nodeListContains(entry.addedNodes, canvas); |
| 8638 | trigger = trigger && !nodeListContains(entry.removedNodes, canvas); |
| 8639 | } |
| 8640 | } catch (err) { |
| 8641 | _didIteratorError = true; |
| 8642 | _iteratorError = err; |
| 8643 | } finally{ |
| 8644 | try { |
| 8645 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 8646 | _iterator.return(); |
| 8647 | } |
| 8648 | } finally{ |
| 8649 | if (_didIteratorError) { |
| 8650 | throw _iteratorError; |
| 8651 | } |
| 8652 | } |
| 8653 | } |
| 8654 | if (trigger) listener(); |
| 8655 | }); |
| 8656 | observer.observe(document, { |
| 8657 | childList: true, |
| 8658 | subtree: true |
| 8659 | }); |
| 8660 | return observer; |
| 8661 | } |
| 8662 | function createDetachObserver(chart, type, listener) { |
| 8663 | var canvas = chart.canvas; |
| 8664 | var observer = new MutationObserver(function(entries) { |
| 8665 | var trigger = false; |
| 8666 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 8667 | try { |
| 8668 | for(var _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 8669 | var entry = _step.value; |
| 8670 | trigger = trigger || nodeListContains(entry.removedNodes, canvas); |
| 8671 | trigger = trigger && !nodeListContains(entry.addedNodes, canvas); |
| 8672 | } |
| 8673 | } catch (err) { |
| 8674 | _didIteratorError = true; |
| 8675 | _iteratorError = err; |
| 8676 | } finally{ |
| 8677 | try { |
| 8678 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 8679 | _iterator.return(); |
| 8680 | } |
| 8681 | } finally{ |
| 8682 | if (_didIteratorError) { |
| 8683 | throw _iteratorError; |
| 8684 | } |
| 8685 | } |
| 8686 | } |
| 8687 | if (trigger) listener(); |
| 8688 | }); |
| 8689 | observer.observe(document, { |
| 8690 | childList: true, |
| 8691 | subtree: true |
| 8692 | }); |
| 8693 | return observer; |
| 8694 | } |
| 8695 | var drpListeningCharts = new Map(); |
| 8696 | var oldDevicePixelRatio = 0; |
| 8697 | function onWindowResize() { |
| 8698 | var dpr = window.devicePixelRatio; |
| 8699 | if (dpr === oldDevicePixelRatio) return; |
| 8700 | oldDevicePixelRatio = dpr; |
| 8701 | drpListeningCharts.forEach(function(resize, chart) { |
| 8702 | if (chart.currentDevicePixelRatio !== dpr) resize(); |
| 8703 | }); |
| 8704 | } |
| 8705 | function listenDevicePixelRatioChanges(chart, resize) { |
| 8706 | if (!drpListeningCharts.size) window.addEventListener("resize", onWindowResize); |
| 8707 | drpListeningCharts.set(chart, resize); |
| 8708 | } |
| 8709 | function unlistenDevicePixelRatioChanges(chart) { |
| 8710 | drpListeningCharts.delete(chart); |
| 8711 | if (!drpListeningCharts.size) window.removeEventListener("resize", onWindowResize); |
| 8712 | } |
| 8713 | function createResizeObserver(chart, type, listener) { |
| 8714 | var canvas = chart.canvas; |
| 8715 | var container = canvas && (0, _helpersSegmentJs.G)(canvas); |
| 8716 | if (!container) return; |
| 8717 | var resize = (0, _helpersSegmentJs.J)(function(width, height) { |
| 8718 | var w = container.clientWidth; |
| 8719 | listener(width, height); |
| 8720 | if (w < container.clientWidth) listener(); |
| 8721 | }, window); |
| 8722 | var observer = new ResizeObserver(function(entries) { |
| 8723 | var entry = entries[0]; |
| 8724 | var width = entry.contentRect.width; |
| 8725 | var height = entry.contentRect.height; |
| 8726 | if (width === 0 && height === 0) return; |
| 8727 | resize(width, height); |
| 8728 | }); |
| 8729 | observer.observe(container); |
| 8730 | listenDevicePixelRatioChanges(chart, resize); |
| 8731 | return observer; |
| 8732 | } |
| 8733 | function releaseObserver(chart, type, observer) { |
| 8734 | if (observer) observer.disconnect(); |
| 8735 | if (type === "resize") unlistenDevicePixelRatioChanges(chart); |
| 8736 | } |
| 8737 | function createProxyAndListen(chart, type, listener) { |
| 8738 | var canvas = chart.canvas; |
| 8739 | var proxy = (0, _helpersSegmentJs.J)(function(event) { |
| 8740 | if (chart.ctx !== null) listener(fromNativeEvent(event, chart)); |
| 8741 | }, chart, function(args) { |
| 8742 | var event = args[0]; |
| 8743 | return [ |
| 8744 | event, |
| 8745 | event.offsetX, |
| 8746 | event.offsetY |
| 8747 | ]; |
| 8748 | }); |
| 8749 | addListener(canvas, type, proxy); |
| 8750 | return proxy; |
| 8751 | } |
| 8752 | var DomPlatform = /*#__PURE__*/ function(BasePlatform) { |
| 8753 | "use strict"; |
| 8754 | (0, _inheritsJsDefault.default)(DomPlatform, BasePlatform); |
| 8755 | var _super = (0, _createSuperJsDefault.default)(DomPlatform); |
| 8756 | function DomPlatform() { |
| 8757 | (0, _classCallCheckJsDefault.default)(this, DomPlatform); |
| 8758 | return _super.apply(this, arguments); |
| 8759 | } |
| 8760 | (0, _createClassJsDefault.default)(DomPlatform, [ |
| 8761 | { |
| 8762 | key: "acquireContext", |
| 8763 | value: function acquireContext(canvas, aspectRatio) { |
| 8764 | var context = canvas && canvas.getContext && canvas.getContext("2d"); |
| 8765 | if (context && context.canvas === canvas) { |
| 8766 | initCanvas(canvas, aspectRatio); |
| 8767 | return context; |
| 8768 | } |
| 8769 | return null; |
| 8770 | } |
| 8771 | }, |
| 8772 | { |
| 8773 | key: "releaseContext", |
| 8774 | value: function releaseContext(context) { |
| 8775 | var canvas = context.canvas; |
| 8776 | if (!canvas[EXPANDO_KEY]) return false; |
| 8777 | var initial = canvas[EXPANDO_KEY].initial; |
| 8778 | [ |
| 8779 | "height", |
| 8780 | "width" |
| 8781 | ].forEach(function(prop) { |
| 8782 | var value = initial[prop]; |
| 8783 | if ((0, _helpersSegmentJs.k)(value)) canvas.removeAttribute(prop); |
| 8784 | else canvas.setAttribute(prop, value); |
| 8785 | }); |
| 8786 | var style = initial.style || {}; |
| 8787 | Object.keys(style).forEach(function(key) { |
| 8788 | canvas.style[key] = style[key]; |
| 8789 | }); |
| 8790 | canvas.width = canvas.width; |
| 8791 | delete canvas[EXPANDO_KEY]; |
| 8792 | return true; |
| 8793 | } |
| 8794 | }, |
| 8795 | { |
| 8796 | key: "addEventListener", |
| 8797 | value: function addEventListener(chart, type, listener) { |
| 8798 | this.removeEventListener(chart, type); |
| 8799 | var proxies = chart.$proxies || (chart.$proxies = {}); |
| 8800 | var handlers = { |
| 8801 | attach: createAttachObserver, |
| 8802 | detach: createDetachObserver, |
| 8803 | resize: createResizeObserver |
| 8804 | }; |
| 8805 | var handler = handlers[type] || createProxyAndListen; |
| 8806 | proxies[type] = handler(chart, type, listener); |
| 8807 | } |
| 8808 | }, |
| 8809 | { |
| 8810 | key: "removeEventListener", |
| 8811 | value: function removeEventListener(chart, type) { |
| 8812 | var proxies = chart.$proxies || (chart.$proxies = {}); |
| 8813 | var proxy = proxies[type]; |
| 8814 | if (!proxy) return; |
| 8815 | var handlers = { |
| 8816 | attach: releaseObserver, |
| 8817 | detach: releaseObserver, |
| 8818 | resize: releaseObserver |
| 8819 | }; |
| 8820 | var handler = handlers[type] || removeListener; |
| 8821 | handler(chart, type, proxy); |
| 8822 | proxies[type] = undefined; |
| 8823 | } |
| 8824 | }, |
| 8825 | { |
| 8826 | key: "getDevicePixelRatio", |
| 8827 | value: function getDevicePixelRatio() { |
| 8828 | return window.devicePixelRatio; |
| 8829 | } |
| 8830 | }, |
| 8831 | { |
| 8832 | key: "getMaximumSize", |
| 8833 | value: function getMaximumSize(canvas, width, height, aspectRatio) { |
| 8834 | return (0, _helpersSegmentJs.F)(canvas, width, height, aspectRatio); |
| 8835 | } |
| 8836 | }, |
| 8837 | { |
| 8838 | key: "isAttached", |
| 8839 | value: function isAttached(canvas) { |
| 8840 | var container = (0, _helpersSegmentJs.G)(canvas); |
| 8841 | return !!(container && container.isConnected); |
| 8842 | } |
| 8843 | } |
| 8844 | ]); |
| 8845 | return DomPlatform; |
| 8846 | }(BasePlatform); |
| 8847 | function _detectPlatform(canvas) { |
| 8848 | if (!(0, _helpersSegmentJs.L)() || typeof OffscreenCanvas !== "undefined" && canvas instanceof OffscreenCanvas) return BasicPlatform; |
| 8849 | return DomPlatform; |
| 8850 | } |
| 8851 | var Element = /*#__PURE__*/ function() { |
| 8852 | "use strict"; |
| 8853 | function Element() { |
| 8854 | (0, _classCallCheckJsDefault.default)(this, Element); |
| 8855 | this.x = undefined; |
| 8856 | this.y = undefined; |
| 8857 | this.active = false; |
| 8858 | this.options = undefined; |
| 8859 | this.$animations = undefined; |
| 8860 | } |
| 8861 | (0, _createClassJsDefault.default)(Element, [ |
| 8862 | { |
| 8863 | key: "tooltipPosition", |
| 8864 | value: function tooltipPosition(useFinalPosition) { |
| 8865 | var ref = this.getProps([ |
| 8866 | "x", |
| 8867 | "y" |
| 8868 | ], useFinalPosition), x = ref.x, y = ref.y; |
| 8869 | return { |
| 8870 | x: x, |
| 8871 | y: y |
| 8872 | }; |
| 8873 | } |
| 8874 | }, |
| 8875 | { |
| 8876 | key: "hasValue", |
| 8877 | value: function hasValue() { |
| 8878 | return (0, _helpersSegmentJs.q)(this.x) && (0, _helpersSegmentJs.q)(this.y); |
| 8879 | } |
| 8880 | }, |
| 8881 | { |
| 8882 | key: "getProps", |
| 8883 | value: function getProps(props, final) { |
| 8884 | var _this = this; |
| 8885 | var anims = this.$animations; |
| 8886 | if (!final || !anims) return this; |
| 8887 | var ret = {}; |
| 8888 | props.forEach(function(prop) { |
| 8889 | ret[prop] = anims[prop] && anims[prop].active() ? anims[prop]._to : _this[prop]; |
| 8890 | }); |
| 8891 | return ret; |
| 8892 | } |
| 8893 | } |
| 8894 | ]); |
| 8895 | return Element; |
| 8896 | }(); |
| 8897 | Element.defaults = {}; |
| 8898 | Element.defaultRoutes = undefined; |
| 8899 | var formatters = { |
| 8900 | values: function(value) { |
| 8901 | return (0, _helpersSegmentJs.b)(value) ? value : "" + value; |
| 8902 | }, |
| 8903 | numeric: function(tickValue, index, ticks) { |
| 8904 | if (tickValue === 0) return "0"; |
| 8905 | var locale = this.chart.options.locale; |
| 8906 | var notation; |
| 8907 | var delta = tickValue; |
| 8908 | if (ticks.length > 1) { |
| 8909 | var maxTick = Math.max(Math.abs(ticks[0].value), Math.abs(ticks[ticks.length - 1].value)); |
| 8910 | if (maxTick < 1e-4 || maxTick > 1e+15) notation = "scientific"; |
| 8911 | delta = calculateDelta(tickValue, ticks); |
| 8912 | } |
| 8913 | var logDelta = (0, _helpersSegmentJs.M)(Math.abs(delta)); |
| 8914 | var numDecimal = Math.max(Math.min(-1 * Math.floor(logDelta), 20), 0); |
| 8915 | var options = { |
| 8916 | notation: notation, |
| 8917 | minimumFractionDigits: numDecimal, |
| 8918 | maximumFractionDigits: numDecimal |
| 8919 | }; |
| 8920 | Object.assign(options, this.options.ticks.format); |
| 8921 | return (0, _helpersSegmentJs.o)(tickValue, locale, options); |
| 8922 | }, |
| 8923 | logarithmic: function(tickValue, index43, ticks) { |
| 8924 | if (tickValue === 0) return "0"; |
| 8925 | var remain = tickValue / Math.pow(10, Math.floor((0, _helpersSegmentJs.M)(tickValue))); |
| 8926 | if (remain === 1 || remain === 2 || remain === 5) return formatters.numeric.call(this, tickValue, index43, ticks); |
| 8927 | return ""; |
| 8928 | } |
| 8929 | }; |
| 8930 | function calculateDelta(tickValue, ticks) { |
| 8931 | var delta = ticks.length > 3 ? ticks[2].value - ticks[1].value : ticks[1].value - ticks[0].value; |
| 8932 | if (Math.abs(delta) >= 1 && tickValue !== Math.floor(tickValue)) delta = tickValue - Math.floor(tickValue); |
| 8933 | return delta; |
| 8934 | } |
| 8935 | var Ticks = { |
| 8936 | formatters: formatters |
| 8937 | }; |
| 8938 | (0, _helpersSegmentJs.d).set("scale", { |
| 8939 | display: true, |
| 8940 | offset: false, |
| 8941 | reverse: false, |
| 8942 | beginAtZero: false, |
| 8943 | bounds: "ticks", |
| 8944 | grace: 0, |
| 8945 | grid: { |
| 8946 | display: true, |
| 8947 | lineWidth: 1, |
| 8948 | drawBorder: true, |
| 8949 | drawOnChartArea: true, |
| 8950 | drawTicks: true, |
| 8951 | tickLength: 8, |
| 8952 | tickWidth: function(_ctx, options) { |
| 8953 | return options.lineWidth; |
| 8954 | }, |
| 8955 | tickColor: function(_ctx, options) { |
| 8956 | return options.color; |
| 8957 | }, |
| 8958 | offset: false, |
| 8959 | borderDash: [], |
| 8960 | borderDashOffset: 0.0, |
| 8961 | borderWidth: 1 |
| 8962 | }, |
| 8963 | title: { |
| 8964 | display: false, |
| 8965 | text: "", |
| 8966 | padding: { |
| 8967 | top: 4, |
| 8968 | bottom: 4 |
| 8969 | } |
| 8970 | }, |
| 8971 | ticks: { |
| 8972 | minRotation: 0, |
| 8973 | maxRotation: 50, |
| 8974 | mirror: false, |
| 8975 | textStrokeWidth: 0, |
| 8976 | textStrokeColor: "", |
| 8977 | padding: 3, |
| 8978 | display: true, |
| 8979 | autoSkip: true, |
| 8980 | autoSkipPadding: 3, |
| 8981 | labelOffset: 0, |
| 8982 | callback: Ticks.formatters.values, |
| 8983 | minor: {}, |
| 8984 | major: {}, |
| 8985 | align: "center", |
| 8986 | crossAlign: "near", |
| 8987 | showLabelBackdrop: false, |
| 8988 | backdropColor: "rgba(255, 255, 255, 0.75)", |
| 8989 | backdropPadding: 2 |
| 8990 | } |
| 8991 | }); |
| 8992 | (0, _helpersSegmentJs.d).route("scale.ticks", "color", "", "color"); |
| 8993 | (0, _helpersSegmentJs.d).route("scale.grid", "color", "", "borderColor"); |
| 8994 | (0, _helpersSegmentJs.d).route("scale.grid", "borderColor", "", "borderColor"); |
| 8995 | (0, _helpersSegmentJs.d).route("scale.title", "color", "", "color"); |
| 8996 | (0, _helpersSegmentJs.d).describe("scale", { |
| 8997 | _fallback: false, |
| 8998 | _scriptable: function(name) { |
| 8999 | return !name.startsWith("before") && !name.startsWith("after") && name !== "callback" && name !== "parser"; |
| 9000 | }, |
| 9001 | _indexable: function(name) { |
| 9002 | return name !== "borderDash" && name !== "tickBorderDash"; |
| 9003 | } |
| 9004 | }); |
| 9005 | (0, _helpersSegmentJs.d).describe("scales", { |
| 9006 | _fallback: "scale" |
| 9007 | }); |
| 9008 | (0, _helpersSegmentJs.d).describe("scale.ticks", { |
| 9009 | _scriptable: function(name) { |
| 9010 | return name !== "backdropPadding" && name !== "callback"; |
| 9011 | }, |
| 9012 | _indexable: function(name) { |
| 9013 | return name !== "backdropPadding"; |
| 9014 | } |
| 9015 | }); |
| 9016 | function autoSkip(scale, ticks) { |
| 9017 | var tickOpts = scale.options.ticks; |
| 9018 | var ticksLimit = tickOpts.maxTicksLimit || determineMaxTicks(scale); |
| 9019 | var majorIndices = tickOpts.major.enabled ? getMajorIndices(ticks) : []; |
| 9020 | var numMajorIndices = majorIndices.length; |
| 9021 | var first = majorIndices[0]; |
| 9022 | var last = majorIndices[numMajorIndices - 1]; |
| 9023 | var newTicks = []; |
| 9024 | if (numMajorIndices > ticksLimit) { |
| 9025 | skipMajors(ticks, newTicks, majorIndices, numMajorIndices / ticksLimit); |
| 9026 | return newTicks; |
| 9027 | } |
| 9028 | var spacing = calculateSpacing(majorIndices, ticks, ticksLimit); |
| 9029 | if (numMajorIndices > 0) { |
| 9030 | var i, ilen; |
| 9031 | var avgMajorSpacing = numMajorIndices > 1 ? Math.round((last - first) / (numMajorIndices - 1)) : null; |
| 9032 | skip(ticks, newTicks, spacing, (0, _helpersSegmentJs.k)(avgMajorSpacing) ? 0 : first - avgMajorSpacing, first); |
| 9033 | for(i = 0, ilen = numMajorIndices - 1; i < ilen; i++)skip(ticks, newTicks, spacing, majorIndices[i], majorIndices[i + 1]); |
| 9034 | skip(ticks, newTicks, spacing, last, (0, _helpersSegmentJs.k)(avgMajorSpacing) ? ticks.length : last + avgMajorSpacing); |
| 9035 | return newTicks; |
| 9036 | } |
| 9037 | skip(ticks, newTicks, spacing); |
| 9038 | return newTicks; |
| 9039 | } |
| 9040 | function determineMaxTicks(scale) { |
| 9041 | var offset = scale.options.offset; |
| 9042 | var tickLength = scale._tickSize(); |
| 9043 | var maxScale = scale._length / tickLength + (offset ? 0 : 1); |
| 9044 | var maxChart = scale._maxLength / tickLength; |
| 9045 | return Math.floor(Math.min(maxScale, maxChart)); |
| 9046 | } |
| 9047 | function calculateSpacing(majorIndices, ticks, ticksLimit) { |
| 9048 | var evenMajorSpacing = getEvenSpacing(majorIndices); |
| 9049 | var spacing = ticks.length / ticksLimit; |
| 9050 | if (!evenMajorSpacing) return Math.max(spacing, 1); |
| 9051 | var factors = (0, _helpersSegmentJs.N)(evenMajorSpacing); |
| 9052 | for(var i = 0, ilen = factors.length - 1; i < ilen; i++){ |
| 9053 | var factor = factors[i]; |
| 9054 | if (factor > spacing) return factor; |
| 9055 | } |
| 9056 | return Math.max(spacing, 1); |
| 9057 | } |
| 9058 | function getMajorIndices(ticks) { |
| 9059 | var result = []; |
| 9060 | var i, ilen; |
| 9061 | for(i = 0, ilen = ticks.length; i < ilen; i++)if (ticks[i].major) result.push(i); |
| 9062 | return result; |
| 9063 | } |
| 9064 | function skipMajors(ticks, newTicks, majorIndices, spacing) { |
| 9065 | var count = 0; |
| 9066 | var next = majorIndices[0]; |
| 9067 | var i; |
| 9068 | spacing = Math.ceil(spacing); |
| 9069 | for(i = 0; i < ticks.length; i++)if (i === next) { |
| 9070 | newTicks.push(ticks[i]); |
| 9071 | count++; |
| 9072 | next = majorIndices[count * spacing]; |
| 9073 | } |
| 9074 | } |
| 9075 | function skip(ticks, newTicks, spacing, majorStart, majorEnd) { |
| 9076 | var start = (0, _helpersSegmentJs.v)(majorStart, 0); |
| 9077 | var end = Math.min((0, _helpersSegmentJs.v)(majorEnd, ticks.length), ticks.length); |
| 9078 | var count = 0; |
| 9079 | var length, i, next; |
| 9080 | spacing = Math.ceil(spacing); |
| 9081 | if (majorEnd) { |
| 9082 | length = majorEnd - majorStart; |
| 9083 | spacing = length / Math.floor(length / spacing); |
| 9084 | } |
| 9085 | next = start; |
| 9086 | while(next < 0){ |
| 9087 | count++; |
| 9088 | next = Math.round(start + count * spacing); |
| 9089 | } |
| 9090 | for(i = Math.max(start, 0); i < end; i++)if (i === next) { |
| 9091 | newTicks.push(ticks[i]); |
| 9092 | count++; |
| 9093 | next = Math.round(start + count * spacing); |
| 9094 | } |
| 9095 | } |
| 9096 | function getEvenSpacing(arr) { |
| 9097 | var len = arr.length; |
| 9098 | var i, diff; |
| 9099 | if (len < 2) return false; |
| 9100 | for(diff = arr[0], i = 1; i < len; ++i){ |
| 9101 | if (arr[i] - arr[i - 1] !== diff) return false; |
| 9102 | } |
| 9103 | return diff; |
| 9104 | } |
| 9105 | var reverseAlign = function(align) { |
| 9106 | return align === "left" ? "right" : align === "right" ? "left" : align; |
| 9107 | }; |
| 9108 | var offsetFromEdge = function(scale, edge, offset) { |
| 9109 | return edge === "top" || edge === "left" ? scale[edge] + offset : scale[edge] - offset; |
| 9110 | }; |
| 9111 | function sample(arr, numItems) { |
| 9112 | var result = []; |
| 9113 | var increment = arr.length / numItems; |
| 9114 | var len = arr.length; |
| 9115 | var i = 0; |
| 9116 | for(; i < len; i += increment)result.push(arr[Math.floor(i)]); |
| 9117 | return result; |
| 9118 | } |
| 9119 | function getPixelForGridLine(scale, index44, offsetGridLines) { |
| 9120 | var length = scale.ticks.length; |
| 9121 | var validIndex1 = Math.min(index44, length - 1); |
| 9122 | var start = scale._startPixel; |
| 9123 | var end = scale._endPixel; |
| 9124 | var epsilon = 1e-6; |
| 9125 | var lineValue = scale.getPixelForTick(validIndex1); |
| 9126 | var offset; |
| 9127 | if (offsetGridLines) { |
| 9128 | if (length === 1) offset = Math.max(lineValue - start, end - lineValue); |
| 9129 | else if (index44 === 0) offset = (scale.getPixelForTick(1) - lineValue) / 2; |
| 9130 | else offset = (lineValue - scale.getPixelForTick(validIndex1 - 1)) / 2; |
| 9131 | lineValue += validIndex1 < index44 ? offset : -offset; |
| 9132 | if (lineValue < start - epsilon || lineValue > end + epsilon) return; |
| 9133 | } |
| 9134 | return lineValue; |
| 9135 | } |
| 9136 | function garbageCollect(caches, length) { |
| 9137 | (0, _helpersSegmentJs.E)(caches, function(cache) { |
| 9138 | var gc = cache.gc; |
| 9139 | var gcLen = gc.length / 2; |
| 9140 | var i; |
| 9141 | if (gcLen > length) { |
| 9142 | for(i = 0; i < gcLen; ++i)delete cache.data[gc[i]]; |
| 9143 | gc.splice(0, gcLen); |
| 9144 | } |
| 9145 | }); |
| 9146 | } |
| 9147 | function getTickMarkLength(options) { |
| 9148 | return options.drawTicks ? options.tickLength : 0; |
| 9149 | } |
| 9150 | function getTitleHeight(options, fallback) { |
| 9151 | if (!options.display) return 0; |
| 9152 | var font = (0, _helpersSegmentJs.$)(options.font, fallback); |
| 9153 | var padding = (0, _helpersSegmentJs.D)(options.padding); |
| 9154 | var lines = (0, _helpersSegmentJs.b)(options.text) ? options.text.length : 1; |
| 9155 | return lines * font.lineHeight + padding.height; |
| 9156 | } |
| 9157 | function createScaleContext(parent, scale) { |
| 9158 | return (0, _helpersSegmentJs.h)(parent, { |
| 9159 | scale: scale, |
| 9160 | type: "scale" |
| 9161 | }); |
| 9162 | } |
| 9163 | function createTickContext(parent, index45, tick) { |
| 9164 | return (0, _helpersSegmentJs.h)(parent, { |
| 9165 | tick: tick, |
| 9166 | index: index45, |
| 9167 | type: "tick" |
| 9168 | }); |
| 9169 | } |
| 9170 | function titleAlign(align, position, reverse) { |
| 9171 | var ret = (0, _helpersSegmentJs.a0)(align); |
| 9172 | if (reverse && position !== "right" || !reverse && position === "right") ret = reverseAlign(ret); |
| 9173 | return ret; |
| 9174 | } |
| 9175 | function titleArgs(scale, offset, position, align) { |
| 9176 | var top = scale.top, left = scale.left, bottom = scale.bottom, right = scale.right, chart = scale.chart; |
| 9177 | var chartArea = chart.chartArea, scales2 = chart.scales; |
| 9178 | var rotation = 0; |
| 9179 | var maxWidth, titleX, titleY; |
| 9180 | var height = bottom - top; |
| 9181 | var width = right - left; |
| 9182 | if (scale.isHorizontal()) { |
| 9183 | titleX = (0, _helpersSegmentJs.a1)(align, left, right); |
| 9184 | if ((0, _helpersSegmentJs.i)(position)) { |
| 9185 | var positionAxisID = Object.keys(position)[0]; |
| 9186 | var value = position[positionAxisID]; |
| 9187 | titleY = scales2[positionAxisID].getPixelForValue(value) + height - offset; |
| 9188 | } else if (position === "center") titleY = (chartArea.bottom + chartArea.top) / 2 + height - offset; |
| 9189 | else titleY = offsetFromEdge(scale, position, offset); |
| 9190 | maxWidth = right - left; |
| 9191 | } else { |
| 9192 | if ((0, _helpersSegmentJs.i)(position)) { |
| 9193 | var positionAxisID1 = Object.keys(position)[0]; |
| 9194 | var value1 = position[positionAxisID1]; |
| 9195 | titleX = scales2[positionAxisID1].getPixelForValue(value1) - width + offset; |
| 9196 | } else if (position === "center") titleX = (chartArea.left + chartArea.right) / 2 - width + offset; |
| 9197 | else titleX = offsetFromEdge(scale, position, offset); |
| 9198 | titleY = (0, _helpersSegmentJs.a1)(align, bottom, top); |
| 9199 | rotation = position === "left" ? -(0, _helpersSegmentJs.H) : (0, _helpersSegmentJs.H); |
| 9200 | } |
| 9201 | return { |
| 9202 | titleX: titleX, |
| 9203 | titleY: titleY, |
| 9204 | maxWidth: maxWidth, |
| 9205 | rotation: rotation |
| 9206 | }; |
| 9207 | } |
| 9208 | var Scale = /*#__PURE__*/ function(Element) { |
| 9209 | "use strict"; |
| 9210 | (0, _inheritsJsDefault.default)(Scale, Element); |
| 9211 | var _super = (0, _createSuperJsDefault.default)(Scale); |
| 9212 | function Scale(cfg) { |
| 9213 | (0, _classCallCheckJsDefault.default)(this, Scale); |
| 9214 | var _this; |
| 9215 | _this = _super.call(this); |
| 9216 | _this.id = cfg.id; |
| 9217 | _this.type = cfg.type; |
| 9218 | _this.options = undefined; |
| 9219 | _this.ctx = cfg.ctx; |
| 9220 | _this.chart = cfg.chart; |
| 9221 | _this.top = undefined; |
| 9222 | _this.bottom = undefined; |
| 9223 | _this.left = undefined; |
| 9224 | _this.right = undefined; |
| 9225 | _this.width = undefined; |
| 9226 | _this.height = undefined; |
| 9227 | _this._margins = { |
| 9228 | left: 0, |
| 9229 | right: 0, |
| 9230 | top: 0, |
| 9231 | bottom: 0 |
| 9232 | }; |
| 9233 | _this.maxWidth = undefined; |
| 9234 | _this.maxHeight = undefined; |
| 9235 | _this.paddingTop = undefined; |
| 9236 | _this.paddingBottom = undefined; |
| 9237 | _this.paddingLeft = undefined; |
| 9238 | _this.paddingRight = undefined; |
| 9239 | _this.axis = undefined; |
| 9240 | _this.labelRotation = undefined; |
| 9241 | _this.min = undefined; |
| 9242 | _this.max = undefined; |
| 9243 | _this._range = undefined; |
| 9244 | _this.ticks = []; |
| 9245 | _this._gridLineItems = null; |
| 9246 | _this._labelItems = null; |
| 9247 | _this._labelSizes = null; |
| 9248 | _this._length = 0; |
| 9249 | _this._maxLength = 0; |
| 9250 | _this._longestTextCache = {}; |
| 9251 | _this._startPixel = undefined; |
| 9252 | _this._endPixel = undefined; |
| 9253 | _this._reversePixels = false; |
| 9254 | _this._userMax = undefined; |
| 9255 | _this._userMin = undefined; |
| 9256 | _this._suggestedMax = undefined; |
| 9257 | _this._suggestedMin = undefined; |
| 9258 | _this._ticksLength = 0; |
| 9259 | _this._borderValue = 0; |
| 9260 | _this._cache = {}; |
| 9261 | _this._dataLimitsCached = false; |
| 9262 | _this.$context = undefined; |
| 9263 | return _this; |
| 9264 | } |
| 9265 | (0, _createClassJsDefault.default)(Scale, [ |
| 9266 | { |
| 9267 | key: "init", |
| 9268 | value: function init(options) { |
| 9269 | this.options = options.setContext(this.getContext()); |
| 9270 | this.axis = options.axis; |
| 9271 | this._userMin = this.parse(options.min); |
| 9272 | this._userMax = this.parse(options.max); |
| 9273 | this._suggestedMin = this.parse(options.suggestedMin); |
| 9274 | this._suggestedMax = this.parse(options.suggestedMax); |
| 9275 | } |
| 9276 | }, |
| 9277 | { |
| 9278 | key: "parse", |
| 9279 | value: function parse1(raw, index) { |
| 9280 | return raw; |
| 9281 | } |
| 9282 | }, |
| 9283 | { |
| 9284 | key: "getUserBounds", |
| 9285 | value: function getUserBounds() { |
| 9286 | var ref = this, _userMin = ref._userMin, _userMax = ref._userMax, _suggestedMin = ref._suggestedMin, _suggestedMax = ref._suggestedMax; |
| 9287 | _userMin = (0, _helpersSegmentJs.O)(_userMin, Number.POSITIVE_INFINITY); |
| 9288 | _userMax = (0, _helpersSegmentJs.O)(_userMax, Number.NEGATIVE_INFINITY); |
| 9289 | _suggestedMin = (0, _helpersSegmentJs.O)(_suggestedMin, Number.POSITIVE_INFINITY); |
| 9290 | _suggestedMax = (0, _helpersSegmentJs.O)(_suggestedMax, Number.NEGATIVE_INFINITY); |
| 9291 | return { |
| 9292 | min: (0, _helpersSegmentJs.O)(_userMin, _suggestedMin), |
| 9293 | max: (0, _helpersSegmentJs.O)(_userMax, _suggestedMax), |
| 9294 | minDefined: (0, _helpersSegmentJs.g)(_userMin), |
| 9295 | maxDefined: (0, _helpersSegmentJs.g)(_userMax) |
| 9296 | }; |
| 9297 | } |
| 9298 | }, |
| 9299 | { |
| 9300 | key: "getMinMax", |
| 9301 | value: function getMinMax(canStack) { |
| 9302 | var ref = this.getUserBounds(), min = ref.min, max = ref.max, minDefined = ref.minDefined, maxDefined = ref.maxDefined; |
| 9303 | var range; |
| 9304 | if (minDefined && maxDefined) return { |
| 9305 | min: min, |
| 9306 | max: max |
| 9307 | }; |
| 9308 | var metas = this.getMatchingVisibleMetas(); |
| 9309 | for(var i = 0, ilen = metas.length; i < ilen; ++i){ |
| 9310 | range = metas[i].controller.getMinMax(this, canStack); |
| 9311 | if (!minDefined) min = Math.min(min, range.min); |
| 9312 | if (!maxDefined) max = Math.max(max, range.max); |
| 9313 | } |
| 9314 | min = maxDefined && min > max ? max : min; |
| 9315 | max = minDefined && min > max ? min : max; |
| 9316 | return { |
| 9317 | min: (0, _helpersSegmentJs.O)(min, (0, _helpersSegmentJs.O)(max, min)), |
| 9318 | max: (0, _helpersSegmentJs.O)(max, (0, _helpersSegmentJs.O)(min, max)) |
| 9319 | }; |
| 9320 | } |
| 9321 | }, |
| 9322 | { |
| 9323 | key: "getPadding", |
| 9324 | value: function getPadding() { |
| 9325 | return { |
| 9326 | left: this.paddingLeft || 0, |
| 9327 | top: this.paddingTop || 0, |
| 9328 | right: this.paddingRight || 0, |
| 9329 | bottom: this.paddingBottom || 0 |
| 9330 | }; |
| 9331 | } |
| 9332 | }, |
| 9333 | { |
| 9334 | key: "getTicks", |
| 9335 | value: function getTicks() { |
| 9336 | return this.ticks; |
| 9337 | } |
| 9338 | }, |
| 9339 | { |
| 9340 | key: "getLabels", |
| 9341 | value: function getLabels() { |
| 9342 | var data = this.chart.data; |
| 9343 | return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels || []; |
| 9344 | } |
| 9345 | }, |
| 9346 | { |
| 9347 | key: "beforeLayout", |
| 9348 | value: function beforeLayout() { |
| 9349 | this._cache = {}; |
| 9350 | this._dataLimitsCached = false; |
| 9351 | } |
| 9352 | }, |
| 9353 | { |
| 9354 | key: "beforeUpdate", |
| 9355 | value: function beforeUpdate() { |
| 9356 | (0, _helpersSegmentJs.Q)(this.options.beforeUpdate, [ |
| 9357 | this |
| 9358 | ]); |
| 9359 | } |
| 9360 | }, |
| 9361 | { |
| 9362 | key: "update", |
| 9363 | value: function update(maxWidth, maxHeight, margins) { |
| 9364 | var _options = this.options, beginAtZero = _options.beginAtZero, grace = _options.grace, tickOpts = _options.ticks; |
| 9365 | var sampleSize = tickOpts.sampleSize; |
| 9366 | this.beforeUpdate(); |
| 9367 | this.maxWidth = maxWidth; |
| 9368 | this.maxHeight = maxHeight; |
| 9369 | this._margins = margins = Object.assign({ |
| 9370 | left: 0, |
| 9371 | right: 0, |
| 9372 | top: 0, |
| 9373 | bottom: 0 |
| 9374 | }, margins); |
| 9375 | this.ticks = null; |
| 9376 | this._labelSizes = null; |
| 9377 | this._gridLineItems = null; |
| 9378 | this._labelItems = null; |
| 9379 | this.beforeSetDimensions(); |
| 9380 | this.setDimensions(); |
| 9381 | this.afterSetDimensions(); |
| 9382 | this._maxLength = this.isHorizontal() ? this.width + margins.left + margins.right : this.height + margins.top + margins.bottom; |
| 9383 | if (!this._dataLimitsCached) { |
| 9384 | this.beforeDataLimits(); |
| 9385 | this.determineDataLimits(); |
| 9386 | this.afterDataLimits(); |
| 9387 | this._range = (0, _helpersSegmentJs.R)(this, grace, beginAtZero); |
| 9388 | this._dataLimitsCached = true; |
| 9389 | } |
| 9390 | this.beforeBuildTicks(); |
| 9391 | this.ticks = this.buildTicks() || []; |
| 9392 | this.afterBuildTicks(); |
| 9393 | var samplingEnabled = sampleSize < this.ticks.length; |
| 9394 | this._convertTicksToLabels(samplingEnabled ? sample(this.ticks, sampleSize) : this.ticks); |
| 9395 | this.configure(); |
| 9396 | this.beforeCalculateLabelRotation(); |
| 9397 | this.calculateLabelRotation(); |
| 9398 | this.afterCalculateLabelRotation(); |
| 9399 | if (tickOpts.display && (tickOpts.autoSkip || tickOpts.source === "auto")) { |
| 9400 | this.ticks = autoSkip(this, this.ticks); |
| 9401 | this._labelSizes = null; |
| 9402 | this.afterAutoSkip(); |
| 9403 | } |
| 9404 | if (samplingEnabled) this._convertTicksToLabels(this.ticks); |
| 9405 | this.beforeFit(); |
| 9406 | this.fit(); |
| 9407 | this.afterFit(); |
| 9408 | this.afterUpdate(); |
| 9409 | } |
| 9410 | }, |
| 9411 | { |
| 9412 | key: "configure", |
| 9413 | value: function configure() { |
| 9414 | var reversePixels = this.options.reverse; |
| 9415 | var startPixel, endPixel; |
| 9416 | if (this.isHorizontal()) { |
| 9417 | startPixel = this.left; |
| 9418 | endPixel = this.right; |
| 9419 | } else { |
| 9420 | startPixel = this.top; |
| 9421 | endPixel = this.bottom; |
| 9422 | reversePixels = !reversePixels; |
| 9423 | } |
| 9424 | this._startPixel = startPixel; |
| 9425 | this._endPixel = endPixel; |
| 9426 | this._reversePixels = reversePixels; |
| 9427 | this._length = endPixel - startPixel; |
| 9428 | this._alignToPixels = this.options.alignToPixels; |
| 9429 | } |
| 9430 | }, |
| 9431 | { |
| 9432 | key: "afterUpdate", |
| 9433 | value: function afterUpdate() { |
| 9434 | (0, _helpersSegmentJs.Q)(this.options.afterUpdate, [ |
| 9435 | this |
| 9436 | ]); |
| 9437 | } |
| 9438 | }, |
| 9439 | { |
| 9440 | key: "beforeSetDimensions", |
| 9441 | value: function beforeSetDimensions() { |
| 9442 | (0, _helpersSegmentJs.Q)(this.options.beforeSetDimensions, [ |
| 9443 | this |
| 9444 | ]); |
| 9445 | } |
| 9446 | }, |
| 9447 | { |
| 9448 | key: "setDimensions", |
| 9449 | value: function setDimensions() { |
| 9450 | if (this.isHorizontal()) { |
| 9451 | this.width = this.maxWidth; |
| 9452 | this.left = 0; |
| 9453 | this.right = this.width; |
| 9454 | } else { |
| 9455 | this.height = this.maxHeight; |
| 9456 | this.top = 0; |
| 9457 | this.bottom = this.height; |
| 9458 | } |
| 9459 | this.paddingLeft = 0; |
| 9460 | this.paddingTop = 0; |
| 9461 | this.paddingRight = 0; |
| 9462 | this.paddingBottom = 0; |
| 9463 | } |
| 9464 | }, |
| 9465 | { |
| 9466 | key: "afterSetDimensions", |
| 9467 | value: function afterSetDimensions() { |
| 9468 | (0, _helpersSegmentJs.Q)(this.options.afterSetDimensions, [ |
| 9469 | this |
| 9470 | ]); |
| 9471 | } |
| 9472 | }, |
| 9473 | { |
| 9474 | key: "_callHooks", |
| 9475 | value: function _callHooks(name) { |
| 9476 | this.chart.notifyPlugins(name, this.getContext()); |
| 9477 | (0, _helpersSegmentJs.Q)(this.options[name], [ |
| 9478 | this |
| 9479 | ]); |
| 9480 | } |
| 9481 | }, |
| 9482 | { |
| 9483 | key: "beforeDataLimits", |
| 9484 | value: function beforeDataLimits() { |
| 9485 | this._callHooks("beforeDataLimits"); |
| 9486 | } |
| 9487 | }, |
| 9488 | { |
| 9489 | key: "determineDataLimits", |
| 9490 | value: function determineDataLimits() {} |
| 9491 | }, |
| 9492 | { |
| 9493 | key: "afterDataLimits", |
| 9494 | value: function afterDataLimits() { |
| 9495 | this._callHooks("afterDataLimits"); |
| 9496 | } |
| 9497 | }, |
| 9498 | { |
| 9499 | key: "beforeBuildTicks", |
| 9500 | value: function beforeBuildTicks() { |
| 9501 | this._callHooks("beforeBuildTicks"); |
| 9502 | } |
| 9503 | }, |
| 9504 | { |
| 9505 | key: "buildTicks", |
| 9506 | value: function buildTicks() { |
| 9507 | return []; |
| 9508 | } |
| 9509 | }, |
| 9510 | { |
| 9511 | key: "afterBuildTicks", |
| 9512 | value: function afterBuildTicks() { |
| 9513 | this._callHooks("afterBuildTicks"); |
| 9514 | } |
| 9515 | }, |
| 9516 | { |
| 9517 | key: "beforeTickToLabelConversion", |
| 9518 | value: function beforeTickToLabelConversion() { |
| 9519 | (0, _helpersSegmentJs.Q)(this.options.beforeTickToLabelConversion, [ |
| 9520 | this |
| 9521 | ]); |
| 9522 | } |
| 9523 | }, |
| 9524 | { |
| 9525 | key: "generateTickLabels", |
| 9526 | value: function generateTickLabels(ticks) { |
| 9527 | var tickOpts = this.options.ticks; |
| 9528 | var i, ilen, tick; |
| 9529 | for(i = 0, ilen = ticks.length; i < ilen; i++){ |
| 9530 | tick = ticks[i]; |
| 9531 | tick.label = (0, _helpersSegmentJs.Q)(tickOpts.callback, [ |
| 9532 | tick.value, |
| 9533 | i, |
| 9534 | ticks |
| 9535 | ], this); |
| 9536 | } |
| 9537 | } |
| 9538 | }, |
| 9539 | { |
| 9540 | key: "afterTickToLabelConversion", |
| 9541 | value: function afterTickToLabelConversion() { |
| 9542 | (0, _helpersSegmentJs.Q)(this.options.afterTickToLabelConversion, [ |
| 9543 | this |
| 9544 | ]); |
| 9545 | } |
| 9546 | }, |
| 9547 | { |
| 9548 | key: "beforeCalculateLabelRotation", |
| 9549 | value: function beforeCalculateLabelRotation() { |
| 9550 | (0, _helpersSegmentJs.Q)(this.options.beforeCalculateLabelRotation, [ |
| 9551 | this |
| 9552 | ]); |
| 9553 | } |
| 9554 | }, |
| 9555 | { |
| 9556 | key: "calculateLabelRotation", |
| 9557 | value: function calculateLabelRotation() { |
| 9558 | var options = this.options; |
| 9559 | var tickOpts = options.ticks; |
| 9560 | var numTicks = this.ticks.length; |
| 9561 | var minRotation = tickOpts.minRotation || 0; |
| 9562 | var maxRotation = tickOpts.maxRotation; |
| 9563 | var labelRotation = minRotation; |
| 9564 | var tickWidth, maxHeight, maxLabelDiagonal; |
| 9565 | if (!this._isVisible() || !tickOpts.display || minRotation >= maxRotation || numTicks <= 1 || !this.isHorizontal()) { |
| 9566 | this.labelRotation = minRotation; |
| 9567 | return; |
| 9568 | } |
| 9569 | var labelSizes = this._getLabelSizes(); |
| 9570 | var maxLabelWidth = labelSizes.widest.width; |
| 9571 | var maxLabelHeight = labelSizes.highest.height; |
| 9572 | var maxWidth = (0, _helpersSegmentJs.w)(this.chart.width - maxLabelWidth, 0, this.maxWidth); |
| 9573 | tickWidth = options.offset ? this.maxWidth / numTicks : maxWidth / (numTicks - 1); |
| 9574 | if (maxLabelWidth + 6 > tickWidth) { |
| 9575 | tickWidth = maxWidth / (numTicks - (options.offset ? 0.5 : 1)); |
| 9576 | maxHeight = this.maxHeight - getTickMarkLength(options.grid) - tickOpts.padding - getTitleHeight(options.title, this.chart.options.font); |
| 9577 | maxLabelDiagonal = Math.sqrt(maxLabelWidth * maxLabelWidth + maxLabelHeight * maxLabelHeight); |
| 9578 | labelRotation = (0, _helpersSegmentJs.S)(Math.min(Math.asin((0, _helpersSegmentJs.w)((labelSizes.highest.height + 6) / tickWidth, -1, 1)), Math.asin((0, _helpersSegmentJs.w)(maxHeight / maxLabelDiagonal, -1, 1)) - Math.asin((0, _helpersSegmentJs.w)(maxLabelHeight / maxLabelDiagonal, -1, 1)))); |
| 9579 | labelRotation = Math.max(minRotation, Math.min(maxRotation, labelRotation)); |
| 9580 | } |
| 9581 | this.labelRotation = labelRotation; |
| 9582 | } |
| 9583 | }, |
| 9584 | { |
| 9585 | key: "afterCalculateLabelRotation", |
| 9586 | value: function afterCalculateLabelRotation() { |
| 9587 | (0, _helpersSegmentJs.Q)(this.options.afterCalculateLabelRotation, [ |
| 9588 | this |
| 9589 | ]); |
| 9590 | } |
| 9591 | }, |
| 9592 | { |
| 9593 | key: "afterAutoSkip", |
| 9594 | value: function afterAutoSkip() {} |
| 9595 | }, |
| 9596 | { |
| 9597 | key: "beforeFit", |
| 9598 | value: function beforeFit() { |
| 9599 | (0, _helpersSegmentJs.Q)(this.options.beforeFit, [ |
| 9600 | this |
| 9601 | ]); |
| 9602 | } |
| 9603 | }, |
| 9604 | { |
| 9605 | key: "fit", |
| 9606 | value: function fit() { |
| 9607 | var minSize = { |
| 9608 | width: 0, |
| 9609 | height: 0 |
| 9610 | }; |
| 9611 | var ref = this, chart = ref.chart, _options = ref.options, tickOpts = _options.ticks, titleOpts = _options.title, gridOpts = _options.grid; |
| 9612 | var display = this._isVisible(); |
| 9613 | var isHorizontal = this.isHorizontal(); |
| 9614 | if (display) { |
| 9615 | var titleHeight = getTitleHeight(titleOpts, chart.options.font); |
| 9616 | if (isHorizontal) { |
| 9617 | minSize.width = this.maxWidth; |
| 9618 | minSize.height = getTickMarkLength(gridOpts) + titleHeight; |
| 9619 | } else { |
| 9620 | minSize.height = this.maxHeight; |
| 9621 | minSize.width = getTickMarkLength(gridOpts) + titleHeight; |
| 9622 | } |
| 9623 | if (tickOpts.display && this.ticks.length) { |
| 9624 | var ref4 = this._getLabelSizes(), first = ref4.first, last = ref4.last, widest = ref4.widest, highest = ref4.highest; |
| 9625 | var tickPadding = tickOpts.padding * 2; |
| 9626 | var angleRadians = (0, _helpersSegmentJs.t)(this.labelRotation); |
| 9627 | var cos = Math.cos(angleRadians); |
| 9628 | var sin = Math.sin(angleRadians); |
| 9629 | if (isHorizontal) { |
| 9630 | var labelHeight = tickOpts.mirror ? 0 : sin * widest.width + cos * highest.height; |
| 9631 | minSize.height = Math.min(this.maxHeight, minSize.height + labelHeight + tickPadding); |
| 9632 | } else { |
| 9633 | var labelWidth = tickOpts.mirror ? 0 : cos * widest.width + sin * highest.height; |
| 9634 | minSize.width = Math.min(this.maxWidth, minSize.width + labelWidth + tickPadding); |
| 9635 | } |
| 9636 | this._calculatePadding(first, last, sin, cos); |
| 9637 | } |
| 9638 | } |
| 9639 | this._handleMargins(); |
| 9640 | if (isHorizontal) { |
| 9641 | this.width = this._length = chart.width - this._margins.left - this._margins.right; |
| 9642 | this.height = minSize.height; |
| 9643 | } else { |
| 9644 | this.width = minSize.width; |
| 9645 | this.height = this._length = chart.height - this._margins.top - this._margins.bottom; |
| 9646 | } |
| 9647 | } |
| 9648 | }, |
| 9649 | { |
| 9650 | key: "_calculatePadding", |
| 9651 | value: function _calculatePadding(first, last, sin, cos) { |
| 9652 | var _options = this.options, _ticks = _options.ticks, align = _ticks.align, padding = _ticks.padding, position = _options.position; |
| 9653 | var isRotated = this.labelRotation !== 0; |
| 9654 | var labelsBelowTicks = position !== "top" && this.axis === "x"; |
| 9655 | if (this.isHorizontal()) { |
| 9656 | var offsetLeft = this.getPixelForTick(0) - this.left; |
| 9657 | var offsetRight = this.right - this.getPixelForTick(this.ticks.length - 1); |
| 9658 | var paddingLeft = 0; |
| 9659 | var paddingRight = 0; |
| 9660 | if (isRotated) { |
| 9661 | if (labelsBelowTicks) { |
| 9662 | paddingLeft = cos * first.width; |
| 9663 | paddingRight = sin * last.height; |
| 9664 | } else { |
| 9665 | paddingLeft = sin * first.height; |
| 9666 | paddingRight = cos * last.width; |
| 9667 | } |
| 9668 | } else if (align === "start") paddingRight = last.width; |
| 9669 | else if (align === "end") paddingLeft = first.width; |
| 9670 | else if (align !== "inner") { |
| 9671 | paddingLeft = first.width / 2; |
| 9672 | paddingRight = last.width / 2; |
| 9673 | } |
| 9674 | this.paddingLeft = Math.max((paddingLeft - offsetLeft + padding) * this.width / (this.width - offsetLeft), 0); |
| 9675 | this.paddingRight = Math.max((paddingRight - offsetRight + padding) * this.width / (this.width - offsetRight), 0); |
| 9676 | } else { |
| 9677 | var paddingTop = last.height / 2; |
| 9678 | var paddingBottom = first.height / 2; |
| 9679 | if (align === "start") { |
| 9680 | paddingTop = 0; |
| 9681 | paddingBottom = first.height; |
| 9682 | } else if (align === "end") { |
| 9683 | paddingTop = last.height; |
| 9684 | paddingBottom = 0; |
| 9685 | } |
| 9686 | this.paddingTop = paddingTop + padding; |
| 9687 | this.paddingBottom = paddingBottom + padding; |
| 9688 | } |
| 9689 | } |
| 9690 | }, |
| 9691 | { |
| 9692 | key: "_handleMargins", |
| 9693 | value: function _handleMargins() { |
| 9694 | if (this._margins) { |
| 9695 | this._margins.left = Math.max(this.paddingLeft, this._margins.left); |
| 9696 | this._margins.top = Math.max(this.paddingTop, this._margins.top); |
| 9697 | this._margins.right = Math.max(this.paddingRight, this._margins.right); |
| 9698 | this._margins.bottom = Math.max(this.paddingBottom, this._margins.bottom); |
| 9699 | } |
| 9700 | } |
| 9701 | }, |
| 9702 | { |
| 9703 | key: "afterFit", |
| 9704 | value: function afterFit() { |
| 9705 | (0, _helpersSegmentJs.Q)(this.options.afterFit, [ |
| 9706 | this |
| 9707 | ]); |
| 9708 | } |
| 9709 | }, |
| 9710 | { |
| 9711 | key: "isHorizontal", |
| 9712 | value: function isHorizontal() { |
| 9713 | var _options = this.options, axis = _options.axis, position = _options.position; |
| 9714 | return position === "top" || position === "bottom" || axis === "x"; |
| 9715 | } |
| 9716 | }, |
| 9717 | { |
| 9718 | key: "isFullSize", |
| 9719 | value: function isFullSize() { |
| 9720 | return this.options.fullSize; |
| 9721 | } |
| 9722 | }, |
| 9723 | { |
| 9724 | key: "_convertTicksToLabels", |
| 9725 | value: function _convertTicksToLabels(ticks) { |
| 9726 | this.beforeTickToLabelConversion(); |
| 9727 | this.generateTickLabels(ticks); |
| 9728 | var i, ilen; |
| 9729 | for(i = 0, ilen = ticks.length; i < ilen; i++)if ((0, _helpersSegmentJs.k)(ticks[i].label)) { |
| 9730 | ticks.splice(i, 1); |
| 9731 | ilen--; |
| 9732 | i--; |
| 9733 | } |
| 9734 | this.afterTickToLabelConversion(); |
| 9735 | } |
| 9736 | }, |
| 9737 | { |
| 9738 | key: "_getLabelSizes", |
| 9739 | value: function _getLabelSizes() { |
| 9740 | var labelSizes = this._labelSizes; |
| 9741 | if (!labelSizes) { |
| 9742 | var sampleSize = this.options.ticks.sampleSize; |
| 9743 | var ticks = this.ticks; |
| 9744 | if (sampleSize < ticks.length) ticks = sample(ticks, sampleSize); |
| 9745 | this._labelSizes = labelSizes = this._computeLabelSizes(ticks, ticks.length); |
| 9746 | } |
| 9747 | return labelSizes; |
| 9748 | } |
| 9749 | }, |
| 9750 | { |
| 9751 | key: "_computeLabelSizes", |
| 9752 | value: function _computeLabelSizes(ticks, length) { |
| 9753 | var ref = this, ctx = ref.ctx, caches = ref._longestTextCache; |
| 9754 | var widths = []; |
| 9755 | var heights = []; |
| 9756 | var widestLabelSize = 0; |
| 9757 | var highestLabelSize = 0; |
| 9758 | var i, j, jlen, label, tickFont, fontString, cache, lineHeight, width, height, nestedLabel; |
| 9759 | for(i = 0; i < length; ++i){ |
| 9760 | label = ticks[i].label; |
| 9761 | tickFont = this._resolveTickFontOptions(i); |
| 9762 | ctx.font = fontString = tickFont.string; |
| 9763 | cache = caches[fontString] = caches[fontString] || { |
| 9764 | data: {}, |
| 9765 | gc: [] |
| 9766 | }; |
| 9767 | lineHeight = tickFont.lineHeight; |
| 9768 | width = height = 0; |
| 9769 | if (!(0, _helpersSegmentJs.k)(label) && !(0, _helpersSegmentJs.b)(label)) { |
| 9770 | width = (0, _helpersSegmentJs.U)(ctx, cache.data, cache.gc, width, label); |
| 9771 | height = lineHeight; |
| 9772 | } else if ((0, _helpersSegmentJs.b)(label)) for(j = 0, jlen = label.length; j < jlen; ++j){ |
| 9773 | nestedLabel = label[j]; |
| 9774 | if (!(0, _helpersSegmentJs.k)(nestedLabel) && !(0, _helpersSegmentJs.b)(nestedLabel)) { |
| 9775 | width = (0, _helpersSegmentJs.U)(ctx, cache.data, cache.gc, width, nestedLabel); |
| 9776 | height += lineHeight; |
| 9777 | } |
| 9778 | } |
| 9779 | widths.push(width); |
| 9780 | heights.push(height); |
| 9781 | widestLabelSize = Math.max(width, widestLabelSize); |
| 9782 | highestLabelSize = Math.max(height, highestLabelSize); |
| 9783 | } |
| 9784 | garbageCollect(caches, length); |
| 9785 | var widest = widths.indexOf(widestLabelSize); |
| 9786 | var highest = heights.indexOf(highestLabelSize); |
| 9787 | var valueAt = function(idx) { |
| 9788 | return { |
| 9789 | width: widths[idx] || 0, |
| 9790 | height: heights[idx] || 0 |
| 9791 | }; |
| 9792 | }; |
| 9793 | return { |
| 9794 | first: valueAt(0), |
| 9795 | last: valueAt(length - 1), |
| 9796 | widest: valueAt(widest), |
| 9797 | highest: valueAt(highest), |
| 9798 | widths: widths, |
| 9799 | heights: heights |
| 9800 | }; |
| 9801 | } |
| 9802 | }, |
| 9803 | { |
| 9804 | key: "getLabelForValue", |
| 9805 | value: function getLabelForValue(value) { |
| 9806 | return value; |
| 9807 | } |
| 9808 | }, |
| 9809 | { |
| 9810 | key: "getPixelForValue", |
| 9811 | value: function getPixelForValue(value, index) { |
| 9812 | return NaN; |
| 9813 | } |
| 9814 | }, |
| 9815 | { |
| 9816 | key: "getValueForPixel", |
| 9817 | value: function getValueForPixel(pixel) {} |
| 9818 | }, |
| 9819 | { |
| 9820 | key: "getPixelForTick", |
| 9821 | value: function getPixelForTick(index46) { |
| 9822 | var ticks = this.ticks; |
| 9823 | if (index46 < 0 || index46 > ticks.length - 1) return null; |
| 9824 | return this.getPixelForValue(ticks[index46].value); |
| 9825 | } |
| 9826 | }, |
| 9827 | { |
| 9828 | key: "getPixelForDecimal", |
| 9829 | value: function getPixelForDecimal(decimal) { |
| 9830 | if (this._reversePixels) decimal = 1 - decimal; |
| 9831 | var pixel = this._startPixel + decimal * this._length; |
| 9832 | return (0, _helpersSegmentJs.V)(this._alignToPixels ? (0, _helpersSegmentJs.W)(this.chart, pixel, 0) : pixel); |
| 9833 | } |
| 9834 | }, |
| 9835 | { |
| 9836 | key: "getDecimalForPixel", |
| 9837 | value: function getDecimalForPixel(pixel) { |
| 9838 | var decimal = (pixel - this._startPixel) / this._length; |
| 9839 | return this._reversePixels ? 1 - decimal : decimal; |
| 9840 | } |
| 9841 | }, |
| 9842 | { |
| 9843 | key: "getBasePixel", |
| 9844 | value: function getBasePixel() { |
| 9845 | return this.getPixelForValue(this.getBaseValue()); |
| 9846 | } |
| 9847 | }, |
| 9848 | { |
| 9849 | key: "getBaseValue", |
| 9850 | value: function getBaseValue() { |
| 9851 | var ref = this, min = ref.min, max = ref.max; |
| 9852 | return min < 0 && max < 0 ? max : min > 0 && max > 0 ? min : 0; |
| 9853 | } |
| 9854 | }, |
| 9855 | { |
| 9856 | key: "getContext", |
| 9857 | value: function getContext(index47) { |
| 9858 | var ticks = this.ticks || []; |
| 9859 | if (index47 >= 0 && index47 < ticks.length) { |
| 9860 | var tick = ticks[index47]; |
| 9861 | return tick.$context || (tick.$context = createTickContext(this.getContext(), index47, tick)); |
| 9862 | } |
| 9863 | return this.$context || (this.$context = createScaleContext(this.chart.getContext(), this)); |
| 9864 | } |
| 9865 | }, |
| 9866 | { |
| 9867 | key: "_tickSize", |
| 9868 | value: function _tickSize() { |
| 9869 | var optionTicks = this.options.ticks; |
| 9870 | var rot = (0, _helpersSegmentJs.t)(this.labelRotation); |
| 9871 | var cos = Math.abs(Math.cos(rot)); |
| 9872 | var sin = Math.abs(Math.sin(rot)); |
| 9873 | var labelSizes = this._getLabelSizes(); |
| 9874 | var padding = optionTicks.autoSkipPadding || 0; |
| 9875 | var w = labelSizes ? labelSizes.widest.width + padding : 0; |
| 9876 | var h = labelSizes ? labelSizes.highest.height + padding : 0; |
| 9877 | return this.isHorizontal() ? h * cos > w * sin ? w / cos : h / sin : h * sin < w * cos ? h / cos : w / sin; |
| 9878 | } |
| 9879 | }, |
| 9880 | { |
| 9881 | key: "_isVisible", |
| 9882 | value: function _isVisible() { |
| 9883 | var display = this.options.display; |
| 9884 | if (display !== "auto") return !!display; |
| 9885 | return this.getMatchingVisibleMetas().length > 0; |
| 9886 | } |
| 9887 | }, |
| 9888 | { |
| 9889 | key: "_computeGridLineItems", |
| 9890 | value: function _computeGridLineItems(chartArea) { |
| 9891 | var axis = this.axis; |
| 9892 | var chart = this.chart; |
| 9893 | var options = this.options; |
| 9894 | var grid = options.grid, position = options.position; |
| 9895 | var offset = grid.offset; |
| 9896 | var isHorizontal = this.isHorizontal(); |
| 9897 | var ticks = this.ticks; |
| 9898 | var ticksLength = ticks.length + (offset ? 1 : 0); |
| 9899 | var tl = getTickMarkLength(grid); |
| 9900 | var items = []; |
| 9901 | var borderOpts = grid.setContext(this.getContext()); |
| 9902 | var axisWidth = borderOpts.drawBorder ? borderOpts.borderWidth : 0; |
| 9903 | var axisHalfWidth = axisWidth / 2; |
| 9904 | var alignBorderValue = function alignBorderValue(pixel) { |
| 9905 | return (0, _helpersSegmentJs.W)(chart, pixel, axisWidth); |
| 9906 | }; |
| 9907 | var borderValue, i, lineValue, alignedLineValue; |
| 9908 | var tx1, ty1, tx2, ty2, x1, y1, x2, y2; |
| 9909 | if (position === "top") { |
| 9910 | borderValue = alignBorderValue(this.bottom); |
| 9911 | ty1 = this.bottom - tl; |
| 9912 | ty2 = borderValue - axisHalfWidth; |
| 9913 | y1 = alignBorderValue(chartArea.top) + axisHalfWidth; |
| 9914 | y2 = chartArea.bottom; |
| 9915 | } else if (position === "bottom") { |
| 9916 | borderValue = alignBorderValue(this.top); |
| 9917 | y1 = chartArea.top; |
| 9918 | y2 = alignBorderValue(chartArea.bottom) - axisHalfWidth; |
| 9919 | ty1 = borderValue + axisHalfWidth; |
| 9920 | ty2 = this.top + tl; |
| 9921 | } else if (position === "left") { |
| 9922 | borderValue = alignBorderValue(this.right); |
| 9923 | tx1 = this.right - tl; |
| 9924 | tx2 = borderValue - axisHalfWidth; |
| 9925 | x1 = alignBorderValue(chartArea.left) + axisHalfWidth; |
| 9926 | x2 = chartArea.right; |
| 9927 | } else if (position === "right") { |
| 9928 | borderValue = alignBorderValue(this.left); |
| 9929 | x1 = chartArea.left; |
| 9930 | x2 = alignBorderValue(chartArea.right) - axisHalfWidth; |
| 9931 | tx1 = borderValue + axisHalfWidth; |
| 9932 | tx2 = this.left + tl; |
| 9933 | } else if (axis === "x") { |
| 9934 | if (position === "center") borderValue = alignBorderValue((chartArea.top + chartArea.bottom) / 2 + 0.5); |
| 9935 | else if ((0, _helpersSegmentJs.i)(position)) { |
| 9936 | var positionAxisID = Object.keys(position)[0]; |
| 9937 | var value = position[positionAxisID]; |
| 9938 | borderValue = alignBorderValue(this.chart.scales[positionAxisID].getPixelForValue(value)); |
| 9939 | } |
| 9940 | y1 = chartArea.top; |
| 9941 | y2 = chartArea.bottom; |
| 9942 | ty1 = borderValue + axisHalfWidth; |
| 9943 | ty2 = ty1 + tl; |
| 9944 | } else if (axis === "y") { |
| 9945 | if (position === "center") borderValue = alignBorderValue((chartArea.left + chartArea.right) / 2); |
| 9946 | else if ((0, _helpersSegmentJs.i)(position)) { |
| 9947 | var positionAxisID2 = Object.keys(position)[0]; |
| 9948 | var value2 = position[positionAxisID2]; |
| 9949 | borderValue = alignBorderValue(this.chart.scales[positionAxisID2].getPixelForValue(value2)); |
| 9950 | } |
| 9951 | tx1 = borderValue - axisHalfWidth; |
| 9952 | tx2 = tx1 - tl; |
| 9953 | x1 = chartArea.left; |
| 9954 | x2 = chartArea.right; |
| 9955 | } |
| 9956 | var limit = (0, _helpersSegmentJs.v)(options.ticks.maxTicksLimit, ticksLength); |
| 9957 | var step = Math.max(1, Math.ceil(ticksLength / limit)); |
| 9958 | for(i = 0; i < ticksLength; i += step){ |
| 9959 | var optsAtIndex = grid.setContext(this.getContext(i)); |
| 9960 | var lineWidth = optsAtIndex.lineWidth; |
| 9961 | var lineColor = optsAtIndex.color; |
| 9962 | var borderDash = grid.borderDash || []; |
| 9963 | var borderDashOffset = optsAtIndex.borderDashOffset; |
| 9964 | var tickWidth = optsAtIndex.tickWidth; |
| 9965 | var tickColor = optsAtIndex.tickColor; |
| 9966 | var tickBorderDash = optsAtIndex.tickBorderDash || []; |
| 9967 | var tickBorderDashOffset = optsAtIndex.tickBorderDashOffset; |
| 9968 | lineValue = getPixelForGridLine(this, i, offset); |
| 9969 | if (lineValue === undefined) continue; |
| 9970 | alignedLineValue = (0, _helpersSegmentJs.W)(chart, lineValue, lineWidth); |
| 9971 | if (isHorizontal) tx1 = tx2 = x1 = x2 = alignedLineValue; |
| 9972 | else ty1 = ty2 = y1 = y2 = alignedLineValue; |
| 9973 | items.push({ |
| 9974 | tx1: tx1, |
| 9975 | ty1: ty1, |
| 9976 | tx2: tx2, |
| 9977 | ty2: ty2, |
| 9978 | x1: x1, |
| 9979 | y1: y1, |
| 9980 | x2: x2, |
| 9981 | y2: y2, |
| 9982 | width: lineWidth, |
| 9983 | color: lineColor, |
| 9984 | borderDash: borderDash, |
| 9985 | borderDashOffset: borderDashOffset, |
| 9986 | tickWidth: tickWidth, |
| 9987 | tickColor: tickColor, |
| 9988 | tickBorderDash: tickBorderDash, |
| 9989 | tickBorderDashOffset: tickBorderDashOffset |
| 9990 | }); |
| 9991 | } |
| 9992 | this._ticksLength = ticksLength; |
| 9993 | this._borderValue = borderValue; |
| 9994 | return items; |
| 9995 | } |
| 9996 | }, |
| 9997 | { |
| 9998 | key: "_computeLabelItems", |
| 9999 | value: function _computeLabelItems(chartArea) { |
| 10000 | var axis = this.axis; |
| 10001 | var options = this.options; |
| 10002 | var position = options.position, optionTicks = options.ticks; |
| 10003 | var isHorizontal = this.isHorizontal(); |
| 10004 | var ticks = this.ticks; |
| 10005 | var align = optionTicks.align, crossAlign = optionTicks.crossAlign, padding = optionTicks.padding, mirror = optionTicks.mirror; |
| 10006 | var tl = getTickMarkLength(options.grid); |
| 10007 | var tickAndPadding = tl + padding; |
| 10008 | var hTickAndPadding = mirror ? -padding : tickAndPadding; |
| 10009 | var rotation = -(0, _helpersSegmentJs.t)(this.labelRotation); |
| 10010 | var items = []; |
| 10011 | var i, ilen, tick, label, x, y, textAlign, pixel, font, lineHeight, lineCount, textOffset; |
| 10012 | var textBaseline = "middle"; |
| 10013 | if (position === "top") { |
| 10014 | y = this.bottom - hTickAndPadding; |
| 10015 | textAlign = this._getXAxisLabelAlignment(); |
| 10016 | } else if (position === "bottom") { |
| 10017 | y = this.top + hTickAndPadding; |
| 10018 | textAlign = this._getXAxisLabelAlignment(); |
| 10019 | } else if (position === "left") { |
| 10020 | var ret = this._getYAxisLabelAlignment(tl); |
| 10021 | textAlign = ret.textAlign; |
| 10022 | x = ret.x; |
| 10023 | } else if (position === "right") { |
| 10024 | var ret1 = this._getYAxisLabelAlignment(tl); |
| 10025 | textAlign = ret1.textAlign; |
| 10026 | x = ret1.x; |
| 10027 | } else if (axis === "x") { |
| 10028 | if (position === "center") y = (chartArea.top + chartArea.bottom) / 2 + tickAndPadding; |
| 10029 | else if ((0, _helpersSegmentJs.i)(position)) { |
| 10030 | var positionAxisID = Object.keys(position)[0]; |
| 10031 | var value = position[positionAxisID]; |
| 10032 | y = this.chart.scales[positionAxisID].getPixelForValue(value) + tickAndPadding; |
| 10033 | } |
| 10034 | textAlign = this._getXAxisLabelAlignment(); |
| 10035 | } else if (axis === "y") { |
| 10036 | if (position === "center") x = (chartArea.left + chartArea.right) / 2 - tickAndPadding; |
| 10037 | else if ((0, _helpersSegmentJs.i)(position)) { |
| 10038 | var positionAxisID3 = Object.keys(position)[0]; |
| 10039 | var value3 = position[positionAxisID3]; |
| 10040 | x = this.chart.scales[positionAxisID3].getPixelForValue(value3); |
| 10041 | } |
| 10042 | textAlign = this._getYAxisLabelAlignment(tl).textAlign; |
| 10043 | } |
| 10044 | if (axis === "y") { |
| 10045 | if (align === "start") textBaseline = "top"; |
| 10046 | else if (align === "end") textBaseline = "bottom"; |
| 10047 | } |
| 10048 | var labelSizes = this._getLabelSizes(); |
| 10049 | for(i = 0, ilen = ticks.length; i < ilen; ++i){ |
| 10050 | tick = ticks[i]; |
| 10051 | label = tick.label; |
| 10052 | var optsAtIndex = optionTicks.setContext(this.getContext(i)); |
| 10053 | pixel = this.getPixelForTick(i) + optionTicks.labelOffset; |
| 10054 | font = this._resolveTickFontOptions(i); |
| 10055 | lineHeight = font.lineHeight; |
| 10056 | lineCount = (0, _helpersSegmentJs.b)(label) ? label.length : 1; |
| 10057 | var halfCount = lineCount / 2; |
| 10058 | var color = optsAtIndex.color; |
| 10059 | var strokeColor = optsAtIndex.textStrokeColor; |
| 10060 | var strokeWidth = optsAtIndex.textStrokeWidth; |
| 10061 | var tickTextAlign = textAlign; |
| 10062 | if (isHorizontal) { |
| 10063 | x = pixel; |
| 10064 | if (textAlign === "inner") { |
| 10065 | if (i === ilen - 1) tickTextAlign = !this.options.reverse ? "right" : "left"; |
| 10066 | else if (i === 0) tickTextAlign = !this.options.reverse ? "left" : "right"; |
| 10067 | else tickTextAlign = "center"; |
| 10068 | } |
| 10069 | if (position === "top") { |
| 10070 | if (crossAlign === "near" || rotation !== 0) textOffset = -lineCount * lineHeight + lineHeight / 2; |
| 10071 | else if (crossAlign === "center") textOffset = -labelSizes.highest.height / 2 - halfCount * lineHeight + lineHeight; |
| 10072 | else textOffset = -labelSizes.highest.height + lineHeight / 2; |
| 10073 | } else { |
| 10074 | if (crossAlign === "near" || rotation !== 0) textOffset = lineHeight / 2; |
| 10075 | else if (crossAlign === "center") textOffset = labelSizes.highest.height / 2 - halfCount * lineHeight; |
| 10076 | else textOffset = labelSizes.highest.height - lineCount * lineHeight; |
| 10077 | } |
| 10078 | if (mirror) textOffset *= -1; |
| 10079 | } else { |
| 10080 | y = pixel; |
| 10081 | textOffset = (1 - lineCount) * lineHeight / 2; |
| 10082 | } |
| 10083 | var backdrop = void 0; |
| 10084 | if (optsAtIndex.showLabelBackdrop) { |
| 10085 | var labelPadding = (0, _helpersSegmentJs.D)(optsAtIndex.backdropPadding); |
| 10086 | var height = labelSizes.heights[i]; |
| 10087 | var width = labelSizes.widths[i]; |
| 10088 | var top = y + textOffset - labelPadding.top; |
| 10089 | var left = x - labelPadding.left; |
| 10090 | switch(textBaseline){ |
| 10091 | case "middle": |
| 10092 | top -= height / 2; |
| 10093 | break; |
| 10094 | case "bottom": |
| 10095 | top -= height; |
| 10096 | break; |
| 10097 | } |
| 10098 | switch(textAlign){ |
| 10099 | case "center": |
| 10100 | left -= width / 2; |
| 10101 | break; |
| 10102 | case "right": |
| 10103 | left -= width; |
| 10104 | break; |
| 10105 | } |
| 10106 | backdrop = { |
| 10107 | left: left, |
| 10108 | top: top, |
| 10109 | width: width + labelPadding.width, |
| 10110 | height: height + labelPadding.height, |
| 10111 | color: optsAtIndex.backdropColor |
| 10112 | }; |
| 10113 | } |
| 10114 | items.push({ |
| 10115 | rotation: rotation, |
| 10116 | label: label, |
| 10117 | font: font, |
| 10118 | color: color, |
| 10119 | strokeColor: strokeColor, |
| 10120 | strokeWidth: strokeWidth, |
| 10121 | textOffset: textOffset, |
| 10122 | textAlign: tickTextAlign, |
| 10123 | textBaseline: textBaseline, |
| 10124 | translation: [ |
| 10125 | x, |
| 10126 | y |
| 10127 | ], |
| 10128 | backdrop: backdrop |
| 10129 | }); |
| 10130 | } |
| 10131 | return items; |
| 10132 | } |
| 10133 | }, |
| 10134 | { |
| 10135 | key: "_getXAxisLabelAlignment", |
| 10136 | value: function _getXAxisLabelAlignment() { |
| 10137 | var _options = this.options, position = _options.position, ticks = _options.ticks; |
| 10138 | var rotation = -(0, _helpersSegmentJs.t)(this.labelRotation); |
| 10139 | if (rotation) return position === "top" ? "left" : "right"; |
| 10140 | var align = "center"; |
| 10141 | if (ticks.align === "start") align = "left"; |
| 10142 | else if (ticks.align === "end") align = "right"; |
| 10143 | else if (ticks.align === "inner") align = "inner"; |
| 10144 | return align; |
| 10145 | } |
| 10146 | }, |
| 10147 | { |
| 10148 | key: "_getYAxisLabelAlignment", |
| 10149 | value: function _getYAxisLabelAlignment(tl) { |
| 10150 | var _options = this.options, position = _options.position, _ticks = _options.ticks, crossAlign = _ticks.crossAlign, mirror = _ticks.mirror, padding = _ticks.padding; |
| 10151 | var labelSizes = this._getLabelSizes(); |
| 10152 | var tickAndPadding = tl + padding; |
| 10153 | var widest = labelSizes.widest.width; |
| 10154 | var textAlign; |
| 10155 | var x; |
| 10156 | if (position === "left") { |
| 10157 | if (mirror) { |
| 10158 | x = this.right + padding; |
| 10159 | if (crossAlign === "near") textAlign = "left"; |
| 10160 | else if (crossAlign === "center") { |
| 10161 | textAlign = "center"; |
| 10162 | x += widest / 2; |
| 10163 | } else { |
| 10164 | textAlign = "right"; |
| 10165 | x += widest; |
| 10166 | } |
| 10167 | } else { |
| 10168 | x = this.right - tickAndPadding; |
| 10169 | if (crossAlign === "near") textAlign = "right"; |
| 10170 | else if (crossAlign === "center") { |
| 10171 | textAlign = "center"; |
| 10172 | x -= widest / 2; |
| 10173 | } else { |
| 10174 | textAlign = "left"; |
| 10175 | x = this.left; |
| 10176 | } |
| 10177 | } |
| 10178 | } else if (position === "right") { |
| 10179 | if (mirror) { |
| 10180 | x = this.left + padding; |
| 10181 | if (crossAlign === "near") textAlign = "right"; |
| 10182 | else if (crossAlign === "center") { |
| 10183 | textAlign = "center"; |
| 10184 | x -= widest / 2; |
| 10185 | } else { |
| 10186 | textAlign = "left"; |
| 10187 | x -= widest; |
| 10188 | } |
| 10189 | } else { |
| 10190 | x = this.left + tickAndPadding; |
| 10191 | if (crossAlign === "near") textAlign = "left"; |
| 10192 | else if (crossAlign === "center") { |
| 10193 | textAlign = "center"; |
| 10194 | x += widest / 2; |
| 10195 | } else { |
| 10196 | textAlign = "right"; |
| 10197 | x = this.right; |
| 10198 | } |
| 10199 | } |
| 10200 | } else textAlign = "right"; |
| 10201 | return { |
| 10202 | textAlign: textAlign, |
| 10203 | x: x |
| 10204 | }; |
| 10205 | } |
| 10206 | }, |
| 10207 | { |
| 10208 | key: "_computeLabelArea", |
| 10209 | value: function _computeLabelArea() { |
| 10210 | if (this.options.ticks.mirror) return; |
| 10211 | var chart = this.chart; |
| 10212 | var position = this.options.position; |
| 10213 | if (position === "left" || position === "right") return { |
| 10214 | top: 0, |
| 10215 | left: this.left, |
| 10216 | bottom: chart.height, |
| 10217 | right: this.right |
| 10218 | }; |
| 10219 | if (position === "top" || position === "bottom") return { |
| 10220 | top: this.top, |
| 10221 | left: 0, |
| 10222 | bottom: this.bottom, |
| 10223 | right: chart.width |
| 10224 | }; |
| 10225 | } |
| 10226 | }, |
| 10227 | { |
| 10228 | key: "drawBackground", |
| 10229 | value: function drawBackground() { |
| 10230 | var ref = this, ctx = ref.ctx, backgroundColor = ref.options.backgroundColor, left = ref.left, top = ref.top, width = ref.width, height = ref.height; |
| 10231 | if (backgroundColor) { |
| 10232 | ctx.save(); |
| 10233 | ctx.fillStyle = backgroundColor; |
| 10234 | ctx.fillRect(left, top, width, height); |
| 10235 | ctx.restore(); |
| 10236 | } |
| 10237 | } |
| 10238 | }, |
| 10239 | { |
| 10240 | key: "getLineWidthForValue", |
| 10241 | value: function getLineWidthForValue(value) { |
| 10242 | var grid = this.options.grid; |
| 10243 | if (!this._isVisible() || !grid.display) return 0; |
| 10244 | var ticks = this.ticks; |
| 10245 | var index48 = ticks.findIndex(function(t) { |
| 10246 | return t.value === value; |
| 10247 | }); |
| 10248 | if (index48 >= 0) { |
| 10249 | var opts = grid.setContext(this.getContext(index48)); |
| 10250 | return opts.lineWidth; |
| 10251 | } |
| 10252 | return 0; |
| 10253 | } |
| 10254 | }, |
| 10255 | { |
| 10256 | key: "drawGrid", |
| 10257 | value: function drawGrid(chartArea) { |
| 10258 | var grid = this.options.grid; |
| 10259 | var ctx = this.ctx; |
| 10260 | var items = this._gridLineItems || (this._gridLineItems = this._computeGridLineItems(chartArea)); |
| 10261 | var i, ilen; |
| 10262 | var drawLine = function(p1, p2, style) { |
| 10263 | if (!style.width || !style.color) return; |
| 10264 | ctx.save(); |
| 10265 | ctx.lineWidth = style.width; |
| 10266 | ctx.strokeStyle = style.color; |
| 10267 | ctx.setLineDash(style.borderDash || []); |
| 10268 | ctx.lineDashOffset = style.borderDashOffset; |
| 10269 | ctx.beginPath(); |
| 10270 | ctx.moveTo(p1.x, p1.y); |
| 10271 | ctx.lineTo(p2.x, p2.y); |
| 10272 | ctx.stroke(); |
| 10273 | ctx.restore(); |
| 10274 | }; |
| 10275 | if (grid.display) for(i = 0, ilen = items.length; i < ilen; ++i){ |
| 10276 | var item = items[i]; |
| 10277 | if (grid.drawOnChartArea) drawLine({ |
| 10278 | x: item.x1, |
| 10279 | y: item.y1 |
| 10280 | }, { |
| 10281 | x: item.x2, |
| 10282 | y: item.y2 |
| 10283 | }, item); |
| 10284 | if (grid.drawTicks) drawLine({ |
| 10285 | x: item.tx1, |
| 10286 | y: item.ty1 |
| 10287 | }, { |
| 10288 | x: item.tx2, |
| 10289 | y: item.ty2 |
| 10290 | }, { |
| 10291 | color: item.tickColor, |
| 10292 | width: item.tickWidth, |
| 10293 | borderDash: item.tickBorderDash, |
| 10294 | borderDashOffset: item.tickBorderDashOffset |
| 10295 | }); |
| 10296 | } |
| 10297 | } |
| 10298 | }, |
| 10299 | { |
| 10300 | key: "drawBorder", |
| 10301 | value: function drawBorder() { |
| 10302 | var ref = this, chart = ref.chart, ctx = ref.ctx, grid = ref.options.grid; |
| 10303 | var borderOpts = grid.setContext(this.getContext()); |
| 10304 | var axisWidth = grid.drawBorder ? borderOpts.borderWidth : 0; |
| 10305 | if (!axisWidth) return; |
| 10306 | var lastLineWidth = grid.setContext(this.getContext(0)).lineWidth; |
| 10307 | var borderValue = this._borderValue; |
| 10308 | var x1, x2, y1, y2; |
| 10309 | if (this.isHorizontal()) { |
| 10310 | x1 = (0, _helpersSegmentJs.W)(chart, this.left, axisWidth) - axisWidth / 2; |
| 10311 | x2 = (0, _helpersSegmentJs.W)(chart, this.right, lastLineWidth) + lastLineWidth / 2; |
| 10312 | y1 = y2 = borderValue; |
| 10313 | } else { |
| 10314 | y1 = (0, _helpersSegmentJs.W)(chart, this.top, axisWidth) - axisWidth / 2; |
| 10315 | y2 = (0, _helpersSegmentJs.W)(chart, this.bottom, lastLineWidth) + lastLineWidth / 2; |
| 10316 | x1 = x2 = borderValue; |
| 10317 | } |
| 10318 | ctx.save(); |
| 10319 | ctx.lineWidth = borderOpts.borderWidth; |
| 10320 | ctx.strokeStyle = borderOpts.borderColor; |
| 10321 | ctx.beginPath(); |
| 10322 | ctx.moveTo(x1, y1); |
| 10323 | ctx.lineTo(x2, y2); |
| 10324 | ctx.stroke(); |
| 10325 | ctx.restore(); |
| 10326 | } |
| 10327 | }, |
| 10328 | { |
| 10329 | key: "drawLabels", |
| 10330 | value: function drawLabels(chartArea) { |
| 10331 | var optionTicks = this.options.ticks; |
| 10332 | if (!optionTicks.display) return; |
| 10333 | var ctx = this.ctx; |
| 10334 | var area = this._computeLabelArea(); |
| 10335 | if (area) (0, _helpersSegmentJs.X)(ctx, area); |
| 10336 | var items = this._labelItems || (this._labelItems = this._computeLabelItems(chartArea)); |
| 10337 | var i, ilen; |
| 10338 | for(i = 0, ilen = items.length; i < ilen; ++i){ |
| 10339 | var item = items[i]; |
| 10340 | var tickFont = item.font; |
| 10341 | var label = item.label; |
| 10342 | if (item.backdrop) { |
| 10343 | ctx.fillStyle = item.backdrop.color; |
| 10344 | ctx.fillRect(item.backdrop.left, item.backdrop.top, item.backdrop.width, item.backdrop.height); |
| 10345 | } |
| 10346 | var y = item.textOffset; |
| 10347 | (0, _helpersSegmentJs.Y)(ctx, label, 0, y, tickFont, item); |
| 10348 | } |
| 10349 | if (area) (0, _helpersSegmentJs.Z)(ctx); |
| 10350 | } |
| 10351 | }, |
| 10352 | { |
| 10353 | key: "drawTitle", |
| 10354 | value: function drawTitle() { |
| 10355 | var ref = this, ctx = ref.ctx, _options = ref.options, position = _options.position, title = _options.title, reverse = _options.reverse; |
| 10356 | if (!title.display) return; |
| 10357 | var font = (0, _helpersSegmentJs.$)(title.font); |
| 10358 | var padding = (0, _helpersSegmentJs.D)(title.padding); |
| 10359 | var align = title.align; |
| 10360 | var offset = font.lineHeight / 2; |
| 10361 | if (position === "bottom" || position === "center" || (0, _helpersSegmentJs.i)(position)) { |
| 10362 | offset += padding.bottom; |
| 10363 | if ((0, _helpersSegmentJs.b)(title.text)) offset += font.lineHeight * (title.text.length - 1); |
| 10364 | } else offset += padding.top; |
| 10365 | var ref5 = titleArgs(this, offset, position, align), titleX = ref5.titleX, titleY = ref5.titleY, maxWidth = ref5.maxWidth, rotation = ref5.rotation; |
| 10366 | (0, _helpersSegmentJs.Y)(ctx, title.text, 0, 0, font, { |
| 10367 | color: title.color, |
| 10368 | maxWidth: maxWidth, |
| 10369 | rotation: rotation, |
| 10370 | textAlign: titleAlign(align, position, reverse), |
| 10371 | textBaseline: "middle", |
| 10372 | translation: [ |
| 10373 | titleX, |
| 10374 | titleY |
| 10375 | ] |
| 10376 | }); |
| 10377 | } |
| 10378 | }, |
| 10379 | { |
| 10380 | key: "draw", |
| 10381 | value: function draw2(chartArea) { |
| 10382 | if (!this._isVisible()) return; |
| 10383 | this.drawBackground(); |
| 10384 | this.drawGrid(chartArea); |
| 10385 | this.drawBorder(); |
| 10386 | this.drawTitle(); |
| 10387 | this.drawLabels(chartArea); |
| 10388 | } |
| 10389 | }, |
| 10390 | { |
| 10391 | key: "_layers", |
| 10392 | value: function _layers() { |
| 10393 | var _this = this; |
| 10394 | var opts = this.options; |
| 10395 | var tz = opts.ticks && opts.ticks.z || 0; |
| 10396 | var gz = (0, _helpersSegmentJs.v)(opts.grid && opts.grid.z, -1); |
| 10397 | if (!this._isVisible() || this.draw !== Scale.prototype.draw) return [ |
| 10398 | { |
| 10399 | z: tz, |
| 10400 | draw: function(chartArea) { |
| 10401 | _this.draw(chartArea); |
| 10402 | } |
| 10403 | } |
| 10404 | ]; |
| 10405 | return [ |
| 10406 | { |
| 10407 | z: gz, |
| 10408 | draw: function(chartArea) { |
| 10409 | _this.drawBackground(); |
| 10410 | _this.drawGrid(chartArea); |
| 10411 | _this.drawTitle(); |
| 10412 | } |
| 10413 | }, |
| 10414 | { |
| 10415 | z: gz + 1, |
| 10416 | draw: function() { |
| 10417 | _this.drawBorder(); |
| 10418 | } |
| 10419 | }, |
| 10420 | { |
| 10421 | z: tz, |
| 10422 | draw: function(chartArea) { |
| 10423 | _this.drawLabels(chartArea); |
| 10424 | } |
| 10425 | } |
| 10426 | ]; |
| 10427 | } |
| 10428 | }, |
| 10429 | { |
| 10430 | key: "getMatchingVisibleMetas", |
| 10431 | value: function getMatchingVisibleMetas(type) { |
| 10432 | var metas = this.chart.getSortedVisibleDatasetMetas(); |
| 10433 | var axisID = this.axis + "AxisID"; |
| 10434 | var result = []; |
| 10435 | var i, ilen; |
| 10436 | for(i = 0, ilen = metas.length; i < ilen; ++i){ |
| 10437 | var meta = metas[i]; |
| 10438 | if (meta[axisID] === this.id && (!type || meta.type === type)) result.push(meta); |
| 10439 | } |
| 10440 | return result; |
| 10441 | } |
| 10442 | }, |
| 10443 | { |
| 10444 | key: "_resolveTickFontOptions", |
| 10445 | value: function _resolveTickFontOptions(index49) { |
| 10446 | var opts = this.options.ticks.setContext(this.getContext(index49)); |
| 10447 | return (0, _helpersSegmentJs.$)(opts.font); |
| 10448 | } |
| 10449 | }, |
| 10450 | { |
| 10451 | key: "_maxDigits", |
| 10452 | value: function _maxDigits() { |
| 10453 | var fontSize = this._resolveTickFontOptions(0).lineHeight; |
| 10454 | return (this.isHorizontal() ? this.width : this.height) / fontSize; |
| 10455 | } |
| 10456 | } |
| 10457 | ]); |
| 10458 | return Scale; |
| 10459 | }((0, _wrapNativeSuperJsDefault.default)(Element)); |
| 10460 | var TypedRegistry = /*#__PURE__*/ function() { |
| 10461 | "use strict"; |
| 10462 | function TypedRegistry(type, scope, override) { |
| 10463 | (0, _classCallCheckJsDefault.default)(this, TypedRegistry); |
| 10464 | this.type = type; |
| 10465 | this.scope = scope; |
| 10466 | this.override = override; |
| 10467 | this.items = Object.create(null); |
| 10468 | } |
| 10469 | (0, _createClassJsDefault.default)(TypedRegistry, [ |
| 10470 | { |
| 10471 | key: "isForType", |
| 10472 | value: function isForType(type) { |
| 10473 | return Object.prototype.isPrototypeOf.call(this.type.prototype, type.prototype); |
| 10474 | } |
| 10475 | }, |
| 10476 | { |
| 10477 | key: "register", |
| 10478 | value: function register(item) { |
| 10479 | var proto = Object.getPrototypeOf(item); |
| 10480 | var parentScope; |
| 10481 | if (isIChartComponent(proto)) parentScope = this.register(proto); |
| 10482 | var items = this.items; |
| 10483 | var id = item.id; |
| 10484 | var scope = this.scope + "." + id; |
| 10485 | if (!id) throw new Error("class does not have id: " + item); |
| 10486 | if (id in items) return scope; |
| 10487 | items[id] = item; |
| 10488 | registerDefaults(item, scope, parentScope); |
| 10489 | if (this.override) (0, _helpersSegmentJs.d).override(item.id, item.overrides); |
| 10490 | return scope; |
| 10491 | } |
| 10492 | }, |
| 10493 | { |
| 10494 | key: "get", |
| 10495 | value: function get(id) { |
| 10496 | return this.items[id]; |
| 10497 | } |
| 10498 | }, |
| 10499 | { |
| 10500 | key: "unregister", |
| 10501 | value: function unregister(item) { |
| 10502 | var items = this.items; |
| 10503 | var id = item.id; |
| 10504 | var scope = this.scope; |
| 10505 | if (id in items) delete items[id]; |
| 10506 | if (scope && id in (0, _helpersSegmentJs.d)[scope]) { |
| 10507 | delete (0, _helpersSegmentJs.d)[scope][id]; |
| 10508 | if (this.override) delete (0, _helpersSegmentJs.a2)[id]; |
| 10509 | } |
| 10510 | } |
| 10511 | } |
| 10512 | ]); |
| 10513 | return TypedRegistry; |
| 10514 | }(); |
| 10515 | function registerDefaults(item, scope, parentScope) { |
| 10516 | var itemDefaults = (0, _helpersSegmentJs.a3)(Object.create(null), [ |
| 10517 | parentScope ? (0, _helpersSegmentJs.d).get(parentScope) : {}, |
| 10518 | (0, _helpersSegmentJs.d).get(scope), |
| 10519 | item.defaults |
| 10520 | ]); |
| 10521 | (0, _helpersSegmentJs.d).set(scope, itemDefaults); |
| 10522 | if (item.defaultRoutes) routeDefaults(scope, item.defaultRoutes); |
| 10523 | if (item.descriptors) (0, _helpersSegmentJs.d).describe(scope, item.descriptors); |
| 10524 | } |
| 10525 | function routeDefaults(scope, routes) { |
| 10526 | Object.keys(routes).forEach(function(property) { |
| 10527 | var propertyParts = property.split("."); |
| 10528 | var sourceName = propertyParts.pop(); |
| 10529 | var sourceScope = [ |
| 10530 | scope |
| 10531 | ].concat(propertyParts).join("."); |
| 10532 | var parts = routes[property].split("."); |
| 10533 | var targetName = parts.pop(); |
| 10534 | var targetScope = parts.join("."); |
| 10535 | (0, _helpersSegmentJs.d).route(sourceScope, sourceName, targetScope, targetName); |
| 10536 | }); |
| 10537 | } |
| 10538 | function isIChartComponent(proto) { |
| 10539 | return "id" in proto && "defaults" in proto; |
| 10540 | } |
| 10541 | var Registry = /*#__PURE__*/ function() { |
| 10542 | "use strict"; |
| 10543 | function Registry() { |
| 10544 | (0, _classCallCheckJsDefault.default)(this, Registry); |
| 10545 | this.controllers = new TypedRegistry(DatasetController, "datasets", true); |
| 10546 | this.elements = new TypedRegistry(Element, "elements"); |
| 10547 | this.plugins = new TypedRegistry(Object, "plugins"); |
| 10548 | this.scales = new TypedRegistry(Scale, "scales"); |
| 10549 | this._typedRegistries = [ |
| 10550 | this.controllers, |
| 10551 | this.scales, |
| 10552 | this.elements |
| 10553 | ]; |
| 10554 | } |
| 10555 | (0, _createClassJsDefault.default)(Registry, [ |
| 10556 | { |
| 10557 | key: "add", |
| 10558 | value: function add() { |
| 10559 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10560 | args[_key] = arguments[_key]; |
| 10561 | } |
| 10562 | this._each("register", args); |
| 10563 | } |
| 10564 | }, |
| 10565 | { |
| 10566 | key: "remove", |
| 10567 | value: function remove() { |
| 10568 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10569 | args[_key] = arguments[_key]; |
| 10570 | } |
| 10571 | this._each("unregister", args); |
| 10572 | } |
| 10573 | }, |
| 10574 | { |
| 10575 | key: "addControllers", |
| 10576 | value: function addControllers() { |
| 10577 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10578 | args[_key] = arguments[_key]; |
| 10579 | } |
| 10580 | this._each("register", args, this.controllers); |
| 10581 | } |
| 10582 | }, |
| 10583 | { |
| 10584 | key: "addElements", |
| 10585 | value: function addElements() { |
| 10586 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10587 | args[_key] = arguments[_key]; |
| 10588 | } |
| 10589 | this._each("register", args, this.elements); |
| 10590 | } |
| 10591 | }, |
| 10592 | { |
| 10593 | key: "addPlugins", |
| 10594 | value: function addPlugins() { |
| 10595 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10596 | args[_key] = arguments[_key]; |
| 10597 | } |
| 10598 | this._each("register", args, this.plugins); |
| 10599 | } |
| 10600 | }, |
| 10601 | { |
| 10602 | key: "addScales", |
| 10603 | value: function addScales() { |
| 10604 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10605 | args[_key] = arguments[_key]; |
| 10606 | } |
| 10607 | this._each("register", args, this.scales); |
| 10608 | } |
| 10609 | }, |
| 10610 | { |
| 10611 | key: "getController", |
| 10612 | value: function getController(id) { |
| 10613 | return this._get(id, this.controllers, "controller"); |
| 10614 | } |
| 10615 | }, |
| 10616 | { |
| 10617 | key: "getElement", |
| 10618 | value: function getElement(id) { |
| 10619 | return this._get(id, this.elements, "element"); |
| 10620 | } |
| 10621 | }, |
| 10622 | { |
| 10623 | key: "getPlugin", |
| 10624 | value: function getPlugin(id) { |
| 10625 | return this._get(id, this.plugins, "plugin"); |
| 10626 | } |
| 10627 | }, |
| 10628 | { |
| 10629 | key: "getScale", |
| 10630 | value: function getScale(id) { |
| 10631 | return this._get(id, this.scales, "scale"); |
| 10632 | } |
| 10633 | }, |
| 10634 | { |
| 10635 | key: "removeControllers", |
| 10636 | value: function removeControllers() { |
| 10637 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10638 | args[_key] = arguments[_key]; |
| 10639 | } |
| 10640 | this._each("unregister", args, this.controllers); |
| 10641 | } |
| 10642 | }, |
| 10643 | { |
| 10644 | key: "removeElements", |
| 10645 | value: function removeElements() { |
| 10646 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10647 | args[_key] = arguments[_key]; |
| 10648 | } |
| 10649 | this._each("unregister", args, this.elements); |
| 10650 | } |
| 10651 | }, |
| 10652 | { |
| 10653 | key: "removePlugins", |
| 10654 | value: function removePlugins() { |
| 10655 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10656 | args[_key] = arguments[_key]; |
| 10657 | } |
| 10658 | this._each("unregister", args, this.plugins); |
| 10659 | } |
| 10660 | }, |
| 10661 | { |
| 10662 | key: "removeScales", |
| 10663 | value: function removeScales() { |
| 10664 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 10665 | args[_key] = arguments[_key]; |
| 10666 | } |
| 10667 | this._each("unregister", args, this.scales); |
| 10668 | } |
| 10669 | }, |
| 10670 | { |
| 10671 | key: "_each", |
| 10672 | value: function _each(method, args, typedRegistry) { |
| 10673 | var _this = this; |
| 10674 | (0, _toConsumableArrayJsDefault.default)(args).forEach(function(arg) { |
| 10675 | var _this1 = _this; |
| 10676 | var reg = typedRegistry || _this._getRegistryForType(arg); |
| 10677 | if (typedRegistry || reg.isForType(arg) || reg === _this.plugins && arg.id) _this._exec(method, reg, arg); |
| 10678 | else (0, _helpersSegmentJs.E)(arg, function(item) { |
| 10679 | var itemReg = typedRegistry || _this1._getRegistryForType(item); |
| 10680 | _this1._exec(method, itemReg, item); |
| 10681 | }); |
| 10682 | }); |
| 10683 | } |
| 10684 | }, |
| 10685 | { |
| 10686 | key: "_exec", |
| 10687 | value: function _exec(method, registry1, component) { |
| 10688 | var camelMethod = (0, _helpersSegmentJs.a4)(method); |
| 10689 | (0, _helpersSegmentJs.Q)(component["before" + camelMethod], [], component); |
| 10690 | registry1[method](component); |
| 10691 | (0, _helpersSegmentJs.Q)(component["after" + camelMethod], [], component); |
| 10692 | } |
| 10693 | }, |
| 10694 | { |
| 10695 | key: "_getRegistryForType", |
| 10696 | value: function _getRegistryForType(type) { |
| 10697 | for(var i = 0; i < this._typedRegistries.length; i++){ |
| 10698 | var reg = this._typedRegistries[i]; |
| 10699 | if (reg.isForType(type)) return reg; |
| 10700 | } |
| 10701 | return this.plugins; |
| 10702 | } |
| 10703 | }, |
| 10704 | { |
| 10705 | key: "_get", |
| 10706 | value: function _get(id, typedRegistry, type) { |
| 10707 | var item = typedRegistry.get(id); |
| 10708 | if (item === undefined) throw new Error('"' + id + '" is not a registered ' + type + "."); |
| 10709 | return item; |
| 10710 | } |
| 10711 | } |
| 10712 | ]); |
| 10713 | return Registry; |
| 10714 | }(); |
| 10715 | var registry = new Registry(); |
| 10716 | var PluginService = /*#__PURE__*/ function() { |
| 10717 | "use strict"; |
| 10718 | function PluginService() { |
| 10719 | (0, _classCallCheckJsDefault.default)(this, PluginService); |
| 10720 | this._init = []; |
| 10721 | } |
| 10722 | (0, _createClassJsDefault.default)(PluginService, [ |
| 10723 | { |
| 10724 | key: "notify", |
| 10725 | value: function notify(chart, hook, args, filter) { |
| 10726 | if (hook === "beforeInit") { |
| 10727 | this._init = this._createDescriptors(chart, true); |
| 10728 | this._notify(this._init, chart, "install"); |
| 10729 | } |
| 10730 | var descriptors = filter ? this._descriptors(chart).filter(filter) : this._descriptors(chart); |
| 10731 | var result = this._notify(descriptors, chart, hook, args); |
| 10732 | if (hook === "afterDestroy") { |
| 10733 | this._notify(descriptors, chart, "stop"); |
| 10734 | this._notify(this._init, chart, "uninstall"); |
| 10735 | } |
| 10736 | return result; |
| 10737 | } |
| 10738 | }, |
| 10739 | { |
| 10740 | key: "_notify", |
| 10741 | value: function _notify(descriptors, chart, hook, args) { |
| 10742 | args = args || {}; |
| 10743 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 10744 | try { |
| 10745 | for(var _iterator = descriptors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 10746 | var descriptor = _step.value; |
| 10747 | var plugin = descriptor.plugin; |
| 10748 | var method = plugin[hook]; |
| 10749 | var params = [ |
| 10750 | chart, |
| 10751 | args, |
| 10752 | descriptor.options |
| 10753 | ]; |
| 10754 | if ((0, _helpersSegmentJs.Q)(method, params, plugin) === false && args.cancelable) return false; |
| 10755 | } |
| 10756 | } catch (err) { |
| 10757 | _didIteratorError = true; |
| 10758 | _iteratorError = err; |
| 10759 | } finally{ |
| 10760 | try { |
| 10761 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 10762 | _iterator.return(); |
| 10763 | } |
| 10764 | } finally{ |
| 10765 | if (_didIteratorError) { |
| 10766 | throw _iteratorError; |
| 10767 | } |
| 10768 | } |
| 10769 | } |
| 10770 | return true; |
| 10771 | } |
| 10772 | }, |
| 10773 | { |
| 10774 | key: "invalidate", |
| 10775 | value: function invalidate() { |
| 10776 | if (!(0, _helpersSegmentJs.k)(this._cache)) { |
| 10777 | this._oldCache = this._cache; |
| 10778 | this._cache = undefined; |
| 10779 | } |
| 10780 | } |
| 10781 | }, |
| 10782 | { |
| 10783 | key: "_descriptors", |
| 10784 | value: function _descriptors(chart) { |
| 10785 | if (this._cache) return this._cache; |
| 10786 | var descriptors = this._cache = this._createDescriptors(chart); |
| 10787 | this._notifyStateChanges(chart); |
| 10788 | return descriptors; |
| 10789 | } |
| 10790 | }, |
| 10791 | { |
| 10792 | key: "_createDescriptors", |
| 10793 | value: function _createDescriptors(chart, all) { |
| 10794 | var config = chart && chart.config; |
| 10795 | var options = (0, _helpersSegmentJs.v)(config.options && config.options.plugins, {}); |
| 10796 | var plugins1 = allPlugins(config); |
| 10797 | return options === false && !all ? [] : createDescriptors(chart, plugins1, options, all); |
| 10798 | } |
| 10799 | }, |
| 10800 | { |
| 10801 | key: "_notifyStateChanges", |
| 10802 | value: function _notifyStateChanges(chart) { |
| 10803 | var previousDescriptors = this._oldCache || []; |
| 10804 | var descriptors = this._cache; |
| 10805 | var diff = function(a, b) { |
| 10806 | return a.filter(function(x) { |
| 10807 | return !b.some(function(y) { |
| 10808 | return x.plugin.id === y.plugin.id; |
| 10809 | }); |
| 10810 | }); |
| 10811 | }; |
| 10812 | this._notify(diff(previousDescriptors, descriptors), chart, "stop"); |
| 10813 | this._notify(diff(descriptors, previousDescriptors), chart, "start"); |
| 10814 | } |
| 10815 | } |
| 10816 | ]); |
| 10817 | return PluginService; |
| 10818 | }(); |
| 10819 | function allPlugins(config) { |
| 10820 | var plugins2 = []; |
| 10821 | var keys = Object.keys(registry.plugins.items); |
| 10822 | for(var i = 0; i < keys.length; i++)plugins2.push(registry.getPlugin(keys[i])); |
| 10823 | var local = config.plugins || []; |
| 10824 | for(var i3 = 0; i3 < local.length; i3++){ |
| 10825 | var plugin = local[i3]; |
| 10826 | if (plugins2.indexOf(plugin) === -1) plugins2.push(plugin); |
| 10827 | } |
| 10828 | return plugins2; |
| 10829 | } |
| 10830 | function getOpts(options, all) { |
| 10831 | if (!all && options === false) return null; |
| 10832 | if (options === true) return {}; |
| 10833 | return options; |
| 10834 | } |
| 10835 | function createDescriptors(chart, plugins3, options, all) { |
| 10836 | var result = []; |
| 10837 | var context = chart.getContext(); |
| 10838 | for(var i = 0; i < plugins3.length; i++){ |
| 10839 | var plugin = plugins3[i]; |
| 10840 | var id = plugin.id; |
| 10841 | var opts = getOpts(options[id], all); |
| 10842 | if (opts === null) continue; |
| 10843 | result.push({ |
| 10844 | plugin: plugin, |
| 10845 | options: pluginOpts(chart.config, plugin, opts, context) |
| 10846 | }); |
| 10847 | } |
| 10848 | return result; |
| 10849 | } |
| 10850 | function pluginOpts(config, plugin, opts, context) { |
| 10851 | var keys = config.pluginScopeKeys(plugin); |
| 10852 | var scopes = config.getOptionScopes(opts, keys); |
| 10853 | return config.createResolver(scopes, context, [ |
| 10854 | "" |
| 10855 | ], { |
| 10856 | scriptable: false, |
| 10857 | indexable: false, |
| 10858 | allKeys: true |
| 10859 | }); |
| 10860 | } |
| 10861 | function getIndexAxis(type, options) { |
| 10862 | var datasetDefaults = (0, _helpersSegmentJs.d).datasets[type] || {}; |
| 10863 | var datasetOptions = (options.datasets || {})[type] || {}; |
| 10864 | return datasetOptions.indexAxis || options.indexAxis || datasetDefaults.indexAxis || "x"; |
| 10865 | } |
| 10866 | function getAxisFromDefaultScaleID(id, indexAxis) { |
| 10867 | var axis = id; |
| 10868 | if (id === "_index_") axis = indexAxis; |
| 10869 | else if (id === "_value_") axis = indexAxis === "x" ? "y" : "x"; |
| 10870 | return axis; |
| 10871 | } |
| 10872 | function getDefaultScaleIDFromAxis(axis, indexAxis) { |
| 10873 | return axis === indexAxis ? "_index_" : "_value_"; |
| 10874 | } |
| 10875 | function axisFromPosition(position) { |
| 10876 | if (position === "top" || position === "bottom") return "x"; |
| 10877 | if (position === "left" || position === "right") return "y"; |
| 10878 | } |
| 10879 | function determineAxis(id, scaleOptions) { |
| 10880 | if (id === "x" || id === "y") return id; |
| 10881 | return scaleOptions.axis || axisFromPosition(scaleOptions.position) || id.charAt(0).toLowerCase(); |
| 10882 | } |
| 10883 | function mergeScaleConfig(config, options) { |
| 10884 | var chartDefaults = (0, _helpersSegmentJs.a2)[config.type] || { |
| 10885 | scales: {} |
| 10886 | }; |
| 10887 | var configScales = options.scales || {}; |
| 10888 | var chartIndexAxis = getIndexAxis(config.type, options); |
| 10889 | var firstIDs = Object.create(null); |
| 10890 | var scales3 = Object.create(null); |
| 10891 | Object.keys(configScales).forEach(function(id) { |
| 10892 | var scaleConf = configScales[id]; |
| 10893 | if (!(0, _helpersSegmentJs.i)(scaleConf)) return console.error("Invalid scale configuration for scale: ".concat(id)); |
| 10894 | if (scaleConf._proxy) return console.warn("Ignoring resolver passed as options for scale: ".concat(id)); |
| 10895 | var axis = determineAxis(id, scaleConf); |
| 10896 | var defaultId = getDefaultScaleIDFromAxis(axis, chartIndexAxis); |
| 10897 | var defaultScaleOptions = chartDefaults.scales || {}; |
| 10898 | firstIDs[axis] = firstIDs[axis] || id; |
| 10899 | scales3[id] = (0, _helpersSegmentJs.aa)(Object.create(null), [ |
| 10900 | { |
| 10901 | axis: axis |
| 10902 | }, |
| 10903 | scaleConf, |
| 10904 | defaultScaleOptions[axis], |
| 10905 | defaultScaleOptions[defaultId] |
| 10906 | ]); |
| 10907 | }); |
| 10908 | config.data.datasets.forEach(function(dataset) { |
| 10909 | var type = dataset.type || config.type; |
| 10910 | var indexAxis = dataset.indexAxis || getIndexAxis(type, options); |
| 10911 | var datasetDefaults = (0, _helpersSegmentJs.a2)[type] || {}; |
| 10912 | var defaultScaleOptions = datasetDefaults.scales || {}; |
| 10913 | Object.keys(defaultScaleOptions).forEach(function(defaultID) { |
| 10914 | var axis = getAxisFromDefaultScaleID(defaultID, indexAxis); |
| 10915 | var id = dataset[axis + "AxisID"] || firstIDs[axis] || axis; |
| 10916 | scales3[id] = scales3[id] || Object.create(null); |
| 10917 | (0, _helpersSegmentJs.aa)(scales3[id], [ |
| 10918 | { |
| 10919 | axis: axis |
| 10920 | }, |
| 10921 | configScales[id], |
| 10922 | defaultScaleOptions[defaultID] |
| 10923 | ]); |
| 10924 | }); |
| 10925 | }); |
| 10926 | Object.keys(scales3).forEach(function(key) { |
| 10927 | var scale = scales3[key]; |
| 10928 | (0, _helpersSegmentJs.aa)(scale, [ |
| 10929 | (0, _helpersSegmentJs.d).scales[scale.type], |
| 10930 | (0, _helpersSegmentJs.d).scale |
| 10931 | ]); |
| 10932 | }); |
| 10933 | return scales3; |
| 10934 | } |
| 10935 | function initOptions(config) { |
| 10936 | var options = config.options || (config.options = {}); |
| 10937 | options.plugins = (0, _helpersSegmentJs.v)(options.plugins, {}); |
| 10938 | options.scales = mergeScaleConfig(config, options); |
| 10939 | } |
| 10940 | function initData(data) { |
| 10941 | data = data || {}; |
| 10942 | data.datasets = data.datasets || []; |
| 10943 | data.labels = data.labels || []; |
| 10944 | return data; |
| 10945 | } |
| 10946 | function initConfig(config) { |
| 10947 | config = config || {}; |
| 10948 | config.data = initData(config.data); |
| 10949 | initOptions(config); |
| 10950 | return config; |
| 10951 | } |
| 10952 | var keyCache = new Map(); |
| 10953 | var keysCached = new Set(); |
| 10954 | function cachedKeys(cacheKey, generate) { |
| 10955 | var keys = keyCache.get(cacheKey); |
| 10956 | if (!keys) { |
| 10957 | keys = generate(); |
| 10958 | keyCache.set(cacheKey, keys); |
| 10959 | keysCached.add(keys); |
| 10960 | } |
| 10961 | return keys; |
| 10962 | } |
| 10963 | var addIfFound = function(set, obj, key) { |
| 10964 | var opts = (0, _helpersSegmentJs.f)(obj, key); |
| 10965 | if (opts !== undefined) set.add(opts); |
| 10966 | }; |
| 10967 | var Config = /*#__PURE__*/ function() { |
| 10968 | "use strict"; |
| 10969 | function Config(config) { |
| 10970 | (0, _classCallCheckJsDefault.default)(this, Config); |
| 10971 | this._config = initConfig(config); |
| 10972 | this._scopeCache = new Map(); |
| 10973 | this._resolverCache = new Map(); |
| 10974 | } |
| 10975 | (0, _createClassJsDefault.default)(Config, [ |
| 10976 | { |
| 10977 | key: "platform", |
| 10978 | get: function get() { |
| 10979 | return this._config.platform; |
| 10980 | } |
| 10981 | }, |
| 10982 | { |
| 10983 | key: "type", |
| 10984 | get: function get() { |
| 10985 | return this._config.type; |
| 10986 | }, |
| 10987 | set: function set(type) { |
| 10988 | this._config.type = type; |
| 10989 | } |
| 10990 | }, |
| 10991 | { |
| 10992 | key: "data", |
| 10993 | get: function get() { |
| 10994 | return this._config.data; |
| 10995 | }, |
| 10996 | set: function set(data) { |
| 10997 | this._config.data = initData(data); |
| 10998 | } |
| 10999 | }, |
| 11000 | { |
| 11001 | key: "options", |
| 11002 | get: function get() { |
| 11003 | return this._config.options; |
| 11004 | }, |
| 11005 | set: function set(options) { |
| 11006 | this._config.options = options; |
| 11007 | } |
| 11008 | }, |
| 11009 | { |
| 11010 | key: "plugins", |
| 11011 | get: function get() { |
| 11012 | return this._config.plugins; |
| 11013 | } |
| 11014 | }, |
| 11015 | { |
| 11016 | key: "update", |
| 11017 | value: function update() { |
| 11018 | var config = this._config; |
| 11019 | this.clearCache(); |
| 11020 | initOptions(config); |
| 11021 | } |
| 11022 | }, |
| 11023 | { |
| 11024 | key: "clearCache", |
| 11025 | value: function clearCache() { |
| 11026 | this._scopeCache.clear(); |
| 11027 | this._resolverCache.clear(); |
| 11028 | } |
| 11029 | }, |
| 11030 | { |
| 11031 | key: "datasetScopeKeys", |
| 11032 | value: function datasetScopeKeys(datasetType) { |
| 11033 | return cachedKeys(datasetType, function() { |
| 11034 | return [ |
| 11035 | [ |
| 11036 | "datasets.".concat(datasetType), |
| 11037 | "" |
| 11038 | ] |
| 11039 | ]; |
| 11040 | }); |
| 11041 | } |
| 11042 | }, |
| 11043 | { |
| 11044 | key: "datasetAnimationScopeKeys", |
| 11045 | value: function datasetAnimationScopeKeys(datasetType, transition) { |
| 11046 | return cachedKeys("".concat(datasetType, ".transition.").concat(transition), function() { |
| 11047 | return [ |
| 11048 | [ |
| 11049 | "datasets.".concat(datasetType, ".transitions.").concat(transition), |
| 11050 | "transitions.".concat(transition), |
| 11051 | ], |
| 11052 | [ |
| 11053 | "datasets.".concat(datasetType), |
| 11054 | "" |
| 11055 | ] |
| 11056 | ]; |
| 11057 | }); |
| 11058 | } |
| 11059 | }, |
| 11060 | { |
| 11061 | key: "datasetElementScopeKeys", |
| 11062 | value: function datasetElementScopeKeys(datasetType, elementType) { |
| 11063 | return cachedKeys("".concat(datasetType, "-").concat(elementType), function() { |
| 11064 | return [ |
| 11065 | [ |
| 11066 | "datasets.".concat(datasetType, ".elements.").concat(elementType), |
| 11067 | "datasets.".concat(datasetType), |
| 11068 | "elements.".concat(elementType), |
| 11069 | "" |
| 11070 | ] |
| 11071 | ]; |
| 11072 | }); |
| 11073 | } |
| 11074 | }, |
| 11075 | { |
| 11076 | key: "pluginScopeKeys", |
| 11077 | value: function pluginScopeKeys(plugin) { |
| 11078 | var id = plugin.id; |
| 11079 | var type = this.type; |
| 11080 | return cachedKeys("".concat(type, "-plugin-").concat(id), function() { |
| 11081 | return [ |
| 11082 | [ |
| 11083 | "plugins.".concat(id), |
| 11084 | ].concat((0, _toConsumableArrayJsDefault.default)(plugin.additionalOptionScopes || [])) |
| 11085 | ]; |
| 11086 | }); |
| 11087 | } |
| 11088 | }, |
| 11089 | { |
| 11090 | key: "_cachedScopes", |
| 11091 | value: function _cachedScopes(mainScope, resetCache) { |
| 11092 | var _scopeCache = this._scopeCache; |
| 11093 | var cache = _scopeCache.get(mainScope); |
| 11094 | if (!cache || resetCache) { |
| 11095 | cache = new Map(); |
| 11096 | _scopeCache.set(mainScope, cache); |
| 11097 | } |
| 11098 | return cache; |
| 11099 | } |
| 11100 | }, |
| 11101 | { |
| 11102 | key: "getOptionScopes", |
| 11103 | value: function getOptionScopes(mainScope, keyLists, resetCache) { |
| 11104 | var ref = this, options = ref.options, type = ref.type; |
| 11105 | var cache = this._cachedScopes(mainScope, resetCache); |
| 11106 | var cached = cache.get(keyLists); |
| 11107 | if (cached) return cached; |
| 11108 | var scopes = new Set(); |
| 11109 | keyLists.forEach(function(keys) { |
| 11110 | if (mainScope) { |
| 11111 | scopes.add(mainScope); |
| 11112 | keys.forEach(function(key) { |
| 11113 | return addIfFound(scopes, mainScope, key); |
| 11114 | }); |
| 11115 | } |
| 11116 | keys.forEach(function(key) { |
| 11117 | return addIfFound(scopes, options, key); |
| 11118 | }); |
| 11119 | keys.forEach(function(key) { |
| 11120 | return addIfFound(scopes, (0, _helpersSegmentJs.a2)[type] || {}, key); |
| 11121 | }); |
| 11122 | keys.forEach(function(key) { |
| 11123 | return addIfFound(scopes, (0, _helpersSegmentJs.d), key); |
| 11124 | }); |
| 11125 | keys.forEach(function(key) { |
| 11126 | return addIfFound(scopes, (0, _helpersSegmentJs.a5), key); |
| 11127 | }); |
| 11128 | }); |
| 11129 | var array = Array.from(scopes); |
| 11130 | if (array.length === 0) array.push(Object.create(null)); |
| 11131 | if (keysCached.has(keyLists)) cache.set(keyLists, array); |
| 11132 | return array; |
| 11133 | } |
| 11134 | }, |
| 11135 | { |
| 11136 | key: "chartOptionScopes", |
| 11137 | value: function chartOptionScopes() { |
| 11138 | var ref = this, options = ref.options, type = ref.type; |
| 11139 | return [ |
| 11140 | options, |
| 11141 | (0, _helpersSegmentJs.a2)[type] || {}, |
| 11142 | (0, _helpersSegmentJs.d).datasets[type] || {}, |
| 11143 | { |
| 11144 | type: type |
| 11145 | }, |
| 11146 | (0, _helpersSegmentJs.d), |
| 11147 | (0, _helpersSegmentJs.a5) |
| 11148 | ]; |
| 11149 | } |
| 11150 | }, |
| 11151 | { |
| 11152 | key: "resolveNamedOptions", |
| 11153 | value: function resolveNamedOptions(scopes, names, context) { |
| 11154 | var prefixes = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : [ |
| 11155 | "" |
| 11156 | ]; |
| 11157 | var result = { |
| 11158 | $shared: true |
| 11159 | }; |
| 11160 | var ref = getResolver(this._resolverCache, scopes, prefixes), resolver = ref.resolver, subPrefixes = ref.subPrefixes; |
| 11161 | var options = resolver; |
| 11162 | if (needContext(resolver, names)) { |
| 11163 | result.$shared = false; |
| 11164 | context = (0, _helpersSegmentJs.a6)(context) ? context() : context; |
| 11165 | var subResolver = this.createResolver(scopes, context, subPrefixes); |
| 11166 | options = (0, _helpersSegmentJs.a7)(resolver, context, subResolver); |
| 11167 | } |
| 11168 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 11169 | try { |
| 11170 | for(var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 11171 | var prop = _step.value; |
| 11172 | result[prop] = options[prop]; |
| 11173 | } |
| 11174 | } catch (err) { |
| 11175 | _didIteratorError = true; |
| 11176 | _iteratorError = err; |
| 11177 | } finally{ |
| 11178 | try { |
| 11179 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 11180 | _iterator.return(); |
| 11181 | } |
| 11182 | } finally{ |
| 11183 | if (_didIteratorError) { |
| 11184 | throw _iteratorError; |
| 11185 | } |
| 11186 | } |
| 11187 | } |
| 11188 | return result; |
| 11189 | } |
| 11190 | }, |
| 11191 | { |
| 11192 | key: "createResolver", |
| 11193 | value: function createResolver(scopes, context) { |
| 11194 | var prefixes = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [ |
| 11195 | "" |
| 11196 | ], descriptorDefaults = arguments.length > 3 ? arguments[3] : void 0; |
| 11197 | var resolver = getResolver(this._resolverCache, scopes, prefixes).resolver; |
| 11198 | return (0, _helpersSegmentJs.i)(context) ? (0, _helpersSegmentJs.a7)(resolver, context, undefined, descriptorDefaults) : resolver; |
| 11199 | } |
| 11200 | } |
| 11201 | ]); |
| 11202 | return Config; |
| 11203 | }(); |
| 11204 | function getResolver(resolverCache, scopes, prefixes) { |
| 11205 | var cache = resolverCache.get(scopes); |
| 11206 | if (!cache) { |
| 11207 | cache = new Map(); |
| 11208 | resolverCache.set(scopes, cache); |
| 11209 | } |
| 11210 | var cacheKey = prefixes.join(); |
| 11211 | var cached = cache.get(cacheKey); |
| 11212 | if (!cached) { |
| 11213 | var resolver = (0, _helpersSegmentJs.a8)(scopes, prefixes); |
| 11214 | cached = { |
| 11215 | resolver: resolver, |
| 11216 | subPrefixes: prefixes.filter(function(p) { |
| 11217 | return !p.toLowerCase().includes("hover"); |
| 11218 | }) |
| 11219 | }; |
| 11220 | cache.set(cacheKey, cached); |
| 11221 | } |
| 11222 | return cached; |
| 11223 | } |
| 11224 | var hasFunction = function(value) { |
| 11225 | return (0, _helpersSegmentJs.i)(value) && Object.getOwnPropertyNames(value).reduce(function(acc, key) { |
| 11226 | return acc || (0, _helpersSegmentJs.a6)(value[key]); |
| 11227 | }, false); |
| 11228 | }; |
| 11229 | function needContext(proxy, names) { |
| 11230 | var ref = (0, _helpersSegmentJs.a9)(proxy), isScriptable = ref.isScriptable, isIndexable = ref.isIndexable; |
| 11231 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 11232 | try { |
| 11233 | for(var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 11234 | var prop = _step.value; |
| 11235 | var scriptable = isScriptable(prop); |
| 11236 | var indexable = isIndexable(prop); |
| 11237 | var value = (indexable || scriptable) && proxy[prop]; |
| 11238 | if (scriptable && ((0, _helpersSegmentJs.a6)(value) || hasFunction(value)) || indexable && (0, _helpersSegmentJs.b)(value)) return true; |
| 11239 | } |
| 11240 | } catch (err) { |
| 11241 | _didIteratorError = true; |
| 11242 | _iteratorError = err; |
| 11243 | } finally{ |
| 11244 | try { |
| 11245 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 11246 | _iterator.return(); |
| 11247 | } |
| 11248 | } finally{ |
| 11249 | if (_didIteratorError) { |
| 11250 | throw _iteratorError; |
| 11251 | } |
| 11252 | } |
| 11253 | } |
| 11254 | return false; |
| 11255 | } |
| 11256 | var version = "3.8.0"; |
| 11257 | var KNOWN_POSITIONS = [ |
| 11258 | "top", |
| 11259 | "bottom", |
| 11260 | "left", |
| 11261 | "right", |
| 11262 | "chartArea" |
| 11263 | ]; |
| 11264 | function positionIsHorizontal(position, axis) { |
| 11265 | return position === "top" || position === "bottom" || KNOWN_POSITIONS.indexOf(position) === -1 && axis === "x"; |
| 11266 | } |
| 11267 | function compare2Level(l1, l2) { |
| 11268 | return function(a, b) { |
| 11269 | return a[l1] === b[l1] ? a[l2] - b[l2] : a[l1] - b[l1]; |
| 11270 | }; |
| 11271 | } |
| 11272 | function onAnimationsComplete(context) { |
| 11273 | var chart = context.chart; |
| 11274 | var animationOptions1 = chart.options.animation; |
| 11275 | chart.notifyPlugins("afterRender"); |
| 11276 | (0, _helpersSegmentJs.Q)(animationOptions1 && animationOptions1.onComplete, [ |
| 11277 | context |
| 11278 | ], chart); |
| 11279 | } |
| 11280 | function onAnimationProgress(context) { |
| 11281 | var chart = context.chart; |
| 11282 | var animationOptions2 = chart.options.animation; |
| 11283 | (0, _helpersSegmentJs.Q)(animationOptions2 && animationOptions2.onProgress, [ |
| 11284 | context |
| 11285 | ], chart); |
| 11286 | } |
| 11287 | function getCanvas(item) { |
| 11288 | if ((0, _helpersSegmentJs.L)() && typeof item === "string") item = document.getElementById(item); |
| 11289 | else if (item && item.length) item = item[0]; |
| 11290 | if (item && item.canvas) item = item.canvas; |
| 11291 | return item; |
| 11292 | } |
| 11293 | var instances = {}; |
| 11294 | var getChart = function(key) { |
| 11295 | var canvas = getCanvas(key); |
| 11296 | return Object.values(instances).filter(function(c) { |
| 11297 | return c.canvas === canvas; |
| 11298 | }).pop(); |
| 11299 | }; |
| 11300 | function moveNumericKeys(obj, start, move) { |
| 11301 | var keys = Object.keys(obj); |
| 11302 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 11303 | try { |
| 11304 | for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 11305 | var key = _step.value; |
| 11306 | var intKey = +key; |
| 11307 | if (intKey >= start) { |
| 11308 | var value = obj[key]; |
| 11309 | delete obj[key]; |
| 11310 | if (move > 0 || intKey > start) obj[intKey + move] = value; |
| 11311 | } |
| 11312 | } |
| 11313 | } catch (err) { |
| 11314 | _didIteratorError = true; |
| 11315 | _iteratorError = err; |
| 11316 | } finally{ |
| 11317 | try { |
| 11318 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 11319 | _iterator.return(); |
| 11320 | } |
| 11321 | } finally{ |
| 11322 | if (_didIteratorError) { |
| 11323 | throw _iteratorError; |
| 11324 | } |
| 11325 | } |
| 11326 | } |
| 11327 | } |
| 11328 | function determineLastEvent(e, lastEvent, inChartArea, isClick) { |
| 11329 | if (!inChartArea || e.type === "mouseout") return null; |
| 11330 | if (isClick) return lastEvent; |
| 11331 | return e; |
| 11332 | } |
| 11333 | var Chart = /*#__PURE__*/ function() { |
| 11334 | "use strict"; |
| 11335 | function Chart(item, userConfig) { |
| 11336 | var _this = this; |
| 11337 | (0, _classCallCheckJsDefault.default)(this, Chart); |
| 11338 | var config = this.config = new Config(userConfig); |
| 11339 | var initialCanvas = getCanvas(item); |
| 11340 | var existingChart = getChart(initialCanvas); |
| 11341 | if (existingChart) throw new Error("Canvas is already in use. Chart with ID '" + existingChart.id + "'" + " must be destroyed before the canvas can be reused."); |
| 11342 | var options = config.createResolver(config.chartOptionScopes(), this.getContext()); |
| 11343 | this.platform = new (config.platform || _detectPlatform(initialCanvas))(); |
| 11344 | this.platform.updateConfig(config); |
| 11345 | var context = this.platform.acquireContext(initialCanvas, options.aspectRatio); |
| 11346 | var canvas = context && context.canvas; |
| 11347 | var height = canvas && canvas.height; |
| 11348 | var width = canvas && canvas.width; |
| 11349 | this.id = (0, _helpersSegmentJs.ab)(); |
| 11350 | this.ctx = context; |
| 11351 | this.canvas = canvas; |
| 11352 | this.width = width; |
| 11353 | this.height = height; |
| 11354 | this._options = options; |
| 11355 | this._aspectRatio = this.aspectRatio; |
| 11356 | this._layers = []; |
| 11357 | this._metasets = []; |
| 11358 | this._stacks = undefined; |
| 11359 | this.boxes = []; |
| 11360 | this.currentDevicePixelRatio = undefined; |
| 11361 | this.chartArea = undefined; |
| 11362 | this._active = []; |
| 11363 | this._lastEvent = undefined; |
| 11364 | this._listeners = {}; |
| 11365 | this._responsiveListeners = undefined; |
| 11366 | this._sortedMetasets = []; |
| 11367 | this.scales = {}; |
| 11368 | this._plugins = new PluginService(); |
| 11369 | this.$proxies = {}; |
| 11370 | this._hiddenIndices = {}; |
| 11371 | this.attached = false; |
| 11372 | this._animationsDisabled = undefined; |
| 11373 | this.$context = undefined; |
| 11374 | this._doResize = (0, _helpersSegmentJs.ac)(function(mode) { |
| 11375 | return _this.update(mode); |
| 11376 | }, options.resizeDelay || 0); |
| 11377 | this._dataChanges = []; |
| 11378 | instances[this.id] = this; |
| 11379 | if (!context || !canvas) { |
| 11380 | console.error("Failed to create chart: can't acquire context from the given item"); |
| 11381 | return; |
| 11382 | } |
| 11383 | animator.listen(this, "complete", onAnimationsComplete); |
| 11384 | animator.listen(this, "progress", onAnimationProgress); |
| 11385 | this._initialize(); |
| 11386 | if (this.attached) this.update(); |
| 11387 | } |
| 11388 | (0, _createClassJsDefault.default)(Chart, [ |
| 11389 | { |
| 11390 | key: "aspectRatio", |
| 11391 | get: function get() { |
| 11392 | var ref = this, _options = ref.options, aspectRatio = _options.aspectRatio, maintainAspectRatio = _options.maintainAspectRatio, width = ref.width, height = ref.height, _aspectRatio = ref._aspectRatio; |
| 11393 | if (!(0, _helpersSegmentJs.k)(aspectRatio)) return aspectRatio; |
| 11394 | if (maintainAspectRatio && _aspectRatio) return _aspectRatio; |
| 11395 | return height ? width / height : null; |
| 11396 | } |
| 11397 | }, |
| 11398 | { |
| 11399 | key: "data", |
| 11400 | get: function get() { |
| 11401 | return this.config.data; |
| 11402 | }, |
| 11403 | set: function set(data) { |
| 11404 | this.config.data = data; |
| 11405 | } |
| 11406 | }, |
| 11407 | { |
| 11408 | key: "options", |
| 11409 | get: function get() { |
| 11410 | return this._options; |
| 11411 | }, |
| 11412 | set: function set(options) { |
| 11413 | this.config.options = options; |
| 11414 | } |
| 11415 | }, |
| 11416 | { |
| 11417 | key: "_initialize", |
| 11418 | value: function _initialize() { |
| 11419 | this.notifyPlugins("beforeInit"); |
| 11420 | if (this.options.responsive) this.resize(); |
| 11421 | else (0, _helpersSegmentJs.ad)(this, this.options.devicePixelRatio); |
| 11422 | this.bindEvents(); |
| 11423 | this.notifyPlugins("afterInit"); |
| 11424 | return this; |
| 11425 | } |
| 11426 | }, |
| 11427 | { |
| 11428 | key: "clear", |
| 11429 | value: function clear() { |
| 11430 | (0, _helpersSegmentJs.ae)(this.canvas, this.ctx); |
| 11431 | return this; |
| 11432 | } |
| 11433 | }, |
| 11434 | { |
| 11435 | key: "stop", |
| 11436 | value: function stop() { |
| 11437 | animator.stop(this); |
| 11438 | return this; |
| 11439 | } |
| 11440 | }, |
| 11441 | { |
| 11442 | key: "resize", |
| 11443 | value: function resize(width, height) { |
| 11444 | if (!animator.running(this)) this._resize(width, height); |
| 11445 | else this._resizeBeforeDraw = { |
| 11446 | width: width, |
| 11447 | height: height |
| 11448 | }; |
| 11449 | } |
| 11450 | }, |
| 11451 | { |
| 11452 | key: "_resize", |
| 11453 | value: function _resize(width, height) { |
| 11454 | var options = this.options; |
| 11455 | var canvas = this.canvas; |
| 11456 | var aspectRatio = options.maintainAspectRatio && this.aspectRatio; |
| 11457 | var newSize = this.platform.getMaximumSize(canvas, width, height, aspectRatio); |
| 11458 | var newRatio = options.devicePixelRatio || this.platform.getDevicePixelRatio(); |
| 11459 | var mode = this.width ? "resize" : "attach"; |
| 11460 | this.width = newSize.width; |
| 11461 | this.height = newSize.height; |
| 11462 | this._aspectRatio = this.aspectRatio; |
| 11463 | if (!(0, _helpersSegmentJs.ad)(this, newRatio, true)) return; |
| 11464 | this.notifyPlugins("resize", { |
| 11465 | size: newSize |
| 11466 | }); |
| 11467 | (0, _helpersSegmentJs.Q)(options.onResize, [ |
| 11468 | this, |
| 11469 | newSize |
| 11470 | ], this); |
| 11471 | if (this.attached) { |
| 11472 | if (this._doResize(mode)) this.render(); |
| 11473 | } |
| 11474 | } |
| 11475 | }, |
| 11476 | { |
| 11477 | key: "ensureScalesHaveIDs", |
| 11478 | value: function ensureScalesHaveIDs() { |
| 11479 | var options = this.options; |
| 11480 | var scalesOptions = options.scales || {}; |
| 11481 | (0, _helpersSegmentJs.E)(scalesOptions, function(axisOptions, axisID) { |
| 11482 | axisOptions.id = axisID; |
| 11483 | }); |
| 11484 | } |
| 11485 | }, |
| 11486 | { |
| 11487 | key: "buildOrUpdateScales", |
| 11488 | value: function buildOrUpdateScales() { |
| 11489 | var _this = this; |
| 11490 | var options = this.options; |
| 11491 | var scaleOpts = options.scales; |
| 11492 | var scales4 = this.scales; |
| 11493 | var updated = Object.keys(scales4).reduce(function(obj, id) { |
| 11494 | obj[id] = false; |
| 11495 | return obj; |
| 11496 | }, {}); |
| 11497 | var items = []; |
| 11498 | if (scaleOpts) items = items.concat(Object.keys(scaleOpts).map(function(id) { |
| 11499 | var scaleOptions = scaleOpts[id]; |
| 11500 | var axis = determineAxis(id, scaleOptions); |
| 11501 | var isRadial = axis === "r"; |
| 11502 | var isHorizontal = axis === "x"; |
| 11503 | return { |
| 11504 | options: scaleOptions, |
| 11505 | dposition: isRadial ? "chartArea" : isHorizontal ? "bottom" : "left", |
| 11506 | dtype: isRadial ? "radialLinear" : isHorizontal ? "category" : "linear" |
| 11507 | }; |
| 11508 | })); |
| 11509 | (0, _helpersSegmentJs.E)(items, function(item) { |
| 11510 | var scaleOptions = item.options; |
| 11511 | var id = scaleOptions.id; |
| 11512 | var axis = determineAxis(id, scaleOptions); |
| 11513 | var scaleType = (0, _helpersSegmentJs.v)(scaleOptions.type, item.dtype); |
| 11514 | if (scaleOptions.position === undefined || positionIsHorizontal(scaleOptions.position, axis) !== positionIsHorizontal(item.dposition)) scaleOptions.position = item.dposition; |
| 11515 | updated[id] = true; |
| 11516 | var scale = null; |
| 11517 | if (id in scales4 && scales4[id].type === scaleType) scale = scales4[id]; |
| 11518 | else { |
| 11519 | var scaleClass = registry.getScale(scaleType); |
| 11520 | scale = new scaleClass({ |
| 11521 | id: id, |
| 11522 | type: scaleType, |
| 11523 | ctx: _this.ctx, |
| 11524 | chart: _this |
| 11525 | }); |
| 11526 | scales4[scale.id] = scale; |
| 11527 | } |
| 11528 | scale.init(scaleOptions, options); |
| 11529 | }); |
| 11530 | (0, _helpersSegmentJs.E)(updated, function(hasUpdated, id) { |
| 11531 | if (!hasUpdated) delete scales4[id]; |
| 11532 | }); |
| 11533 | (0, _helpersSegmentJs.E)(scales4, function(scale) { |
| 11534 | layouts.configure(_this, scale, scale.options); |
| 11535 | layouts.addBox(_this, scale); |
| 11536 | }); |
| 11537 | } |
| 11538 | }, |
| 11539 | { |
| 11540 | key: "_updateMetasets", |
| 11541 | value: function _updateMetasets() { |
| 11542 | var metasets = this._metasets; |
| 11543 | var numData = this.data.datasets.length; |
| 11544 | var numMeta = metasets.length; |
| 11545 | metasets.sort(function(a, b) { |
| 11546 | return a.index - b.index; |
| 11547 | }); |
| 11548 | if (numMeta > numData) { |
| 11549 | for(var i = numData; i < numMeta; ++i)this._destroyDatasetMeta(i); |
| 11550 | metasets.splice(numData, numMeta - numData); |
| 11551 | } |
| 11552 | this._sortedMetasets = metasets.slice(0).sort(compare2Level("order", "index")); |
| 11553 | } |
| 11554 | }, |
| 11555 | { |
| 11556 | key: "_removeUnreferencedMetasets", |
| 11557 | value: function _removeUnreferencedMetasets() { |
| 11558 | var _this = this; |
| 11559 | var ref = this, metasets = ref._metasets, datasets = ref.data.datasets; |
| 11560 | if (metasets.length > datasets.length) delete this._stacks; |
| 11561 | metasets.forEach(function(meta, index50) { |
| 11562 | if (datasets.filter(function(x) { |
| 11563 | return x === meta._dataset; |
| 11564 | }).length === 0) _this._destroyDatasetMeta(index50); |
| 11565 | }); |
| 11566 | } |
| 11567 | }, |
| 11568 | { |
| 11569 | key: "buildOrUpdateControllers", |
| 11570 | value: function buildOrUpdateControllers() { |
| 11571 | var newControllers = []; |
| 11572 | var datasets = this.data.datasets; |
| 11573 | var i, ilen; |
| 11574 | this._removeUnreferencedMetasets(); |
| 11575 | for(i = 0, ilen = datasets.length; i < ilen; i++){ |
| 11576 | var dataset = datasets[i]; |
| 11577 | var meta = this.getDatasetMeta(i); |
| 11578 | var type = dataset.type || this.config.type; |
| 11579 | if (meta.type && meta.type !== type) { |
| 11580 | this._destroyDatasetMeta(i); |
| 11581 | meta = this.getDatasetMeta(i); |
| 11582 | } |
| 11583 | meta.type = type; |
| 11584 | meta.indexAxis = dataset.indexAxis || getIndexAxis(type, this.options); |
| 11585 | meta.order = dataset.order || 0; |
| 11586 | meta.index = i; |
| 11587 | meta.label = "" + dataset.label; |
| 11588 | meta.visible = this.isDatasetVisible(i); |
| 11589 | if (meta.controller) { |
| 11590 | meta.controller.updateIndex(i); |
| 11591 | meta.controller.linkScales(); |
| 11592 | } else { |
| 11593 | var ControllerClass = registry.getController(type); |
| 11594 | var _type = (0, _helpersSegmentJs.d).datasets[type], datasetElementType = _type.datasetElementType, dataElementType = _type.dataElementType; |
| 11595 | Object.assign(ControllerClass.prototype, { |
| 11596 | dataElementType: registry.getElement(dataElementType), |
| 11597 | datasetElementType: datasetElementType && registry.getElement(datasetElementType) |
| 11598 | }); |
| 11599 | meta.controller = new ControllerClass(this, i); |
| 11600 | newControllers.push(meta.controller); |
| 11601 | } |
| 11602 | } |
| 11603 | this._updateMetasets(); |
| 11604 | return newControllers; |
| 11605 | } |
| 11606 | }, |
| 11607 | { |
| 11608 | key: "_resetElements", |
| 11609 | value: function _resetElements() { |
| 11610 | var _this = this; |
| 11611 | (0, _helpersSegmentJs.E)(this.data.datasets, function(dataset, datasetIndex) { |
| 11612 | _this.getDatasetMeta(datasetIndex).controller.reset(); |
| 11613 | }, this); |
| 11614 | } |
| 11615 | }, |
| 11616 | { |
| 11617 | key: "reset", |
| 11618 | value: function reset() { |
| 11619 | this._resetElements(); |
| 11620 | this.notifyPlugins("reset"); |
| 11621 | } |
| 11622 | }, |
| 11623 | { |
| 11624 | key: "update", |
| 11625 | value: function update(mode) { |
| 11626 | var config = this.config; |
| 11627 | config.update(); |
| 11628 | var options = this._options = config.createResolver(config.chartOptionScopes(), this.getContext()); |
| 11629 | var animsDisabled = this._animationsDisabled = !options.animation; |
| 11630 | this._updateScales(); |
| 11631 | this._checkEventBindings(); |
| 11632 | this._updateHiddenIndices(); |
| 11633 | this._plugins.invalidate(); |
| 11634 | if (this.notifyPlugins("beforeUpdate", { |
| 11635 | mode: mode, |
| 11636 | cancelable: true |
| 11637 | }) === false) return; |
| 11638 | var newControllers = this.buildOrUpdateControllers(); |
| 11639 | this.notifyPlugins("beforeElementsUpdate"); |
| 11640 | var minPadding = 0; |
| 11641 | for(var i = 0, ilen = this.data.datasets.length; i < ilen; i++){ |
| 11642 | var controller = this.getDatasetMeta(i).controller; |
| 11643 | var reset = !animsDisabled && newControllers.indexOf(controller) === -1; |
| 11644 | controller.buildOrUpdateElements(reset); |
| 11645 | minPadding = Math.max(+controller.getMaxOverflow(), minPadding); |
| 11646 | } |
| 11647 | minPadding = this._minPadding = options.layout.autoPadding ? minPadding : 0; |
| 11648 | this._updateLayout(minPadding); |
| 11649 | if (!animsDisabled) (0, _helpersSegmentJs.E)(newControllers, function(controller) { |
| 11650 | controller.reset(); |
| 11651 | }); |
| 11652 | this._updateDatasets(mode); |
| 11653 | this.notifyPlugins("afterUpdate", { |
| 11654 | mode: mode |
| 11655 | }); |
| 11656 | this._layers.sort(compare2Level("z", "_idx")); |
| 11657 | var ref = this, _active = ref._active, _lastEvent = ref._lastEvent; |
| 11658 | if (_lastEvent) this._eventHandler(_lastEvent, true); |
| 11659 | else if (_active.length) this._updateHoverStyles(_active, _active, true); |
| 11660 | this.render(); |
| 11661 | } |
| 11662 | }, |
| 11663 | { |
| 11664 | key: "_updateScales", |
| 11665 | value: function _updateScales() { |
| 11666 | var _this = this; |
| 11667 | (0, _helpersSegmentJs.E)(this.scales, function(scale) { |
| 11668 | layouts.removeBox(_this, scale); |
| 11669 | }); |
| 11670 | this.ensureScalesHaveIDs(); |
| 11671 | this.buildOrUpdateScales(); |
| 11672 | } |
| 11673 | }, |
| 11674 | { |
| 11675 | key: "_checkEventBindings", |
| 11676 | value: function _checkEventBindings() { |
| 11677 | var options = this.options; |
| 11678 | var existingEvents = new Set(Object.keys(this._listeners)); |
| 11679 | var newEvents = new Set(options.events); |
| 11680 | if (!(0, _helpersSegmentJs.af)(existingEvents, newEvents) || !!this._responsiveListeners !== options.responsive) { |
| 11681 | this.unbindEvents(); |
| 11682 | this.bindEvents(); |
| 11683 | } |
| 11684 | } |
| 11685 | }, |
| 11686 | { |
| 11687 | key: "_updateHiddenIndices", |
| 11688 | value: function _updateHiddenIndices() { |
| 11689 | var _hiddenIndices = this._hiddenIndices; |
| 11690 | var changes = this._getUniformDataChanges() || []; |
| 11691 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 11692 | try { |
| 11693 | for(var _iterator = changes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 11694 | var _value = _step.value, method = _value.method, start = _value.start, count = _value.count; |
| 11695 | var move = method === "_removeElements" ? -count : count; |
| 11696 | moveNumericKeys(_hiddenIndices, start, move); |
| 11697 | } |
| 11698 | } catch (err) { |
| 11699 | _didIteratorError = true; |
| 11700 | _iteratorError = err; |
| 11701 | } finally{ |
| 11702 | try { |
| 11703 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 11704 | _iterator.return(); |
| 11705 | } |
| 11706 | } finally{ |
| 11707 | if (_didIteratorError) { |
| 11708 | throw _iteratorError; |
| 11709 | } |
| 11710 | } |
| 11711 | } |
| 11712 | } |
| 11713 | }, |
| 11714 | { |
| 11715 | key: "_getUniformDataChanges", |
| 11716 | value: function _getUniformDataChanges() { |
| 11717 | var _dataChanges = this._dataChanges; |
| 11718 | if (!_dataChanges || !_dataChanges.length) return; |
| 11719 | this._dataChanges = []; |
| 11720 | var datasetCount = this.data.datasets.length; |
| 11721 | var makeSet = function(idx) { |
| 11722 | return new Set(_dataChanges.filter(function(c) { |
| 11723 | return c[0] === idx; |
| 11724 | }).map(function(c, i) { |
| 11725 | return i + "," + c.splice(1).join(","); |
| 11726 | })); |
| 11727 | }; |
| 11728 | var changeSet = makeSet(0); |
| 11729 | for(var i4 = 1; i4 < datasetCount; i4++){ |
| 11730 | if (!(0, _helpersSegmentJs.af)(changeSet, makeSet(i4))) return; |
| 11731 | } |
| 11732 | return Array.from(changeSet).map(function(c) { |
| 11733 | return c.split(","); |
| 11734 | }).map(function(a) { |
| 11735 | return { |
| 11736 | method: a[1], |
| 11737 | start: +a[2], |
| 11738 | count: +a[3] |
| 11739 | }; |
| 11740 | }); |
| 11741 | } |
| 11742 | }, |
| 11743 | { |
| 11744 | key: "_updateLayout", |
| 11745 | value: function _updateLayout(minPadding) { |
| 11746 | var _this = this; |
| 11747 | if (this.notifyPlugins("beforeLayout", { |
| 11748 | cancelable: true |
| 11749 | }) === false) return; |
| 11750 | layouts.update(this, this.width, this.height, minPadding); |
| 11751 | var area = this.chartArea; |
| 11752 | var noArea = area.width <= 0 || area.height <= 0; |
| 11753 | this._layers = []; |
| 11754 | (0, _helpersSegmentJs.E)(this.boxes, function(box) { |
| 11755 | var __layers; |
| 11756 | if (noArea && box.position === "chartArea") return; |
| 11757 | if (box.configure) box.configure(); |
| 11758 | (__layers = _this._layers).push.apply(__layers, (0, _toConsumableArrayJsDefault.default)(box._layers())); |
| 11759 | }, this); |
| 11760 | this._layers.forEach(function(item, index51) { |
| 11761 | item._idx = index51; |
| 11762 | }); |
| 11763 | this.notifyPlugins("afterLayout"); |
| 11764 | } |
| 11765 | }, |
| 11766 | { |
| 11767 | key: "_updateDatasets", |
| 11768 | value: function _updateDatasets(mode) { |
| 11769 | if (this.notifyPlugins("beforeDatasetsUpdate", { |
| 11770 | mode: mode, |
| 11771 | cancelable: true |
| 11772 | }) === false) return; |
| 11773 | for(var i = 0, ilen = this.data.datasets.length; i < ilen; ++i)this.getDatasetMeta(i).controller.configure(); |
| 11774 | for(var i5 = 0, ilen1 = this.data.datasets.length; i5 < ilen1; ++i5)this._updateDataset(i5, (0, _helpersSegmentJs.a6)(mode) ? mode({ |
| 11775 | datasetIndex: i5 |
| 11776 | }) : mode); |
| 11777 | this.notifyPlugins("afterDatasetsUpdate", { |
| 11778 | mode: mode |
| 11779 | }); |
| 11780 | } |
| 11781 | }, |
| 11782 | { |
| 11783 | key: "_updateDataset", |
| 11784 | value: function _updateDataset(index52, mode) { |
| 11785 | var meta = this.getDatasetMeta(index52); |
| 11786 | var args = { |
| 11787 | meta: meta, |
| 11788 | index: index52, |
| 11789 | mode: mode, |
| 11790 | cancelable: true |
| 11791 | }; |
| 11792 | if (this.notifyPlugins("beforeDatasetUpdate", args) === false) return; |
| 11793 | meta.controller._update(mode); |
| 11794 | args.cancelable = false; |
| 11795 | this.notifyPlugins("afterDatasetUpdate", args); |
| 11796 | } |
| 11797 | }, |
| 11798 | { |
| 11799 | key: "render", |
| 11800 | value: function render() { |
| 11801 | if (this.notifyPlugins("beforeRender", { |
| 11802 | cancelable: true |
| 11803 | }) === false) return; |
| 11804 | if (animator.has(this)) { |
| 11805 | if (this.attached && !animator.running(this)) animator.start(this); |
| 11806 | } else { |
| 11807 | this.draw(); |
| 11808 | onAnimationsComplete({ |
| 11809 | chart: this |
| 11810 | }); |
| 11811 | } |
| 11812 | } |
| 11813 | }, |
| 11814 | { |
| 11815 | key: "draw", |
| 11816 | value: function draw2() { |
| 11817 | var i; |
| 11818 | if (this._resizeBeforeDraw) { |
| 11819 | var __resizeBeforeDraw = this._resizeBeforeDraw, width = __resizeBeforeDraw.width, height = __resizeBeforeDraw.height; |
| 11820 | this._resize(width, height); |
| 11821 | this._resizeBeforeDraw = null; |
| 11822 | } |
| 11823 | this.clear(); |
| 11824 | if (this.width <= 0 || this.height <= 0) return; |
| 11825 | if (this.notifyPlugins("beforeDraw", { |
| 11826 | cancelable: true |
| 11827 | }) === false) return; |
| 11828 | var layers = this._layers; |
| 11829 | for(i = 0; i < layers.length && layers[i].z <= 0; ++i)layers[i].draw(this.chartArea); |
| 11830 | this._drawDatasets(); |
| 11831 | for(; i < layers.length; ++i)layers[i].draw(this.chartArea); |
| 11832 | this.notifyPlugins("afterDraw"); |
| 11833 | } |
| 11834 | }, |
| 11835 | { |
| 11836 | key: "_getSortedDatasetMetas", |
| 11837 | value: function _getSortedDatasetMetas(filterVisible) { |
| 11838 | var metasets = this._sortedMetasets; |
| 11839 | var result = []; |
| 11840 | var i, ilen; |
| 11841 | for(i = 0, ilen = metasets.length; i < ilen; ++i){ |
| 11842 | var meta = metasets[i]; |
| 11843 | if (!filterVisible || meta.visible) result.push(meta); |
| 11844 | } |
| 11845 | return result; |
| 11846 | } |
| 11847 | }, |
| 11848 | { |
| 11849 | key: "getSortedVisibleDatasetMetas", |
| 11850 | value: function getSortedVisibleDatasetMetas() { |
| 11851 | return this._getSortedDatasetMetas(true); |
| 11852 | } |
| 11853 | }, |
| 11854 | { |
| 11855 | key: "_drawDatasets", |
| 11856 | value: function _drawDatasets() { |
| 11857 | if (this.notifyPlugins("beforeDatasetsDraw", { |
| 11858 | cancelable: true |
| 11859 | }) === false) return; |
| 11860 | var metasets = this.getSortedVisibleDatasetMetas(); |
| 11861 | for(var i = metasets.length - 1; i >= 0; --i)this._drawDataset(metasets[i]); |
| 11862 | this.notifyPlugins("afterDatasetsDraw"); |
| 11863 | } |
| 11864 | }, |
| 11865 | { |
| 11866 | key: "_drawDataset", |
| 11867 | value: function _drawDataset(meta) { |
| 11868 | var ctx = this.ctx; |
| 11869 | var clip = meta._clip; |
| 11870 | var useClip = !clip.disabled; |
| 11871 | var area = this.chartArea; |
| 11872 | var args = { |
| 11873 | meta: meta, |
| 11874 | index: meta.index, |
| 11875 | cancelable: true |
| 11876 | }; |
| 11877 | if (this.notifyPlugins("beforeDatasetDraw", args) === false) return; |
| 11878 | if (useClip) (0, _helpersSegmentJs.X)(ctx, { |
| 11879 | left: clip.left === false ? 0 : area.left - clip.left, |
| 11880 | right: clip.right === false ? this.width : area.right + clip.right, |
| 11881 | top: clip.top === false ? 0 : area.top - clip.top, |
| 11882 | bottom: clip.bottom === false ? this.height : area.bottom + clip.bottom |
| 11883 | }); |
| 11884 | meta.controller.draw(); |
| 11885 | if (useClip) (0, _helpersSegmentJs.Z)(ctx); |
| 11886 | args.cancelable = false; |
| 11887 | this.notifyPlugins("afterDatasetDraw", args); |
| 11888 | } |
| 11889 | }, |
| 11890 | { |
| 11891 | key: "isPointInArea", |
| 11892 | value: function isPointInArea(point) { |
| 11893 | return (0, _helpersSegmentJs.B)(point, this.chartArea, this._minPadding); |
| 11894 | } |
| 11895 | }, |
| 11896 | { |
| 11897 | key: "getElementsAtEventForMode", |
| 11898 | value: function getElementsAtEventForMode(e, mode, options, useFinalPosition) { |
| 11899 | var method = Interaction.modes[mode]; |
| 11900 | if (typeof method === "function") return method(this, e, options, useFinalPosition); |
| 11901 | return []; |
| 11902 | } |
| 11903 | }, |
| 11904 | { |
| 11905 | key: "getDatasetMeta", |
| 11906 | value: function getDatasetMeta(datasetIndex) { |
| 11907 | var dataset = this.data.datasets[datasetIndex]; |
| 11908 | var metasets = this._metasets; |
| 11909 | var meta = metasets.filter(function(x) { |
| 11910 | return x && x._dataset === dataset; |
| 11911 | }).pop(); |
| 11912 | if (!meta) { |
| 11913 | meta = { |
| 11914 | type: null, |
| 11915 | data: [], |
| 11916 | dataset: null, |
| 11917 | controller: null, |
| 11918 | hidden: null, |
| 11919 | xAxisID: null, |
| 11920 | yAxisID: null, |
| 11921 | order: dataset && dataset.order || 0, |
| 11922 | index: datasetIndex, |
| 11923 | _dataset: dataset, |
| 11924 | _parsed: [], |
| 11925 | _sorted: false |
| 11926 | }; |
| 11927 | metasets.push(meta); |
| 11928 | } |
| 11929 | return meta; |
| 11930 | } |
| 11931 | }, |
| 11932 | { |
| 11933 | key: "getContext", |
| 11934 | value: function getContext() { |
| 11935 | return this.$context || (this.$context = (0, _helpersSegmentJs.h)(null, { |
| 11936 | chart: this, |
| 11937 | type: "chart" |
| 11938 | })); |
| 11939 | } |
| 11940 | }, |
| 11941 | { |
| 11942 | key: "getVisibleDatasetCount", |
| 11943 | value: function getVisibleDatasetCount() { |
| 11944 | return this.getSortedVisibleDatasetMetas().length; |
| 11945 | } |
| 11946 | }, |
| 11947 | { |
| 11948 | key: "isDatasetVisible", |
| 11949 | value: function isDatasetVisible(datasetIndex) { |
| 11950 | var dataset = this.data.datasets[datasetIndex]; |
| 11951 | if (!dataset) return false; |
| 11952 | var meta = this.getDatasetMeta(datasetIndex); |
| 11953 | return typeof meta.hidden === "boolean" ? !meta.hidden : !dataset.hidden; |
| 11954 | } |
| 11955 | }, |
| 11956 | { |
| 11957 | key: "setDatasetVisibility", |
| 11958 | value: function setDatasetVisibility(datasetIndex, visible) { |
| 11959 | var meta = this.getDatasetMeta(datasetIndex); |
| 11960 | meta.hidden = !visible; |
| 11961 | } |
| 11962 | }, |
| 11963 | { |
| 11964 | key: "toggleDataVisibility", |
| 11965 | value: function toggleDataVisibility(index53) { |
| 11966 | this._hiddenIndices[index53] = !this._hiddenIndices[index53]; |
| 11967 | } |
| 11968 | }, |
| 11969 | { |
| 11970 | key: "getDataVisibility", |
| 11971 | value: function getDataVisibility(index54) { |
| 11972 | return !this._hiddenIndices[index54]; |
| 11973 | } |
| 11974 | }, |
| 11975 | { |
| 11976 | key: "_updateVisibility", |
| 11977 | value: function _updateVisibility(datasetIndex, dataIndex, visible) { |
| 11978 | var mode = visible ? "show" : "hide"; |
| 11979 | var meta = this.getDatasetMeta(datasetIndex); |
| 11980 | var anims = meta.controller._resolveAnimations(undefined, mode); |
| 11981 | if ((0, _helpersSegmentJs.j)(dataIndex)) { |
| 11982 | meta.data[dataIndex].hidden = !visible; |
| 11983 | this.update(); |
| 11984 | } else { |
| 11985 | this.setDatasetVisibility(datasetIndex, visible); |
| 11986 | anims.update(meta, { |
| 11987 | visible: visible |
| 11988 | }); |
| 11989 | this.update(function(ctx) { |
| 11990 | return ctx.datasetIndex === datasetIndex ? mode : undefined; |
| 11991 | }); |
| 11992 | } |
| 11993 | } |
| 11994 | }, |
| 11995 | { |
| 11996 | key: "hide", |
| 11997 | value: function hide(datasetIndex, dataIndex) { |
| 11998 | this._updateVisibility(datasetIndex, dataIndex, false); |
| 11999 | } |
| 12000 | }, |
| 12001 | { |
| 12002 | key: "show", |
| 12003 | value: function show(datasetIndex, dataIndex) { |
| 12004 | this._updateVisibility(datasetIndex, dataIndex, true); |
| 12005 | } |
| 12006 | }, |
| 12007 | { |
| 12008 | key: "_destroyDatasetMeta", |
| 12009 | value: function _destroyDatasetMeta(datasetIndex) { |
| 12010 | var meta = this._metasets[datasetIndex]; |
| 12011 | if (meta && meta.controller) meta.controller._destroy(); |
| 12012 | delete this._metasets[datasetIndex]; |
| 12013 | } |
| 12014 | }, |
| 12015 | { |
| 12016 | key: "_stop", |
| 12017 | value: function _stop() { |
| 12018 | var i, ilen; |
| 12019 | this.stop(); |
| 12020 | animator.remove(this); |
| 12021 | for(i = 0, ilen = this.data.datasets.length; i < ilen; ++i)this._destroyDatasetMeta(i); |
| 12022 | } |
| 12023 | }, |
| 12024 | { |
| 12025 | key: "destroy", |
| 12026 | value: function destroy() { |
| 12027 | this.notifyPlugins("beforeDestroy"); |
| 12028 | var ref = this, canvas = ref.canvas, ctx = ref.ctx; |
| 12029 | this._stop(); |
| 12030 | this.config.clearCache(); |
| 12031 | if (canvas) { |
| 12032 | this.unbindEvents(); |
| 12033 | (0, _helpersSegmentJs.ae)(canvas, ctx); |
| 12034 | this.platform.releaseContext(ctx); |
| 12035 | this.canvas = null; |
| 12036 | this.ctx = null; |
| 12037 | } |
| 12038 | this.notifyPlugins("destroy"); |
| 12039 | delete instances[this.id]; |
| 12040 | this.notifyPlugins("afterDestroy"); |
| 12041 | } |
| 12042 | }, |
| 12043 | { |
| 12044 | key: "toBase64Image", |
| 12045 | value: function toBase64Image() { |
| 12046 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 12047 | args[_key] = arguments[_key]; |
| 12048 | } |
| 12049 | var _canvas; |
| 12050 | return (_canvas = this.canvas).toDataURL.apply(_canvas, (0, _toConsumableArrayJsDefault.default)(args)); |
| 12051 | } |
| 12052 | }, |
| 12053 | { |
| 12054 | key: "bindEvents", |
| 12055 | value: function bindEvents() { |
| 12056 | this.bindUserEvents(); |
| 12057 | if (this.options.responsive) this.bindResponsiveEvents(); |
| 12058 | else this.attached = true; |
| 12059 | } |
| 12060 | }, |
| 12061 | { |
| 12062 | key: "bindUserEvents", |
| 12063 | value: function bindUserEvents() { |
| 12064 | var _this = this; |
| 12065 | var listeners = this._listeners; |
| 12066 | var platform = this.platform; |
| 12067 | var _add = function(type, listener) { |
| 12068 | platform.addEventListener(_this, type, listener); |
| 12069 | listeners[type] = listener; |
| 12070 | }; |
| 12071 | var listener1 = function(e, x, y) { |
| 12072 | e.offsetX = x; |
| 12073 | e.offsetY = y; |
| 12074 | _this._eventHandler(e); |
| 12075 | }; |
| 12076 | (0, _helpersSegmentJs.E)(this.options.events, function(type) { |
| 12077 | return _add(type, listener1); |
| 12078 | }); |
| 12079 | } |
| 12080 | }, |
| 12081 | { |
| 12082 | key: "bindResponsiveEvents", |
| 12083 | value: function bindResponsiveEvents() { |
| 12084 | var _this = this; |
| 12085 | if (!this._responsiveListeners) this._responsiveListeners = {}; |
| 12086 | var listeners = this._responsiveListeners; |
| 12087 | var platform = this.platform; |
| 12088 | var _add = function(type, listener) { |
| 12089 | platform.addEventListener(_this, type, listener); |
| 12090 | listeners[type] = listener; |
| 12091 | }; |
| 12092 | var _remove = function(type, listener) { |
| 12093 | if (listeners[type]) { |
| 12094 | platform.removeEventListener(_this, type, listener); |
| 12095 | delete listeners[type]; |
| 12096 | } |
| 12097 | }; |
| 12098 | var listener2 = function(width, height) { |
| 12099 | if (_this.canvas) _this.resize(width, height); |
| 12100 | }; |
| 12101 | var detached; |
| 12102 | var attached = function() { |
| 12103 | _remove("attach", attached); |
| 12104 | _this.attached = true; |
| 12105 | _this.resize(); |
| 12106 | _add("resize", listener2); |
| 12107 | _add("detach", detached); |
| 12108 | }; |
| 12109 | detached = function() { |
| 12110 | _this.attached = false; |
| 12111 | _remove("resize", listener2); |
| 12112 | _this._stop(); |
| 12113 | _this._resize(0, 0); |
| 12114 | _add("attach", attached); |
| 12115 | }; |
| 12116 | if (platform.isAttached(this.canvas)) attached(); |
| 12117 | else detached(); |
| 12118 | } |
| 12119 | }, |
| 12120 | { |
| 12121 | key: "unbindEvents", |
| 12122 | value: function unbindEvents() { |
| 12123 | var _this = this; |
| 12124 | (0, _helpersSegmentJs.E)(this._listeners, function(listener, type) { |
| 12125 | _this.platform.removeEventListener(_this, type, listener); |
| 12126 | }); |
| 12127 | this._listeners = {}; |
| 12128 | (0, _helpersSegmentJs.E)(this._responsiveListeners, function(listener, type) { |
| 12129 | _this.platform.removeEventListener(_this, type, listener); |
| 12130 | }); |
| 12131 | this._responsiveListeners = undefined; |
| 12132 | } |
| 12133 | }, |
| 12134 | { |
| 12135 | key: "updateHoverStyle", |
| 12136 | value: function updateHoverStyle(items, mode, enabled) { |
| 12137 | var prefix = enabled ? "set" : "remove"; |
| 12138 | var meta, item, i, ilen; |
| 12139 | if (mode === "dataset") { |
| 12140 | meta = this.getDatasetMeta(items[0].datasetIndex); |
| 12141 | meta.controller["_" + prefix + "DatasetHoverStyle"](); |
| 12142 | } |
| 12143 | for(i = 0, ilen = items.length; i < ilen; ++i){ |
| 12144 | item = items[i]; |
| 12145 | var controller = item && this.getDatasetMeta(item.datasetIndex).controller; |
| 12146 | if (controller) controller[prefix + "HoverStyle"](item.element, item.datasetIndex, item.index); |
| 12147 | } |
| 12148 | } |
| 12149 | }, |
| 12150 | { |
| 12151 | key: "getActiveElements", |
| 12152 | value: function getActiveElements() { |
| 12153 | return this._active || []; |
| 12154 | } |
| 12155 | }, |
| 12156 | { |
| 12157 | key: "setActiveElements", |
| 12158 | value: function setActiveElements(activeElements) { |
| 12159 | var _this = this; |
| 12160 | var lastActive = this._active || []; |
| 12161 | var active = activeElements.map(function(param) { |
| 12162 | var datasetIndex = param.datasetIndex, index55 = param.index; |
| 12163 | var meta = _this.getDatasetMeta(datasetIndex); |
| 12164 | if (!meta) throw new Error("No dataset found at index " + datasetIndex); |
| 12165 | return { |
| 12166 | datasetIndex: datasetIndex, |
| 12167 | element: meta.data[index55], |
| 12168 | index: index55 |
| 12169 | }; |
| 12170 | }); |
| 12171 | var changed = !(0, _helpersSegmentJs.ag)(active, lastActive); |
| 12172 | if (changed) { |
| 12173 | this._active = active; |
| 12174 | this._lastEvent = null; |
| 12175 | this._updateHoverStyles(active, lastActive); |
| 12176 | } |
| 12177 | } |
| 12178 | }, |
| 12179 | { |
| 12180 | key: "notifyPlugins", |
| 12181 | value: function notifyPlugins(hook, args, filter) { |
| 12182 | return this._plugins.notify(this, hook, args, filter); |
| 12183 | } |
| 12184 | }, |
| 12185 | { |
| 12186 | key: "_updateHoverStyles", |
| 12187 | value: function _updateHoverStyles(active, lastActive, replay) { |
| 12188 | var hoverOptions = this.options.hover; |
| 12189 | var diff = function(a, b) { |
| 12190 | return a.filter(function(x) { |
| 12191 | return !b.some(function(y) { |
| 12192 | return x.datasetIndex === y.datasetIndex && x.index === y.index; |
| 12193 | }); |
| 12194 | }); |
| 12195 | }; |
| 12196 | var deactivated = diff(lastActive, active); |
| 12197 | var activated = replay ? active : diff(active, lastActive); |
| 12198 | if (deactivated.length) this.updateHoverStyle(deactivated, hoverOptions.mode, false); |
| 12199 | if (activated.length && hoverOptions.mode) this.updateHoverStyle(activated, hoverOptions.mode, true); |
| 12200 | } |
| 12201 | }, |
| 12202 | { |
| 12203 | key: "_eventHandler", |
| 12204 | value: function _eventHandler(e, replay) { |
| 12205 | var _this = this; |
| 12206 | var args = { |
| 12207 | event: e, |
| 12208 | replay: replay, |
| 12209 | cancelable: true, |
| 12210 | inChartArea: this.isPointInArea(e) |
| 12211 | }; |
| 12212 | var eventFilter = function(plugin) { |
| 12213 | return (plugin.options.events || _this.options.events).includes(e.native.type); |
| 12214 | }; |
| 12215 | if (this.notifyPlugins("beforeEvent", args, eventFilter) === false) return; |
| 12216 | var changed = this._handleEvent(e, replay, args.inChartArea); |
| 12217 | args.cancelable = false; |
| 12218 | this.notifyPlugins("afterEvent", args, eventFilter); |
| 12219 | if (changed || args.changed) this.render(); |
| 12220 | return this; |
| 12221 | } |
| 12222 | }, |
| 12223 | { |
| 12224 | key: "_handleEvent", |
| 12225 | value: function _handleEvent(e, replay, inChartArea) { |
| 12226 | var ref = this, tmp = ref._active, lastActive = tmp === void 0 ? [] : tmp, options = ref.options; |
| 12227 | var useFinalPosition = replay; |
| 12228 | var active = this._getActiveElements(e, lastActive, inChartArea, useFinalPosition); |
| 12229 | var isClick = (0, _helpersSegmentJs.ah)(e); |
| 12230 | var lastEvent = determineLastEvent(e, this._lastEvent, inChartArea, isClick); |
| 12231 | if (inChartArea) { |
| 12232 | this._lastEvent = null; |
| 12233 | (0, _helpersSegmentJs.Q)(options.onHover, [ |
| 12234 | e, |
| 12235 | active, |
| 12236 | this |
| 12237 | ], this); |
| 12238 | if (isClick) (0, _helpersSegmentJs.Q)(options.onClick, [ |
| 12239 | e, |
| 12240 | active, |
| 12241 | this |
| 12242 | ], this); |
| 12243 | } |
| 12244 | var changed = !(0, _helpersSegmentJs.ag)(active, lastActive); |
| 12245 | if (changed || replay) { |
| 12246 | this._active = active; |
| 12247 | this._updateHoverStyles(active, lastActive, replay); |
| 12248 | } |
| 12249 | this._lastEvent = lastEvent; |
| 12250 | return changed; |
| 12251 | } |
| 12252 | }, |
| 12253 | { |
| 12254 | key: "_getActiveElements", |
| 12255 | value: function _getActiveElements(e, lastActive, inChartArea, useFinalPosition) { |
| 12256 | if (e.type === "mouseout") return []; |
| 12257 | if (!inChartArea) return lastActive; |
| 12258 | var hoverOptions = this.options.hover; |
| 12259 | return this.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions, useFinalPosition); |
| 12260 | } |
| 12261 | } |
| 12262 | ]); |
| 12263 | return Chart; |
| 12264 | }(); |
| 12265 | var invalidatePlugins = function() { |
| 12266 | return (0, _helpersSegmentJs.E)(Chart.instances, function(chart) { |
| 12267 | return chart._plugins.invalidate(); |
| 12268 | }); |
| 12269 | }; |
| 12270 | var enumerable = true; |
| 12271 | Object.defineProperties(Chart, { |
| 12272 | defaults: { |
| 12273 | enumerable: enumerable, |
| 12274 | value: (0, _helpersSegmentJs.d) |
| 12275 | }, |
| 12276 | instances: { |
| 12277 | enumerable: enumerable, |
| 12278 | value: instances |
| 12279 | }, |
| 12280 | overrides: { |
| 12281 | enumerable: enumerable, |
| 12282 | value: (0, _helpersSegmentJs.a2) |
| 12283 | }, |
| 12284 | registry: { |
| 12285 | enumerable: enumerable, |
| 12286 | value: registry |
| 12287 | }, |
| 12288 | version: { |
| 12289 | enumerable: enumerable, |
| 12290 | value: version |
| 12291 | }, |
| 12292 | getChart: { |
| 12293 | enumerable: enumerable, |
| 12294 | value: getChart |
| 12295 | }, |
| 12296 | register: { |
| 12297 | enumerable: enumerable, |
| 12298 | value: function() { |
| 12299 | for(var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++){ |
| 12300 | items[_key] = arguments[_key]; |
| 12301 | } |
| 12302 | var _registry; |
| 12303 | (_registry = registry).add.apply(_registry, (0, _toConsumableArrayJsDefault.default)(items)); |
| 12304 | invalidatePlugins(); |
| 12305 | } |
| 12306 | }, |
| 12307 | unregister: { |
| 12308 | enumerable: enumerable, |
| 12309 | value: function() { |
| 12310 | for(var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++){ |
| 12311 | items[_key] = arguments[_key]; |
| 12312 | } |
| 12313 | var _registry; |
| 12314 | (_registry = registry).remove.apply(_registry, (0, _toConsumableArrayJsDefault.default)(items)); |
| 12315 | invalidatePlugins(); |
| 12316 | } |
| 12317 | } |
| 12318 | }); |
| 12319 | function clipArc(ctx, element, endAngle) { |
| 12320 | var startAngle = element.startAngle, pixelMargin = element.pixelMargin, x = element.x, y = element.y, outerRadius = element.outerRadius, innerRadius = element.innerRadius; |
| 12321 | var angleMargin = pixelMargin / outerRadius; |
| 12322 | ctx.beginPath(); |
| 12323 | ctx.arc(x, y, outerRadius, startAngle - angleMargin, endAngle + angleMargin); |
| 12324 | if (innerRadius > pixelMargin) { |
| 12325 | angleMargin = pixelMargin / innerRadius; |
| 12326 | ctx.arc(x, y, innerRadius, endAngle + angleMargin, startAngle - angleMargin, true); |
| 12327 | } else ctx.arc(x, y, pixelMargin, endAngle + (0, _helpersSegmentJs.H), startAngle - (0, _helpersSegmentJs.H)); |
| 12328 | ctx.closePath(); |
| 12329 | ctx.clip(); |
| 12330 | } |
| 12331 | function toRadiusCorners(value) { |
| 12332 | return (0, _helpersSegmentJs.aj)(value, [ |
| 12333 | "outerStart", |
| 12334 | "outerEnd", |
| 12335 | "innerStart", |
| 12336 | "innerEnd" |
| 12337 | ]); |
| 12338 | } |
| 12339 | function parseBorderRadius$1(arc, innerRadius, outerRadius, angleDelta) { |
| 12340 | var o = toRadiusCorners(arc.options.borderRadius); |
| 12341 | var halfThickness = (outerRadius - innerRadius) / 2; |
| 12342 | var innerLimit = Math.min(halfThickness, angleDelta * innerRadius / 2); |
| 12343 | var computeOuterLimit = function(val) { |
| 12344 | var outerArcLimit = (outerRadius - Math.min(halfThickness, val)) * angleDelta / 2; |
| 12345 | return (0, _helpersSegmentJs.w)(val, 0, Math.min(halfThickness, outerArcLimit)); |
| 12346 | }; |
| 12347 | return { |
| 12348 | outerStart: computeOuterLimit(o.outerStart), |
| 12349 | outerEnd: computeOuterLimit(o.outerEnd), |
| 12350 | innerStart: (0, _helpersSegmentJs.w)(o.innerStart, 0, innerLimit), |
| 12351 | innerEnd: (0, _helpersSegmentJs.w)(o.innerEnd, 0, innerLimit) |
| 12352 | }; |
| 12353 | } |
| 12354 | function rThetaToXY(r, theta, x, y) { |
| 12355 | return { |
| 12356 | x: x + r * Math.cos(theta), |
| 12357 | y: y + r * Math.sin(theta) |
| 12358 | }; |
| 12359 | } |
| 12360 | function pathArc(ctx, element, offset, spacing, end) { |
| 12361 | var x = element.x, y = element.y, start = element.startAngle, pixelMargin = element.pixelMargin, innerR = element.innerRadius; |
| 12362 | var outerRadius = Math.max(element.outerRadius + spacing + offset - pixelMargin, 0); |
| 12363 | var innerRadius = innerR > 0 ? innerR + spacing + offset + pixelMargin : 0; |
| 12364 | var spacingOffset = 0; |
| 12365 | var alpha = end - start; |
| 12366 | if (spacing) { |
| 12367 | var noSpacingInnerRadius = innerR > 0 ? innerR - spacing : 0; |
| 12368 | var noSpacingOuterRadius = outerRadius > 0 ? outerRadius - spacing : 0; |
| 12369 | var avNogSpacingRadius = (noSpacingInnerRadius + noSpacingOuterRadius) / 2; |
| 12370 | var adjustedAngle = avNogSpacingRadius !== 0 ? alpha * avNogSpacingRadius / (avNogSpacingRadius + spacing) : alpha; |
| 12371 | spacingOffset = (alpha - adjustedAngle) / 2; |
| 12372 | } |
| 12373 | var beta = Math.max(0.001, alpha * outerRadius - offset / (0, _helpersSegmentJs.P)) / outerRadius; |
| 12374 | var angleOffset = (alpha - beta) / 2; |
| 12375 | var startAngle = start + angleOffset + spacingOffset; |
| 12376 | var endAngle = end - angleOffset - spacingOffset; |
| 12377 | var ref = parseBorderRadius$1(element, innerRadius, outerRadius, endAngle - startAngle), outerStart = ref.outerStart, outerEnd = ref.outerEnd, innerStart = ref.innerStart, innerEnd = ref.innerEnd; |
| 12378 | var outerStartAdjustedRadius = outerRadius - outerStart; |
| 12379 | var outerEndAdjustedRadius = outerRadius - outerEnd; |
| 12380 | var outerStartAdjustedAngle = startAngle + outerStart / outerStartAdjustedRadius; |
| 12381 | var outerEndAdjustedAngle = endAngle - outerEnd / outerEndAdjustedRadius; |
| 12382 | var innerStartAdjustedRadius = innerRadius + innerStart; |
| 12383 | var innerEndAdjustedRadius = innerRadius + innerEnd; |
| 12384 | var innerStartAdjustedAngle = startAngle + innerStart / innerStartAdjustedRadius; |
| 12385 | var innerEndAdjustedAngle = endAngle - innerEnd / innerEndAdjustedRadius; |
| 12386 | ctx.beginPath(); |
| 12387 | ctx.arc(x, y, outerRadius, outerStartAdjustedAngle, outerEndAdjustedAngle); |
| 12388 | if (outerEnd > 0) { |
| 12389 | var pCenter = rThetaToXY(outerEndAdjustedRadius, outerEndAdjustedAngle, x, y); |
| 12390 | ctx.arc(pCenter.x, pCenter.y, outerEnd, outerEndAdjustedAngle, endAngle + (0, _helpersSegmentJs.H)); |
| 12391 | } |
| 12392 | var p4 = rThetaToXY(innerEndAdjustedRadius, endAngle, x, y); |
| 12393 | ctx.lineTo(p4.x, p4.y); |
| 12394 | if (innerEnd > 0) { |
| 12395 | var pCenter1 = rThetaToXY(innerEndAdjustedRadius, innerEndAdjustedAngle, x, y); |
| 12396 | ctx.arc(pCenter1.x, pCenter1.y, innerEnd, endAngle + (0, _helpersSegmentJs.H), innerEndAdjustedAngle + Math.PI); |
| 12397 | } |
| 12398 | ctx.arc(x, y, innerRadius, endAngle - innerEnd / innerRadius, startAngle + innerStart / innerRadius, true); |
| 12399 | if (innerStart > 0) { |
| 12400 | var pCenter2 = rThetaToXY(innerStartAdjustedRadius, innerStartAdjustedAngle, x, y); |
| 12401 | ctx.arc(pCenter2.x, pCenter2.y, innerStart, innerStartAdjustedAngle + Math.PI, startAngle - (0, _helpersSegmentJs.H)); |
| 12402 | } |
| 12403 | var p8 = rThetaToXY(outerStartAdjustedRadius, startAngle, x, y); |
| 12404 | ctx.lineTo(p8.x, p8.y); |
| 12405 | if (outerStart > 0) { |
| 12406 | var pCenter3 = rThetaToXY(outerStartAdjustedRadius, outerStartAdjustedAngle, x, y); |
| 12407 | ctx.arc(pCenter3.x, pCenter3.y, outerStart, startAngle - (0, _helpersSegmentJs.H), outerStartAdjustedAngle); |
| 12408 | } |
| 12409 | ctx.closePath(); |
| 12410 | } |
| 12411 | function drawArc(ctx, element, offset, spacing) { |
| 12412 | var fullCircles = element.fullCircles, startAngle = element.startAngle, circumference = element.circumference; |
| 12413 | var endAngle = element.endAngle; |
| 12414 | if (fullCircles) { |
| 12415 | pathArc(ctx, element, offset, spacing, startAngle + (0, _helpersSegmentJs.T)); |
| 12416 | for(var i = 0; i < fullCircles; ++i)ctx.fill(); |
| 12417 | if (!isNaN(circumference)) { |
| 12418 | endAngle = startAngle + circumference % (0, _helpersSegmentJs.T); |
| 12419 | if (circumference % (0, _helpersSegmentJs.T) === 0) endAngle += (0, _helpersSegmentJs.T); |
| 12420 | } |
| 12421 | } |
| 12422 | pathArc(ctx, element, offset, spacing, endAngle); |
| 12423 | ctx.fill(); |
| 12424 | return endAngle; |
| 12425 | } |
| 12426 | function drawFullCircleBorders(ctx, element, inner) { |
| 12427 | var x = element.x, y = element.y, startAngle = element.startAngle, pixelMargin = element.pixelMargin, fullCircles = element.fullCircles; |
| 12428 | var outerRadius = Math.max(element.outerRadius - pixelMargin, 0); |
| 12429 | var innerRadius = element.innerRadius + pixelMargin; |
| 12430 | var i; |
| 12431 | if (inner) clipArc(ctx, element, startAngle + (0, _helpersSegmentJs.T)); |
| 12432 | ctx.beginPath(); |
| 12433 | ctx.arc(x, y, innerRadius, startAngle + (0, _helpersSegmentJs.T), startAngle, true); |
| 12434 | for(i = 0; i < fullCircles; ++i)ctx.stroke(); |
| 12435 | ctx.beginPath(); |
| 12436 | ctx.arc(x, y, outerRadius, startAngle, startAngle + (0, _helpersSegmentJs.T)); |
| 12437 | for(i = 0; i < fullCircles; ++i)ctx.stroke(); |
| 12438 | } |
| 12439 | function drawBorder(ctx, element, offset, spacing, endAngle) { |
| 12440 | var options = element.options; |
| 12441 | var borderWidth = options.borderWidth, borderJoinStyle = options.borderJoinStyle; |
| 12442 | var inner = options.borderAlign === "inner"; |
| 12443 | if (!borderWidth) return; |
| 12444 | if (inner) { |
| 12445 | ctx.lineWidth = borderWidth * 2; |
| 12446 | ctx.lineJoin = borderJoinStyle || "round"; |
| 12447 | } else { |
| 12448 | ctx.lineWidth = borderWidth; |
| 12449 | ctx.lineJoin = borderJoinStyle || "bevel"; |
| 12450 | } |
| 12451 | if (element.fullCircles) drawFullCircleBorders(ctx, element, inner); |
| 12452 | if (inner) clipArc(ctx, element, endAngle); |
| 12453 | pathArc(ctx, element, offset, spacing, endAngle); |
| 12454 | ctx.stroke(); |
| 12455 | } |
| 12456 | var ArcElement = /*#__PURE__*/ function(Element) { |
| 12457 | "use strict"; |
| 12458 | (0, _inheritsJsDefault.default)(ArcElement, Element); |
| 12459 | var _super = (0, _createSuperJsDefault.default)(ArcElement); |
| 12460 | function ArcElement(cfg) { |
| 12461 | (0, _classCallCheckJsDefault.default)(this, ArcElement); |
| 12462 | var _this; |
| 12463 | _this = _super.call(this); |
| 12464 | _this.options = undefined; |
| 12465 | _this.circumference = undefined; |
| 12466 | _this.startAngle = undefined; |
| 12467 | _this.endAngle = undefined; |
| 12468 | _this.innerRadius = undefined; |
| 12469 | _this.outerRadius = undefined; |
| 12470 | _this.pixelMargin = 0; |
| 12471 | _this.fullCircles = 0; |
| 12472 | if (cfg) Object.assign((0, _assertThisInitializedJsDefault.default)(_this), cfg); |
| 12473 | return _this; |
| 12474 | } |
| 12475 | (0, _createClassJsDefault.default)(ArcElement, [ |
| 12476 | { |
| 12477 | key: "inRange", |
| 12478 | value: function inRange2(chartX, chartY, useFinalPosition) { |
| 12479 | var point = this.getProps([ |
| 12480 | "x", |
| 12481 | "y" |
| 12482 | ], useFinalPosition); |
| 12483 | var ref = (0, _helpersSegmentJs.C)(point, { |
| 12484 | x: chartX, |
| 12485 | y: chartY |
| 12486 | }), angle = ref.angle, distance = ref.distance; |
| 12487 | var ref6 = this.getProps([ |
| 12488 | "startAngle", |
| 12489 | "endAngle", |
| 12490 | "innerRadius", |
| 12491 | "outerRadius", |
| 12492 | "circumference" |
| 12493 | ], useFinalPosition), startAngle = ref6.startAngle, endAngle = ref6.endAngle, innerRadius = ref6.innerRadius, outerRadius = ref6.outerRadius, circumference = ref6.circumference; |
| 12494 | var rAdjust = this.options.spacing / 2; |
| 12495 | var _circumference = (0, _helpersSegmentJs.v)(circumference, endAngle - startAngle); |
| 12496 | var betweenAngles = _circumference >= (0, _helpersSegmentJs.T) || (0, _helpersSegmentJs.p)(angle, startAngle, endAngle); |
| 12497 | var withinRadius = (0, _helpersSegmentJs.ai)(distance, innerRadius + rAdjust, outerRadius + rAdjust); |
| 12498 | return betweenAngles && withinRadius; |
| 12499 | } |
| 12500 | }, |
| 12501 | { |
| 12502 | key: "getCenterPoint", |
| 12503 | value: function getCenterPoint(useFinalPosition) { |
| 12504 | var ref = this.getProps([ |
| 12505 | "x", |
| 12506 | "y", |
| 12507 | "startAngle", |
| 12508 | "endAngle", |
| 12509 | "innerRadius", |
| 12510 | "outerRadius", |
| 12511 | "circumference", |
| 12512 | ], useFinalPosition), x = ref.x, y = ref.y, startAngle = ref.startAngle, endAngle = ref.endAngle, innerRadius = ref.innerRadius, outerRadius = ref.outerRadius; |
| 12513 | var _options = this.options, offset = _options.offset, spacing = _options.spacing; |
| 12514 | var halfAngle = (startAngle + endAngle) / 2; |
| 12515 | var halfRadius = (innerRadius + outerRadius + spacing + offset) / 2; |
| 12516 | return { |
| 12517 | x: x + Math.cos(halfAngle) * halfRadius, |
| 12518 | y: y + Math.sin(halfAngle) * halfRadius |
| 12519 | }; |
| 12520 | } |
| 12521 | }, |
| 12522 | { |
| 12523 | key: "tooltipPosition", |
| 12524 | value: function tooltipPosition(useFinalPosition) { |
| 12525 | return this.getCenterPoint(useFinalPosition); |
| 12526 | } |
| 12527 | }, |
| 12528 | { |
| 12529 | key: "draw", |
| 12530 | value: function draw2(ctx) { |
| 12531 | var ref = this, options = ref.options, circumference = ref.circumference; |
| 12532 | var offset = (options.offset || 0) / 2; |
| 12533 | var spacing = (options.spacing || 0) / 2; |
| 12534 | this.pixelMargin = options.borderAlign === "inner" ? 0.33 : 0; |
| 12535 | this.fullCircles = circumference > (0, _helpersSegmentJs.T) ? Math.floor(circumference / (0, _helpersSegmentJs.T)) : 0; |
| 12536 | if (circumference === 0 || this.innerRadius < 0 || this.outerRadius < 0) return; |
| 12537 | ctx.save(); |
| 12538 | var radiusOffset = 0; |
| 12539 | if (offset) { |
| 12540 | radiusOffset = offset / 2; |
| 12541 | var halfAngle = (this.startAngle + this.endAngle) / 2; |
| 12542 | ctx.translate(Math.cos(halfAngle) * radiusOffset, Math.sin(halfAngle) * radiusOffset); |
| 12543 | if (this.circumference >= (0, _helpersSegmentJs.P)) radiusOffset = offset; |
| 12544 | } |
| 12545 | ctx.fillStyle = options.backgroundColor; |
| 12546 | ctx.strokeStyle = options.borderColor; |
| 12547 | var endAngle = drawArc(ctx, this, radiusOffset, spacing); |
| 12548 | drawBorder(ctx, this, radiusOffset, spacing, endAngle); |
| 12549 | ctx.restore(); |
| 12550 | } |
| 12551 | } |
| 12552 | ]); |
| 12553 | return ArcElement; |
| 12554 | }((0, _wrapNativeSuperJsDefault.default)(Element)); |
| 12555 | ArcElement.id = "arc"; |
| 12556 | ArcElement.defaults = { |
| 12557 | borderAlign: "center", |
| 12558 | borderColor: "#fff", |
| 12559 | borderJoinStyle: undefined, |
| 12560 | borderRadius: 0, |
| 12561 | borderWidth: 2, |
| 12562 | offset: 0, |
| 12563 | spacing: 0, |
| 12564 | angle: undefined |
| 12565 | }; |
| 12566 | ArcElement.defaultRoutes = { |
| 12567 | backgroundColor: "backgroundColor" |
| 12568 | }; |
| 12569 | function setStyle(ctx, options) { |
| 12570 | var style = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : options; |
| 12571 | ctx.lineCap = (0, _helpersSegmentJs.v)(style.borderCapStyle, options.borderCapStyle); |
| 12572 | ctx.setLineDash((0, _helpersSegmentJs.v)(style.borderDash, options.borderDash)); |
| 12573 | ctx.lineDashOffset = (0, _helpersSegmentJs.v)(style.borderDashOffset, options.borderDashOffset); |
| 12574 | ctx.lineJoin = (0, _helpersSegmentJs.v)(style.borderJoinStyle, options.borderJoinStyle); |
| 12575 | ctx.lineWidth = (0, _helpersSegmentJs.v)(style.borderWidth, options.borderWidth); |
| 12576 | ctx.strokeStyle = (0, _helpersSegmentJs.v)(style.borderColor, options.borderColor); |
| 12577 | } |
| 12578 | function lineTo(ctx, previous, target) { |
| 12579 | ctx.lineTo(target.x, target.y); |
| 12580 | } |
| 12581 | function getLineMethod(options) { |
| 12582 | if (options.stepped) return 0, _helpersSegmentJs.aq; |
| 12583 | if (options.tension || options.cubicInterpolationMode === "monotone") return 0, _helpersSegmentJs.ar; |
| 12584 | return lineTo; |
| 12585 | } |
| 12586 | function pathVars(points, segment) { |
| 12587 | var params = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}; |
| 12588 | var count = points.length; |
| 12589 | var tmp = params.start, paramsStart = tmp === void 0 ? 0 : tmp, tmp1 = params.end, paramsEnd = tmp1 === void 0 ? count - 1 : tmp1; |
| 12590 | var segmentStart = segment.start, segmentEnd = segment.end; |
| 12591 | var start = Math.max(paramsStart, segmentStart); |
| 12592 | var end = Math.min(paramsEnd, segmentEnd); |
| 12593 | var outside = paramsStart < segmentStart && paramsEnd < segmentStart || paramsStart > segmentEnd && paramsEnd > segmentEnd; |
| 12594 | return { |
| 12595 | count: count, |
| 12596 | start: start, |
| 12597 | loop: segment.loop, |
| 12598 | ilen: end < start && !outside ? count + end - start : end - start |
| 12599 | }; |
| 12600 | } |
| 12601 | function pathSegment(ctx, line, segment, params) { |
| 12602 | var points = line.points, options = line.options; |
| 12603 | var ref = pathVars(points, segment, params), count = ref.count, start = ref.start, loop = ref.loop, ilen = ref.ilen; |
| 12604 | var lineMethod = getLineMethod(options); |
| 12605 | var ref7 = params || {}, _move = ref7.move, move = _move === void 0 ? true : _move, reverse = ref7.reverse; |
| 12606 | var i, point, prev; |
| 12607 | for(i = 0; i <= ilen; ++i){ |
| 12608 | point = points[(start + (reverse ? ilen - i : i)) % count]; |
| 12609 | if (point.skip) continue; |
| 12610 | else if (move) { |
| 12611 | ctx.moveTo(point.x, point.y); |
| 12612 | move = false; |
| 12613 | } else lineMethod(ctx, prev, point, reverse, options.stepped); |
| 12614 | prev = point; |
| 12615 | } |
| 12616 | if (loop) { |
| 12617 | point = points[(start + (reverse ? ilen : 0)) % count]; |
| 12618 | lineMethod(ctx, prev, point, reverse, options.stepped); |
| 12619 | } |
| 12620 | return !!loop; |
| 12621 | } |
| 12622 | function fastPathSegment(ctx, line, segment, params) { |
| 12623 | var points = line.points; |
| 12624 | var ref = pathVars(points, segment, params), count = ref.count, start = ref.start, ilen = ref.ilen; |
| 12625 | var ref8 = params || {}, _move = ref8.move, move = _move === void 0 ? true : _move, reverse = ref8.reverse; |
| 12626 | var avgX = 0; |
| 12627 | var countX = 0; |
| 12628 | var i, point, prevX, minY, maxY, lastY; |
| 12629 | var pointIndex = function(index56) { |
| 12630 | return (start + (reverse ? ilen - index56 : index56)) % count; |
| 12631 | }; |
| 12632 | var drawX = function() { |
| 12633 | if (minY !== maxY) { |
| 12634 | ctx.lineTo(avgX, maxY); |
| 12635 | ctx.lineTo(avgX, minY); |
| 12636 | ctx.lineTo(avgX, lastY); |
| 12637 | } |
| 12638 | }; |
| 12639 | if (move) { |
| 12640 | point = points[pointIndex(0)]; |
| 12641 | ctx.moveTo(point.x, point.y); |
| 12642 | } |
| 12643 | for(i = 0; i <= ilen; ++i){ |
| 12644 | point = points[pointIndex(i)]; |
| 12645 | if (point.skip) continue; |
| 12646 | var x = point.x; |
| 12647 | var y = point.y; |
| 12648 | var truncX = x | 0; |
| 12649 | if (truncX === prevX) { |
| 12650 | if (y < minY) minY = y; |
| 12651 | else if (y > maxY) maxY = y; |
| 12652 | avgX = (countX * avgX + x) / ++countX; |
| 12653 | } else { |
| 12654 | drawX(); |
| 12655 | ctx.lineTo(x, y); |
| 12656 | prevX = truncX; |
| 12657 | countX = 0; |
| 12658 | minY = maxY = y; |
| 12659 | } |
| 12660 | lastY = y; |
| 12661 | } |
| 12662 | drawX(); |
| 12663 | } |
| 12664 | function _getSegmentMethod(line) { |
| 12665 | var opts = line.options; |
| 12666 | var borderDash = opts.borderDash && opts.borderDash.length; |
| 12667 | var useFastPath = !line._decimated && !line._loop && !opts.tension && opts.cubicInterpolationMode !== "monotone" && !opts.stepped && !borderDash; |
| 12668 | return useFastPath ? fastPathSegment : pathSegment; |
| 12669 | } |
| 12670 | function _getInterpolationMethod(options) { |
| 12671 | if (options.stepped) return 0, _helpersSegmentJs.an; |
| 12672 | if (options.tension || options.cubicInterpolationMode === "monotone") return 0, _helpersSegmentJs.ao; |
| 12673 | return 0, _helpersSegmentJs.ap; |
| 12674 | } |
| 12675 | function strokePathWithCache(ctx, line, start, count) { |
| 12676 | var path = line._path; |
| 12677 | if (!path) { |
| 12678 | path = line._path = new Path2D(); |
| 12679 | if (line.path(path, start, count)) path.closePath(); |
| 12680 | } |
| 12681 | setStyle(ctx, line.options); |
| 12682 | ctx.stroke(path); |
| 12683 | } |
| 12684 | function strokePathDirect(ctx, line, start, count) { |
| 12685 | var segments = line.segments, options = line.options; |
| 12686 | var segmentMethod = _getSegmentMethod(line); |
| 12687 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 12688 | try { |
| 12689 | for(var _iterator = segments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 12690 | var segment = _step.value; |
| 12691 | setStyle(ctx, options, segment.style); |
| 12692 | ctx.beginPath(); |
| 12693 | if (segmentMethod(ctx, line, segment, { |
| 12694 | start: start, |
| 12695 | end: start + count - 1 |
| 12696 | })) ctx.closePath(); |
| 12697 | ctx.stroke(); |
| 12698 | } |
| 12699 | } catch (err) { |
| 12700 | _didIteratorError = true; |
| 12701 | _iteratorError = err; |
| 12702 | } finally{ |
| 12703 | try { |
| 12704 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 12705 | _iterator.return(); |
| 12706 | } |
| 12707 | } finally{ |
| 12708 | if (_didIteratorError) { |
| 12709 | throw _iteratorError; |
| 12710 | } |
| 12711 | } |
| 12712 | } |
| 12713 | } |
| 12714 | var usePath2D = typeof Path2D === "function"; |
| 12715 | function draw(ctx, line, start, count) { |
| 12716 | if (usePath2D && !line.options.segment) strokePathWithCache(ctx, line, start, count); |
| 12717 | else strokePathDirect(ctx, line, start, count); |
| 12718 | } |
| 12719 | var LineElement = /*#__PURE__*/ function(Element) { |
| 12720 | "use strict"; |
| 12721 | (0, _inheritsJsDefault.default)(LineElement, Element); |
| 12722 | var _super = (0, _createSuperJsDefault.default)(LineElement); |
| 12723 | function LineElement(cfg) { |
| 12724 | (0, _classCallCheckJsDefault.default)(this, LineElement); |
| 12725 | var _this; |
| 12726 | _this = _super.call(this); |
| 12727 | _this.animated = true; |
| 12728 | _this.options = undefined; |
| 12729 | _this._chart = undefined; |
| 12730 | _this._loop = undefined; |
| 12731 | _this._fullLoop = undefined; |
| 12732 | _this._path = undefined; |
| 12733 | _this._points = undefined; |
| 12734 | _this._segments = undefined; |
| 12735 | _this._decimated = false; |
| 12736 | _this._pointsUpdated = false; |
| 12737 | _this._datasetIndex = undefined; |
| 12738 | if (cfg) Object.assign((0, _assertThisInitializedJsDefault.default)(_this), cfg); |
| 12739 | return _this; |
| 12740 | } |
| 12741 | (0, _createClassJsDefault.default)(LineElement, [ |
| 12742 | { |
| 12743 | key: "updateControlPoints", |
| 12744 | value: function updateControlPoints(chartArea, indexAxis) { |
| 12745 | var options = this.options; |
| 12746 | if ((options.tension || options.cubicInterpolationMode === "monotone") && !options.stepped && !this._pointsUpdated) { |
| 12747 | var loop = options.spanGaps ? this._loop : this._fullLoop; |
| 12748 | (0, _helpersSegmentJs.ak)(this._points, options, chartArea, loop, indexAxis); |
| 12749 | this._pointsUpdated = true; |
| 12750 | } |
| 12751 | } |
| 12752 | }, |
| 12753 | { |
| 12754 | key: "points", |
| 12755 | get: function get() { |
| 12756 | return this._points; |
| 12757 | }, |
| 12758 | set: function set(points) { |
| 12759 | this._points = points; |
| 12760 | delete this._segments; |
| 12761 | delete this._path; |
| 12762 | this._pointsUpdated = false; |
| 12763 | } |
| 12764 | }, |
| 12765 | { |
| 12766 | key: "segments", |
| 12767 | get: function get() { |
| 12768 | return this._segments || (this._segments = (0, _helpersSegmentJs.al)(this, this.options.segment)); |
| 12769 | } |
| 12770 | }, |
| 12771 | { |
| 12772 | key: "first", |
| 12773 | value: function first() { |
| 12774 | var segments = this.segments; |
| 12775 | var points = this.points; |
| 12776 | return segments.length && points[segments[0].start]; |
| 12777 | } |
| 12778 | }, |
| 12779 | { |
| 12780 | key: "last", |
| 12781 | value: function last() { |
| 12782 | var segments = this.segments; |
| 12783 | var points = this.points; |
| 12784 | var count = segments.length; |
| 12785 | return count && points[segments[count - 1].end]; |
| 12786 | } |
| 12787 | }, |
| 12788 | { |
| 12789 | key: "interpolate", |
| 12790 | value: function interpolate(point, property) { |
| 12791 | var options = this.options; |
| 12792 | var value = point[property]; |
| 12793 | var points = this.points; |
| 12794 | var segments = (0, _helpersSegmentJs.am)(this, { |
| 12795 | property: property, |
| 12796 | start: value, |
| 12797 | end: value |
| 12798 | }); |
| 12799 | if (!segments.length) return; |
| 12800 | var result = []; |
| 12801 | var _interpolate = _getInterpolationMethod(options); |
| 12802 | var i, ilen; |
| 12803 | for(i = 0, ilen = segments.length; i < ilen; ++i){ |
| 12804 | var _i = segments[i], start = _i.start, end = _i.end; |
| 12805 | var p1 = points[start]; |
| 12806 | var p2 = points[end]; |
| 12807 | if (p1 === p2) { |
| 12808 | result.push(p1); |
| 12809 | continue; |
| 12810 | } |
| 12811 | var t = Math.abs((value - p1[property]) / (p2[property] - p1[property])); |
| 12812 | var interpolated = _interpolate(p1, p2, t, options.stepped); |
| 12813 | interpolated[property] = point[property]; |
| 12814 | result.push(interpolated); |
| 12815 | } |
| 12816 | return result.length === 1 ? result[0] : result; |
| 12817 | } |
| 12818 | }, |
| 12819 | { |
| 12820 | key: "pathSegment", |
| 12821 | value: function pathSegment(ctx, segment, params) { |
| 12822 | var segmentMethod = _getSegmentMethod(this); |
| 12823 | return segmentMethod(ctx, this, segment, params); |
| 12824 | } |
| 12825 | }, |
| 12826 | { |
| 12827 | key: "path", |
| 12828 | value: function path(ctx, start, count) { |
| 12829 | var segments = this.segments; |
| 12830 | var segmentMethod = _getSegmentMethod(this); |
| 12831 | var loop = this._loop; |
| 12832 | start = start || 0; |
| 12833 | count = count || this.points.length - start; |
| 12834 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 12835 | try { |
| 12836 | for(var _iterator = segments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 12837 | var segment = _step.value; |
| 12838 | loop &= segmentMethod(ctx, this, segment, { |
| 12839 | start: start, |
| 12840 | end: start + count - 1 |
| 12841 | }); |
| 12842 | } |
| 12843 | } catch (err) { |
| 12844 | _didIteratorError = true; |
| 12845 | _iteratorError = err; |
| 12846 | } finally{ |
| 12847 | try { |
| 12848 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 12849 | _iterator.return(); |
| 12850 | } |
| 12851 | } finally{ |
| 12852 | if (_didIteratorError) { |
| 12853 | throw _iteratorError; |
| 12854 | } |
| 12855 | } |
| 12856 | } |
| 12857 | return !!loop; |
| 12858 | } |
| 12859 | }, |
| 12860 | { |
| 12861 | key: "draw", |
| 12862 | value: function draw2(ctx, chartArea, start, count) { |
| 12863 | var options = this.options || {}; |
| 12864 | var points = this.points || []; |
| 12865 | if (points.length && options.borderWidth) { |
| 12866 | ctx.save(); |
| 12867 | draw(ctx, this, start, count); |
| 12868 | ctx.restore(); |
| 12869 | } |
| 12870 | if (this.animated) { |
| 12871 | this._pointsUpdated = false; |
| 12872 | this._path = undefined; |
| 12873 | } |
| 12874 | } |
| 12875 | } |
| 12876 | ]); |
| 12877 | return LineElement; |
| 12878 | }((0, _wrapNativeSuperJsDefault.default)(Element)); |
| 12879 | LineElement.id = "line"; |
| 12880 | LineElement.defaults = { |
| 12881 | borderCapStyle: "butt", |
| 12882 | borderDash: [], |
| 12883 | borderDashOffset: 0, |
| 12884 | borderJoinStyle: "miter", |
| 12885 | borderWidth: 3, |
| 12886 | capBezierPoints: true, |
| 12887 | cubicInterpolationMode: "default", |
| 12888 | fill: false, |
| 12889 | spanGaps: false, |
| 12890 | stepped: false, |
| 12891 | tension: 0 |
| 12892 | }; |
| 12893 | LineElement.defaultRoutes = { |
| 12894 | backgroundColor: "backgroundColor", |
| 12895 | borderColor: "borderColor" |
| 12896 | }; |
| 12897 | LineElement.descriptors = { |
| 12898 | _scriptable: true, |
| 12899 | _indexable: function(name) { |
| 12900 | return name !== "borderDash" && name !== "fill"; |
| 12901 | } |
| 12902 | }; |
| 12903 | function inRange$1(el, pos, axis, useFinalPosition) { |
| 12904 | var options = el.options; |
| 12905 | var ref = el.getProps([ |
| 12906 | axis |
| 12907 | ], useFinalPosition), value = ref[axis]; |
| 12908 | return Math.abs(pos - value) < options.radius + options.hitRadius; |
| 12909 | } |
| 12910 | var PointElement = /*#__PURE__*/ function(Element) { |
| 12911 | "use strict"; |
| 12912 | (0, _inheritsJsDefault.default)(PointElement, Element); |
| 12913 | var _super = (0, _createSuperJsDefault.default)(PointElement); |
| 12914 | function PointElement(cfg) { |
| 12915 | (0, _classCallCheckJsDefault.default)(this, PointElement); |
| 12916 | var _this; |
| 12917 | _this = _super.call(this); |
| 12918 | _this.options = undefined; |
| 12919 | _this.parsed = undefined; |
| 12920 | _this.skip = undefined; |
| 12921 | _this.stop = undefined; |
| 12922 | if (cfg) Object.assign((0, _assertThisInitializedJsDefault.default)(_this), cfg); |
| 12923 | return _this; |
| 12924 | } |
| 12925 | (0, _createClassJsDefault.default)(PointElement, [ |
| 12926 | { |
| 12927 | key: "inRange", |
| 12928 | value: function inRange2(mouseX, mouseY, useFinalPosition) { |
| 12929 | var options = this.options; |
| 12930 | var ref = this.getProps([ |
| 12931 | "x", |
| 12932 | "y" |
| 12933 | ], useFinalPosition), x = ref.x, y = ref.y; |
| 12934 | return Math.pow(mouseX - x, 2) + Math.pow(mouseY - y, 2) < Math.pow(options.hitRadius + options.radius, 2); |
| 12935 | } |
| 12936 | }, |
| 12937 | { |
| 12938 | key: "inXRange", |
| 12939 | value: function inXRange(mouseX, useFinalPosition) { |
| 12940 | return inRange$1(this, mouseX, "x", useFinalPosition); |
| 12941 | } |
| 12942 | }, |
| 12943 | { |
| 12944 | key: "inYRange", |
| 12945 | value: function inYRange(mouseY, useFinalPosition) { |
| 12946 | return inRange$1(this, mouseY, "y", useFinalPosition); |
| 12947 | } |
| 12948 | }, |
| 12949 | { |
| 12950 | key: "getCenterPoint", |
| 12951 | value: function getCenterPoint(useFinalPosition) { |
| 12952 | var ref = this.getProps([ |
| 12953 | "x", |
| 12954 | "y" |
| 12955 | ], useFinalPosition), x = ref.x, y = ref.y; |
| 12956 | return { |
| 12957 | x: x, |
| 12958 | y: y |
| 12959 | }; |
| 12960 | } |
| 12961 | }, |
| 12962 | { |
| 12963 | key: "size", |
| 12964 | value: function size(options) { |
| 12965 | options = options || this.options || {}; |
| 12966 | var radius = options.radius || 0; |
| 12967 | radius = Math.max(radius, radius && options.hoverRadius || 0); |
| 12968 | var borderWidth = radius && options.borderWidth || 0; |
| 12969 | return (radius + borderWidth) * 2; |
| 12970 | } |
| 12971 | }, |
| 12972 | { |
| 12973 | key: "draw", |
| 12974 | value: function draw2(ctx, area) { |
| 12975 | var options = this.options; |
| 12976 | if (this.skip || options.radius < 0.1 || !(0, _helpersSegmentJs.B)(this, area, this.size(options) / 2)) return; |
| 12977 | ctx.strokeStyle = options.borderColor; |
| 12978 | ctx.lineWidth = options.borderWidth; |
| 12979 | ctx.fillStyle = options.backgroundColor; |
| 12980 | (0, _helpersSegmentJs.as)(ctx, options, this.x, this.y); |
| 12981 | } |
| 12982 | }, |
| 12983 | { |
| 12984 | key: "getRange", |
| 12985 | value: function getRange() { |
| 12986 | var options = this.options || {}; |
| 12987 | return options.radius + options.hitRadius; |
| 12988 | } |
| 12989 | } |
| 12990 | ]); |
| 12991 | return PointElement; |
| 12992 | }((0, _wrapNativeSuperJsDefault.default)(Element)); |
| 12993 | PointElement.id = "point"; |
| 12994 | PointElement.defaults = { |
| 12995 | borderWidth: 1, |
| 12996 | hitRadius: 1, |
| 12997 | hoverBorderWidth: 1, |
| 12998 | hoverRadius: 4, |
| 12999 | pointStyle: "circle", |
| 13000 | radius: 3, |
| 13001 | rotation: 0 |
| 13002 | }; |
| 13003 | PointElement.defaultRoutes = { |
| 13004 | backgroundColor: "backgroundColor", |
| 13005 | borderColor: "borderColor" |
| 13006 | }; |
| 13007 | function getBarBounds(bar, useFinalPosition) { |
| 13008 | var ref = bar.getProps([ |
| 13009 | "x", |
| 13010 | "y", |
| 13011 | "base", |
| 13012 | "width", |
| 13013 | "height" |
| 13014 | ], useFinalPosition), x = ref.x, y = ref.y, base = ref.base, width = ref.width, height = ref.height; |
| 13015 | var left, right, top, bottom, half; |
| 13016 | if (bar.horizontal) { |
| 13017 | half = height / 2; |
| 13018 | left = Math.min(x, base); |
| 13019 | right = Math.max(x, base); |
| 13020 | top = y - half; |
| 13021 | bottom = y + half; |
| 13022 | } else { |
| 13023 | half = width / 2; |
| 13024 | left = x - half; |
| 13025 | right = x + half; |
| 13026 | top = Math.min(y, base); |
| 13027 | bottom = Math.max(y, base); |
| 13028 | } |
| 13029 | return { |
| 13030 | left: left, |
| 13031 | top: top, |
| 13032 | right: right, |
| 13033 | bottom: bottom |
| 13034 | }; |
| 13035 | } |
| 13036 | function skipOrLimit(skip1, value, min, max) { |
| 13037 | return skip1 ? 0 : (0, _helpersSegmentJs.w)(value, min, max); |
| 13038 | } |
| 13039 | function parseBorderWidth(bar, maxW, maxH) { |
| 13040 | var value = bar.options.borderWidth; |
| 13041 | var skip2 = bar.borderSkipped; |
| 13042 | var o = (0, _helpersSegmentJs.au)(value); |
| 13043 | return { |
| 13044 | t: skipOrLimit(skip2.top, o.top, 0, maxH), |
| 13045 | r: skipOrLimit(skip2.right, o.right, 0, maxW), |
| 13046 | b: skipOrLimit(skip2.bottom, o.bottom, 0, maxH), |
| 13047 | l: skipOrLimit(skip2.left, o.left, 0, maxW) |
| 13048 | }; |
| 13049 | } |
| 13050 | function parseBorderRadius(bar, maxW, maxH) { |
| 13051 | var enableBorderRadius = bar.getProps([ |
| 13052 | "enableBorderRadius" |
| 13053 | ]).enableBorderRadius; |
| 13054 | var value = bar.options.borderRadius; |
| 13055 | var o = (0, _helpersSegmentJs.av)(value); |
| 13056 | var maxR = Math.min(maxW, maxH); |
| 13057 | var skip3 = bar.borderSkipped; |
| 13058 | var enableBorder = enableBorderRadius || (0, _helpersSegmentJs.i)(value); |
| 13059 | return { |
| 13060 | topLeft: skipOrLimit(!enableBorder || skip3.top || skip3.left, o.topLeft, 0, maxR), |
| 13061 | topRight: skipOrLimit(!enableBorder || skip3.top || skip3.right, o.topRight, 0, maxR), |
| 13062 | bottomLeft: skipOrLimit(!enableBorder || skip3.bottom || skip3.left, o.bottomLeft, 0, maxR), |
| 13063 | bottomRight: skipOrLimit(!enableBorder || skip3.bottom || skip3.right, o.bottomRight, 0, maxR) |
| 13064 | }; |
| 13065 | } |
| 13066 | function boundingRects(bar) { |
| 13067 | var bounds = getBarBounds(bar); |
| 13068 | var width = bounds.right - bounds.left; |
| 13069 | var height = bounds.bottom - bounds.top; |
| 13070 | var border = parseBorderWidth(bar, width / 2, height / 2); |
| 13071 | var radius = parseBorderRadius(bar, width / 2, height / 2); |
| 13072 | return { |
| 13073 | outer: { |
| 13074 | x: bounds.left, |
| 13075 | y: bounds.top, |
| 13076 | w: width, |
| 13077 | h: height, |
| 13078 | radius: radius |
| 13079 | }, |
| 13080 | inner: { |
| 13081 | x: bounds.left + border.l, |
| 13082 | y: bounds.top + border.t, |
| 13083 | w: width - border.l - border.r, |
| 13084 | h: height - border.t - border.b, |
| 13085 | radius: { |
| 13086 | topLeft: Math.max(0, radius.topLeft - Math.max(border.t, border.l)), |
| 13087 | topRight: Math.max(0, radius.topRight - Math.max(border.t, border.r)), |
| 13088 | bottomLeft: Math.max(0, radius.bottomLeft - Math.max(border.b, border.l)), |
| 13089 | bottomRight: Math.max(0, radius.bottomRight - Math.max(border.b, border.r)) |
| 13090 | } |
| 13091 | } |
| 13092 | }; |
| 13093 | } |
| 13094 | function inRange(bar, x, y, useFinalPosition) { |
| 13095 | var skipX = x === null; |
| 13096 | var skipY = y === null; |
| 13097 | var skipBoth = skipX && skipY; |
| 13098 | var bounds = bar && !skipBoth && getBarBounds(bar, useFinalPosition); |
| 13099 | return bounds && (skipX || (0, _helpersSegmentJs.ai)(x, bounds.left, bounds.right)) && (skipY || (0, _helpersSegmentJs.ai)(y, bounds.top, bounds.bottom)); |
| 13100 | } |
| 13101 | function hasRadius(radius) { |
| 13102 | return radius.topLeft || radius.topRight || radius.bottomLeft || radius.bottomRight; |
| 13103 | } |
| 13104 | function addNormalRectPath(ctx, rect) { |
| 13105 | ctx.rect(rect.x, rect.y, rect.w, rect.h); |
| 13106 | } |
| 13107 | function inflateRect(rect, amount) { |
| 13108 | var refRect = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}; |
| 13109 | var x = rect.x !== refRect.x ? -amount : 0; |
| 13110 | var y = rect.y !== refRect.y ? -amount : 0; |
| 13111 | var w = (rect.x + rect.w !== refRect.x + refRect.w ? amount : 0) - x; |
| 13112 | var h = (rect.y + rect.h !== refRect.y + refRect.h ? amount : 0) - y; |
| 13113 | return { |
| 13114 | x: rect.x + x, |
| 13115 | y: rect.y + y, |
| 13116 | w: rect.w + w, |
| 13117 | h: rect.h + h, |
| 13118 | radius: rect.radius |
| 13119 | }; |
| 13120 | } |
| 13121 | var BarElement = /*#__PURE__*/ function(Element) { |
| 13122 | "use strict"; |
| 13123 | (0, _inheritsJsDefault.default)(BarElement, Element); |
| 13124 | var _super = (0, _createSuperJsDefault.default)(BarElement); |
| 13125 | function BarElement(cfg) { |
| 13126 | (0, _classCallCheckJsDefault.default)(this, BarElement); |
| 13127 | var _this; |
| 13128 | _this = _super.call(this); |
| 13129 | _this.options = undefined; |
| 13130 | _this.horizontal = undefined; |
| 13131 | _this.base = undefined; |
| 13132 | _this.width = undefined; |
| 13133 | _this.height = undefined; |
| 13134 | _this.inflateAmount = undefined; |
| 13135 | if (cfg) Object.assign((0, _assertThisInitializedJsDefault.default)(_this), cfg); |
| 13136 | return _this; |
| 13137 | } |
| 13138 | (0, _createClassJsDefault.default)(BarElement, [ |
| 13139 | { |
| 13140 | key: "draw", |
| 13141 | value: function draw2(ctx) { |
| 13142 | var ref = this, inflateAmount = ref.inflateAmount, _options = ref.options, borderColor = _options.borderColor, backgroundColor = _options.backgroundColor; |
| 13143 | var ref9 = boundingRects(this), inner = ref9.inner, outer = ref9.outer; |
| 13144 | var addRectPath = hasRadius(outer.radius) ? (0, _helpersSegmentJs.at) : addNormalRectPath; |
| 13145 | ctx.save(); |
| 13146 | if (outer.w !== inner.w || outer.h !== inner.h) { |
| 13147 | ctx.beginPath(); |
| 13148 | addRectPath(ctx, inflateRect(outer, inflateAmount, inner)); |
| 13149 | ctx.clip(); |
| 13150 | addRectPath(ctx, inflateRect(inner, -inflateAmount, outer)); |
| 13151 | ctx.fillStyle = borderColor; |
| 13152 | ctx.fill("evenodd"); |
| 13153 | } |
| 13154 | ctx.beginPath(); |
| 13155 | addRectPath(ctx, inflateRect(inner, inflateAmount)); |
| 13156 | ctx.fillStyle = backgroundColor; |
| 13157 | ctx.fill(); |
| 13158 | ctx.restore(); |
| 13159 | } |
| 13160 | }, |
| 13161 | { |
| 13162 | key: "inRange", |
| 13163 | value: function inRange2(mouseX, mouseY, useFinalPosition) { |
| 13164 | return inRange(this, mouseX, mouseY, useFinalPosition); |
| 13165 | } |
| 13166 | }, |
| 13167 | { |
| 13168 | key: "inXRange", |
| 13169 | value: function inXRange(mouseX, useFinalPosition) { |
| 13170 | return inRange(this, mouseX, null, useFinalPosition); |
| 13171 | } |
| 13172 | }, |
| 13173 | { |
| 13174 | key: "inYRange", |
| 13175 | value: function inYRange(mouseY, useFinalPosition) { |
| 13176 | return inRange(this, null, mouseY, useFinalPosition); |
| 13177 | } |
| 13178 | }, |
| 13179 | { |
| 13180 | key: "getCenterPoint", |
| 13181 | value: function getCenterPoint(useFinalPosition) { |
| 13182 | var ref = this.getProps([ |
| 13183 | "x", |
| 13184 | "y", |
| 13185 | "base", |
| 13186 | "horizontal" |
| 13187 | ], useFinalPosition), x = ref.x, y = ref.y, base = ref.base, horizontal = ref.horizontal; |
| 13188 | return { |
| 13189 | x: horizontal ? (x + base) / 2 : x, |
| 13190 | y: horizontal ? y : (y + base) / 2 |
| 13191 | }; |
| 13192 | } |
| 13193 | }, |
| 13194 | { |
| 13195 | key: "getRange", |
| 13196 | value: function getRange(axis) { |
| 13197 | return axis === "x" ? this.width / 2 : this.height / 2; |
| 13198 | } |
| 13199 | } |
| 13200 | ]); |
| 13201 | return BarElement; |
| 13202 | }((0, _wrapNativeSuperJsDefault.default)(Element)); |
| 13203 | BarElement.id = "bar"; |
| 13204 | BarElement.defaults = { |
| 13205 | borderSkipped: "start", |
| 13206 | borderWidth: 0, |
| 13207 | borderRadius: 0, |
| 13208 | inflateAmount: "auto", |
| 13209 | pointStyle: undefined |
| 13210 | }; |
| 13211 | BarElement.defaultRoutes = { |
| 13212 | backgroundColor: "backgroundColor", |
| 13213 | borderColor: "borderColor" |
| 13214 | }; |
| 13215 | var elements = /*#__PURE__*/ Object.freeze({ |
| 13216 | __proto__: null, |
| 13217 | ArcElement: ArcElement, |
| 13218 | LineElement: LineElement, |
| 13219 | PointElement: PointElement, |
| 13220 | BarElement: BarElement |
| 13221 | }); |
| 13222 | function lttbDecimation(data, start, count, availableWidth, options) { |
| 13223 | var samples = options.samples || availableWidth; |
| 13224 | if (samples >= count) return data.slice(start, start + count); |
| 13225 | var decimated = []; |
| 13226 | var bucketWidth = (count - 2) / (samples - 2); |
| 13227 | var sampledIndex = 0; |
| 13228 | var endIndex = start + count - 1; |
| 13229 | var a = start; |
| 13230 | var i, maxAreaPoint, maxArea, area, nextA; |
| 13231 | decimated[sampledIndex++] = data[a]; |
| 13232 | for(i = 0; i < samples - 2; i++){ |
| 13233 | var avgX = 0; |
| 13234 | var avgY = 0; |
| 13235 | var j = void 0; |
| 13236 | var avgRangeStart = Math.floor((i + 1) * bucketWidth) + 1 + start; |
| 13237 | var avgRangeEnd = Math.min(Math.floor((i + 2) * bucketWidth) + 1, count) + start; |
| 13238 | var avgRangeLength = avgRangeEnd - avgRangeStart; |
| 13239 | for(j = avgRangeStart; j < avgRangeEnd; j++){ |
| 13240 | avgX += data[j].x; |
| 13241 | avgY += data[j].y; |
| 13242 | } |
| 13243 | avgX /= avgRangeLength; |
| 13244 | avgY /= avgRangeLength; |
| 13245 | var rangeOffs = Math.floor(i * bucketWidth) + 1 + start; |
| 13246 | var rangeTo = Math.min(Math.floor((i + 1) * bucketWidth) + 1, count) + start; |
| 13247 | var _a = data[a], pointAx = _a.x, pointAy = _a.y; |
| 13248 | maxArea = area = -1; |
| 13249 | for(j = rangeOffs; j < rangeTo; j++){ |
| 13250 | area = 0.5 * Math.abs((pointAx - avgX) * (data[j].y - pointAy) - (pointAx - data[j].x) * (avgY - pointAy)); |
| 13251 | if (area > maxArea) { |
| 13252 | maxArea = area; |
| 13253 | maxAreaPoint = data[j]; |
| 13254 | nextA = j; |
| 13255 | } |
| 13256 | } |
| 13257 | decimated[sampledIndex++] = maxAreaPoint; |
| 13258 | a = nextA; |
| 13259 | } |
| 13260 | decimated[sampledIndex++] = data[endIndex]; |
| 13261 | return decimated; |
| 13262 | } |
| 13263 | function minMaxDecimation(data, start, count, availableWidth) { |
| 13264 | var avgX = 0; |
| 13265 | var countX = 0; |
| 13266 | var i, point, x, y, prevX, minIndex, maxIndex, startIndex, minY, maxY; |
| 13267 | var decimated = []; |
| 13268 | var endIndex = start + count - 1; |
| 13269 | var xMin = data[start].x; |
| 13270 | var xMax = data[endIndex].x; |
| 13271 | var dx = xMax - xMin; |
| 13272 | for(i = start; i < start + count; ++i){ |
| 13273 | point = data[i]; |
| 13274 | x = (point.x - xMin) / dx * availableWidth; |
| 13275 | y = point.y; |
| 13276 | var truncX = x | 0; |
| 13277 | if (truncX === prevX) { |
| 13278 | if (y < minY) { |
| 13279 | minY = y; |
| 13280 | minIndex = i; |
| 13281 | } else if (y > maxY) { |
| 13282 | maxY = y; |
| 13283 | maxIndex = i; |
| 13284 | } |
| 13285 | avgX = (countX * avgX + point.x) / ++countX; |
| 13286 | } else { |
| 13287 | var lastIndex = i - 1; |
| 13288 | if (!(0, _helpersSegmentJs.k)(minIndex) && !(0, _helpersSegmentJs.k)(maxIndex)) { |
| 13289 | var intermediateIndex1 = Math.min(minIndex, maxIndex); |
| 13290 | var intermediateIndex2 = Math.max(minIndex, maxIndex); |
| 13291 | if (intermediateIndex1 !== startIndex && intermediateIndex1 !== lastIndex) decimated.push((0, _objectSpreadJsDefault.default)({}, data[intermediateIndex1], { |
| 13292 | x: avgX |
| 13293 | })); |
| 13294 | if (intermediateIndex2 !== startIndex && intermediateIndex2 !== lastIndex) decimated.push((0, _objectSpreadJsDefault.default)({}, data[intermediateIndex2], { |
| 13295 | x: avgX |
| 13296 | })); |
| 13297 | } |
| 13298 | if (i > 0 && lastIndex !== startIndex) decimated.push(data[lastIndex]); |
| 13299 | decimated.push(point); |
| 13300 | prevX = truncX; |
| 13301 | countX = 0; |
| 13302 | minY = maxY = y; |
| 13303 | minIndex = maxIndex = startIndex = i; |
| 13304 | } |
| 13305 | } |
| 13306 | return decimated; |
| 13307 | } |
| 13308 | function cleanDecimatedDataset(dataset) { |
| 13309 | if (dataset._decimated) { |
| 13310 | var data = dataset._data; |
| 13311 | delete dataset._decimated; |
| 13312 | delete dataset._data; |
| 13313 | Object.defineProperty(dataset, "data", { |
| 13314 | value: data |
| 13315 | }); |
| 13316 | } |
| 13317 | } |
| 13318 | function cleanDecimatedData(chart) { |
| 13319 | chart.data.datasets.forEach(function(dataset) { |
| 13320 | cleanDecimatedDataset(dataset); |
| 13321 | }); |
| 13322 | } |
| 13323 | function getStartAndCountOfVisiblePointsSimplified(meta, points) { |
| 13324 | var pointCount = points.length; |
| 13325 | var start = 0; |
| 13326 | var count; |
| 13327 | var iScale = meta.iScale; |
| 13328 | var ref = iScale.getUserBounds(), min = ref.min, max = ref.max, minDefined = ref.minDefined, maxDefined = ref.maxDefined; |
| 13329 | if (minDefined) start = (0, _helpersSegmentJs.w)((0, _helpersSegmentJs.x)(points, iScale.axis, min).lo, 0, pointCount - 1); |
| 13330 | if (maxDefined) count = (0, _helpersSegmentJs.w)((0, _helpersSegmentJs.x)(points, iScale.axis, max).hi + 1, start, pointCount) - start; |
| 13331 | else count = pointCount - start; |
| 13332 | return { |
| 13333 | start: start, |
| 13334 | count: count |
| 13335 | }; |
| 13336 | } |
| 13337 | var plugin_decimation = { |
| 13338 | id: "decimation", |
| 13339 | defaults: { |
| 13340 | algorithm: "min-max", |
| 13341 | enabled: false |
| 13342 | }, |
| 13343 | beforeElementsUpdate: function(chart, args, options) { |
| 13344 | if (!options.enabled) { |
| 13345 | cleanDecimatedData(chart); |
| 13346 | return; |
| 13347 | } |
| 13348 | var availableWidth = chart.width; |
| 13349 | chart.data.datasets.forEach(function(dataset, datasetIndex) { |
| 13350 | var _data = dataset._data, indexAxis = dataset.indexAxis; |
| 13351 | var meta = chart.getDatasetMeta(datasetIndex); |
| 13352 | var data = _data || dataset.data; |
| 13353 | if ((0, _helpersSegmentJs.a)([ |
| 13354 | indexAxis, |
| 13355 | chart.options.indexAxis |
| 13356 | ]) === "y") return; |
| 13357 | if (!meta.controller.supportsDecimation) return; |
| 13358 | var xAxis = chart.scales[meta.xAxisID]; |
| 13359 | if (xAxis.type !== "linear" && xAxis.type !== "time") return; |
| 13360 | if (chart.options.parsing) return; |
| 13361 | var ref = getStartAndCountOfVisiblePointsSimplified(meta, data), start = ref.start, count = ref.count; |
| 13362 | var threshold = options.threshold || 4 * availableWidth; |
| 13363 | if (count <= threshold) { |
| 13364 | cleanDecimatedDataset(dataset); |
| 13365 | return; |
| 13366 | } |
| 13367 | if ((0, _helpersSegmentJs.k)(_data)) { |
| 13368 | dataset._data = data; |
| 13369 | delete dataset.data; |
| 13370 | Object.defineProperty(dataset, "data", { |
| 13371 | configurable: true, |
| 13372 | enumerable: true, |
| 13373 | get: function get() { |
| 13374 | return this._decimated; |
| 13375 | }, |
| 13376 | set: function set(d) { |
| 13377 | this._data = d; |
| 13378 | } |
| 13379 | }); |
| 13380 | } |
| 13381 | var decimated; |
| 13382 | switch(options.algorithm){ |
| 13383 | case "lttb": |
| 13384 | decimated = lttbDecimation(data, start, count, availableWidth, options); |
| 13385 | break; |
| 13386 | case "min-max": |
| 13387 | decimated = minMaxDecimation(data, start, count, availableWidth); |
| 13388 | break; |
| 13389 | default: |
| 13390 | throw new Error("Unsupported decimation algorithm '".concat(options.algorithm, "'")); |
| 13391 | } |
| 13392 | dataset._decimated = decimated; |
| 13393 | }); |
| 13394 | }, |
| 13395 | destroy: function(chart) { |
| 13396 | cleanDecimatedData(chart); |
| 13397 | } |
| 13398 | }; |
| 13399 | function _segments(line, target, property) { |
| 13400 | var segments = line.segments; |
| 13401 | var points = line.points; |
| 13402 | var tpoints = target.points; |
| 13403 | var parts = []; |
| 13404 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 13405 | try { |
| 13406 | for(var _iterator = segments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 13407 | var segment = _step.value; |
| 13408 | var start = segment.start, end = segment.end; |
| 13409 | end = _findSegmentEnd(start, end, points); |
| 13410 | var bounds = _getBounds(property, points[start], points[end], segment.loop); |
| 13411 | if (!target.segments) { |
| 13412 | parts.push({ |
| 13413 | source: segment, |
| 13414 | target: bounds, |
| 13415 | start: points[start], |
| 13416 | end: points[end] |
| 13417 | }); |
| 13418 | continue; |
| 13419 | } |
| 13420 | var targetSegments = (0, _helpersSegmentJs.am)(target, bounds); |
| 13421 | var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; |
| 13422 | try { |
| 13423 | for(var _iterator1 = targetSegments[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ |
| 13424 | var tgt = _step1.value; |
| 13425 | var subBounds = _getBounds(property, tpoints[tgt.start], tpoints[tgt.end], tgt.loop); |
| 13426 | var fillSources = (0, _helpersSegmentJs.aw)(segment, points, subBounds); |
| 13427 | var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined; |
| 13428 | try { |
| 13429 | for(var _iterator2 = fillSources[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){ |
| 13430 | var fillSource = _step2.value; |
| 13431 | parts.push({ |
| 13432 | source: fillSource, |
| 13433 | target: tgt, |
| 13434 | start: (0, _definePropertyJsDefault.default)({}, property, _getEdge(bounds, subBounds, "start", Math.max)), |
| 13435 | end: (0, _definePropertyJsDefault.default)({}, property, _getEdge(bounds, subBounds, "end", Math.min)) |
| 13436 | }); |
| 13437 | } |
| 13438 | } catch (err) { |
| 13439 | _didIteratorError2 = true; |
| 13440 | _iteratorError2 = err; |
| 13441 | } finally{ |
| 13442 | try { |
| 13443 | if (!_iteratorNormalCompletion2 && _iterator2.return != null) { |
| 13444 | _iterator2.return(); |
| 13445 | } |
| 13446 | } finally{ |
| 13447 | if (_didIteratorError2) { |
| 13448 | throw _iteratorError2; |
| 13449 | } |
| 13450 | } |
| 13451 | } |
| 13452 | } |
| 13453 | } catch (err) { |
| 13454 | _didIteratorError1 = true; |
| 13455 | _iteratorError1 = err; |
| 13456 | } finally{ |
| 13457 | try { |
| 13458 | if (!_iteratorNormalCompletion1 && _iterator1.return != null) { |
| 13459 | _iterator1.return(); |
| 13460 | } |
| 13461 | } finally{ |
| 13462 | if (_didIteratorError1) { |
| 13463 | throw _iteratorError1; |
| 13464 | } |
| 13465 | } |
| 13466 | } |
| 13467 | } |
| 13468 | } catch (err) { |
| 13469 | _didIteratorError = true; |
| 13470 | _iteratorError = err; |
| 13471 | } finally{ |
| 13472 | try { |
| 13473 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 13474 | _iterator.return(); |
| 13475 | } |
| 13476 | } finally{ |
| 13477 | if (_didIteratorError) { |
| 13478 | throw _iteratorError; |
| 13479 | } |
| 13480 | } |
| 13481 | } |
| 13482 | return parts; |
| 13483 | } |
| 13484 | function _getBounds(property, first, last, loop) { |
| 13485 | if (loop) return; |
| 13486 | var start = first[property]; |
| 13487 | var end = last[property]; |
| 13488 | if (property === "angle") { |
| 13489 | start = (0, _helpersSegmentJs.ax)(start); |
| 13490 | end = (0, _helpersSegmentJs.ax)(end); |
| 13491 | } |
| 13492 | return { |
| 13493 | property: property, |
| 13494 | start: start, |
| 13495 | end: end |
| 13496 | }; |
| 13497 | } |
| 13498 | function _pointsFromSegments(boundary, line) { |
| 13499 | var ref = boundary || {}, _x = ref.x, x = _x === void 0 ? null : _x, _y = ref.y, y = _y === void 0 ? null : _y; |
| 13500 | var linePoints = line.points; |
| 13501 | var points = []; |
| 13502 | line.segments.forEach(function(param) { |
| 13503 | var start = param.start, end = param.end; |
| 13504 | end = _findSegmentEnd(start, end, linePoints); |
| 13505 | var first = linePoints[start]; |
| 13506 | var last = linePoints[end]; |
| 13507 | if (y !== null) { |
| 13508 | points.push({ |
| 13509 | x: first.x, |
| 13510 | y: y |
| 13511 | }); |
| 13512 | points.push({ |
| 13513 | x: last.x, |
| 13514 | y: y |
| 13515 | }); |
| 13516 | } else if (x !== null) { |
| 13517 | points.push({ |
| 13518 | x: x, |
| 13519 | y: first.y |
| 13520 | }); |
| 13521 | points.push({ |
| 13522 | x: x, |
| 13523 | y: last.y |
| 13524 | }); |
| 13525 | } |
| 13526 | }); |
| 13527 | return points; |
| 13528 | } |
| 13529 | function _findSegmentEnd(start, end, points) { |
| 13530 | for(; end > start; end--){ |
| 13531 | var point = points[end]; |
| 13532 | if (!isNaN(point.x) && !isNaN(point.y)) break; |
| 13533 | } |
| 13534 | return end; |
| 13535 | } |
| 13536 | function _getEdge(a, b, prop, fn) { |
| 13537 | if (a && b) return fn(a[prop], b[prop]); |
| 13538 | return a ? a[prop] : b ? b[prop] : 0; |
| 13539 | } |
| 13540 | function _createBoundaryLine(boundary, line) { |
| 13541 | var points = []; |
| 13542 | var _loop = false; |
| 13543 | if ((0, _helpersSegmentJs.b)(boundary)) { |
| 13544 | _loop = true; |
| 13545 | points = boundary; |
| 13546 | } else points = _pointsFromSegments(boundary, line); |
| 13547 | return points.length ? new LineElement({ |
| 13548 | points: points, |
| 13549 | options: { |
| 13550 | tension: 0 |
| 13551 | }, |
| 13552 | _loop: _loop, |
| 13553 | _fullLoop: _loop |
| 13554 | }) : null; |
| 13555 | } |
| 13556 | function _resolveTarget(sources, index57, propagate) { |
| 13557 | var source = sources[index57]; |
| 13558 | var fill1 = source.fill; |
| 13559 | var visited = [ |
| 13560 | index57 |
| 13561 | ]; |
| 13562 | var target; |
| 13563 | if (!propagate) return fill1; |
| 13564 | while(fill1 !== false && visited.indexOf(fill1) === -1){ |
| 13565 | if (!(0, _helpersSegmentJs.g)(fill1)) return fill1; |
| 13566 | target = sources[fill1]; |
| 13567 | if (!target) return false; |
| 13568 | if (target.visible) return fill1; |
| 13569 | visited.push(fill1); |
| 13570 | fill1 = target.fill; |
| 13571 | } |
| 13572 | return false; |
| 13573 | } |
| 13574 | function _decodeFill(line, index58, count) { |
| 13575 | var fill2 = parseFillOption(line); |
| 13576 | if ((0, _helpersSegmentJs.i)(fill2)) return isNaN(fill2.value) ? false : fill2; |
| 13577 | var target = parseFloat(fill2); |
| 13578 | if ((0, _helpersSegmentJs.g)(target) && Math.floor(target) === target) return decodeTargetIndex(fill2[0], index58, target, count); |
| 13579 | return [ |
| 13580 | "origin", |
| 13581 | "start", |
| 13582 | "end", |
| 13583 | "stack", |
| 13584 | "shape" |
| 13585 | ].indexOf(fill2) >= 0 && fill2; |
| 13586 | } |
| 13587 | function decodeTargetIndex(firstCh, index59, target, count) { |
| 13588 | if (firstCh === "-" || firstCh === "+") target = index59 + target; |
| 13589 | if (target === index59 || target < 0 || target >= count) return false; |
| 13590 | return target; |
| 13591 | } |
| 13592 | function _getTargetPixel(fill3, scale) { |
| 13593 | var pixel = null; |
| 13594 | if (fill3 === "start") pixel = scale.bottom; |
| 13595 | else if (fill3 === "end") pixel = scale.top; |
| 13596 | else if ((0, _helpersSegmentJs.i)(fill3)) pixel = scale.getPixelForValue(fill3.value); |
| 13597 | else if (scale.getBasePixel) pixel = scale.getBasePixel(); |
| 13598 | return pixel; |
| 13599 | } |
| 13600 | function _getTargetValue(fill4, scale, startValue) { |
| 13601 | var value; |
| 13602 | if (fill4 === "start") value = startValue; |
| 13603 | else if (fill4 === "end") value = scale.options.reverse ? scale.min : scale.max; |
| 13604 | else if ((0, _helpersSegmentJs.i)(fill4)) value = fill4.value; |
| 13605 | else value = scale.getBaseValue(); |
| 13606 | return value; |
| 13607 | } |
| 13608 | function parseFillOption(line) { |
| 13609 | var options = line.options; |
| 13610 | var fillOption = options.fill; |
| 13611 | var fill5 = (0, _helpersSegmentJs.v)(fillOption && fillOption.target, fillOption); |
| 13612 | if (fill5 === undefined) fill5 = !!options.backgroundColor; |
| 13613 | if (fill5 === false || fill5 === null) return false; |
| 13614 | if (fill5 === true) return "origin"; |
| 13615 | return fill5; |
| 13616 | } |
| 13617 | function _buildStackLine(source) { |
| 13618 | var scale = source.scale, index60 = source.index, line = source.line; |
| 13619 | var points = []; |
| 13620 | var segments = line.segments; |
| 13621 | var sourcePoints = line.points; |
| 13622 | var linesBelow = getLinesBelow(scale, index60); |
| 13623 | linesBelow.push(_createBoundaryLine({ |
| 13624 | x: null, |
| 13625 | y: scale.bottom |
| 13626 | }, line)); |
| 13627 | for(var i = 0; i < segments.length; i++){ |
| 13628 | var segment = segments[i]; |
| 13629 | for(var j = segment.start; j <= segment.end; j++)addPointsBelow(points, sourcePoints[j], linesBelow); |
| 13630 | } |
| 13631 | return new LineElement({ |
| 13632 | points: points, |
| 13633 | options: {} |
| 13634 | }); |
| 13635 | } |
| 13636 | function getLinesBelow(scale, index61) { |
| 13637 | var below = []; |
| 13638 | var metas = scale.getMatchingVisibleMetas("line"); |
| 13639 | for(var i = 0; i < metas.length; i++){ |
| 13640 | var meta = metas[i]; |
| 13641 | if (meta.index === index61) break; |
| 13642 | if (!meta.hidden) below.unshift(meta.dataset); |
| 13643 | } |
| 13644 | return below; |
| 13645 | } |
| 13646 | function addPointsBelow(points, sourcePoint, linesBelow) { |
| 13647 | var _points; |
| 13648 | var postponed = []; |
| 13649 | for(var j = 0; j < linesBelow.length; j++){ |
| 13650 | var line = linesBelow[j]; |
| 13651 | var ref = findPoint(line, sourcePoint, "x"), first = ref.first, last = ref.last, point = ref.point; |
| 13652 | if (!point || first && last) continue; |
| 13653 | if (first) postponed.unshift(point); |
| 13654 | else { |
| 13655 | points.push(point); |
| 13656 | if (!last) break; |
| 13657 | } |
| 13658 | } |
| 13659 | (_points = points).push.apply(_points, (0, _toConsumableArrayJsDefault.default)(postponed)); |
| 13660 | } |
| 13661 | function findPoint(line, sourcePoint, property) { |
| 13662 | var point = line.interpolate(sourcePoint, property); |
| 13663 | if (!point) return {}; |
| 13664 | var pointValue = point[property]; |
| 13665 | var segments = line.segments; |
| 13666 | var linePoints = line.points; |
| 13667 | var first = false; |
| 13668 | var last = false; |
| 13669 | for(var i = 0; i < segments.length; i++){ |
| 13670 | var segment = segments[i]; |
| 13671 | var firstValue = linePoints[segment.start][property]; |
| 13672 | var lastValue = linePoints[segment.end][property]; |
| 13673 | if ((0, _helpersSegmentJs.ai)(pointValue, firstValue, lastValue)) { |
| 13674 | first = pointValue === firstValue; |
| 13675 | last = pointValue === lastValue; |
| 13676 | break; |
| 13677 | } |
| 13678 | } |
| 13679 | return { |
| 13680 | first: first, |
| 13681 | last: last, |
| 13682 | point: point |
| 13683 | }; |
| 13684 | } |
| 13685 | var simpleArc = /*#__PURE__*/ function() { |
| 13686 | "use strict"; |
| 13687 | function simpleArc(opts) { |
| 13688 | (0, _classCallCheckJsDefault.default)(this, simpleArc); |
| 13689 | this.x = opts.x; |
| 13690 | this.y = opts.y; |
| 13691 | this.radius = opts.radius; |
| 13692 | } |
| 13693 | (0, _createClassJsDefault.default)(simpleArc, [ |
| 13694 | { |
| 13695 | key: "pathSegment", |
| 13696 | value: function pathSegment(ctx, bounds, opts) { |
| 13697 | var ref = this, x = ref.x, y = ref.y, radius = ref.radius; |
| 13698 | bounds = bounds || { |
| 13699 | start: 0, |
| 13700 | end: (0, _helpersSegmentJs.T) |
| 13701 | }; |
| 13702 | ctx.arc(x, y, radius, bounds.end, bounds.start, true); |
| 13703 | return !opts.bounds; |
| 13704 | } |
| 13705 | }, |
| 13706 | { |
| 13707 | key: "interpolate", |
| 13708 | value: function interpolate(point) { |
| 13709 | var ref = this, x = ref.x, y = ref.y, radius = ref.radius; |
| 13710 | var angle = point.angle; |
| 13711 | return { |
| 13712 | x: x + Math.cos(angle) * radius, |
| 13713 | y: y + Math.sin(angle) * radius, |
| 13714 | angle: angle |
| 13715 | }; |
| 13716 | } |
| 13717 | } |
| 13718 | ]); |
| 13719 | return simpleArc; |
| 13720 | }(); |
| 13721 | function _getTarget(source) { |
| 13722 | var chart = source.chart, fill6 = source.fill, line = source.line; |
| 13723 | if ((0, _helpersSegmentJs.g)(fill6)) return getLineByIndex(chart, fill6); |
| 13724 | if (fill6 === "stack") return _buildStackLine(source); |
| 13725 | if (fill6 === "shape") return true; |
| 13726 | var boundary = computeBoundary(source); |
| 13727 | if (boundary instanceof simpleArc) return boundary; |
| 13728 | return _createBoundaryLine(boundary, line); |
| 13729 | } |
| 13730 | function getLineByIndex(chart, index62) { |
| 13731 | var meta = chart.getDatasetMeta(index62); |
| 13732 | var visible = meta && chart.isDatasetVisible(index62); |
| 13733 | return visible ? meta.dataset : null; |
| 13734 | } |
| 13735 | function computeBoundary(source) { |
| 13736 | var scale = source.scale || {}; |
| 13737 | if (scale.getPointPositionForValue) return computeCircularBoundary(source); |
| 13738 | return computeLinearBoundary(source); |
| 13739 | } |
| 13740 | function computeLinearBoundary(source) { |
| 13741 | var _scale = source.scale, scale = _scale === void 0 ? {} : _scale, fill7 = source.fill; |
| 13742 | var pixel = _getTargetPixel(fill7, scale); |
| 13743 | if ((0, _helpersSegmentJs.g)(pixel)) { |
| 13744 | var horizontal = scale.isHorizontal(); |
| 13745 | return { |
| 13746 | x: horizontal ? pixel : null, |
| 13747 | y: horizontal ? null : pixel |
| 13748 | }; |
| 13749 | } |
| 13750 | return null; |
| 13751 | } |
| 13752 | function computeCircularBoundary(source) { |
| 13753 | var scale = source.scale, fill8 = source.fill; |
| 13754 | var options = scale.options; |
| 13755 | var length = scale.getLabels().length; |
| 13756 | var start = options.reverse ? scale.max : scale.min; |
| 13757 | var value = _getTargetValue(fill8, scale, start); |
| 13758 | var target = []; |
| 13759 | if (options.grid.circular) { |
| 13760 | var center = scale.getPointPositionForValue(0, start); |
| 13761 | return new simpleArc({ |
| 13762 | x: center.x, |
| 13763 | y: center.y, |
| 13764 | radius: scale.getDistanceFromCenterForValue(value) |
| 13765 | }); |
| 13766 | } |
| 13767 | for(var i = 0; i < length; ++i)target.push(scale.getPointPositionForValue(i, value)); |
| 13768 | return target; |
| 13769 | } |
| 13770 | function _drawfill(ctx, source, area) { |
| 13771 | var target = _getTarget(source); |
| 13772 | var line = source.line, scale = source.scale, axis = source.axis; |
| 13773 | var lineOpts = line.options; |
| 13774 | var fillOption = lineOpts.fill; |
| 13775 | var color = lineOpts.backgroundColor; |
| 13776 | var ref = fillOption || {}, _above = ref.above, above = _above === void 0 ? color : _above, _below = ref.below, below = _below === void 0 ? color : _below; |
| 13777 | if (target && line.points.length) { |
| 13778 | (0, _helpersSegmentJs.X)(ctx, area); |
| 13779 | doFill(ctx, { |
| 13780 | line: line, |
| 13781 | target: target, |
| 13782 | above: above, |
| 13783 | below: below, |
| 13784 | area: area, |
| 13785 | scale: scale, |
| 13786 | axis: axis |
| 13787 | }); |
| 13788 | (0, _helpersSegmentJs.Z)(ctx); |
| 13789 | } |
| 13790 | } |
| 13791 | function doFill(ctx, cfg) { |
| 13792 | var line = cfg.line, target = cfg.target, above = cfg.above, below = cfg.below, area = cfg.area, scale = cfg.scale; |
| 13793 | var property = line._loop ? "angle" : cfg.axis; |
| 13794 | ctx.save(); |
| 13795 | if (property === "x" && below !== above) { |
| 13796 | clipVertical(ctx, target, area.top); |
| 13797 | fill(ctx, { |
| 13798 | line: line, |
| 13799 | target: target, |
| 13800 | color: above, |
| 13801 | scale: scale, |
| 13802 | property: property |
| 13803 | }); |
| 13804 | ctx.restore(); |
| 13805 | ctx.save(); |
| 13806 | clipVertical(ctx, target, area.bottom); |
| 13807 | } |
| 13808 | fill(ctx, { |
| 13809 | line: line, |
| 13810 | target: target, |
| 13811 | color: below, |
| 13812 | scale: scale, |
| 13813 | property: property |
| 13814 | }); |
| 13815 | ctx.restore(); |
| 13816 | } |
| 13817 | function clipVertical(ctx, target, clipY) { |
| 13818 | var segments = target.segments, points = target.points; |
| 13819 | var first = true; |
| 13820 | var lineLoop = false; |
| 13821 | ctx.beginPath(); |
| 13822 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 13823 | try { |
| 13824 | for(var _iterator = segments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 13825 | var segment = _step.value; |
| 13826 | var start = segment.start, end = segment.end; |
| 13827 | var firstPoint = points[start]; |
| 13828 | var lastPoint = points[_findSegmentEnd(start, end, points)]; |
| 13829 | if (first) { |
| 13830 | ctx.moveTo(firstPoint.x, firstPoint.y); |
| 13831 | first = false; |
| 13832 | } else { |
| 13833 | ctx.lineTo(firstPoint.x, clipY); |
| 13834 | ctx.lineTo(firstPoint.x, firstPoint.y); |
| 13835 | } |
| 13836 | lineLoop = !!target.pathSegment(ctx, segment, { |
| 13837 | move: lineLoop |
| 13838 | }); |
| 13839 | if (lineLoop) ctx.closePath(); |
| 13840 | else ctx.lineTo(lastPoint.x, clipY); |
| 13841 | } |
| 13842 | } catch (err) { |
| 13843 | _didIteratorError = true; |
| 13844 | _iteratorError = err; |
| 13845 | } finally{ |
| 13846 | try { |
| 13847 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 13848 | _iterator.return(); |
| 13849 | } |
| 13850 | } finally{ |
| 13851 | if (_didIteratorError) { |
| 13852 | throw _iteratorError; |
| 13853 | } |
| 13854 | } |
| 13855 | } |
| 13856 | ctx.lineTo(target.first().x, clipY); |
| 13857 | ctx.closePath(); |
| 13858 | ctx.clip(); |
| 13859 | } |
| 13860 | function fill(ctx, cfg) { |
| 13861 | var line = cfg.line, target = cfg.target, property = cfg.property, color = cfg.color, scale = cfg.scale; |
| 13862 | var segments = _segments(line, target, property); |
| 13863 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 13864 | try { |
| 13865 | for(var _iterator = segments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 13866 | var _value = _step.value, src = _value.source, tgt = _value.target, start = _value.start, end = _value.end; |
| 13867 | var tmp = src.style, ref = tmp === void 0 ? {} : tmp, _backgroundColor = ref.backgroundColor, backgroundColor = _backgroundColor === void 0 ? color : _backgroundColor; |
| 13868 | var notShape = target !== true; |
| 13869 | ctx.save(); |
| 13870 | ctx.fillStyle = backgroundColor; |
| 13871 | clipBounds(ctx, scale, notShape && _getBounds(property, start, end)); |
| 13872 | ctx.beginPath(); |
| 13873 | var lineLoop = !!line.pathSegment(ctx, src); |
| 13874 | var loop = void 0; |
| 13875 | if (notShape) { |
| 13876 | if (lineLoop) ctx.closePath(); |
| 13877 | else interpolatedLineTo(ctx, target, end, property); |
| 13878 | var targetLoop = !!target.pathSegment(ctx, tgt, { |
| 13879 | move: lineLoop, |
| 13880 | reverse: true |
| 13881 | }); |
| 13882 | loop = lineLoop && targetLoop; |
| 13883 | if (!loop) interpolatedLineTo(ctx, target, start, property); |
| 13884 | } |
| 13885 | ctx.closePath(); |
| 13886 | ctx.fill(loop ? "evenodd" : "nonzero"); |
| 13887 | ctx.restore(); |
| 13888 | } |
| 13889 | } catch (err) { |
| 13890 | _didIteratorError = true; |
| 13891 | _iteratorError = err; |
| 13892 | } finally{ |
| 13893 | try { |
| 13894 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 13895 | _iterator.return(); |
| 13896 | } |
| 13897 | } finally{ |
| 13898 | if (_didIteratorError) { |
| 13899 | throw _iteratorError; |
| 13900 | } |
| 13901 | } |
| 13902 | } |
| 13903 | } |
| 13904 | function clipBounds(ctx, scale, bounds) { |
| 13905 | var _chartArea = scale.chart.chartArea, top = _chartArea.top, bottom = _chartArea.bottom; |
| 13906 | var ref = bounds || {}, property = ref.property, start = ref.start, end = ref.end; |
| 13907 | if (property === "x") { |
| 13908 | ctx.beginPath(); |
| 13909 | ctx.rect(start, top, end - start, bottom - top); |
| 13910 | ctx.clip(); |
| 13911 | } |
| 13912 | } |
| 13913 | function interpolatedLineTo(ctx, target, point, property) { |
| 13914 | var interpolatedPoint = target.interpolate(point, property); |
| 13915 | if (interpolatedPoint) ctx.lineTo(interpolatedPoint.x, interpolatedPoint.y); |
| 13916 | } |
| 13917 | var index = { |
| 13918 | id: "filler", |
| 13919 | afterDatasetsUpdate: function(chart, _args, options) { |
| 13920 | var count = (chart.data.datasets || []).length; |
| 13921 | var sources = []; |
| 13922 | var meta, i, line, source; |
| 13923 | for(i = 0; i < count; ++i){ |
| 13924 | meta = chart.getDatasetMeta(i); |
| 13925 | line = meta.dataset; |
| 13926 | source = null; |
| 13927 | if (line && line.options && line instanceof LineElement) source = { |
| 13928 | visible: chart.isDatasetVisible(i), |
| 13929 | index: i, |
| 13930 | fill: _decodeFill(line, i, count), |
| 13931 | chart: chart, |
| 13932 | axis: meta.controller.options.indexAxis, |
| 13933 | scale: meta.vScale, |
| 13934 | line: line |
| 13935 | }; |
| 13936 | meta.$filler = source; |
| 13937 | sources.push(source); |
| 13938 | } |
| 13939 | for(i = 0; i < count; ++i){ |
| 13940 | source = sources[i]; |
| 13941 | if (!source || source.fill === false) continue; |
| 13942 | source.fill = _resolveTarget(sources, i, options.propagate); |
| 13943 | } |
| 13944 | }, |
| 13945 | beforeDraw: function(chart, _args, options) { |
| 13946 | var draw3 = options.drawTime === "beforeDraw"; |
| 13947 | var metasets = chart.getSortedVisibleDatasetMetas(); |
| 13948 | var area = chart.chartArea; |
| 13949 | for(var i = metasets.length - 1; i >= 0; --i){ |
| 13950 | var source = metasets[i].$filler; |
| 13951 | if (!source) continue; |
| 13952 | source.line.updateControlPoints(area, source.axis); |
| 13953 | if (draw3) _drawfill(chart.ctx, source, area); |
| 13954 | } |
| 13955 | }, |
| 13956 | beforeDatasetsDraw: function(chart, _args, options) { |
| 13957 | if (options.drawTime !== "beforeDatasetsDraw") return; |
| 13958 | var metasets = chart.getSortedVisibleDatasetMetas(); |
| 13959 | for(var i = metasets.length - 1; i >= 0; --i){ |
| 13960 | var source = metasets[i].$filler; |
| 13961 | if (source) _drawfill(chart.ctx, source, chart.chartArea); |
| 13962 | } |
| 13963 | }, |
| 13964 | beforeDatasetDraw: function(chart, args, options) { |
| 13965 | var source = args.meta.$filler; |
| 13966 | if (!source || source.fill === false || options.drawTime !== "beforeDatasetDraw") return; |
| 13967 | _drawfill(chart.ctx, source, chart.chartArea); |
| 13968 | }, |
| 13969 | defaults: { |
| 13970 | propagate: true, |
| 13971 | drawTime: "beforeDatasetDraw" |
| 13972 | } |
| 13973 | }; |
| 13974 | var getBoxSize = function(labelOpts, fontSize) { |
| 13975 | var _boxHeight = labelOpts.boxHeight, boxHeight = _boxHeight === void 0 ? fontSize : _boxHeight, _boxWidth = labelOpts.boxWidth, boxWidth = _boxWidth === void 0 ? fontSize : _boxWidth; |
| 13976 | if (labelOpts.usePointStyle) { |
| 13977 | boxHeight = Math.min(boxHeight, fontSize); |
| 13978 | boxWidth = Math.min(boxWidth, fontSize); |
| 13979 | } |
| 13980 | return { |
| 13981 | boxWidth: boxWidth, |
| 13982 | boxHeight: boxHeight, |
| 13983 | itemHeight: Math.max(fontSize, boxHeight) |
| 13984 | }; |
| 13985 | }; |
| 13986 | var itemsEqual = function(a, b) { |
| 13987 | return a !== null && b !== null && a.datasetIndex === b.datasetIndex && a.index === b.index; |
| 13988 | }; |
| 13989 | var Legend = /*#__PURE__*/ function(Element) { |
| 13990 | "use strict"; |
| 13991 | (0, _inheritsJsDefault.default)(Legend, Element); |
| 13992 | var _super = (0, _createSuperJsDefault.default)(Legend); |
| 13993 | function Legend(config) { |
| 13994 | (0, _classCallCheckJsDefault.default)(this, Legend); |
| 13995 | var _this; |
| 13996 | _this = _super.call(this); |
| 13997 | _this._added = false; |
| 13998 | _this.legendHitBoxes = []; |
| 13999 | _this._hoveredItem = null; |
| 14000 | _this.doughnutMode = false; |
| 14001 | _this.chart = config.chart; |
| 14002 | _this.options = config.options; |
| 14003 | _this.ctx = config.ctx; |
| 14004 | _this.legendItems = undefined; |
| 14005 | _this.columnSizes = undefined; |
| 14006 | _this.lineWidths = undefined; |
| 14007 | _this.maxHeight = undefined; |
| 14008 | _this.maxWidth = undefined; |
| 14009 | _this.top = undefined; |
| 14010 | _this.bottom = undefined; |
| 14011 | _this.left = undefined; |
| 14012 | _this.right = undefined; |
| 14013 | _this.height = undefined; |
| 14014 | _this.width = undefined; |
| 14015 | _this._margins = undefined; |
| 14016 | _this.position = undefined; |
| 14017 | _this.weight = undefined; |
| 14018 | _this.fullSize = undefined; |
| 14019 | return _this; |
| 14020 | } |
| 14021 | (0, _createClassJsDefault.default)(Legend, [ |
| 14022 | { |
| 14023 | key: "update", |
| 14024 | value: function update(maxWidth, maxHeight, margins) { |
| 14025 | this.maxWidth = maxWidth; |
| 14026 | this.maxHeight = maxHeight; |
| 14027 | this._margins = margins; |
| 14028 | this.setDimensions(); |
| 14029 | this.buildLabels(); |
| 14030 | this.fit(); |
| 14031 | } |
| 14032 | }, |
| 14033 | { |
| 14034 | key: "setDimensions", |
| 14035 | value: function setDimensions() { |
| 14036 | if (this.isHorizontal()) { |
| 14037 | this.width = this.maxWidth; |
| 14038 | this.left = this._margins.left; |
| 14039 | this.right = this.width; |
| 14040 | } else { |
| 14041 | this.height = this.maxHeight; |
| 14042 | this.top = this._margins.top; |
| 14043 | this.bottom = this.height; |
| 14044 | } |
| 14045 | } |
| 14046 | }, |
| 14047 | { |
| 14048 | key: "buildLabels", |
| 14049 | value: function buildLabels() { |
| 14050 | var _this = this; |
| 14051 | var labelOpts = this.options.labels || {}; |
| 14052 | var legendItems = (0, _helpersSegmentJs.Q)(labelOpts.generateLabels, [ |
| 14053 | this.chart |
| 14054 | ], this) || []; |
| 14055 | if (labelOpts.filter) legendItems = legendItems.filter(function(item) { |
| 14056 | return labelOpts.filter(item, _this.chart.data); |
| 14057 | }); |
| 14058 | if (labelOpts.sort) legendItems = legendItems.sort(function(a, b) { |
| 14059 | return labelOpts.sort(a, b, _this.chart.data); |
| 14060 | }); |
| 14061 | if (this.options.reverse) legendItems.reverse(); |
| 14062 | this.legendItems = legendItems; |
| 14063 | } |
| 14064 | }, |
| 14065 | { |
| 14066 | key: "fit", |
| 14067 | value: function fit() { |
| 14068 | var ref = this, options = ref.options, ctx = ref.ctx; |
| 14069 | if (!options.display) { |
| 14070 | this.width = this.height = 0; |
| 14071 | return; |
| 14072 | } |
| 14073 | var labelOpts = options.labels; |
| 14074 | var labelFont = (0, _helpersSegmentJs.$)(labelOpts.font); |
| 14075 | var fontSize = labelFont.size; |
| 14076 | var titleHeight = this._computeTitleHeight(); |
| 14077 | var ref10 = getBoxSize(labelOpts, fontSize), boxWidth = ref10.boxWidth, itemHeight = ref10.itemHeight; |
| 14078 | var width, height; |
| 14079 | ctx.font = labelFont.string; |
| 14080 | if (this.isHorizontal()) { |
| 14081 | width = this.maxWidth; |
| 14082 | height = this._fitRows(titleHeight, fontSize, boxWidth, itemHeight) + 10; |
| 14083 | } else { |
| 14084 | height = this.maxHeight; |
| 14085 | width = this._fitCols(titleHeight, fontSize, boxWidth, itemHeight) + 10; |
| 14086 | } |
| 14087 | this.width = Math.min(width, options.maxWidth || this.maxWidth); |
| 14088 | this.height = Math.min(height, options.maxHeight || this.maxHeight); |
| 14089 | } |
| 14090 | }, |
| 14091 | { |
| 14092 | key: "_fitRows", |
| 14093 | value: function _fitRows(titleHeight, fontSize, boxWidth, itemHeight) { |
| 14094 | var ref = this, ctx = ref.ctx, maxWidth = ref.maxWidth, _options = ref.options, padding = _options.labels.padding; |
| 14095 | var hitboxes = this.legendHitBoxes = []; |
| 14096 | var lineWidths = this.lineWidths = [ |
| 14097 | 0 |
| 14098 | ]; |
| 14099 | var lineHeight = itemHeight + padding; |
| 14100 | var totalHeight = titleHeight; |
| 14101 | ctx.textAlign = "left"; |
| 14102 | ctx.textBaseline = "middle"; |
| 14103 | var row = -1; |
| 14104 | var top = -lineHeight; |
| 14105 | this.legendItems.forEach(function(legendItem, i) { |
| 14106 | var itemWidth = boxWidth + fontSize / 2 + ctx.measureText(legendItem.text).width; |
| 14107 | if (i === 0 || lineWidths[lineWidths.length - 1] + itemWidth + 2 * padding > maxWidth) { |
| 14108 | totalHeight += lineHeight; |
| 14109 | lineWidths[lineWidths.length - (i > 0 ? 0 : 1)] = 0; |
| 14110 | top += lineHeight; |
| 14111 | row++; |
| 14112 | } |
| 14113 | hitboxes[i] = { |
| 14114 | left: 0, |
| 14115 | top: top, |
| 14116 | row: row, |
| 14117 | width: itemWidth, |
| 14118 | height: itemHeight |
| 14119 | }; |
| 14120 | lineWidths[lineWidths.length - 1] += itemWidth + padding; |
| 14121 | }); |
| 14122 | return totalHeight; |
| 14123 | } |
| 14124 | }, |
| 14125 | { |
| 14126 | key: "_fitCols", |
| 14127 | value: function _fitCols(titleHeight, fontSize, boxWidth, itemHeight) { |
| 14128 | var ref = this, ctx = ref.ctx, maxHeight = ref.maxHeight, _options = ref.options, padding = _options.labels.padding; |
| 14129 | var hitboxes = this.legendHitBoxes = []; |
| 14130 | var columnSizes = this.columnSizes = []; |
| 14131 | var heightLimit = maxHeight - titleHeight; |
| 14132 | var totalWidth = padding; |
| 14133 | var currentColWidth = 0; |
| 14134 | var currentColHeight = 0; |
| 14135 | var left = 0; |
| 14136 | var col = 0; |
| 14137 | this.legendItems.forEach(function(legendItem, i) { |
| 14138 | var itemWidth = boxWidth + fontSize / 2 + ctx.measureText(legendItem.text).width; |
| 14139 | if (i > 0 && currentColHeight + itemHeight + 2 * padding > heightLimit) { |
| 14140 | totalWidth += currentColWidth + padding; |
| 14141 | columnSizes.push({ |
| 14142 | width: currentColWidth, |
| 14143 | height: currentColHeight |
| 14144 | }); |
| 14145 | left += currentColWidth + padding; |
| 14146 | col++; |
| 14147 | currentColWidth = currentColHeight = 0; |
| 14148 | } |
| 14149 | hitboxes[i] = { |
| 14150 | left: left, |
| 14151 | top: currentColHeight, |
| 14152 | col: col, |
| 14153 | width: itemWidth, |
| 14154 | height: itemHeight |
| 14155 | }; |
| 14156 | currentColWidth = Math.max(currentColWidth, itemWidth); |
| 14157 | currentColHeight += itemHeight + padding; |
| 14158 | }); |
| 14159 | totalWidth += currentColWidth; |
| 14160 | columnSizes.push({ |
| 14161 | width: currentColWidth, |
| 14162 | height: currentColHeight |
| 14163 | }); |
| 14164 | return totalWidth; |
| 14165 | } |
| 14166 | }, |
| 14167 | { |
| 14168 | key: "adjustHitBoxes", |
| 14169 | value: function adjustHitBoxes() { |
| 14170 | if (!this.options.display) return; |
| 14171 | var titleHeight = this._computeTitleHeight(); |
| 14172 | var ref = this, hitboxes = ref.legendHitBoxes, _options = ref.options, align = _options.align, padding = _options.labels.padding, rtl = _options.rtl; |
| 14173 | var rtlHelper = (0, _helpersSegmentJs.ay)(rtl, this.left, this.width); |
| 14174 | if (this.isHorizontal()) { |
| 14175 | var row = 0; |
| 14176 | var left = (0, _helpersSegmentJs.a1)(align, this.left + padding, this.right - this.lineWidths[row]); |
| 14177 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 14178 | try { |
| 14179 | for(var _iterator = hitboxes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 14180 | var hitbox = _step.value; |
| 14181 | if (row !== hitbox.row) { |
| 14182 | row = hitbox.row; |
| 14183 | left = (0, _helpersSegmentJs.a1)(align, this.left + padding, this.right - this.lineWidths[row]); |
| 14184 | } |
| 14185 | hitbox.top += this.top + titleHeight + padding; |
| 14186 | hitbox.left = rtlHelper.leftForLtr(rtlHelper.x(left), hitbox.width); |
| 14187 | left += hitbox.width + padding; |
| 14188 | } |
| 14189 | } catch (err) { |
| 14190 | _didIteratorError = true; |
| 14191 | _iteratorError = err; |
| 14192 | } finally{ |
| 14193 | try { |
| 14194 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 14195 | _iterator.return(); |
| 14196 | } |
| 14197 | } finally{ |
| 14198 | if (_didIteratorError) { |
| 14199 | throw _iteratorError; |
| 14200 | } |
| 14201 | } |
| 14202 | } |
| 14203 | } else { |
| 14204 | var col = 0; |
| 14205 | var top = (0, _helpersSegmentJs.a1)(align, this.top + titleHeight + padding, this.bottom - this.columnSizes[col].height); |
| 14206 | var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined; |
| 14207 | try { |
| 14208 | for(var _iterator3 = hitboxes[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){ |
| 14209 | var hitbox1 = _step3.value; |
| 14210 | if (hitbox1.col !== col) { |
| 14211 | col = hitbox1.col; |
| 14212 | top = (0, _helpersSegmentJs.a1)(align, this.top + titleHeight + padding, this.bottom - this.columnSizes[col].height); |
| 14213 | } |
| 14214 | hitbox1.top = top; |
| 14215 | hitbox1.left += this.left + padding; |
| 14216 | hitbox1.left = rtlHelper.leftForLtr(rtlHelper.x(hitbox1.left), hitbox1.width); |
| 14217 | top += hitbox1.height + padding; |
| 14218 | } |
| 14219 | } catch (err) { |
| 14220 | _didIteratorError3 = true; |
| 14221 | _iteratorError3 = err; |
| 14222 | } finally{ |
| 14223 | try { |
| 14224 | if (!_iteratorNormalCompletion3 && _iterator3.return != null) { |
| 14225 | _iterator3.return(); |
| 14226 | } |
| 14227 | } finally{ |
| 14228 | if (_didIteratorError3) { |
| 14229 | throw _iteratorError3; |
| 14230 | } |
| 14231 | } |
| 14232 | } |
| 14233 | } |
| 14234 | } |
| 14235 | }, |
| 14236 | { |
| 14237 | key: "isHorizontal", |
| 14238 | value: function isHorizontal() { |
| 14239 | return this.options.position === "top" || this.options.position === "bottom"; |
| 14240 | } |
| 14241 | }, |
| 14242 | { |
| 14243 | key: "draw", |
| 14244 | value: function draw2() { |
| 14245 | if (this.options.display) { |
| 14246 | var ctx = this.ctx; |
| 14247 | (0, _helpersSegmentJs.X)(ctx, this); |
| 14248 | this._draw(); |
| 14249 | (0, _helpersSegmentJs.Z)(ctx); |
| 14250 | } |
| 14251 | } |
| 14252 | }, |
| 14253 | { |
| 14254 | key: "_draw", |
| 14255 | value: function _draw() { |
| 14256 | var _this = this; |
| 14257 | var ref = this, opts = ref.options, columnSizes = ref.columnSizes, lineWidths = ref.lineWidths, ctx = ref.ctx; |
| 14258 | var align = opts.align, labelOpts = opts.labels; |
| 14259 | var defaultColor = (0, _helpersSegmentJs.d).color; |
| 14260 | var rtlHelper = (0, _helpersSegmentJs.ay)(opts.rtl, this.left, this.width); |
| 14261 | var labelFont = (0, _helpersSegmentJs.$)(labelOpts.font); |
| 14262 | var fontColor = labelOpts.color, padding = labelOpts.padding; |
| 14263 | var fontSize = labelFont.size; |
| 14264 | var halfFontSize = fontSize / 2; |
| 14265 | var cursor; |
| 14266 | this.drawTitle(); |
| 14267 | ctx.textAlign = rtlHelper.textAlign("left"); |
| 14268 | ctx.textBaseline = "middle"; |
| 14269 | ctx.lineWidth = 0.5; |
| 14270 | ctx.font = labelFont.string; |
| 14271 | var ref11 = getBoxSize(labelOpts, fontSize), boxWidth = ref11.boxWidth, boxHeight = ref11.boxHeight, itemHeight = ref11.itemHeight; |
| 14272 | var drawLegendBox = function drawLegendBox(x, y, legendItem) { |
| 14273 | if (isNaN(boxWidth) || boxWidth <= 0 || isNaN(boxHeight) || boxHeight < 0) return; |
| 14274 | ctx.save(); |
| 14275 | var lineWidth = (0, _helpersSegmentJs.v)(legendItem.lineWidth, 1); |
| 14276 | ctx.fillStyle = (0, _helpersSegmentJs.v)(legendItem.fillStyle, defaultColor); |
| 14277 | ctx.lineCap = (0, _helpersSegmentJs.v)(legendItem.lineCap, "butt"); |
| 14278 | ctx.lineDashOffset = (0, _helpersSegmentJs.v)(legendItem.lineDashOffset, 0); |
| 14279 | ctx.lineJoin = (0, _helpersSegmentJs.v)(legendItem.lineJoin, "miter"); |
| 14280 | ctx.lineWidth = lineWidth; |
| 14281 | ctx.strokeStyle = (0, _helpersSegmentJs.v)(legendItem.strokeStyle, defaultColor); |
| 14282 | ctx.setLineDash((0, _helpersSegmentJs.v)(legendItem.lineDash, [])); |
| 14283 | if (labelOpts.usePointStyle) { |
| 14284 | var drawOptions = { |
| 14285 | radius: boxWidth * Math.SQRT2 / 2, |
| 14286 | pointStyle: legendItem.pointStyle, |
| 14287 | rotation: legendItem.rotation, |
| 14288 | borderWidth: lineWidth |
| 14289 | }; |
| 14290 | var centerX = rtlHelper.xPlus(x, boxWidth / 2); |
| 14291 | var centerY = y + halfFontSize; |
| 14292 | (0, _helpersSegmentJs.as)(ctx, drawOptions, centerX, centerY); |
| 14293 | } else { |
| 14294 | var yBoxTop = y + Math.max((fontSize - boxHeight) / 2, 0); |
| 14295 | var xBoxLeft = rtlHelper.leftForLtr(x, boxWidth); |
| 14296 | var borderRadius = (0, _helpersSegmentJs.av)(legendItem.borderRadius); |
| 14297 | ctx.beginPath(); |
| 14298 | if (Object.values(borderRadius).some(function(v) { |
| 14299 | return v !== 0; |
| 14300 | })) (0, _helpersSegmentJs.at)(ctx, { |
| 14301 | x: xBoxLeft, |
| 14302 | y: yBoxTop, |
| 14303 | w: boxWidth, |
| 14304 | h: boxHeight, |
| 14305 | radius: borderRadius |
| 14306 | }); |
| 14307 | else ctx.rect(xBoxLeft, yBoxTop, boxWidth, boxHeight); |
| 14308 | ctx.fill(); |
| 14309 | if (lineWidth !== 0) ctx.stroke(); |
| 14310 | } |
| 14311 | ctx.restore(); |
| 14312 | }; |
| 14313 | var fillText = function fillText(x, y, legendItem) { |
| 14314 | (0, _helpersSegmentJs.Y)(ctx, legendItem.text, x, y + itemHeight / 2, labelFont, { |
| 14315 | strikethrough: legendItem.hidden, |
| 14316 | textAlign: rtlHelper.textAlign(legendItem.textAlign) |
| 14317 | }); |
| 14318 | }; |
| 14319 | var isHorizontal = this.isHorizontal(); |
| 14320 | var titleHeight = this._computeTitleHeight(); |
| 14321 | if (isHorizontal) cursor = { |
| 14322 | x: (0, _helpersSegmentJs.a1)(align, this.left + padding, this.right - lineWidths[0]), |
| 14323 | y: this.top + padding + titleHeight, |
| 14324 | line: 0 |
| 14325 | }; |
| 14326 | else cursor = { |
| 14327 | x: this.left + padding, |
| 14328 | y: (0, _helpersSegmentJs.a1)(align, this.top + titleHeight + padding, this.bottom - columnSizes[0].height), |
| 14329 | line: 0 |
| 14330 | }; |
| 14331 | (0, _helpersSegmentJs.az)(this.ctx, opts.textDirection); |
| 14332 | var lineHeight = itemHeight + padding; |
| 14333 | this.legendItems.forEach(function(legendItem, i) { |
| 14334 | ctx.strokeStyle = legendItem.fontColor || fontColor; |
| 14335 | ctx.fillStyle = legendItem.fontColor || fontColor; |
| 14336 | var textWidth = ctx.measureText(legendItem.text).width; |
| 14337 | var textAlign = rtlHelper.textAlign(legendItem.textAlign || (legendItem.textAlign = labelOpts.textAlign)); |
| 14338 | var width = boxWidth + halfFontSize + textWidth; |
| 14339 | var x = cursor.x; |
| 14340 | var y = cursor.y; |
| 14341 | rtlHelper.setWidth(_this.width); |
| 14342 | if (isHorizontal) { |
| 14343 | if (i > 0 && x + width + padding > _this.right) { |
| 14344 | y = cursor.y += lineHeight; |
| 14345 | cursor.line++; |
| 14346 | x = cursor.x = (0, _helpersSegmentJs.a1)(align, _this.left + padding, _this.right - lineWidths[cursor.line]); |
| 14347 | } |
| 14348 | } else if (i > 0 && y + lineHeight > _this.bottom) { |
| 14349 | x = cursor.x = x + columnSizes[cursor.line].width + padding; |
| 14350 | cursor.line++; |
| 14351 | y = cursor.y = (0, _helpersSegmentJs.a1)(align, _this.top + titleHeight + padding, _this.bottom - columnSizes[cursor.line].height); |
| 14352 | } |
| 14353 | var realX = rtlHelper.x(x); |
| 14354 | drawLegendBox(realX, y, legendItem); |
| 14355 | x = (0, _helpersSegmentJs.aA)(textAlign, x + boxWidth + halfFontSize, isHorizontal ? x + width : _this.right, opts.rtl); |
| 14356 | fillText(rtlHelper.x(x), y, legendItem); |
| 14357 | if (isHorizontal) cursor.x += width + padding; |
| 14358 | else cursor.y += lineHeight; |
| 14359 | }); |
| 14360 | (0, _helpersSegmentJs.aB)(this.ctx, opts.textDirection); |
| 14361 | } |
| 14362 | }, |
| 14363 | { |
| 14364 | key: "drawTitle", |
| 14365 | value: function drawTitle() { |
| 14366 | var opts = this.options; |
| 14367 | var titleOpts = opts.title; |
| 14368 | var titleFont = (0, _helpersSegmentJs.$)(titleOpts.font); |
| 14369 | var titlePadding = (0, _helpersSegmentJs.D)(titleOpts.padding); |
| 14370 | if (!titleOpts.display) return; |
| 14371 | var rtlHelper = (0, _helpersSegmentJs.ay)(opts.rtl, this.left, this.width); |
| 14372 | var ctx = this.ctx; |
| 14373 | var position = titleOpts.position; |
| 14374 | var halfFontSize = titleFont.size / 2; |
| 14375 | var topPaddingPlusHalfFontSize = titlePadding.top + halfFontSize; |
| 14376 | var y; |
| 14377 | var left = this.left; |
| 14378 | var maxWidth = this.width; |
| 14379 | if (this.isHorizontal()) { |
| 14380 | var _Math; |
| 14381 | maxWidth = (_Math = Math).max.apply(_Math, (0, _toConsumableArrayJsDefault.default)(this.lineWidths)); |
| 14382 | y = this.top + topPaddingPlusHalfFontSize; |
| 14383 | left = (0, _helpersSegmentJs.a1)(opts.align, left, this.right - maxWidth); |
| 14384 | } else { |
| 14385 | var maxHeight = this.columnSizes.reduce(function(acc, size) { |
| 14386 | return Math.max(acc, size.height); |
| 14387 | }, 0); |
| 14388 | y = topPaddingPlusHalfFontSize + (0, _helpersSegmentJs.a1)(opts.align, this.top, this.bottom - maxHeight - opts.labels.padding - this._computeTitleHeight()); |
| 14389 | } |
| 14390 | var x = (0, _helpersSegmentJs.a1)(position, left, left + maxWidth); |
| 14391 | ctx.textAlign = rtlHelper.textAlign((0, _helpersSegmentJs.a0)(position)); |
| 14392 | ctx.textBaseline = "middle"; |
| 14393 | ctx.strokeStyle = titleOpts.color; |
| 14394 | ctx.fillStyle = titleOpts.color; |
| 14395 | ctx.font = titleFont.string; |
| 14396 | (0, _helpersSegmentJs.Y)(ctx, titleOpts.text, x, y, titleFont); |
| 14397 | } |
| 14398 | }, |
| 14399 | { |
| 14400 | key: "_computeTitleHeight", |
| 14401 | value: function _computeTitleHeight() { |
| 14402 | var titleOpts = this.options.title; |
| 14403 | var titleFont = (0, _helpersSegmentJs.$)(titleOpts.font); |
| 14404 | var titlePadding = (0, _helpersSegmentJs.D)(titleOpts.padding); |
| 14405 | return titleOpts.display ? titleFont.lineHeight + titlePadding.height : 0; |
| 14406 | } |
| 14407 | }, |
| 14408 | { |
| 14409 | key: "_getLegendItemAt", |
| 14410 | value: function _getLegendItemAt(x, y) { |
| 14411 | var i, hitBox, lh; |
| 14412 | if ((0, _helpersSegmentJs.ai)(x, this.left, this.right) && (0, _helpersSegmentJs.ai)(y, this.top, this.bottom)) { |
| 14413 | lh = this.legendHitBoxes; |
| 14414 | for(i = 0; i < lh.length; ++i){ |
| 14415 | hitBox = lh[i]; |
| 14416 | if ((0, _helpersSegmentJs.ai)(x, hitBox.left, hitBox.left + hitBox.width) && (0, _helpersSegmentJs.ai)(y, hitBox.top, hitBox.top + hitBox.height)) return this.legendItems[i]; |
| 14417 | } |
| 14418 | } |
| 14419 | return null; |
| 14420 | } |
| 14421 | }, |
| 14422 | { |
| 14423 | key: "handleEvent", |
| 14424 | value: function handleEvent(e) { |
| 14425 | var opts = this.options; |
| 14426 | if (!isListened(e.type, opts)) return; |
| 14427 | var hoveredItem = this._getLegendItemAt(e.x, e.y); |
| 14428 | if (e.type === "mousemove" || e.type === "mouseout") { |
| 14429 | var previous = this._hoveredItem; |
| 14430 | var sameItem = itemsEqual(previous, hoveredItem); |
| 14431 | if (previous && !sameItem) (0, _helpersSegmentJs.Q)(opts.onLeave, [ |
| 14432 | e, |
| 14433 | previous, |
| 14434 | this |
| 14435 | ], this); |
| 14436 | this._hoveredItem = hoveredItem; |
| 14437 | if (hoveredItem && !sameItem) (0, _helpersSegmentJs.Q)(opts.onHover, [ |
| 14438 | e, |
| 14439 | hoveredItem, |
| 14440 | this |
| 14441 | ], this); |
| 14442 | } else if (hoveredItem) (0, _helpersSegmentJs.Q)(opts.onClick, [ |
| 14443 | e, |
| 14444 | hoveredItem, |
| 14445 | this |
| 14446 | ], this); |
| 14447 | } |
| 14448 | } |
| 14449 | ]); |
| 14450 | return Legend; |
| 14451 | }((0, _wrapNativeSuperJsDefault.default)(Element)); |
| 14452 | function isListened(type, opts) { |
| 14453 | if ((type === "mousemove" || type === "mouseout") && (opts.onHover || opts.onLeave)) return true; |
| 14454 | if (opts.onClick && (type === "click" || type === "mouseup")) return true; |
| 14455 | return false; |
| 14456 | } |
| 14457 | var plugin_legend = { |
| 14458 | id: "legend", |
| 14459 | _element: Legend, |
| 14460 | start: function(chart, _args, options) { |
| 14461 | var legend = chart.legend = new Legend({ |
| 14462 | ctx: chart.ctx, |
| 14463 | options: options, |
| 14464 | chart: chart |
| 14465 | }); |
| 14466 | layouts.configure(chart, legend, options); |
| 14467 | layouts.addBox(chart, legend); |
| 14468 | }, |
| 14469 | stop: function(chart) { |
| 14470 | layouts.removeBox(chart, chart.legend); |
| 14471 | delete chart.legend; |
| 14472 | }, |
| 14473 | beforeUpdate: function(chart, _args, options) { |
| 14474 | var legend = chart.legend; |
| 14475 | layouts.configure(chart, legend, options); |
| 14476 | legend.options = options; |
| 14477 | }, |
| 14478 | afterUpdate: function(chart) { |
| 14479 | var legend = chart.legend; |
| 14480 | legend.buildLabels(); |
| 14481 | legend.adjustHitBoxes(); |
| 14482 | }, |
| 14483 | afterEvent: function(chart, args) { |
| 14484 | if (!args.replay) chart.legend.handleEvent(args.event); |
| 14485 | }, |
| 14486 | defaults: { |
| 14487 | display: true, |
| 14488 | position: "top", |
| 14489 | align: "center", |
| 14490 | fullSize: true, |
| 14491 | reverse: false, |
| 14492 | weight: 1000, |
| 14493 | onClick: function(e, legendItem, legend) { |
| 14494 | var index63 = legendItem.datasetIndex; |
| 14495 | var ci = legend.chart; |
| 14496 | if (ci.isDatasetVisible(index63)) { |
| 14497 | ci.hide(index63); |
| 14498 | legendItem.hidden = true; |
| 14499 | } else { |
| 14500 | ci.show(index63); |
| 14501 | legendItem.hidden = false; |
| 14502 | } |
| 14503 | }, |
| 14504 | onHover: null, |
| 14505 | onLeave: null, |
| 14506 | labels: { |
| 14507 | color: function(ctx) { |
| 14508 | return ctx.chart.options.color; |
| 14509 | }, |
| 14510 | boxWidth: 40, |
| 14511 | padding: 10, |
| 14512 | generateLabels: function(chart) { |
| 14513 | var datasets = chart.data.datasets; |
| 14514 | var _options = chart.legend.options, _labels = _options.labels, usePointStyle = _labels.usePointStyle, pointStyle = _labels.pointStyle, textAlign = _labels.textAlign, color = _labels.color; |
| 14515 | return chart._getSortedDatasetMetas().map(function(meta) { |
| 14516 | var style = meta.controller.getStyle(usePointStyle ? 0 : undefined); |
| 14517 | var borderWidth = (0, _helpersSegmentJs.D)(style.borderWidth); |
| 14518 | return { |
| 14519 | text: datasets[meta.index].label, |
| 14520 | fillStyle: style.backgroundColor, |
| 14521 | fontColor: color, |
| 14522 | hidden: !meta.visible, |
| 14523 | lineCap: style.borderCapStyle, |
| 14524 | lineDash: style.borderDash, |
| 14525 | lineDashOffset: style.borderDashOffset, |
| 14526 | lineJoin: style.borderJoinStyle, |
| 14527 | lineWidth: (borderWidth.width + borderWidth.height) / 4, |
| 14528 | strokeStyle: style.borderColor, |
| 14529 | pointStyle: pointStyle || style.pointStyle, |
| 14530 | rotation: style.rotation, |
| 14531 | textAlign: textAlign || style.textAlign, |
| 14532 | borderRadius: 0, |
| 14533 | datasetIndex: meta.index |
| 14534 | }; |
| 14535 | }, this); |
| 14536 | } |
| 14537 | }, |
| 14538 | title: { |
| 14539 | color: function(ctx) { |
| 14540 | return ctx.chart.options.color; |
| 14541 | }, |
| 14542 | display: false, |
| 14543 | position: "center", |
| 14544 | text: "" |
| 14545 | } |
| 14546 | }, |
| 14547 | descriptors: { |
| 14548 | _scriptable: function(name) { |
| 14549 | return !name.startsWith("on"); |
| 14550 | }, |
| 14551 | labels: { |
| 14552 | _scriptable: function(name) { |
| 14553 | return ![ |
| 14554 | "generateLabels", |
| 14555 | "filter", |
| 14556 | "sort" |
| 14557 | ].includes(name); |
| 14558 | } |
| 14559 | } |
| 14560 | } |
| 14561 | }; |
| 14562 | var Title = /*#__PURE__*/ function(Element) { |
| 14563 | "use strict"; |
| 14564 | (0, _inheritsJsDefault.default)(Title, Element); |
| 14565 | var _super = (0, _createSuperJsDefault.default)(Title); |
| 14566 | function Title(config) { |
| 14567 | (0, _classCallCheckJsDefault.default)(this, Title); |
| 14568 | var _this; |
| 14569 | _this = _super.call(this); |
| 14570 | _this.chart = config.chart; |
| 14571 | _this.options = config.options; |
| 14572 | _this.ctx = config.ctx; |
| 14573 | _this._padding = undefined; |
| 14574 | _this.top = undefined; |
| 14575 | _this.bottom = undefined; |
| 14576 | _this.left = undefined; |
| 14577 | _this.right = undefined; |
| 14578 | _this.width = undefined; |
| 14579 | _this.height = undefined; |
| 14580 | _this.position = undefined; |
| 14581 | _this.weight = undefined; |
| 14582 | _this.fullSize = undefined; |
| 14583 | return _this; |
| 14584 | } |
| 14585 | (0, _createClassJsDefault.default)(Title, [ |
| 14586 | { |
| 14587 | key: "update", |
| 14588 | value: function update(maxWidth, maxHeight) { |
| 14589 | var opts = this.options; |
| 14590 | this.left = 0; |
| 14591 | this.top = 0; |
| 14592 | if (!opts.display) { |
| 14593 | this.width = this.height = this.right = this.bottom = 0; |
| 14594 | return; |
| 14595 | } |
| 14596 | this.width = this.right = maxWidth; |
| 14597 | this.height = this.bottom = maxHeight; |
| 14598 | var lineCount = (0, _helpersSegmentJs.b)(opts.text) ? opts.text.length : 1; |
| 14599 | this._padding = (0, _helpersSegmentJs.D)(opts.padding); |
| 14600 | var textSize = lineCount * (0, _helpersSegmentJs.$)(opts.font).lineHeight + this._padding.height; |
| 14601 | if (this.isHorizontal()) this.height = textSize; |
| 14602 | else this.width = textSize; |
| 14603 | } |
| 14604 | }, |
| 14605 | { |
| 14606 | key: "isHorizontal", |
| 14607 | value: function isHorizontal() { |
| 14608 | var pos = this.options.position; |
| 14609 | return pos === "top" || pos === "bottom"; |
| 14610 | } |
| 14611 | }, |
| 14612 | { |
| 14613 | key: "_drawArgs", |
| 14614 | value: function _drawArgs(offset) { |
| 14615 | var ref = this, top = ref.top, left = ref.left, bottom = ref.bottom, right = ref.right, options = ref.options; |
| 14616 | var align = options.align; |
| 14617 | var rotation = 0; |
| 14618 | var maxWidth, titleX, titleY; |
| 14619 | if (this.isHorizontal()) { |
| 14620 | titleX = (0, _helpersSegmentJs.a1)(align, left, right); |
| 14621 | titleY = top + offset; |
| 14622 | maxWidth = right - left; |
| 14623 | } else { |
| 14624 | if (options.position === "left") { |
| 14625 | titleX = left + offset; |
| 14626 | titleY = (0, _helpersSegmentJs.a1)(align, bottom, top); |
| 14627 | rotation = (0, _helpersSegmentJs.P) * -0.5; |
| 14628 | } else { |
| 14629 | titleX = right - offset; |
| 14630 | titleY = (0, _helpersSegmentJs.a1)(align, top, bottom); |
| 14631 | rotation = (0, _helpersSegmentJs.P) * 0.5; |
| 14632 | } |
| 14633 | maxWidth = bottom - top; |
| 14634 | } |
| 14635 | return { |
| 14636 | titleX: titleX, |
| 14637 | titleY: titleY, |
| 14638 | maxWidth: maxWidth, |
| 14639 | rotation: rotation |
| 14640 | }; |
| 14641 | } |
| 14642 | }, |
| 14643 | { |
| 14644 | key: "draw", |
| 14645 | value: function draw2() { |
| 14646 | var ctx = this.ctx; |
| 14647 | var opts = this.options; |
| 14648 | if (!opts.display) return; |
| 14649 | var fontOpts = (0, _helpersSegmentJs.$)(opts.font); |
| 14650 | var lineHeight = fontOpts.lineHeight; |
| 14651 | var offset = lineHeight / 2 + this._padding.top; |
| 14652 | var ref = this._drawArgs(offset), titleX = ref.titleX, titleY = ref.titleY, maxWidth = ref.maxWidth, rotation = ref.rotation; |
| 14653 | (0, _helpersSegmentJs.Y)(ctx, opts.text, 0, 0, fontOpts, { |
| 14654 | color: opts.color, |
| 14655 | maxWidth: maxWidth, |
| 14656 | rotation: rotation, |
| 14657 | textAlign: (0, _helpersSegmentJs.a0)(opts.align), |
| 14658 | textBaseline: "middle", |
| 14659 | translation: [ |
| 14660 | titleX, |
| 14661 | titleY |
| 14662 | ] |
| 14663 | }); |
| 14664 | } |
| 14665 | } |
| 14666 | ]); |
| 14667 | return Title; |
| 14668 | }((0, _wrapNativeSuperJsDefault.default)(Element)); |
| 14669 | function createTitle(chart, titleOpts) { |
| 14670 | var title = new Title({ |
| 14671 | ctx: chart.ctx, |
| 14672 | options: titleOpts, |
| 14673 | chart: chart |
| 14674 | }); |
| 14675 | layouts.configure(chart, title, titleOpts); |
| 14676 | layouts.addBox(chart, title); |
| 14677 | chart.titleBlock = title; |
| 14678 | } |
| 14679 | var plugin_title = { |
| 14680 | id: "title", |
| 14681 | _element: Title, |
| 14682 | start: function(chart, _args, options) { |
| 14683 | createTitle(chart, options); |
| 14684 | }, |
| 14685 | stop: function(chart) { |
| 14686 | var titleBlock = chart.titleBlock; |
| 14687 | layouts.removeBox(chart, titleBlock); |
| 14688 | delete chart.titleBlock; |
| 14689 | }, |
| 14690 | beforeUpdate: function(chart, _args, options) { |
| 14691 | var title = chart.titleBlock; |
| 14692 | layouts.configure(chart, title, options); |
| 14693 | title.options = options; |
| 14694 | }, |
| 14695 | defaults: { |
| 14696 | align: "center", |
| 14697 | display: false, |
| 14698 | font: { |
| 14699 | weight: "bold" |
| 14700 | }, |
| 14701 | fullSize: true, |
| 14702 | padding: 10, |
| 14703 | position: "top", |
| 14704 | text: "", |
| 14705 | weight: 2000 |
| 14706 | }, |
| 14707 | defaultRoutes: { |
| 14708 | color: "color" |
| 14709 | }, |
| 14710 | descriptors: { |
| 14711 | _scriptable: true, |
| 14712 | _indexable: false |
| 14713 | } |
| 14714 | }; |
| 14715 | var map = new WeakMap(); |
| 14716 | var plugin_subtitle = { |
| 14717 | id: "subtitle", |
| 14718 | start: function(chart, _args, options) { |
| 14719 | var title = new Title({ |
| 14720 | ctx: chart.ctx, |
| 14721 | options: options, |
| 14722 | chart: chart |
| 14723 | }); |
| 14724 | layouts.configure(chart, title, options); |
| 14725 | layouts.addBox(chart, title); |
| 14726 | map.set(chart, title); |
| 14727 | }, |
| 14728 | stop: function(chart) { |
| 14729 | layouts.removeBox(chart, map.get(chart)); |
| 14730 | map.delete(chart); |
| 14731 | }, |
| 14732 | beforeUpdate: function(chart, _args, options) { |
| 14733 | var title = map.get(chart); |
| 14734 | layouts.configure(chart, title, options); |
| 14735 | title.options = options; |
| 14736 | }, |
| 14737 | defaults: { |
| 14738 | align: "center", |
| 14739 | display: false, |
| 14740 | font: { |
| 14741 | weight: "normal" |
| 14742 | }, |
| 14743 | fullSize: true, |
| 14744 | padding: 0, |
| 14745 | position: "top", |
| 14746 | text: "", |
| 14747 | weight: 1500 |
| 14748 | }, |
| 14749 | defaultRoutes: { |
| 14750 | color: "color" |
| 14751 | }, |
| 14752 | descriptors: { |
| 14753 | _scriptable: true, |
| 14754 | _indexable: false |
| 14755 | } |
| 14756 | }; |
| 14757 | var positioners = { |
| 14758 | average: function(items) { |
| 14759 | if (!items.length) return false; |
| 14760 | var i, len; |
| 14761 | var x = 0; |
| 14762 | var y = 0; |
| 14763 | var count = 0; |
| 14764 | for(i = 0, len = items.length; i < len; ++i){ |
| 14765 | var el = items[i].element; |
| 14766 | if (el && el.hasValue()) { |
| 14767 | var pos = el.tooltipPosition(); |
| 14768 | x += pos.x; |
| 14769 | y += pos.y; |
| 14770 | ++count; |
| 14771 | } |
| 14772 | } |
| 14773 | return { |
| 14774 | x: x / count, |
| 14775 | y: y / count |
| 14776 | }; |
| 14777 | }, |
| 14778 | nearest: function(items, eventPosition) { |
| 14779 | if (!items.length) return false; |
| 14780 | var x = eventPosition.x; |
| 14781 | var y = eventPosition.y; |
| 14782 | var minDistance = Number.POSITIVE_INFINITY; |
| 14783 | var i, len, nearestElement; |
| 14784 | for(i = 0, len = items.length; i < len; ++i){ |
| 14785 | var el = items[i].element; |
| 14786 | if (el && el.hasValue()) { |
| 14787 | var center = el.getCenterPoint(); |
| 14788 | var d = (0, _helpersSegmentJs.aD)(eventPosition, center); |
| 14789 | if (d < minDistance) { |
| 14790 | minDistance = d; |
| 14791 | nearestElement = el; |
| 14792 | } |
| 14793 | } |
| 14794 | } |
| 14795 | if (nearestElement) { |
| 14796 | var tp = nearestElement.tooltipPosition(); |
| 14797 | x = tp.x; |
| 14798 | y = tp.y; |
| 14799 | } |
| 14800 | return { |
| 14801 | x: x, |
| 14802 | y: y |
| 14803 | }; |
| 14804 | } |
| 14805 | }; |
| 14806 | function pushOrConcat(base, toPush) { |
| 14807 | if (toPush) { |
| 14808 | if ((0, _helpersSegmentJs.b)(toPush)) Array.prototype.push.apply(base, toPush); |
| 14809 | else base.push(toPush); |
| 14810 | } |
| 14811 | return base; |
| 14812 | } |
| 14813 | function splitNewlines(str) { |
| 14814 | if ((typeof str === "string" || str instanceof String) && str.indexOf("\n") > -1) return str.split("\n"); |
| 14815 | return str; |
| 14816 | } |
| 14817 | function createTooltipItem(chart, item) { |
| 14818 | var element = item.element, datasetIndex = item.datasetIndex, index64 = item.index; |
| 14819 | var controller = chart.getDatasetMeta(datasetIndex).controller; |
| 14820 | var ref = controller.getLabelAndValue(index64), label = ref.label, value = ref.value; |
| 14821 | return { |
| 14822 | chart: chart, |
| 14823 | label: label, |
| 14824 | parsed: controller.getParsed(index64), |
| 14825 | raw: chart.data.datasets[datasetIndex].data[index64], |
| 14826 | formattedValue: value, |
| 14827 | dataset: controller.getDataset(), |
| 14828 | dataIndex: index64, |
| 14829 | datasetIndex: datasetIndex, |
| 14830 | element: element |
| 14831 | }; |
| 14832 | } |
| 14833 | function getTooltipSize(tooltip, options) { |
| 14834 | var ctx = tooltip.chart.ctx; |
| 14835 | var body = tooltip.body, footer = tooltip.footer, title = tooltip.title; |
| 14836 | var boxWidth = options.boxWidth, boxHeight = options.boxHeight; |
| 14837 | var bodyFont = (0, _helpersSegmentJs.$)(options.bodyFont); |
| 14838 | var titleFont = (0, _helpersSegmentJs.$)(options.titleFont); |
| 14839 | var footerFont = (0, _helpersSegmentJs.$)(options.footerFont); |
| 14840 | var titleLineCount = title.length; |
| 14841 | var footerLineCount = footer.length; |
| 14842 | var bodyLineItemCount = body.length; |
| 14843 | var padding = (0, _helpersSegmentJs.D)(options.padding); |
| 14844 | var height = padding.height; |
| 14845 | var width = 0; |
| 14846 | var combinedBodyLength = body.reduce(function(count, bodyItem) { |
| 14847 | return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length; |
| 14848 | }, 0); |
| 14849 | combinedBodyLength += tooltip.beforeBody.length + tooltip.afterBody.length; |
| 14850 | if (titleLineCount) height += titleLineCount * titleFont.lineHeight + (titleLineCount - 1) * options.titleSpacing + options.titleMarginBottom; |
| 14851 | if (combinedBodyLength) { |
| 14852 | var bodyLineHeight = options.displayColors ? Math.max(boxHeight, bodyFont.lineHeight) : bodyFont.lineHeight; |
| 14853 | height += bodyLineItemCount * bodyLineHeight + (combinedBodyLength - bodyLineItemCount) * bodyFont.lineHeight + (combinedBodyLength - 1) * options.bodySpacing; |
| 14854 | } |
| 14855 | if (footerLineCount) height += options.footerMarginTop + footerLineCount * footerFont.lineHeight + (footerLineCount - 1) * options.footerSpacing; |
| 14856 | var widthPadding = 0; |
| 14857 | var maxLineWidth = function maxLineWidth(line) { |
| 14858 | width = Math.max(width, ctx.measureText(line).width + widthPadding); |
| 14859 | }; |
| 14860 | ctx.save(); |
| 14861 | ctx.font = titleFont.string; |
| 14862 | (0, _helpersSegmentJs.E)(tooltip.title, maxLineWidth); |
| 14863 | ctx.font = bodyFont.string; |
| 14864 | (0, _helpersSegmentJs.E)(tooltip.beforeBody.concat(tooltip.afterBody), maxLineWidth); |
| 14865 | widthPadding = options.displayColors ? boxWidth + 2 + options.boxPadding : 0; |
| 14866 | (0, _helpersSegmentJs.E)(body, function(bodyItem) { |
| 14867 | (0, _helpersSegmentJs.E)(bodyItem.before, maxLineWidth); |
| 14868 | (0, _helpersSegmentJs.E)(bodyItem.lines, maxLineWidth); |
| 14869 | (0, _helpersSegmentJs.E)(bodyItem.after, maxLineWidth); |
| 14870 | }); |
| 14871 | widthPadding = 0; |
| 14872 | ctx.font = footerFont.string; |
| 14873 | (0, _helpersSegmentJs.E)(tooltip.footer, maxLineWidth); |
| 14874 | ctx.restore(); |
| 14875 | width += padding.width; |
| 14876 | return { |
| 14877 | width: width, |
| 14878 | height: height |
| 14879 | }; |
| 14880 | } |
| 14881 | function determineYAlign(chart, size) { |
| 14882 | var y = size.y, height = size.height; |
| 14883 | if (y < height / 2) return "top"; |
| 14884 | else if (y > chart.height - height / 2) return "bottom"; |
| 14885 | return "center"; |
| 14886 | } |
| 14887 | function doesNotFitWithAlign(xAlign, chart, options, size) { |
| 14888 | var x = size.x, width = size.width; |
| 14889 | var caret = options.caretSize + options.caretPadding; |
| 14890 | if (xAlign === "left" && x + width + caret > chart.width) return true; |
| 14891 | if (xAlign === "right" && x - width - caret < 0) return true; |
| 14892 | } |
| 14893 | function determineXAlign(chart, options, size, yAlign) { |
| 14894 | var x = size.x, width = size.width; |
| 14895 | var chartWidth = chart.width, _chartArea = chart.chartArea, left = _chartArea.left, right = _chartArea.right; |
| 14896 | var xAlign = "center"; |
| 14897 | if (yAlign === "center") xAlign = x <= (left + right) / 2 ? "left" : "right"; |
| 14898 | else if (x <= width / 2) xAlign = "left"; |
| 14899 | else if (x >= chartWidth - width / 2) xAlign = "right"; |
| 14900 | if (doesNotFitWithAlign(xAlign, chart, options, size)) xAlign = "center"; |
| 14901 | return xAlign; |
| 14902 | } |
| 14903 | function determineAlignment(chart, options, size) { |
| 14904 | var yAlign = size.yAlign || options.yAlign || determineYAlign(chart, size); |
| 14905 | return { |
| 14906 | xAlign: size.xAlign || options.xAlign || determineXAlign(chart, options, size, yAlign), |
| 14907 | yAlign: yAlign |
| 14908 | }; |
| 14909 | } |
| 14910 | function alignX(size, xAlign) { |
| 14911 | var x = size.x, width = size.width; |
| 14912 | if (xAlign === "right") x -= width; |
| 14913 | else if (xAlign === "center") x -= width / 2; |
| 14914 | return x; |
| 14915 | } |
| 14916 | function alignY(size, yAlign, paddingAndSize) { |
| 14917 | var y = size.y, height = size.height; |
| 14918 | if (yAlign === "top") y += paddingAndSize; |
| 14919 | else if (yAlign === "bottom") y -= height + paddingAndSize; |
| 14920 | else y -= height / 2; |
| 14921 | return y; |
| 14922 | } |
| 14923 | function getBackgroundPoint(options, size, alignment, chart) { |
| 14924 | var caretSize = options.caretSize, caretPadding = options.caretPadding, cornerRadius = options.cornerRadius; |
| 14925 | var xAlign = alignment.xAlign, yAlign = alignment.yAlign; |
| 14926 | var paddingAndSize = caretSize + caretPadding; |
| 14927 | var ref = (0, _helpersSegmentJs.av)(cornerRadius), topLeft = ref.topLeft, topRight = ref.topRight, bottomLeft = ref.bottomLeft, bottomRight = ref.bottomRight; |
| 14928 | var x = alignX(size, xAlign); |
| 14929 | var y = alignY(size, yAlign, paddingAndSize); |
| 14930 | if (yAlign === "center") { |
| 14931 | if (xAlign === "left") x += paddingAndSize; |
| 14932 | else if (xAlign === "right") x -= paddingAndSize; |
| 14933 | } else if (xAlign === "left") x -= Math.max(topLeft, bottomLeft) + caretSize; |
| 14934 | else if (xAlign === "right") x += Math.max(topRight, bottomRight) + caretSize; |
| 14935 | return { |
| 14936 | x: (0, _helpersSegmentJs.w)(x, 0, chart.width - size.width), |
| 14937 | y: (0, _helpersSegmentJs.w)(y, 0, chart.height - size.height) |
| 14938 | }; |
| 14939 | } |
| 14940 | function getAlignedX(tooltip, align, options) { |
| 14941 | var padding = (0, _helpersSegmentJs.D)(options.padding); |
| 14942 | return align === "center" ? tooltip.x + tooltip.width / 2 : align === "right" ? tooltip.x + tooltip.width - padding.right : tooltip.x + padding.left; |
| 14943 | } |
| 14944 | function getBeforeAfterBodyLines(callback) { |
| 14945 | return pushOrConcat([], splitNewlines(callback)); |
| 14946 | } |
| 14947 | function createTooltipContext(parent, tooltip, tooltipItems) { |
| 14948 | return (0, _helpersSegmentJs.h)(parent, { |
| 14949 | tooltip: tooltip, |
| 14950 | tooltipItems: tooltipItems, |
| 14951 | type: "tooltip" |
| 14952 | }); |
| 14953 | } |
| 14954 | function overrideCallbacks(callbacks, context) { |
| 14955 | var override = context && context.dataset && context.dataset.tooltip && context.dataset.tooltip.callbacks; |
| 14956 | return override ? callbacks.override(override) : callbacks; |
| 14957 | } |
| 14958 | var Tooltip = /*#__PURE__*/ function(Element) { |
| 14959 | "use strict"; |
| 14960 | (0, _inheritsJsDefault.default)(Tooltip, Element); |
| 14961 | var _super = (0, _createSuperJsDefault.default)(Tooltip); |
| 14962 | function Tooltip(config) { |
| 14963 | (0, _classCallCheckJsDefault.default)(this, Tooltip); |
| 14964 | var _this; |
| 14965 | _this = _super.call(this); |
| 14966 | _this.opacity = 0; |
| 14967 | _this._active = []; |
| 14968 | _this._eventPosition = undefined; |
| 14969 | _this._size = undefined; |
| 14970 | _this._cachedAnimations = undefined; |
| 14971 | _this._tooltipItems = []; |
| 14972 | _this.$animations = undefined; |
| 14973 | _this.$context = undefined; |
| 14974 | _this.chart = config.chart || config._chart; |
| 14975 | _this._chart = _this.chart; |
| 14976 | _this.options = config.options; |
| 14977 | _this.dataPoints = undefined; |
| 14978 | _this.title = undefined; |
| 14979 | _this.beforeBody = undefined; |
| 14980 | _this.body = undefined; |
| 14981 | _this.afterBody = undefined; |
| 14982 | _this.footer = undefined; |
| 14983 | _this.xAlign = undefined; |
| 14984 | _this.yAlign = undefined; |
| 14985 | _this.x = undefined; |
| 14986 | _this.y = undefined; |
| 14987 | _this.height = undefined; |
| 14988 | _this.width = undefined; |
| 14989 | _this.caretX = undefined; |
| 14990 | _this.caretY = undefined; |
| 14991 | _this.labelColors = undefined; |
| 14992 | _this.labelPointStyles = undefined; |
| 14993 | _this.labelTextColors = undefined; |
| 14994 | return _this; |
| 14995 | } |
| 14996 | (0, _createClassJsDefault.default)(Tooltip, [ |
| 14997 | { |
| 14998 | key: "initialize", |
| 14999 | value: function initialize(options) { |
| 15000 | this.options = options; |
| 15001 | this._cachedAnimations = undefined; |
| 15002 | this.$context = undefined; |
| 15003 | } |
| 15004 | }, |
| 15005 | { |
| 15006 | key: "_resolveAnimations", |
| 15007 | value: function _resolveAnimations() { |
| 15008 | var cached = this._cachedAnimations; |
| 15009 | if (cached) return cached; |
| 15010 | var chart = this.chart; |
| 15011 | var options = this.options.setContext(this.getContext()); |
| 15012 | var opts = options.enabled && chart.options.animation && options.animations; |
| 15013 | var animations = new Animations(this.chart, opts); |
| 15014 | if (opts._cacheable) this._cachedAnimations = Object.freeze(animations); |
| 15015 | return animations; |
| 15016 | } |
| 15017 | }, |
| 15018 | { |
| 15019 | key: "getContext", |
| 15020 | value: function getContext() { |
| 15021 | return this.$context || (this.$context = createTooltipContext(this.chart.getContext(), this, this._tooltipItems)); |
| 15022 | } |
| 15023 | }, |
| 15024 | { |
| 15025 | key: "getTitle", |
| 15026 | value: function getTitle(context, options) { |
| 15027 | var callbacks = options.callbacks; |
| 15028 | var beforeTitle = callbacks.beforeTitle.apply(this, [ |
| 15029 | context |
| 15030 | ]); |
| 15031 | var title = callbacks.title.apply(this, [ |
| 15032 | context |
| 15033 | ]); |
| 15034 | var afterTitle = callbacks.afterTitle.apply(this, [ |
| 15035 | context |
| 15036 | ]); |
| 15037 | var lines = []; |
| 15038 | lines = pushOrConcat(lines, splitNewlines(beforeTitle)); |
| 15039 | lines = pushOrConcat(lines, splitNewlines(title)); |
| 15040 | lines = pushOrConcat(lines, splitNewlines(afterTitle)); |
| 15041 | return lines; |
| 15042 | } |
| 15043 | }, |
| 15044 | { |
| 15045 | key: "getBeforeBody", |
| 15046 | value: function getBeforeBody(tooltipItems, options) { |
| 15047 | return getBeforeAfterBodyLines(options.callbacks.beforeBody.apply(this, [ |
| 15048 | tooltipItems |
| 15049 | ])); |
| 15050 | } |
| 15051 | }, |
| 15052 | { |
| 15053 | key: "getBody", |
| 15054 | value: function getBody(tooltipItems, options) { |
| 15055 | var _this = this; |
| 15056 | var callbacks = options.callbacks; |
| 15057 | var bodyItems = []; |
| 15058 | (0, _helpersSegmentJs.E)(tooltipItems, function(context) { |
| 15059 | var bodyItem = { |
| 15060 | before: [], |
| 15061 | lines: [], |
| 15062 | after: [] |
| 15063 | }; |
| 15064 | var scoped = overrideCallbacks(callbacks, context); |
| 15065 | pushOrConcat(bodyItem.before, splitNewlines(scoped.beforeLabel.call(_this, context))); |
| 15066 | pushOrConcat(bodyItem.lines, scoped.label.call(_this, context)); |
| 15067 | pushOrConcat(bodyItem.after, splitNewlines(scoped.afterLabel.call(_this, context))); |
| 15068 | bodyItems.push(bodyItem); |
| 15069 | }); |
| 15070 | return bodyItems; |
| 15071 | } |
| 15072 | }, |
| 15073 | { |
| 15074 | key: "getAfterBody", |
| 15075 | value: function getAfterBody(tooltipItems, options) { |
| 15076 | return getBeforeAfterBodyLines(options.callbacks.afterBody.apply(this, [ |
| 15077 | tooltipItems |
| 15078 | ])); |
| 15079 | } |
| 15080 | }, |
| 15081 | { |
| 15082 | key: "getFooter", |
| 15083 | value: function getFooter(tooltipItems, options) { |
| 15084 | var callbacks = options.callbacks; |
| 15085 | var beforeFooter = callbacks.beforeFooter.apply(this, [ |
| 15086 | tooltipItems |
| 15087 | ]); |
| 15088 | var footer = callbacks.footer.apply(this, [ |
| 15089 | tooltipItems |
| 15090 | ]); |
| 15091 | var afterFooter = callbacks.afterFooter.apply(this, [ |
| 15092 | tooltipItems |
| 15093 | ]); |
| 15094 | var lines = []; |
| 15095 | lines = pushOrConcat(lines, splitNewlines(beforeFooter)); |
| 15096 | lines = pushOrConcat(lines, splitNewlines(footer)); |
| 15097 | lines = pushOrConcat(lines, splitNewlines(afterFooter)); |
| 15098 | return lines; |
| 15099 | } |
| 15100 | }, |
| 15101 | { |
| 15102 | key: "_createItems", |
| 15103 | value: function _createItems(options) { |
| 15104 | var _this = this; |
| 15105 | var active = this._active; |
| 15106 | var data = this.chart.data; |
| 15107 | var labelColors = []; |
| 15108 | var labelPointStyles = []; |
| 15109 | var labelTextColors = []; |
| 15110 | var tooltipItems = []; |
| 15111 | var i, len; |
| 15112 | for(i = 0, len = active.length; i < len; ++i)tooltipItems.push(createTooltipItem(this.chart, active[i])); |
| 15113 | if (options.filter) tooltipItems = tooltipItems.filter(function(element, index65, array) { |
| 15114 | return options.filter(element, index65, array, data); |
| 15115 | }); |
| 15116 | if (options.itemSort) tooltipItems = tooltipItems.sort(function(a, b) { |
| 15117 | return options.itemSort(a, b, data); |
| 15118 | }); |
| 15119 | (0, _helpersSegmentJs.E)(tooltipItems, function(context) { |
| 15120 | var scoped = overrideCallbacks(options.callbacks, context); |
| 15121 | labelColors.push(scoped.labelColor.call(_this, context)); |
| 15122 | labelPointStyles.push(scoped.labelPointStyle.call(_this, context)); |
| 15123 | labelTextColors.push(scoped.labelTextColor.call(_this, context)); |
| 15124 | }); |
| 15125 | this.labelColors = labelColors; |
| 15126 | this.labelPointStyles = labelPointStyles; |
| 15127 | this.labelTextColors = labelTextColors; |
| 15128 | this.dataPoints = tooltipItems; |
| 15129 | return tooltipItems; |
| 15130 | } |
| 15131 | }, |
| 15132 | { |
| 15133 | key: "update", |
| 15134 | value: function update(changed, replay) { |
| 15135 | var options = this.options.setContext(this.getContext()); |
| 15136 | var active = this._active; |
| 15137 | var properties; |
| 15138 | var tooltipItems = []; |
| 15139 | if (!active.length) { |
| 15140 | if (this.opacity !== 0) properties = { |
| 15141 | opacity: 0 |
| 15142 | }; |
| 15143 | } else { |
| 15144 | var position = positioners[options.position].call(this, active, this._eventPosition); |
| 15145 | tooltipItems = this._createItems(options); |
| 15146 | this.title = this.getTitle(tooltipItems, options); |
| 15147 | this.beforeBody = this.getBeforeBody(tooltipItems, options); |
| 15148 | this.body = this.getBody(tooltipItems, options); |
| 15149 | this.afterBody = this.getAfterBody(tooltipItems, options); |
| 15150 | this.footer = this.getFooter(tooltipItems, options); |
| 15151 | var size = this._size = getTooltipSize(this, options); |
| 15152 | var positionAndSize = Object.assign({}, position, size); |
| 15153 | var alignment = determineAlignment(this.chart, options, positionAndSize); |
| 15154 | var backgroundPoint = getBackgroundPoint(options, positionAndSize, alignment, this.chart); |
| 15155 | this.xAlign = alignment.xAlign; |
| 15156 | this.yAlign = alignment.yAlign; |
| 15157 | properties = { |
| 15158 | opacity: 1, |
| 15159 | x: backgroundPoint.x, |
| 15160 | y: backgroundPoint.y, |
| 15161 | width: size.width, |
| 15162 | height: size.height, |
| 15163 | caretX: position.x, |
| 15164 | caretY: position.y |
| 15165 | }; |
| 15166 | } |
| 15167 | this._tooltipItems = tooltipItems; |
| 15168 | this.$context = undefined; |
| 15169 | if (properties) this._resolveAnimations().update(this, properties); |
| 15170 | if (changed && options.external) options.external.call(this, { |
| 15171 | chart: this.chart, |
| 15172 | tooltip: this, |
| 15173 | replay: replay |
| 15174 | }); |
| 15175 | } |
| 15176 | }, |
| 15177 | { |
| 15178 | key: "drawCaret", |
| 15179 | value: function drawCaret(tooltipPoint, ctx, size, options) { |
| 15180 | var caretPosition = this.getCaretPosition(tooltipPoint, size, options); |
| 15181 | ctx.lineTo(caretPosition.x1, caretPosition.y1); |
| 15182 | ctx.lineTo(caretPosition.x2, caretPosition.y2); |
| 15183 | ctx.lineTo(caretPosition.x3, caretPosition.y3); |
| 15184 | } |
| 15185 | }, |
| 15186 | { |
| 15187 | key: "getCaretPosition", |
| 15188 | value: function getCaretPosition(tooltipPoint, size, options) { |
| 15189 | var ref = this, xAlign = ref.xAlign, yAlign = ref.yAlign; |
| 15190 | var caretSize = options.caretSize, cornerRadius = options.cornerRadius; |
| 15191 | var ref12 = (0, _helpersSegmentJs.av)(cornerRadius), topLeft = ref12.topLeft, topRight = ref12.topRight, bottomLeft = ref12.bottomLeft, bottomRight = ref12.bottomRight; |
| 15192 | var ptX = tooltipPoint.x, ptY = tooltipPoint.y; |
| 15193 | var width = size.width, height = size.height; |
| 15194 | var x1, x2, x3, y1, y2, y3; |
| 15195 | if (yAlign === "center") { |
| 15196 | y2 = ptY + height / 2; |
| 15197 | if (xAlign === "left") { |
| 15198 | x1 = ptX; |
| 15199 | x2 = x1 - caretSize; |
| 15200 | y1 = y2 + caretSize; |
| 15201 | y3 = y2 - caretSize; |
| 15202 | } else { |
| 15203 | x1 = ptX + width; |
| 15204 | x2 = x1 + caretSize; |
| 15205 | y1 = y2 - caretSize; |
| 15206 | y3 = y2 + caretSize; |
| 15207 | } |
| 15208 | x3 = x1; |
| 15209 | } else { |
| 15210 | if (xAlign === "left") x2 = ptX + Math.max(topLeft, bottomLeft) + caretSize; |
| 15211 | else if (xAlign === "right") x2 = ptX + width - Math.max(topRight, bottomRight) - caretSize; |
| 15212 | else x2 = this.caretX; |
| 15213 | if (yAlign === "top") { |
| 15214 | y1 = ptY; |
| 15215 | y2 = y1 - caretSize; |
| 15216 | x1 = x2 - caretSize; |
| 15217 | x3 = x2 + caretSize; |
| 15218 | } else { |
| 15219 | y1 = ptY + height; |
| 15220 | y2 = y1 + caretSize; |
| 15221 | x1 = x2 + caretSize; |
| 15222 | x3 = x2 - caretSize; |
| 15223 | } |
| 15224 | y3 = y1; |
| 15225 | } |
| 15226 | return { |
| 15227 | x1: x1, |
| 15228 | x2: x2, |
| 15229 | x3: x3, |
| 15230 | y1: y1, |
| 15231 | y2: y2, |
| 15232 | y3: y3 |
| 15233 | }; |
| 15234 | } |
| 15235 | }, |
| 15236 | { |
| 15237 | key: "drawTitle", |
| 15238 | value: function drawTitle(pt, ctx, options) { |
| 15239 | var title = this.title; |
| 15240 | var length = title.length; |
| 15241 | var titleFont, titleSpacing, i; |
| 15242 | if (length) { |
| 15243 | var rtlHelper = (0, _helpersSegmentJs.ay)(options.rtl, this.x, this.width); |
| 15244 | pt.x = getAlignedX(this, options.titleAlign, options); |
| 15245 | ctx.textAlign = rtlHelper.textAlign(options.titleAlign); |
| 15246 | ctx.textBaseline = "middle"; |
| 15247 | titleFont = (0, _helpersSegmentJs.$)(options.titleFont); |
| 15248 | titleSpacing = options.titleSpacing; |
| 15249 | ctx.fillStyle = options.titleColor; |
| 15250 | ctx.font = titleFont.string; |
| 15251 | for(i = 0; i < length; ++i){ |
| 15252 | ctx.fillText(title[i], rtlHelper.x(pt.x), pt.y + titleFont.lineHeight / 2); |
| 15253 | pt.y += titleFont.lineHeight + titleSpacing; |
| 15254 | if (i + 1 === length) pt.y += options.titleMarginBottom - titleSpacing; |
| 15255 | } |
| 15256 | } |
| 15257 | } |
| 15258 | }, |
| 15259 | { |
| 15260 | key: "_drawColorBox", |
| 15261 | value: function _drawColorBox(ctx, pt, i, rtlHelper, options) { |
| 15262 | var labelColors = this.labelColors[i]; |
| 15263 | var labelPointStyle = this.labelPointStyles[i]; |
| 15264 | var boxHeight = options.boxHeight, boxWidth = options.boxWidth, boxPadding = options.boxPadding; |
| 15265 | var bodyFont = (0, _helpersSegmentJs.$)(options.bodyFont); |
| 15266 | var colorX = getAlignedX(this, "left", options); |
| 15267 | var rtlColorX = rtlHelper.x(colorX); |
| 15268 | var yOffSet = boxHeight < bodyFont.lineHeight ? (bodyFont.lineHeight - boxHeight) / 2 : 0; |
| 15269 | var colorY = pt.y + yOffSet; |
| 15270 | if (options.usePointStyle) { |
| 15271 | var drawOptions = { |
| 15272 | radius: Math.min(boxWidth, boxHeight) / 2, |
| 15273 | pointStyle: labelPointStyle.pointStyle, |
| 15274 | rotation: labelPointStyle.rotation, |
| 15275 | borderWidth: 1 |
| 15276 | }; |
| 15277 | var centerX = rtlHelper.leftForLtr(rtlColorX, boxWidth) + boxWidth / 2; |
| 15278 | var centerY = colorY + boxHeight / 2; |
| 15279 | ctx.strokeStyle = options.multiKeyBackground; |
| 15280 | ctx.fillStyle = options.multiKeyBackground; |
| 15281 | (0, _helpersSegmentJs.as)(ctx, drawOptions, centerX, centerY); |
| 15282 | ctx.strokeStyle = labelColors.borderColor; |
| 15283 | ctx.fillStyle = labelColors.backgroundColor; |
| 15284 | (0, _helpersSegmentJs.as)(ctx, drawOptions, centerX, centerY); |
| 15285 | } else { |
| 15286 | ctx.lineWidth = labelColors.borderWidth || 1; |
| 15287 | ctx.strokeStyle = labelColors.borderColor; |
| 15288 | ctx.setLineDash(labelColors.borderDash || []); |
| 15289 | ctx.lineDashOffset = labelColors.borderDashOffset || 0; |
| 15290 | var outerX = rtlHelper.leftForLtr(rtlColorX, boxWidth - boxPadding); |
| 15291 | var innerX = rtlHelper.leftForLtr(rtlHelper.xPlus(rtlColorX, 1), boxWidth - boxPadding - 2); |
| 15292 | var borderRadius = (0, _helpersSegmentJs.av)(labelColors.borderRadius); |
| 15293 | if (Object.values(borderRadius).some(function(v) { |
| 15294 | return v !== 0; |
| 15295 | })) { |
| 15296 | ctx.beginPath(); |
| 15297 | ctx.fillStyle = options.multiKeyBackground; |
| 15298 | (0, _helpersSegmentJs.at)(ctx, { |
| 15299 | x: outerX, |
| 15300 | y: colorY, |
| 15301 | w: boxWidth, |
| 15302 | h: boxHeight, |
| 15303 | radius: borderRadius |
| 15304 | }); |
| 15305 | ctx.fill(); |
| 15306 | ctx.stroke(); |
| 15307 | ctx.fillStyle = labelColors.backgroundColor; |
| 15308 | ctx.beginPath(); |
| 15309 | (0, _helpersSegmentJs.at)(ctx, { |
| 15310 | x: innerX, |
| 15311 | y: colorY + 1, |
| 15312 | w: boxWidth - 2, |
| 15313 | h: boxHeight - 2, |
| 15314 | radius: borderRadius |
| 15315 | }); |
| 15316 | ctx.fill(); |
| 15317 | } else { |
| 15318 | ctx.fillStyle = options.multiKeyBackground; |
| 15319 | ctx.fillRect(outerX, colorY, boxWidth, boxHeight); |
| 15320 | ctx.strokeRect(outerX, colorY, boxWidth, boxHeight); |
| 15321 | ctx.fillStyle = labelColors.backgroundColor; |
| 15322 | ctx.fillRect(innerX, colorY + 1, boxWidth - 2, boxHeight - 2); |
| 15323 | } |
| 15324 | } |
| 15325 | ctx.fillStyle = this.labelTextColors[i]; |
| 15326 | } |
| 15327 | }, |
| 15328 | { |
| 15329 | key: "drawBody", |
| 15330 | value: function drawBody(pt, ctx, options) { |
| 15331 | var body = this.body; |
| 15332 | var bodySpacing = options.bodySpacing, bodyAlign = options.bodyAlign, displayColors = options.displayColors, boxHeight = options.boxHeight, boxWidth = options.boxWidth, boxPadding = options.boxPadding; |
| 15333 | var bodyFont = (0, _helpersSegmentJs.$)(options.bodyFont); |
| 15334 | var bodyLineHeight = bodyFont.lineHeight; |
| 15335 | var xLinePadding = 0; |
| 15336 | var rtlHelper = (0, _helpersSegmentJs.ay)(options.rtl, this.x, this.width); |
| 15337 | var fillLineOfText = function fillLineOfText(line) { |
| 15338 | ctx.fillText(line, rtlHelper.x(pt.x + xLinePadding), pt.y + bodyLineHeight / 2); |
| 15339 | pt.y += bodyLineHeight + bodySpacing; |
| 15340 | }; |
| 15341 | var bodyAlignForCalculation = rtlHelper.textAlign(bodyAlign); |
| 15342 | var bodyItem, textColor, lines, i, j, ilen, jlen; |
| 15343 | ctx.textAlign = bodyAlign; |
| 15344 | ctx.textBaseline = "middle"; |
| 15345 | ctx.font = bodyFont.string; |
| 15346 | pt.x = getAlignedX(this, bodyAlignForCalculation, options); |
| 15347 | ctx.fillStyle = options.bodyColor; |
| 15348 | (0, _helpersSegmentJs.E)(this.beforeBody, fillLineOfText); |
| 15349 | xLinePadding = displayColors && bodyAlignForCalculation !== "right" ? bodyAlign === "center" ? boxWidth / 2 + boxPadding : boxWidth + 2 + boxPadding : 0; |
| 15350 | for(i = 0, ilen = body.length; i < ilen; ++i){ |
| 15351 | bodyItem = body[i]; |
| 15352 | textColor = this.labelTextColors[i]; |
| 15353 | ctx.fillStyle = textColor; |
| 15354 | (0, _helpersSegmentJs.E)(bodyItem.before, fillLineOfText); |
| 15355 | lines = bodyItem.lines; |
| 15356 | if (displayColors && lines.length) { |
| 15357 | this._drawColorBox(ctx, pt, i, rtlHelper, options); |
| 15358 | bodyLineHeight = Math.max(bodyFont.lineHeight, boxHeight); |
| 15359 | } |
| 15360 | for(j = 0, jlen = lines.length; j < jlen; ++j){ |
| 15361 | fillLineOfText(lines[j]); |
| 15362 | bodyLineHeight = bodyFont.lineHeight; |
| 15363 | } |
| 15364 | (0, _helpersSegmentJs.E)(bodyItem.after, fillLineOfText); |
| 15365 | } |
| 15366 | xLinePadding = 0; |
| 15367 | bodyLineHeight = bodyFont.lineHeight; |
| 15368 | (0, _helpersSegmentJs.E)(this.afterBody, fillLineOfText); |
| 15369 | pt.y -= bodySpacing; |
| 15370 | } |
| 15371 | }, |
| 15372 | { |
| 15373 | key: "drawFooter", |
| 15374 | value: function drawFooter(pt, ctx, options) { |
| 15375 | var footer = this.footer; |
| 15376 | var length = footer.length; |
| 15377 | var footerFont, i; |
| 15378 | if (length) { |
| 15379 | var rtlHelper = (0, _helpersSegmentJs.ay)(options.rtl, this.x, this.width); |
| 15380 | pt.x = getAlignedX(this, options.footerAlign, options); |
| 15381 | pt.y += options.footerMarginTop; |
| 15382 | ctx.textAlign = rtlHelper.textAlign(options.footerAlign); |
| 15383 | ctx.textBaseline = "middle"; |
| 15384 | footerFont = (0, _helpersSegmentJs.$)(options.footerFont); |
| 15385 | ctx.fillStyle = options.footerColor; |
| 15386 | ctx.font = footerFont.string; |
| 15387 | for(i = 0; i < length; ++i){ |
| 15388 | ctx.fillText(footer[i], rtlHelper.x(pt.x), pt.y + footerFont.lineHeight / 2); |
| 15389 | pt.y += footerFont.lineHeight + options.footerSpacing; |
| 15390 | } |
| 15391 | } |
| 15392 | } |
| 15393 | }, |
| 15394 | { |
| 15395 | key: "drawBackground", |
| 15396 | value: function drawBackground(pt, ctx, tooltipSize, options) { |
| 15397 | var ref = this, xAlign = ref.xAlign, yAlign = ref.yAlign; |
| 15398 | var x = pt.x, y = pt.y; |
| 15399 | var width = tooltipSize.width, height = tooltipSize.height; |
| 15400 | var ref13 = (0, _helpersSegmentJs.av)(options.cornerRadius), topLeft = ref13.topLeft, topRight = ref13.topRight, bottomLeft = ref13.bottomLeft, bottomRight = ref13.bottomRight; |
| 15401 | ctx.fillStyle = options.backgroundColor; |
| 15402 | ctx.strokeStyle = options.borderColor; |
| 15403 | ctx.lineWidth = options.borderWidth; |
| 15404 | ctx.beginPath(); |
| 15405 | ctx.moveTo(x + topLeft, y); |
| 15406 | if (yAlign === "top") this.drawCaret(pt, ctx, tooltipSize, options); |
| 15407 | ctx.lineTo(x + width - topRight, y); |
| 15408 | ctx.quadraticCurveTo(x + width, y, x + width, y + topRight); |
| 15409 | if (yAlign === "center" && xAlign === "right") this.drawCaret(pt, ctx, tooltipSize, options); |
| 15410 | ctx.lineTo(x + width, y + height - bottomRight); |
| 15411 | ctx.quadraticCurveTo(x + width, y + height, x + width - bottomRight, y + height); |
| 15412 | if (yAlign === "bottom") this.drawCaret(pt, ctx, tooltipSize, options); |
| 15413 | ctx.lineTo(x + bottomLeft, y + height); |
| 15414 | ctx.quadraticCurveTo(x, y + height, x, y + height - bottomLeft); |
| 15415 | if (yAlign === "center" && xAlign === "left") this.drawCaret(pt, ctx, tooltipSize, options); |
| 15416 | ctx.lineTo(x, y + topLeft); |
| 15417 | ctx.quadraticCurveTo(x, y, x + topLeft, y); |
| 15418 | ctx.closePath(); |
| 15419 | ctx.fill(); |
| 15420 | if (options.borderWidth > 0) ctx.stroke(); |
| 15421 | } |
| 15422 | }, |
| 15423 | { |
| 15424 | key: "_updateAnimationTarget", |
| 15425 | value: function _updateAnimationTarget(options) { |
| 15426 | var chart = this.chart; |
| 15427 | var anims = this.$animations; |
| 15428 | var animX = anims && anims.x; |
| 15429 | var animY = anims && anims.y; |
| 15430 | if (animX || animY) { |
| 15431 | var position = positioners[options.position].call(this, this._active, this._eventPosition); |
| 15432 | if (!position) return; |
| 15433 | var size = this._size = getTooltipSize(this, options); |
| 15434 | var positionAndSize = Object.assign({}, position, this._size); |
| 15435 | var alignment = determineAlignment(chart, options, positionAndSize); |
| 15436 | var point = getBackgroundPoint(options, positionAndSize, alignment, chart); |
| 15437 | if (animX._to !== point.x || animY._to !== point.y) { |
| 15438 | this.xAlign = alignment.xAlign; |
| 15439 | this.yAlign = alignment.yAlign; |
| 15440 | this.width = size.width; |
| 15441 | this.height = size.height; |
| 15442 | this.caretX = position.x; |
| 15443 | this.caretY = position.y; |
| 15444 | this._resolveAnimations().update(this, point); |
| 15445 | } |
| 15446 | } |
| 15447 | } |
| 15448 | }, |
| 15449 | { |
| 15450 | key: "_willRender", |
| 15451 | value: function _willRender() { |
| 15452 | return !!this.opacity; |
| 15453 | } |
| 15454 | }, |
| 15455 | { |
| 15456 | key: "draw", |
| 15457 | value: function draw2(ctx) { |
| 15458 | var options = this.options.setContext(this.getContext()); |
| 15459 | var opacity = this.opacity; |
| 15460 | if (!opacity) return; |
| 15461 | this._updateAnimationTarget(options); |
| 15462 | var tooltipSize = { |
| 15463 | width: this.width, |
| 15464 | height: this.height |
| 15465 | }; |
| 15466 | var pt = { |
| 15467 | x: this.x, |
| 15468 | y: this.y |
| 15469 | }; |
| 15470 | opacity = Math.abs(opacity) < 1e-3 ? 0 : opacity; |
| 15471 | var padding = (0, _helpersSegmentJs.D)(options.padding); |
| 15472 | var hasTooltipContent = this.title.length || this.beforeBody.length || this.body.length || this.afterBody.length || this.footer.length; |
| 15473 | if (options.enabled && hasTooltipContent) { |
| 15474 | ctx.save(); |
| 15475 | ctx.globalAlpha = opacity; |
| 15476 | this.drawBackground(pt, ctx, tooltipSize, options); |
| 15477 | (0, _helpersSegmentJs.az)(ctx, options.textDirection); |
| 15478 | pt.y += padding.top; |
| 15479 | this.drawTitle(pt, ctx, options); |
| 15480 | this.drawBody(pt, ctx, options); |
| 15481 | this.drawFooter(pt, ctx, options); |
| 15482 | (0, _helpersSegmentJs.aB)(ctx, options.textDirection); |
| 15483 | ctx.restore(); |
| 15484 | } |
| 15485 | } |
| 15486 | }, |
| 15487 | { |
| 15488 | key: "getActiveElements", |
| 15489 | value: function getActiveElements() { |
| 15490 | return this._active || []; |
| 15491 | } |
| 15492 | }, |
| 15493 | { |
| 15494 | key: "setActiveElements", |
| 15495 | value: function setActiveElements(activeElements, eventPosition) { |
| 15496 | var _this = this; |
| 15497 | var lastActive = this._active; |
| 15498 | var active = activeElements.map(function(param) { |
| 15499 | var datasetIndex = param.datasetIndex, index66 = param.index; |
| 15500 | var meta = _this.chart.getDatasetMeta(datasetIndex); |
| 15501 | if (!meta) throw new Error("Cannot find a dataset at index " + datasetIndex); |
| 15502 | return { |
| 15503 | datasetIndex: datasetIndex, |
| 15504 | element: meta.data[index66], |
| 15505 | index: index66 |
| 15506 | }; |
| 15507 | }); |
| 15508 | var changed = !(0, _helpersSegmentJs.ag)(lastActive, active); |
| 15509 | var positionChanged = this._positionChanged(active, eventPosition); |
| 15510 | if (changed || positionChanged) { |
| 15511 | this._active = active; |
| 15512 | this._eventPosition = eventPosition; |
| 15513 | this._ignoreReplayEvents = true; |
| 15514 | this.update(true); |
| 15515 | } |
| 15516 | } |
| 15517 | }, |
| 15518 | { |
| 15519 | key: "handleEvent", |
| 15520 | value: function handleEvent(e, replay) { |
| 15521 | var inChartArea = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true; |
| 15522 | if (replay && this._ignoreReplayEvents) return false; |
| 15523 | this._ignoreReplayEvents = false; |
| 15524 | var options = this.options; |
| 15525 | var lastActive = this._active || []; |
| 15526 | var active = this._getActiveElements(e, lastActive, replay, inChartArea); |
| 15527 | var positionChanged = this._positionChanged(active, e); |
| 15528 | var changed = replay || !(0, _helpersSegmentJs.ag)(active, lastActive) || positionChanged; |
| 15529 | if (changed) { |
| 15530 | this._active = active; |
| 15531 | if (options.enabled || options.external) { |
| 15532 | this._eventPosition = { |
| 15533 | x: e.x, |
| 15534 | y: e.y |
| 15535 | }; |
| 15536 | this.update(true, replay); |
| 15537 | } |
| 15538 | } |
| 15539 | return changed; |
| 15540 | } |
| 15541 | }, |
| 15542 | { |
| 15543 | key: "_getActiveElements", |
| 15544 | value: function _getActiveElements(e, lastActive, replay, inChartArea) { |
| 15545 | var options = this.options; |
| 15546 | if (e.type === "mouseout") return []; |
| 15547 | if (!inChartArea) return lastActive; |
| 15548 | var active = this.chart.getElementsAtEventForMode(e, options.mode, options, replay); |
| 15549 | if (options.reverse) active.reverse(); |
| 15550 | return active; |
| 15551 | } |
| 15552 | }, |
| 15553 | { |
| 15554 | key: "_positionChanged", |
| 15555 | value: function _positionChanged(active, e) { |
| 15556 | var ref = this, caretX = ref.caretX, caretY = ref.caretY, options = ref.options; |
| 15557 | var position = positioners[options.position].call(this, active, e); |
| 15558 | return position !== false && (caretX !== position.x || caretY !== position.y); |
| 15559 | } |
| 15560 | } |
| 15561 | ]); |
| 15562 | return Tooltip; |
| 15563 | }((0, _wrapNativeSuperJsDefault.default)(Element)); |
| 15564 | Tooltip.positioners = positioners; |
| 15565 | var plugin_tooltip = { |
| 15566 | id: "tooltip", |
| 15567 | _element: Tooltip, |
| 15568 | positioners: positioners, |
| 15569 | afterInit: function(chart, _args, options) { |
| 15570 | if (options) chart.tooltip = new Tooltip({ |
| 15571 | chart: chart, |
| 15572 | options: options |
| 15573 | }); |
| 15574 | }, |
| 15575 | beforeUpdate: function(chart, _args, options) { |
| 15576 | if (chart.tooltip) chart.tooltip.initialize(options); |
| 15577 | }, |
| 15578 | reset: function(chart, _args, options) { |
| 15579 | if (chart.tooltip) chart.tooltip.initialize(options); |
| 15580 | }, |
| 15581 | afterDraw: function(chart) { |
| 15582 | var tooltip = chart.tooltip; |
| 15583 | if (tooltip && tooltip._willRender()) { |
| 15584 | var args = { |
| 15585 | tooltip: tooltip |
| 15586 | }; |
| 15587 | if (chart.notifyPlugins("beforeTooltipDraw", args) === false) return; |
| 15588 | tooltip.draw(chart.ctx); |
| 15589 | chart.notifyPlugins("afterTooltipDraw", args); |
| 15590 | } |
| 15591 | }, |
| 15592 | afterEvent: function(chart, args) { |
| 15593 | if (chart.tooltip) { |
| 15594 | var useFinalPosition = args.replay; |
| 15595 | if (chart.tooltip.handleEvent(args.event, useFinalPosition, args.inChartArea)) args.changed = true; |
| 15596 | } |
| 15597 | }, |
| 15598 | defaults: { |
| 15599 | enabled: true, |
| 15600 | external: null, |
| 15601 | position: "average", |
| 15602 | backgroundColor: "rgba(0,0,0,0.8)", |
| 15603 | titleColor: "#fff", |
| 15604 | titleFont: { |
| 15605 | weight: "bold" |
| 15606 | }, |
| 15607 | titleSpacing: 2, |
| 15608 | titleMarginBottom: 6, |
| 15609 | titleAlign: "left", |
| 15610 | bodyColor: "#fff", |
| 15611 | bodySpacing: 2, |
| 15612 | bodyFont: {}, |
| 15613 | bodyAlign: "left", |
| 15614 | footerColor: "#fff", |
| 15615 | footerSpacing: 2, |
| 15616 | footerMarginTop: 6, |
| 15617 | footerFont: { |
| 15618 | weight: "bold" |
| 15619 | }, |
| 15620 | footerAlign: "left", |
| 15621 | padding: 6, |
| 15622 | caretPadding: 2, |
| 15623 | caretSize: 5, |
| 15624 | cornerRadius: 6, |
| 15625 | boxHeight: function(ctx, opts) { |
| 15626 | return opts.bodyFont.size; |
| 15627 | }, |
| 15628 | boxWidth: function(ctx, opts) { |
| 15629 | return opts.bodyFont.size; |
| 15630 | }, |
| 15631 | multiKeyBackground: "#fff", |
| 15632 | displayColors: true, |
| 15633 | boxPadding: 0, |
| 15634 | borderColor: "rgba(0,0,0,0)", |
| 15635 | borderWidth: 0, |
| 15636 | animation: { |
| 15637 | duration: 400, |
| 15638 | easing: "easeOutQuart" |
| 15639 | }, |
| 15640 | animations: { |
| 15641 | numbers: { |
| 15642 | type: "number", |
| 15643 | properties: [ |
| 15644 | "x", |
| 15645 | "y", |
| 15646 | "width", |
| 15647 | "height", |
| 15648 | "caretX", |
| 15649 | "caretY" |
| 15650 | ] |
| 15651 | }, |
| 15652 | opacity: { |
| 15653 | easing: "linear", |
| 15654 | duration: 200 |
| 15655 | } |
| 15656 | }, |
| 15657 | callbacks: { |
| 15658 | beforeTitle: (0, _helpersSegmentJs.aC), |
| 15659 | title: function(tooltipItems) { |
| 15660 | if (tooltipItems.length > 0) { |
| 15661 | var item = tooltipItems[0]; |
| 15662 | var labels = item.chart.data.labels; |
| 15663 | var labelCount = labels ? labels.length : 0; |
| 15664 | if (this && this.options && this.options.mode === "dataset") return item.dataset.label || ""; |
| 15665 | else if (item.label) return item.label; |
| 15666 | else if (labelCount > 0 && item.dataIndex < labelCount) return labels[item.dataIndex]; |
| 15667 | } |
| 15668 | return ""; |
| 15669 | }, |
| 15670 | afterTitle: (0, _helpersSegmentJs.aC), |
| 15671 | beforeBody: (0, _helpersSegmentJs.aC), |
| 15672 | beforeLabel: (0, _helpersSegmentJs.aC), |
| 15673 | label: function(tooltipItem) { |
| 15674 | if (this && this.options && this.options.mode === "dataset") return tooltipItem.label + ": " + tooltipItem.formattedValue || tooltipItem.formattedValue; |
| 15675 | var label = tooltipItem.dataset.label || ""; |
| 15676 | if (label) label += ": "; |
| 15677 | var value = tooltipItem.formattedValue; |
| 15678 | if (!(0, _helpersSegmentJs.k)(value)) label += value; |
| 15679 | return label; |
| 15680 | }, |
| 15681 | labelColor: function(tooltipItem) { |
| 15682 | var meta = tooltipItem.chart.getDatasetMeta(tooltipItem.datasetIndex); |
| 15683 | var options = meta.controller.getStyle(tooltipItem.dataIndex); |
| 15684 | return { |
| 15685 | borderColor: options.borderColor, |
| 15686 | backgroundColor: options.backgroundColor, |
| 15687 | borderWidth: options.borderWidth, |
| 15688 | borderDash: options.borderDash, |
| 15689 | borderDashOffset: options.borderDashOffset, |
| 15690 | borderRadius: 0 |
| 15691 | }; |
| 15692 | }, |
| 15693 | labelTextColor: function() { |
| 15694 | return this.options.bodyColor; |
| 15695 | }, |
| 15696 | labelPointStyle: function(tooltipItem) { |
| 15697 | var meta = tooltipItem.chart.getDatasetMeta(tooltipItem.datasetIndex); |
| 15698 | var options = meta.controller.getStyle(tooltipItem.dataIndex); |
| 15699 | return { |
| 15700 | pointStyle: options.pointStyle, |
| 15701 | rotation: options.rotation |
| 15702 | }; |
| 15703 | }, |
| 15704 | afterLabel: (0, _helpersSegmentJs.aC), |
| 15705 | afterBody: (0, _helpersSegmentJs.aC), |
| 15706 | beforeFooter: (0, _helpersSegmentJs.aC), |
| 15707 | footer: (0, _helpersSegmentJs.aC), |
| 15708 | afterFooter: (0, _helpersSegmentJs.aC) |
| 15709 | } |
| 15710 | }, |
| 15711 | defaultRoutes: { |
| 15712 | bodyFont: "font", |
| 15713 | footerFont: "font", |
| 15714 | titleFont: "font" |
| 15715 | }, |
| 15716 | descriptors: { |
| 15717 | _scriptable: function(name) { |
| 15718 | return name !== "filter" && name !== "itemSort" && name !== "external"; |
| 15719 | }, |
| 15720 | _indexable: false, |
| 15721 | callbacks: { |
| 15722 | _scriptable: false, |
| 15723 | _indexable: false |
| 15724 | }, |
| 15725 | animation: { |
| 15726 | _fallback: false |
| 15727 | }, |
| 15728 | animations: { |
| 15729 | _fallback: "animation" |
| 15730 | } |
| 15731 | }, |
| 15732 | additionalOptionScopes: [ |
| 15733 | "interaction" |
| 15734 | ] |
| 15735 | }; |
| 15736 | var plugins = /*#__PURE__*/ Object.freeze({ |
| 15737 | __proto__: null, |
| 15738 | Decimation: plugin_decimation, |
| 15739 | Filler: index, |
| 15740 | Legend: plugin_legend, |
| 15741 | SubTitle: plugin_subtitle, |
| 15742 | Title: plugin_title, |
| 15743 | Tooltip: plugin_tooltip |
| 15744 | }); |
| 15745 | var addIfString = function(labels, raw, index67, addedLabels) { |
| 15746 | if (typeof raw === "string") { |
| 15747 | index67 = labels.push(raw) - 1; |
| 15748 | addedLabels.unshift({ |
| 15749 | index: index67, |
| 15750 | label: raw |
| 15751 | }); |
| 15752 | } else if (isNaN(raw)) index67 = null; |
| 15753 | return index67; |
| 15754 | }; |
| 15755 | function findOrAddLabel(labels, raw, index68, addedLabels) { |
| 15756 | var first = labels.indexOf(raw); |
| 15757 | if (first === -1) return addIfString(labels, raw, index68, addedLabels); |
| 15758 | var last = labels.lastIndexOf(raw); |
| 15759 | return first !== last ? index68 : first; |
| 15760 | } |
| 15761 | var validIndex = function(index69, max) { |
| 15762 | return index69 === null ? null : (0, _helpersSegmentJs.w)(Math.round(index69), 0, max); |
| 15763 | }; |
| 15764 | var CategoryScale = /*#__PURE__*/ function(Scale) { |
| 15765 | "use strict"; |
| 15766 | (0, _inheritsJsDefault.default)(CategoryScale, Scale); |
| 15767 | var _super = (0, _createSuperJsDefault.default)(CategoryScale); |
| 15768 | function CategoryScale(cfg) { |
| 15769 | (0, _classCallCheckJsDefault.default)(this, CategoryScale); |
| 15770 | var _this; |
| 15771 | _this = _super.call(this, cfg); |
| 15772 | _this._startValue = undefined; |
| 15773 | _this._valueRange = 0; |
| 15774 | _this._addedLabels = []; |
| 15775 | return _this; |
| 15776 | } |
| 15777 | (0, _createClassJsDefault.default)(CategoryScale, [ |
| 15778 | { |
| 15779 | key: "init", |
| 15780 | value: function init(scaleOptions) { |
| 15781 | var added = this._addedLabels; |
| 15782 | if (added.length) { |
| 15783 | var labels = this.getLabels(); |
| 15784 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 15785 | try { |
| 15786 | for(var _iterator = added[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 15787 | var _value = _step.value, index70 = _value.index, label = _value.label; |
| 15788 | if (labels[index70] === label) labels.splice(index70, 1); |
| 15789 | } |
| 15790 | } catch (err) { |
| 15791 | _didIteratorError = true; |
| 15792 | _iteratorError = err; |
| 15793 | } finally{ |
| 15794 | try { |
| 15795 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 15796 | _iterator.return(); |
| 15797 | } |
| 15798 | } finally{ |
| 15799 | if (_didIteratorError) { |
| 15800 | throw _iteratorError; |
| 15801 | } |
| 15802 | } |
| 15803 | } |
| 15804 | this._addedLabels = []; |
| 15805 | } |
| 15806 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(CategoryScale.prototype), "init", this).call(this, scaleOptions); |
| 15807 | } |
| 15808 | }, |
| 15809 | { |
| 15810 | key: "parse", |
| 15811 | value: function parse1(raw, index71) { |
| 15812 | if ((0, _helpersSegmentJs.k)(raw)) return null; |
| 15813 | var labels = this.getLabels(); |
| 15814 | index71 = isFinite(index71) && labels[index71] === raw ? index71 : findOrAddLabel(labels, raw, (0, _helpersSegmentJs.v)(index71, raw), this._addedLabels); |
| 15815 | return validIndex(index71, labels.length - 1); |
| 15816 | } |
| 15817 | }, |
| 15818 | { |
| 15819 | key: "determineDataLimits", |
| 15820 | value: function determineDataLimits() { |
| 15821 | var ref = this.getUserBounds(), minDefined = ref.minDefined, maxDefined = ref.maxDefined; |
| 15822 | var ref14 = this.getMinMax(true), min = ref14.min, max = ref14.max; |
| 15823 | if (this.options.bounds === "ticks") { |
| 15824 | if (!minDefined) min = 0; |
| 15825 | if (!maxDefined) max = this.getLabels().length - 1; |
| 15826 | } |
| 15827 | this.min = min; |
| 15828 | this.max = max; |
| 15829 | } |
| 15830 | }, |
| 15831 | { |
| 15832 | key: "buildTicks", |
| 15833 | value: function buildTicks() { |
| 15834 | var min = this.min; |
| 15835 | var max = this.max; |
| 15836 | var offset = this.options.offset; |
| 15837 | var ticks = []; |
| 15838 | var labels = this.getLabels(); |
| 15839 | labels = min === 0 && max === labels.length - 1 ? labels : labels.slice(min, max + 1); |
| 15840 | this._valueRange = Math.max(labels.length - (offset ? 0 : 1), 1); |
| 15841 | this._startValue = this.min - (offset ? 0.5 : 0); |
| 15842 | for(var value = min; value <= max; value++)ticks.push({ |
| 15843 | value: value |
| 15844 | }); |
| 15845 | return ticks; |
| 15846 | } |
| 15847 | }, |
| 15848 | { |
| 15849 | key: "getLabelForValue", |
| 15850 | value: function getLabelForValue(value) { |
| 15851 | var labels = this.getLabels(); |
| 15852 | if (value >= 0 && value < labels.length) return labels[value]; |
| 15853 | return value; |
| 15854 | } |
| 15855 | }, |
| 15856 | { |
| 15857 | key: "configure", |
| 15858 | value: function configure() { |
| 15859 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(CategoryScale.prototype), "configure", this).call(this); |
| 15860 | if (!this.isHorizontal()) this._reversePixels = !this._reversePixels; |
| 15861 | } |
| 15862 | }, |
| 15863 | { |
| 15864 | key: "getPixelForValue", |
| 15865 | value: function getPixelForValue(value) { |
| 15866 | if (typeof value !== "number") value = this.parse(value); |
| 15867 | return value === null ? NaN : this.getPixelForDecimal((value - this._startValue) / this._valueRange); |
| 15868 | } |
| 15869 | }, |
| 15870 | { |
| 15871 | key: "getPixelForTick", |
| 15872 | value: function getPixelForTick(index72) { |
| 15873 | var ticks = this.ticks; |
| 15874 | if (index72 < 0 || index72 > ticks.length - 1) return null; |
| 15875 | return this.getPixelForValue(ticks[index72].value); |
| 15876 | } |
| 15877 | }, |
| 15878 | { |
| 15879 | key: "getValueForPixel", |
| 15880 | value: function getValueForPixel(pixel) { |
| 15881 | return Math.round(this._startValue + this.getDecimalForPixel(pixel) * this._valueRange); |
| 15882 | } |
| 15883 | }, |
| 15884 | { |
| 15885 | key: "getBasePixel", |
| 15886 | value: function getBasePixel() { |
| 15887 | return this.bottom; |
| 15888 | } |
| 15889 | } |
| 15890 | ]); |
| 15891 | return CategoryScale; |
| 15892 | }(Scale); |
| 15893 | CategoryScale.id = "category"; |
| 15894 | CategoryScale.defaults = { |
| 15895 | ticks: { |
| 15896 | callback: CategoryScale.prototype.getLabelForValue |
| 15897 | } |
| 15898 | }; |
| 15899 | function generateTicks$1(generationOptions, dataRange) { |
| 15900 | var ticks = []; |
| 15901 | var MIN_SPACING = 1e-14; |
| 15902 | var bounds = generationOptions.bounds, step = generationOptions.step, min = generationOptions.min, max = generationOptions.max, precision = generationOptions.precision, count = generationOptions.count, maxTicks = generationOptions.maxTicks, maxDigits = generationOptions.maxDigits, includeBounds = generationOptions.includeBounds; |
| 15903 | var unit = step || 1; |
| 15904 | var maxSpaces = maxTicks - 1; |
| 15905 | var rmin = dataRange.min, rmax = dataRange.max; |
| 15906 | var minDefined = !(0, _helpersSegmentJs.k)(min); |
| 15907 | var maxDefined = !(0, _helpersSegmentJs.k)(max); |
| 15908 | var countDefined = !(0, _helpersSegmentJs.k)(count); |
| 15909 | var minSpacing = (rmax - rmin) / (maxDigits + 1); |
| 15910 | var spacing = (0, _helpersSegmentJs.aF)((rmax - rmin) / maxSpaces / unit) * unit; |
| 15911 | var factor, niceMin, niceMax, numSpaces; |
| 15912 | if (spacing < MIN_SPACING && !minDefined && !maxDefined) return [ |
| 15913 | { |
| 15914 | value: rmin |
| 15915 | }, |
| 15916 | { |
| 15917 | value: rmax |
| 15918 | } |
| 15919 | ]; |
| 15920 | numSpaces = Math.ceil(rmax / spacing) - Math.floor(rmin / spacing); |
| 15921 | if (numSpaces > maxSpaces) spacing = (0, _helpersSegmentJs.aF)(numSpaces * spacing / maxSpaces / unit) * unit; |
| 15922 | if (!(0, _helpersSegmentJs.k)(precision)) { |
| 15923 | factor = Math.pow(10, precision); |
| 15924 | spacing = Math.ceil(spacing * factor) / factor; |
| 15925 | } |
| 15926 | if (bounds === "ticks") { |
| 15927 | niceMin = Math.floor(rmin / spacing) * spacing; |
| 15928 | niceMax = Math.ceil(rmax / spacing) * spacing; |
| 15929 | } else { |
| 15930 | niceMin = rmin; |
| 15931 | niceMax = rmax; |
| 15932 | } |
| 15933 | if (minDefined && maxDefined && step && (0, _helpersSegmentJs.aG)((max - min) / step, spacing / 1000)) { |
| 15934 | numSpaces = Math.round(Math.min((max - min) / spacing, maxTicks)); |
| 15935 | spacing = (max - min) / numSpaces; |
| 15936 | niceMin = min; |
| 15937 | niceMax = max; |
| 15938 | } else if (countDefined) { |
| 15939 | niceMin = minDefined ? min : niceMin; |
| 15940 | niceMax = maxDefined ? max : niceMax; |
| 15941 | numSpaces = count - 1; |
| 15942 | spacing = (niceMax - niceMin) / numSpaces; |
| 15943 | } else { |
| 15944 | numSpaces = (niceMax - niceMin) / spacing; |
| 15945 | if ((0, _helpersSegmentJs.aH)(numSpaces, Math.round(numSpaces), spacing / 1000)) numSpaces = Math.round(numSpaces); |
| 15946 | else numSpaces = Math.ceil(numSpaces); |
| 15947 | } |
| 15948 | var decimalPlaces = Math.max((0, _helpersSegmentJs.aI)(spacing), (0, _helpersSegmentJs.aI)(niceMin)); |
| 15949 | factor = Math.pow(10, (0, _helpersSegmentJs.k)(precision) ? decimalPlaces : precision); |
| 15950 | niceMin = Math.round(niceMin * factor) / factor; |
| 15951 | niceMax = Math.round(niceMax * factor) / factor; |
| 15952 | var j = 0; |
| 15953 | if (minDefined) { |
| 15954 | if (includeBounds && niceMin !== min) { |
| 15955 | ticks.push({ |
| 15956 | value: min |
| 15957 | }); |
| 15958 | if (niceMin < min) j++; |
| 15959 | if ((0, _helpersSegmentJs.aH)(Math.round((niceMin + j * spacing) * factor) / factor, min, relativeLabelSize(min, minSpacing, generationOptions))) j++; |
| 15960 | } else if (niceMin < min) j++; |
| 15961 | } |
| 15962 | for(; j < numSpaces; ++j)ticks.push({ |
| 15963 | value: Math.round((niceMin + j * spacing) * factor) / factor |
| 15964 | }); |
| 15965 | if (maxDefined && includeBounds && niceMax !== max) { |
| 15966 | if (ticks.length && (0, _helpersSegmentJs.aH)(ticks[ticks.length - 1].value, max, relativeLabelSize(max, minSpacing, generationOptions))) ticks[ticks.length - 1].value = max; |
| 15967 | else ticks.push({ |
| 15968 | value: max |
| 15969 | }); |
| 15970 | } else if (!maxDefined || niceMax === max) ticks.push({ |
| 15971 | value: niceMax |
| 15972 | }); |
| 15973 | return ticks; |
| 15974 | } |
| 15975 | function relativeLabelSize(value, minSpacing, param) { |
| 15976 | var horizontal = param.horizontal, minRotation = param.minRotation; |
| 15977 | var rad = (0, _helpersSegmentJs.t)(minRotation); |
| 15978 | var ratio = (horizontal ? Math.sin(rad) : Math.cos(rad)) || 0.001; |
| 15979 | var length = 0.75 * minSpacing * ("" + value).length; |
| 15980 | return Math.min(minSpacing / ratio, length); |
| 15981 | } |
| 15982 | var LinearScaleBase = /*#__PURE__*/ function(Scale) { |
| 15983 | "use strict"; |
| 15984 | (0, _inheritsJsDefault.default)(LinearScaleBase, Scale); |
| 15985 | var _super = (0, _createSuperJsDefault.default)(LinearScaleBase); |
| 15986 | function LinearScaleBase(cfg) { |
| 15987 | (0, _classCallCheckJsDefault.default)(this, LinearScaleBase); |
| 15988 | var _this; |
| 15989 | _this = _super.call(this, cfg); |
| 15990 | _this.start = undefined; |
| 15991 | _this.end = undefined; |
| 15992 | _this._startValue = undefined; |
| 15993 | _this._endValue = undefined; |
| 15994 | _this._valueRange = 0; |
| 15995 | return _this; |
| 15996 | } |
| 15997 | (0, _createClassJsDefault.default)(LinearScaleBase, [ |
| 15998 | { |
| 15999 | key: "parse", |
| 16000 | value: function parse1(raw, index) { |
| 16001 | if ((0, _helpersSegmentJs.k)(raw)) return null; |
| 16002 | if ((typeof raw === "number" || raw instanceof Number) && !isFinite(+raw)) return null; |
| 16003 | return +raw; |
| 16004 | } |
| 16005 | }, |
| 16006 | { |
| 16007 | key: "handleTickRangeOptions", |
| 16008 | value: function handleTickRangeOptions() { |
| 16009 | var beginAtZero = this.options.beginAtZero; |
| 16010 | var ref = this.getUserBounds(), minDefined = ref.minDefined, maxDefined = ref.maxDefined; |
| 16011 | var ref15 = this, min = ref15.min, max = ref15.max; |
| 16012 | var setMin = function(v) { |
| 16013 | return min = minDefined ? min : v; |
| 16014 | }; |
| 16015 | var setMax = function(v) { |
| 16016 | return max = maxDefined ? max : v; |
| 16017 | }; |
| 16018 | if (beginAtZero) { |
| 16019 | var minSign = (0, _helpersSegmentJs.s)(min); |
| 16020 | var maxSign = (0, _helpersSegmentJs.s)(max); |
| 16021 | if (minSign < 0 && maxSign < 0) setMax(0); |
| 16022 | else if (minSign > 0 && maxSign > 0) setMin(0); |
| 16023 | } |
| 16024 | if (min === max) { |
| 16025 | var offset = 1; |
| 16026 | if (max >= Number.MAX_SAFE_INTEGER || min <= Number.MIN_SAFE_INTEGER) offset = Math.abs(max * 0.05); |
| 16027 | setMax(max + offset); |
| 16028 | if (!beginAtZero) setMin(min - offset); |
| 16029 | } |
| 16030 | this.min = min; |
| 16031 | this.max = max; |
| 16032 | } |
| 16033 | }, |
| 16034 | { |
| 16035 | key: "getTickLimit", |
| 16036 | value: function getTickLimit() { |
| 16037 | var tickOpts = this.options.ticks; |
| 16038 | var maxTicksLimit = tickOpts.maxTicksLimit, stepSize = tickOpts.stepSize; |
| 16039 | var maxTicks; |
| 16040 | if (stepSize) { |
| 16041 | maxTicks = Math.ceil(this.max / stepSize) - Math.floor(this.min / stepSize) + 1; |
| 16042 | if (maxTicks > 1000) { |
| 16043 | console.warn("scales.".concat(this.id, ".ticks.stepSize: ").concat(stepSize, " would result generating up to ").concat(maxTicks, " ticks. Limiting to 1000.")); |
| 16044 | maxTicks = 1000; |
| 16045 | } |
| 16046 | } else { |
| 16047 | maxTicks = this.computeTickLimit(); |
| 16048 | maxTicksLimit = maxTicksLimit || 11; |
| 16049 | } |
| 16050 | if (maxTicksLimit) maxTicks = Math.min(maxTicksLimit, maxTicks); |
| 16051 | return maxTicks; |
| 16052 | } |
| 16053 | }, |
| 16054 | { |
| 16055 | key: "computeTickLimit", |
| 16056 | value: function computeTickLimit() { |
| 16057 | return Number.POSITIVE_INFINITY; |
| 16058 | } |
| 16059 | }, |
| 16060 | { |
| 16061 | key: "buildTicks", |
| 16062 | value: function buildTicks() { |
| 16063 | var opts = this.options; |
| 16064 | var tickOpts = opts.ticks; |
| 16065 | var maxTicks = this.getTickLimit(); |
| 16066 | maxTicks = Math.max(2, maxTicks); |
| 16067 | var numericGeneratorOptions = { |
| 16068 | maxTicks: maxTicks, |
| 16069 | bounds: opts.bounds, |
| 16070 | min: opts.min, |
| 16071 | max: opts.max, |
| 16072 | precision: tickOpts.precision, |
| 16073 | step: tickOpts.stepSize, |
| 16074 | count: tickOpts.count, |
| 16075 | maxDigits: this._maxDigits(), |
| 16076 | horizontal: this.isHorizontal(), |
| 16077 | minRotation: tickOpts.minRotation || 0, |
| 16078 | includeBounds: tickOpts.includeBounds !== false |
| 16079 | }; |
| 16080 | var dataRange = this._range || this; |
| 16081 | var ticks = generateTicks$1(numericGeneratorOptions, dataRange); |
| 16082 | if (opts.bounds === "ticks") (0, _helpersSegmentJs.aE)(ticks, this, "value"); |
| 16083 | if (opts.reverse) { |
| 16084 | ticks.reverse(); |
| 16085 | this.start = this.max; |
| 16086 | this.end = this.min; |
| 16087 | } else { |
| 16088 | this.start = this.min; |
| 16089 | this.end = this.max; |
| 16090 | } |
| 16091 | return ticks; |
| 16092 | } |
| 16093 | }, |
| 16094 | { |
| 16095 | key: "configure", |
| 16096 | value: function configure() { |
| 16097 | var ticks = this.ticks; |
| 16098 | var start = this.min; |
| 16099 | var end = this.max; |
| 16100 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(LinearScaleBase.prototype), "configure", this).call(this); |
| 16101 | if (this.options.offset && ticks.length) { |
| 16102 | var offset = (end - start) / Math.max(ticks.length - 1, 1) / 2; |
| 16103 | start -= offset; |
| 16104 | end += offset; |
| 16105 | } |
| 16106 | this._startValue = start; |
| 16107 | this._endValue = end; |
| 16108 | this._valueRange = end - start; |
| 16109 | } |
| 16110 | }, |
| 16111 | { |
| 16112 | key: "getLabelForValue", |
| 16113 | value: function getLabelForValue(value) { |
| 16114 | return (0, _helpersSegmentJs.o)(value, this.chart.options.locale, this.options.ticks.format); |
| 16115 | } |
| 16116 | } |
| 16117 | ]); |
| 16118 | return LinearScaleBase; |
| 16119 | }(Scale); |
| 16120 | var LinearScale = /*#__PURE__*/ function(LinearScaleBase) { |
| 16121 | "use strict"; |
| 16122 | (0, _inheritsJsDefault.default)(LinearScale, LinearScaleBase); |
| 16123 | var _super = (0, _createSuperJsDefault.default)(LinearScale); |
| 16124 | function LinearScale() { |
| 16125 | (0, _classCallCheckJsDefault.default)(this, LinearScale); |
| 16126 | return _super.apply(this, arguments); |
| 16127 | } |
| 16128 | (0, _createClassJsDefault.default)(LinearScale, [ |
| 16129 | { |
| 16130 | key: "determineDataLimits", |
| 16131 | value: function determineDataLimits() { |
| 16132 | var ref = this.getMinMax(true), min = ref.min, max = ref.max; |
| 16133 | this.min = (0, _helpersSegmentJs.g)(min) ? min : 0; |
| 16134 | this.max = (0, _helpersSegmentJs.g)(max) ? max : 1; |
| 16135 | this.handleTickRangeOptions(); |
| 16136 | } |
| 16137 | }, |
| 16138 | { |
| 16139 | key: "computeTickLimit", |
| 16140 | value: function computeTickLimit() { |
| 16141 | var horizontal = this.isHorizontal(); |
| 16142 | var length = horizontal ? this.width : this.height; |
| 16143 | var minRotation = (0, _helpersSegmentJs.t)(this.options.ticks.minRotation); |
| 16144 | var ratio = (horizontal ? Math.sin(minRotation) : Math.cos(minRotation)) || 0.001; |
| 16145 | var tickFont = this._resolveTickFontOptions(0); |
| 16146 | return Math.ceil(length / Math.min(40, tickFont.lineHeight / ratio)); |
| 16147 | } |
| 16148 | }, |
| 16149 | { |
| 16150 | key: "getPixelForValue", |
| 16151 | value: function getPixelForValue(value) { |
| 16152 | return value === null ? NaN : this.getPixelForDecimal((value - this._startValue) / this._valueRange); |
| 16153 | } |
| 16154 | }, |
| 16155 | { |
| 16156 | key: "getValueForPixel", |
| 16157 | value: function getValueForPixel(pixel) { |
| 16158 | return this._startValue + this.getDecimalForPixel(pixel) * this._valueRange; |
| 16159 | } |
| 16160 | } |
| 16161 | ]); |
| 16162 | return LinearScale; |
| 16163 | }(LinearScaleBase); |
| 16164 | LinearScale.id = "linear"; |
| 16165 | LinearScale.defaults = { |
| 16166 | ticks: { |
| 16167 | callback: Ticks.formatters.numeric |
| 16168 | } |
| 16169 | }; |
| 16170 | function isMajor(tickVal) { |
| 16171 | var remain = tickVal / Math.pow(10, Math.floor((0, _helpersSegmentJs.M)(tickVal))); |
| 16172 | return remain === 1; |
| 16173 | } |
| 16174 | function generateTicks(generationOptions, dataRange) { |
| 16175 | var endExp = Math.floor((0, _helpersSegmentJs.M)(dataRange.max)); |
| 16176 | var endSignificand = Math.ceil(dataRange.max / Math.pow(10, endExp)); |
| 16177 | var ticks = []; |
| 16178 | var tickVal = (0, _helpersSegmentJs.O)(generationOptions.min, Math.pow(10, Math.floor((0, _helpersSegmentJs.M)(dataRange.min)))); |
| 16179 | var exp = Math.floor((0, _helpersSegmentJs.M)(tickVal)); |
| 16180 | var significand = Math.floor(tickVal / Math.pow(10, exp)); |
| 16181 | var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1; |
| 16182 | do { |
| 16183 | ticks.push({ |
| 16184 | value: tickVal, |
| 16185 | major: isMajor(tickVal) |
| 16186 | }); |
| 16187 | ++significand; |
| 16188 | if (significand === 10) { |
| 16189 | significand = 1; |
| 16190 | ++exp; |
| 16191 | precision = exp >= 0 ? 1 : precision; |
| 16192 | } |
| 16193 | tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision; |
| 16194 | }while (exp < endExp || exp === endExp && significand < endSignificand); |
| 16195 | var lastTick = (0, _helpersSegmentJs.O)(generationOptions.max, tickVal); |
| 16196 | ticks.push({ |
| 16197 | value: lastTick, |
| 16198 | major: isMajor(tickVal) |
| 16199 | }); |
| 16200 | return ticks; |
| 16201 | } |
| 16202 | var LogarithmicScale = /*#__PURE__*/ function(Scale) { |
| 16203 | "use strict"; |
| 16204 | (0, _inheritsJsDefault.default)(LogarithmicScale, Scale); |
| 16205 | var _super = (0, _createSuperJsDefault.default)(LogarithmicScale); |
| 16206 | function LogarithmicScale(cfg) { |
| 16207 | (0, _classCallCheckJsDefault.default)(this, LogarithmicScale); |
| 16208 | var _this; |
| 16209 | _this = _super.call(this, cfg); |
| 16210 | _this.start = undefined; |
| 16211 | _this.end = undefined; |
| 16212 | _this._startValue = undefined; |
| 16213 | _this._valueRange = 0; |
| 16214 | return _this; |
| 16215 | } |
| 16216 | (0, _createClassJsDefault.default)(LogarithmicScale, [ |
| 16217 | { |
| 16218 | key: "parse", |
| 16219 | value: function parse1(raw, index73) { |
| 16220 | var value = LinearScaleBase.prototype.parse.apply(this, [ |
| 16221 | raw, |
| 16222 | index73 |
| 16223 | ]); |
| 16224 | if (value === 0) { |
| 16225 | this._zero = true; |
| 16226 | return undefined; |
| 16227 | } |
| 16228 | return (0, _helpersSegmentJs.g)(value) && value > 0 ? value : null; |
| 16229 | } |
| 16230 | }, |
| 16231 | { |
| 16232 | key: "determineDataLimits", |
| 16233 | value: function determineDataLimits() { |
| 16234 | var ref = this.getMinMax(true), min = ref.min, max = ref.max; |
| 16235 | this.min = (0, _helpersSegmentJs.g)(min) ? Math.max(0, min) : null; |
| 16236 | this.max = (0, _helpersSegmentJs.g)(max) ? Math.max(0, max) : null; |
| 16237 | if (this.options.beginAtZero) this._zero = true; |
| 16238 | this.handleTickRangeOptions(); |
| 16239 | } |
| 16240 | }, |
| 16241 | { |
| 16242 | key: "handleTickRangeOptions", |
| 16243 | value: function handleTickRangeOptions() { |
| 16244 | var ref = this.getUserBounds(), minDefined = ref.minDefined, maxDefined = ref.maxDefined; |
| 16245 | var min = this.min; |
| 16246 | var max = this.max; |
| 16247 | var setMin = function(v) { |
| 16248 | return min = minDefined ? min : v; |
| 16249 | }; |
| 16250 | var setMax = function(v) { |
| 16251 | return max = maxDefined ? max : v; |
| 16252 | }; |
| 16253 | var exp = function(v, m) { |
| 16254 | return Math.pow(10, Math.floor((0, _helpersSegmentJs.M)(v)) + m); |
| 16255 | }; |
| 16256 | if (min === max) { |
| 16257 | if (min <= 0) { |
| 16258 | setMin(1); |
| 16259 | setMax(10); |
| 16260 | } else { |
| 16261 | setMin(exp(min, -1)); |
| 16262 | setMax(exp(max, 1)); |
| 16263 | } |
| 16264 | } |
| 16265 | if (min <= 0) setMin(exp(max, -1)); |
| 16266 | if (max <= 0) setMax(exp(min, 1)); |
| 16267 | if (this._zero && this.min !== this._suggestedMin && min === exp(this.min, 0)) setMin(exp(min, -1)); |
| 16268 | this.min = min; |
| 16269 | this.max = max; |
| 16270 | } |
| 16271 | }, |
| 16272 | { |
| 16273 | key: "buildTicks", |
| 16274 | value: function buildTicks() { |
| 16275 | var opts = this.options; |
| 16276 | var generationOptions = { |
| 16277 | min: this._userMin, |
| 16278 | max: this._userMax |
| 16279 | }; |
| 16280 | var ticks = generateTicks(generationOptions, this); |
| 16281 | if (opts.bounds === "ticks") (0, _helpersSegmentJs.aE)(ticks, this, "value"); |
| 16282 | if (opts.reverse) { |
| 16283 | ticks.reverse(); |
| 16284 | this.start = this.max; |
| 16285 | this.end = this.min; |
| 16286 | } else { |
| 16287 | this.start = this.min; |
| 16288 | this.end = this.max; |
| 16289 | } |
| 16290 | return ticks; |
| 16291 | } |
| 16292 | }, |
| 16293 | { |
| 16294 | key: "getLabelForValue", |
| 16295 | value: function getLabelForValue(value) { |
| 16296 | return value === undefined ? "0" : (0, _helpersSegmentJs.o)(value, this.chart.options.locale, this.options.ticks.format); |
| 16297 | } |
| 16298 | }, |
| 16299 | { |
| 16300 | key: "configure", |
| 16301 | value: function configure() { |
| 16302 | var start = this.min; |
| 16303 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(LogarithmicScale.prototype), "configure", this).call(this); |
| 16304 | this._startValue = (0, _helpersSegmentJs.M)(start); |
| 16305 | this._valueRange = (0, _helpersSegmentJs.M)(this.max) - (0, _helpersSegmentJs.M)(start); |
| 16306 | } |
| 16307 | }, |
| 16308 | { |
| 16309 | key: "getPixelForValue", |
| 16310 | value: function getPixelForValue(value) { |
| 16311 | if (value === undefined || value === 0) value = this.min; |
| 16312 | if (value === null || isNaN(value)) return NaN; |
| 16313 | return this.getPixelForDecimal(value === this.min ? 0 : ((0, _helpersSegmentJs.M)(value) - this._startValue) / this._valueRange); |
| 16314 | } |
| 16315 | }, |
| 16316 | { |
| 16317 | key: "getValueForPixel", |
| 16318 | value: function getValueForPixel(pixel) { |
| 16319 | var decimal = this.getDecimalForPixel(pixel); |
| 16320 | return Math.pow(10, this._startValue + decimal * this._valueRange); |
| 16321 | } |
| 16322 | } |
| 16323 | ]); |
| 16324 | return LogarithmicScale; |
| 16325 | }(Scale); |
| 16326 | LogarithmicScale.id = "logarithmic"; |
| 16327 | LogarithmicScale.defaults = { |
| 16328 | ticks: { |
| 16329 | callback: Ticks.formatters.logarithmic, |
| 16330 | major: { |
| 16331 | enabled: true |
| 16332 | } |
| 16333 | } |
| 16334 | }; |
| 16335 | function getTickBackdropHeight(opts) { |
| 16336 | var tickOpts = opts.ticks; |
| 16337 | if (tickOpts.display && opts.display) { |
| 16338 | var padding = (0, _helpersSegmentJs.D)(tickOpts.backdropPadding); |
| 16339 | return (0, _helpersSegmentJs.v)(tickOpts.font && tickOpts.font.size, (0, _helpersSegmentJs.d).font.size) + padding.height; |
| 16340 | } |
| 16341 | return 0; |
| 16342 | } |
| 16343 | function measureLabelSize(ctx, font, label) { |
| 16344 | label = (0, _helpersSegmentJs.b)(label) ? label : [ |
| 16345 | label |
| 16346 | ]; |
| 16347 | return { |
| 16348 | w: (0, _helpersSegmentJs.aJ)(ctx, font.string, label), |
| 16349 | h: label.length * font.lineHeight |
| 16350 | }; |
| 16351 | } |
| 16352 | function determineLimits(angle, pos, size, min, max) { |
| 16353 | if (angle === min || angle === max) return { |
| 16354 | start: pos - size / 2, |
| 16355 | end: pos + size / 2 |
| 16356 | }; |
| 16357 | else if (angle < min || angle > max) return { |
| 16358 | start: pos - size, |
| 16359 | end: pos |
| 16360 | }; |
| 16361 | return { |
| 16362 | start: pos, |
| 16363 | end: pos + size |
| 16364 | }; |
| 16365 | } |
| 16366 | function fitWithPointLabels(scale) { |
| 16367 | var orig = { |
| 16368 | l: scale.left + scale._padding.left, |
| 16369 | r: scale.right - scale._padding.right, |
| 16370 | t: scale.top + scale._padding.top, |
| 16371 | b: scale.bottom - scale._padding.bottom |
| 16372 | }; |
| 16373 | var limits = Object.assign({}, orig); |
| 16374 | var labelSizes = []; |
| 16375 | var padding = []; |
| 16376 | var valueCount = scale._pointLabels.length; |
| 16377 | var pointLabelOpts = scale.options.pointLabels; |
| 16378 | var additionalAngle = pointLabelOpts.centerPointLabels ? (0, _helpersSegmentJs.P) / valueCount : 0; |
| 16379 | for(var i = 0; i < valueCount; i++){ |
| 16380 | var opts = pointLabelOpts.setContext(scale.getPointLabelContext(i)); |
| 16381 | padding[i] = opts.padding; |
| 16382 | var pointPosition = scale.getPointPosition(i, scale.drawingArea + padding[i], additionalAngle); |
| 16383 | var plFont = (0, _helpersSegmentJs.$)(opts.font); |
| 16384 | var textSize = measureLabelSize(scale.ctx, plFont, scale._pointLabels[i]); |
| 16385 | labelSizes[i] = textSize; |
| 16386 | var angleRadians = (0, _helpersSegmentJs.ax)(scale.getIndexAngle(i) + additionalAngle); |
| 16387 | var angle = Math.round((0, _helpersSegmentJs.S)(angleRadians)); |
| 16388 | var hLimits = determineLimits(angle, pointPosition.x, textSize.w, 0, 180); |
| 16389 | var vLimits = determineLimits(angle, pointPosition.y, textSize.h, 90, 270); |
| 16390 | updateLimits(limits, orig, angleRadians, hLimits, vLimits); |
| 16391 | } |
| 16392 | scale.setCenterPoint(orig.l - limits.l, limits.r - orig.r, orig.t - limits.t, limits.b - orig.b); |
| 16393 | scale._pointLabelItems = buildPointLabelItems(scale, labelSizes, padding); |
| 16394 | } |
| 16395 | function updateLimits(limits, orig, angle, hLimits, vLimits) { |
| 16396 | var sin = Math.abs(Math.sin(angle)); |
| 16397 | var cos = Math.abs(Math.cos(angle)); |
| 16398 | var x = 0; |
| 16399 | var y = 0; |
| 16400 | if (hLimits.start < orig.l) { |
| 16401 | x = (orig.l - hLimits.start) / sin; |
| 16402 | limits.l = Math.min(limits.l, orig.l - x); |
| 16403 | } else if (hLimits.end > orig.r) { |
| 16404 | x = (hLimits.end - orig.r) / sin; |
| 16405 | limits.r = Math.max(limits.r, orig.r + x); |
| 16406 | } |
| 16407 | if (vLimits.start < orig.t) { |
| 16408 | y = (orig.t - vLimits.start) / cos; |
| 16409 | limits.t = Math.min(limits.t, orig.t - y); |
| 16410 | } else if (vLimits.end > orig.b) { |
| 16411 | y = (vLimits.end - orig.b) / cos; |
| 16412 | limits.b = Math.max(limits.b, orig.b + y); |
| 16413 | } |
| 16414 | } |
| 16415 | function buildPointLabelItems(scale, labelSizes, padding) { |
| 16416 | var items = []; |
| 16417 | var valueCount = scale._pointLabels.length; |
| 16418 | var opts = scale.options; |
| 16419 | var extra = getTickBackdropHeight(opts) / 2; |
| 16420 | var outerDistance = scale.drawingArea; |
| 16421 | var additionalAngle = opts.pointLabels.centerPointLabels ? (0, _helpersSegmentJs.P) / valueCount : 0; |
| 16422 | for(var i = 0; i < valueCount; i++){ |
| 16423 | var pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + padding[i], additionalAngle); |
| 16424 | var angle = Math.round((0, _helpersSegmentJs.S)((0, _helpersSegmentJs.ax)(pointLabelPosition.angle + (0, _helpersSegmentJs.H)))); |
| 16425 | var size = labelSizes[i]; |
| 16426 | var y = yForAngle(pointLabelPosition.y, size.h, angle); |
| 16427 | var textAlign = getTextAlignForAngle(angle); |
| 16428 | var left = leftForTextAlign(pointLabelPosition.x, size.w, textAlign); |
| 16429 | items.push({ |
| 16430 | x: pointLabelPosition.x, |
| 16431 | y: y, |
| 16432 | textAlign: textAlign, |
| 16433 | left: left, |
| 16434 | top: y, |
| 16435 | right: left + size.w, |
| 16436 | bottom: y + size.h |
| 16437 | }); |
| 16438 | } |
| 16439 | return items; |
| 16440 | } |
| 16441 | function getTextAlignForAngle(angle) { |
| 16442 | if (angle === 0 || angle === 180) return "center"; |
| 16443 | else if (angle < 180) return "left"; |
| 16444 | return "right"; |
| 16445 | } |
| 16446 | function leftForTextAlign(x, w, align) { |
| 16447 | if (align === "right") x -= w; |
| 16448 | else if (align === "center") x -= w / 2; |
| 16449 | return x; |
| 16450 | } |
| 16451 | function yForAngle(y, h, angle) { |
| 16452 | if (angle === 90 || angle === 270) y -= h / 2; |
| 16453 | else if (angle > 270 || angle < 90) y -= h; |
| 16454 | return y; |
| 16455 | } |
| 16456 | function drawPointLabels(scale, labelCount) { |
| 16457 | var ctx = scale.ctx, pointLabels = scale.options.pointLabels; |
| 16458 | for(var i = labelCount - 1; i >= 0; i--){ |
| 16459 | var optsAtIndex = pointLabels.setContext(scale.getPointLabelContext(i)); |
| 16460 | var plFont = (0, _helpersSegmentJs.$)(optsAtIndex.font); |
| 16461 | var _i = scale._pointLabelItems[i], x = _i.x, y = _i.y, textAlign = _i.textAlign, left = _i.left, top = _i.top, right = _i.right, bottom = _i.bottom; |
| 16462 | var backdropColor = optsAtIndex.backdropColor; |
| 16463 | if (!(0, _helpersSegmentJs.k)(backdropColor)) { |
| 16464 | var borderRadius = (0, _helpersSegmentJs.av)(optsAtIndex.borderRadius); |
| 16465 | var padding = (0, _helpersSegmentJs.D)(optsAtIndex.backdropPadding); |
| 16466 | ctx.fillStyle = backdropColor; |
| 16467 | var backdropLeft = left - padding.left; |
| 16468 | var backdropTop = top - padding.top; |
| 16469 | var backdropWidth = right - left + padding.width; |
| 16470 | var backdropHeight = bottom - top + padding.height; |
| 16471 | if (Object.values(borderRadius).some(function(v) { |
| 16472 | return v !== 0; |
| 16473 | })) { |
| 16474 | ctx.beginPath(); |
| 16475 | (0, _helpersSegmentJs.at)(ctx, { |
| 16476 | x: backdropLeft, |
| 16477 | y: backdropTop, |
| 16478 | w: backdropWidth, |
| 16479 | h: backdropHeight, |
| 16480 | radius: borderRadius |
| 16481 | }); |
| 16482 | ctx.fill(); |
| 16483 | } else ctx.fillRect(backdropLeft, backdropTop, backdropWidth, backdropHeight); |
| 16484 | } |
| 16485 | (0, _helpersSegmentJs.Y)(ctx, scale._pointLabels[i], x, y + plFont.lineHeight / 2, plFont, { |
| 16486 | color: optsAtIndex.color, |
| 16487 | textAlign: textAlign, |
| 16488 | textBaseline: "middle" |
| 16489 | }); |
| 16490 | } |
| 16491 | } |
| 16492 | function pathRadiusLine(scale, radius, circular, labelCount) { |
| 16493 | var ctx = scale.ctx; |
| 16494 | if (circular) ctx.arc(scale.xCenter, scale.yCenter, radius, 0, (0, _helpersSegmentJs.T)); |
| 16495 | else { |
| 16496 | var pointPosition = scale.getPointPosition(0, radius); |
| 16497 | ctx.moveTo(pointPosition.x, pointPosition.y); |
| 16498 | for(var i = 1; i < labelCount; i++){ |
| 16499 | pointPosition = scale.getPointPosition(i, radius); |
| 16500 | ctx.lineTo(pointPosition.x, pointPosition.y); |
| 16501 | } |
| 16502 | } |
| 16503 | } |
| 16504 | function drawRadiusLine(scale, gridLineOpts, radius, labelCount) { |
| 16505 | var ctx = scale.ctx; |
| 16506 | var circular = gridLineOpts.circular; |
| 16507 | var color = gridLineOpts.color, lineWidth = gridLineOpts.lineWidth; |
| 16508 | if (!circular && !labelCount || !color || !lineWidth || radius < 0) return; |
| 16509 | ctx.save(); |
| 16510 | ctx.strokeStyle = color; |
| 16511 | ctx.lineWidth = lineWidth; |
| 16512 | ctx.setLineDash(gridLineOpts.borderDash); |
| 16513 | ctx.lineDashOffset = gridLineOpts.borderDashOffset; |
| 16514 | ctx.beginPath(); |
| 16515 | pathRadiusLine(scale, radius, circular, labelCount); |
| 16516 | ctx.closePath(); |
| 16517 | ctx.stroke(); |
| 16518 | ctx.restore(); |
| 16519 | } |
| 16520 | function createPointLabelContext(parent, index74, label) { |
| 16521 | return (0, _helpersSegmentJs.h)(parent, { |
| 16522 | label: label, |
| 16523 | index: index74, |
| 16524 | type: "pointLabel" |
| 16525 | }); |
| 16526 | } |
| 16527 | var RadialLinearScale = /*#__PURE__*/ function(LinearScaleBase1) { |
| 16528 | "use strict"; |
| 16529 | (0, _inheritsJsDefault.default)(RadialLinearScale, LinearScaleBase1); |
| 16530 | var _super = (0, _createSuperJsDefault.default)(RadialLinearScale); |
| 16531 | function RadialLinearScale(cfg) { |
| 16532 | (0, _classCallCheckJsDefault.default)(this, RadialLinearScale); |
| 16533 | var _this; |
| 16534 | _this = _super.call(this, cfg); |
| 16535 | _this.xCenter = undefined; |
| 16536 | _this.yCenter = undefined; |
| 16537 | _this.drawingArea = undefined; |
| 16538 | _this._pointLabels = []; |
| 16539 | _this._pointLabelItems = []; |
| 16540 | return _this; |
| 16541 | } |
| 16542 | (0, _createClassJsDefault.default)(RadialLinearScale, [ |
| 16543 | { |
| 16544 | key: "setDimensions", |
| 16545 | value: function setDimensions() { |
| 16546 | var padding = this._padding = (0, _helpersSegmentJs.D)(getTickBackdropHeight(this.options) / 2); |
| 16547 | var w = this.width = this.maxWidth - padding.width; |
| 16548 | var h = this.height = this.maxHeight - padding.height; |
| 16549 | this.xCenter = Math.floor(this.left + w / 2 + padding.left); |
| 16550 | this.yCenter = Math.floor(this.top + h / 2 + padding.top); |
| 16551 | this.drawingArea = Math.floor(Math.min(w, h) / 2); |
| 16552 | } |
| 16553 | }, |
| 16554 | { |
| 16555 | key: "determineDataLimits", |
| 16556 | value: function determineDataLimits() { |
| 16557 | var ref = this.getMinMax(false), min = ref.min, max = ref.max; |
| 16558 | this.min = (0, _helpersSegmentJs.g)(min) && !isNaN(min) ? min : 0; |
| 16559 | this.max = (0, _helpersSegmentJs.g)(max) && !isNaN(max) ? max : 0; |
| 16560 | this.handleTickRangeOptions(); |
| 16561 | } |
| 16562 | }, |
| 16563 | { |
| 16564 | key: "computeTickLimit", |
| 16565 | value: function computeTickLimit() { |
| 16566 | return Math.ceil(this.drawingArea / getTickBackdropHeight(this.options)); |
| 16567 | } |
| 16568 | }, |
| 16569 | { |
| 16570 | key: "generateTickLabels", |
| 16571 | value: function generateTickLabels(ticks) { |
| 16572 | var _this = this; |
| 16573 | LinearScaleBase.prototype.generateTickLabels.call(this, ticks); |
| 16574 | this._pointLabels = this.getLabels().map(function(value, index75) { |
| 16575 | var label = (0, _helpersSegmentJs.Q)(_this.options.pointLabels.callback, [ |
| 16576 | value, |
| 16577 | index75 |
| 16578 | ], _this); |
| 16579 | return label || label === 0 ? label : ""; |
| 16580 | }).filter(function(v, i) { |
| 16581 | return _this.chart.getDataVisibility(i); |
| 16582 | }); |
| 16583 | } |
| 16584 | }, |
| 16585 | { |
| 16586 | key: "fit", |
| 16587 | value: function fit() { |
| 16588 | var opts = this.options; |
| 16589 | if (opts.display && opts.pointLabels.display) fitWithPointLabels(this); |
| 16590 | else this.setCenterPoint(0, 0, 0, 0); |
| 16591 | } |
| 16592 | }, |
| 16593 | { |
| 16594 | key: "setCenterPoint", |
| 16595 | value: function setCenterPoint(leftMovement, rightMovement, topMovement, bottomMovement) { |
| 16596 | this.xCenter += Math.floor((leftMovement - rightMovement) / 2); |
| 16597 | this.yCenter += Math.floor((topMovement - bottomMovement) / 2); |
| 16598 | this.drawingArea -= Math.min(this.drawingArea / 2, Math.max(leftMovement, rightMovement, topMovement, bottomMovement)); |
| 16599 | } |
| 16600 | }, |
| 16601 | { |
| 16602 | key: "getIndexAngle", |
| 16603 | value: function getIndexAngle(index76) { |
| 16604 | var angleMultiplier = (0, _helpersSegmentJs.T) / (this._pointLabels.length || 1); |
| 16605 | var startAngle = this.options.startAngle || 0; |
| 16606 | return (0, _helpersSegmentJs.ax)(index76 * angleMultiplier + (0, _helpersSegmentJs.t)(startAngle)); |
| 16607 | } |
| 16608 | }, |
| 16609 | { |
| 16610 | key: "getDistanceFromCenterForValue", |
| 16611 | value: function getDistanceFromCenterForValue(value) { |
| 16612 | if ((0, _helpersSegmentJs.k)(value)) return NaN; |
| 16613 | var scalingFactor = this.drawingArea / (this.max - this.min); |
| 16614 | if (this.options.reverse) return (this.max - value) * scalingFactor; |
| 16615 | return (value - this.min) * scalingFactor; |
| 16616 | } |
| 16617 | }, |
| 16618 | { |
| 16619 | key: "getValueForDistanceFromCenter", |
| 16620 | value: function getValueForDistanceFromCenter(distance) { |
| 16621 | if ((0, _helpersSegmentJs.k)(distance)) return NaN; |
| 16622 | var scaledDistance = distance / (this.drawingArea / (this.max - this.min)); |
| 16623 | return this.options.reverse ? this.max - scaledDistance : this.min + scaledDistance; |
| 16624 | } |
| 16625 | }, |
| 16626 | { |
| 16627 | key: "getPointLabelContext", |
| 16628 | value: function getPointLabelContext(index77) { |
| 16629 | var pointLabels = this._pointLabels || []; |
| 16630 | if (index77 >= 0 && index77 < pointLabels.length) { |
| 16631 | var pointLabel = pointLabels[index77]; |
| 16632 | return createPointLabelContext(this.getContext(), index77, pointLabel); |
| 16633 | } |
| 16634 | } |
| 16635 | }, |
| 16636 | { |
| 16637 | key: "getPointPosition", |
| 16638 | value: function getPointPosition(index78, distanceFromCenter) { |
| 16639 | var additionalAngle = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0; |
| 16640 | var angle = this.getIndexAngle(index78) - (0, _helpersSegmentJs.H) + additionalAngle; |
| 16641 | return { |
| 16642 | x: Math.cos(angle) * distanceFromCenter + this.xCenter, |
| 16643 | y: Math.sin(angle) * distanceFromCenter + this.yCenter, |
| 16644 | angle: angle |
| 16645 | }; |
| 16646 | } |
| 16647 | }, |
| 16648 | { |
| 16649 | key: "getPointPositionForValue", |
| 16650 | value: function getPointPositionForValue(index79, value) { |
| 16651 | return this.getPointPosition(index79, this.getDistanceFromCenterForValue(value)); |
| 16652 | } |
| 16653 | }, |
| 16654 | { |
| 16655 | key: "getBasePosition", |
| 16656 | value: function getBasePosition(index80) { |
| 16657 | return this.getPointPositionForValue(index80 || 0, this.getBaseValue()); |
| 16658 | } |
| 16659 | }, |
| 16660 | { |
| 16661 | key: "getPointLabelPosition", |
| 16662 | value: function getPointLabelPosition(index81) { |
| 16663 | var _index = this._pointLabelItems[index81], left = _index.left, top = _index.top, right = _index.right, bottom = _index.bottom; |
| 16664 | return { |
| 16665 | left: left, |
| 16666 | top: top, |
| 16667 | right: right, |
| 16668 | bottom: bottom |
| 16669 | }; |
| 16670 | } |
| 16671 | }, |
| 16672 | { |
| 16673 | key: "drawBackground", |
| 16674 | value: function drawBackground() { |
| 16675 | var _options = this.options, backgroundColor = _options.backgroundColor, circular = _options.grid.circular; |
| 16676 | if (backgroundColor) { |
| 16677 | var ctx = this.ctx; |
| 16678 | ctx.save(); |
| 16679 | ctx.beginPath(); |
| 16680 | pathRadiusLine(this, this.getDistanceFromCenterForValue(this._endValue), circular, this._pointLabels.length); |
| 16681 | ctx.closePath(); |
| 16682 | ctx.fillStyle = backgroundColor; |
| 16683 | ctx.fill(); |
| 16684 | ctx.restore(); |
| 16685 | } |
| 16686 | } |
| 16687 | }, |
| 16688 | { |
| 16689 | key: "drawGrid", |
| 16690 | value: function drawGrid() { |
| 16691 | var _this = this; |
| 16692 | var ctx = this.ctx; |
| 16693 | var opts = this.options; |
| 16694 | var angleLines = opts.angleLines, grid = opts.grid; |
| 16695 | var labelCount = this._pointLabels.length; |
| 16696 | var i, offset, position; |
| 16697 | if (opts.pointLabels.display) drawPointLabels(this, labelCount); |
| 16698 | if (grid.display) this.ticks.forEach(function(tick, index82) { |
| 16699 | if (index82 !== 0) { |
| 16700 | offset = _this.getDistanceFromCenterForValue(tick.value); |
| 16701 | var optsAtIndex = grid.setContext(_this.getContext(index82 - 1)); |
| 16702 | drawRadiusLine(_this, optsAtIndex, offset, labelCount); |
| 16703 | } |
| 16704 | }); |
| 16705 | if (angleLines.display) { |
| 16706 | ctx.save(); |
| 16707 | for(i = labelCount - 1; i >= 0; i--){ |
| 16708 | var optsAtIndex1 = angleLines.setContext(this.getPointLabelContext(i)); |
| 16709 | var color = optsAtIndex1.color, lineWidth = optsAtIndex1.lineWidth; |
| 16710 | if (!lineWidth || !color) continue; |
| 16711 | ctx.lineWidth = lineWidth; |
| 16712 | ctx.strokeStyle = color; |
| 16713 | ctx.setLineDash(optsAtIndex1.borderDash); |
| 16714 | ctx.lineDashOffset = optsAtIndex1.borderDashOffset; |
| 16715 | offset = this.getDistanceFromCenterForValue(opts.ticks.reverse ? this.min : this.max); |
| 16716 | position = this.getPointPosition(i, offset); |
| 16717 | ctx.beginPath(); |
| 16718 | ctx.moveTo(this.xCenter, this.yCenter); |
| 16719 | ctx.lineTo(position.x, position.y); |
| 16720 | ctx.stroke(); |
| 16721 | } |
| 16722 | ctx.restore(); |
| 16723 | } |
| 16724 | } |
| 16725 | }, |
| 16726 | { |
| 16727 | key: "drawBorder", |
| 16728 | value: function drawBorder() {} |
| 16729 | }, |
| 16730 | { |
| 16731 | key: "drawLabels", |
| 16732 | value: function drawLabels() { |
| 16733 | var _this = this; |
| 16734 | var ctx = this.ctx; |
| 16735 | var opts = this.options; |
| 16736 | var tickOpts = opts.ticks; |
| 16737 | if (!tickOpts.display) return; |
| 16738 | var startAngle = this.getIndexAngle(0); |
| 16739 | var offset, width; |
| 16740 | ctx.save(); |
| 16741 | ctx.translate(this.xCenter, this.yCenter); |
| 16742 | ctx.rotate(startAngle); |
| 16743 | ctx.textAlign = "center"; |
| 16744 | ctx.textBaseline = "middle"; |
| 16745 | this.ticks.forEach(function(tick, index83) { |
| 16746 | if (index83 === 0 && !opts.reverse) return; |
| 16747 | var optsAtIndex = tickOpts.setContext(_this.getContext(index83)); |
| 16748 | var tickFont = (0, _helpersSegmentJs.$)(optsAtIndex.font); |
| 16749 | offset = _this.getDistanceFromCenterForValue(_this.ticks[index83].value); |
| 16750 | if (optsAtIndex.showLabelBackdrop) { |
| 16751 | ctx.font = tickFont.string; |
| 16752 | width = ctx.measureText(tick.label).width; |
| 16753 | ctx.fillStyle = optsAtIndex.backdropColor; |
| 16754 | var padding = (0, _helpersSegmentJs.D)(optsAtIndex.backdropPadding); |
| 16755 | ctx.fillRect(-width / 2 - padding.left, -offset - tickFont.size / 2 - padding.top, width + padding.width, tickFont.size + padding.height); |
| 16756 | } |
| 16757 | (0, _helpersSegmentJs.Y)(ctx, tick.label, 0, -offset, tickFont, { |
| 16758 | color: optsAtIndex.color |
| 16759 | }); |
| 16760 | }); |
| 16761 | ctx.restore(); |
| 16762 | } |
| 16763 | }, |
| 16764 | { |
| 16765 | key: "drawTitle", |
| 16766 | value: function drawTitle() {} |
| 16767 | } |
| 16768 | ]); |
| 16769 | return RadialLinearScale; |
| 16770 | }(LinearScaleBase); |
| 16771 | RadialLinearScale.id = "radialLinear"; |
| 16772 | RadialLinearScale.defaults = { |
| 16773 | display: true, |
| 16774 | animate: true, |
| 16775 | position: "chartArea", |
| 16776 | angleLines: { |
| 16777 | display: true, |
| 16778 | lineWidth: 1, |
| 16779 | borderDash: [], |
| 16780 | borderDashOffset: 0.0 |
| 16781 | }, |
| 16782 | grid: { |
| 16783 | circular: false |
| 16784 | }, |
| 16785 | startAngle: 0, |
| 16786 | ticks: { |
| 16787 | showLabelBackdrop: true, |
| 16788 | callback: Ticks.formatters.numeric |
| 16789 | }, |
| 16790 | pointLabels: { |
| 16791 | backdropColor: undefined, |
| 16792 | backdropPadding: 2, |
| 16793 | display: true, |
| 16794 | font: { |
| 16795 | size: 10 |
| 16796 | }, |
| 16797 | callback: function(label) { |
| 16798 | return label; |
| 16799 | }, |
| 16800 | padding: 5, |
| 16801 | centerPointLabels: false |
| 16802 | } |
| 16803 | }; |
| 16804 | RadialLinearScale.defaultRoutes = { |
| 16805 | "angleLines.color": "borderColor", |
| 16806 | "pointLabels.color": "color", |
| 16807 | "ticks.color": "color" |
| 16808 | }; |
| 16809 | RadialLinearScale.descriptors = { |
| 16810 | angleLines: { |
| 16811 | _fallback: "grid" |
| 16812 | } |
| 16813 | }; |
| 16814 | var INTERVALS = { |
| 16815 | millisecond: { |
| 16816 | common: true, |
| 16817 | size: 1, |
| 16818 | steps: 1000 |
| 16819 | }, |
| 16820 | second: { |
| 16821 | common: true, |
| 16822 | size: 1000, |
| 16823 | steps: 60 |
| 16824 | }, |
| 16825 | minute: { |
| 16826 | common: true, |
| 16827 | size: 60000, |
| 16828 | steps: 60 |
| 16829 | }, |
| 16830 | hour: { |
| 16831 | common: true, |
| 16832 | size: 3600000, |
| 16833 | steps: 24 |
| 16834 | }, |
| 16835 | day: { |
| 16836 | common: true, |
| 16837 | size: 86400000, |
| 16838 | steps: 30 |
| 16839 | }, |
| 16840 | week: { |
| 16841 | common: false, |
| 16842 | size: 604800000, |
| 16843 | steps: 4 |
| 16844 | }, |
| 16845 | month: { |
| 16846 | common: true, |
| 16847 | size: 2.628e9, |
| 16848 | steps: 12 |
| 16849 | }, |
| 16850 | quarter: { |
| 16851 | common: false, |
| 16852 | size: 7.884e9, |
| 16853 | steps: 4 |
| 16854 | }, |
| 16855 | year: { |
| 16856 | common: true, |
| 16857 | size: 3.154e10 |
| 16858 | } |
| 16859 | }; |
| 16860 | var UNITS = Object.keys(INTERVALS); |
| 16861 | function sorter(a, b) { |
| 16862 | return a - b; |
| 16863 | } |
| 16864 | function parse(scale, input) { |
| 16865 | if ((0, _helpersSegmentJs.k)(input)) return null; |
| 16866 | var adapter = scale._adapter; |
| 16867 | var __parseOpts = scale._parseOpts, parser = __parseOpts.parser, round = __parseOpts.round, isoWeekday = __parseOpts.isoWeekday; |
| 16868 | var value = input; |
| 16869 | if (typeof parser === "function") value = parser(value); |
| 16870 | if (!(0, _helpersSegmentJs.g)(value)) value = typeof parser === "string" ? adapter.parse(value, parser) : adapter.parse(value); |
| 16871 | if (value === null) return null; |
| 16872 | if (round) value = round === "week" && ((0, _helpersSegmentJs.q)(isoWeekday) || isoWeekday === true) ? adapter.startOf(value, "isoWeek", isoWeekday) : adapter.startOf(value, round); |
| 16873 | return +value; |
| 16874 | } |
| 16875 | function determineUnitForAutoTicks(minUnit, min, max, capacity) { |
| 16876 | var ilen = UNITS.length; |
| 16877 | for(var i = UNITS.indexOf(minUnit); i < ilen - 1; ++i){ |
| 16878 | var interval = INTERVALS[UNITS[i]]; |
| 16879 | var factor = interval.steps ? interval.steps : Number.MAX_SAFE_INTEGER; |
| 16880 | if (interval.common && Math.ceil((max - min) / (factor * interval.size)) <= capacity) return UNITS[i]; |
| 16881 | } |
| 16882 | return UNITS[ilen - 1]; |
| 16883 | } |
| 16884 | function determineUnitForFormatting(scale, numTicks, minUnit, min, max) { |
| 16885 | for(var i = UNITS.length - 1; i >= UNITS.indexOf(minUnit); i--){ |
| 16886 | var unit = UNITS[i]; |
| 16887 | if (INTERVALS[unit].common && scale._adapter.diff(max, min, unit) >= numTicks - 1) return unit; |
| 16888 | } |
| 16889 | return UNITS[minUnit ? UNITS.indexOf(minUnit) : 0]; |
| 16890 | } |
| 16891 | function determineMajorUnit(unit) { |
| 16892 | for(var i = UNITS.indexOf(unit) + 1, ilen = UNITS.length; i < ilen; ++i){ |
| 16893 | if (INTERVALS[UNITS[i]].common) return UNITS[i]; |
| 16894 | } |
| 16895 | } |
| 16896 | function addTick(ticks, time, timestamps) { |
| 16897 | if (!timestamps) ticks[time] = true; |
| 16898 | else if (timestamps.length) { |
| 16899 | var ref = (0, _helpersSegmentJs.aL)(timestamps, time), lo = ref.lo, hi = ref.hi; |
| 16900 | var timestamp = timestamps[lo] >= time ? timestamps[lo] : timestamps[hi]; |
| 16901 | ticks[timestamp] = true; |
| 16902 | } |
| 16903 | } |
| 16904 | function setMajorTicks(scale, ticks, map1, majorUnit) { |
| 16905 | var adapter = scale._adapter; |
| 16906 | var first = +adapter.startOf(ticks[0].value, majorUnit); |
| 16907 | var last = ticks[ticks.length - 1].value; |
| 16908 | var major, index84; |
| 16909 | for(major = first; major <= last; major = +adapter.add(major, 1, majorUnit)){ |
| 16910 | index84 = map1[major]; |
| 16911 | if (index84 >= 0) ticks[index84].major = true; |
| 16912 | } |
| 16913 | return ticks; |
| 16914 | } |
| 16915 | function ticksFromTimestamps(scale, values, majorUnit) { |
| 16916 | var ticks = []; |
| 16917 | var map2 = {}; |
| 16918 | var ilen = values.length; |
| 16919 | var i, value; |
| 16920 | for(i = 0; i < ilen; ++i){ |
| 16921 | value = values[i]; |
| 16922 | map2[value] = i; |
| 16923 | ticks.push({ |
| 16924 | value: value, |
| 16925 | major: false |
| 16926 | }); |
| 16927 | } |
| 16928 | return ilen === 0 || !majorUnit ? ticks : setMajorTicks(scale, ticks, map2, majorUnit); |
| 16929 | } |
| 16930 | var TimeScale = /*#__PURE__*/ function(Scale) { |
| 16931 | "use strict"; |
| 16932 | (0, _inheritsJsDefault.default)(TimeScale, Scale); |
| 16933 | var _super = (0, _createSuperJsDefault.default)(TimeScale); |
| 16934 | function TimeScale(props) { |
| 16935 | (0, _classCallCheckJsDefault.default)(this, TimeScale); |
| 16936 | var _this; |
| 16937 | _this = _super.call(this, props); |
| 16938 | _this._cache = { |
| 16939 | data: [], |
| 16940 | labels: [], |
| 16941 | all: [] |
| 16942 | }; |
| 16943 | _this._unit = "day"; |
| 16944 | _this._majorUnit = undefined; |
| 16945 | _this._offsets = {}; |
| 16946 | _this._normalized = false; |
| 16947 | _this._parseOpts = undefined; |
| 16948 | return _this; |
| 16949 | } |
| 16950 | (0, _createClassJsDefault.default)(TimeScale, [ |
| 16951 | { |
| 16952 | key: "init", |
| 16953 | value: function init(scaleOpts, opts) { |
| 16954 | var time = scaleOpts.time || (scaleOpts.time = {}); |
| 16955 | var adapter = this._adapter = new adapters._date(scaleOpts.adapters.date); |
| 16956 | (0, _helpersSegmentJs.aa)(time.displayFormats, adapter.formats()); |
| 16957 | this._parseOpts = { |
| 16958 | parser: time.parser, |
| 16959 | round: time.round, |
| 16960 | isoWeekday: time.isoWeekday |
| 16961 | }; |
| 16962 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(TimeScale.prototype), "init", this).call(this, scaleOpts); |
| 16963 | this._normalized = opts.normalized; |
| 16964 | } |
| 16965 | }, |
| 16966 | { |
| 16967 | key: "parse", |
| 16968 | value: function parse1(raw, index) { |
| 16969 | if (raw === undefined) return null; |
| 16970 | return parse(this, raw); |
| 16971 | } |
| 16972 | }, |
| 16973 | { |
| 16974 | key: "beforeLayout", |
| 16975 | value: function beforeLayout() { |
| 16976 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(TimeScale.prototype), "beforeLayout", this).call(this); |
| 16977 | this._cache = { |
| 16978 | data: [], |
| 16979 | labels: [], |
| 16980 | all: [] |
| 16981 | }; |
| 16982 | } |
| 16983 | }, |
| 16984 | { |
| 16985 | key: "determineDataLimits", |
| 16986 | value: function determineDataLimits() { |
| 16987 | var options = this.options; |
| 16988 | var adapter = this._adapter; |
| 16989 | var unit = options.time.unit || "day"; |
| 16990 | var ref = this.getUserBounds(), min = ref.min, max = ref.max, minDefined = ref.minDefined, maxDefined = ref.maxDefined; |
| 16991 | function _applyBounds(bounds) { |
| 16992 | if (!minDefined && !isNaN(bounds.min)) min = Math.min(min, bounds.min); |
| 16993 | if (!maxDefined && !isNaN(bounds.max)) max = Math.max(max, bounds.max); |
| 16994 | } |
| 16995 | if (!minDefined || !maxDefined) { |
| 16996 | _applyBounds(this._getLabelBounds()); |
| 16997 | if (options.bounds !== "ticks" || options.ticks.source !== "labels") _applyBounds(this.getMinMax(false)); |
| 16998 | } |
| 16999 | min = (0, _helpersSegmentJs.g)(min) && !isNaN(min) ? min : +adapter.startOf(Date.now(), unit); |
| 17000 | max = (0, _helpersSegmentJs.g)(max) && !isNaN(max) ? max : +adapter.endOf(Date.now(), unit) + 1; |
| 17001 | this.min = Math.min(min, max - 1); |
| 17002 | this.max = Math.max(min + 1, max); |
| 17003 | } |
| 17004 | }, |
| 17005 | { |
| 17006 | key: "_getLabelBounds", |
| 17007 | value: function _getLabelBounds() { |
| 17008 | var arr = this.getLabelTimestamps(); |
| 17009 | var min = Number.POSITIVE_INFINITY; |
| 17010 | var max = Number.NEGATIVE_INFINITY; |
| 17011 | if (arr.length) { |
| 17012 | min = arr[0]; |
| 17013 | max = arr[arr.length - 1]; |
| 17014 | } |
| 17015 | return { |
| 17016 | min: min, |
| 17017 | max: max |
| 17018 | }; |
| 17019 | } |
| 17020 | }, |
| 17021 | { |
| 17022 | key: "buildTicks", |
| 17023 | value: function buildTicks() { |
| 17024 | var options = this.options; |
| 17025 | var timeOpts = options.time; |
| 17026 | var tickOpts = options.ticks; |
| 17027 | var timestamps = tickOpts.source === "labels" ? this.getLabelTimestamps() : this._generate(); |
| 17028 | if (options.bounds === "ticks" && timestamps.length) { |
| 17029 | this.min = this._userMin || timestamps[0]; |
| 17030 | this.max = this._userMax || timestamps[timestamps.length - 1]; |
| 17031 | } |
| 17032 | var min = this.min; |
| 17033 | var max = this.max; |
| 17034 | var ticks = (0, _helpersSegmentJs.aK)(timestamps, min, max); |
| 17035 | this._unit = timeOpts.unit || (tickOpts.autoSkip ? determineUnitForAutoTicks(timeOpts.minUnit, this.min, this.max, this._getLabelCapacity(min)) : determineUnitForFormatting(this, ticks.length, timeOpts.minUnit, this.min, this.max)); |
| 17036 | this._majorUnit = !tickOpts.major.enabled || this._unit === "year" ? undefined : determineMajorUnit(this._unit); |
| 17037 | this.initOffsets(timestamps); |
| 17038 | if (options.reverse) ticks.reverse(); |
| 17039 | return ticksFromTimestamps(this, ticks, this._majorUnit); |
| 17040 | } |
| 17041 | }, |
| 17042 | { |
| 17043 | key: "afterAutoSkip", |
| 17044 | value: function afterAutoSkip() { |
| 17045 | if (this.options.offsetAfterAutoskip) this.initOffsets(this.ticks.map(function(tick) { |
| 17046 | return +tick.value; |
| 17047 | })); |
| 17048 | } |
| 17049 | }, |
| 17050 | { |
| 17051 | key: "initOffsets", |
| 17052 | value: function initOffsets(timestamps) { |
| 17053 | var start = 0; |
| 17054 | var end = 0; |
| 17055 | var first, last; |
| 17056 | if (this.options.offset && timestamps.length) { |
| 17057 | first = this.getDecimalForValue(timestamps[0]); |
| 17058 | if (timestamps.length === 1) start = 1 - first; |
| 17059 | else start = (this.getDecimalForValue(timestamps[1]) - first) / 2; |
| 17060 | last = this.getDecimalForValue(timestamps[timestamps.length - 1]); |
| 17061 | if (timestamps.length === 1) end = last; |
| 17062 | else end = (last - this.getDecimalForValue(timestamps[timestamps.length - 2])) / 2; |
| 17063 | } |
| 17064 | var limit = timestamps.length < 3 ? 0.5 : 0.25; |
| 17065 | start = (0, _helpersSegmentJs.w)(start, 0, limit); |
| 17066 | end = (0, _helpersSegmentJs.w)(end, 0, limit); |
| 17067 | this._offsets = { |
| 17068 | start: start, |
| 17069 | end: end, |
| 17070 | factor: 1 / (start + 1 + end) |
| 17071 | }; |
| 17072 | } |
| 17073 | }, |
| 17074 | { |
| 17075 | key: "_generate", |
| 17076 | value: function _generate() { |
| 17077 | var adapter = this._adapter; |
| 17078 | var min = this.min; |
| 17079 | var max = this.max; |
| 17080 | var options = this.options; |
| 17081 | var timeOpts = options.time; |
| 17082 | var minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, this._getLabelCapacity(min)); |
| 17083 | var stepSize = (0, _helpersSegmentJs.v)(timeOpts.stepSize, 1); |
| 17084 | var weekday = minor === "week" ? timeOpts.isoWeekday : false; |
| 17085 | var hasWeekday = (0, _helpersSegmentJs.q)(weekday) || weekday === true; |
| 17086 | var ticks = {}; |
| 17087 | var first = min; |
| 17088 | var time, count; |
| 17089 | if (hasWeekday) first = +adapter.startOf(first, "isoWeek", weekday); |
| 17090 | first = +adapter.startOf(first, hasWeekday ? "day" : minor); |
| 17091 | if (adapter.diff(max, min, minor) > 100000 * stepSize) throw new Error(min + " and " + max + " are too far apart with stepSize of " + stepSize + " " + minor); |
| 17092 | var timestamps = options.ticks.source === "data" && this.getDataTimestamps(); |
| 17093 | for(time = first, count = 0; time < max; time = +adapter.add(time, stepSize, minor), count++)addTick(ticks, time, timestamps); |
| 17094 | if (time === max || options.bounds === "ticks" || count === 1) addTick(ticks, time, timestamps); |
| 17095 | return Object.keys(ticks).sort(function(a, b) { |
| 17096 | return a - b; |
| 17097 | }).map(function(x) { |
| 17098 | return +x; |
| 17099 | }); |
| 17100 | } |
| 17101 | }, |
| 17102 | { |
| 17103 | key: "getLabelForValue", |
| 17104 | value: function getLabelForValue(value) { |
| 17105 | var adapter = this._adapter; |
| 17106 | var timeOpts = this.options.time; |
| 17107 | if (timeOpts.tooltipFormat) return adapter.format(value, timeOpts.tooltipFormat); |
| 17108 | return adapter.format(value, timeOpts.displayFormats.datetime); |
| 17109 | } |
| 17110 | }, |
| 17111 | { |
| 17112 | key: "_tickFormatFunction", |
| 17113 | value: function _tickFormatFunction(time, index85, ticks, format) { |
| 17114 | var options = this.options; |
| 17115 | var formats = options.time.displayFormats; |
| 17116 | var unit = this._unit; |
| 17117 | var majorUnit = this._majorUnit; |
| 17118 | var minorFormat = unit && formats[unit]; |
| 17119 | var majorFormat = majorUnit && formats[majorUnit]; |
| 17120 | var tick = ticks[index85]; |
| 17121 | var major = majorUnit && majorFormat && tick && tick.major; |
| 17122 | var label = this._adapter.format(time, format || (major ? majorFormat : minorFormat)); |
| 17123 | var formatter = options.ticks.callback; |
| 17124 | return formatter ? (0, _helpersSegmentJs.Q)(formatter, [ |
| 17125 | label, |
| 17126 | index85, |
| 17127 | ticks |
| 17128 | ], this) : label; |
| 17129 | } |
| 17130 | }, |
| 17131 | { |
| 17132 | key: "generateTickLabels", |
| 17133 | value: function generateTickLabels(ticks) { |
| 17134 | var i, ilen, tick; |
| 17135 | for(i = 0, ilen = ticks.length; i < ilen; ++i){ |
| 17136 | tick = ticks[i]; |
| 17137 | tick.label = this._tickFormatFunction(tick.value, i, ticks); |
| 17138 | } |
| 17139 | } |
| 17140 | }, |
| 17141 | { |
| 17142 | key: "getDecimalForValue", |
| 17143 | value: function getDecimalForValue(value) { |
| 17144 | return value === null ? NaN : (value - this.min) / (this.max - this.min); |
| 17145 | } |
| 17146 | }, |
| 17147 | { |
| 17148 | key: "getPixelForValue", |
| 17149 | value: function getPixelForValue(value) { |
| 17150 | var offsets = this._offsets; |
| 17151 | var pos = this.getDecimalForValue(value); |
| 17152 | return this.getPixelForDecimal((offsets.start + pos) * offsets.factor); |
| 17153 | } |
| 17154 | }, |
| 17155 | { |
| 17156 | key: "getValueForPixel", |
| 17157 | value: function getValueForPixel(pixel) { |
| 17158 | var offsets = this._offsets; |
| 17159 | var pos = this.getDecimalForPixel(pixel) / offsets.factor - offsets.end; |
| 17160 | return this.min + pos * (this.max - this.min); |
| 17161 | } |
| 17162 | }, |
| 17163 | { |
| 17164 | key: "_getLabelSize", |
| 17165 | value: function _getLabelSize(label) { |
| 17166 | var ticksOpts = this.options.ticks; |
| 17167 | var tickLabelWidth = this.ctx.measureText(label).width; |
| 17168 | var angle = (0, _helpersSegmentJs.t)(this.isHorizontal() ? ticksOpts.maxRotation : ticksOpts.minRotation); |
| 17169 | var cosRotation = Math.cos(angle); |
| 17170 | var sinRotation = Math.sin(angle); |
| 17171 | var tickFontSize = this._resolveTickFontOptions(0).size; |
| 17172 | return { |
| 17173 | w: tickLabelWidth * cosRotation + tickFontSize * sinRotation, |
| 17174 | h: tickLabelWidth * sinRotation + tickFontSize * cosRotation |
| 17175 | }; |
| 17176 | } |
| 17177 | }, |
| 17178 | { |
| 17179 | key: "_getLabelCapacity", |
| 17180 | value: function _getLabelCapacity(exampleTime) { |
| 17181 | var timeOpts = this.options.time; |
| 17182 | var displayFormats = timeOpts.displayFormats; |
| 17183 | var format = displayFormats[timeOpts.unit] || displayFormats.millisecond; |
| 17184 | var exampleLabel = this._tickFormatFunction(exampleTime, 0, ticksFromTimestamps(this, [ |
| 17185 | exampleTime |
| 17186 | ], this._majorUnit), format); |
| 17187 | var size = this._getLabelSize(exampleLabel); |
| 17188 | var capacity = Math.floor(this.isHorizontal() ? this.width / size.w : this.height / size.h) - 1; |
| 17189 | return capacity > 0 ? capacity : 1; |
| 17190 | } |
| 17191 | }, |
| 17192 | { |
| 17193 | key: "getDataTimestamps", |
| 17194 | value: function getDataTimestamps() { |
| 17195 | var timestamps = this._cache.data || []; |
| 17196 | var i, ilen; |
| 17197 | if (timestamps.length) return timestamps; |
| 17198 | var metas = this.getMatchingVisibleMetas(); |
| 17199 | if (this._normalized && metas.length) return this._cache.data = metas[0].controller.getAllParsedValues(this); |
| 17200 | for(i = 0, ilen = metas.length; i < ilen; ++i)timestamps = timestamps.concat(metas[i].controller.getAllParsedValues(this)); |
| 17201 | return this._cache.data = this.normalize(timestamps); |
| 17202 | } |
| 17203 | }, |
| 17204 | { |
| 17205 | key: "getLabelTimestamps", |
| 17206 | value: function getLabelTimestamps() { |
| 17207 | var timestamps = this._cache.labels || []; |
| 17208 | var i, ilen; |
| 17209 | if (timestamps.length) return timestamps; |
| 17210 | var labels = this.getLabels(); |
| 17211 | for(i = 0, ilen = labels.length; i < ilen; ++i)timestamps.push(parse(this, labels[i])); |
| 17212 | return this._cache.labels = this._normalized ? timestamps : this.normalize(timestamps); |
| 17213 | } |
| 17214 | }, |
| 17215 | { |
| 17216 | key: "normalize", |
| 17217 | value: function normalize(values) { |
| 17218 | return (0, _helpersSegmentJs._)(values.sort(sorter)); |
| 17219 | } |
| 17220 | } |
| 17221 | ]); |
| 17222 | return TimeScale; |
| 17223 | }(Scale); |
| 17224 | TimeScale.id = "time"; |
| 17225 | TimeScale.defaults = { |
| 17226 | bounds: "data", |
| 17227 | adapters: {}, |
| 17228 | time: { |
| 17229 | parser: false, |
| 17230 | unit: false, |
| 17231 | round: false, |
| 17232 | isoWeekday: false, |
| 17233 | minUnit: "millisecond", |
| 17234 | displayFormats: {} |
| 17235 | }, |
| 17236 | ticks: { |
| 17237 | source: "auto", |
| 17238 | major: { |
| 17239 | enabled: false |
| 17240 | } |
| 17241 | } |
| 17242 | }; |
| 17243 | function interpolate(table, val, reverse) { |
| 17244 | var lo = 0; |
| 17245 | var hi = table.length - 1; |
| 17246 | var prevSource, nextSource, prevTarget, nextTarget; |
| 17247 | if (reverse) { |
| 17248 | var ref; |
| 17249 | if (val >= table[lo].pos && val <= table[hi].pos) ref = (0, _helpersSegmentJs.x)(table, "pos", val), lo = ref.lo, hi = ref.hi, ref; |
| 17250 | var ref16; |
| 17251 | ref16 = table[lo], prevSource = ref16.pos, prevTarget = ref16.time, ref16; |
| 17252 | var ref17; |
| 17253 | ref17 = table[hi], nextSource = ref17.pos, nextTarget = ref17.time, ref17; |
| 17254 | } else { |
| 17255 | var ref18; |
| 17256 | if (val >= table[lo].time && val <= table[hi].time) ref18 = (0, _helpersSegmentJs.x)(table, "time", val), lo = ref18.lo, hi = ref18.hi, ref18; |
| 17257 | var ref19; |
| 17258 | ref19 = table[lo], prevSource = ref19.time, prevTarget = ref19.pos, ref19; |
| 17259 | var ref20; |
| 17260 | ref20 = table[hi], nextSource = ref20.time, nextTarget = ref20.pos, ref20; |
| 17261 | } |
| 17262 | var span = nextSource - prevSource; |
| 17263 | return span ? prevTarget + (nextTarget - prevTarget) * (val - prevSource) / span : prevTarget; |
| 17264 | } |
| 17265 | var TimeSeriesScale = /*#__PURE__*/ function(TimeScale) { |
| 17266 | "use strict"; |
| 17267 | (0, _inheritsJsDefault.default)(TimeSeriesScale, TimeScale); |
| 17268 | var _super = (0, _createSuperJsDefault.default)(TimeSeriesScale); |
| 17269 | function TimeSeriesScale(props) { |
| 17270 | (0, _classCallCheckJsDefault.default)(this, TimeSeriesScale); |
| 17271 | var _this; |
| 17272 | _this = _super.call(this, props); |
| 17273 | _this._table = []; |
| 17274 | _this._minPos = undefined; |
| 17275 | _this._tableRange = undefined; |
| 17276 | return _this; |
| 17277 | } |
| 17278 | (0, _createClassJsDefault.default)(TimeSeriesScale, [ |
| 17279 | { |
| 17280 | key: "initOffsets", |
| 17281 | value: function initOffsets() { |
| 17282 | var timestamps = this._getTimestampsForTable(); |
| 17283 | var table = this._table = this.buildLookupTable(timestamps); |
| 17284 | this._minPos = interpolate(table, this.min); |
| 17285 | this._tableRange = interpolate(table, this.max) - this._minPos; |
| 17286 | (0, _getJsDefault.default)((0, _getPrototypeOfJsDefault.default)(TimeSeriesScale.prototype), "initOffsets", this).call(this, timestamps); |
| 17287 | } |
| 17288 | }, |
| 17289 | { |
| 17290 | key: "buildLookupTable", |
| 17291 | value: function buildLookupTable(timestamps) { |
| 17292 | var ref = this, min = ref.min, max = ref.max; |
| 17293 | var items = []; |
| 17294 | var table = []; |
| 17295 | var i, ilen, prev, curr, next; |
| 17296 | for(i = 0, ilen = timestamps.length; i < ilen; ++i){ |
| 17297 | curr = timestamps[i]; |
| 17298 | if (curr >= min && curr <= max) items.push(curr); |
| 17299 | } |
| 17300 | if (items.length < 2) return [ |
| 17301 | { |
| 17302 | time: min, |
| 17303 | pos: 0 |
| 17304 | }, |
| 17305 | { |
| 17306 | time: max, |
| 17307 | pos: 1 |
| 17308 | } |
| 17309 | ]; |
| 17310 | for(i = 0, ilen = items.length; i < ilen; ++i){ |
| 17311 | next = items[i + 1]; |
| 17312 | prev = items[i - 1]; |
| 17313 | curr = items[i]; |
| 17314 | if (Math.round((next + prev) / 2) !== curr) table.push({ |
| 17315 | time: curr, |
| 17316 | pos: i / (ilen - 1) |
| 17317 | }); |
| 17318 | } |
| 17319 | return table; |
| 17320 | } |
| 17321 | }, |
| 17322 | { |
| 17323 | key: "_getTimestampsForTable", |
| 17324 | value: function _getTimestampsForTable() { |
| 17325 | var timestamps = this._cache.all || []; |
| 17326 | if (timestamps.length) return timestamps; |
| 17327 | var data = this.getDataTimestamps(); |
| 17328 | var label = this.getLabelTimestamps(); |
| 17329 | if (data.length && label.length) timestamps = this.normalize(data.concat(label)); |
| 17330 | else timestamps = data.length ? data : label; |
| 17331 | timestamps = this._cache.all = timestamps; |
| 17332 | return timestamps; |
| 17333 | } |
| 17334 | }, |
| 17335 | { |
| 17336 | key: "getDecimalForValue", |
| 17337 | value: function getDecimalForValue(value) { |
| 17338 | return (interpolate(this._table, value) - this._minPos) / this._tableRange; |
| 17339 | } |
| 17340 | }, |
| 17341 | { |
| 17342 | key: "getValueForPixel", |
| 17343 | value: function getValueForPixel(pixel) { |
| 17344 | var offsets = this._offsets; |
| 17345 | var decimal = this.getDecimalForPixel(pixel) / offsets.factor - offsets.end; |
| 17346 | return interpolate(this._table, decimal * this._tableRange + this._minPos, true); |
| 17347 | } |
| 17348 | } |
| 17349 | ]); |
| 17350 | return TimeSeriesScale; |
| 17351 | }(TimeScale); |
| 17352 | TimeSeriesScale.id = "timeseries"; |
| 17353 | TimeSeriesScale.defaults = TimeScale.defaults; |
| 17354 | var scales = /*#__PURE__*/ Object.freeze({ |
| 17355 | __proto__: null, |
| 17356 | CategoryScale: CategoryScale, |
| 17357 | LinearScale: LinearScale, |
| 17358 | LogarithmicScale: LogarithmicScale, |
| 17359 | RadialLinearScale: RadialLinearScale, |
| 17360 | TimeScale: TimeScale, |
| 17361 | TimeSeriesScale: TimeSeriesScale |
| 17362 | }); |
| 17363 | var registerables = [ |
| 17364 | controllers, |
| 17365 | elements, |
| 17366 | plugins, |
| 17367 | scales, |
| 17368 | ]; |
| 17369 | |
| 17370 | },{"@swc/helpers/lib/_assert_this_initialized.js":"l7nF8","@swc/helpers/lib/_class_call_check.js":"gNxF8","@swc/helpers/lib/_create_class.js":"iyoaN","@swc/helpers/lib/_define_property.js":"6IXzf","@swc/helpers/lib/_get.js":"5g4pb","@swc/helpers/lib/_get_prototype_of.js":"7Gb6H","@swc/helpers/lib/_inherits.js":"atvDk","@swc/helpers/lib/_object_spread.js":"d5EJT","@swc/helpers/lib/_sliced_to_array.js":"4IWLM","@swc/helpers/lib/_to_consumable_array.js":"cccKv","@swc/helpers/lib/_type_of.js":"9FF45","@swc/helpers/lib/_wrap_native_super.js":"4U7ja","@swc/helpers/lib/_create_super.js":"5rW3S","./chunks/helpers.segment.js":"eXwLh","@parcel/transformer-js/src/esmodule-helpers.js":"jIm8e"}],"d5EJT":[function(require,module,exports) { |
| 17371 | "use strict"; |
| 17372 | Object.defineProperty(exports, "__esModule", { |
| 17373 | value: true |
| 17374 | }); |
| 17375 | exports.default = _objectSpread; |
| 17376 | var _defineProperty = _interopRequireDefault(require("./_define_property")); |
| 17377 | function _objectSpread(target) { |
| 17378 | for(var i = 1; i < arguments.length; i++){ |
| 17379 | var source = arguments[i] != null ? arguments[i] : {}; |
| 17380 | var ownKeys = Object.keys(source); |
| 17381 | if (typeof Object.getOwnPropertySymbols === "function") ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { |
| 17382 | return Object.getOwnPropertyDescriptor(source, sym).enumerable; |
| 17383 | })); |
| 17384 | ownKeys.forEach(function(key) { |
| 17385 | _defineProperty.default(target, key, source[key]); |
| 17386 | }); |
| 17387 | } |
| 17388 | return target; |
| 17389 | } |
| 17390 | function _interopRequireDefault(obj) { |
| 17391 | return obj && obj.__esModule ? obj : { |
| 17392 | default: obj |
| 17393 | }; |
| 17394 | } |
| 17395 | |
| 17396 | },{"./_define_property":"6IXzf"}],"4U7ja":[function(require,module,exports) { |
| 17397 | "use strict"; |
| 17398 | Object.defineProperty(exports, "__esModule", { |
| 17399 | value: true |
| 17400 | }); |
| 17401 | exports.default = _wrapNativeSuper; |
| 17402 | var _construct = _interopRequireDefault(require("./_construct")); |
| 17403 | var _isNativeFunction = _interopRequireDefault(require("./_is_native_function")); |
| 17404 | var _getPrototypeOf = _interopRequireDefault(require("./_get_prototype_of")); |
| 17405 | var _setPrototypeOf = _interopRequireDefault(require("./_set_prototype_of")); |
| 17406 | function _wrapNativeSuper(Class) { |
| 17407 | return wrapNativeSuper(Class); |
| 17408 | } |
| 17409 | function _interopRequireDefault(obj) { |
| 17410 | return obj && obj.__esModule ? obj : { |
| 17411 | default: obj |
| 17412 | }; |
| 17413 | } |
| 17414 | function wrapNativeSuper(Class1) { |
| 17415 | var _cache = typeof Map === "function" ? new Map() : undefined; |
| 17416 | wrapNativeSuper = function wrapNativeSuper(Class) { |
| 17417 | if (Class === null || !_isNativeFunction.default(Class)) return Class; |
| 17418 | if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function"); |
| 17419 | if (typeof _cache !== "undefined") { |
| 17420 | if (_cache.has(Class)) return _cache.get(Class); |
| 17421 | _cache.set(Class, Wrapper); |
| 17422 | } |
| 17423 | function Wrapper() { |
| 17424 | return _construct.default(Class, arguments, _getPrototypeOf.default(this).constructor); |
| 17425 | } |
| 17426 | Wrapper.prototype = Object.create(Class.prototype, { |
| 17427 | constructor: { |
| 17428 | value: Wrapper, |
| 17429 | enumerable: false, |
| 17430 | writable: true, |
| 17431 | configurable: true |
| 17432 | } |
| 17433 | }); |
| 17434 | return _setPrototypeOf.default(Wrapper, Class); |
| 17435 | }; |
| 17436 | return wrapNativeSuper(Class1); |
| 17437 | } |
| 17438 | |
| 17439 | },{"./_construct":"597Bk","./_is_native_function":"9evrd","./_get_prototype_of":"7Gb6H","./_set_prototype_of":"1rATD"}],"597Bk":[function(require,module,exports) { |
| 17440 | "use strict"; |
| 17441 | Object.defineProperty(exports, "__esModule", { |
| 17442 | value: true |
| 17443 | }); |
| 17444 | exports.default = _construct; |
| 17445 | var _setPrototypeOf = _interopRequireDefault(require("./_set_prototype_of")); |
| 17446 | function _construct(Parent, args, Class) { |
| 17447 | return construct.apply(null, arguments); |
| 17448 | } |
| 17449 | function _interopRequireDefault(obj) { |
| 17450 | return obj && obj.__esModule ? obj : { |
| 17451 | default: obj |
| 17452 | }; |
| 17453 | } |
| 17454 | function isNativeReflectConstruct() { |
| 17455 | if (typeof Reflect === "undefined" || !Reflect.construct) return false; |
| 17456 | if (Reflect.construct.sham) return false; |
| 17457 | if (typeof Proxy === "function") return true; |
| 17458 | try { |
| 17459 | Date.prototype.toString.call(Reflect.construct(Date, [], function() {})); |
| 17460 | return true; |
| 17461 | } catch (e) { |
| 17462 | return false; |
| 17463 | } |
| 17464 | } |
| 17465 | function construct(Parent1, args1, Class1) { |
| 17466 | if (isNativeReflectConstruct()) construct = Reflect.construct; |
| 17467 | else construct = function construct(Parent, args, Class) { |
| 17468 | var a = [ |
| 17469 | null |
| 17470 | ]; |
| 17471 | a.push.apply(a, args); |
| 17472 | var Constructor = Function.bind.apply(Parent, a); |
| 17473 | var instance = new Constructor(); |
| 17474 | if (Class) _setPrototypeOf.default(instance, Class.prototype); |
| 17475 | return instance; |
| 17476 | }; |
| 17477 | return construct.apply(null, arguments); |
| 17478 | } |
| 17479 | |
| 17480 | },{"./_set_prototype_of":"1rATD"}],"9evrd":[function(require,module,exports) { |
| 17481 | "use strict"; |
| 17482 | Object.defineProperty(exports, "__esModule", { |
| 17483 | value: true |
| 17484 | }); |
| 17485 | exports.default = _isNativeFunction; |
| 17486 | function _isNativeFunction(fn) { |
| 17487 | return Function.toString.call(fn).indexOf("[native code]") !== -1; |
| 17488 | } |
| 17489 | |
| 17490 | },{}],"eXwLh":[function(require,module,exports) { |
| 17491 | var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); |
| 17492 | parcelHelpers.defineInteropFlag(exports); |
| 17493 | parcelHelpers.export(exports, "$", function() { |
| 17494 | return toFont; |
| 17495 | }); |
| 17496 | parcelHelpers.export(exports, "A", function() { |
| 17497 | return _rlookupByKey; |
| 17498 | }); |
| 17499 | parcelHelpers.export(exports, "B", function() { |
| 17500 | return _isPointInArea; |
| 17501 | }); |
| 17502 | parcelHelpers.export(exports, "C", function() { |
| 17503 | return getAngleFromPoint; |
| 17504 | }); |
| 17505 | parcelHelpers.export(exports, "D", function() { |
| 17506 | return toPadding; |
| 17507 | }); |
| 17508 | parcelHelpers.export(exports, "E", function() { |
| 17509 | return each; |
| 17510 | }); |
| 17511 | parcelHelpers.export(exports, "F", function() { |
| 17512 | return getMaximumSize; |
| 17513 | }); |
| 17514 | parcelHelpers.export(exports, "G", function() { |
| 17515 | return _getParentNode; |
| 17516 | }); |
| 17517 | parcelHelpers.export(exports, "H", function() { |
| 17518 | return HALF_PI; |
| 17519 | }); |
| 17520 | parcelHelpers.export(exports, "I", function() { |
| 17521 | return readUsedSize; |
| 17522 | }); |
| 17523 | parcelHelpers.export(exports, "J", function() { |
| 17524 | return throttled; |
| 17525 | }); |
| 17526 | parcelHelpers.export(exports, "K", function() { |
| 17527 | return supportsEventListenerOptions; |
| 17528 | }); |
| 17529 | parcelHelpers.export(exports, "L", function() { |
| 17530 | return _isDomSupported; |
| 17531 | }); |
| 17532 | parcelHelpers.export(exports, "M", function() { |
| 17533 | return log10; |
| 17534 | }); |
| 17535 | parcelHelpers.export(exports, "N", function() { |
| 17536 | return _factorize; |
| 17537 | }); |
| 17538 | parcelHelpers.export(exports, "O", function() { |
| 17539 | return finiteOrDefault; |
| 17540 | }); |
| 17541 | parcelHelpers.export(exports, "P", function() { |
| 17542 | return PI; |
| 17543 | }); |
| 17544 | parcelHelpers.export(exports, "Q", function() { |
| 17545 | return callback; |
| 17546 | }); |
| 17547 | parcelHelpers.export(exports, "R", function() { |
| 17548 | return _addGrace; |
| 17549 | }); |
| 17550 | parcelHelpers.export(exports, "S", function() { |
| 17551 | return toDegrees; |
| 17552 | }); |
| 17553 | parcelHelpers.export(exports, "T", function() { |
| 17554 | return TAU; |
| 17555 | }); |
| 17556 | parcelHelpers.export(exports, "U", function() { |
| 17557 | return _measureText; |
| 17558 | }); |
| 17559 | parcelHelpers.export(exports, "V", function() { |
| 17560 | return _int16Range; |
| 17561 | }); |
| 17562 | parcelHelpers.export(exports, "W", function() { |
| 17563 | return _alignPixel; |
| 17564 | }); |
| 17565 | parcelHelpers.export(exports, "X", function() { |
| 17566 | return clipArea; |
| 17567 | }); |
| 17568 | parcelHelpers.export(exports, "Y", function() { |
| 17569 | return renderText; |
| 17570 | }); |
| 17571 | parcelHelpers.export(exports, "Z", function() { |
| 17572 | return unclipArea; |
| 17573 | }); |
| 17574 | parcelHelpers.export(exports, "_", function() { |
| 17575 | return _arrayUnique; |
| 17576 | }); |
| 17577 | parcelHelpers.export(exports, "a", function() { |
| 17578 | return resolve; |
| 17579 | }); |
| 17580 | parcelHelpers.export(exports, "a$", function() { |
| 17581 | return QUARTER_PI; |
| 17582 | }); |
| 17583 | parcelHelpers.export(exports, "a0", function() { |
| 17584 | return _toLeftRightCenter; |
| 17585 | }); |
| 17586 | parcelHelpers.export(exports, "a1", function() { |
| 17587 | return _alignStartEnd; |
| 17588 | }); |
| 17589 | parcelHelpers.export(exports, "a2", function() { |
| 17590 | return overrides; |
| 17591 | }); |
| 17592 | parcelHelpers.export(exports, "a3", function() { |
| 17593 | return merge; |
| 17594 | }); |
| 17595 | parcelHelpers.export(exports, "a4", function() { |
| 17596 | return _capitalize; |
| 17597 | }); |
| 17598 | parcelHelpers.export(exports, "a5", function() { |
| 17599 | return descriptors; |
| 17600 | }); |
| 17601 | parcelHelpers.export(exports, "a6", function() { |
| 17602 | return isFunction; |
| 17603 | }); |
| 17604 | parcelHelpers.export(exports, "a7", function() { |
| 17605 | return _attachContext; |
| 17606 | }); |
| 17607 | parcelHelpers.export(exports, "a8", function() { |
| 17608 | return _createResolver; |
| 17609 | }); |
| 17610 | parcelHelpers.export(exports, "a9", function() { |
| 17611 | return _descriptors; |
| 17612 | }); |
| 17613 | parcelHelpers.export(exports, "aA", function() { |
| 17614 | return _textX; |
| 17615 | }); |
| 17616 | parcelHelpers.export(exports, "aB", function() { |
| 17617 | return restoreTextDirection; |
| 17618 | }); |
| 17619 | parcelHelpers.export(exports, "aC", function() { |
| 17620 | return noop; |
| 17621 | }); |
| 17622 | parcelHelpers.export(exports, "aD", function() { |
| 17623 | return distanceBetweenPoints; |
| 17624 | }); |
| 17625 | parcelHelpers.export(exports, "aE", function() { |
| 17626 | return _setMinAndMaxByKey; |
| 17627 | }); |
| 17628 | parcelHelpers.export(exports, "aF", function() { |
| 17629 | return niceNum; |
| 17630 | }); |
| 17631 | parcelHelpers.export(exports, "aG", function() { |
| 17632 | return almostWhole; |
| 17633 | }); |
| 17634 | parcelHelpers.export(exports, "aH", function() { |
| 17635 | return almostEquals; |
| 17636 | }); |
| 17637 | parcelHelpers.export(exports, "aI", function() { |
| 17638 | return _decimalPlaces; |
| 17639 | }); |
| 17640 | parcelHelpers.export(exports, "aJ", function() { |
| 17641 | return _longestText; |
| 17642 | }); |
| 17643 | parcelHelpers.export(exports, "aK", function() { |
| 17644 | return _filterBetween; |
| 17645 | }); |
| 17646 | parcelHelpers.export(exports, "aL", function() { |
| 17647 | return _lookup; |
| 17648 | }); |
| 17649 | parcelHelpers.export(exports, "aM", function() { |
| 17650 | return isPatternOrGradient; |
| 17651 | }); |
| 17652 | parcelHelpers.export(exports, "aN", function() { |
| 17653 | return getHoverColor; |
| 17654 | }); |
| 17655 | parcelHelpers.export(exports, "aO", function() { |
| 17656 | return clone$1; |
| 17657 | }); |
| 17658 | parcelHelpers.export(exports, "aP", function() { |
| 17659 | return _merger; |
| 17660 | }); |
| 17661 | parcelHelpers.export(exports, "aQ", function() { |
| 17662 | return _mergerIf; |
| 17663 | }); |
| 17664 | parcelHelpers.export(exports, "aR", function() { |
| 17665 | return _deprecated; |
| 17666 | }); |
| 17667 | parcelHelpers.export(exports, "aS", function() { |
| 17668 | return toFontString; |
| 17669 | }); |
| 17670 | parcelHelpers.export(exports, "aT", function() { |
| 17671 | return splineCurve; |
| 17672 | }); |
| 17673 | parcelHelpers.export(exports, "aU", function() { |
| 17674 | return splineCurveMonotone; |
| 17675 | }); |
| 17676 | parcelHelpers.export(exports, "aV", function() { |
| 17677 | return getStyle; |
| 17678 | }); |
| 17679 | parcelHelpers.export(exports, "aW", function() { |
| 17680 | return fontString; |
| 17681 | }); |
| 17682 | parcelHelpers.export(exports, "aX", function() { |
| 17683 | return toLineHeight; |
| 17684 | }); |
| 17685 | parcelHelpers.export(exports, "aY", function() { |
| 17686 | return PITAU; |
| 17687 | }); |
| 17688 | parcelHelpers.export(exports, "aZ", function() { |
| 17689 | return INFINITY; |
| 17690 | }); |
| 17691 | parcelHelpers.export(exports, "a_", function() { |
| 17692 | return RAD_PER_DEG; |
| 17693 | }); |
| 17694 | parcelHelpers.export(exports, "aa", function() { |
| 17695 | return mergeIf; |
| 17696 | }); |
| 17697 | parcelHelpers.export(exports, "ab", function() { |
| 17698 | return uid; |
| 17699 | }); |
| 17700 | parcelHelpers.export(exports, "ac", function() { |
| 17701 | return debounce; |
| 17702 | }); |
| 17703 | parcelHelpers.export(exports, "ad", function() { |
| 17704 | return retinaScale; |
| 17705 | }); |
| 17706 | parcelHelpers.export(exports, "ae", function() { |
| 17707 | return clearCanvas; |
| 17708 | }); |
| 17709 | parcelHelpers.export(exports, "af", function() { |
| 17710 | return setsEqual; |
| 17711 | }); |
| 17712 | parcelHelpers.export(exports, "ag", function() { |
| 17713 | return _elementsEqual; |
| 17714 | }); |
| 17715 | parcelHelpers.export(exports, "ah", function() { |
| 17716 | return _isClickEvent; |
| 17717 | }); |
| 17718 | parcelHelpers.export(exports, "ai", function() { |
| 17719 | return _isBetween; |
| 17720 | }); |
| 17721 | parcelHelpers.export(exports, "aj", function() { |
| 17722 | return _readValueToProps; |
| 17723 | }); |
| 17724 | parcelHelpers.export(exports, "ak", function() { |
| 17725 | return _updateBezierControlPoints; |
| 17726 | }); |
| 17727 | parcelHelpers.export(exports, "al", function() { |
| 17728 | return _computeSegments; |
| 17729 | }); |
| 17730 | parcelHelpers.export(exports, "am", function() { |
| 17731 | return _boundSegments; |
| 17732 | }); |
| 17733 | parcelHelpers.export(exports, "an", function() { |
| 17734 | return _steppedInterpolation; |
| 17735 | }); |
| 17736 | parcelHelpers.export(exports, "ao", function() { |
| 17737 | return _bezierInterpolation; |
| 17738 | }); |
| 17739 | parcelHelpers.export(exports, "ap", function() { |
| 17740 | return _pointInLine; |
| 17741 | }); |
| 17742 | parcelHelpers.export(exports, "aq", function() { |
| 17743 | return _steppedLineTo; |
| 17744 | }); |
| 17745 | parcelHelpers.export(exports, "ar", function() { |
| 17746 | return _bezierCurveTo; |
| 17747 | }); |
| 17748 | parcelHelpers.export(exports, "as", function() { |
| 17749 | return drawPoint; |
| 17750 | }); |
| 17751 | parcelHelpers.export(exports, "at", function() { |
| 17752 | return addRoundedRectPath; |
| 17753 | }); |
| 17754 | parcelHelpers.export(exports, "au", function() { |
| 17755 | return toTRBL; |
| 17756 | }); |
| 17757 | parcelHelpers.export(exports, "av", function() { |
| 17758 | return toTRBLCorners; |
| 17759 | }); |
| 17760 | parcelHelpers.export(exports, "aw", function() { |
| 17761 | return _boundSegment; |
| 17762 | }); |
| 17763 | parcelHelpers.export(exports, "ax", function() { |
| 17764 | return _normalizeAngle; |
| 17765 | }); |
| 17766 | parcelHelpers.export(exports, "ay", function() { |
| 17767 | return getRtlAdapter; |
| 17768 | }); |
| 17769 | parcelHelpers.export(exports, "az", function() { |
| 17770 | return overrideTextDirection; |
| 17771 | }); |
| 17772 | parcelHelpers.export(exports, "b", function() { |
| 17773 | return isArray; |
| 17774 | }); |
| 17775 | parcelHelpers.export(exports, "b0", function() { |
| 17776 | return TWO_THIRDS_PI; |
| 17777 | }); |
| 17778 | parcelHelpers.export(exports, "b1", function() { |
| 17779 | return _angleDiff; |
| 17780 | }); |
| 17781 | parcelHelpers.export(exports, "c", function() { |
| 17782 | return color; |
| 17783 | }); |
| 17784 | parcelHelpers.export(exports, "d", function() { |
| 17785 | return defaults; |
| 17786 | }); |
| 17787 | parcelHelpers.export(exports, "e", function() { |
| 17788 | return effects; |
| 17789 | }); |
| 17790 | parcelHelpers.export(exports, "f", function() { |
| 17791 | return resolveObjectKey; |
| 17792 | }); |
| 17793 | parcelHelpers.export(exports, "g", function() { |
| 17794 | return isNumberFinite; |
| 17795 | }); |
| 17796 | parcelHelpers.export(exports, "h", function() { |
| 17797 | return createContext; |
| 17798 | }); |
| 17799 | parcelHelpers.export(exports, "i", function() { |
| 17800 | return isObject; |
| 17801 | }); |
| 17802 | parcelHelpers.export(exports, "j", function() { |
| 17803 | return defined; |
| 17804 | }); |
| 17805 | parcelHelpers.export(exports, "k", function() { |
| 17806 | return isNullOrUndef; |
| 17807 | }); |
| 17808 | parcelHelpers.export(exports, "l", function() { |
| 17809 | return listenArrayEvents; |
| 17810 | }); |
| 17811 | parcelHelpers.export(exports, "m", function() { |
| 17812 | return toPercentage; |
| 17813 | }); |
| 17814 | parcelHelpers.export(exports, "n", function() { |
| 17815 | return toDimension; |
| 17816 | }); |
| 17817 | parcelHelpers.export(exports, "o", function() { |
| 17818 | return formatNumber; |
| 17819 | }); |
| 17820 | parcelHelpers.export(exports, "p", function() { |
| 17821 | return _angleBetween; |
| 17822 | }); |
| 17823 | parcelHelpers.export(exports, "q", function() { |
| 17824 | return isNumber; |
| 17825 | }); |
| 17826 | parcelHelpers.export(exports, "r", function() { |
| 17827 | return requestAnimFrame; |
| 17828 | }); |
| 17829 | parcelHelpers.export(exports, "s", function() { |
| 17830 | return sign; |
| 17831 | }); |
| 17832 | parcelHelpers.export(exports, "t", function() { |
| 17833 | return toRadians; |
| 17834 | }); |
| 17835 | parcelHelpers.export(exports, "u", function() { |
| 17836 | return unlistenArrayEvents; |
| 17837 | }); |
| 17838 | parcelHelpers.export(exports, "v", function() { |
| 17839 | return valueOrDefault; |
| 17840 | }); |
| 17841 | parcelHelpers.export(exports, "w", function() { |
| 17842 | return _limitValue; |
| 17843 | }); |
| 17844 | parcelHelpers.export(exports, "x", function() { |
| 17845 | return _lookupByKey; |
| 17846 | }); |
| 17847 | parcelHelpers.export(exports, "y", function() { |
| 17848 | return _parseObjectDataRadialScale; |
| 17849 | }); |
| 17850 | parcelHelpers.export(exports, "z", function() { |
| 17851 | return getRelativePosition; |
| 17852 | }); |
| 17853 | var _classCallCheckJs = require("@swc/helpers/lib/_class_call_check.js"); |
| 17854 | var _classCallCheckJsDefault = parcelHelpers.interopDefault(_classCallCheckJs); |
| 17855 | var _createClassJs = require("@swc/helpers/lib/_create_class.js"); |
| 17856 | var _createClassJsDefault = parcelHelpers.interopDefault(_createClassJs); |
| 17857 | var _definePropertyJs = require("@swc/helpers/lib/_define_property.js"); |
| 17858 | var _definePropertyJsDefault = parcelHelpers.interopDefault(_definePropertyJs); |
| 17859 | var _toConsumableArrayJs = require("@swc/helpers/lib/_to_consumable_array.js"); |
| 17860 | var _toConsumableArrayJsDefault = parcelHelpers.interopDefault(_toConsumableArrayJs); |
| 17861 | var _typeOfJs = require("@swc/helpers/lib/_type_of.js"); |
| 17862 | var _typeOfJsDefault = parcelHelpers.interopDefault(_typeOfJs); |
| 17863 | /*! |
| 17864 | * Chart.js v3.8.0 |
| 17865 | * https://www.chartjs.org |
| 17866 | * (c) 2022 Chart.js Contributors |
| 17867 | * Released under the MIT License |
| 17868 | */ function fontString(pixelSize, fontStyle, fontFamily) { |
| 17869 | return fontStyle + " " + pixelSize + "px " + fontFamily; |
| 17870 | } |
| 17871 | var requestAnimFrame = function() { |
| 17872 | if (typeof window === "undefined") return function(callback1) { |
| 17873 | return callback1(); |
| 17874 | }; |
| 17875 | return window.requestAnimationFrame; |
| 17876 | }(); |
| 17877 | function throttled(fn, thisArg, updateFn) { |
| 17878 | var updateArgs = updateFn || function(args) { |
| 17879 | return Array.prototype.slice.call(args); |
| 17880 | }; |
| 17881 | var ticking = false; |
| 17882 | var args1 = []; |
| 17883 | return function() { |
| 17884 | for(var _len = arguments.length, rest = new Array(_len), _key = 0; _key < _len; _key++){ |
| 17885 | rest[_key] = arguments[_key]; |
| 17886 | } |
| 17887 | args1 = updateArgs(rest); |
| 17888 | if (!ticking) { |
| 17889 | ticking = true; |
| 17890 | requestAnimFrame.call(window, function() { |
| 17891 | ticking = false; |
| 17892 | fn.apply(thisArg, args1); |
| 17893 | }); |
| 17894 | } |
| 17895 | }; |
| 17896 | } |
| 17897 | function debounce(fn, delay) { |
| 17898 | var timeout; |
| 17899 | return function() { |
| 17900 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 17901 | args[_key] = arguments[_key]; |
| 17902 | } |
| 17903 | if (delay) { |
| 17904 | clearTimeout(timeout); |
| 17905 | timeout = setTimeout(fn, delay, args); |
| 17906 | } else fn.apply(this, args); |
| 17907 | return delay; |
| 17908 | }; |
| 17909 | } |
| 17910 | var _toLeftRightCenter = function(align) { |
| 17911 | return align === "start" ? "left" : align === "end" ? "right" : "center"; |
| 17912 | }; |
| 17913 | var _alignStartEnd = function(align, start, end) { |
| 17914 | return align === "start" ? start : align === "end" ? end : (start + end) / 2; |
| 17915 | }; |
| 17916 | var _textX = function(align, left, right, rtl) { |
| 17917 | var check = rtl ? "left" : "right"; |
| 17918 | return align === check ? right : align === "center" ? (left + right) / 2 : left; |
| 17919 | }; |
| 17920 | function noop() {} |
| 17921 | var uid = function() { |
| 17922 | var id = 0; |
| 17923 | return function() { |
| 17924 | return id++; |
| 17925 | }; |
| 17926 | }(); |
| 17927 | function isNullOrUndef(value) { |
| 17928 | return value === null || typeof value === "undefined"; |
| 17929 | } |
| 17930 | function isArray(value) { |
| 17931 | if (Array.isArray && Array.isArray(value)) return true; |
| 17932 | var type = Object.prototype.toString.call(value); |
| 17933 | if (type.slice(0, 7) === "[object" && type.slice(-6) === "Array]") return true; |
| 17934 | return false; |
| 17935 | } |
| 17936 | function isObject(value) { |
| 17937 | return value !== null && Object.prototype.toString.call(value) === "[object Object]"; |
| 17938 | } |
| 17939 | var isNumberFinite = function(value) { |
| 17940 | return (typeof value === "number" || value instanceof Number) && isFinite(+value); |
| 17941 | }; |
| 17942 | function finiteOrDefault(value, defaultValue) { |
| 17943 | return isNumberFinite(value) ? value : defaultValue; |
| 17944 | } |
| 17945 | function valueOrDefault(value, defaultValue) { |
| 17946 | return typeof value === "undefined" ? defaultValue : value; |
| 17947 | } |
| 17948 | var toPercentage = function(value, dimension) { |
| 17949 | return typeof value === "string" && value.endsWith("%") ? parseFloat(value) / 100 : value / dimension; |
| 17950 | }; |
| 17951 | var toDimension = function(value, dimension) { |
| 17952 | return typeof value === "string" && value.endsWith("%") ? parseFloat(value) / 100 * dimension : +value; |
| 17953 | }; |
| 17954 | function callback(fn, args, thisArg) { |
| 17955 | if (fn && typeof fn.call === "function") return fn.apply(thisArg, args); |
| 17956 | } |
| 17957 | function each(loopable, fn, thisArg, reverse) { |
| 17958 | var i, len, keys; |
| 17959 | if (isArray(loopable)) { |
| 17960 | len = loopable.length; |
| 17961 | if (reverse) for(i = len - 1; i >= 0; i--)fn.call(thisArg, loopable[i], i); |
| 17962 | else for(i = 0; i < len; i++)fn.call(thisArg, loopable[i], i); |
| 17963 | } else if (isObject(loopable)) { |
| 17964 | keys = Object.keys(loopable); |
| 17965 | len = keys.length; |
| 17966 | for(i = 0; i < len; i++)fn.call(thisArg, loopable[keys[i]], keys[i]); |
| 17967 | } |
| 17968 | } |
| 17969 | function _elementsEqual(a0, a1) { |
| 17970 | var i, ilen, v0, v1; |
| 17971 | if (!a0 || !a1 || a0.length !== a1.length) return false; |
| 17972 | for(i = 0, ilen = a0.length; i < ilen; ++i){ |
| 17973 | v0 = a0[i]; |
| 17974 | v1 = a1[i]; |
| 17975 | if (v0.datasetIndex !== v1.datasetIndex || v0.index !== v1.index) return false; |
| 17976 | } |
| 17977 | return true; |
| 17978 | } |
| 17979 | function clone$1(source) { |
| 17980 | if (isArray(source)) return source.map(clone$1); |
| 17981 | if (isObject(source)) { |
| 17982 | var target = Object.create(null); |
| 17983 | var keys = Object.keys(source); |
| 17984 | var klen = keys.length; |
| 17985 | var k = 0; |
| 17986 | for(; k < klen; ++k)target[keys[k]] = clone$1(source[keys[k]]); |
| 17987 | return target; |
| 17988 | } |
| 17989 | return source; |
| 17990 | } |
| 17991 | function isValidKey(key) { |
| 17992 | return [ |
| 17993 | "__proto__", |
| 17994 | "prototype", |
| 17995 | "constructor" |
| 17996 | ].indexOf(key) === -1; |
| 17997 | } |
| 17998 | function _merger(key, target, source, options) { |
| 17999 | if (!isValidKey(key)) return; |
| 18000 | var tval = target[key]; |
| 18001 | var sval = source[key]; |
| 18002 | if (isObject(tval) && isObject(sval)) merge(tval, sval, options); |
| 18003 | else target[key] = clone$1(sval); |
| 18004 | } |
| 18005 | function merge(target, source, options) { |
| 18006 | var sources = isArray(source) ? source : [ |
| 18007 | source |
| 18008 | ]; |
| 18009 | var ilen = sources.length; |
| 18010 | if (!isObject(target)) return target; |
| 18011 | options = options || {}; |
| 18012 | var merger = options.merger || _merger; |
| 18013 | for(var i = 0; i < ilen; ++i){ |
| 18014 | source = sources[i]; |
| 18015 | if (!isObject(source)) continue; |
| 18016 | var keys = Object.keys(source); |
| 18017 | for(var k = 0, klen = keys.length; k < klen; ++k)merger(keys[k], target, source, options); |
| 18018 | } |
| 18019 | return target; |
| 18020 | } |
| 18021 | function mergeIf(target, source) { |
| 18022 | return merge(target, source, { |
| 18023 | merger: _mergerIf |
| 18024 | }); |
| 18025 | } |
| 18026 | function _mergerIf(key, target, source) { |
| 18027 | if (!isValidKey(key)) return; |
| 18028 | var tval = target[key]; |
| 18029 | var sval = source[key]; |
| 18030 | if (isObject(tval) && isObject(sval)) mergeIf(tval, sval); |
| 18031 | else if (!Object.prototype.hasOwnProperty.call(target, key)) target[key] = clone$1(sval); |
| 18032 | } |
| 18033 | function _deprecated(scope, value, previous, current) { |
| 18034 | if (value !== undefined) console.warn(scope + ': "' + previous + '" is deprecated. Please use "' + current + '" instead'); |
| 18035 | } |
| 18036 | var emptyString = ""; |
| 18037 | var dot = "."; |
| 18038 | function indexOfDotOrLength(key, start) { |
| 18039 | var idx = key.indexOf(dot, start); |
| 18040 | return idx === -1 ? key.length : idx; |
| 18041 | } |
| 18042 | function resolveObjectKey(obj, key) { |
| 18043 | if (key === emptyString) return obj; |
| 18044 | var pos = 0; |
| 18045 | var idx = indexOfDotOrLength(key, pos); |
| 18046 | while(obj && idx > pos){ |
| 18047 | obj = obj[key.slice(pos, idx)]; |
| 18048 | pos = idx + 1; |
| 18049 | idx = indexOfDotOrLength(key, pos); |
| 18050 | } |
| 18051 | return obj; |
| 18052 | } |
| 18053 | function _capitalize(str) { |
| 18054 | return str.charAt(0).toUpperCase() + str.slice(1); |
| 18055 | } |
| 18056 | var defined = function(value) { |
| 18057 | return typeof value !== "undefined"; |
| 18058 | }; |
| 18059 | var isFunction = function(value) { |
| 18060 | return typeof value === "function"; |
| 18061 | }; |
| 18062 | var setsEqual = function(a, b) { |
| 18063 | if (a.size !== b.size) return false; |
| 18064 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 18065 | try { |
| 18066 | for(var _iterator = a[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 18067 | var item = _step.value; |
| 18068 | if (!b.has(item)) return false; |
| 18069 | } |
| 18070 | } catch (err) { |
| 18071 | _didIteratorError = true; |
| 18072 | _iteratorError = err; |
| 18073 | } finally{ |
| 18074 | try { |
| 18075 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 18076 | _iterator.return(); |
| 18077 | } |
| 18078 | } finally{ |
| 18079 | if (_didIteratorError) { |
| 18080 | throw _iteratorError; |
| 18081 | } |
| 18082 | } |
| 18083 | } |
| 18084 | return true; |
| 18085 | }; |
| 18086 | function _isClickEvent(e) { |
| 18087 | return e.type === "mouseup" || e.type === "click" || e.type === "contextmenu"; |
| 18088 | } |
| 18089 | var PI = Math.PI; |
| 18090 | var TAU = 2 * PI; |
| 18091 | var PITAU = TAU + PI; |
| 18092 | var INFINITY = Number.POSITIVE_INFINITY; |
| 18093 | var RAD_PER_DEG = PI / 180; |
| 18094 | var HALF_PI = PI / 2; |
| 18095 | var QUARTER_PI = PI / 4; |
| 18096 | var TWO_THIRDS_PI = PI * 2 / 3; |
| 18097 | var log10 = Math.log10; |
| 18098 | var sign = Math.sign; |
| 18099 | function niceNum(range) { |
| 18100 | var roundedRange = Math.round(range); |
| 18101 | range = almostEquals(range, roundedRange, range / 1000) ? roundedRange : range; |
| 18102 | var niceRange = Math.pow(10, Math.floor(log10(range))); |
| 18103 | var fraction = range / niceRange; |
| 18104 | var niceFraction = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10; |
| 18105 | return niceFraction * niceRange; |
| 18106 | } |
| 18107 | function _factorize(value) { |
| 18108 | var result = []; |
| 18109 | var sqrt = Math.sqrt(value); |
| 18110 | var i; |
| 18111 | for(i = 1; i < sqrt; i++)if (value % i === 0) { |
| 18112 | result.push(i); |
| 18113 | result.push(value / i); |
| 18114 | } |
| 18115 | if (sqrt === (sqrt | 0)) result.push(sqrt); |
| 18116 | result.sort(function(a, b) { |
| 18117 | return a - b; |
| 18118 | }).pop(); |
| 18119 | return result; |
| 18120 | } |
| 18121 | function isNumber(n) { |
| 18122 | return !isNaN(parseFloat(n)) && isFinite(n); |
| 18123 | } |
| 18124 | function almostEquals(x, y, epsilon) { |
| 18125 | return Math.abs(x - y) < epsilon; |
| 18126 | } |
| 18127 | function almostWhole(x, epsilon) { |
| 18128 | var rounded = Math.round(x); |
| 18129 | return rounded - epsilon <= x && rounded + epsilon >= x; |
| 18130 | } |
| 18131 | function _setMinAndMaxByKey(array, target, property) { |
| 18132 | var i, ilen, value; |
| 18133 | for(i = 0, ilen = array.length; i < ilen; i++){ |
| 18134 | value = array[i][property]; |
| 18135 | if (!isNaN(value)) { |
| 18136 | target.min = Math.min(target.min, value); |
| 18137 | target.max = Math.max(target.max, value); |
| 18138 | } |
| 18139 | } |
| 18140 | } |
| 18141 | function toRadians(degrees) { |
| 18142 | return degrees * (PI / 180); |
| 18143 | } |
| 18144 | function toDegrees(radians) { |
| 18145 | return radians * (180 / PI); |
| 18146 | } |
| 18147 | function _decimalPlaces(x) { |
| 18148 | if (!isNumberFinite(x)) return; |
| 18149 | var e = 1; |
| 18150 | var p = 0; |
| 18151 | while(Math.round(x * e) / e !== x){ |
| 18152 | e *= 10; |
| 18153 | p++; |
| 18154 | } |
| 18155 | return p; |
| 18156 | } |
| 18157 | function getAngleFromPoint(centrePoint, anglePoint) { |
| 18158 | var distanceFromXCenter = anglePoint.x - centrePoint.x; |
| 18159 | var distanceFromYCenter = anglePoint.y - centrePoint.y; |
| 18160 | var radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter); |
| 18161 | var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter); |
| 18162 | if (angle < -0.5 * PI) angle += TAU; |
| 18163 | return { |
| 18164 | angle: angle, |
| 18165 | distance: radialDistanceFromCenter |
| 18166 | }; |
| 18167 | } |
| 18168 | function distanceBetweenPoints(pt1, pt2) { |
| 18169 | return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2)); |
| 18170 | } |
| 18171 | function _angleDiff(a, b) { |
| 18172 | return (a - b + PITAU) % TAU - PI; |
| 18173 | } |
| 18174 | function _normalizeAngle(a) { |
| 18175 | return (a % TAU + TAU) % TAU; |
| 18176 | } |
| 18177 | function _angleBetween(angle, start, end, sameAngleIsFullCircle) { |
| 18178 | var a = _normalizeAngle(angle); |
| 18179 | var s = _normalizeAngle(start); |
| 18180 | var e = _normalizeAngle(end); |
| 18181 | var angleToStart = _normalizeAngle(s - a); |
| 18182 | var angleToEnd = _normalizeAngle(e - a); |
| 18183 | var startToAngle = _normalizeAngle(a - s); |
| 18184 | var endToAngle = _normalizeAngle(a - e); |
| 18185 | return a === s || a === e || sameAngleIsFullCircle && s === e || angleToStart > angleToEnd && startToAngle < endToAngle; |
| 18186 | } |
| 18187 | function _limitValue(value, min, max) { |
| 18188 | return Math.max(min, Math.min(max, value)); |
| 18189 | } |
| 18190 | function _int16Range(value) { |
| 18191 | return _limitValue(value, -32768, 32767); |
| 18192 | } |
| 18193 | function _isBetween(value, start, end) { |
| 18194 | var epsilon = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 1e-6; |
| 18195 | return value >= Math.min(start, end) - epsilon && value <= Math.max(start, end) + epsilon; |
| 18196 | } |
| 18197 | var atEdge = function(t) { |
| 18198 | return t === 0 || t === 1; |
| 18199 | }; |
| 18200 | var elasticIn = function(t, s, p) { |
| 18201 | return -(Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * TAU / p)); |
| 18202 | }; |
| 18203 | var elasticOut = function(t, s, p) { |
| 18204 | return Math.pow(2, -10 * t) * Math.sin((t - s) * TAU / p) + 1; |
| 18205 | }; |
| 18206 | var effects = { |
| 18207 | linear: function(t) { |
| 18208 | return t; |
| 18209 | }, |
| 18210 | easeInQuad: function(t) { |
| 18211 | return t * t; |
| 18212 | }, |
| 18213 | easeOutQuad: function(t) { |
| 18214 | return -t * (t - 2); |
| 18215 | }, |
| 18216 | easeInOutQuad: function(t) { |
| 18217 | return (t /= 0.5) < 1 ? 0.5 * t * t : -0.5 * (--t * (t - 2) - 1); |
| 18218 | }, |
| 18219 | easeInCubic: function(t) { |
| 18220 | return t * t * t; |
| 18221 | }, |
| 18222 | easeOutCubic: function(t) { |
| 18223 | return (t -= 1) * t * t + 1; |
| 18224 | }, |
| 18225 | easeInOutCubic: function(t) { |
| 18226 | return (t /= 0.5) < 1 ? 0.5 * t * t * t : 0.5 * ((t -= 2) * t * t + 2); |
| 18227 | }, |
| 18228 | easeInQuart: function(t) { |
| 18229 | return t * t * t * t; |
| 18230 | }, |
| 18231 | easeOutQuart: function(t) { |
| 18232 | return -((t -= 1) * t * t * t - 1); |
| 18233 | }, |
| 18234 | easeInOutQuart: function(t) { |
| 18235 | return (t /= 0.5) < 1 ? 0.5 * t * t * t * t : -0.5 * ((t -= 2) * t * t * t - 2); |
| 18236 | }, |
| 18237 | easeInQuint: function(t) { |
| 18238 | return t * t * t * t * t; |
| 18239 | }, |
| 18240 | easeOutQuint: function(t) { |
| 18241 | return (t -= 1) * t * t * t * t + 1; |
| 18242 | }, |
| 18243 | easeInOutQuint: function(t) { |
| 18244 | return (t /= 0.5) < 1 ? 0.5 * t * t * t * t * t : 0.5 * ((t -= 2) * t * t * t * t + 2); |
| 18245 | }, |
| 18246 | easeInSine: function(t) { |
| 18247 | return -Math.cos(t * HALF_PI) + 1; |
| 18248 | }, |
| 18249 | easeOutSine: function(t) { |
| 18250 | return Math.sin(t * HALF_PI); |
| 18251 | }, |
| 18252 | easeInOutSine: function(t) { |
| 18253 | return -0.5 * (Math.cos(PI * t) - 1); |
| 18254 | }, |
| 18255 | easeInExpo: function(t) { |
| 18256 | return t === 0 ? 0 : Math.pow(2, 10 * (t - 1)); |
| 18257 | }, |
| 18258 | easeOutExpo: function(t) { |
| 18259 | return t === 1 ? 1 : -Math.pow(2, -10 * t) + 1; |
| 18260 | }, |
| 18261 | easeInOutExpo: function(t) { |
| 18262 | return atEdge(t) ? t : t < 0.5 ? 0.5 * Math.pow(2, 10 * (t * 2 - 1)) : 0.5 * (-Math.pow(2, -10 * (t * 2 - 1)) + 2); |
| 18263 | }, |
| 18264 | easeInCirc: function(t) { |
| 18265 | return t >= 1 ? t : -(Math.sqrt(1 - t * t) - 1); |
| 18266 | }, |
| 18267 | easeOutCirc: function(t) { |
| 18268 | return Math.sqrt(1 - (t -= 1) * t); |
| 18269 | }, |
| 18270 | easeInOutCirc: function(t) { |
| 18271 | return (t /= 0.5) < 1 ? -0.5 * (Math.sqrt(1 - t * t) - 1) : 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1); |
| 18272 | }, |
| 18273 | easeInElastic: function(t) { |
| 18274 | return atEdge(t) ? t : elasticIn(t, 0.075, 0.3); |
| 18275 | }, |
| 18276 | easeOutElastic: function(t) { |
| 18277 | return atEdge(t) ? t : elasticOut(t, 0.075, 0.3); |
| 18278 | }, |
| 18279 | easeInOutElastic: function(t) { |
| 18280 | var s = 0.1125; |
| 18281 | var p = 0.45; |
| 18282 | return atEdge(t) ? t : t < 0.5 ? 0.5 * elasticIn(t * 2, s, p) : 0.5 + 0.5 * elasticOut(t * 2 - 1, s, p); |
| 18283 | }, |
| 18284 | easeInBack: function(t) { |
| 18285 | var s = 1.70158; |
| 18286 | return t * t * ((s + 1) * t - s); |
| 18287 | }, |
| 18288 | easeOutBack: function(t) { |
| 18289 | var s = 1.70158; |
| 18290 | return (t -= 1) * t * ((s + 1) * t + s) + 1; |
| 18291 | }, |
| 18292 | easeInOutBack: function(t) { |
| 18293 | var s = 1.70158; |
| 18294 | if ((t /= 0.5) < 1) return 0.5 * (t * t * (((s *= 1.525) + 1) * t - s)); |
| 18295 | return 0.5 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2); |
| 18296 | }, |
| 18297 | easeInBounce: function(t) { |
| 18298 | return 1 - effects.easeOutBounce(1 - t); |
| 18299 | }, |
| 18300 | easeOutBounce: function(t) { |
| 18301 | var m = 7.5625; |
| 18302 | var d = 2.75; |
| 18303 | if (t < 1 / d) return m * t * t; |
| 18304 | if (t < 2 / d) return m * (t -= 1.5 / d) * t + 0.75; |
| 18305 | if (t < 2.5 / d) return m * (t -= 2.25 / d) * t + 0.9375; |
| 18306 | return m * (t -= 2.625 / d) * t + 0.984375; |
| 18307 | }, |
| 18308 | easeInOutBounce: function(t) { |
| 18309 | return t < 0.5 ? effects.easeInBounce(t * 2) * 0.5 : effects.easeOutBounce(t * 2 - 1) * 0.5 + 0.5; |
| 18310 | } |
| 18311 | }; |
| 18312 | /*! |
| 18313 | * @kurkle/color v0.2.1 |
| 18314 | * https://github.com/kurkle/color#readme |
| 18315 | * (c) 2022 Jukka Kurkela |
| 18316 | * Released under the MIT License |
| 18317 | */ function round(v) { |
| 18318 | return v + 0.5 | 0; |
| 18319 | } |
| 18320 | var lim = function(v, l, h) { |
| 18321 | return Math.max(Math.min(v, h), l); |
| 18322 | }; |
| 18323 | function p2b(v) { |
| 18324 | return lim(round(v * 2.55), 0, 255); |
| 18325 | } |
| 18326 | function n2b(v) { |
| 18327 | return lim(round(v * 255), 0, 255); |
| 18328 | } |
| 18329 | function b2n(v) { |
| 18330 | return lim(round(v / 2.55) / 100, 0, 1); |
| 18331 | } |
| 18332 | function n2p(v) { |
| 18333 | return lim(round(v * 100), 0, 100); |
| 18334 | } |
| 18335 | var map$1 = { |
| 18336 | 0: 0, |
| 18337 | 1: 1, |
| 18338 | 2: 2, |
| 18339 | 3: 3, |
| 18340 | 4: 4, |
| 18341 | 5: 5, |
| 18342 | 6: 6, |
| 18343 | 7: 7, |
| 18344 | 8: 8, |
| 18345 | 9: 9, |
| 18346 | A: 10, |
| 18347 | B: 11, |
| 18348 | C: 12, |
| 18349 | D: 13, |
| 18350 | E: 14, |
| 18351 | F: 15, |
| 18352 | a: 10, |
| 18353 | b: 11, |
| 18354 | c: 12, |
| 18355 | d: 13, |
| 18356 | e: 14, |
| 18357 | f: 15 |
| 18358 | }; |
| 18359 | var hex = Array.from("0123456789ABCDEF"); |
| 18360 | var h1 = function(b) { |
| 18361 | return hex[b & 0xF]; |
| 18362 | }; |
| 18363 | var h2 = function(b) { |
| 18364 | return hex[(b & 0xF0) >> 4] + hex[b & 0xF]; |
| 18365 | }; |
| 18366 | var eq = function(b) { |
| 18367 | return (b & 0xF0) >> 4 === (b & 0xF); |
| 18368 | }; |
| 18369 | var isShort = function(v) { |
| 18370 | return eq(v.r) && eq(v.g) && eq(v.b) && eq(v.a); |
| 18371 | }; |
| 18372 | function hexParse(str) { |
| 18373 | var len = str.length; |
| 18374 | var ret; |
| 18375 | if (str[0] === "#") { |
| 18376 | if (len === 4 || len === 5) ret = { |
| 18377 | r: 255 & map$1[str[1]] * 17, |
| 18378 | g: 255 & map$1[str[2]] * 17, |
| 18379 | b: 255 & map$1[str[3]] * 17, |
| 18380 | a: len === 5 ? map$1[str[4]] * 17 : 255 |
| 18381 | }; |
| 18382 | else if (len === 7 || len === 9) ret = { |
| 18383 | r: map$1[str[1]] << 4 | map$1[str[2]], |
| 18384 | g: map$1[str[3]] << 4 | map$1[str[4]], |
| 18385 | b: map$1[str[5]] << 4 | map$1[str[6]], |
| 18386 | a: len === 9 ? map$1[str[7]] << 4 | map$1[str[8]] : 255 |
| 18387 | }; |
| 18388 | } |
| 18389 | return ret; |
| 18390 | } |
| 18391 | var alpha = function(a, f) { |
| 18392 | return a < 255 ? f(a) : ""; |
| 18393 | }; |
| 18394 | function hexString(v) { |
| 18395 | var f = isShort(v) ? h1 : h2; |
| 18396 | return v ? "#" + f(v.r) + f(v.g) + f(v.b) + alpha(v.a, f) : undefined; |
| 18397 | } |
| 18398 | var HUE_RE = /^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/; |
| 18399 | function hsl2rgbn(h, s, l) { |
| 18400 | var a = s * Math.min(l, 1 - l); |
| 18401 | var f = function(n) { |
| 18402 | var k = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : (n + h / 30) % 12; |
| 18403 | return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1); |
| 18404 | }; |
| 18405 | return [ |
| 18406 | f(0), |
| 18407 | f(8), |
| 18408 | f(4) |
| 18409 | ]; |
| 18410 | } |
| 18411 | function hsv2rgbn(h, s, v) { |
| 18412 | var f = function(n) { |
| 18413 | var k = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : (n + h / 60) % 6; |
| 18414 | return v - v * s * Math.max(Math.min(k, 4 - k, 1), 0); |
| 18415 | }; |
| 18416 | return [ |
| 18417 | f(5), |
| 18418 | f(3), |
| 18419 | f(1) |
| 18420 | ]; |
| 18421 | } |
| 18422 | function hwb2rgbn(h, w, b) { |
| 18423 | var rgb = hsl2rgbn(h, 1, 0.5); |
| 18424 | var i; |
| 18425 | if (w + b > 1) { |
| 18426 | i = 1 / (w + b); |
| 18427 | w *= i; |
| 18428 | b *= i; |
| 18429 | } |
| 18430 | for(i = 0; i < 3; i++){ |
| 18431 | rgb[i] *= 1 - w - b; |
| 18432 | rgb[i] += w; |
| 18433 | } |
| 18434 | return rgb; |
| 18435 | } |
| 18436 | function hueValue(r, g, b, d, max) { |
| 18437 | if (r === max) return (g - b) / d + (g < b ? 6 : 0); |
| 18438 | if (g === max) return (b - r) / d + 2; |
| 18439 | return (r - g) / d + 4; |
| 18440 | } |
| 18441 | function rgb2hsl(v) { |
| 18442 | var range = 255; |
| 18443 | var r = v.r / range; |
| 18444 | var g = v.g / range; |
| 18445 | var b = v.b / range; |
| 18446 | var max = Math.max(r, g, b); |
| 18447 | var min = Math.min(r, g, b); |
| 18448 | var l = (max + min) / 2; |
| 18449 | var h, s, d; |
| 18450 | if (max !== min) { |
| 18451 | d = max - min; |
| 18452 | s = l > 0.5 ? d / (2 - max - min) : d / (max + min); |
| 18453 | h = hueValue(r, g, b, d, max); |
| 18454 | h = h * 60 + 0.5; |
| 18455 | } |
| 18456 | return [ |
| 18457 | h | 0, |
| 18458 | s || 0, |
| 18459 | l |
| 18460 | ]; |
| 18461 | } |
| 18462 | function calln(f, a, b, c) { |
| 18463 | return (Array.isArray(a) ? f(a[0], a[1], a[2]) : f(a, b, c)).map(n2b); |
| 18464 | } |
| 18465 | function hsl2rgb(h, s, l) { |
| 18466 | return calln(hsl2rgbn, h, s, l); |
| 18467 | } |
| 18468 | function hwb2rgb(h, w, b) { |
| 18469 | return calln(hwb2rgbn, h, w, b); |
| 18470 | } |
| 18471 | function hsv2rgb(h, s, v) { |
| 18472 | return calln(hsv2rgbn, h, s, v); |
| 18473 | } |
| 18474 | function hue(h) { |
| 18475 | return (h % 360 + 360) % 360; |
| 18476 | } |
| 18477 | function hueParse(str) { |
| 18478 | var m = HUE_RE.exec(str); |
| 18479 | var a = 255; |
| 18480 | var v; |
| 18481 | if (!m) return; |
| 18482 | if (m[5] !== v) a = m[6] ? p2b(+m[5]) : n2b(+m[5]); |
| 18483 | var h = hue(+m[2]); |
| 18484 | var p1 = +m[3] / 100; |
| 18485 | var p2 = +m[4] / 100; |
| 18486 | if (m[1] === "hwb") v = hwb2rgb(h, p1, p2); |
| 18487 | else if (m[1] === "hsv") v = hsv2rgb(h, p1, p2); |
| 18488 | else v = hsl2rgb(h, p1, p2); |
| 18489 | return { |
| 18490 | r: v[0], |
| 18491 | g: v[1], |
| 18492 | b: v[2], |
| 18493 | a: a |
| 18494 | }; |
| 18495 | } |
| 18496 | function rotate(v, deg) { |
| 18497 | var h = rgb2hsl(v); |
| 18498 | h[0] = hue(h[0] + deg); |
| 18499 | h = hsl2rgb(h); |
| 18500 | v.r = h[0]; |
| 18501 | v.g = h[1]; |
| 18502 | v.b = h[2]; |
| 18503 | } |
| 18504 | function hslString(v) { |
| 18505 | if (!v) return; |
| 18506 | var a = rgb2hsl(v); |
| 18507 | var h = a[0]; |
| 18508 | var s = n2p(a[1]); |
| 18509 | var l = n2p(a[2]); |
| 18510 | return v.a < 255 ? "hsla(".concat(h, ", ").concat(s, "%, ").concat(l, "%, ").concat(b2n(v.a), ")") : "hsl(".concat(h, ", ").concat(s, "%, ").concat(l, "%)"); |
| 18511 | } |
| 18512 | var map = { |
| 18513 | x: "dark", |
| 18514 | Z: "light", |
| 18515 | Y: "re", |
| 18516 | X: "blu", |
| 18517 | W: "gr", |
| 18518 | V: "medium", |
| 18519 | U: "slate", |
| 18520 | A: "ee", |
| 18521 | T: "ol", |
| 18522 | S: "or", |
| 18523 | B: "ra", |
| 18524 | C: "lateg", |
| 18525 | D: "ights", |
| 18526 | R: "in", |
| 18527 | Q: "turquois", |
| 18528 | E: "hi", |
| 18529 | P: "ro", |
| 18530 | O: "al", |
| 18531 | N: "le", |
| 18532 | M: "de", |
| 18533 | L: "yello", |
| 18534 | F: "en", |
| 18535 | K: "ch", |
| 18536 | G: "arks", |
| 18537 | H: "ea", |
| 18538 | I: "ightg", |
| 18539 | J: "wh" |
| 18540 | }; |
| 18541 | var names$1 = { |
| 18542 | OiceXe: "f0f8ff", |
| 18543 | antiquewEte: "faebd7", |
| 18544 | aqua: "ffff", |
| 18545 | aquamarRe: "7fffd4", |
| 18546 | azuY: "f0ffff", |
| 18547 | beige: "f5f5dc", |
| 18548 | bisque: "ffe4c4", |
| 18549 | black: "0", |
| 18550 | blanKedOmond: "ffebcd", |
| 18551 | Xe: "ff", |
| 18552 | XeviTet: "8a2be2", |
| 18553 | bPwn: "a52a2a", |
| 18554 | burlywood: "deb887", |
| 18555 | caMtXe: "5f9ea0", |
| 18556 | KartYuse: "7fff00", |
| 18557 | KocTate: "d2691e", |
| 18558 | cSO: "ff7f50", |
| 18559 | cSnflowerXe: "6495ed", |
| 18560 | cSnsilk: "fff8dc", |
| 18561 | crimson: "dc143c", |
| 18562 | cyan: "ffff", |
| 18563 | xXe: "8b", |
| 18564 | xcyan: "8b8b", |
| 18565 | xgTMnPd: "b8860b", |
| 18566 | xWay: "a9a9a9", |
| 18567 | xgYF: "6400", |
| 18568 | xgYy: "a9a9a9", |
| 18569 | xkhaki: "bdb76b", |
| 18570 | xmagFta: "8b008b", |
| 18571 | xTivegYF: "556b2f", |
| 18572 | xSange: "ff8c00", |
| 18573 | xScEd: "9932cc", |
| 18574 | xYd: "8b0000", |
| 18575 | xsOmon: "e9967a", |
| 18576 | xsHgYF: "8fbc8f", |
| 18577 | xUXe: "483d8b", |
| 18578 | xUWay: "2f4f4f", |
| 18579 | xUgYy: "2f4f4f", |
| 18580 | xQe: "ced1", |
| 18581 | xviTet: "9400d3", |
| 18582 | dAppRk: "ff1493", |
| 18583 | dApskyXe: "bfff", |
| 18584 | dimWay: "696969", |
| 18585 | dimgYy: "696969", |
| 18586 | dodgerXe: "1e90ff", |
| 18587 | fiYbrick: "b22222", |
| 18588 | flSOwEte: "fffaf0", |
| 18589 | foYstWAn: "228b22", |
| 18590 | fuKsia: "ff00ff", |
| 18591 | gaRsbSo: "dcdcdc", |
| 18592 | ghostwEte: "f8f8ff", |
| 18593 | gTd: "ffd700", |
| 18594 | gTMnPd: "daa520", |
| 18595 | Way: "808080", |
| 18596 | gYF: "8000", |
| 18597 | gYFLw: "adff2f", |
| 18598 | gYy: "808080", |
| 18599 | honeyMw: "f0fff0", |
| 18600 | hotpRk: "ff69b4", |
| 18601 | RdianYd: "cd5c5c", |
| 18602 | Rdigo: "4b0082", |
| 18603 | ivSy: "fffff0", |
| 18604 | khaki: "f0e68c", |
| 18605 | lavFMr: "e6e6fa", |
| 18606 | lavFMrXsh: "fff0f5", |
| 18607 | lawngYF: "7cfc00", |
| 18608 | NmoncEffon: "fffacd", |
| 18609 | ZXe: "add8e6", |
| 18610 | ZcSO: "f08080", |
| 18611 | Zcyan: "e0ffff", |
| 18612 | ZgTMnPdLw: "fafad2", |
| 18613 | ZWay: "d3d3d3", |
| 18614 | ZgYF: "90ee90", |
| 18615 | ZgYy: "d3d3d3", |
| 18616 | ZpRk: "ffb6c1", |
| 18617 | ZsOmon: "ffa07a", |
| 18618 | ZsHgYF: "20b2aa", |
| 18619 | ZskyXe: "87cefa", |
| 18620 | ZUWay: "778899", |
| 18621 | ZUgYy: "778899", |
| 18622 | ZstAlXe: "b0c4de", |
| 18623 | ZLw: "ffffe0", |
| 18624 | lime: "ff00", |
| 18625 | limegYF: "32cd32", |
| 18626 | lRF: "faf0e6", |
| 18627 | magFta: "ff00ff", |
| 18628 | maPon: "800000", |
| 18629 | VaquamarRe: "66cdaa", |
| 18630 | VXe: "cd", |
| 18631 | VScEd: "ba55d3", |
| 18632 | VpurpN: "9370db", |
| 18633 | VsHgYF: "3cb371", |
| 18634 | VUXe: "7b68ee", |
| 18635 | VsprRggYF: "fa9a", |
| 18636 | VQe: "48d1cc", |
| 18637 | VviTetYd: "c71585", |
| 18638 | midnightXe: "191970", |
| 18639 | mRtcYam: "f5fffa", |
| 18640 | mistyPse: "ffe4e1", |
| 18641 | moccasR: "ffe4b5", |
| 18642 | navajowEte: "ffdead", |
| 18643 | navy: "80", |
| 18644 | Tdlace: "fdf5e6", |
| 18645 | Tive: "808000", |
| 18646 | TivedBb: "6b8e23", |
| 18647 | Sange: "ffa500", |
| 18648 | SangeYd: "ff4500", |
| 18649 | ScEd: "da70d6", |
| 18650 | pOegTMnPd: "eee8aa", |
| 18651 | pOegYF: "98fb98", |
| 18652 | pOeQe: "afeeee", |
| 18653 | pOeviTetYd: "db7093", |
| 18654 | papayawEp: "ffefd5", |
| 18655 | pHKpuff: "ffdab9", |
| 18656 | peru: "cd853f", |
| 18657 | pRk: "ffc0cb", |
| 18658 | plum: "dda0dd", |
| 18659 | powMrXe: "b0e0e6", |
| 18660 | purpN: "800080", |
| 18661 | YbeccapurpN: "663399", |
| 18662 | Yd: "ff0000", |
| 18663 | Psybrown: "bc8f8f", |
| 18664 | PyOXe: "4169e1", |
| 18665 | saddNbPwn: "8b4513", |
| 18666 | sOmon: "fa8072", |
| 18667 | sandybPwn: "f4a460", |
| 18668 | sHgYF: "2e8b57", |
| 18669 | sHshell: "fff5ee", |
| 18670 | siFna: "a0522d", |
| 18671 | silver: "c0c0c0", |
| 18672 | skyXe: "87ceeb", |
| 18673 | UXe: "6a5acd", |
| 18674 | UWay: "708090", |
| 18675 | UgYy: "708090", |
| 18676 | snow: "fffafa", |
| 18677 | sprRggYF: "ff7f", |
| 18678 | stAlXe: "4682b4", |
| 18679 | tan: "d2b48c", |
| 18680 | teO: "8080", |
| 18681 | tEstN: "d8bfd8", |
| 18682 | tomato: "ff6347", |
| 18683 | Qe: "40e0d0", |
| 18684 | viTet: "ee82ee", |
| 18685 | JHt: "f5deb3", |
| 18686 | wEte: "ffffff", |
| 18687 | wEtesmoke: "f5f5f5", |
| 18688 | Lw: "ffff00", |
| 18689 | LwgYF: "9acd32" |
| 18690 | }; |
| 18691 | function unpack() { |
| 18692 | var unpacked = {}; |
| 18693 | var keys = Object.keys(names$1); |
| 18694 | var tkeys = Object.keys(map); |
| 18695 | var i, j, k, ok, nk; |
| 18696 | for(i = 0; i < keys.length; i++){ |
| 18697 | ok = nk = keys[i]; |
| 18698 | for(j = 0; j < tkeys.length; j++){ |
| 18699 | k = tkeys[j]; |
| 18700 | nk = nk.replace(k, map[k]); |
| 18701 | } |
| 18702 | k = parseInt(names$1[ok], 16); |
| 18703 | unpacked[nk] = [ |
| 18704 | k >> 16 & 0xFF, |
| 18705 | k >> 8 & 0xFF, |
| 18706 | k & 0xFF |
| 18707 | ]; |
| 18708 | } |
| 18709 | return unpacked; |
| 18710 | } |
| 18711 | var names; |
| 18712 | function nameParse(str) { |
| 18713 | if (!names) { |
| 18714 | names = unpack(); |
| 18715 | names.transparent = [ |
| 18716 | 0, |
| 18717 | 0, |
| 18718 | 0, |
| 18719 | 0 |
| 18720 | ]; |
| 18721 | } |
| 18722 | var a = names[str.toLowerCase()]; |
| 18723 | return a && { |
| 18724 | r: a[0], |
| 18725 | g: a[1], |
| 18726 | b: a[2], |
| 18727 | a: a.length === 4 ? a[3] : 255 |
| 18728 | }; |
| 18729 | } |
| 18730 | var RGB_RE = /^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/; |
| 18731 | function rgbParse(str) { |
| 18732 | var m = RGB_RE.exec(str); |
| 18733 | var a = 255; |
| 18734 | var r, g, b; |
| 18735 | if (!m) return; |
| 18736 | if (m[7] !== r) { |
| 18737 | var v = +m[7]; |
| 18738 | a = m[8] ? p2b(v) : lim(v * 255, 0, 255); |
| 18739 | } |
| 18740 | r = +m[1]; |
| 18741 | g = +m[3]; |
| 18742 | b = +m[5]; |
| 18743 | r = 255 & (m[2] ? p2b(r) : lim(r, 0, 255)); |
| 18744 | g = 255 & (m[4] ? p2b(g) : lim(g, 0, 255)); |
| 18745 | b = 255 & (m[6] ? p2b(b) : lim(b, 0, 255)); |
| 18746 | return { |
| 18747 | r: r, |
| 18748 | g: g, |
| 18749 | b: b, |
| 18750 | a: a |
| 18751 | }; |
| 18752 | } |
| 18753 | function rgbString(v) { |
| 18754 | return v && (v.a < 255 ? "rgba(".concat(v.r, ", ").concat(v.g, ", ").concat(v.b, ", ").concat(b2n(v.a), ")") : "rgb(".concat(v.r, ", ").concat(v.g, ", ").concat(v.b, ")")); |
| 18755 | } |
| 18756 | var to = function(v) { |
| 18757 | return v <= 0.0031308 ? v * 12.92 : Math.pow(v, 1.0 / 2.4) * 1.055 - 0.055; |
| 18758 | }; |
| 18759 | var from = function(v) { |
| 18760 | return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); |
| 18761 | }; |
| 18762 | function interpolate(rgb1, rgb2, t) { |
| 18763 | var r = from(b2n(rgb1.r)); |
| 18764 | var g = from(b2n(rgb1.g)); |
| 18765 | var b = from(b2n(rgb1.b)); |
| 18766 | return { |
| 18767 | r: n2b(to(r + t * (from(b2n(rgb2.r)) - r))), |
| 18768 | g: n2b(to(g + t * (from(b2n(rgb2.g)) - g))), |
| 18769 | b: n2b(to(b + t * (from(b2n(rgb2.b)) - b))), |
| 18770 | a: rgb1.a + t * (rgb2.a - rgb1.a) |
| 18771 | }; |
| 18772 | } |
| 18773 | function modHSL(v, i, ratio) { |
| 18774 | if (v) { |
| 18775 | var tmp = rgb2hsl(v); |
| 18776 | tmp[i] = Math.max(0, Math.min(tmp[i] + tmp[i] * ratio, i === 0 ? 360 : 1)); |
| 18777 | tmp = hsl2rgb(tmp); |
| 18778 | v.r = tmp[0]; |
| 18779 | v.g = tmp[1]; |
| 18780 | v.b = tmp[2]; |
| 18781 | } |
| 18782 | } |
| 18783 | function clone(v, proto) { |
| 18784 | return v ? Object.assign(proto || {}, v) : v; |
| 18785 | } |
| 18786 | function fromObject(input) { |
| 18787 | var v = { |
| 18788 | r: 0, |
| 18789 | g: 0, |
| 18790 | b: 0, |
| 18791 | a: 255 |
| 18792 | }; |
| 18793 | if (Array.isArray(input)) { |
| 18794 | if (input.length >= 3) { |
| 18795 | v = { |
| 18796 | r: input[0], |
| 18797 | g: input[1], |
| 18798 | b: input[2], |
| 18799 | a: 255 |
| 18800 | }; |
| 18801 | if (input.length > 3) v.a = n2b(input[3]); |
| 18802 | } |
| 18803 | } else { |
| 18804 | v = clone(input, { |
| 18805 | r: 0, |
| 18806 | g: 0, |
| 18807 | b: 0, |
| 18808 | a: 1 |
| 18809 | }); |
| 18810 | v.a = n2b(v.a); |
| 18811 | } |
| 18812 | return v; |
| 18813 | } |
| 18814 | function functionParse(str) { |
| 18815 | if (str.charAt(0) === "r") return rgbParse(str); |
| 18816 | return hueParse(str); |
| 18817 | } |
| 18818 | var Color = /*#__PURE__*/ function() { |
| 18819 | "use strict"; |
| 18820 | function Color(input) { |
| 18821 | (0, _classCallCheckJsDefault.default)(this, Color); |
| 18822 | if (input instanceof Color) return input; |
| 18823 | var type = typeof input === "undefined" ? "undefined" : (0, _typeOfJsDefault.default)(input); |
| 18824 | var v; |
| 18825 | if (type === "object") v = fromObject(input); |
| 18826 | else if (type === "string") v = hexParse(input) || nameParse(input) || functionParse(input); |
| 18827 | this._rgb = v; |
| 18828 | this._valid = !!v; |
| 18829 | } |
| 18830 | (0, _createClassJsDefault.default)(Color, [ |
| 18831 | { |
| 18832 | key: "valid", |
| 18833 | get: function get() { |
| 18834 | return this._valid; |
| 18835 | } |
| 18836 | }, |
| 18837 | { |
| 18838 | key: "rgb", |
| 18839 | get: function get() { |
| 18840 | var v = clone(this._rgb); |
| 18841 | if (v) v.a = b2n(v.a); |
| 18842 | return v; |
| 18843 | }, |
| 18844 | set: function set1(obj) { |
| 18845 | this._rgb = fromObject(obj); |
| 18846 | } |
| 18847 | }, |
| 18848 | { |
| 18849 | key: "rgbString", |
| 18850 | value: function rgbString1() { |
| 18851 | return this._valid ? rgbString(this._rgb) : undefined; |
| 18852 | } |
| 18853 | }, |
| 18854 | { |
| 18855 | key: "hexString", |
| 18856 | value: function hexString1() { |
| 18857 | return this._valid ? hexString(this._rgb) : undefined; |
| 18858 | } |
| 18859 | }, |
| 18860 | { |
| 18861 | key: "hslString", |
| 18862 | value: function hslString1() { |
| 18863 | return this._valid ? hslString(this._rgb) : undefined; |
| 18864 | } |
| 18865 | }, |
| 18866 | { |
| 18867 | key: "mix", |
| 18868 | value: function mix(color1, weight) { |
| 18869 | if (color1) { |
| 18870 | var c1 = this.rgb; |
| 18871 | var c2 = color1.rgb; |
| 18872 | var w2; |
| 18873 | var p = weight === w2 ? 0.5 : weight; |
| 18874 | var w = 2 * p - 1; |
| 18875 | var a = c1.a - c2.a; |
| 18876 | var w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2.0; |
| 18877 | w2 = 1 - w1; |
| 18878 | c1.r = 0xFF & w1 * c1.r + w2 * c2.r + 0.5; |
| 18879 | c1.g = 0xFF & w1 * c1.g + w2 * c2.g + 0.5; |
| 18880 | c1.b = 0xFF & w1 * c1.b + w2 * c2.b + 0.5; |
| 18881 | c1.a = p * c1.a + (1 - p) * c2.a; |
| 18882 | this.rgb = c1; |
| 18883 | } |
| 18884 | return this; |
| 18885 | } |
| 18886 | }, |
| 18887 | { |
| 18888 | key: "interpolate", |
| 18889 | value: function interpolate1(color2, t) { |
| 18890 | if (color2) this._rgb = interpolate(this._rgb, color2._rgb, t); |
| 18891 | return this; |
| 18892 | } |
| 18893 | }, |
| 18894 | { |
| 18895 | key: "clone", |
| 18896 | value: function clone() { |
| 18897 | return new Color(this.rgb); |
| 18898 | } |
| 18899 | }, |
| 18900 | { |
| 18901 | key: "alpha", |
| 18902 | value: function alpha(a) { |
| 18903 | this._rgb.a = n2b(a); |
| 18904 | return this; |
| 18905 | } |
| 18906 | }, |
| 18907 | { |
| 18908 | key: "clearer", |
| 18909 | value: function clearer(ratio) { |
| 18910 | var rgb = this._rgb; |
| 18911 | rgb.a *= 1 - ratio; |
| 18912 | return this; |
| 18913 | } |
| 18914 | }, |
| 18915 | { |
| 18916 | key: "greyscale", |
| 18917 | value: function greyscale() { |
| 18918 | var rgb = this._rgb; |
| 18919 | var val = round(rgb.r * 0.3 + rgb.g * 0.59 + rgb.b * 0.11); |
| 18920 | rgb.r = rgb.g = rgb.b = val; |
| 18921 | return this; |
| 18922 | } |
| 18923 | }, |
| 18924 | { |
| 18925 | key: "opaquer", |
| 18926 | value: function opaquer(ratio) { |
| 18927 | var rgb = this._rgb; |
| 18928 | rgb.a *= 1 + ratio; |
| 18929 | return this; |
| 18930 | } |
| 18931 | }, |
| 18932 | { |
| 18933 | key: "negate", |
| 18934 | value: function negate() { |
| 18935 | var v = this._rgb; |
| 18936 | v.r = 255 - v.r; |
| 18937 | v.g = 255 - v.g; |
| 18938 | v.b = 255 - v.b; |
| 18939 | return this; |
| 18940 | } |
| 18941 | }, |
| 18942 | { |
| 18943 | key: "lighten", |
| 18944 | value: function lighten(ratio) { |
| 18945 | modHSL(this._rgb, 2, ratio); |
| 18946 | return this; |
| 18947 | } |
| 18948 | }, |
| 18949 | { |
| 18950 | key: "darken", |
| 18951 | value: function darken(ratio) { |
| 18952 | modHSL(this._rgb, 2, -ratio); |
| 18953 | return this; |
| 18954 | } |
| 18955 | }, |
| 18956 | { |
| 18957 | key: "saturate", |
| 18958 | value: function saturate(ratio) { |
| 18959 | modHSL(this._rgb, 1, ratio); |
| 18960 | return this; |
| 18961 | } |
| 18962 | }, |
| 18963 | { |
| 18964 | key: "desaturate", |
| 18965 | value: function desaturate(ratio) { |
| 18966 | modHSL(this._rgb, 1, -ratio); |
| 18967 | return this; |
| 18968 | } |
| 18969 | }, |
| 18970 | { |
| 18971 | key: "rotate", |
| 18972 | value: function rotate1(deg) { |
| 18973 | rotate(this._rgb, deg); |
| 18974 | return this; |
| 18975 | } |
| 18976 | } |
| 18977 | ]); |
| 18978 | return Color; |
| 18979 | }(); |
| 18980 | function index_esm(input) { |
| 18981 | return new Color(input); |
| 18982 | } |
| 18983 | function isPatternOrGradient(value) { |
| 18984 | if (value && typeof value === "object") { |
| 18985 | var type = value.toString(); |
| 18986 | return type === "[object CanvasPattern]" || type === "[object CanvasGradient]"; |
| 18987 | } |
| 18988 | return false; |
| 18989 | } |
| 18990 | function color(value) { |
| 18991 | return isPatternOrGradient(value) ? value : index_esm(value); |
| 18992 | } |
| 18993 | function getHoverColor(value) { |
| 18994 | return isPatternOrGradient(value) ? value : index_esm(value).saturate(0.5).darken(0.1).hexString(); |
| 18995 | } |
| 18996 | var overrides = Object.create(null); |
| 18997 | var descriptors = Object.create(null); |
| 18998 | function getScope$1(node, key) { |
| 18999 | if (!key) return node; |
| 19000 | var keys = key.split("."); |
| 19001 | for(var i = 0, n = keys.length; i < n; ++i){ |
| 19002 | var k = keys[i]; |
| 19003 | node = node[k] || (node[k] = Object.create(null)); |
| 19004 | } |
| 19005 | return node; |
| 19006 | } |
| 19007 | function set(root, scope, values) { |
| 19008 | if (typeof scope === "string") return merge(getScope$1(root, scope), values); |
| 19009 | return merge(getScope$1(root, ""), scope); |
| 19010 | } |
| 19011 | var Defaults = /*#__PURE__*/ function() { |
| 19012 | "use strict"; |
| 19013 | function Defaults(_descriptors1) { |
| 19014 | (0, _classCallCheckJsDefault.default)(this, Defaults); |
| 19015 | this.animation = undefined; |
| 19016 | this.backgroundColor = "rgba(0,0,0,0.1)"; |
| 19017 | this.borderColor = "rgba(0,0,0,0.1)"; |
| 19018 | this.color = "#666"; |
| 19019 | this.datasets = {}; |
| 19020 | this.devicePixelRatio = function(context) { |
| 19021 | return context.chart.platform.getDevicePixelRatio(); |
| 19022 | }; |
| 19023 | this.elements = {}; |
| 19024 | this.events = [ |
| 19025 | "mousemove", |
| 19026 | "mouseout", |
| 19027 | "click", |
| 19028 | "touchstart", |
| 19029 | "touchmove" |
| 19030 | ]; |
| 19031 | this.font = { |
| 19032 | family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", |
| 19033 | size: 12, |
| 19034 | style: "normal", |
| 19035 | lineHeight: 1.2, |
| 19036 | weight: null |
| 19037 | }; |
| 19038 | this.hover = {}; |
| 19039 | this.hoverBackgroundColor = function(ctx, options) { |
| 19040 | return getHoverColor(options.backgroundColor); |
| 19041 | }; |
| 19042 | this.hoverBorderColor = function(ctx, options) { |
| 19043 | return getHoverColor(options.borderColor); |
| 19044 | }; |
| 19045 | this.hoverColor = function(ctx, options) { |
| 19046 | return getHoverColor(options.color); |
| 19047 | }; |
| 19048 | this.indexAxis = "x"; |
| 19049 | this.interaction = { |
| 19050 | mode: "nearest", |
| 19051 | intersect: true, |
| 19052 | includeInvisible: false |
| 19053 | }; |
| 19054 | this.maintainAspectRatio = true; |
| 19055 | this.onHover = null; |
| 19056 | this.onClick = null; |
| 19057 | this.parsing = true; |
| 19058 | this.plugins = {}; |
| 19059 | this.responsive = true; |
| 19060 | this.scale = undefined; |
| 19061 | this.scales = {}; |
| 19062 | this.showLine = true; |
| 19063 | this.drawActiveElementsOnTop = true; |
| 19064 | this.describe(_descriptors1); |
| 19065 | } |
| 19066 | (0, _createClassJsDefault.default)(Defaults, [ |
| 19067 | { |
| 19068 | key: "set", |
| 19069 | value: function set1(scope, values) { |
| 19070 | return set(this, scope, values); |
| 19071 | } |
| 19072 | }, |
| 19073 | { |
| 19074 | key: "get", |
| 19075 | value: function get(scope) { |
| 19076 | return getScope$1(this, scope); |
| 19077 | } |
| 19078 | }, |
| 19079 | { |
| 19080 | key: "describe", |
| 19081 | value: function describe(scope, values) { |
| 19082 | return set(descriptors, scope, values); |
| 19083 | } |
| 19084 | }, |
| 19085 | { |
| 19086 | key: "override", |
| 19087 | value: function override(scope, values) { |
| 19088 | return set(overrides, scope, values); |
| 19089 | } |
| 19090 | }, |
| 19091 | { |
| 19092 | key: "route", |
| 19093 | value: function route(scope, name, targetScope, targetName) { |
| 19094 | var scopeObject = getScope$1(this, scope); |
| 19095 | var targetScopeObject = getScope$1(this, targetScope); |
| 19096 | var privateName = "_" + name; |
| 19097 | var _obj; |
| 19098 | Object.defineProperties(scopeObject, (_obj = {}, (0, _definePropertyJsDefault.default)(_obj, privateName, { |
| 19099 | value: scopeObject[name], |
| 19100 | writable: true |
| 19101 | }), (0, _definePropertyJsDefault.default)(_obj, name, { |
| 19102 | enumerable: true, |
| 19103 | get: function() { |
| 19104 | var local = this[privateName]; |
| 19105 | var target = targetScopeObject[targetName]; |
| 19106 | if (isObject(local)) return Object.assign({}, target, local); |
| 19107 | return valueOrDefault(local, target); |
| 19108 | }, |
| 19109 | set: function(value) { |
| 19110 | this[privateName] = value; |
| 19111 | } |
| 19112 | }), _obj)); |
| 19113 | } |
| 19114 | } |
| 19115 | ]); |
| 19116 | return Defaults; |
| 19117 | }(); |
| 19118 | var defaults = new Defaults({ |
| 19119 | _scriptable: function(name) { |
| 19120 | return !name.startsWith("on"); |
| 19121 | }, |
| 19122 | _indexable: function(name) { |
| 19123 | return name !== "events"; |
| 19124 | }, |
| 19125 | hover: { |
| 19126 | _fallback: "interaction" |
| 19127 | }, |
| 19128 | interaction: { |
| 19129 | _scriptable: false, |
| 19130 | _indexable: false |
| 19131 | } |
| 19132 | }); |
| 19133 | function toFontString(font) { |
| 19134 | if (!font || isNullOrUndef(font.size) || isNullOrUndef(font.family)) return null; |
| 19135 | return (font.style ? font.style + " " : "") + (font.weight ? font.weight + " " : "") + font.size + "px " + font.family; |
| 19136 | } |
| 19137 | function _measureText(ctx, data, gc, longest, string) { |
| 19138 | var textWidth = data[string]; |
| 19139 | if (!textWidth) { |
| 19140 | textWidth = data[string] = ctx.measureText(string).width; |
| 19141 | gc.push(string); |
| 19142 | } |
| 19143 | if (textWidth > longest) longest = textWidth; |
| 19144 | return longest; |
| 19145 | } |
| 19146 | function _longestText(ctx, font, arrayOfThings, cache) { |
| 19147 | cache = cache || {}; |
| 19148 | var data = cache.data = cache.data || {}; |
| 19149 | var gc = cache.garbageCollect = cache.garbageCollect || []; |
| 19150 | if (cache.font !== font) { |
| 19151 | data = cache.data = {}; |
| 19152 | gc = cache.garbageCollect = []; |
| 19153 | cache.font = font; |
| 19154 | } |
| 19155 | ctx.save(); |
| 19156 | ctx.font = font; |
| 19157 | var longest = 0; |
| 19158 | var ilen = arrayOfThings.length; |
| 19159 | var i, j, jlen, thing, nestedThing; |
| 19160 | for(i = 0; i < ilen; i++){ |
| 19161 | thing = arrayOfThings[i]; |
| 19162 | if (thing !== undefined && thing !== null && isArray(thing) !== true) longest = _measureText(ctx, data, gc, longest, thing); |
| 19163 | else if (isArray(thing)) for(j = 0, jlen = thing.length; j < jlen; j++){ |
| 19164 | nestedThing = thing[j]; |
| 19165 | if (nestedThing !== undefined && nestedThing !== null && !isArray(nestedThing)) longest = _measureText(ctx, data, gc, longest, nestedThing); |
| 19166 | } |
| 19167 | } |
| 19168 | ctx.restore(); |
| 19169 | var gcLen = gc.length / 2; |
| 19170 | if (gcLen > arrayOfThings.length) { |
| 19171 | for(i = 0; i < gcLen; i++)delete data[gc[i]]; |
| 19172 | gc.splice(0, gcLen); |
| 19173 | } |
| 19174 | return longest; |
| 19175 | } |
| 19176 | function _alignPixel(chart, pixel, width) { |
| 19177 | var devicePixelRatio = chart.currentDevicePixelRatio; |
| 19178 | var halfWidth = width !== 0 ? Math.max(width / 2, 0.5) : 0; |
| 19179 | return Math.round((pixel - halfWidth) * devicePixelRatio) / devicePixelRatio + halfWidth; |
| 19180 | } |
| 19181 | function clearCanvas(canvas, ctx) { |
| 19182 | ctx = ctx || canvas.getContext("2d"); |
| 19183 | ctx.save(); |
| 19184 | ctx.resetTransform(); |
| 19185 | ctx.clearRect(0, 0, canvas.width, canvas.height); |
| 19186 | ctx.restore(); |
| 19187 | } |
| 19188 | function drawPoint(ctx, options, x, y) { |
| 19189 | var type, xOffset, yOffset, size, cornerRadius; |
| 19190 | var style = options.pointStyle; |
| 19191 | var rotation = options.rotation; |
| 19192 | var radius = options.radius; |
| 19193 | var rad = (rotation || 0) * RAD_PER_DEG; |
| 19194 | if (style && typeof style === "object") { |
| 19195 | type = style.toString(); |
| 19196 | if (type === "[object HTMLImageElement]" || type === "[object HTMLCanvasElement]") { |
| 19197 | ctx.save(); |
| 19198 | ctx.translate(x, y); |
| 19199 | ctx.rotate(rad); |
| 19200 | ctx.drawImage(style, -style.width / 2, -style.height / 2, style.width, style.height); |
| 19201 | ctx.restore(); |
| 19202 | return; |
| 19203 | } |
| 19204 | } |
| 19205 | if (isNaN(radius) || radius <= 0) return; |
| 19206 | ctx.beginPath(); |
| 19207 | switch(style){ |
| 19208 | default: |
| 19209 | ctx.arc(x, y, radius, 0, TAU); |
| 19210 | ctx.closePath(); |
| 19211 | break; |
| 19212 | case "triangle": |
| 19213 | ctx.moveTo(x + Math.sin(rad) * radius, y - Math.cos(rad) * radius); |
| 19214 | rad += TWO_THIRDS_PI; |
| 19215 | ctx.lineTo(x + Math.sin(rad) * radius, y - Math.cos(rad) * radius); |
| 19216 | rad += TWO_THIRDS_PI; |
| 19217 | ctx.lineTo(x + Math.sin(rad) * radius, y - Math.cos(rad) * radius); |
| 19218 | ctx.closePath(); |
| 19219 | break; |
| 19220 | case "rectRounded": |
| 19221 | cornerRadius = radius * 0.516; |
| 19222 | size = radius - cornerRadius; |
| 19223 | xOffset = Math.cos(rad + QUARTER_PI) * size; |
| 19224 | yOffset = Math.sin(rad + QUARTER_PI) * size; |
| 19225 | ctx.arc(x - xOffset, y - yOffset, cornerRadius, rad - PI, rad - HALF_PI); |
| 19226 | ctx.arc(x + yOffset, y - xOffset, cornerRadius, rad - HALF_PI, rad); |
| 19227 | ctx.arc(x + xOffset, y + yOffset, cornerRadius, rad, rad + HALF_PI); |
| 19228 | ctx.arc(x - yOffset, y + xOffset, cornerRadius, rad + HALF_PI, rad + PI); |
| 19229 | ctx.closePath(); |
| 19230 | break; |
| 19231 | case "rect": |
| 19232 | if (!rotation) { |
| 19233 | size = Math.SQRT1_2 * radius; |
| 19234 | ctx.rect(x - size, y - size, 2 * size, 2 * size); |
| 19235 | break; |
| 19236 | } |
| 19237 | rad += QUARTER_PI; |
| 19238 | case "rectRot": |
| 19239 | xOffset = Math.cos(rad) * radius; |
| 19240 | yOffset = Math.sin(rad) * radius; |
| 19241 | ctx.moveTo(x - xOffset, y - yOffset); |
| 19242 | ctx.lineTo(x + yOffset, y - xOffset); |
| 19243 | ctx.lineTo(x + xOffset, y + yOffset); |
| 19244 | ctx.lineTo(x - yOffset, y + xOffset); |
| 19245 | ctx.closePath(); |
| 19246 | break; |
| 19247 | case "crossRot": |
| 19248 | rad += QUARTER_PI; |
| 19249 | case "cross": |
| 19250 | xOffset = Math.cos(rad) * radius; |
| 19251 | yOffset = Math.sin(rad) * radius; |
| 19252 | ctx.moveTo(x - xOffset, y - yOffset); |
| 19253 | ctx.lineTo(x + xOffset, y + yOffset); |
| 19254 | ctx.moveTo(x + yOffset, y - xOffset); |
| 19255 | ctx.lineTo(x - yOffset, y + xOffset); |
| 19256 | break; |
| 19257 | case "star": |
| 19258 | xOffset = Math.cos(rad) * radius; |
| 19259 | yOffset = Math.sin(rad) * radius; |
| 19260 | ctx.moveTo(x - xOffset, y - yOffset); |
| 19261 | ctx.lineTo(x + xOffset, y + yOffset); |
| 19262 | ctx.moveTo(x + yOffset, y - xOffset); |
| 19263 | ctx.lineTo(x - yOffset, y + xOffset); |
| 19264 | rad += QUARTER_PI; |
| 19265 | xOffset = Math.cos(rad) * radius; |
| 19266 | yOffset = Math.sin(rad) * radius; |
| 19267 | ctx.moveTo(x - xOffset, y - yOffset); |
| 19268 | ctx.lineTo(x + xOffset, y + yOffset); |
| 19269 | ctx.moveTo(x + yOffset, y - xOffset); |
| 19270 | ctx.lineTo(x - yOffset, y + xOffset); |
| 19271 | break; |
| 19272 | case "line": |
| 19273 | xOffset = Math.cos(rad) * radius; |
| 19274 | yOffset = Math.sin(rad) * radius; |
| 19275 | ctx.moveTo(x - xOffset, y - yOffset); |
| 19276 | ctx.lineTo(x + xOffset, y + yOffset); |
| 19277 | break; |
| 19278 | case "dash": |
| 19279 | ctx.moveTo(x, y); |
| 19280 | ctx.lineTo(x + Math.cos(rad) * radius, y + Math.sin(rad) * radius); |
| 19281 | break; |
| 19282 | } |
| 19283 | ctx.fill(); |
| 19284 | if (options.borderWidth > 0) ctx.stroke(); |
| 19285 | } |
| 19286 | function _isPointInArea(point, area, margin) { |
| 19287 | margin = margin || 0.5; |
| 19288 | return !area || point && point.x > area.left - margin && point.x < area.right + margin && point.y > area.top - margin && point.y < area.bottom + margin; |
| 19289 | } |
| 19290 | function clipArea(ctx, area) { |
| 19291 | ctx.save(); |
| 19292 | ctx.beginPath(); |
| 19293 | ctx.rect(area.left, area.top, area.right - area.left, area.bottom - area.top); |
| 19294 | ctx.clip(); |
| 19295 | } |
| 19296 | function unclipArea(ctx) { |
| 19297 | ctx.restore(); |
| 19298 | } |
| 19299 | function _steppedLineTo(ctx, previous, target, flip, mode) { |
| 19300 | if (!previous) return ctx.lineTo(target.x, target.y); |
| 19301 | if (mode === "middle") { |
| 19302 | var midpoint = (previous.x + target.x) / 2.0; |
| 19303 | ctx.lineTo(midpoint, previous.y); |
| 19304 | ctx.lineTo(midpoint, target.y); |
| 19305 | } else if (mode === "after" !== !!flip) ctx.lineTo(previous.x, target.y); |
| 19306 | else ctx.lineTo(target.x, previous.y); |
| 19307 | ctx.lineTo(target.x, target.y); |
| 19308 | } |
| 19309 | function _bezierCurveTo(ctx, previous, target, flip) { |
| 19310 | if (!previous) return ctx.lineTo(target.x, target.y); |
| 19311 | ctx.bezierCurveTo(flip ? previous.cp1x : previous.cp2x, flip ? previous.cp1y : previous.cp2y, flip ? target.cp2x : target.cp1x, flip ? target.cp2y : target.cp1y, target.x, target.y); |
| 19312 | } |
| 19313 | function renderText(ctx, text, x, y, font) { |
| 19314 | var opts = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {}; |
| 19315 | var lines = isArray(text) ? text : [ |
| 19316 | text |
| 19317 | ]; |
| 19318 | var stroke = opts.strokeWidth > 0 && opts.strokeColor !== ""; |
| 19319 | var i, line; |
| 19320 | ctx.save(); |
| 19321 | ctx.font = font.string; |
| 19322 | setRenderOpts(ctx, opts); |
| 19323 | for(i = 0; i < lines.length; ++i){ |
| 19324 | line = lines[i]; |
| 19325 | if (stroke) { |
| 19326 | if (opts.strokeColor) ctx.strokeStyle = opts.strokeColor; |
| 19327 | if (!isNullOrUndef(opts.strokeWidth)) ctx.lineWidth = opts.strokeWidth; |
| 19328 | ctx.strokeText(line, x, y, opts.maxWidth); |
| 19329 | } |
| 19330 | ctx.fillText(line, x, y, opts.maxWidth); |
| 19331 | decorateText(ctx, x, y, line, opts); |
| 19332 | y += font.lineHeight; |
| 19333 | } |
| 19334 | ctx.restore(); |
| 19335 | } |
| 19336 | function setRenderOpts(ctx, opts) { |
| 19337 | if (opts.translation) ctx.translate(opts.translation[0], opts.translation[1]); |
| 19338 | if (!isNullOrUndef(opts.rotation)) ctx.rotate(opts.rotation); |
| 19339 | if (opts.color) ctx.fillStyle = opts.color; |
| 19340 | if (opts.textAlign) ctx.textAlign = opts.textAlign; |
| 19341 | if (opts.textBaseline) ctx.textBaseline = opts.textBaseline; |
| 19342 | } |
| 19343 | function decorateText(ctx, x, y, line, opts) { |
| 19344 | if (opts.strikethrough || opts.underline) { |
| 19345 | var metrics = ctx.measureText(line); |
| 19346 | var left = x - metrics.actualBoundingBoxLeft; |
| 19347 | var right = x + metrics.actualBoundingBoxRight; |
| 19348 | var top = y - metrics.actualBoundingBoxAscent; |
| 19349 | var bottom = y + metrics.actualBoundingBoxDescent; |
| 19350 | var yDecoration = opts.strikethrough ? (top + bottom) / 2 : bottom; |
| 19351 | ctx.strokeStyle = ctx.fillStyle; |
| 19352 | ctx.beginPath(); |
| 19353 | ctx.lineWidth = opts.decorationWidth || 2; |
| 19354 | ctx.moveTo(left, yDecoration); |
| 19355 | ctx.lineTo(right, yDecoration); |
| 19356 | ctx.stroke(); |
| 19357 | } |
| 19358 | } |
| 19359 | function addRoundedRectPath(ctx, rect) { |
| 19360 | var x = rect.x, y = rect.y, w = rect.w, h = rect.h, radius = rect.radius; |
| 19361 | ctx.arc(x + radius.topLeft, y + radius.topLeft, radius.topLeft, -HALF_PI, PI, true); |
| 19362 | ctx.lineTo(x, y + h - radius.bottomLeft); |
| 19363 | ctx.arc(x + radius.bottomLeft, y + h - radius.bottomLeft, radius.bottomLeft, PI, HALF_PI, true); |
| 19364 | ctx.lineTo(x + w - radius.bottomRight, y + h); |
| 19365 | ctx.arc(x + w - radius.bottomRight, y + h - radius.bottomRight, radius.bottomRight, HALF_PI, 0, true); |
| 19366 | ctx.lineTo(x + w, y + radius.topRight); |
| 19367 | ctx.arc(x + w - radius.topRight, y + radius.topRight, radius.topRight, 0, -HALF_PI, true); |
| 19368 | ctx.lineTo(x + radius.topLeft, y); |
| 19369 | } |
| 19370 | var LINE_HEIGHT = new RegExp(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/); |
| 19371 | var FONT_STYLE = new RegExp(/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/); |
| 19372 | function toLineHeight(value, size) { |
| 19373 | var matches = ("" + value).match(LINE_HEIGHT); |
| 19374 | if (!matches || matches[1] === "normal") return size * 1.2; |
| 19375 | value = +matches[2]; |
| 19376 | switch(matches[3]){ |
| 19377 | case "px": |
| 19378 | return value; |
| 19379 | case "%": |
| 19380 | value /= 100; |
| 19381 | break; |
| 19382 | } |
| 19383 | return size * value; |
| 19384 | } |
| 19385 | var numberOrZero = function(v) { |
| 19386 | return +v || 0; |
| 19387 | }; |
| 19388 | function _readValueToProps(value, props) { |
| 19389 | var ret = {}; |
| 19390 | var objProps = isObject(props); |
| 19391 | var keys = objProps ? Object.keys(props) : props; |
| 19392 | var read = isObject(value) ? objProps ? function(prop) { |
| 19393 | return valueOrDefault(value[prop], value[props[prop]]); |
| 19394 | } : function(prop) { |
| 19395 | return value[prop]; |
| 19396 | } : function() { |
| 19397 | return value; |
| 19398 | }; |
| 19399 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 19400 | try { |
| 19401 | for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 19402 | var prop1 = _step.value; |
| 19403 | ret[prop1] = numberOrZero(read(prop1)); |
| 19404 | } |
| 19405 | } catch (err) { |
| 19406 | _didIteratorError = true; |
| 19407 | _iteratorError = err; |
| 19408 | } finally{ |
| 19409 | try { |
| 19410 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 19411 | _iterator.return(); |
| 19412 | } |
| 19413 | } finally{ |
| 19414 | if (_didIteratorError) { |
| 19415 | throw _iteratorError; |
| 19416 | } |
| 19417 | } |
| 19418 | } |
| 19419 | return ret; |
| 19420 | } |
| 19421 | function toTRBL(value) { |
| 19422 | return _readValueToProps(value, { |
| 19423 | top: "y", |
| 19424 | right: "x", |
| 19425 | bottom: "y", |
| 19426 | left: "x" |
| 19427 | }); |
| 19428 | } |
| 19429 | function toTRBLCorners(value) { |
| 19430 | return _readValueToProps(value, [ |
| 19431 | "topLeft", |
| 19432 | "topRight", |
| 19433 | "bottomLeft", |
| 19434 | "bottomRight" |
| 19435 | ]); |
| 19436 | } |
| 19437 | function toPadding(value) { |
| 19438 | var obj = toTRBL(value); |
| 19439 | obj.width = obj.left + obj.right; |
| 19440 | obj.height = obj.top + obj.bottom; |
| 19441 | return obj; |
| 19442 | } |
| 19443 | function toFont(options, fallback) { |
| 19444 | options = options || {}; |
| 19445 | fallback = fallback || defaults.font; |
| 19446 | var size = valueOrDefault(options.size, fallback.size); |
| 19447 | if (typeof size === "string") size = parseInt(size, 10); |
| 19448 | var style = valueOrDefault(options.style, fallback.style); |
| 19449 | if (style && !("" + style).match(FONT_STYLE)) { |
| 19450 | console.warn('Invalid font style specified: "' + style + '"'); |
| 19451 | style = ""; |
| 19452 | } |
| 19453 | var font = { |
| 19454 | family: valueOrDefault(options.family, fallback.family), |
| 19455 | lineHeight: toLineHeight(valueOrDefault(options.lineHeight, fallback.lineHeight), size), |
| 19456 | size: size, |
| 19457 | style: style, |
| 19458 | weight: valueOrDefault(options.weight, fallback.weight), |
| 19459 | string: "" |
| 19460 | }; |
| 19461 | font.string = toFontString(font); |
| 19462 | return font; |
| 19463 | } |
| 19464 | function resolve(inputs, context, index, info) { |
| 19465 | var cacheable = true; |
| 19466 | var i, ilen, value; |
| 19467 | for(i = 0, ilen = inputs.length; i < ilen; ++i){ |
| 19468 | value = inputs[i]; |
| 19469 | if (value === undefined) continue; |
| 19470 | if (context !== undefined && typeof value === "function") { |
| 19471 | value = value(context); |
| 19472 | cacheable = false; |
| 19473 | } |
| 19474 | if (index !== undefined && isArray(value)) { |
| 19475 | value = value[index % value.length]; |
| 19476 | cacheable = false; |
| 19477 | } |
| 19478 | if (value !== undefined) { |
| 19479 | if (info && !cacheable) info.cacheable = false; |
| 19480 | return value; |
| 19481 | } |
| 19482 | } |
| 19483 | } |
| 19484 | function _addGrace(minmax, grace, beginAtZero) { |
| 19485 | var min = minmax.min, max = minmax.max; |
| 19486 | var change = toDimension(grace, (max - min) / 2); |
| 19487 | var keepZero = function(value, add) { |
| 19488 | return beginAtZero && value === 0 ? 0 : value + add; |
| 19489 | }; |
| 19490 | return { |
| 19491 | min: keepZero(min, -Math.abs(change)), |
| 19492 | max: keepZero(max, change) |
| 19493 | }; |
| 19494 | } |
| 19495 | function createContext(parentContext, context) { |
| 19496 | return Object.assign(Object.create(parentContext), context); |
| 19497 | } |
| 19498 | function _lookup(table, value, cmp) { |
| 19499 | cmp = cmp || function(index) { |
| 19500 | return table[index] < value; |
| 19501 | }; |
| 19502 | var hi = table.length - 1; |
| 19503 | var lo = 0; |
| 19504 | var mid; |
| 19505 | while(hi - lo > 1){ |
| 19506 | mid = lo + hi >> 1; |
| 19507 | if (cmp(mid)) lo = mid; |
| 19508 | else hi = mid; |
| 19509 | } |
| 19510 | return { |
| 19511 | lo: lo, |
| 19512 | hi: hi |
| 19513 | }; |
| 19514 | } |
| 19515 | var _lookupByKey = function(table, key, value) { |
| 19516 | return _lookup(table, value, function(index) { |
| 19517 | return table[index][key] < value; |
| 19518 | }); |
| 19519 | }; |
| 19520 | var _rlookupByKey = function(table, key, value) { |
| 19521 | return _lookup(table, value, function(index) { |
| 19522 | return table[index][key] >= value; |
| 19523 | }); |
| 19524 | }; |
| 19525 | function _filterBetween(values, min, max) { |
| 19526 | var start = 0; |
| 19527 | var end = values.length; |
| 19528 | while(start < end && values[start] < min)start++; |
| 19529 | while(end > start && values[end - 1] > max)end--; |
| 19530 | return start > 0 || end < values.length ? values.slice(start, end) : values; |
| 19531 | } |
| 19532 | var arrayEvents = [ |
| 19533 | "push", |
| 19534 | "pop", |
| 19535 | "shift", |
| 19536 | "splice", |
| 19537 | "unshift" |
| 19538 | ]; |
| 19539 | function listenArrayEvents(array, listener) { |
| 19540 | if (array._chartjs) { |
| 19541 | array._chartjs.listeners.push(listener); |
| 19542 | return; |
| 19543 | } |
| 19544 | Object.defineProperty(array, "_chartjs", { |
| 19545 | configurable: true, |
| 19546 | enumerable: false, |
| 19547 | value: { |
| 19548 | listeners: [ |
| 19549 | listener |
| 19550 | ] |
| 19551 | } |
| 19552 | }); |
| 19553 | arrayEvents.forEach(function(key) { |
| 19554 | var method = "_onData" + _capitalize(key); |
| 19555 | var base = array[key]; |
| 19556 | Object.defineProperty(array, key, { |
| 19557 | configurable: true, |
| 19558 | enumerable: false, |
| 19559 | value: function() { |
| 19560 | for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ |
| 19561 | args[_key] = arguments[_key]; |
| 19562 | } |
| 19563 | var res = base.apply(this, args); |
| 19564 | array._chartjs.listeners.forEach(function(object) { |
| 19565 | var _object; |
| 19566 | if (typeof object[method] === "function") (_object = object)[method].apply(_object, (0, _toConsumableArrayJsDefault.default)(args)); |
| 19567 | }); |
| 19568 | return res; |
| 19569 | } |
| 19570 | }); |
| 19571 | }); |
| 19572 | } |
| 19573 | function unlistenArrayEvents(array, listener) { |
| 19574 | var stub = array._chartjs; |
| 19575 | if (!stub) return; |
| 19576 | var listeners = stub.listeners; |
| 19577 | var index = listeners.indexOf(listener); |
| 19578 | if (index !== -1) listeners.splice(index, 1); |
| 19579 | if (listeners.length > 0) return; |
| 19580 | arrayEvents.forEach(function(key) { |
| 19581 | delete array[key]; |
| 19582 | }); |
| 19583 | delete array._chartjs; |
| 19584 | } |
| 19585 | function _arrayUnique(items) { |
| 19586 | var set2 = new Set(); |
| 19587 | var i, ilen; |
| 19588 | for(i = 0, ilen = items.length; i < ilen; ++i)set2.add(items[i]); |
| 19589 | if (set2.size === ilen) return items; |
| 19590 | return Array.from(set2); |
| 19591 | } |
| 19592 | function _createResolver(scopes) { |
| 19593 | var prefixes = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [ |
| 19594 | "" |
| 19595 | ], rootScopes = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : scopes, fallback = arguments.length > 3 ? arguments[3] : void 0, getTarget = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : function() { |
| 19596 | return scopes[0]; |
| 19597 | }; |
| 19598 | if (!defined(fallback)) fallback = _resolve("_fallback", scopes); |
| 19599 | var _obj; |
| 19600 | var cache = (_obj = {}, (0, _definePropertyJsDefault.default)(_obj, Symbol.toStringTag, "Object"), (0, _definePropertyJsDefault.default)(_obj, "_cacheable", true), (0, _definePropertyJsDefault.default)(_obj, "_scopes", scopes), (0, _definePropertyJsDefault.default)(_obj, "_rootScopes", rootScopes), (0, _definePropertyJsDefault.default)(_obj, "_fallback", fallback), (0, _definePropertyJsDefault.default)(_obj, "_getTarget", getTarget), (0, _definePropertyJsDefault.default)(_obj, "override", function(scope) { |
| 19601 | return _createResolver([ |
| 19602 | scope |
| 19603 | ].concat((0, _toConsumableArrayJsDefault.default)(scopes)), prefixes, rootScopes, fallback); |
| 19604 | }), _obj); |
| 19605 | return new Proxy(cache, { |
| 19606 | deleteProperty: function(target, prop) { |
| 19607 | delete target[prop]; |
| 19608 | delete target._keys; |
| 19609 | delete scopes[0][prop]; |
| 19610 | return true; |
| 19611 | }, |
| 19612 | get: function(target, prop) { |
| 19613 | return _cached(target, prop, function() { |
| 19614 | return _resolveWithPrefixes(prop, prefixes, scopes, target); |
| 19615 | }); |
| 19616 | }, |
| 19617 | getOwnPropertyDescriptor: function(target, prop) { |
| 19618 | return Reflect.getOwnPropertyDescriptor(target._scopes[0], prop); |
| 19619 | }, |
| 19620 | getPrototypeOf: function() { |
| 19621 | return Reflect.getPrototypeOf(scopes[0]); |
| 19622 | }, |
| 19623 | has: function(target, prop) { |
| 19624 | return getKeysFromAllScopes(target).includes(prop); |
| 19625 | }, |
| 19626 | ownKeys: function(target) { |
| 19627 | return getKeysFromAllScopes(target); |
| 19628 | }, |
| 19629 | set: function(target, prop, value) { |
| 19630 | var storage = target._storage || (target._storage = getTarget()); |
| 19631 | target[prop] = storage[prop] = value; |
| 19632 | delete target._keys; |
| 19633 | return true; |
| 19634 | } |
| 19635 | }); |
| 19636 | } |
| 19637 | function _attachContext(proxy, context, subProxy, descriptorDefaults) { |
| 19638 | var cache = { |
| 19639 | _cacheable: false, |
| 19640 | _proxy: proxy, |
| 19641 | _context: context, |
| 19642 | _subProxy: subProxy, |
| 19643 | _stack: new Set(), |
| 19644 | _descriptors: _descriptors(proxy, descriptorDefaults), |
| 19645 | setContext: function(ctx) { |
| 19646 | return _attachContext(proxy, ctx, subProxy, descriptorDefaults); |
| 19647 | }, |
| 19648 | override: function(scope) { |
| 19649 | return _attachContext(proxy.override(scope), context, subProxy, descriptorDefaults); |
| 19650 | } |
| 19651 | }; |
| 19652 | return new Proxy(cache, { |
| 19653 | deleteProperty: function(target, prop) { |
| 19654 | delete target[prop]; |
| 19655 | delete proxy[prop]; |
| 19656 | return true; |
| 19657 | }, |
| 19658 | get: function(target, prop, receiver) { |
| 19659 | return _cached(target, prop, function() { |
| 19660 | return _resolveWithContext(target, prop, receiver); |
| 19661 | }); |
| 19662 | }, |
| 19663 | getOwnPropertyDescriptor: function(target, prop) { |
| 19664 | return target._descriptors.allKeys ? Reflect.has(proxy, prop) ? { |
| 19665 | enumerable: true, |
| 19666 | configurable: true |
| 19667 | } : undefined : Reflect.getOwnPropertyDescriptor(proxy, prop); |
| 19668 | }, |
| 19669 | getPrototypeOf: function() { |
| 19670 | return Reflect.getPrototypeOf(proxy); |
| 19671 | }, |
| 19672 | has: function(target, prop) { |
| 19673 | return Reflect.has(proxy, prop); |
| 19674 | }, |
| 19675 | ownKeys: function() { |
| 19676 | return Reflect.ownKeys(proxy); |
| 19677 | }, |
| 19678 | set: function(target, prop, value) { |
| 19679 | proxy[prop] = value; |
| 19680 | delete target[prop]; |
| 19681 | return true; |
| 19682 | } |
| 19683 | }); |
| 19684 | } |
| 19685 | function _descriptors(proxy) { |
| 19686 | var defaults1 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : { |
| 19687 | scriptable: true, |
| 19688 | indexable: true |
| 19689 | }; |
| 19690 | var __scriptable = proxy._scriptable, _scriptable = __scriptable === void 0 ? defaults1.scriptable : __scriptable, __indexable = proxy._indexable, _indexable = __indexable === void 0 ? defaults1.indexable : __indexable, __allKeys = proxy._allKeys, _allKeys = __allKeys === void 0 ? defaults1.allKeys : __allKeys; |
| 19691 | return { |
| 19692 | allKeys: _allKeys, |
| 19693 | scriptable: _scriptable, |
| 19694 | indexable: _indexable, |
| 19695 | isScriptable: isFunction(_scriptable) ? _scriptable : function() { |
| 19696 | return _scriptable; |
| 19697 | }, |
| 19698 | isIndexable: isFunction(_indexable) ? _indexable : function() { |
| 19699 | return _indexable; |
| 19700 | } |
| 19701 | }; |
| 19702 | } |
| 19703 | var readKey = function(prefix, name) { |
| 19704 | return prefix ? prefix + _capitalize(name) : name; |
| 19705 | }; |
| 19706 | var needsSubResolver = function(prop, value) { |
| 19707 | return isObject(value) && prop !== "adapters" && (Object.getPrototypeOf(value) === null || value.constructor === Object); |
| 19708 | }; |
| 19709 | function _cached(target, prop, resolve1) { |
| 19710 | if (Object.prototype.hasOwnProperty.call(target, prop)) return target[prop]; |
| 19711 | var value = resolve1(); |
| 19712 | target[prop] = value; |
| 19713 | return value; |
| 19714 | } |
| 19715 | function _resolveWithContext(target, prop, receiver) { |
| 19716 | var _proxy = target._proxy, _context = target._context, _subProxy = target._subProxy, descriptors1 = target._descriptors; |
| 19717 | var value = _proxy[prop]; |
| 19718 | if (isFunction(value) && descriptors1.isScriptable(prop)) value = _resolveScriptable(prop, value, target, receiver); |
| 19719 | if (isArray(value) && value.length) value = _resolveArray(prop, value, target, descriptors1.isIndexable); |
| 19720 | if (needsSubResolver(prop, value)) value = _attachContext(value, _context, _subProxy && _subProxy[prop], descriptors1); |
| 19721 | return value; |
| 19722 | } |
| 19723 | function _resolveScriptable(prop, value, target, receiver) { |
| 19724 | var _proxy = target._proxy, _context = target._context, _subProxy = target._subProxy, _stack = target._stack; |
| 19725 | if (_stack.has(prop)) throw new Error("Recursion detected: " + Array.from(_stack).join("->") + "->" + prop); |
| 19726 | _stack.add(prop); |
| 19727 | value = value(_context, _subProxy || receiver); |
| 19728 | _stack.delete(prop); |
| 19729 | if (needsSubResolver(prop, value)) value = createSubResolver(_proxy._scopes, _proxy, prop, value); |
| 19730 | return value; |
| 19731 | } |
| 19732 | function _resolveArray(prop, value, target, isIndexable) { |
| 19733 | var _proxy = target._proxy, _context = target._context, _subProxy = target._subProxy, descriptors2 = target._descriptors; |
| 19734 | if (defined(_context.index) && isIndexable(prop)) value = value[_context.index % value.length]; |
| 19735 | else if (isObject(value[0])) { |
| 19736 | var arr = value; |
| 19737 | var scopes = _proxy._scopes.filter(function(s) { |
| 19738 | return s !== arr; |
| 19739 | }); |
| 19740 | value = []; |
| 19741 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 19742 | try { |
| 19743 | for(var _iterator = arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 19744 | var item = _step.value; |
| 19745 | var resolver = createSubResolver(scopes, _proxy, prop, item); |
| 19746 | value.push(_attachContext(resolver, _context, _subProxy && _subProxy[prop], descriptors2)); |
| 19747 | } |
| 19748 | } catch (err) { |
| 19749 | _didIteratorError = true; |
| 19750 | _iteratorError = err; |
| 19751 | } finally{ |
| 19752 | try { |
| 19753 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 19754 | _iterator.return(); |
| 19755 | } |
| 19756 | } finally{ |
| 19757 | if (_didIteratorError) { |
| 19758 | throw _iteratorError; |
| 19759 | } |
| 19760 | } |
| 19761 | } |
| 19762 | } |
| 19763 | return value; |
| 19764 | } |
| 19765 | function resolveFallback(fallback, prop, value) { |
| 19766 | return isFunction(fallback) ? fallback(prop, value) : fallback; |
| 19767 | } |
| 19768 | var getScope = function(key, parent) { |
| 19769 | return key === true ? parent : typeof key === "string" ? resolveObjectKey(parent, key) : undefined; |
| 19770 | }; |
| 19771 | function addScopes(set3, parentScopes, key, parentFallback, value) { |
| 19772 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 19773 | try { |
| 19774 | for(var _iterator = parentScopes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 19775 | var parent = _step.value; |
| 19776 | var scope = getScope(key, parent); |
| 19777 | if (scope) { |
| 19778 | set3.add(scope); |
| 19779 | var fallback = resolveFallback(scope._fallback, key, value); |
| 19780 | if (defined(fallback) && fallback !== key && fallback !== parentFallback) return fallback; |
| 19781 | } else if (scope === false && defined(parentFallback) && key !== parentFallback) return null; |
| 19782 | } |
| 19783 | } catch (err) { |
| 19784 | _didIteratorError = true; |
| 19785 | _iteratorError = err; |
| 19786 | } finally{ |
| 19787 | try { |
| 19788 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 19789 | _iterator.return(); |
| 19790 | } |
| 19791 | } finally{ |
| 19792 | if (_didIteratorError) { |
| 19793 | throw _iteratorError; |
| 19794 | } |
| 19795 | } |
| 19796 | } |
| 19797 | return false; |
| 19798 | } |
| 19799 | function createSubResolver(parentScopes, resolver, prop, value) { |
| 19800 | var rootScopes = resolver._rootScopes; |
| 19801 | var fallback = resolveFallback(resolver._fallback, prop, value); |
| 19802 | var allScopes = (0, _toConsumableArrayJsDefault.default)(parentScopes).concat((0, _toConsumableArrayJsDefault.default)(rootScopes)); |
| 19803 | var set4 = new Set(); |
| 19804 | set4.add(value); |
| 19805 | var key = addScopesFromKey(set4, allScopes, prop, fallback || prop, value); |
| 19806 | if (key === null) return false; |
| 19807 | if (defined(fallback) && fallback !== prop) { |
| 19808 | key = addScopesFromKey(set4, allScopes, fallback, key, value); |
| 19809 | if (key === null) return false; |
| 19810 | } |
| 19811 | return _createResolver(Array.from(set4), [ |
| 19812 | "" |
| 19813 | ], rootScopes, fallback, function() { |
| 19814 | return subGetTarget(resolver, prop, value); |
| 19815 | }); |
| 19816 | } |
| 19817 | function addScopesFromKey(set5, allScopes, key, fallback, item) { |
| 19818 | while(key)key = addScopes(set5, allScopes, key, fallback, item); |
| 19819 | return key; |
| 19820 | } |
| 19821 | function subGetTarget(resolver, prop, value) { |
| 19822 | var parent = resolver._getTarget(); |
| 19823 | if (!(prop in parent)) parent[prop] = {}; |
| 19824 | var target = parent[prop]; |
| 19825 | if (isArray(target) && isObject(value)) return value; |
| 19826 | return target; |
| 19827 | } |
| 19828 | function _resolveWithPrefixes(prop, prefixes, scopes, proxy) { |
| 19829 | var value; |
| 19830 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 19831 | try { |
| 19832 | for(var _iterator = prefixes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 19833 | var prefix = _step.value; |
| 19834 | value = _resolve(readKey(prefix, prop), scopes); |
| 19835 | if (defined(value)) return needsSubResolver(prop, value) ? createSubResolver(scopes, proxy, prop, value) : value; |
| 19836 | } |
| 19837 | } catch (err) { |
| 19838 | _didIteratorError = true; |
| 19839 | _iteratorError = err; |
| 19840 | } finally{ |
| 19841 | try { |
| 19842 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 19843 | _iterator.return(); |
| 19844 | } |
| 19845 | } finally{ |
| 19846 | if (_didIteratorError) { |
| 19847 | throw _iteratorError; |
| 19848 | } |
| 19849 | } |
| 19850 | } |
| 19851 | } |
| 19852 | function _resolve(key, scopes) { |
| 19853 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 19854 | try { |
| 19855 | for(var _iterator = scopes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 19856 | var scope = _step.value; |
| 19857 | if (!scope) continue; |
| 19858 | var value = scope[key]; |
| 19859 | if (defined(value)) return value; |
| 19860 | } |
| 19861 | } catch (err) { |
| 19862 | _didIteratorError = true; |
| 19863 | _iteratorError = err; |
| 19864 | } finally{ |
| 19865 | try { |
| 19866 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 19867 | _iterator.return(); |
| 19868 | } |
| 19869 | } finally{ |
| 19870 | if (_didIteratorError) { |
| 19871 | throw _iteratorError; |
| 19872 | } |
| 19873 | } |
| 19874 | } |
| 19875 | } |
| 19876 | function getKeysFromAllScopes(target) { |
| 19877 | var keys = target._keys; |
| 19878 | if (!keys) keys = target._keys = resolveKeysFromAllScopes(target._scopes); |
| 19879 | return keys; |
| 19880 | } |
| 19881 | function resolveKeysFromAllScopes(scopes) { |
| 19882 | var set6 = new Set(); |
| 19883 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined, _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; |
| 19884 | try { |
| 19885 | for(var _iterator = scopes[Symbol.iterator](), _step; !(_iteratorNormalCompletion1 = (_step = _iterator.next()).done); _iteratorNormalCompletion1 = true){ |
| 19886 | var scope = _step.value; |
| 19887 | try { |
| 19888 | for(var _iterator1 = Object.keys(scope).filter(function(k) { |
| 19889 | return !k.startsWith("_"); |
| 19890 | })[Symbol.iterator](), _step1; !(_iteratorNormalCompletion = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion = true){ |
| 19891 | var key = _step1.value; |
| 19892 | set6.add(key); |
| 19893 | } |
| 19894 | } catch (err) { |
| 19895 | _didIteratorError = true; |
| 19896 | _iteratorError = err; |
| 19897 | } finally{ |
| 19898 | try { |
| 19899 | if (!_iteratorNormalCompletion && _iterator1.return != null) { |
| 19900 | _iterator1.return(); |
| 19901 | } |
| 19902 | } finally{ |
| 19903 | if (_didIteratorError) { |
| 19904 | throw _iteratorError; |
| 19905 | } |
| 19906 | } |
| 19907 | } |
| 19908 | } |
| 19909 | } catch (err) { |
| 19910 | _didIteratorError1 = true; |
| 19911 | _iteratorError1 = err; |
| 19912 | } finally{ |
| 19913 | try { |
| 19914 | if (!_iteratorNormalCompletion1 && _iterator.return != null) { |
| 19915 | _iterator.return(); |
| 19916 | } |
| 19917 | } finally{ |
| 19918 | if (_didIteratorError1) { |
| 19919 | throw _iteratorError1; |
| 19920 | } |
| 19921 | } |
| 19922 | } |
| 19923 | return Array.from(set6); |
| 19924 | } |
| 19925 | function _parseObjectDataRadialScale(meta, data, start, count) { |
| 19926 | var iScale = meta.iScale; |
| 19927 | var __parsing = this._parsing, _key = __parsing.key, key = _key === void 0 ? "r" : _key; |
| 19928 | var parsed = new Array(count); |
| 19929 | var i, ilen, index, item; |
| 19930 | for(i = 0, ilen = count; i < ilen; ++i){ |
| 19931 | index = i + start; |
| 19932 | item = data[index]; |
| 19933 | parsed[i] = { |
| 19934 | r: iScale.parse(resolveObjectKey(item, key), index) |
| 19935 | }; |
| 19936 | } |
| 19937 | return parsed; |
| 19938 | } |
| 19939 | var EPSILON = Number.EPSILON || 1e-14; |
| 19940 | var getPoint = function(points, i) { |
| 19941 | return i < points.length && !points[i].skip && points[i]; |
| 19942 | }; |
| 19943 | var getValueAxis = function(indexAxis) { |
| 19944 | return indexAxis === "x" ? "y" : "x"; |
| 19945 | }; |
| 19946 | function splineCurve(firstPoint, middlePoint, afterPoint, t) { |
| 19947 | var previous = firstPoint.skip ? middlePoint : firstPoint; |
| 19948 | var current = middlePoint; |
| 19949 | var next = afterPoint.skip ? middlePoint : afterPoint; |
| 19950 | var d01 = distanceBetweenPoints(current, previous); |
| 19951 | var d12 = distanceBetweenPoints(next, current); |
| 19952 | var s01 = d01 / (d01 + d12); |
| 19953 | var s12 = d12 / (d01 + d12); |
| 19954 | s01 = isNaN(s01) ? 0 : s01; |
| 19955 | s12 = isNaN(s12) ? 0 : s12; |
| 19956 | var fa = t * s01; |
| 19957 | var fb = t * s12; |
| 19958 | return { |
| 19959 | previous: { |
| 19960 | x: current.x - fa * (next.x - previous.x), |
| 19961 | y: current.y - fa * (next.y - previous.y) |
| 19962 | }, |
| 19963 | next: { |
| 19964 | x: current.x + fb * (next.x - previous.x), |
| 19965 | y: current.y + fb * (next.y - previous.y) |
| 19966 | } |
| 19967 | }; |
| 19968 | } |
| 19969 | function monotoneAdjust(points, deltaK, mK) { |
| 19970 | var pointsLen = points.length; |
| 19971 | var alphaK, betaK, tauK, squaredMagnitude, pointCurrent; |
| 19972 | var pointAfter = getPoint(points, 0); |
| 19973 | for(var i = 0; i < pointsLen - 1; ++i){ |
| 19974 | pointCurrent = pointAfter; |
| 19975 | pointAfter = getPoint(points, i + 1); |
| 19976 | if (!pointCurrent || !pointAfter) continue; |
| 19977 | if (almostEquals(deltaK[i], 0, EPSILON)) { |
| 19978 | mK[i] = mK[i + 1] = 0; |
| 19979 | continue; |
| 19980 | } |
| 19981 | alphaK = mK[i] / deltaK[i]; |
| 19982 | betaK = mK[i + 1] / deltaK[i]; |
| 19983 | squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2); |
| 19984 | if (squaredMagnitude <= 9) continue; |
| 19985 | tauK = 3 / Math.sqrt(squaredMagnitude); |
| 19986 | mK[i] = alphaK * tauK * deltaK[i]; |
| 19987 | mK[i + 1] = betaK * tauK * deltaK[i]; |
| 19988 | } |
| 19989 | } |
| 19990 | function monotoneCompute(points, mK) { |
| 19991 | var indexAxis = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "x"; |
| 19992 | var valueAxis = getValueAxis(indexAxis); |
| 19993 | var pointsLen = points.length; |
| 19994 | var delta, pointBefore, pointCurrent; |
| 19995 | var pointAfter = getPoint(points, 0); |
| 19996 | for(var i = 0; i < pointsLen; ++i){ |
| 19997 | pointBefore = pointCurrent; |
| 19998 | pointCurrent = pointAfter; |
| 19999 | pointAfter = getPoint(points, i + 1); |
| 20000 | if (!pointCurrent) continue; |
| 20001 | var iPixel = pointCurrent[indexAxis]; |
| 20002 | var vPixel = pointCurrent[valueAxis]; |
| 20003 | if (pointBefore) { |
| 20004 | delta = (iPixel - pointBefore[indexAxis]) / 3; |
| 20005 | pointCurrent["cp1".concat(indexAxis)] = iPixel - delta; |
| 20006 | pointCurrent["cp1".concat(valueAxis)] = vPixel - delta * mK[i]; |
| 20007 | } |
| 20008 | if (pointAfter) { |
| 20009 | delta = (pointAfter[indexAxis] - iPixel) / 3; |
| 20010 | pointCurrent["cp2".concat(indexAxis)] = iPixel + delta; |
| 20011 | pointCurrent["cp2".concat(valueAxis)] = vPixel + delta * mK[i]; |
| 20012 | } |
| 20013 | } |
| 20014 | } |
| 20015 | function splineCurveMonotone(points) { |
| 20016 | var indexAxis = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "x"; |
| 20017 | var valueAxis = getValueAxis(indexAxis); |
| 20018 | var pointsLen = points.length; |
| 20019 | var deltaK = Array(pointsLen).fill(0); |
| 20020 | var mK = Array(pointsLen); |
| 20021 | var i, pointBefore, pointCurrent; |
| 20022 | var pointAfter = getPoint(points, 0); |
| 20023 | for(i = 0; i < pointsLen; ++i){ |
| 20024 | pointBefore = pointCurrent; |
| 20025 | pointCurrent = pointAfter; |
| 20026 | pointAfter = getPoint(points, i + 1); |
| 20027 | if (!pointCurrent) continue; |
| 20028 | if (pointAfter) { |
| 20029 | var slopeDelta = pointAfter[indexAxis] - pointCurrent[indexAxis]; |
| 20030 | deltaK[i] = slopeDelta !== 0 ? (pointAfter[valueAxis] - pointCurrent[valueAxis]) / slopeDelta : 0; |
| 20031 | } |
| 20032 | mK[i] = !pointBefore ? deltaK[i] : !pointAfter ? deltaK[i - 1] : sign(deltaK[i - 1]) !== sign(deltaK[i]) ? 0 : (deltaK[i - 1] + deltaK[i]) / 2; |
| 20033 | } |
| 20034 | monotoneAdjust(points, deltaK, mK); |
| 20035 | monotoneCompute(points, mK, indexAxis); |
| 20036 | } |
| 20037 | function capControlPoint(pt, min, max) { |
| 20038 | return Math.max(Math.min(pt, max), min); |
| 20039 | } |
| 20040 | function capBezierPoints(points, area) { |
| 20041 | var i, ilen, point, inArea, inAreaPrev; |
| 20042 | var inAreaNext = _isPointInArea(points[0], area); |
| 20043 | for(i = 0, ilen = points.length; i < ilen; ++i){ |
| 20044 | inAreaPrev = inArea; |
| 20045 | inArea = inAreaNext; |
| 20046 | inAreaNext = i < ilen - 1 && _isPointInArea(points[i + 1], area); |
| 20047 | if (!inArea) continue; |
| 20048 | point = points[i]; |
| 20049 | if (inAreaPrev) { |
| 20050 | point.cp1x = capControlPoint(point.cp1x, area.left, area.right); |
| 20051 | point.cp1y = capControlPoint(point.cp1y, area.top, area.bottom); |
| 20052 | } |
| 20053 | if (inAreaNext) { |
| 20054 | point.cp2x = capControlPoint(point.cp2x, area.left, area.right); |
| 20055 | point.cp2y = capControlPoint(point.cp2y, area.top, area.bottom); |
| 20056 | } |
| 20057 | } |
| 20058 | } |
| 20059 | function _updateBezierControlPoints(points, options, area, loop, indexAxis) { |
| 20060 | var i, ilen, point, controlPoints; |
| 20061 | if (options.spanGaps) points = points.filter(function(pt) { |
| 20062 | return !pt.skip; |
| 20063 | }); |
| 20064 | if (options.cubicInterpolationMode === "monotone") splineCurveMonotone(points, indexAxis); |
| 20065 | else { |
| 20066 | var prev = loop ? points[points.length - 1] : points[0]; |
| 20067 | for(i = 0, ilen = points.length; i < ilen; ++i){ |
| 20068 | point = points[i]; |
| 20069 | controlPoints = splineCurve(prev, point, points[Math.min(i + 1, ilen - (loop ? 0 : 1)) % ilen], options.tension); |
| 20070 | point.cp1x = controlPoints.previous.x; |
| 20071 | point.cp1y = controlPoints.previous.y; |
| 20072 | point.cp2x = controlPoints.next.x; |
| 20073 | point.cp2y = controlPoints.next.y; |
| 20074 | prev = point; |
| 20075 | } |
| 20076 | } |
| 20077 | if (options.capBezierPoints) capBezierPoints(points, area); |
| 20078 | } |
| 20079 | function _isDomSupported() { |
| 20080 | return typeof window !== "undefined" && typeof document !== "undefined"; |
| 20081 | } |
| 20082 | function _getParentNode(domNode) { |
| 20083 | var parent = domNode.parentNode; |
| 20084 | if (parent && parent.toString() === "[object ShadowRoot]") parent = parent.host; |
| 20085 | return parent; |
| 20086 | } |
| 20087 | function parseMaxStyle(styleValue, node, parentProperty) { |
| 20088 | var valueInPixels; |
| 20089 | if (typeof styleValue === "string") { |
| 20090 | valueInPixels = parseInt(styleValue, 10); |
| 20091 | if (styleValue.indexOf("%") !== -1) valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty]; |
| 20092 | } else valueInPixels = styleValue; |
| 20093 | return valueInPixels; |
| 20094 | } |
| 20095 | var getComputedStyle = function(element) { |
| 20096 | return window.getComputedStyle(element, null); |
| 20097 | }; |
| 20098 | function getStyle(el, property) { |
| 20099 | return getComputedStyle(el).getPropertyValue(property); |
| 20100 | } |
| 20101 | var positions = [ |
| 20102 | "top", |
| 20103 | "right", |
| 20104 | "bottom", |
| 20105 | "left" |
| 20106 | ]; |
| 20107 | function getPositionedStyle(styles, style, suffix) { |
| 20108 | var result = {}; |
| 20109 | suffix = suffix ? "-" + suffix : ""; |
| 20110 | for(var i = 0; i < 4; i++){ |
| 20111 | var pos = positions[i]; |
| 20112 | result[pos] = parseFloat(styles[style + "-" + pos + suffix]) || 0; |
| 20113 | } |
| 20114 | result.width = result.left + result.right; |
| 20115 | result.height = result.top + result.bottom; |
| 20116 | return result; |
| 20117 | } |
| 20118 | var useOffsetPos = function(x, y, target) { |
| 20119 | return (x > 0 || y > 0) && (!target || !target.shadowRoot); |
| 20120 | }; |
| 20121 | function getCanvasPosition(e, canvas) { |
| 20122 | var touches = e.touches; |
| 20123 | var source = touches && touches.length ? touches[0] : e; |
| 20124 | var offsetX = source.offsetX, offsetY = source.offsetY; |
| 20125 | var box = false; |
| 20126 | var x, y; |
| 20127 | if (useOffsetPos(offsetX, offsetY, e.target)) { |
| 20128 | x = offsetX; |
| 20129 | y = offsetY; |
| 20130 | } else { |
| 20131 | var rect = canvas.getBoundingClientRect(); |
| 20132 | x = source.clientX - rect.left; |
| 20133 | y = source.clientY - rect.top; |
| 20134 | box = true; |
| 20135 | } |
| 20136 | return { |
| 20137 | x: x, |
| 20138 | y: y, |
| 20139 | box: box |
| 20140 | }; |
| 20141 | } |
| 20142 | function getRelativePosition(evt, chart) { |
| 20143 | if ("native" in evt) return evt; |
| 20144 | var canvas = chart.canvas, currentDevicePixelRatio = chart.currentDevicePixelRatio; |
| 20145 | var style = getComputedStyle(canvas); |
| 20146 | var borderBox = style.boxSizing === "border-box"; |
| 20147 | var paddings = getPositionedStyle(style, "padding"); |
| 20148 | var borders = getPositionedStyle(style, "border", "width"); |
| 20149 | var ref = getCanvasPosition(evt, canvas), x = ref.x, y = ref.y, box = ref.box; |
| 20150 | var xOffset = paddings.left + (box && borders.left); |
| 20151 | var yOffset = paddings.top + (box && borders.top); |
| 20152 | var width = chart.width, height = chart.height; |
| 20153 | if (borderBox) { |
| 20154 | width -= paddings.width + borders.width; |
| 20155 | height -= paddings.height + borders.height; |
| 20156 | } |
| 20157 | return { |
| 20158 | x: Math.round((x - xOffset) / width * canvas.width / currentDevicePixelRatio), |
| 20159 | y: Math.round((y - yOffset) / height * canvas.height / currentDevicePixelRatio) |
| 20160 | }; |
| 20161 | } |
| 20162 | function getContainerSize(canvas, width, height) { |
| 20163 | var maxWidth, maxHeight; |
| 20164 | if (width === undefined || height === undefined) { |
| 20165 | var container = _getParentNode(canvas); |
| 20166 | if (!container) { |
| 20167 | width = canvas.clientWidth; |
| 20168 | height = canvas.clientHeight; |
| 20169 | } else { |
| 20170 | var rect = container.getBoundingClientRect(); |
| 20171 | var containerStyle = getComputedStyle(container); |
| 20172 | var containerBorder = getPositionedStyle(containerStyle, "border", "width"); |
| 20173 | var containerPadding = getPositionedStyle(containerStyle, "padding"); |
| 20174 | width = rect.width - containerPadding.width - containerBorder.width; |
| 20175 | height = rect.height - containerPadding.height - containerBorder.height; |
| 20176 | maxWidth = parseMaxStyle(containerStyle.maxWidth, container, "clientWidth"); |
| 20177 | maxHeight = parseMaxStyle(containerStyle.maxHeight, container, "clientHeight"); |
| 20178 | } |
| 20179 | } |
| 20180 | return { |
| 20181 | width: width, |
| 20182 | height: height, |
| 20183 | maxWidth: maxWidth || INFINITY, |
| 20184 | maxHeight: maxHeight || INFINITY |
| 20185 | }; |
| 20186 | } |
| 20187 | var round1 = function(v) { |
| 20188 | return Math.round(v * 10) / 10; |
| 20189 | }; |
| 20190 | function getMaximumSize(canvas, bbWidth, bbHeight, aspectRatio) { |
| 20191 | var style = getComputedStyle(canvas); |
| 20192 | var margins = getPositionedStyle(style, "margin"); |
| 20193 | var maxWidth = parseMaxStyle(style.maxWidth, canvas, "clientWidth") || INFINITY; |
| 20194 | var maxHeight = parseMaxStyle(style.maxHeight, canvas, "clientHeight") || INFINITY; |
| 20195 | var containerSize = getContainerSize(canvas, bbWidth, bbHeight); |
| 20196 | var width = containerSize.width, height = containerSize.height; |
| 20197 | if (style.boxSizing === "content-box") { |
| 20198 | var borders = getPositionedStyle(style, "border", "width"); |
| 20199 | var paddings = getPositionedStyle(style, "padding"); |
| 20200 | width -= paddings.width + borders.width; |
| 20201 | height -= paddings.height + borders.height; |
| 20202 | } |
| 20203 | width = Math.max(0, width - margins.width); |
| 20204 | height = Math.max(0, aspectRatio ? Math.floor(width / aspectRatio) : height - margins.height); |
| 20205 | width = round1(Math.min(width, maxWidth, containerSize.maxWidth)); |
| 20206 | height = round1(Math.min(height, maxHeight, containerSize.maxHeight)); |
| 20207 | if (width && !height) height = round1(width / 2); |
| 20208 | return { |
| 20209 | width: width, |
| 20210 | height: height |
| 20211 | }; |
| 20212 | } |
| 20213 | function retinaScale(chart, forceRatio, forceStyle) { |
| 20214 | var pixelRatio = forceRatio || 1; |
| 20215 | var deviceHeight = Math.floor(chart.height * pixelRatio); |
| 20216 | var deviceWidth = Math.floor(chart.width * pixelRatio); |
| 20217 | chart.height = deviceHeight / pixelRatio; |
| 20218 | chart.width = deviceWidth / pixelRatio; |
| 20219 | var canvas = chart.canvas; |
| 20220 | if (canvas.style && (forceStyle || !canvas.style.height && !canvas.style.width)) { |
| 20221 | canvas.style.height = "".concat(chart.height, "px"); |
| 20222 | canvas.style.width = "".concat(chart.width, "px"); |
| 20223 | } |
| 20224 | if (chart.currentDevicePixelRatio !== pixelRatio || canvas.height !== deviceHeight || canvas.width !== deviceWidth) { |
| 20225 | chart.currentDevicePixelRatio = pixelRatio; |
| 20226 | canvas.height = deviceHeight; |
| 20227 | canvas.width = deviceWidth; |
| 20228 | chart.ctx.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0); |
| 20229 | return true; |
| 20230 | } |
| 20231 | return false; |
| 20232 | } |
| 20233 | var supportsEventListenerOptions = function() { |
| 20234 | var passiveSupported = false; |
| 20235 | try { |
| 20236 | var options = { |
| 20237 | get passive () { |
| 20238 | passiveSupported = true; |
| 20239 | return false; |
| 20240 | } |
| 20241 | }; |
| 20242 | window.addEventListener("test", null, options); |
| 20243 | window.removeEventListener("test", null, options); |
| 20244 | } catch (e) {} |
| 20245 | return passiveSupported; |
| 20246 | }(); |
| 20247 | function readUsedSize(element, property) { |
| 20248 | var value = getStyle(element, property); |
| 20249 | var matches = value && value.match(/^(\d+)(\.\d+)?px$/); |
| 20250 | return matches ? +matches[1] : undefined; |
| 20251 | } |
| 20252 | function _pointInLine(p1, p2, t, mode) { |
| 20253 | return { |
| 20254 | x: p1.x + t * (p2.x - p1.x), |
| 20255 | y: p1.y + t * (p2.y - p1.y) |
| 20256 | }; |
| 20257 | } |
| 20258 | function _steppedInterpolation(p1, p2, t, mode) { |
| 20259 | return { |
| 20260 | x: p1.x + t * (p2.x - p1.x), |
| 20261 | y: mode === "middle" ? t < 0.5 ? p1.y : p2.y : mode === "after" ? t < 1 ? p1.y : p2.y : t > 0 ? p2.y : p1.y |
| 20262 | }; |
| 20263 | } |
| 20264 | function _bezierInterpolation(p1, p2, t, mode) { |
| 20265 | var cp1 = { |
| 20266 | x: p1.cp2x, |
| 20267 | y: p1.cp2y |
| 20268 | }; |
| 20269 | var cp2 = { |
| 20270 | x: p2.cp1x, |
| 20271 | y: p2.cp1y |
| 20272 | }; |
| 20273 | var a = _pointInLine(p1, cp1, t); |
| 20274 | var b = _pointInLine(cp1, cp2, t); |
| 20275 | var c = _pointInLine(cp2, p2, t); |
| 20276 | var d = _pointInLine(a, b, t); |
| 20277 | var e = _pointInLine(b, c, t); |
| 20278 | return _pointInLine(d, e, t); |
| 20279 | } |
| 20280 | var intlCache = new Map(); |
| 20281 | function getNumberFormat(locale, options) { |
| 20282 | options = options || {}; |
| 20283 | var cacheKey = locale + JSON.stringify(options); |
| 20284 | var formatter = intlCache.get(cacheKey); |
| 20285 | if (!formatter) { |
| 20286 | formatter = new Intl.NumberFormat(locale, options); |
| 20287 | intlCache.set(cacheKey, formatter); |
| 20288 | } |
| 20289 | return formatter; |
| 20290 | } |
| 20291 | function formatNumber(num, locale, options) { |
| 20292 | return getNumberFormat(locale, options).format(num); |
| 20293 | } |
| 20294 | var getRightToLeftAdapter = function getRightToLeftAdapter(rectX, width) { |
| 20295 | return { |
| 20296 | x: function(x) { |
| 20297 | return rectX + rectX + width - x; |
| 20298 | }, |
| 20299 | setWidth: function(w) { |
| 20300 | width = w; |
| 20301 | }, |
| 20302 | textAlign: function(align) { |
| 20303 | if (align === "center") return align; |
| 20304 | return align === "right" ? "left" : "right"; |
| 20305 | }, |
| 20306 | xPlus: function(x, value) { |
| 20307 | return x - value; |
| 20308 | }, |
| 20309 | leftForLtr: function(x, itemWidth) { |
| 20310 | return x - itemWidth; |
| 20311 | } |
| 20312 | }; |
| 20313 | }; |
| 20314 | var getLeftToRightAdapter = function getLeftToRightAdapter() { |
| 20315 | return { |
| 20316 | x: function(x) { |
| 20317 | return x; |
| 20318 | }, |
| 20319 | setWidth: function(w) {}, |
| 20320 | textAlign: function(align) { |
| 20321 | return align; |
| 20322 | }, |
| 20323 | xPlus: function(x, value) { |
| 20324 | return x + value; |
| 20325 | }, |
| 20326 | leftForLtr: function(x, _itemWidth) { |
| 20327 | return x; |
| 20328 | } |
| 20329 | }; |
| 20330 | }; |
| 20331 | function getRtlAdapter(rtl, rectX, width) { |
| 20332 | return rtl ? getRightToLeftAdapter(rectX, width) : getLeftToRightAdapter(); |
| 20333 | } |
| 20334 | function overrideTextDirection(ctx, direction) { |
| 20335 | var style, original; |
| 20336 | if (direction === "ltr" || direction === "rtl") { |
| 20337 | style = ctx.canvas.style; |
| 20338 | original = [ |
| 20339 | style.getPropertyValue("direction"), |
| 20340 | style.getPropertyPriority("direction"), |
| 20341 | ]; |
| 20342 | style.setProperty("direction", direction, "important"); |
| 20343 | ctx.prevTextDirection = original; |
| 20344 | } |
| 20345 | } |
| 20346 | function restoreTextDirection(ctx, original) { |
| 20347 | if (original !== undefined) { |
| 20348 | delete ctx.prevTextDirection; |
| 20349 | ctx.canvas.style.setProperty("direction", original[0], original[1]); |
| 20350 | } |
| 20351 | } |
| 20352 | function propertyFn(property) { |
| 20353 | if (property === "angle") return { |
| 20354 | between: _angleBetween, |
| 20355 | compare: _angleDiff, |
| 20356 | normalize: _normalizeAngle |
| 20357 | }; |
| 20358 | return { |
| 20359 | between: _isBetween, |
| 20360 | compare: function(a, b) { |
| 20361 | return a - b; |
| 20362 | }, |
| 20363 | normalize: function(x) { |
| 20364 | return x; |
| 20365 | } |
| 20366 | }; |
| 20367 | } |
| 20368 | function normalizeSegment(param) { |
| 20369 | var start = param.start, end = param.end, count = param.count, loop = param.loop, style = param.style; |
| 20370 | return { |
| 20371 | start: start % count, |
| 20372 | end: end % count, |
| 20373 | loop: loop && (end - start + 1) % count === 0, |
| 20374 | style: style |
| 20375 | }; |
| 20376 | } |
| 20377 | function getSegment(segment, points, bounds) { |
| 20378 | var property = bounds.property, startBound = bounds.start, endBound = bounds.end; |
| 20379 | var ref = propertyFn(property), between = ref.between, normalize = ref.normalize; |
| 20380 | var count = points.length; |
| 20381 | var start = segment.start, end = segment.end, loop = segment.loop; |
| 20382 | var i, ilen; |
| 20383 | if (loop) { |
| 20384 | start += count; |
| 20385 | end += count; |
| 20386 | for(i = 0, ilen = count; i < ilen; ++i){ |
| 20387 | if (!between(normalize(points[start % count][property]), startBound, endBound)) break; |
| 20388 | start--; |
| 20389 | end--; |
| 20390 | } |
| 20391 | start %= count; |
| 20392 | end %= count; |
| 20393 | } |
| 20394 | if (end < start) end += count; |
| 20395 | return { |
| 20396 | start: start, |
| 20397 | end: end, |
| 20398 | loop: loop, |
| 20399 | style: segment.style |
| 20400 | }; |
| 20401 | } |
| 20402 | function _boundSegment(segment, points, bounds) { |
| 20403 | if (!bounds) return [ |
| 20404 | segment |
| 20405 | ]; |
| 20406 | var property = bounds.property, startBound = bounds.start, endBound = bounds.end; |
| 20407 | var count = points.length; |
| 20408 | var ref = propertyFn(property), compare = ref.compare, between = ref.between, normalize = ref.normalize; |
| 20409 | var ref1 = getSegment(segment, points, bounds), start = ref1.start, end = ref1.end, loop = ref1.loop, style = ref1.style; |
| 20410 | var result = []; |
| 20411 | var inside = false; |
| 20412 | var subStart = null; |
| 20413 | var value, point, prevValue; |
| 20414 | var startIsBefore = function() { |
| 20415 | return between(startBound, prevValue, value) && compare(startBound, prevValue) !== 0; |
| 20416 | }; |
| 20417 | var endIsBefore = function() { |
| 20418 | return compare(endBound, value) === 0 || between(endBound, prevValue, value); |
| 20419 | }; |
| 20420 | var shouldStart = function() { |
| 20421 | return inside || startIsBefore(); |
| 20422 | }; |
| 20423 | var shouldStop = function() { |
| 20424 | return !inside || endIsBefore(); |
| 20425 | }; |
| 20426 | for(var i = start, prev = start; i <= end; ++i){ |
| 20427 | point = points[i % count]; |
| 20428 | if (point.skip) continue; |
| 20429 | value = normalize(point[property]); |
| 20430 | if (value === prevValue) continue; |
| 20431 | inside = between(value, startBound, endBound); |
| 20432 | if (subStart === null && shouldStart()) subStart = compare(value, startBound) === 0 ? i : prev; |
| 20433 | if (subStart !== null && shouldStop()) { |
| 20434 | result.push(normalizeSegment({ |
| 20435 | start: subStart, |
| 20436 | end: i, |
| 20437 | loop: loop, |
| 20438 | count: count, |
| 20439 | style: style |
| 20440 | })); |
| 20441 | subStart = null; |
| 20442 | } |
| 20443 | prev = i; |
| 20444 | prevValue = value; |
| 20445 | } |
| 20446 | if (subStart !== null) result.push(normalizeSegment({ |
| 20447 | start: subStart, |
| 20448 | end: end, |
| 20449 | loop: loop, |
| 20450 | count: count, |
| 20451 | style: style |
| 20452 | })); |
| 20453 | return result; |
| 20454 | } |
| 20455 | function _boundSegments(line, bounds) { |
| 20456 | var result = []; |
| 20457 | var segments = line.segments; |
| 20458 | for(var i = 0; i < segments.length; i++){ |
| 20459 | var _result; |
| 20460 | var sub = _boundSegment(segments[i], line.points, bounds); |
| 20461 | if (sub.length) (_result = result).push.apply(_result, (0, _toConsumableArrayJsDefault.default)(sub)); |
| 20462 | } |
| 20463 | return result; |
| 20464 | } |
| 20465 | function findStartAndEnd(points, count, loop, spanGaps) { |
| 20466 | var start = 0; |
| 20467 | var end = count - 1; |
| 20468 | if (loop && !spanGaps) while(start < count && !points[start].skip)start++; |
| 20469 | while(start < count && points[start].skip)start++; |
| 20470 | start %= count; |
| 20471 | if (loop) end += start; |
| 20472 | while(end > start && points[end % count].skip)end--; |
| 20473 | end %= count; |
| 20474 | return { |
| 20475 | start: start, |
| 20476 | end: end |
| 20477 | }; |
| 20478 | } |
| 20479 | function solidSegments(points, start, max, loop) { |
| 20480 | var count = points.length; |
| 20481 | var result = []; |
| 20482 | var last = start; |
| 20483 | var prev = points[start]; |
| 20484 | var end; |
| 20485 | for(end = start + 1; end <= max; ++end){ |
| 20486 | var cur = points[end % count]; |
| 20487 | if (cur.skip || cur.stop) { |
| 20488 | if (!prev.skip) { |
| 20489 | loop = false; |
| 20490 | result.push({ |
| 20491 | start: start % count, |
| 20492 | end: (end - 1) % count, |
| 20493 | loop: loop |
| 20494 | }); |
| 20495 | start = last = cur.stop ? end : null; |
| 20496 | } |
| 20497 | } else { |
| 20498 | last = end; |
| 20499 | if (prev.skip) start = end; |
| 20500 | } |
| 20501 | prev = cur; |
| 20502 | } |
| 20503 | if (last !== null) result.push({ |
| 20504 | start: start % count, |
| 20505 | end: last % count, |
| 20506 | loop: loop |
| 20507 | }); |
| 20508 | return result; |
| 20509 | } |
| 20510 | function _computeSegments(line, segmentOptions) { |
| 20511 | var points = line.points; |
| 20512 | var spanGaps = line.options.spanGaps; |
| 20513 | var count = points.length; |
| 20514 | if (!count) return []; |
| 20515 | var loop = !!line._loop; |
| 20516 | var ref = findStartAndEnd(points, count, loop, spanGaps), start = ref.start, end = ref.end; |
| 20517 | if (spanGaps === true) return splitByStyles(line, [ |
| 20518 | { |
| 20519 | start: start, |
| 20520 | end: end, |
| 20521 | loop: loop |
| 20522 | } |
| 20523 | ], points, segmentOptions); |
| 20524 | var max = end < start ? end + count : end; |
| 20525 | var completeLoop = !!line._fullLoop && start === 0 && end === count - 1; |
| 20526 | return splitByStyles(line, solidSegments(points, start, max, completeLoop), points, segmentOptions); |
| 20527 | } |
| 20528 | function splitByStyles(line, segments, points, segmentOptions) { |
| 20529 | if (!segmentOptions || !segmentOptions.setContext || !points) return segments; |
| 20530 | return doSplitByStyles(line, segments, points, segmentOptions); |
| 20531 | } |
| 20532 | function doSplitByStyles(line, segments, points, segmentOptions) { |
| 20533 | var chartContext = line._chart.getContext(); |
| 20534 | var baseStyle = readStyle(line.options); |
| 20535 | var datasetIndex = line._datasetIndex, spanGaps = line.options.spanGaps; |
| 20536 | var count = points.length; |
| 20537 | var result = []; |
| 20538 | var prevStyle = baseStyle; |
| 20539 | var start = segments[0].start; |
| 20540 | var i = start; |
| 20541 | function addStyle(s, e, l, st) { |
| 20542 | var dir = spanGaps ? -1 : 1; |
| 20543 | if (s === e) return; |
| 20544 | s += count; |
| 20545 | while(points[s % count].skip)s -= dir; |
| 20546 | while(points[e % count].skip)e += dir; |
| 20547 | if (s % count !== e % count) { |
| 20548 | result.push({ |
| 20549 | start: s % count, |
| 20550 | end: e % count, |
| 20551 | loop: l, |
| 20552 | style: st |
| 20553 | }); |
| 20554 | prevStyle = st; |
| 20555 | start = e % count; |
| 20556 | } |
| 20557 | } |
| 20558 | var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; |
| 20559 | try { |
| 20560 | for(var _iterator = segments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ |
| 20561 | var segment = _step.value; |
| 20562 | start = spanGaps ? start : segment.start; |
| 20563 | var prev = points[start % count]; |
| 20564 | var style = void 0; |
| 20565 | for(i = start + 1; i <= segment.end; i++){ |
| 20566 | var pt = points[i % count]; |
| 20567 | style = readStyle(segmentOptions.setContext(createContext(chartContext, { |
| 20568 | type: "segment", |
| 20569 | p0: prev, |
| 20570 | p1: pt, |
| 20571 | p0DataIndex: (i - 1) % count, |
| 20572 | p1DataIndex: i % count, |
| 20573 | datasetIndex: datasetIndex |
| 20574 | }))); |
| 20575 | if (styleChanged(style, prevStyle)) addStyle(start, i - 1, segment.loop, prevStyle); |
| 20576 | prev = pt; |
| 20577 | prevStyle = style; |
| 20578 | } |
| 20579 | if (start < i - 1) addStyle(start, i - 1, segment.loop, prevStyle); |
| 20580 | } |
| 20581 | } catch (err) { |
| 20582 | _didIteratorError = true; |
| 20583 | _iteratorError = err; |
| 20584 | } finally{ |
| 20585 | try { |
| 20586 | if (!_iteratorNormalCompletion && _iterator.return != null) { |
| 20587 | _iterator.return(); |
| 20588 | } |
| 20589 | } finally{ |
| 20590 | if (_didIteratorError) { |
| 20591 | throw _iteratorError; |
| 20592 | } |
| 20593 | } |
| 20594 | } |
| 20595 | return result; |
| 20596 | } |
| 20597 | function readStyle(options) { |
| 20598 | return { |
| 20599 | backgroundColor: options.backgroundColor, |
| 20600 | borderCapStyle: options.borderCapStyle, |
| 20601 | borderDash: options.borderDash, |
| 20602 | borderDashOffset: options.borderDashOffset, |
| 20603 | borderJoinStyle: options.borderJoinStyle, |
| 20604 | borderWidth: options.borderWidth, |
| 20605 | borderColor: options.borderColor |
| 20606 | }; |
| 20607 | } |
| 20608 | function styleChanged(style, prevStyle) { |
| 20609 | return prevStyle && JSON.stringify(style) !== JSON.stringify(prevStyle); |
| 20610 | } |
| 20611 | |
| 20612 | },{"@swc/helpers/lib/_class_call_check.js":"gNxF8","@swc/helpers/lib/_create_class.js":"iyoaN","@swc/helpers/lib/_define_property.js":"6IXzf","@swc/helpers/lib/_to_consumable_array.js":"cccKv","@swc/helpers/lib/_type_of.js":"9FF45","@parcel/transformer-js/src/esmodule-helpers.js":"jIm8e"}]},["kILFo"], "kILFo", "parcelRequirec571") |
| 20613 | |
| 20614 | //# sourceMappingURL=dashboard_widget.js.map |
| 20615 |