helpers.segment.js 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432
  1. /*!
  2. * Chart.js v3.2.1
  3. * https://www.chartjs.org
  4. * (c) 2021 Chart.js Contributors
  5. * Released under the MIT License
  6. */
  7. function fontString(pixelSize, fontStyle, fontFamily) {
  8. return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
  9. }
  10. const requestAnimFrame = (function() {
  11. if (typeof window === 'undefined') {
  12. return function(callback) {
  13. return callback();
  14. };
  15. }
  16. return window.requestAnimationFrame;
  17. }());
  18. function throttled(fn, thisArg, updateFn) {
  19. const updateArgs = updateFn || ((args) => Array.prototype.slice.call(args));
  20. let ticking = false;
  21. let args = [];
  22. return function(...rest) {
  23. args = updateArgs(rest);
  24. if (!ticking) {
  25. ticking = true;
  26. requestAnimFrame.call(window, () => {
  27. ticking = false;
  28. fn.apply(thisArg, args);
  29. });
  30. }
  31. };
  32. }
  33. function debounce(fn, delay) {
  34. let timeout;
  35. return function() {
  36. if (delay) {
  37. clearTimeout(timeout);
  38. timeout = setTimeout(fn, delay);
  39. } else {
  40. fn();
  41. }
  42. return delay;
  43. };
  44. }
  45. const _toLeftRightCenter = (align) => align === 'start' ? 'left' : align === 'end' ? 'right' : 'center';
  46. const _alignStartEnd = (align, start, end) => align === 'start' ? start : align === 'end' ? end : (start + end) / 2;
  47. const _textX = (align, left, right) => align === 'right' ? right : align === 'center' ? (left + right) / 2 : left;
  48. function noop() {}
  49. const uid = (function() {
  50. let id = 0;
  51. return function() {
  52. return id++;
  53. };
  54. }());
  55. function isNullOrUndef(value) {
  56. return value === null || typeof value === 'undefined';
  57. }
  58. function isArray(value) {
  59. if (Array.isArray && Array.isArray(value)) {
  60. return true;
  61. }
  62. const type = Object.prototype.toString.call(value);
  63. if (type.substr(0, 7) === '[object' && type.substr(-6) === 'Array]') {
  64. return true;
  65. }
  66. return false;
  67. }
  68. function isObject(value) {
  69. return value !== null && Object.prototype.toString.call(value) === '[object Object]';
  70. }
  71. const isNumberFinite = (value) => (typeof value === 'number' || value instanceof Number) && isFinite(+value);
  72. function finiteOrDefault(value, defaultValue) {
  73. return isNumberFinite(value) ? value : defaultValue;
  74. }
  75. function valueOrDefault(value, defaultValue) {
  76. return typeof value === 'undefined' ? defaultValue : value;
  77. }
  78. const toPercentage = (value, dimension) =>
  79. typeof value === 'string' && value.endsWith('%') ?
  80. parseFloat(value) / 100
  81. : value / dimension;
  82. const toDimension = (value, dimension) =>
  83. typeof value === 'string' && value.endsWith('%') ?
  84. parseFloat(value) / 100 * dimension
  85. : +value;
  86. function callback(fn, args, thisArg) {
  87. if (fn && typeof fn.call === 'function') {
  88. return fn.apply(thisArg, args);
  89. }
  90. }
  91. function each(loopable, fn, thisArg, reverse) {
  92. let i, len, keys;
  93. if (isArray(loopable)) {
  94. len = loopable.length;
  95. if (reverse) {
  96. for (i = len - 1; i >= 0; i--) {
  97. fn.call(thisArg, loopable[i], i);
  98. }
  99. } else {
  100. for (i = 0; i < len; i++) {
  101. fn.call(thisArg, loopable[i], i);
  102. }
  103. }
  104. } else if (isObject(loopable)) {
  105. keys = Object.keys(loopable);
  106. len = keys.length;
  107. for (i = 0; i < len; i++) {
  108. fn.call(thisArg, loopable[keys[i]], keys[i]);
  109. }
  110. }
  111. }
  112. function _elementsEqual(a0, a1) {
  113. let i, ilen, v0, v1;
  114. if (!a0 || !a1 || a0.length !== a1.length) {
  115. return false;
  116. }
  117. for (i = 0, ilen = a0.length; i < ilen; ++i) {
  118. v0 = a0[i];
  119. v1 = a1[i];
  120. if (v0.datasetIndex !== v1.datasetIndex || v0.index !== v1.index) {
  121. return false;
  122. }
  123. }
  124. return true;
  125. }
  126. function clone$1(source) {
  127. if (isArray(source)) {
  128. return source.map(clone$1);
  129. }
  130. if (isObject(source)) {
  131. const target = Object.create(null);
  132. const keys = Object.keys(source);
  133. const klen = keys.length;
  134. let k = 0;
  135. for (; k < klen; ++k) {
  136. target[keys[k]] = clone$1(source[keys[k]]);
  137. }
  138. return target;
  139. }
  140. return source;
  141. }
  142. function isValidKey(key) {
  143. return ['__proto__', 'prototype', 'constructor'].indexOf(key) === -1;
  144. }
  145. function _merger(key, target, source, options) {
  146. if (!isValidKey(key)) {
  147. return;
  148. }
  149. const tval = target[key];
  150. const sval = source[key];
  151. if (isObject(tval) && isObject(sval)) {
  152. merge(tval, sval, options);
  153. } else {
  154. target[key] = clone$1(sval);
  155. }
  156. }
  157. function merge(target, source, options) {
  158. const sources = isArray(source) ? source : [source];
  159. const ilen = sources.length;
  160. if (!isObject(target)) {
  161. return target;
  162. }
  163. options = options || {};
  164. const merger = options.merger || _merger;
  165. for (let i = 0; i < ilen; ++i) {
  166. source = sources[i];
  167. if (!isObject(source)) {
  168. continue;
  169. }
  170. const keys = Object.keys(source);
  171. for (let k = 0, klen = keys.length; k < klen; ++k) {
  172. merger(keys[k], target, source, options);
  173. }
  174. }
  175. return target;
  176. }
  177. function mergeIf(target, source) {
  178. return merge(target, source, {merger: _mergerIf});
  179. }
  180. function _mergerIf(key, target, source) {
  181. if (!isValidKey(key)) {
  182. return;
  183. }
  184. const tval = target[key];
  185. const sval = source[key];
  186. if (isObject(tval) && isObject(sval)) {
  187. mergeIf(tval, sval);
  188. } else if (!Object.prototype.hasOwnProperty.call(target, key)) {
  189. target[key] = clone$1(sval);
  190. }
  191. }
  192. function _deprecated(scope, value, previous, current) {
  193. if (value !== undefined) {
  194. console.warn(scope + ': "' + previous +
  195. '" is deprecated. Please use "' + current + '" instead');
  196. }
  197. }
  198. const emptyString = '';
  199. const dot = '.';
  200. function indexOfDotOrLength(key, start) {
  201. const idx = key.indexOf(dot, start);
  202. return idx === -1 ? key.length : idx;
  203. }
  204. function resolveObjectKey(obj, key) {
  205. if (key === emptyString) {
  206. return obj;
  207. }
  208. let pos = 0;
  209. let idx = indexOfDotOrLength(key, pos);
  210. while (obj && idx > pos) {
  211. obj = obj[key.substr(pos, idx - pos)];
  212. pos = idx + 1;
  213. idx = indexOfDotOrLength(key, pos);
  214. }
  215. return obj;
  216. }
  217. function _capitalize(str) {
  218. return str.charAt(0).toUpperCase() + str.slice(1);
  219. }
  220. const defined = (value) => typeof value !== 'undefined';
  221. const isFunction = (value) => typeof value === 'function';
  222. const setsEqual = (a, b) => {
  223. if (a.size !== b.size) {
  224. return false;
  225. }
  226. for (const item of a) {
  227. if (!b.has(item)) {
  228. return false;
  229. }
  230. }
  231. return true;
  232. };
  233. const PI = Math.PI;
  234. const TAU = 2 * PI;
  235. const PITAU = TAU + PI;
  236. const INFINITY = Number.POSITIVE_INFINITY;
  237. const RAD_PER_DEG = PI / 180;
  238. const HALF_PI = PI / 2;
  239. const QUARTER_PI = PI / 4;
  240. const TWO_THIRDS_PI = PI * 2 / 3;
  241. const log10 = Math.log10;
  242. const sign = Math.sign;
  243. function niceNum(range) {
  244. const niceRange = Math.pow(10, Math.floor(log10(range)));
  245. const fraction = range / niceRange;
  246. const niceFraction = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10;
  247. return niceFraction * niceRange;
  248. }
  249. function _factorize(value) {
  250. const result = [];
  251. const sqrt = Math.sqrt(value);
  252. let i;
  253. for (i = 1; i < sqrt; i++) {
  254. if (value % i === 0) {
  255. result.push(i);
  256. result.push(value / i);
  257. }
  258. }
  259. if (sqrt === (sqrt | 0)) {
  260. result.push(sqrt);
  261. }
  262. result.sort((a, b) => a - b).pop();
  263. return result;
  264. }
  265. function isNumber(n) {
  266. return !isNaN(parseFloat(n)) && isFinite(n);
  267. }
  268. function almostEquals(x, y, epsilon) {
  269. return Math.abs(x - y) < epsilon;
  270. }
  271. function almostWhole(x, epsilon) {
  272. const rounded = Math.round(x);
  273. return ((rounded - epsilon) <= x) && ((rounded + epsilon) >= x);
  274. }
  275. function _setMinAndMaxByKey(array, target, property) {
  276. let i, ilen, value;
  277. for (i = 0, ilen = array.length; i < ilen; i++) {
  278. value = array[i][property];
  279. if (!isNaN(value)) {
  280. target.min = Math.min(target.min, value);
  281. target.max = Math.max(target.max, value);
  282. }
  283. }
  284. }
  285. function toRadians(degrees) {
  286. return degrees * (PI / 180);
  287. }
  288. function toDegrees(radians) {
  289. return radians * (180 / PI);
  290. }
  291. function _decimalPlaces(x) {
  292. if (!isNumberFinite(x)) {
  293. return;
  294. }
  295. let e = 1;
  296. let p = 0;
  297. while (Math.round(x * e) / e !== x) {
  298. e *= 10;
  299. p++;
  300. }
  301. return p;
  302. }
  303. function getAngleFromPoint(centrePoint, anglePoint) {
  304. const distanceFromXCenter = anglePoint.x - centrePoint.x;
  305. const distanceFromYCenter = anglePoint.y - centrePoint.y;
  306. const radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  307. let angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  308. if (angle < (-0.5 * PI)) {
  309. angle += TAU;
  310. }
  311. return {
  312. angle,
  313. distance: radialDistanceFromCenter
  314. };
  315. }
  316. function distanceBetweenPoints(pt1, pt2) {
  317. return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
  318. }
  319. function _angleDiff(a, b) {
  320. return (a - b + PITAU) % TAU - PI;
  321. }
  322. function _normalizeAngle(a) {
  323. return (a % TAU + TAU) % TAU;
  324. }
  325. function _angleBetween(angle, start, end) {
  326. const a = _normalizeAngle(angle);
  327. const s = _normalizeAngle(start);
  328. const e = _normalizeAngle(end);
  329. const angleToStart = _normalizeAngle(s - a);
  330. const angleToEnd = _normalizeAngle(e - a);
  331. const startToAngle = _normalizeAngle(a - s);
  332. const endToAngle = _normalizeAngle(a - e);
  333. return a === s || a === e || (angleToStart > angleToEnd && startToAngle < endToAngle);
  334. }
  335. function _limitValue(value, min, max) {
  336. return Math.max(min, Math.min(max, value));
  337. }
  338. function _int16Range(value) {
  339. return _limitValue(value, -32768, 32767);
  340. }
  341. const atEdge = (t) => t === 0 || t === 1;
  342. const elasticIn = (t, s, p) => -(Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * TAU / p));
  343. const elasticOut = (t, s, p) => Math.pow(2, -10 * t) * Math.sin((t - s) * TAU / p) + 1;
  344. const effects = {
  345. linear: t => t,
  346. easeInQuad: t => t * t,
  347. easeOutQuad: t => -t * (t - 2),
  348. easeInOutQuad: t => ((t /= 0.5) < 1)
  349. ? 0.5 * t * t
  350. : -0.5 * ((--t) * (t - 2) - 1),
  351. easeInCubic: t => t * t * t,
  352. easeOutCubic: t => (t -= 1) * t * t + 1,
  353. easeInOutCubic: t => ((t /= 0.5) < 1)
  354. ? 0.5 * t * t * t
  355. : 0.5 * ((t -= 2) * t * t + 2),
  356. easeInQuart: t => t * t * t * t,
  357. easeOutQuart: t => -((t -= 1) * t * t * t - 1),
  358. easeInOutQuart: t => ((t /= 0.5) < 1)
  359. ? 0.5 * t * t * t * t
  360. : -0.5 * ((t -= 2) * t * t * t - 2),
  361. easeInQuint: t => t * t * t * t * t,
  362. easeOutQuint: t => (t -= 1) * t * t * t * t + 1,
  363. easeInOutQuint: t => ((t /= 0.5) < 1)
  364. ? 0.5 * t * t * t * t * t
  365. : 0.5 * ((t -= 2) * t * t * t * t + 2),
  366. easeInSine: t => -Math.cos(t * HALF_PI) + 1,
  367. easeOutSine: t => Math.sin(t * HALF_PI),
  368. easeInOutSine: t => -0.5 * (Math.cos(PI * t) - 1),
  369. easeInExpo: t => (t === 0) ? 0 : Math.pow(2, 10 * (t - 1)),
  370. easeOutExpo: t => (t === 1) ? 1 : -Math.pow(2, -10 * t) + 1,
  371. easeInOutExpo: t => atEdge(t) ? t : t < 0.5
  372. ? 0.5 * Math.pow(2, 10 * (t * 2 - 1))
  373. : 0.5 * (-Math.pow(2, -10 * (t * 2 - 1)) + 2),
  374. easeInCirc: t => (t >= 1) ? t : -(Math.sqrt(1 - t * t) - 1),
  375. easeOutCirc: t => Math.sqrt(1 - (t -= 1) * t),
  376. easeInOutCirc: t => ((t /= 0.5) < 1)
  377. ? -0.5 * (Math.sqrt(1 - t * t) - 1)
  378. : 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1),
  379. easeInElastic: t => atEdge(t) ? t : elasticIn(t, 0.075, 0.3),
  380. easeOutElastic: t => atEdge(t) ? t : elasticOut(t, 0.075, 0.3),
  381. easeInOutElastic(t) {
  382. const s = 0.1125;
  383. const p = 0.45;
  384. return atEdge(t) ? t :
  385. t < 0.5
  386. ? 0.5 * elasticIn(t * 2, s, p)
  387. : 0.5 + 0.5 * elasticOut(t * 2 - 1, s, p);
  388. },
  389. easeInBack(t) {
  390. const s = 1.70158;
  391. return t * t * ((s + 1) * t - s);
  392. },
  393. easeOutBack(t) {
  394. const s = 1.70158;
  395. return (t -= 1) * t * ((s + 1) * t + s) + 1;
  396. },
  397. easeInOutBack(t) {
  398. let s = 1.70158;
  399. if ((t /= 0.5) < 1) {
  400. return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s));
  401. }
  402. return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  403. },
  404. easeInBounce: t => 1 - effects.easeOutBounce(1 - t),
  405. easeOutBounce(t) {
  406. const m = 7.5625;
  407. const d = 2.75;
  408. if (t < (1 / d)) {
  409. return m * t * t;
  410. }
  411. if (t < (2 / d)) {
  412. return m * (t -= (1.5 / d)) * t + 0.75;
  413. }
  414. if (t < (2.5 / d)) {
  415. return m * (t -= (2.25 / d)) * t + 0.9375;
  416. }
  417. return m * (t -= (2.625 / d)) * t + 0.984375;
  418. },
  419. easeInOutBounce: t => (t < 0.5)
  420. ? effects.easeInBounce(t * 2) * 0.5
  421. : effects.easeOutBounce(t * 2 - 1) * 0.5 + 0.5,
  422. };
  423. /*!
  424. * @kurkle/color v0.1.9
  425. * https://github.com/kurkle/color#readme
  426. * (c) 2020 Jukka Kurkela
  427. * Released under the MIT License
  428. */
  429. const map = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, A: 10, B: 11, C: 12, D: 13, E: 14, F: 15, a: 10, b: 11, c: 12, d: 13, e: 14, f: 15};
  430. const hex = '0123456789ABCDEF';
  431. const h1 = (b) => hex[b & 0xF];
  432. const h2 = (b) => hex[(b & 0xF0) >> 4] + hex[b & 0xF];
  433. const eq = (b) => (((b & 0xF0) >> 4) === (b & 0xF));
  434. function isShort(v) {
  435. return eq(v.r) && eq(v.g) && eq(v.b) && eq(v.a);
  436. }
  437. function hexParse(str) {
  438. var len = str.length;
  439. var ret;
  440. if (str[0] === '#') {
  441. if (len === 4 || len === 5) {
  442. ret = {
  443. r: 255 & map[str[1]] * 17,
  444. g: 255 & map[str[2]] * 17,
  445. b: 255 & map[str[3]] * 17,
  446. a: len === 5 ? map[str[4]] * 17 : 255
  447. };
  448. } else if (len === 7 || len === 9) {
  449. ret = {
  450. r: map[str[1]] << 4 | map[str[2]],
  451. g: map[str[3]] << 4 | map[str[4]],
  452. b: map[str[5]] << 4 | map[str[6]],
  453. a: len === 9 ? (map[str[7]] << 4 | map[str[8]]) : 255
  454. };
  455. }
  456. }
  457. return ret;
  458. }
  459. function hexString(v) {
  460. var f = isShort(v) ? h1 : h2;
  461. return v
  462. ? '#' + f(v.r) + f(v.g) + f(v.b) + (v.a < 255 ? f(v.a) : '')
  463. : v;
  464. }
  465. function round(v) {
  466. return v + 0.5 | 0;
  467. }
  468. const lim = (v, l, h) => Math.max(Math.min(v, h), l);
  469. function p2b(v) {
  470. return lim(round(v * 2.55), 0, 255);
  471. }
  472. function n2b(v) {
  473. return lim(round(v * 255), 0, 255);
  474. }
  475. function b2n(v) {
  476. return lim(round(v / 2.55) / 100, 0, 1);
  477. }
  478. function n2p(v) {
  479. return lim(round(v * 100), 0, 100);
  480. }
  481. const RGB_RE = /^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;
  482. function rgbParse(str) {
  483. const m = RGB_RE.exec(str);
  484. let a = 255;
  485. let r, g, b;
  486. if (!m) {
  487. return;
  488. }
  489. if (m[7] !== r) {
  490. const v = +m[7];
  491. a = 255 & (m[8] ? p2b(v) : v * 255);
  492. }
  493. r = +m[1];
  494. g = +m[3];
  495. b = +m[5];
  496. r = 255 & (m[2] ? p2b(r) : r);
  497. g = 255 & (m[4] ? p2b(g) : g);
  498. b = 255 & (m[6] ? p2b(b) : b);
  499. return {
  500. r: r,
  501. g: g,
  502. b: b,
  503. a: a
  504. };
  505. }
  506. function rgbString(v) {
  507. return v && (
  508. v.a < 255
  509. ? `rgba(${v.r}, ${v.g}, ${v.b}, ${b2n(v.a)})`
  510. : `rgb(${v.r}, ${v.g}, ${v.b})`
  511. );
  512. }
  513. const HUE_RE = /^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;
  514. function hsl2rgbn(h, s, l) {
  515. const a = s * Math.min(l, 1 - l);
  516. const f = (n, k = (n + h / 30) % 12) => l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
  517. return [f(0), f(8), f(4)];
  518. }
  519. function hsv2rgbn(h, s, v) {
  520. const f = (n, k = (n + h / 60) % 6) => v - v * s * Math.max(Math.min(k, 4 - k, 1), 0);
  521. return [f(5), f(3), f(1)];
  522. }
  523. function hwb2rgbn(h, w, b) {
  524. const rgb = hsl2rgbn(h, 1, 0.5);
  525. let i;
  526. if (w + b > 1) {
  527. i = 1 / (w + b);
  528. w *= i;
  529. b *= i;
  530. }
  531. for (i = 0; i < 3; i++) {
  532. rgb[i] *= 1 - w - b;
  533. rgb[i] += w;
  534. }
  535. return rgb;
  536. }
  537. function rgb2hsl(v) {
  538. const range = 255;
  539. const r = v.r / range;
  540. const g = v.g / range;
  541. const b = v.b / range;
  542. const max = Math.max(r, g, b);
  543. const min = Math.min(r, g, b);
  544. const l = (max + min) / 2;
  545. let h, s, d;
  546. if (max !== min) {
  547. d = max - min;
  548. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  549. h = max === r
  550. ? ((g - b) / d) + (g < b ? 6 : 0)
  551. : max === g
  552. ? (b - r) / d + 2
  553. : (r - g) / d + 4;
  554. h = h * 60 + 0.5;
  555. }
  556. return [h | 0, s || 0, l];
  557. }
  558. function calln(f, a, b, c) {
  559. return (
  560. Array.isArray(a)
  561. ? f(a[0], a[1], a[2])
  562. : f(a, b, c)
  563. ).map(n2b);
  564. }
  565. function hsl2rgb(h, s, l) {
  566. return calln(hsl2rgbn, h, s, l);
  567. }
  568. function hwb2rgb(h, w, b) {
  569. return calln(hwb2rgbn, h, w, b);
  570. }
  571. function hsv2rgb(h, s, v) {
  572. return calln(hsv2rgbn, h, s, v);
  573. }
  574. function hue(h) {
  575. return (h % 360 + 360) % 360;
  576. }
  577. function hueParse(str) {
  578. const m = HUE_RE.exec(str);
  579. let a = 255;
  580. let v;
  581. if (!m) {
  582. return;
  583. }
  584. if (m[5] !== v) {
  585. a = m[6] ? p2b(+m[5]) : n2b(+m[5]);
  586. }
  587. const h = hue(+m[2]);
  588. const p1 = +m[3] / 100;
  589. const p2 = +m[4] / 100;
  590. if (m[1] === 'hwb') {
  591. v = hwb2rgb(h, p1, p2);
  592. } else if (m[1] === 'hsv') {
  593. v = hsv2rgb(h, p1, p2);
  594. } else {
  595. v = hsl2rgb(h, p1, p2);
  596. }
  597. return {
  598. r: v[0],
  599. g: v[1],
  600. b: v[2],
  601. a: a
  602. };
  603. }
  604. function rotate(v, deg) {
  605. var h = rgb2hsl(v);
  606. h[0] = hue(h[0] + deg);
  607. h = hsl2rgb(h);
  608. v.r = h[0];
  609. v.g = h[1];
  610. v.b = h[2];
  611. }
  612. function hslString(v) {
  613. if (!v) {
  614. return;
  615. }
  616. const a = rgb2hsl(v);
  617. const h = a[0];
  618. const s = n2p(a[1]);
  619. const l = n2p(a[2]);
  620. return v.a < 255
  621. ? `hsla(${h}, ${s}%, ${l}%, ${b2n(v.a)})`
  622. : `hsl(${h}, ${s}%, ${l}%)`;
  623. }
  624. const map$1 = {
  625. x: 'dark',
  626. Z: 'light',
  627. Y: 're',
  628. X: 'blu',
  629. W: 'gr',
  630. V: 'medium',
  631. U: 'slate',
  632. A: 'ee',
  633. T: 'ol',
  634. S: 'or',
  635. B: 'ra',
  636. C: 'lateg',
  637. D: 'ights',
  638. R: 'in',
  639. Q: 'turquois',
  640. E: 'hi',
  641. P: 'ro',
  642. O: 'al',
  643. N: 'le',
  644. M: 'de',
  645. L: 'yello',
  646. F: 'en',
  647. K: 'ch',
  648. G: 'arks',
  649. H: 'ea',
  650. I: 'ightg',
  651. J: 'wh'
  652. };
  653. const names = {
  654. OiceXe: 'f0f8ff',
  655. antiquewEte: 'faebd7',
  656. aqua: 'ffff',
  657. aquamarRe: '7fffd4',
  658. azuY: 'f0ffff',
  659. beige: 'f5f5dc',
  660. bisque: 'ffe4c4',
  661. black: '0',
  662. blanKedOmond: 'ffebcd',
  663. Xe: 'ff',
  664. XeviTet: '8a2be2',
  665. bPwn: 'a52a2a',
  666. burlywood: 'deb887',
  667. caMtXe: '5f9ea0',
  668. KartYuse: '7fff00',
  669. KocTate: 'd2691e',
  670. cSO: 'ff7f50',
  671. cSnflowerXe: '6495ed',
  672. cSnsilk: 'fff8dc',
  673. crimson: 'dc143c',
  674. cyan: 'ffff',
  675. xXe: '8b',
  676. xcyan: '8b8b',
  677. xgTMnPd: 'b8860b',
  678. xWay: 'a9a9a9',
  679. xgYF: '6400',
  680. xgYy: 'a9a9a9',
  681. xkhaki: 'bdb76b',
  682. xmagFta: '8b008b',
  683. xTivegYF: '556b2f',
  684. xSange: 'ff8c00',
  685. xScEd: '9932cc',
  686. xYd: '8b0000',
  687. xsOmon: 'e9967a',
  688. xsHgYF: '8fbc8f',
  689. xUXe: '483d8b',
  690. xUWay: '2f4f4f',
  691. xUgYy: '2f4f4f',
  692. xQe: 'ced1',
  693. xviTet: '9400d3',
  694. dAppRk: 'ff1493',
  695. dApskyXe: 'bfff',
  696. dimWay: '696969',
  697. dimgYy: '696969',
  698. dodgerXe: '1e90ff',
  699. fiYbrick: 'b22222',
  700. flSOwEte: 'fffaf0',
  701. foYstWAn: '228b22',
  702. fuKsia: 'ff00ff',
  703. gaRsbSo: 'dcdcdc',
  704. ghostwEte: 'f8f8ff',
  705. gTd: 'ffd700',
  706. gTMnPd: 'daa520',
  707. Way: '808080',
  708. gYF: '8000',
  709. gYFLw: 'adff2f',
  710. gYy: '808080',
  711. honeyMw: 'f0fff0',
  712. hotpRk: 'ff69b4',
  713. RdianYd: 'cd5c5c',
  714. Rdigo: '4b0082',
  715. ivSy: 'fffff0',
  716. khaki: 'f0e68c',
  717. lavFMr: 'e6e6fa',
  718. lavFMrXsh: 'fff0f5',
  719. lawngYF: '7cfc00',
  720. NmoncEffon: 'fffacd',
  721. ZXe: 'add8e6',
  722. ZcSO: 'f08080',
  723. Zcyan: 'e0ffff',
  724. ZgTMnPdLw: 'fafad2',
  725. ZWay: 'd3d3d3',
  726. ZgYF: '90ee90',
  727. ZgYy: 'd3d3d3',
  728. ZpRk: 'ffb6c1',
  729. ZsOmon: 'ffa07a',
  730. ZsHgYF: '20b2aa',
  731. ZskyXe: '87cefa',
  732. ZUWay: '778899',
  733. ZUgYy: '778899',
  734. ZstAlXe: 'b0c4de',
  735. ZLw: 'ffffe0',
  736. lime: 'ff00',
  737. limegYF: '32cd32',
  738. lRF: 'faf0e6',
  739. magFta: 'ff00ff',
  740. maPon: '800000',
  741. VaquamarRe: '66cdaa',
  742. VXe: 'cd',
  743. VScEd: 'ba55d3',
  744. VpurpN: '9370db',
  745. VsHgYF: '3cb371',
  746. VUXe: '7b68ee',
  747. VsprRggYF: 'fa9a',
  748. VQe: '48d1cc',
  749. VviTetYd: 'c71585',
  750. midnightXe: '191970',
  751. mRtcYam: 'f5fffa',
  752. mistyPse: 'ffe4e1',
  753. moccasR: 'ffe4b5',
  754. navajowEte: 'ffdead',
  755. navy: '80',
  756. Tdlace: 'fdf5e6',
  757. Tive: '808000',
  758. TivedBb: '6b8e23',
  759. Sange: 'ffa500',
  760. SangeYd: 'ff4500',
  761. ScEd: 'da70d6',
  762. pOegTMnPd: 'eee8aa',
  763. pOegYF: '98fb98',
  764. pOeQe: 'afeeee',
  765. pOeviTetYd: 'db7093',
  766. papayawEp: 'ffefd5',
  767. pHKpuff: 'ffdab9',
  768. peru: 'cd853f',
  769. pRk: 'ffc0cb',
  770. plum: 'dda0dd',
  771. powMrXe: 'b0e0e6',
  772. purpN: '800080',
  773. YbeccapurpN: '663399',
  774. Yd: 'ff0000',
  775. Psybrown: 'bc8f8f',
  776. PyOXe: '4169e1',
  777. saddNbPwn: '8b4513',
  778. sOmon: 'fa8072',
  779. sandybPwn: 'f4a460',
  780. sHgYF: '2e8b57',
  781. sHshell: 'fff5ee',
  782. siFna: 'a0522d',
  783. silver: 'c0c0c0',
  784. skyXe: '87ceeb',
  785. UXe: '6a5acd',
  786. UWay: '708090',
  787. UgYy: '708090',
  788. snow: 'fffafa',
  789. sprRggYF: 'ff7f',
  790. stAlXe: '4682b4',
  791. tan: 'd2b48c',
  792. teO: '8080',
  793. tEstN: 'd8bfd8',
  794. tomato: 'ff6347',
  795. Qe: '40e0d0',
  796. viTet: 'ee82ee',
  797. JHt: 'f5deb3',
  798. wEte: 'ffffff',
  799. wEtesmoke: 'f5f5f5',
  800. Lw: 'ffff00',
  801. LwgYF: '9acd32'
  802. };
  803. function unpack() {
  804. const unpacked = {};
  805. const keys = Object.keys(names);
  806. const tkeys = Object.keys(map$1);
  807. let i, j, k, ok, nk;
  808. for (i = 0; i < keys.length; i++) {
  809. ok = nk = keys[i];
  810. for (j = 0; j < tkeys.length; j++) {
  811. k = tkeys[j];
  812. nk = nk.replace(k, map$1[k]);
  813. }
  814. k = parseInt(names[ok], 16);
  815. unpacked[nk] = [k >> 16 & 0xFF, k >> 8 & 0xFF, k & 0xFF];
  816. }
  817. return unpacked;
  818. }
  819. let names$1;
  820. function nameParse(str) {
  821. if (!names$1) {
  822. names$1 = unpack();
  823. names$1.transparent = [0, 0, 0, 0];
  824. }
  825. const a = names$1[str.toLowerCase()];
  826. return a && {
  827. r: a[0],
  828. g: a[1],
  829. b: a[2],
  830. a: a.length === 4 ? a[3] : 255
  831. };
  832. }
  833. function modHSL(v, i, ratio) {
  834. if (v) {
  835. let tmp = rgb2hsl(v);
  836. tmp[i] = Math.max(0, Math.min(tmp[i] + tmp[i] * ratio, i === 0 ? 360 : 1));
  837. tmp = hsl2rgb(tmp);
  838. v.r = tmp[0];
  839. v.g = tmp[1];
  840. v.b = tmp[2];
  841. }
  842. }
  843. function clone(v, proto) {
  844. return v ? Object.assign(proto || {}, v) : v;
  845. }
  846. function fromObject(input) {
  847. var v = {r: 0, g: 0, b: 0, a: 255};
  848. if (Array.isArray(input)) {
  849. if (input.length >= 3) {
  850. v = {r: input[0], g: input[1], b: input[2], a: 255};
  851. if (input.length > 3) {
  852. v.a = n2b(input[3]);
  853. }
  854. }
  855. } else {
  856. v = clone(input, {r: 0, g: 0, b: 0, a: 1});
  857. v.a = n2b(v.a);
  858. }
  859. return v;
  860. }
  861. function functionParse(str) {
  862. if (str.charAt(0) === 'r') {
  863. return rgbParse(str);
  864. }
  865. return hueParse(str);
  866. }
  867. class Color {
  868. constructor(input) {
  869. if (input instanceof Color) {
  870. return input;
  871. }
  872. const type = typeof input;
  873. let v;
  874. if (type === 'object') {
  875. v = fromObject(input);
  876. } else if (type === 'string') {
  877. v = hexParse(input) || nameParse(input) || functionParse(input);
  878. }
  879. this._rgb = v;
  880. this._valid = !!v;
  881. }
  882. get valid() {
  883. return this._valid;
  884. }
  885. get rgb() {
  886. var v = clone(this._rgb);
  887. if (v) {
  888. v.a = b2n(v.a);
  889. }
  890. return v;
  891. }
  892. set rgb(obj) {
  893. this._rgb = fromObject(obj);
  894. }
  895. rgbString() {
  896. return this._valid ? rgbString(this._rgb) : this._rgb;
  897. }
  898. hexString() {
  899. return this._valid ? hexString(this._rgb) : this._rgb;
  900. }
  901. hslString() {
  902. return this._valid ? hslString(this._rgb) : this._rgb;
  903. }
  904. mix(color, weight) {
  905. const me = this;
  906. if (color) {
  907. const c1 = me.rgb;
  908. const c2 = color.rgb;
  909. let w2;
  910. const p = weight === w2 ? 0.5 : weight;
  911. const w = 2 * p - 1;
  912. const a = c1.a - c2.a;
  913. const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  914. w2 = 1 - w1;
  915. c1.r = 0xFF & w1 * c1.r + w2 * c2.r + 0.5;
  916. c1.g = 0xFF & w1 * c1.g + w2 * c2.g + 0.5;
  917. c1.b = 0xFF & w1 * c1.b + w2 * c2.b + 0.5;
  918. c1.a = p * c1.a + (1 - p) * c2.a;
  919. me.rgb = c1;
  920. }
  921. return me;
  922. }
  923. clone() {
  924. return new Color(this.rgb);
  925. }
  926. alpha(a) {
  927. this._rgb.a = n2b(a);
  928. return this;
  929. }
  930. clearer(ratio) {
  931. const rgb = this._rgb;
  932. rgb.a *= 1 - ratio;
  933. return this;
  934. }
  935. greyscale() {
  936. const rgb = this._rgb;
  937. const val = round(rgb.r * 0.3 + rgb.g * 0.59 + rgb.b * 0.11);
  938. rgb.r = rgb.g = rgb.b = val;
  939. return this;
  940. }
  941. opaquer(ratio) {
  942. const rgb = this._rgb;
  943. rgb.a *= 1 + ratio;
  944. return this;
  945. }
  946. negate() {
  947. const v = this._rgb;
  948. v.r = 255 - v.r;
  949. v.g = 255 - v.g;
  950. v.b = 255 - v.b;
  951. return this;
  952. }
  953. lighten(ratio) {
  954. modHSL(this._rgb, 2, ratio);
  955. return this;
  956. }
  957. darken(ratio) {
  958. modHSL(this._rgb, 2, -ratio);
  959. return this;
  960. }
  961. saturate(ratio) {
  962. modHSL(this._rgb, 1, ratio);
  963. return this;
  964. }
  965. desaturate(ratio) {
  966. modHSL(this._rgb, 1, -ratio);
  967. return this;
  968. }
  969. rotate(deg) {
  970. rotate(this._rgb, deg);
  971. return this;
  972. }
  973. }
  974. function index_esm(input) {
  975. return new Color(input);
  976. }
  977. const isPatternOrGradient = (value) => value instanceof CanvasGradient || value instanceof CanvasPattern;
  978. function color(value) {
  979. return isPatternOrGradient(value) ? value : index_esm(value);
  980. }
  981. function getHoverColor(value) {
  982. return isPatternOrGradient(value)
  983. ? value
  984. : index_esm(value).saturate(0.5).darken(0.1).hexString();
  985. }
  986. const overrides = Object.create(null);
  987. const descriptors = Object.create(null);
  988. function getScope$1(node, key) {
  989. if (!key) {
  990. return node;
  991. }
  992. const keys = key.split('.');
  993. for (let i = 0, n = keys.length; i < n; ++i) {
  994. const k = keys[i];
  995. node = node[k] || (node[k] = Object.create(null));
  996. }
  997. return node;
  998. }
  999. function set(root, scope, values) {
  1000. if (typeof scope === 'string') {
  1001. return merge(getScope$1(root, scope), values);
  1002. }
  1003. return merge(getScope$1(root, ''), scope);
  1004. }
  1005. class Defaults {
  1006. constructor(_descriptors) {
  1007. this.animation = undefined;
  1008. this.backgroundColor = 'rgba(0,0,0,0.1)';
  1009. this.borderColor = 'rgba(0,0,0,0.1)';
  1010. this.color = '#666';
  1011. this.datasets = {};
  1012. this.devicePixelRatio = (context) => context.chart.platform.getDevicePixelRatio();
  1013. this.elements = {};
  1014. this.events = [
  1015. 'mousemove',
  1016. 'mouseout',
  1017. 'click',
  1018. 'touchstart',
  1019. 'touchmove'
  1020. ];
  1021. this.font = {
  1022. family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  1023. size: 12,
  1024. style: 'normal',
  1025. lineHeight: 1.2,
  1026. weight: null
  1027. };
  1028. this.hover = {};
  1029. this.hoverBackgroundColor = (ctx, options) => getHoverColor(options.backgroundColor);
  1030. this.hoverBorderColor = (ctx, options) => getHoverColor(options.borderColor);
  1031. this.hoverColor = (ctx, options) => getHoverColor(options.color);
  1032. this.indexAxis = 'x';
  1033. this.interaction = {
  1034. mode: 'nearest',
  1035. intersect: true
  1036. };
  1037. this.maintainAspectRatio = true;
  1038. this.onHover = null;
  1039. this.onClick = null;
  1040. this.parsing = true;
  1041. this.plugins = {};
  1042. this.responsive = true;
  1043. this.scale = undefined;
  1044. this.scales = {};
  1045. this.showLine = true;
  1046. this.describe(_descriptors);
  1047. }
  1048. set(scope, values) {
  1049. return set(this, scope, values);
  1050. }
  1051. get(scope) {
  1052. return getScope$1(this, scope);
  1053. }
  1054. describe(scope, values) {
  1055. return set(descriptors, scope, values);
  1056. }
  1057. override(scope, values) {
  1058. return set(overrides, scope, values);
  1059. }
  1060. route(scope, name, targetScope, targetName) {
  1061. const scopeObject = getScope$1(this, scope);
  1062. const targetScopeObject = getScope$1(this, targetScope);
  1063. const privateName = '_' + name;
  1064. Object.defineProperties(scopeObject, {
  1065. [privateName]: {
  1066. value: scopeObject[name],
  1067. writable: true
  1068. },
  1069. [name]: {
  1070. enumerable: true,
  1071. get() {
  1072. const local = this[privateName];
  1073. const target = targetScopeObject[targetName];
  1074. if (isObject(local)) {
  1075. return Object.assign({}, target, local);
  1076. }
  1077. return valueOrDefault(local, target);
  1078. },
  1079. set(value) {
  1080. this[privateName] = value;
  1081. }
  1082. }
  1083. });
  1084. }
  1085. }
  1086. var defaults = new Defaults({
  1087. _scriptable: (name) => !name.startsWith('on'),
  1088. _indexable: (name) => name !== 'events',
  1089. hover: {
  1090. _fallback: 'interaction'
  1091. },
  1092. interaction: {
  1093. _scriptable: false,
  1094. _indexable: false,
  1095. }
  1096. });
  1097. function toFontString(font) {
  1098. if (!font || isNullOrUndef(font.size) || isNullOrUndef(font.family)) {
  1099. return null;
  1100. }
  1101. return (font.style ? font.style + ' ' : '')
  1102. + (font.weight ? font.weight + ' ' : '')
  1103. + font.size + 'px '
  1104. + font.family;
  1105. }
  1106. function _measureText(ctx, data, gc, longest, string) {
  1107. let textWidth = data[string];
  1108. if (!textWidth) {
  1109. textWidth = data[string] = ctx.measureText(string).width;
  1110. gc.push(string);
  1111. }
  1112. if (textWidth > longest) {
  1113. longest = textWidth;
  1114. }
  1115. return longest;
  1116. }
  1117. function _longestText(ctx, font, arrayOfThings, cache) {
  1118. cache = cache || {};
  1119. let data = cache.data = cache.data || {};
  1120. let gc = cache.garbageCollect = cache.garbageCollect || [];
  1121. if (cache.font !== font) {
  1122. data = cache.data = {};
  1123. gc = cache.garbageCollect = [];
  1124. cache.font = font;
  1125. }
  1126. ctx.save();
  1127. ctx.font = font;
  1128. let longest = 0;
  1129. const ilen = arrayOfThings.length;
  1130. let i, j, jlen, thing, nestedThing;
  1131. for (i = 0; i < ilen; i++) {
  1132. thing = arrayOfThings[i];
  1133. if (thing !== undefined && thing !== null && isArray(thing) !== true) {
  1134. longest = _measureText(ctx, data, gc, longest, thing);
  1135. } else if (isArray(thing)) {
  1136. for (j = 0, jlen = thing.length; j < jlen; j++) {
  1137. nestedThing = thing[j];
  1138. if (nestedThing !== undefined && nestedThing !== null && !isArray(nestedThing)) {
  1139. longest = _measureText(ctx, data, gc, longest, nestedThing);
  1140. }
  1141. }
  1142. }
  1143. }
  1144. ctx.restore();
  1145. const gcLen = gc.length / 2;
  1146. if (gcLen > arrayOfThings.length) {
  1147. for (i = 0; i < gcLen; i++) {
  1148. delete data[gc[i]];
  1149. }
  1150. gc.splice(0, gcLen);
  1151. }
  1152. return longest;
  1153. }
  1154. function _alignPixel(chart, pixel, width) {
  1155. const devicePixelRatio = chart.currentDevicePixelRatio;
  1156. const halfWidth = width !== 0 ? Math.max(width / 2, 0.5) : 0;
  1157. return Math.round((pixel - halfWidth) * devicePixelRatio) / devicePixelRatio + halfWidth;
  1158. }
  1159. function clearCanvas(canvas, ctx) {
  1160. ctx = ctx || canvas.getContext('2d');
  1161. ctx.save();
  1162. ctx.resetTransform();
  1163. ctx.clearRect(0, 0, canvas.width, canvas.height);
  1164. ctx.restore();
  1165. }
  1166. function drawPoint(ctx, options, x, y) {
  1167. let type, xOffset, yOffset, size, cornerRadius;
  1168. const style = options.pointStyle;
  1169. const rotation = options.rotation;
  1170. const radius = options.radius;
  1171. let rad = (rotation || 0) * RAD_PER_DEG;
  1172. if (style && typeof style === 'object') {
  1173. type = style.toString();
  1174. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  1175. ctx.save();
  1176. ctx.translate(x, y);
  1177. ctx.rotate(rad);
  1178. ctx.drawImage(style, -style.width / 2, -style.height / 2, style.width, style.height);
  1179. ctx.restore();
  1180. return;
  1181. }
  1182. }
  1183. if (isNaN(radius) || radius <= 0) {
  1184. return;
  1185. }
  1186. ctx.beginPath();
  1187. switch (style) {
  1188. default:
  1189. ctx.arc(x, y, radius, 0, TAU);
  1190. ctx.closePath();
  1191. break;
  1192. case 'triangle':
  1193. ctx.moveTo(x + Math.sin(rad) * radius, y - Math.cos(rad) * radius);
  1194. rad += TWO_THIRDS_PI;
  1195. ctx.lineTo(x + Math.sin(rad) * radius, y - Math.cos(rad) * radius);
  1196. rad += TWO_THIRDS_PI;
  1197. ctx.lineTo(x + Math.sin(rad) * radius, y - Math.cos(rad) * radius);
  1198. ctx.closePath();
  1199. break;
  1200. case 'rectRounded':
  1201. cornerRadius = radius * 0.516;
  1202. size = radius - cornerRadius;
  1203. xOffset = Math.cos(rad + QUARTER_PI) * size;
  1204. yOffset = Math.sin(rad + QUARTER_PI) * size;
  1205. ctx.arc(x - xOffset, y - yOffset, cornerRadius, rad - PI, rad - HALF_PI);
  1206. ctx.arc(x + yOffset, y - xOffset, cornerRadius, rad - HALF_PI, rad);
  1207. ctx.arc(x + xOffset, y + yOffset, cornerRadius, rad, rad + HALF_PI);
  1208. ctx.arc(x - yOffset, y + xOffset, cornerRadius, rad + HALF_PI, rad + PI);
  1209. ctx.closePath();
  1210. break;
  1211. case 'rect':
  1212. if (!rotation) {
  1213. size = Math.SQRT1_2 * radius;
  1214. ctx.rect(x - size, y - size, 2 * size, 2 * size);
  1215. break;
  1216. }
  1217. rad += QUARTER_PI;
  1218. case 'rectRot':
  1219. xOffset = Math.cos(rad) * radius;
  1220. yOffset = Math.sin(rad) * radius;
  1221. ctx.moveTo(x - xOffset, y - yOffset);
  1222. ctx.lineTo(x + yOffset, y - xOffset);
  1223. ctx.lineTo(x + xOffset, y + yOffset);
  1224. ctx.lineTo(x - yOffset, y + xOffset);
  1225. ctx.closePath();
  1226. break;
  1227. case 'crossRot':
  1228. rad += QUARTER_PI;
  1229. case 'cross':
  1230. xOffset = Math.cos(rad) * radius;
  1231. yOffset = Math.sin(rad) * radius;
  1232. ctx.moveTo(x - xOffset, y - yOffset);
  1233. ctx.lineTo(x + xOffset, y + yOffset);
  1234. ctx.moveTo(x + yOffset, y - xOffset);
  1235. ctx.lineTo(x - yOffset, y + xOffset);
  1236. break;
  1237. case 'star':
  1238. xOffset = Math.cos(rad) * radius;
  1239. yOffset = Math.sin(rad) * radius;
  1240. ctx.moveTo(x - xOffset, y - yOffset);
  1241. ctx.lineTo(x + xOffset, y + yOffset);
  1242. ctx.moveTo(x + yOffset, y - xOffset);
  1243. ctx.lineTo(x - yOffset, y + xOffset);
  1244. rad += QUARTER_PI;
  1245. xOffset = Math.cos(rad) * radius;
  1246. yOffset = Math.sin(rad) * radius;
  1247. ctx.moveTo(x - xOffset, y - yOffset);
  1248. ctx.lineTo(x + xOffset, y + yOffset);
  1249. ctx.moveTo(x + yOffset, y - xOffset);
  1250. ctx.lineTo(x - yOffset, y + xOffset);
  1251. break;
  1252. case 'line':
  1253. xOffset = Math.cos(rad) * radius;
  1254. yOffset = Math.sin(rad) * radius;
  1255. ctx.moveTo(x - xOffset, y - yOffset);
  1256. ctx.lineTo(x + xOffset, y + yOffset);
  1257. break;
  1258. case 'dash':
  1259. ctx.moveTo(x, y);
  1260. ctx.lineTo(x + Math.cos(rad) * radius, y + Math.sin(rad) * radius);
  1261. break;
  1262. }
  1263. ctx.fill();
  1264. if (options.borderWidth > 0) {
  1265. ctx.stroke();
  1266. }
  1267. }
  1268. function _isPointInArea(point, area, margin) {
  1269. margin = margin || 0.5;
  1270. return point && point.x > area.left - margin && point.x < area.right + margin &&
  1271. point.y > area.top - margin && point.y < area.bottom + margin;
  1272. }
  1273. function clipArea(ctx, area) {
  1274. ctx.save();
  1275. ctx.beginPath();
  1276. ctx.rect(area.left, area.top, area.right - area.left, area.bottom - area.top);
  1277. ctx.clip();
  1278. }
  1279. function unclipArea(ctx) {
  1280. ctx.restore();
  1281. }
  1282. function _steppedLineTo(ctx, previous, target, flip, mode) {
  1283. if (!previous) {
  1284. return ctx.lineTo(target.x, target.y);
  1285. }
  1286. if (mode === 'middle') {
  1287. const midpoint = (previous.x + target.x) / 2.0;
  1288. ctx.lineTo(midpoint, previous.y);
  1289. ctx.lineTo(midpoint, target.y);
  1290. } else if (mode === 'after' !== !!flip) {
  1291. ctx.lineTo(previous.x, target.y);
  1292. } else {
  1293. ctx.lineTo(target.x, previous.y);
  1294. }
  1295. ctx.lineTo(target.x, target.y);
  1296. }
  1297. function _bezierCurveTo(ctx, previous, target, flip) {
  1298. if (!previous) {
  1299. return ctx.lineTo(target.x, target.y);
  1300. }
  1301. ctx.bezierCurveTo(
  1302. flip ? previous.cp1x : previous.cp2x,
  1303. flip ? previous.cp1y : previous.cp2y,
  1304. flip ? target.cp2x : target.cp1x,
  1305. flip ? target.cp2y : target.cp1y,
  1306. target.x,
  1307. target.y);
  1308. }
  1309. function renderText(ctx, text, x, y, font, opts = {}) {
  1310. const lines = isArray(text) ? text : [text];
  1311. const stroke = opts.strokeWidth > 0 && opts.strokeColor !== '';
  1312. let i, line;
  1313. ctx.save();
  1314. if (opts.translation) {
  1315. ctx.translate(opts.translation[0], opts.translation[1]);
  1316. }
  1317. if (!isNullOrUndef(opts.rotation)) {
  1318. ctx.rotate(opts.rotation);
  1319. }
  1320. ctx.font = font.string;
  1321. if (opts.color) {
  1322. ctx.fillStyle = opts.color;
  1323. }
  1324. if (opts.textAlign) {
  1325. ctx.textAlign = opts.textAlign;
  1326. }
  1327. if (opts.textBaseline) {
  1328. ctx.textBaseline = opts.textBaseline;
  1329. }
  1330. for (i = 0; i < lines.length; ++i) {
  1331. line = lines[i];
  1332. if (stroke) {
  1333. if (opts.strokeColor) {
  1334. ctx.strokeStyle = opts.strokeColor;
  1335. }
  1336. if (!isNullOrUndef(opts.strokeWidth)) {
  1337. ctx.lineWidth = opts.strokeWidth;
  1338. }
  1339. ctx.strokeText(line, x, y, opts.maxWidth);
  1340. }
  1341. ctx.fillText(line, x, y, opts.maxWidth);
  1342. if (opts.strikethrough || opts.underline) {
  1343. const metrics = ctx.measureText(line);
  1344. const left = x - metrics.actualBoundingBoxLeft;
  1345. const right = x + metrics.actualBoundingBoxRight;
  1346. const top = y - metrics.actualBoundingBoxAscent;
  1347. const bottom = y + metrics.actualBoundingBoxDescent;
  1348. const yDecoration = opts.strikethrough ? (top + bottom) / 2 : bottom;
  1349. ctx.strokeStyle = ctx.fillStyle;
  1350. ctx.beginPath();
  1351. ctx.lineWidth = opts.decorationWidth || 2;
  1352. ctx.moveTo(left, yDecoration);
  1353. ctx.lineTo(right, yDecoration);
  1354. ctx.stroke();
  1355. }
  1356. y += font.lineHeight;
  1357. }
  1358. ctx.restore();
  1359. }
  1360. function addRoundedRectPath(ctx, rect) {
  1361. const {x, y, w, h, radius} = rect;
  1362. ctx.arc(x + radius.topLeft, y + radius.topLeft, radius.topLeft, -HALF_PI, PI, true);
  1363. ctx.lineTo(x, y + h - radius.bottomLeft);
  1364. ctx.arc(x + radius.bottomLeft, y + h - radius.bottomLeft, radius.bottomLeft, PI, HALF_PI, true);
  1365. ctx.lineTo(x + w - radius.bottomRight, y + h);
  1366. ctx.arc(x + w - radius.bottomRight, y + h - radius.bottomRight, radius.bottomRight, HALF_PI, 0, true);
  1367. ctx.lineTo(x + w, y + radius.topRight);
  1368. ctx.arc(x + w - radius.topRight, y + radius.topRight, radius.topRight, 0, -HALF_PI, true);
  1369. ctx.lineTo(x + radius.topLeft, y);
  1370. }
  1371. const LINE_HEIGHT = new RegExp(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
  1372. const FONT_STYLE = new RegExp(/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/);
  1373. function toLineHeight(value, size) {
  1374. const matches = ('' + value).match(LINE_HEIGHT);
  1375. if (!matches || matches[1] === 'normal') {
  1376. return size * 1.2;
  1377. }
  1378. value = +matches[2];
  1379. switch (matches[3]) {
  1380. case 'px':
  1381. return value;
  1382. case '%':
  1383. value /= 100;
  1384. break;
  1385. }
  1386. return size * value;
  1387. }
  1388. const numberOrZero = v => +v || 0;
  1389. function _readValueToProps(value, props) {
  1390. const ret = {};
  1391. const objProps = isObject(props);
  1392. const keys = objProps ? Object.keys(props) : props;
  1393. const read = isObject(value)
  1394. ? objProps
  1395. ? prop => valueOrDefault(value[prop], value[props[prop]])
  1396. : prop => value[prop]
  1397. : () => value;
  1398. for (const prop of keys) {
  1399. ret[prop] = numberOrZero(read(prop));
  1400. }
  1401. return ret;
  1402. }
  1403. function toTRBL(value) {
  1404. return _readValueToProps(value, {top: 'y', right: 'x', bottom: 'y', left: 'x'});
  1405. }
  1406. function toTRBLCorners(value) {
  1407. return _readValueToProps(value, ['topLeft', 'topRight', 'bottomLeft', 'bottomRight']);
  1408. }
  1409. function toPadding(value) {
  1410. const obj = toTRBL(value);
  1411. obj.width = obj.left + obj.right;
  1412. obj.height = obj.top + obj.bottom;
  1413. return obj;
  1414. }
  1415. function toFont(options, fallback) {
  1416. options = options || {};
  1417. fallback = fallback || defaults.font;
  1418. let size = valueOrDefault(options.size, fallback.size);
  1419. if (typeof size === 'string') {
  1420. size = parseInt(size, 10);
  1421. }
  1422. let style = valueOrDefault(options.style, fallback.style);
  1423. if (style && !('' + style).match(FONT_STYLE)) {
  1424. console.warn('Invalid font style specified: "' + style + '"');
  1425. style = '';
  1426. }
  1427. const font = {
  1428. family: valueOrDefault(options.family, fallback.family),
  1429. lineHeight: toLineHeight(valueOrDefault(options.lineHeight, fallback.lineHeight), size),
  1430. size,
  1431. style,
  1432. weight: valueOrDefault(options.weight, fallback.weight),
  1433. string: ''
  1434. };
  1435. font.string = toFontString(font);
  1436. return font;
  1437. }
  1438. function resolve(inputs, context, index, info) {
  1439. let cacheable = true;
  1440. let i, ilen, value;
  1441. for (i = 0, ilen = inputs.length; i < ilen; ++i) {
  1442. value = inputs[i];
  1443. if (value === undefined) {
  1444. continue;
  1445. }
  1446. if (context !== undefined && typeof value === 'function') {
  1447. value = value(context);
  1448. cacheable = false;
  1449. }
  1450. if (index !== undefined && isArray(value)) {
  1451. value = value[index % value.length];
  1452. cacheable = false;
  1453. }
  1454. if (value !== undefined) {
  1455. if (info && !cacheable) {
  1456. info.cacheable = false;
  1457. }
  1458. return value;
  1459. }
  1460. }
  1461. }
  1462. function _addGrace(minmax, grace) {
  1463. const {min, max} = minmax;
  1464. return {
  1465. min: min - Math.abs(toDimension(grace, min)),
  1466. max: max + toDimension(grace, max)
  1467. };
  1468. }
  1469. function _lookup(table, value, cmp) {
  1470. cmp = cmp || ((index) => table[index] < value);
  1471. let hi = table.length - 1;
  1472. let lo = 0;
  1473. let mid;
  1474. while (hi - lo > 1) {
  1475. mid = (lo + hi) >> 1;
  1476. if (cmp(mid)) {
  1477. lo = mid;
  1478. } else {
  1479. hi = mid;
  1480. }
  1481. }
  1482. return {lo, hi};
  1483. }
  1484. const _lookupByKey = (table, key, value) =>
  1485. _lookup(table, value, index => table[index][key] < value);
  1486. const _rlookupByKey = (table, key, value) =>
  1487. _lookup(table, value, index => table[index][key] >= value);
  1488. function _filterBetween(values, min, max) {
  1489. let start = 0;
  1490. let end = values.length;
  1491. while (start < end && values[start] < min) {
  1492. start++;
  1493. }
  1494. while (end > start && values[end - 1] > max) {
  1495. end--;
  1496. }
  1497. return start > 0 || end < values.length
  1498. ? values.slice(start, end)
  1499. : values;
  1500. }
  1501. const arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
  1502. function listenArrayEvents(array, listener) {
  1503. if (array._chartjs) {
  1504. array._chartjs.listeners.push(listener);
  1505. return;
  1506. }
  1507. Object.defineProperty(array, '_chartjs', {
  1508. configurable: true,
  1509. enumerable: false,
  1510. value: {
  1511. listeners: [listener]
  1512. }
  1513. });
  1514. arrayEvents.forEach((key) => {
  1515. const method = '_onData' + _capitalize(key);
  1516. const base = array[key];
  1517. Object.defineProperty(array, key, {
  1518. configurable: true,
  1519. enumerable: false,
  1520. value(...args) {
  1521. const res = base.apply(this, args);
  1522. array._chartjs.listeners.forEach((object) => {
  1523. if (typeof object[method] === 'function') {
  1524. object[method](...args);
  1525. }
  1526. });
  1527. return res;
  1528. }
  1529. });
  1530. });
  1531. }
  1532. function unlistenArrayEvents(array, listener) {
  1533. const stub = array._chartjs;
  1534. if (!stub) {
  1535. return;
  1536. }
  1537. const listeners = stub.listeners;
  1538. const index = listeners.indexOf(listener);
  1539. if (index !== -1) {
  1540. listeners.splice(index, 1);
  1541. }
  1542. if (listeners.length > 0) {
  1543. return;
  1544. }
  1545. arrayEvents.forEach((key) => {
  1546. delete array[key];
  1547. });
  1548. delete array._chartjs;
  1549. }
  1550. function _arrayUnique(items) {
  1551. const set = new Set();
  1552. let i, ilen;
  1553. for (i = 0, ilen = items.length; i < ilen; ++i) {
  1554. set.add(items[i]);
  1555. }
  1556. if (set.size === ilen) {
  1557. return items;
  1558. }
  1559. const result = [];
  1560. set.forEach(item => {
  1561. result.push(item);
  1562. });
  1563. return result;
  1564. }
  1565. function _createResolver(scopes, prefixes = [''], rootScopes = scopes, fallback, getTarget = () => scopes[0]) {
  1566. if (!defined(fallback)) {
  1567. fallback = _resolve('_fallback', scopes);
  1568. }
  1569. const cache = {
  1570. [Symbol.toStringTag]: 'Object',
  1571. _cacheable: true,
  1572. _scopes: scopes,
  1573. _rootScopes: rootScopes,
  1574. _fallback: fallback,
  1575. _getTarget: getTarget,
  1576. override: (scope) => _createResolver([scope, ...scopes], prefixes, rootScopes, fallback),
  1577. };
  1578. return new Proxy(cache, {
  1579. deleteProperty(target, prop) {
  1580. delete target[prop];
  1581. delete target._keys;
  1582. delete scopes[0][prop];
  1583. return true;
  1584. },
  1585. get(target, prop) {
  1586. return _cached(target, prop,
  1587. () => _resolveWithPrefixes(prop, prefixes, scopes, target));
  1588. },
  1589. getOwnPropertyDescriptor(target, prop) {
  1590. return Reflect.getOwnPropertyDescriptor(target._scopes[0], prop);
  1591. },
  1592. getPrototypeOf() {
  1593. return Reflect.getPrototypeOf(scopes[0]);
  1594. },
  1595. has(target, prop) {
  1596. return getKeysFromAllScopes(target).includes(prop);
  1597. },
  1598. ownKeys(target) {
  1599. return getKeysFromAllScopes(target);
  1600. },
  1601. set(target, prop, value) {
  1602. const storage = target._storage || (target._storage = getTarget());
  1603. storage[prop] = value;
  1604. delete target[prop];
  1605. delete target._keys;
  1606. return true;
  1607. }
  1608. });
  1609. }
  1610. function _attachContext(proxy, context, subProxy, descriptorDefaults) {
  1611. const cache = {
  1612. _cacheable: false,
  1613. _proxy: proxy,
  1614. _context: context,
  1615. _subProxy: subProxy,
  1616. _stack: new Set(),
  1617. _descriptors: _descriptors(proxy, descriptorDefaults),
  1618. setContext: (ctx) => _attachContext(proxy, ctx, subProxy, descriptorDefaults),
  1619. override: (scope) => _attachContext(proxy.override(scope), context, subProxy, descriptorDefaults)
  1620. };
  1621. return new Proxy(cache, {
  1622. deleteProperty(target, prop) {
  1623. delete target[prop];
  1624. delete proxy[prop];
  1625. return true;
  1626. },
  1627. get(target, prop, receiver) {
  1628. return _cached(target, prop,
  1629. () => _resolveWithContext(target, prop, receiver));
  1630. },
  1631. getOwnPropertyDescriptor(target, prop) {
  1632. return target._descriptors.allKeys
  1633. ? Reflect.has(proxy, prop) ? {enumerable: true, configurable: true} : undefined
  1634. : Reflect.getOwnPropertyDescriptor(proxy, prop);
  1635. },
  1636. getPrototypeOf() {
  1637. return Reflect.getPrototypeOf(proxy);
  1638. },
  1639. has(target, prop) {
  1640. return Reflect.has(proxy, prop);
  1641. },
  1642. ownKeys() {
  1643. return Reflect.ownKeys(proxy);
  1644. },
  1645. set(target, prop, value) {
  1646. proxy[prop] = value;
  1647. delete target[prop];
  1648. return true;
  1649. }
  1650. });
  1651. }
  1652. function _descriptors(proxy, defaults = {scriptable: true, indexable: true}) {
  1653. const {_scriptable = defaults.scriptable, _indexable = defaults.indexable, _allKeys = defaults.allKeys} = proxy;
  1654. return {
  1655. allKeys: _allKeys,
  1656. scriptable: _scriptable,
  1657. indexable: _indexable,
  1658. isScriptable: isFunction(_scriptable) ? _scriptable : () => _scriptable,
  1659. isIndexable: isFunction(_indexable) ? _indexable : () => _indexable
  1660. };
  1661. }
  1662. const readKey = (prefix, name) => prefix ? prefix + _capitalize(name) : name;
  1663. const needsSubResolver = (prop, value) => isObject(value) && prop !== 'adapters';
  1664. function _cached(target, prop, resolve) {
  1665. let value = target[prop];
  1666. if (defined(value)) {
  1667. return value;
  1668. }
  1669. value = resolve();
  1670. if (defined(value)) {
  1671. target[prop] = value;
  1672. }
  1673. return value;
  1674. }
  1675. function _resolveWithContext(target, prop, receiver) {
  1676. const {_proxy, _context, _subProxy, _descriptors: descriptors} = target;
  1677. let value = _proxy[prop];
  1678. if (isFunction(value) && descriptors.isScriptable(prop)) {
  1679. value = _resolveScriptable(prop, value, target, receiver);
  1680. }
  1681. if (isArray(value) && value.length) {
  1682. value = _resolveArray(prop, value, target, descriptors.isIndexable);
  1683. }
  1684. if (needsSubResolver(prop, value)) {
  1685. value = _attachContext(value, _context, _subProxy && _subProxy[prop], descriptors);
  1686. }
  1687. return value;
  1688. }
  1689. function _resolveScriptable(prop, value, target, receiver) {
  1690. const {_proxy, _context, _subProxy, _stack} = target;
  1691. if (_stack.has(prop)) {
  1692. throw new Error('Recursion detected: ' + [..._stack].join('->') + '->' + prop);
  1693. }
  1694. _stack.add(prop);
  1695. value = value(_context, _subProxy || receiver);
  1696. _stack.delete(prop);
  1697. if (isObject(value)) {
  1698. value = createSubResolver(_proxy._scopes, _proxy, prop, value);
  1699. }
  1700. return value;
  1701. }
  1702. function _resolveArray(prop, value, target, isIndexable) {
  1703. const {_proxy, _context, _subProxy, _descriptors: descriptors} = target;
  1704. if (defined(_context.index) && isIndexable(prop)) {
  1705. value = value[_context.index % value.length];
  1706. } else if (isObject(value[0])) {
  1707. const arr = value;
  1708. const scopes = _proxy._scopes.filter(s => s !== arr);
  1709. value = [];
  1710. for (const item of arr) {
  1711. const resolver = createSubResolver(scopes, _proxy, prop, item);
  1712. value.push(_attachContext(resolver, _context, _subProxy && _subProxy[prop], descriptors));
  1713. }
  1714. }
  1715. return value;
  1716. }
  1717. function resolveFallback(fallback, prop, value) {
  1718. return isFunction(fallback) ? fallback(prop, value) : fallback;
  1719. }
  1720. const getScope = (key, parent) => key === true ? parent
  1721. : typeof key === 'string' ? resolveObjectKey(parent, key) : undefined;
  1722. function addScopes(set, parentScopes, key, parentFallback) {
  1723. for (const parent of parentScopes) {
  1724. const scope = getScope(key, parent);
  1725. if (scope) {
  1726. set.add(scope);
  1727. const fallback = resolveFallback(scope._fallback, key, scope);
  1728. if (defined(fallback) && fallback !== key && fallback !== parentFallback) {
  1729. return fallback;
  1730. }
  1731. } else if (scope === false && defined(parentFallback) && key !== parentFallback) {
  1732. return null;
  1733. }
  1734. }
  1735. return false;
  1736. }
  1737. function createSubResolver(parentScopes, resolver, prop, value) {
  1738. const rootScopes = resolver._rootScopes;
  1739. const fallback = resolveFallback(resolver._fallback, prop, value);
  1740. const allScopes = [...parentScopes, ...rootScopes];
  1741. const set = new Set();
  1742. set.add(value);
  1743. let key = addScopesFromKey(set, allScopes, prop, fallback || prop);
  1744. if (key === null) {
  1745. return false;
  1746. }
  1747. if (defined(fallback) && fallback !== prop) {
  1748. key = addScopesFromKey(set, allScopes, fallback, key);
  1749. if (key === null) {
  1750. return false;
  1751. }
  1752. }
  1753. return _createResolver([...set], [''], rootScopes, fallback, () => {
  1754. const parent = resolver._getTarget();
  1755. if (!(prop in parent)) {
  1756. parent[prop] = {};
  1757. }
  1758. return parent[prop];
  1759. });
  1760. }
  1761. function addScopesFromKey(set, allScopes, key, fallback) {
  1762. while (key) {
  1763. key = addScopes(set, allScopes, key, fallback);
  1764. }
  1765. return key;
  1766. }
  1767. function _resolveWithPrefixes(prop, prefixes, scopes, proxy) {
  1768. let value;
  1769. for (const prefix of prefixes) {
  1770. value = _resolve(readKey(prefix, prop), scopes);
  1771. if (defined(value)) {
  1772. return needsSubResolver(prop, value)
  1773. ? createSubResolver(scopes, proxy, prop, value)
  1774. : value;
  1775. }
  1776. }
  1777. }
  1778. function _resolve(key, scopes) {
  1779. for (const scope of scopes) {
  1780. if (!scope) {
  1781. continue;
  1782. }
  1783. const value = scope[key];
  1784. if (defined(value)) {
  1785. return value;
  1786. }
  1787. }
  1788. }
  1789. function getKeysFromAllScopes(target) {
  1790. let keys = target._keys;
  1791. if (!keys) {
  1792. keys = target._keys = resolveKeysFromAllScopes(target._scopes);
  1793. }
  1794. return keys;
  1795. }
  1796. function resolveKeysFromAllScopes(scopes) {
  1797. const set = new Set();
  1798. for (const scope of scopes) {
  1799. for (const key of Object.keys(scope).filter(k => !k.startsWith('_'))) {
  1800. set.add(key);
  1801. }
  1802. }
  1803. return [...set];
  1804. }
  1805. const EPSILON = Number.EPSILON || 1e-14;
  1806. const getPoint = (points, i) => i < points.length && !points[i].skip && points[i];
  1807. function splineCurve(firstPoint, middlePoint, afterPoint, t) {
  1808. const previous = firstPoint.skip ? middlePoint : firstPoint;
  1809. const current = middlePoint;
  1810. const next = afterPoint.skip ? middlePoint : afterPoint;
  1811. const d01 = distanceBetweenPoints(current, previous);
  1812. const d12 = distanceBetweenPoints(next, current);
  1813. let s01 = d01 / (d01 + d12);
  1814. let s12 = d12 / (d01 + d12);
  1815. s01 = isNaN(s01) ? 0 : s01;
  1816. s12 = isNaN(s12) ? 0 : s12;
  1817. const fa = t * s01;
  1818. const fb = t * s12;
  1819. return {
  1820. previous: {
  1821. x: current.x - fa * (next.x - previous.x),
  1822. y: current.y - fa * (next.y - previous.y)
  1823. },
  1824. next: {
  1825. x: current.x + fb * (next.x - previous.x),
  1826. y: current.y + fb * (next.y - previous.y)
  1827. }
  1828. };
  1829. }
  1830. function monotoneAdjust(points, deltaK, mK) {
  1831. const pointsLen = points.length;
  1832. let alphaK, betaK, tauK, squaredMagnitude, pointCurrent;
  1833. let pointAfter = getPoint(points, 0);
  1834. for (let i = 0; i < pointsLen - 1; ++i) {
  1835. pointCurrent = pointAfter;
  1836. pointAfter = getPoint(points, i + 1);
  1837. if (!pointCurrent || !pointAfter) {
  1838. continue;
  1839. }
  1840. if (almostEquals(deltaK[i], 0, EPSILON)) {
  1841. mK[i] = mK[i + 1] = 0;
  1842. continue;
  1843. }
  1844. alphaK = mK[i] / deltaK[i];
  1845. betaK = mK[i + 1] / deltaK[i];
  1846. squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
  1847. if (squaredMagnitude <= 9) {
  1848. continue;
  1849. }
  1850. tauK = 3 / Math.sqrt(squaredMagnitude);
  1851. mK[i] = alphaK * tauK * deltaK[i];
  1852. mK[i + 1] = betaK * tauK * deltaK[i];
  1853. }
  1854. }
  1855. function monotoneCompute(points, mK) {
  1856. const pointsLen = points.length;
  1857. let deltaX, pointBefore, pointCurrent;
  1858. let pointAfter = getPoint(points, 0);
  1859. for (let i = 0; i < pointsLen; ++i) {
  1860. pointBefore = pointCurrent;
  1861. pointCurrent = pointAfter;
  1862. pointAfter = getPoint(points, i + 1);
  1863. if (!pointCurrent) {
  1864. continue;
  1865. }
  1866. const {x, y} = pointCurrent;
  1867. if (pointBefore) {
  1868. deltaX = (x - pointBefore.x) / 3;
  1869. pointCurrent.cp1x = x - deltaX;
  1870. pointCurrent.cp1y = y - deltaX * mK[i];
  1871. }
  1872. if (pointAfter) {
  1873. deltaX = (pointAfter.x - x) / 3;
  1874. pointCurrent.cp2x = x + deltaX;
  1875. pointCurrent.cp2y = y + deltaX * mK[i];
  1876. }
  1877. }
  1878. }
  1879. function splineCurveMonotone(points) {
  1880. const pointsLen = points.length;
  1881. const deltaK = Array(pointsLen).fill(0);
  1882. const mK = Array(pointsLen);
  1883. let i, pointBefore, pointCurrent;
  1884. let pointAfter = getPoint(points, 0);
  1885. for (i = 0; i < pointsLen; ++i) {
  1886. pointBefore = pointCurrent;
  1887. pointCurrent = pointAfter;
  1888. pointAfter = getPoint(points, i + 1);
  1889. if (!pointCurrent) {
  1890. continue;
  1891. }
  1892. if (pointAfter) {
  1893. const slopeDeltaX = (pointAfter.x - pointCurrent.x);
  1894. deltaK[i] = slopeDeltaX !== 0 ? (pointAfter.y - pointCurrent.y) / slopeDeltaX : 0;
  1895. }
  1896. mK[i] = !pointBefore ? deltaK[i]
  1897. : !pointAfter ? deltaK[i - 1]
  1898. : (sign(deltaK[i - 1]) !== sign(deltaK[i])) ? 0
  1899. : (deltaK[i - 1] + deltaK[i]) / 2;
  1900. }
  1901. monotoneAdjust(points, deltaK, mK);
  1902. monotoneCompute(points, mK);
  1903. }
  1904. function capControlPoint(pt, min, max) {
  1905. return Math.max(Math.min(pt, max), min);
  1906. }
  1907. function capBezierPoints(points, area) {
  1908. let i, ilen, point, inArea, inAreaPrev;
  1909. let inAreaNext = _isPointInArea(points[0], area);
  1910. for (i = 0, ilen = points.length; i < ilen; ++i) {
  1911. inAreaPrev = inArea;
  1912. inArea = inAreaNext;
  1913. inAreaNext = i < ilen - 1 && _isPointInArea(points[i + 1], area);
  1914. if (!inArea) {
  1915. continue;
  1916. }
  1917. point = points[i];
  1918. if (inAreaPrev) {
  1919. point.cp1x = capControlPoint(point.cp1x, area.left, area.right);
  1920. point.cp1y = capControlPoint(point.cp1y, area.top, area.bottom);
  1921. }
  1922. if (inAreaNext) {
  1923. point.cp2x = capControlPoint(point.cp2x, area.left, area.right);
  1924. point.cp2y = capControlPoint(point.cp2y, area.top, area.bottom);
  1925. }
  1926. }
  1927. }
  1928. function _updateBezierControlPoints(points, options, area, loop) {
  1929. let i, ilen, point, controlPoints;
  1930. if (options.spanGaps) {
  1931. points = points.filter((pt) => !pt.skip);
  1932. }
  1933. if (options.cubicInterpolationMode === 'monotone') {
  1934. splineCurveMonotone(points);
  1935. } else {
  1936. let prev = loop ? points[points.length - 1] : points[0];
  1937. for (i = 0, ilen = points.length; i < ilen; ++i) {
  1938. point = points[i];
  1939. controlPoints = splineCurve(
  1940. prev,
  1941. point,
  1942. points[Math.min(i + 1, ilen - (loop ? 0 : 1)) % ilen],
  1943. options.tension
  1944. );
  1945. point.cp1x = controlPoints.previous.x;
  1946. point.cp1y = controlPoints.previous.y;
  1947. point.cp2x = controlPoints.next.x;
  1948. point.cp2y = controlPoints.next.y;
  1949. prev = point;
  1950. }
  1951. }
  1952. if (options.capBezierPoints) {
  1953. capBezierPoints(points, area);
  1954. }
  1955. }
  1956. function _getParentNode(domNode) {
  1957. let parent = domNode.parentNode;
  1958. if (parent && parent.toString() === '[object ShadowRoot]') {
  1959. parent = parent.host;
  1960. }
  1961. return parent;
  1962. }
  1963. function parseMaxStyle(styleValue, node, parentProperty) {
  1964. let valueInPixels;
  1965. if (typeof styleValue === 'string') {
  1966. valueInPixels = parseInt(styleValue, 10);
  1967. if (styleValue.indexOf('%') !== -1) {
  1968. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  1969. }
  1970. } else {
  1971. valueInPixels = styleValue;
  1972. }
  1973. return valueInPixels;
  1974. }
  1975. const getComputedStyle = (element) => window.getComputedStyle(element, null);
  1976. function getStyle(el, property) {
  1977. return getComputedStyle(el).getPropertyValue(property);
  1978. }
  1979. const positions = ['top', 'right', 'bottom', 'left'];
  1980. function getPositionedStyle(styles, style, suffix) {
  1981. const result = {};
  1982. suffix = suffix ? '-' + suffix : '';
  1983. for (let i = 0; i < 4; i++) {
  1984. const pos = positions[i];
  1985. result[pos] = parseFloat(styles[style + '-' + pos + suffix]) || 0;
  1986. }
  1987. result.width = result.left + result.right;
  1988. result.height = result.top + result.bottom;
  1989. return result;
  1990. }
  1991. const useOffsetPos = (x, y, target) => (x > 0 || y > 0) && (!target || !target.shadowRoot);
  1992. function getCanvasPosition(evt, canvas) {
  1993. const e = evt.native || evt;
  1994. const touches = e.touches;
  1995. const source = touches && touches.length ? touches[0] : e;
  1996. const {offsetX, offsetY} = source;
  1997. let box = false;
  1998. let x, y;
  1999. if (useOffsetPos(offsetX, offsetY, e.target)) {
  2000. x = offsetX;
  2001. y = offsetY;
  2002. } else {
  2003. const rect = canvas.getBoundingClientRect();
  2004. x = source.clientX - rect.left;
  2005. y = source.clientY - rect.top;
  2006. box = true;
  2007. }
  2008. return {x, y, box};
  2009. }
  2010. function getRelativePosition(evt, chart) {
  2011. const {canvas, currentDevicePixelRatio} = chart;
  2012. const style = getComputedStyle(canvas);
  2013. const borderBox = style.boxSizing === 'border-box';
  2014. const paddings = getPositionedStyle(style, 'padding');
  2015. const borders = getPositionedStyle(style, 'border', 'width');
  2016. const {x, y, box} = getCanvasPosition(evt, canvas);
  2017. const xOffset = paddings.left + (box && borders.left);
  2018. const yOffset = paddings.top + (box && borders.top);
  2019. let {width, height} = chart;
  2020. if (borderBox) {
  2021. width -= paddings.width + borders.width;
  2022. height -= paddings.height + borders.height;
  2023. }
  2024. return {
  2025. x: Math.round((x - xOffset) / width * canvas.width / currentDevicePixelRatio),
  2026. y: Math.round((y - yOffset) / height * canvas.height / currentDevicePixelRatio)
  2027. };
  2028. }
  2029. function getContainerSize(canvas, width, height) {
  2030. let maxWidth, maxHeight;
  2031. if (width === undefined || height === undefined) {
  2032. const container = _getParentNode(canvas);
  2033. if (!container) {
  2034. width = canvas.clientWidth;
  2035. height = canvas.clientHeight;
  2036. } else {
  2037. const rect = container.getBoundingClientRect();
  2038. const containerStyle = getComputedStyle(container);
  2039. const containerBorder = getPositionedStyle(containerStyle, 'border', 'width');
  2040. const containerPadding = getPositionedStyle(containerStyle, 'padding');
  2041. width = rect.width - containerPadding.width - containerBorder.width;
  2042. height = rect.height - containerPadding.height - containerBorder.height;
  2043. maxWidth = parseMaxStyle(containerStyle.maxWidth, container, 'clientWidth');
  2044. maxHeight = parseMaxStyle(containerStyle.maxHeight, container, 'clientHeight');
  2045. }
  2046. }
  2047. return {
  2048. width,
  2049. height,
  2050. maxWidth: maxWidth || INFINITY,
  2051. maxHeight: maxHeight || INFINITY
  2052. };
  2053. }
  2054. const round1 = v => Math.round(v * 10) / 10;
  2055. function getMaximumSize(canvas, bbWidth, bbHeight, aspectRatio) {
  2056. const style = getComputedStyle(canvas);
  2057. const margins = getPositionedStyle(style, 'margin');
  2058. const maxWidth = parseMaxStyle(style.maxWidth, canvas, 'clientWidth') || INFINITY;
  2059. const maxHeight = parseMaxStyle(style.maxHeight, canvas, 'clientHeight') || INFINITY;
  2060. const containerSize = getContainerSize(canvas, bbWidth, bbHeight);
  2061. let {width, height} = containerSize;
  2062. if (style.boxSizing === 'content-box') {
  2063. const borders = getPositionedStyle(style, 'border', 'width');
  2064. const paddings = getPositionedStyle(style, 'padding');
  2065. width -= paddings.width + borders.width;
  2066. height -= paddings.height + borders.height;
  2067. }
  2068. width = Math.max(0, width - margins.width);
  2069. height = Math.max(0, aspectRatio ? Math.floor(width / aspectRatio) : height - margins.height);
  2070. width = round1(Math.min(width, maxWidth, containerSize.maxWidth));
  2071. height = round1(Math.min(height, maxHeight, containerSize.maxHeight));
  2072. if (width && !height) {
  2073. height = round1(width / 2);
  2074. }
  2075. return {
  2076. width,
  2077. height
  2078. };
  2079. }
  2080. function retinaScale(chart, forceRatio, forceStyle) {
  2081. const pixelRatio = chart.currentDevicePixelRatio = forceRatio || 1;
  2082. const {canvas, width, height} = chart;
  2083. canvas.height = height * pixelRatio;
  2084. canvas.width = width * pixelRatio;
  2085. chart.ctx.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
  2086. if (canvas.style && (forceStyle || (!canvas.style.height && !canvas.style.width))) {
  2087. canvas.style.height = height + 'px';
  2088. canvas.style.width = width + 'px';
  2089. }
  2090. }
  2091. const supportsEventListenerOptions = (function() {
  2092. let passiveSupported = false;
  2093. try {
  2094. const options = {
  2095. get passive() {
  2096. passiveSupported = true;
  2097. return false;
  2098. }
  2099. };
  2100. window.addEventListener('test', null, options);
  2101. window.removeEventListener('test', null, options);
  2102. } catch (e) {
  2103. }
  2104. return passiveSupported;
  2105. }());
  2106. function readUsedSize(element, property) {
  2107. const value = getStyle(element, property);
  2108. const matches = value && value.match(/^(\d+)(\.\d+)?px$/);
  2109. return matches ? +matches[1] : undefined;
  2110. }
  2111. function _pointInLine(p1, p2, t, mode) {
  2112. return {
  2113. x: p1.x + t * (p2.x - p1.x),
  2114. y: p1.y + t * (p2.y - p1.y)
  2115. };
  2116. }
  2117. function _steppedInterpolation(p1, p2, t, mode) {
  2118. return {
  2119. x: p1.x + t * (p2.x - p1.x),
  2120. y: mode === 'middle' ? t < 0.5 ? p1.y : p2.y
  2121. : mode === 'after' ? t < 1 ? p1.y : p2.y
  2122. : t > 0 ? p2.y : p1.y
  2123. };
  2124. }
  2125. function _bezierInterpolation(p1, p2, t, mode) {
  2126. const cp1 = {x: p1.cp2x, y: p1.cp2y};
  2127. const cp2 = {x: p2.cp1x, y: p2.cp1y};
  2128. const a = _pointInLine(p1, cp1, t);
  2129. const b = _pointInLine(cp1, cp2, t);
  2130. const c = _pointInLine(cp2, p2, t);
  2131. const d = _pointInLine(a, b, t);
  2132. const e = _pointInLine(b, c, t);
  2133. return _pointInLine(d, e, t);
  2134. }
  2135. const intlCache = new Map();
  2136. function getNumberFormat(locale, options) {
  2137. options = options || {};
  2138. const cacheKey = locale + JSON.stringify(options);
  2139. let formatter = intlCache.get(cacheKey);
  2140. if (!formatter) {
  2141. formatter = new Intl.NumberFormat(locale, options);
  2142. intlCache.set(cacheKey, formatter);
  2143. }
  2144. return formatter;
  2145. }
  2146. function formatNumber(num, locale, options) {
  2147. return getNumberFormat(locale, options).format(num);
  2148. }
  2149. const getRightToLeftAdapter = function(rectX, width) {
  2150. return {
  2151. x(x) {
  2152. return rectX + rectX + width - x;
  2153. },
  2154. setWidth(w) {
  2155. width = w;
  2156. },
  2157. textAlign(align) {
  2158. if (align === 'center') {
  2159. return align;
  2160. }
  2161. return align === 'right' ? 'left' : 'right';
  2162. },
  2163. xPlus(x, value) {
  2164. return x - value;
  2165. },
  2166. leftForLtr(x, itemWidth) {
  2167. return x - itemWidth;
  2168. },
  2169. };
  2170. };
  2171. const getLeftToRightAdapter = function() {
  2172. return {
  2173. x(x) {
  2174. return x;
  2175. },
  2176. setWidth(w) {
  2177. },
  2178. textAlign(align) {
  2179. return align;
  2180. },
  2181. xPlus(x, value) {
  2182. return x + value;
  2183. },
  2184. leftForLtr(x, _itemWidth) {
  2185. return x;
  2186. },
  2187. };
  2188. };
  2189. function getRtlAdapter(rtl, rectX, width) {
  2190. return rtl ? getRightToLeftAdapter(rectX, width) : getLeftToRightAdapter();
  2191. }
  2192. function overrideTextDirection(ctx, direction) {
  2193. let style, original;
  2194. if (direction === 'ltr' || direction === 'rtl') {
  2195. style = ctx.canvas.style;
  2196. original = [
  2197. style.getPropertyValue('direction'),
  2198. style.getPropertyPriority('direction'),
  2199. ];
  2200. style.setProperty('direction', direction, 'important');
  2201. ctx.prevTextDirection = original;
  2202. }
  2203. }
  2204. function restoreTextDirection(ctx, original) {
  2205. if (original !== undefined) {
  2206. delete ctx.prevTextDirection;
  2207. ctx.canvas.style.setProperty('direction', original[0], original[1]);
  2208. }
  2209. }
  2210. function propertyFn(property) {
  2211. if (property === 'angle') {
  2212. return {
  2213. between: _angleBetween,
  2214. compare: _angleDiff,
  2215. normalize: _normalizeAngle,
  2216. };
  2217. }
  2218. return {
  2219. between: (n, s, e) => n >= Math.min(s, e) && n <= Math.max(e, s),
  2220. compare: (a, b) => a - b,
  2221. normalize: x => x
  2222. };
  2223. }
  2224. function normalizeSegment({start, end, count, loop, style}) {
  2225. return {
  2226. start: start % count,
  2227. end: end % count,
  2228. loop: loop && (end - start + 1) % count === 0,
  2229. style
  2230. };
  2231. }
  2232. function getSegment(segment, points, bounds) {
  2233. const {property, start: startBound, end: endBound} = bounds;
  2234. const {between, normalize} = propertyFn(property);
  2235. const count = points.length;
  2236. let {start, end, loop} = segment;
  2237. let i, ilen;
  2238. if (loop) {
  2239. start += count;
  2240. end += count;
  2241. for (i = 0, ilen = count; i < ilen; ++i) {
  2242. if (!between(normalize(points[start % count][property]), startBound, endBound)) {
  2243. break;
  2244. }
  2245. start--;
  2246. end--;
  2247. }
  2248. start %= count;
  2249. end %= count;
  2250. }
  2251. if (end < start) {
  2252. end += count;
  2253. }
  2254. return {start, end, loop, style: segment.style};
  2255. }
  2256. function _boundSegment(segment, points, bounds) {
  2257. if (!bounds) {
  2258. return [segment];
  2259. }
  2260. const {property, start: startBound, end: endBound} = bounds;
  2261. const count = points.length;
  2262. const {compare, between, normalize} = propertyFn(property);
  2263. const {start, end, loop, style} = getSegment(segment, points, bounds);
  2264. const result = [];
  2265. let inside = false;
  2266. let subStart = null;
  2267. let value, point, prevValue;
  2268. const startIsBefore = () => between(startBound, prevValue, value) && compare(startBound, prevValue) !== 0;
  2269. const endIsBefore = () => compare(endBound, value) === 0 || between(endBound, prevValue, value);
  2270. const shouldStart = () => inside || startIsBefore();
  2271. const shouldStop = () => !inside || endIsBefore();
  2272. for (let i = start, prev = start; i <= end; ++i) {
  2273. point = points[i % count];
  2274. if (point.skip) {
  2275. continue;
  2276. }
  2277. value = normalize(point[property]);
  2278. inside = between(value, startBound, endBound);
  2279. if (subStart === null && shouldStart()) {
  2280. subStart = compare(value, startBound) === 0 ? i : prev;
  2281. }
  2282. if (subStart !== null && shouldStop()) {
  2283. result.push(normalizeSegment({start: subStart, end: i, loop, count, style}));
  2284. subStart = null;
  2285. }
  2286. prev = i;
  2287. prevValue = value;
  2288. }
  2289. if (subStart !== null) {
  2290. result.push(normalizeSegment({start: subStart, end, loop, count, style}));
  2291. }
  2292. return result;
  2293. }
  2294. function _boundSegments(line, bounds) {
  2295. const result = [];
  2296. const segments = line.segments;
  2297. for (let i = 0; i < segments.length; i++) {
  2298. const sub = _boundSegment(segments[i], line.points, bounds);
  2299. if (sub.length) {
  2300. result.push(...sub);
  2301. }
  2302. }
  2303. return result;
  2304. }
  2305. function findStartAndEnd(points, count, loop, spanGaps) {
  2306. let start = 0;
  2307. let end = count - 1;
  2308. if (loop && !spanGaps) {
  2309. while (start < count && !points[start].skip) {
  2310. start++;
  2311. }
  2312. }
  2313. while (start < count && points[start].skip) {
  2314. start++;
  2315. }
  2316. start %= count;
  2317. if (loop) {
  2318. end += start;
  2319. }
  2320. while (end > start && points[end % count].skip) {
  2321. end--;
  2322. }
  2323. end %= count;
  2324. return {start, end};
  2325. }
  2326. function solidSegments(points, start, max, loop) {
  2327. const count = points.length;
  2328. const result = [];
  2329. let last = start;
  2330. let prev = points[start];
  2331. let end;
  2332. for (end = start + 1; end <= max; ++end) {
  2333. const cur = points[end % count];
  2334. if (cur.skip || cur.stop) {
  2335. if (!prev.skip) {
  2336. loop = false;
  2337. result.push({start: start % count, end: (end - 1) % count, loop});
  2338. start = last = cur.stop ? end : null;
  2339. }
  2340. } else {
  2341. last = end;
  2342. if (prev.skip) {
  2343. start = end;
  2344. }
  2345. }
  2346. prev = cur;
  2347. }
  2348. if (last !== null) {
  2349. result.push({start: start % count, end: last % count, loop});
  2350. }
  2351. return result;
  2352. }
  2353. function _computeSegments(line, segmentOptions) {
  2354. const points = line.points;
  2355. const spanGaps = line.options.spanGaps;
  2356. const count = points.length;
  2357. if (!count) {
  2358. return [];
  2359. }
  2360. const loop = !!line._loop;
  2361. const {start, end} = findStartAndEnd(points, count, loop, spanGaps);
  2362. if (spanGaps === true) {
  2363. return splitByStyles([{start, end, loop}], points, segmentOptions);
  2364. }
  2365. const max = end < start ? end + count : end;
  2366. const completeLoop = !!line._fullLoop && start === 0 && end === count - 1;
  2367. return splitByStyles(solidSegments(points, start, max, completeLoop), points, segmentOptions);
  2368. }
  2369. function splitByStyles(segments, points, segmentOptions) {
  2370. if (!segmentOptions || !segmentOptions.setContext || !points) {
  2371. return segments;
  2372. }
  2373. return doSplitByStyles(segments, points, segmentOptions);
  2374. }
  2375. function doSplitByStyles(segments, points, segmentOptions) {
  2376. const count = points.length;
  2377. const result = [];
  2378. let start = segments[0].start;
  2379. let i = start;
  2380. for (const segment of segments) {
  2381. let prevStyle, style;
  2382. let prev = points[start % count];
  2383. for (i = start + 1; i <= segment.end; i++) {
  2384. const pt = points[i % count];
  2385. style = readStyle(segmentOptions.setContext({type: 'segment', p0: prev, p1: pt}));
  2386. if (styleChanged(style, prevStyle)) {
  2387. result.push({start: start, end: i - 1, loop: segment.loop, style: prevStyle});
  2388. prevStyle = style;
  2389. start = i - 1;
  2390. }
  2391. prev = pt;
  2392. prevStyle = style;
  2393. }
  2394. if (start < i - 1) {
  2395. result.push({start, end: i - 1, loop: segment.loop, style});
  2396. start = i - 1;
  2397. }
  2398. }
  2399. return result;
  2400. }
  2401. function readStyle(options) {
  2402. return {
  2403. backgroundColor: options.backgroundColor,
  2404. borderCapStyle: options.borderCapStyle,
  2405. borderDash: options.borderDash,
  2406. borderDashOffset: options.borderDashOffset,
  2407. borderJoinStyle: options.borderJoinStyle,
  2408. borderWidth: options.borderWidth,
  2409. borderColor: options.borderColor
  2410. };
  2411. }
  2412. function styleChanged(style, prevStyle) {
  2413. return prevStyle && JSON.stringify(style) !== JSON.stringify(prevStyle);
  2414. }
  2415. export { merge as $, _isPointInArea as A, _rlookupByKey as B, toPadding as C, each as D, getMaximumSize as E, _getParentNode as F, readUsedSize as G, HALF_PI as H, throttled as I, supportsEventListenerOptions as J, log10 as K, _factorize as L, finiteOrDefault as M, callback as N, _addGrace as O, PI as P, toDegrees as Q, _measureText as R, _int16Range as S, TAU as T, _alignPixel as U, renderText as V, toFont as W, _toLeftRightCenter as X, _alignStartEnd as Y, overrides as Z, _arrayUnique as _, resolve as a, _capitalize as a0, descriptors as a1, isFunction as a2, _attachContext as a3, _createResolver as a4, _descriptors as a5, mergeIf as a6, uid as a7, debounce as a8, retinaScale as a9, niceNum as aA, almostWhole as aB, almostEquals as aC, _decimalPlaces as aD, _longestText as aE, _filterBetween as aF, _lookup as aG, getHoverColor as aH, clone$1 as aI, _merger as aJ, _mergerIf as aK, _deprecated as aL, toFontString as aM, splineCurve as aN, splineCurveMonotone as aO, getStyle as aP, fontString as aQ, toLineHeight as aR, PITAU as aS, INFINITY as aT, RAD_PER_DEG as aU, QUARTER_PI as aV, TWO_THIRDS_PI as aW, _angleDiff as aX, clearCanvas as aa, setsEqual as ab, _elementsEqual as ac, getAngleFromPoint as ad, _readValueToProps as ae, _updateBezierControlPoints as af, _computeSegments as ag, _boundSegments as ah, _steppedInterpolation as ai, _bezierInterpolation as aj, _pointInLine as ak, _steppedLineTo as al, _bezierCurveTo as am, drawPoint as an, addRoundedRectPath as ao, toTRBL as ap, toTRBLCorners as aq, _boundSegment as ar, _normalizeAngle as as, getRtlAdapter as at, overrideTextDirection as au, _textX as av, restoreTextDirection as aw, noop as ax, distanceBetweenPoints as ay, _setMinAndMaxByKey as az, isArray as b, color as c, defaults as d, effects as e, resolveObjectKey as f, isNumberFinite as g, defined as h, isObject as i, isNullOrUndef as j, clipArea as k, listenArrayEvents as l, unclipArea as m, toPercentage as n, toDimension as o, formatNumber as p, _angleBetween as q, requestAnimFrame as r, sign as s, toRadians as t, unlistenArrayEvents as u, valueOrDefault as v, isNumber as w, _limitValue as x, _lookupByKey as y, getRelativePosition as z };