boost.src.js 164 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824
  1. /**
  2. * @license Highcharts JS v9.1.0 (2021-05-04)
  3. *
  4. * Boost module
  5. *
  6. * (c) 2010-2021 Highsoft AS
  7. * Author: Torstein Honsi
  8. *
  9. * License: www.highcharts.com/license
  10. *
  11. * */
  12. 'use strict';
  13. (function (factory) {
  14. if (typeof module === 'object' && module.exports) {
  15. factory['default'] = factory;
  16. module.exports = factory;
  17. } else if (typeof define === 'function' && define.amd) {
  18. define('highcharts/modules/boost', ['highcharts'], function (Highcharts) {
  19. factory(Highcharts);
  20. factory.Highcharts = Highcharts;
  21. return factory;
  22. });
  23. } else {
  24. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  25. }
  26. }(function (Highcharts) {
  27. var _modules = Highcharts ? Highcharts._modules : {};
  28. function _registerModule(obj, path, args, fn) {
  29. if (!obj.hasOwnProperty(path)) {
  30. obj[path] = fn.apply(null, args);
  31. }
  32. }
  33. _registerModule(_modules, 'Extensions/Boost/Boostables.js', [], function () {
  34. /* *
  35. *
  36. * Copyright (c) 2019-2021 Highsoft AS
  37. *
  38. * Boost module: stripped-down renderer for higher performance
  39. *
  40. * License: highcharts.com/license
  41. *
  42. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  43. *
  44. * */
  45. // These are the series we allow boosting for.
  46. var boostables = [
  47. 'area',
  48. 'arearange',
  49. 'column',
  50. 'columnrange',
  51. 'bar',
  52. 'line',
  53. 'scatter',
  54. 'heatmap',
  55. 'bubble',
  56. 'treemap'
  57. ];
  58. return boostables;
  59. });
  60. _registerModule(_modules, 'Extensions/Boost/BoostableMap.js', [_modules['Extensions/Boost/Boostables.js']], function (boostables) {
  61. /* *
  62. *
  63. * Copyright (c) 2019-2021 Highsoft AS
  64. *
  65. * Boost module: stripped-down renderer for higher performance
  66. *
  67. * License: highcharts.com/license
  68. *
  69. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  70. *
  71. * */
  72. // These are the series we allow boosting for.
  73. var boostableMap = {};
  74. boostables.forEach(function (item) {
  75. boostableMap[item] = 1;
  76. });
  77. return boostableMap;
  78. });
  79. _registerModule(_modules, 'Extensions/Boost/WGLShader.js', [_modules['Core/Utilities.js']], function (U) {
  80. /* *
  81. *
  82. * Copyright (c) 2019-2021 Highsoft AS
  83. *
  84. * Boost module: stripped-down renderer for higher performance
  85. *
  86. * License: highcharts.com/license
  87. *
  88. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  89. *
  90. * */
  91. var clamp = U.clamp,
  92. error = U.error,
  93. pick = U.pick;
  94. /* eslint-disable valid-jsdoc */
  95. /**
  96. * A static shader mimicing axis translation functions found in Core/Axis
  97. *
  98. * @private
  99. * @function GLShader
  100. *
  101. * @param {WebGLContext} gl
  102. * the context in which the shader is active
  103. *
  104. * @return {*}
  105. */
  106. function GLShader(gl) {
  107. var vertShade = [
  108. /* eslint-disable max-len, @typescript-eslint/indent */
  109. '#version 100',
  110. '#define LN10 2.302585092994046',
  111. 'precision highp float;',
  112. 'attribute vec4 aVertexPosition;',
  113. 'attribute vec4 aColor;',
  114. 'varying highp vec2 position;',
  115. 'varying highp vec4 vColor;',
  116. 'uniform mat4 uPMatrix;',
  117. 'uniform float pSize;',
  118. 'uniform float translatedThreshold;',
  119. 'uniform bool hasThreshold;',
  120. 'uniform bool skipTranslation;',
  121. 'uniform float xAxisTrans;',
  122. 'uniform float xAxisMin;',
  123. 'uniform float xAxisMinPad;',
  124. 'uniform float xAxisPointRange;',
  125. 'uniform float xAxisLen;',
  126. 'uniform bool xAxisPostTranslate;',
  127. 'uniform float xAxisOrdinalSlope;',
  128. 'uniform float xAxisOrdinalOffset;',
  129. 'uniform float xAxisPos;',
  130. 'uniform bool xAxisCVSCoord;',
  131. 'uniform bool xAxisIsLog;',
  132. 'uniform bool xAxisReversed;',
  133. 'uniform float yAxisTrans;',
  134. 'uniform float yAxisMin;',
  135. 'uniform float yAxisMinPad;',
  136. 'uniform float yAxisPointRange;',
  137. 'uniform float yAxisLen;',
  138. 'uniform bool yAxisPostTranslate;',
  139. 'uniform float yAxisOrdinalSlope;',
  140. 'uniform float yAxisOrdinalOffset;',
  141. 'uniform float yAxisPos;',
  142. 'uniform bool yAxisCVSCoord;',
  143. 'uniform bool yAxisIsLog;',
  144. 'uniform bool yAxisReversed;',
  145. 'uniform bool isBubble;',
  146. 'uniform bool bubbleSizeByArea;',
  147. 'uniform float bubbleZMin;',
  148. 'uniform float bubbleZMax;',
  149. 'uniform float bubbleZThreshold;',
  150. 'uniform float bubbleMinSize;',
  151. 'uniform float bubbleMaxSize;',
  152. 'uniform bool bubbleSizeAbs;',
  153. 'uniform bool isInverted;',
  154. 'float bubbleRadius(){',
  155. 'float value = aVertexPosition.w;',
  156. 'float zMax = bubbleZMax;',
  157. 'float zMin = bubbleZMin;',
  158. 'float radius = 0.0;',
  159. 'float pos = 0.0;',
  160. 'float zRange = zMax - zMin;',
  161. 'if (bubbleSizeAbs){',
  162. 'value = value - bubbleZThreshold;',
  163. 'zMax = max(zMax - bubbleZThreshold, zMin - bubbleZThreshold);',
  164. 'zMin = 0.0;',
  165. '}',
  166. 'if (value < zMin){',
  167. 'radius = bubbleZMin / 2.0 - 1.0;',
  168. '} else {',
  169. 'pos = zRange > 0.0 ? (value - zMin) / zRange : 0.5;',
  170. 'if (bubbleSizeByArea && pos > 0.0){',
  171. 'pos = sqrt(pos);',
  172. '}',
  173. 'radius = ceil(bubbleMinSize + pos * (bubbleMaxSize - bubbleMinSize)) / 2.0;',
  174. '}',
  175. 'return radius * 2.0;',
  176. '}',
  177. 'float translate(float val,',
  178. 'float pointPlacement,',
  179. 'float localA,',
  180. 'float localMin,',
  181. 'float minPixelPadding,',
  182. 'float pointRange,',
  183. 'float len,',
  184. 'bool cvsCoord,',
  185. 'bool isLog,',
  186. 'bool reversed',
  187. '){',
  188. 'float sign = 1.0;',
  189. 'float cvsOffset = 0.0;',
  190. 'if (cvsCoord) {',
  191. 'sign *= -1.0;',
  192. 'cvsOffset = len;',
  193. '}',
  194. 'if (isLog) {',
  195. 'val = log(val) / LN10;',
  196. '}',
  197. 'if (reversed) {',
  198. 'sign *= -1.0;',
  199. 'cvsOffset -= sign * len;',
  200. '}',
  201. 'return sign * (val - localMin) * localA + cvsOffset + ',
  202. '(sign * minPixelPadding);',
  203. '}',
  204. 'float xToPixels(float value) {',
  205. 'if (skipTranslation){',
  206. 'return value;// + xAxisPos;',
  207. '}',
  208. 'return translate(value, 0.0, xAxisTrans, xAxisMin, xAxisMinPad, xAxisPointRange, xAxisLen, xAxisCVSCoord, xAxisIsLog, xAxisReversed);// + xAxisPos;',
  209. '}',
  210. 'float yToPixels(float value, float checkTreshold) {',
  211. 'float v;',
  212. 'if (skipTranslation){',
  213. 'v = value;// + yAxisPos;',
  214. '} else {',
  215. 'v = translate(value, 0.0, yAxisTrans, yAxisMin, yAxisMinPad, yAxisPointRange, yAxisLen, yAxisCVSCoord, yAxisIsLog, yAxisReversed);// + yAxisPos;',
  216. 'if (v > yAxisLen) {',
  217. 'v = yAxisLen;',
  218. '}',
  219. '}',
  220. 'if (checkTreshold > 0.0 && hasThreshold) {',
  221. 'v = min(v, translatedThreshold);',
  222. '}',
  223. 'return v;',
  224. '}',
  225. 'void main(void) {',
  226. 'if (isBubble){',
  227. 'gl_PointSize = bubbleRadius();',
  228. '} else {',
  229. 'gl_PointSize = pSize;',
  230. '}',
  231. // 'gl_PointSize = 10.0;',
  232. 'vColor = aColor;',
  233. 'if (skipTranslation && isInverted) {',
  234. // If we get translated values from JS, just swap them (x, y)
  235. 'gl_Position = uPMatrix * vec4(aVertexPosition.y + yAxisPos, aVertexPosition.x + xAxisPos, 0.0, 1.0);',
  236. '} else if (isInverted) {',
  237. // But when calculating pixel positions directly,
  238. // swap axes and values (x, y)
  239. 'gl_Position = uPMatrix * vec4(yToPixels(aVertexPosition.y, aVertexPosition.z) + yAxisPos, xToPixels(aVertexPosition.x) + xAxisPos, 0.0, 1.0);',
  240. '} else {',
  241. 'gl_Position = uPMatrix * vec4(xToPixels(aVertexPosition.x) + xAxisPos, yToPixels(aVertexPosition.y, aVertexPosition.z) + yAxisPos, 0.0, 1.0);',
  242. '}',
  243. // 'gl_Position = uPMatrix * vec4(aVertexPosition.x, aVertexPosition.y, 0.0, 1.0);',
  244. '}'
  245. /* eslint-enable max-len, @typescript-eslint/indent */
  246. ].join('\n'),
  247. // Fragment shader source
  248. fragShade = [
  249. /* eslint-disable max-len, @typescript-eslint/indent */
  250. 'precision highp float;',
  251. 'uniform vec4 fillColor;',
  252. 'varying highp vec2 position;',
  253. 'varying highp vec4 vColor;',
  254. 'uniform sampler2D uSampler;',
  255. 'uniform bool isCircle;',
  256. 'uniform bool hasColor;',
  257. // 'vec4 toColor(float value, vec2 point) {',
  258. // 'return vec4(0.0, 0.0, 0.0, 0.0);',
  259. // '}',
  260. 'void main(void) {',
  261. 'vec4 col = fillColor;',
  262. 'vec4 tcol = texture2D(uSampler, gl_PointCoord.st);',
  263. 'if (hasColor) {',
  264. 'col = vColor;',
  265. '}',
  266. 'if (isCircle) {',
  267. 'col *= tcol;',
  268. 'if (tcol.r < 0.0) {',
  269. 'discard;',
  270. '} else {',
  271. 'gl_FragColor = col;',
  272. '}',
  273. '} else {',
  274. 'gl_FragColor = col;',
  275. '}',
  276. '}'
  277. /* eslint-enable max-len, @typescript-eslint/indent */
  278. ].join('\n'), uLocations = {},
  279. // The shader program
  280. shaderProgram,
  281. // Uniform handle to the perspective matrix
  282. pUniform,
  283. // Uniform for point size
  284. psUniform,
  285. // Uniform for fill color
  286. fillColorUniform,
  287. // Uniform for isBubble
  288. isBubbleUniform,
  289. // Uniform for bubble abs sizing
  290. bubbleSizeAbsUniform, bubbleSizeAreaUniform,
  291. // Skip translation uniform
  292. skipTranslationUniform,
  293. // Set to 1 if circle
  294. isCircleUniform,
  295. // Uniform for invertion
  296. isInverted,
  297. // Error stack
  298. errors = [],
  299. // Texture uniform
  300. uSamplerUniform;
  301. /**
  302. * Handle errors accumulated in errors stack
  303. * @private
  304. */
  305. function handleErrors() {
  306. if (errors.length) {
  307. error('[highcharts boost] shader error - ' + errors.join('\n'));
  308. }
  309. }
  310. /**
  311. * String to shader program
  312. * @private
  313. * @param {string} str - the program source
  314. * @param {string} type - the program type: either `vertex` or `fragment`
  315. * @returns {bool|shader}
  316. */
  317. function stringToProgram(str, type) {
  318. var t = type === 'vertex' ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER,
  319. shader = gl.createShader(t);
  320. gl.shaderSource(shader, str);
  321. gl.compileShader(shader);
  322. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  323. errors.push('when compiling ' +
  324. type +
  325. ' shader:\n' +
  326. gl.getShaderInfoLog(shader));
  327. return false;
  328. }
  329. return shader;
  330. }
  331. /**
  332. * Create the shader.
  333. * Loads the shader program statically defined above
  334. * @private
  335. */
  336. function createShader() {
  337. var v = stringToProgram(vertShade, 'vertex'), f = stringToProgram(fragShade, 'fragment');
  338. if (!v || !f) {
  339. shaderProgram = false;
  340. handleErrors();
  341. return false;
  342. }
  343. /**
  344. * @private
  345. */
  346. function uloc(n) {
  347. return gl.getUniformLocation(shaderProgram, n);
  348. }
  349. shaderProgram = gl.createProgram();
  350. gl.attachShader(shaderProgram, v);
  351. gl.attachShader(shaderProgram, f);
  352. gl.linkProgram(shaderProgram);
  353. if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
  354. errors.push(gl.getProgramInfoLog(shaderProgram));
  355. handleErrors();
  356. shaderProgram = false;
  357. return false;
  358. }
  359. gl.useProgram(shaderProgram);
  360. gl.bindAttribLocation(shaderProgram, 0, 'aVertexPosition');
  361. pUniform = uloc('uPMatrix');
  362. psUniform = uloc('pSize');
  363. fillColorUniform = uloc('fillColor');
  364. isBubbleUniform = uloc('isBubble');
  365. bubbleSizeAbsUniform = uloc('bubbleSizeAbs');
  366. bubbleSizeAreaUniform = uloc('bubbleSizeByArea');
  367. uSamplerUniform = uloc('uSampler');
  368. skipTranslationUniform = uloc('skipTranslation');
  369. isCircleUniform = uloc('isCircle');
  370. isInverted = uloc('isInverted');
  371. return true;
  372. }
  373. /**
  374. * Destroy the shader
  375. * @private
  376. */
  377. function destroy() {
  378. if (gl && shaderProgram) {
  379. gl.deleteProgram(shaderProgram);
  380. shaderProgram = false;
  381. }
  382. }
  383. /**
  384. * Bind the shader.
  385. * This makes the shader the active one until another one is bound,
  386. * or until 0 is bound.
  387. * @private
  388. */
  389. function bind() {
  390. if (gl && shaderProgram) {
  391. gl.useProgram(shaderProgram);
  392. }
  393. }
  394. /**
  395. * Set a uniform value.
  396. * This uses a hash map to cache uniform locations.
  397. * @private
  398. * @param name {string} - the name of the uniform to set
  399. * @param val {float} - the value to set
  400. */
  401. function setUniform(name, val) {
  402. if (gl && shaderProgram) {
  403. var u = uLocations[name] = (uLocations[name] ||
  404. gl.getUniformLocation(shaderProgram,
  405. name));
  406. gl.uniform1f(u, val);
  407. }
  408. }
  409. /**
  410. * Set the active texture
  411. * @private
  412. * @param texture - the texture
  413. */
  414. function setTexture(texture) {
  415. if (gl && shaderProgram) {
  416. gl.uniform1i(uSamplerUniform, texture);
  417. }
  418. }
  419. /**
  420. * Set if inversion state
  421. * @private
  422. * @flag is the state
  423. */
  424. function setInverted(flag) {
  425. if (gl && shaderProgram) {
  426. gl.uniform1i(isInverted, flag);
  427. }
  428. }
  429. /**
  430. * Enable/disable circle drawing
  431. * @private
  432. */
  433. function setDrawAsCircle(flag) {
  434. if (gl && shaderProgram) {
  435. gl.uniform1i(isCircleUniform, flag ? 1 : 0);
  436. }
  437. }
  438. /**
  439. * Flush
  440. * @private
  441. */
  442. function reset() {
  443. if (gl && shaderProgram) {
  444. gl.uniform1i(isBubbleUniform, 0);
  445. gl.uniform1i(isCircleUniform, 0);
  446. }
  447. }
  448. /**
  449. * Set bubble uniforms
  450. * @private
  451. * @param series {Highcharts.Series} - the series to use
  452. */
  453. function setBubbleUniforms(series, zCalcMin, zCalcMax) {
  454. var seriesOptions = series.options,
  455. zMin = Number.MAX_VALUE,
  456. zMax = -Number.MAX_VALUE;
  457. if (gl && shaderProgram && series.type === 'bubble') {
  458. zMin = pick(seriesOptions.zMin, clamp(zCalcMin, seriesOptions.displayNegative === false ?
  459. seriesOptions.zThreshold : -Number.MAX_VALUE, zMin));
  460. zMax = pick(seriesOptions.zMax, Math.max(zMax, zCalcMax));
  461. gl.uniform1i(isBubbleUniform, 1);
  462. gl.uniform1i(isCircleUniform, 1);
  463. gl.uniform1i(bubbleSizeAreaUniform, (series.options.sizeBy !== 'width'));
  464. gl.uniform1i(bubbleSizeAbsUniform, series.options
  465. .sizeByAbsoluteValue);
  466. setUniform('bubbleZMin', zMin);
  467. setUniform('bubbleZMax', zMax);
  468. setUniform('bubbleZThreshold', series.options.zThreshold);
  469. setUniform('bubbleMinSize', series.minPxSize);
  470. setUniform('bubbleMaxSize', series.maxPxSize);
  471. }
  472. }
  473. /**
  474. * Set the Color uniform.
  475. * @private
  476. * @param color {Array<float>} - an array with RGBA values
  477. */
  478. function setColor(color) {
  479. if (gl && shaderProgram) {
  480. gl.uniform4f(fillColorUniform, color[0] / 255.0, color[1] / 255.0, color[2] / 255.0, color[3]);
  481. }
  482. }
  483. /**
  484. * Set skip translation
  485. * @private
  486. */
  487. function setSkipTranslation(flag) {
  488. if (gl && shaderProgram) {
  489. gl.uniform1i(skipTranslationUniform, flag === true ? 1 : 0);
  490. }
  491. }
  492. /**
  493. * Set the perspective matrix
  494. * @private
  495. * @param m {Matrix4x4} - the matrix
  496. */
  497. function setPMatrix(m) {
  498. if (gl && shaderProgram) {
  499. gl.uniformMatrix4fv(pUniform, false, m);
  500. }
  501. }
  502. /**
  503. * Set the point size.
  504. * @private
  505. * @param p {float} - point size
  506. */
  507. function setPointSize(p) {
  508. if (gl && shaderProgram) {
  509. gl.uniform1f(psUniform, p);
  510. }
  511. }
  512. /**
  513. * Get the shader program handle
  514. * @private
  515. * @return {GLInt} - the handle for the program
  516. */
  517. function getProgram() {
  518. return shaderProgram;
  519. }
  520. if (gl) {
  521. if (!createShader()) {
  522. return false;
  523. }
  524. }
  525. return {
  526. psUniform: function () {
  527. return psUniform;
  528. },
  529. pUniform: function () {
  530. return pUniform;
  531. },
  532. fillColorUniform: function () {
  533. return fillColorUniform;
  534. },
  535. setBubbleUniforms: setBubbleUniforms,
  536. bind: bind,
  537. program: getProgram,
  538. create: createShader,
  539. setUniform: setUniform,
  540. setPMatrix: setPMatrix,
  541. setColor: setColor,
  542. setPointSize: setPointSize,
  543. setSkipTranslation: setSkipTranslation,
  544. setTexture: setTexture,
  545. setDrawAsCircle: setDrawAsCircle,
  546. reset: reset,
  547. setInverted: setInverted,
  548. destroy: destroy
  549. };
  550. }
  551. return GLShader;
  552. });
  553. _registerModule(_modules, 'Extensions/Boost/WGLVBuffer.js', [], function () {
  554. /* *
  555. *
  556. * Copyright (c) 2019-2021 Highsoft AS
  557. *
  558. * Boost module: stripped-down renderer for higher performance
  559. *
  560. * License: highcharts.com/license
  561. *
  562. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  563. *
  564. * */
  565. /* eslint-disable valid-jsdoc */
  566. /**
  567. * Vertex Buffer abstraction.
  568. * A vertex buffer is a set of vertices which are passed to the GPU
  569. * in a single call.
  570. *
  571. * @private
  572. * @function GLVertexBuffer
  573. *
  574. * @param {WebGLContext} gl
  575. * the context in which to create the buffer
  576. *
  577. * @param {GLShader} shader
  578. * the shader to use
  579. *
  580. * @return {*}
  581. */
  582. function GLVertexBuffer(gl, shader, dataComponents
  583. /* , type */
  584. ) {
  585. var buffer = false,
  586. vertAttribute = false,
  587. components = dataComponents || 2,
  588. preAllocated = false,
  589. iterator = 0,
  590. // farray = false,
  591. data;
  592. // type = type || 'float';
  593. /**
  594. * @private
  595. */
  596. function destroy() {
  597. if (buffer) {
  598. gl.deleteBuffer(buffer);
  599. buffer = false;
  600. vertAttribute = false;
  601. }
  602. iterator = 0;
  603. components = dataComponents || 2;
  604. data = [];
  605. }
  606. /**
  607. * Build the buffer
  608. * @private
  609. * @param dataIn {Array<float>} - a 0 padded array of indices
  610. * @param attrib {String} - the name of the Attribute to bind the buffer to
  611. * @param dataComponents {Integer} - the number of components per. indice
  612. */
  613. function build(dataIn, attrib, dataComponents) {
  614. var farray;
  615. data = dataIn || [];
  616. if ((!data || data.length === 0) && !preAllocated) {
  617. // console.error('trying to render empty vbuffer');
  618. destroy();
  619. return false;
  620. }
  621. components = dataComponents || components;
  622. if (buffer) {
  623. gl.deleteBuffer(buffer);
  624. }
  625. if (!preAllocated) {
  626. farray = new Float32Array(data);
  627. }
  628. buffer = gl.createBuffer();
  629. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  630. gl.bufferData(gl.ARRAY_BUFFER, preAllocated || farray, gl.STATIC_DRAW);
  631. // gl.bindAttribLocation(shader.program(), 0, 'aVertexPosition');
  632. vertAttribute = gl.getAttribLocation(shader.program(), attrib);
  633. gl.enableVertexAttribArray(vertAttribute);
  634. // Trigger cleanup
  635. farray = false;
  636. return true;
  637. }
  638. /**
  639. * Bind the buffer
  640. * @private
  641. */
  642. function bind() {
  643. if (!buffer) {
  644. return false;
  645. }
  646. // gl.bindAttribLocation(shader.program(), 0, 'aVertexPosition');
  647. // gl.enableVertexAttribArray(vertAttribute);
  648. // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  649. gl.vertexAttribPointer(vertAttribute, components, gl.FLOAT, false, 0, 0);
  650. // gl.enableVertexAttribArray(vertAttribute);
  651. }
  652. /**
  653. * Render the buffer
  654. * @private
  655. * @param from {Integer} - the start indice
  656. * @param to {Integer} - the end indice
  657. * @param drawMode {String} - the draw mode
  658. */
  659. function render(from, to, drawMode) {
  660. var length = preAllocated ? preAllocated.length : data.length;
  661. if (!buffer) {
  662. return false;
  663. }
  664. if (!length) {
  665. return false;
  666. }
  667. if (!from || from > length || from < 0) {
  668. from = 0;
  669. }
  670. if (!to || to > length) {
  671. to = length;
  672. }
  673. drawMode = drawMode || 'points';
  674. gl.drawArrays(gl[drawMode.toUpperCase()], from / components, (to - from) / components);
  675. return true;
  676. }
  677. /**
  678. * @private
  679. */
  680. function push(x, y, a, b) {
  681. if (preAllocated) { // && iterator <= preAllocated.length - 4) {
  682. preAllocated[++iterator] = x;
  683. preAllocated[++iterator] = y;
  684. preAllocated[++iterator] = a;
  685. preAllocated[++iterator] = b;
  686. }
  687. }
  688. /**
  689. * Note about pre-allocated buffers:
  690. * - This is slower for charts with many series
  691. * @private
  692. */
  693. function allocate(size) {
  694. size *= 4;
  695. iterator = -1;
  696. preAllocated = new Float32Array(size);
  697. }
  698. // /////////////////////////////////////////////////////////////////////////
  699. return {
  700. destroy: destroy,
  701. bind: bind,
  702. data: data,
  703. build: build,
  704. render: render,
  705. allocate: allocate,
  706. push: push
  707. };
  708. }
  709. return GLVertexBuffer;
  710. });
  711. _registerModule(_modules, 'Extensions/Boost/WGLRenderer.js', [_modules['Core/Color/Color.js'], _modules['Extensions/Boost/WGLShader.js'], _modules['Extensions/Boost/WGLVBuffer.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (Color, GLShader, GLVertexBuffer, H, U) {
  712. /* *
  713. *
  714. * Copyright (c) 2019-2021 Highsoft AS
  715. *
  716. * Boost module: stripped-down renderer for higher performance
  717. *
  718. * License: highcharts.com/license
  719. *
  720. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  721. *
  722. * */
  723. var color = Color.parse;
  724. var doc = H.doc;
  725. var isNumber = U.isNumber,
  726. isObject = U.isObject,
  727. merge = U.merge,
  728. objectEach = U.objectEach,
  729. pick = U.pick;
  730. /* eslint-disable valid-jsdoc */
  731. /**
  732. * Main renderer. Used to render series.
  733. *
  734. * Notes to self:
  735. * - May be able to build a point map by rendering to a separate canvas and
  736. * encoding values in the color data.
  737. * - Need to figure out a way to transform the data quicker
  738. *
  739. * @private
  740. * @function GLRenderer
  741. *
  742. * @param {Function} postRenderCallback
  743. *
  744. * @return {*}
  745. */
  746. function GLRenderer(postRenderCallback) {
  747. // // Shader
  748. var shader = false,
  749. // Vertex buffers - keyed on shader attribute name
  750. vbuffer = false,
  751. vlen = 0,
  752. // Opengl context
  753. gl = false,
  754. // Width of our viewport in pixels
  755. width = 0,
  756. // Height of our viewport in pixels
  757. height = 0,
  758. // The data to render - array of coordinates
  759. data = false,
  760. // The marker data
  761. markerData = false,
  762. // Exports
  763. exports = {},
  764. // Is it inited?
  765. isInited = false,
  766. // The series stack
  767. series = [],
  768. // Texture handles
  769. textureHandles = {},
  770. // Things to draw as "rectangles" (i.e lines)
  771. asBar = {
  772. 'column': true,
  773. 'columnrange': true,
  774. 'bar': true,
  775. 'area': true,
  776. 'arearange': true
  777. },
  778. asCircle = {
  779. 'scatter': true,
  780. 'bubble': true
  781. },
  782. // Render settings
  783. settings = {
  784. pointSize: 1,
  785. lineWidth: 1,
  786. fillColor: '#AA00AA',
  787. useAlpha: true,
  788. usePreallocated: false,
  789. useGPUTranslations: false,
  790. debug: {
  791. timeRendering: false,
  792. timeSeriesProcessing: false,
  793. timeSetup: false,
  794. timeBufferCopy: false,
  795. timeKDTree: false,
  796. showSkipSummary: false
  797. }
  798. };
  799. // /////////////////////////////////////////////////////////////////////////
  800. /**
  801. * @private
  802. */
  803. function setOptions(options) {
  804. merge(true, settings, options);
  805. }
  806. /**
  807. * @private
  808. */
  809. function seriesPointCount(series) {
  810. var isStacked,
  811. xData,
  812. s;
  813. if (series.isSeriesBoosting) {
  814. isStacked = !!series.options.stacking;
  815. xData = (series.xData ||
  816. series.options.xData ||
  817. series.processedXData);
  818. s = (isStacked ? series.data : (xData || series.options.data))
  819. .length;
  820. if (series.type === 'treemap') {
  821. s *= 12;
  822. }
  823. else if (series.type === 'heatmap') {
  824. s *= 6;
  825. }
  826. else if (asBar[series.type]) {
  827. s *= 2;
  828. }
  829. return s;
  830. }
  831. return 0;
  832. }
  833. /**
  834. * Allocate a float buffer to fit all series
  835. * @private
  836. */
  837. function allocateBuffer(chart) {
  838. var s = 0;
  839. if (!settings.usePreallocated) {
  840. return;
  841. }
  842. chart.series.forEach(function (series) {
  843. if (series.isSeriesBoosting) {
  844. s += seriesPointCount(series);
  845. }
  846. });
  847. vbuffer.allocate(s);
  848. }
  849. /**
  850. * @private
  851. */
  852. function allocateBufferForSingleSeries(series) {
  853. var s = 0;
  854. if (!settings.usePreallocated) {
  855. return;
  856. }
  857. if (series.isSeriesBoosting) {
  858. s = seriesPointCount(series);
  859. }
  860. vbuffer.allocate(s);
  861. }
  862. /**
  863. * Returns an orthographic perspective matrix
  864. * @private
  865. * @param {number} width - the width of the viewport in pixels
  866. * @param {number} height - the height of the viewport in pixels
  867. */
  868. function orthoMatrix(width, height) {
  869. var near = 0,
  870. far = 1;
  871. return [
  872. 2 / width, 0, 0, 0,
  873. 0, -(2 / height), 0, 0,
  874. 0, 0, -2 / (far - near), 0,
  875. -1, 1, -(far + near) / (far - near), 1
  876. ];
  877. }
  878. /**
  879. * Clear the depth and color buffer
  880. * @private
  881. */
  882. function clear() {
  883. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  884. }
  885. /**
  886. * Get the WebGL context
  887. * @private
  888. * @returns {WebGLContext} - the context
  889. */
  890. function getGL() {
  891. return gl;
  892. }
  893. /**
  894. * Push data for a single series
  895. * This calculates additional vertices and transforms the data to be
  896. * aligned correctly in memory
  897. * @private
  898. */
  899. function pushSeriesData(series, inst) {
  900. var isRange = (series.pointArrayMap &&
  901. series.pointArrayMap.join(',') === 'low,high'), chart = series.chart, options = series.options, isStacked = !!options.stacking, rawData = options.data, xExtremes = series.xAxis.getExtremes(), xMin = xExtremes.min, xMax = xExtremes.max, yExtremes = series.yAxis.getExtremes(), yMin = yExtremes.min, yMax = yExtremes.max, xData = series.xData || options.xData || series.processedXData, yData = series.yData || options.yData || series.processedYData, zData = (series.zData || options.zData ||
  902. series.processedZData), yAxis = series.yAxis, xAxis = series.xAxis,
  903. // plotHeight = series.chart.plotHeight,
  904. plotWidth = series.chart.plotWidth, useRaw = !xData || xData.length === 0,
  905. // threshold = options.threshold,
  906. // yBottom = chart.yAxis[0].getThreshold(threshold),
  907. // hasThreshold = isNumber(threshold),
  908. // colorByPoint = series.options.colorByPoint,
  909. // This is required for color by point, so make sure this is
  910. // uncommented if enabling that
  911. // colorIndex = 0,
  912. // Required for color axis support
  913. // caxis,
  914. connectNulls = options.connectNulls,
  915. // For some reason eslint/TypeScript don't pick up that this is
  916. // actually used: --- bre1470: it is never read, just set
  917. // maxVal: (number|undefined), // eslint-disable-line no-unused-vars
  918. points = series.points || false, lastX = false, lastY = false, minVal, scolor, sdata = isStacked ? series.data : (xData || rawData), closestLeft = { x: Number.MAX_VALUE, y: 0 }, closestRight = { x: -Number.MAX_VALUE, y: 0 },
  919. //
  920. skipped = 0, hadPoints = false,
  921. //
  922. cullXThreshold = 1, cullYThreshold = 1,
  923. // The following are used in the builder while loop
  924. x, y, d, z, i = -1, px = false, nx = false, low, chartDestroyed = typeof chart.index === 'undefined', nextInside = false, prevInside = false, pcolor = false, drawAsBar = asBar[series.type], isXInside = false, isYInside = true, firstPoint = true, zoneAxis = options.zoneAxis || 'y', zones = options.zones || false, zoneDefColor = false, threshold = options.threshold, gapSize = false;
  925. if (options.boostData && options.boostData.length > 0) {
  926. return;
  927. }
  928. if (options.gapSize) {
  929. gapSize = options.gapUnit !== 'value' ?
  930. options.gapSize * series.closestPointRange :
  931. options.gapSize;
  932. }
  933. if (zones) {
  934. zones.some(function (zone) {
  935. if (typeof zone.value === 'undefined') {
  936. zoneDefColor = new Color(zone.color);
  937. return true;
  938. }
  939. return false;
  940. });
  941. if (!zoneDefColor) {
  942. zoneDefColor = ((series.pointAttribs && series.pointAttribs().fill) ||
  943. series.color);
  944. zoneDefColor = new Color(zoneDefColor);
  945. }
  946. }
  947. if (chart.inverted) {
  948. // plotHeight = series.chart.plotWidth;
  949. plotWidth = series.chart.plotHeight;
  950. }
  951. series.closestPointRangePx = Number.MAX_VALUE;
  952. /**
  953. * Push color to color buffer - need to do this per vertex.
  954. * @private
  955. */
  956. function pushColor(color) {
  957. if (color) {
  958. inst.colorData.push(color[0]);
  959. inst.colorData.push(color[1]);
  960. inst.colorData.push(color[2]);
  961. inst.colorData.push(color[3]);
  962. }
  963. }
  964. /**
  965. * Push a vertice to the data buffer.
  966. * @private
  967. */
  968. function vertice(x, y, checkTreshold, pointSize, color) {
  969. pushColor(color);
  970. if (settings.usePreallocated) {
  971. vbuffer.push(x, y, checkTreshold ? 1 : 0, pointSize || 1);
  972. vlen += 4;
  973. }
  974. else {
  975. data.push(x);
  976. data.push(y);
  977. data.push(checkTreshold ? 1 : 0);
  978. data.push(pointSize || 1);
  979. }
  980. }
  981. /**
  982. * @private
  983. */
  984. function closeSegment() {
  985. if (inst.segments.length) {
  986. inst.segments[inst.segments.length - 1].to = data.length || vlen;
  987. }
  988. }
  989. /**
  990. * Create a new segment for the current set.
  991. * @private
  992. */
  993. function beginSegment() {
  994. // Insert a segment on the series.
  995. // A segment is just a start indice.
  996. // When adding a segment, if one exists from before, it should
  997. // set the previous segment's end
  998. if (inst.segments.length &&
  999. inst.segments[inst.segments.length - 1].from === (data.length || vlen)) {
  1000. return;
  1001. }
  1002. closeSegment();
  1003. inst.segments.push({
  1004. from: data.length || vlen
  1005. });
  1006. }
  1007. /**
  1008. * Push a rectangle to the data buffer.
  1009. * @private
  1010. */
  1011. function pushRect(x, y, w, h, color) {
  1012. pushColor(color);
  1013. vertice(x + w, y);
  1014. pushColor(color);
  1015. vertice(x, y);
  1016. pushColor(color);
  1017. vertice(x, y + h);
  1018. pushColor(color);
  1019. vertice(x, y + h);
  1020. pushColor(color);
  1021. vertice(x + w, y + h);
  1022. pushColor(color);
  1023. vertice(x + w, y);
  1024. }
  1025. // Create the first segment
  1026. beginSegment();
  1027. // Special case for point shapes
  1028. if (points && points.length > 0) {
  1029. // If we're doing points, we assume that the points are already
  1030. // translated, so we skip the shader translation.
  1031. inst.skipTranslation = true;
  1032. // Force triangle draw mode
  1033. inst.drawMode = 'triangles';
  1034. // We don't have a z component in the shader, so we need to sort.
  1035. if (points[0].node && points[0].node.levelDynamic) {
  1036. points.sort(function (a, b) {
  1037. if (a.node) {
  1038. if (a.node.levelDynamic >
  1039. b.node.levelDynamic) {
  1040. return 1;
  1041. }
  1042. if (a.node.levelDynamic <
  1043. b.node.levelDynamic) {
  1044. return -1;
  1045. }
  1046. }
  1047. return 0;
  1048. });
  1049. }
  1050. points.forEach(function (point) {
  1051. var plotY = point.plotY,
  1052. swidth,
  1053. pointAttr;
  1054. if (typeof plotY !== 'undefined' &&
  1055. !isNaN(plotY) &&
  1056. point.y !== null &&
  1057. point.shapeArgs) {
  1058. var _a = point.shapeArgs,
  1059. _b = _a.x,
  1060. x_1 = _b === void 0 ? 0 : _b,
  1061. _c = _a.y,
  1062. y_1 = _c === void 0 ? 0 : _c,
  1063. _d = _a.width,
  1064. width_1 = _d === void 0 ? 0 : _d,
  1065. _e = _a.height,
  1066. height_1 = _e === void 0 ? 0 : _e;
  1067. pointAttr = chart.styledMode ?
  1068. point.series
  1069. .colorAttribs(point) :
  1070. pointAttr = point.series.pointAttribs(point);
  1071. swidth = pointAttr['stroke-width'] || 0;
  1072. // Handle point colors
  1073. pcolor = color(pointAttr.fill).rgba;
  1074. pcolor[0] /= 255.0;
  1075. pcolor[1] /= 255.0;
  1076. pcolor[2] /= 255.0;
  1077. // So there are two ways of doing this. Either we can
  1078. // create a rectangle of two triangles, or we can do a
  1079. // point and use point size. Latter is faster, but
  1080. // only supports squares. So we're doing triangles.
  1081. // We could also use one color per. vertice to get
  1082. // better color interpolation.
  1083. // If there's stroking, we do an additional rect
  1084. if (series.type === 'treemap') {
  1085. swidth = swidth || 1;
  1086. scolor = color(pointAttr.stroke).rgba;
  1087. scolor[0] /= 255.0;
  1088. scolor[1] /= 255.0;
  1089. scolor[2] /= 255.0;
  1090. pushRect(x_1, y_1, width_1, height_1, scolor);
  1091. swidth /= 2;
  1092. }
  1093. // } else {
  1094. // swidth = 0;
  1095. // }
  1096. // Fixes issues with inverted heatmaps (see #6981)
  1097. // The root cause is that the coordinate system is flipped.
  1098. // In other words, instead of [0,0] being top-left, it's
  1099. // bottom-right. This causes a vertical and horizontal flip
  1100. // in the resulting image, making it rotated 180 degrees.
  1101. if (series.type === 'heatmap' && chart.inverted) {
  1102. x_1 = xAxis.len - x_1;
  1103. y_1 = yAxis.len - y_1;
  1104. width_1 = -width_1;
  1105. height_1 = -height_1;
  1106. }
  1107. pushRect(x_1 + swidth, y_1 + swidth, width_1 - (swidth * 2), height_1 - (swidth * 2), pcolor);
  1108. }
  1109. });
  1110. closeSegment();
  1111. return;
  1112. }
  1113. // Extract color axis
  1114. // (chart.axes || []).forEach(function (a) {
  1115. // if (H.ColorAxis && a instanceof H.ColorAxis) {
  1116. // caxis = a;
  1117. // }
  1118. // });
  1119. while (i < sdata.length - 1) {
  1120. d = sdata[++i];
  1121. if (typeof d === 'undefined') {
  1122. continue;
  1123. }
  1124. // px = x = y = z = nx = low = false;
  1125. // chartDestroyed = typeof chart.index === 'undefined';
  1126. // nextInside = prevInside = pcolor = isXInside = isYInside = false;
  1127. // drawAsBar = asBar[series.type];
  1128. if (chartDestroyed) {
  1129. break;
  1130. }
  1131. // Uncomment this to enable color by point.
  1132. // This currently left disabled as the charts look really ugly
  1133. // when enabled and there's a lot of points.
  1134. // Leaving in for the future (tm).
  1135. // if (colorByPoint) {
  1136. // colorIndex = ++colorIndex %
  1137. // series.chart.options.colors.length;
  1138. // pcolor = toRGBAFast(series.chart.options.colors[colorIndex]);
  1139. // pcolor[0] /= 255.0;
  1140. // pcolor[1] /= 255.0;
  1141. // pcolor[2] /= 255.0;
  1142. // }
  1143. // Handle the point.color option (#5999)
  1144. var pointOptions = rawData && rawData[i];
  1145. if (!useRaw && isObject(pointOptions, true)) {
  1146. if (pointOptions.color) {
  1147. pcolor = color(pointOptions.color).rgba;
  1148. pcolor[0] /= 255.0;
  1149. pcolor[1] /= 255.0;
  1150. pcolor[2] /= 255.0;
  1151. }
  1152. }
  1153. if (useRaw) {
  1154. x = d[0];
  1155. y = d[1];
  1156. if (sdata[i + 1]) {
  1157. nx = sdata[i + 1][0];
  1158. }
  1159. if (sdata[i - 1]) {
  1160. px = sdata[i - 1][0];
  1161. }
  1162. if (d.length >= 3) {
  1163. z = d[2];
  1164. if (d[2] > inst.zMax) {
  1165. inst.zMax = d[2];
  1166. }
  1167. if (d[2] < inst.zMin) {
  1168. inst.zMin = d[2];
  1169. }
  1170. }
  1171. }
  1172. else {
  1173. x = d;
  1174. y = yData[i];
  1175. if (sdata[i + 1]) {
  1176. nx = sdata[i + 1];
  1177. }
  1178. if (sdata[i - 1]) {
  1179. px = sdata[i - 1];
  1180. }
  1181. if (zData && zData.length) {
  1182. z = zData[i];
  1183. if (zData[i] > inst.zMax) {
  1184. inst.zMax = zData[i];
  1185. }
  1186. if (zData[i] < inst.zMin) {
  1187. inst.zMin = zData[i];
  1188. }
  1189. }
  1190. }
  1191. if (!connectNulls && (x === null || y === null)) {
  1192. beginSegment();
  1193. continue;
  1194. }
  1195. if (nx && nx >= xMin && nx <= xMax) {
  1196. nextInside = true;
  1197. }
  1198. if (px && px >= xMin && px <= xMax) {
  1199. prevInside = true;
  1200. }
  1201. if (isRange) {
  1202. if (useRaw) {
  1203. y = d.slice(1, 3);
  1204. }
  1205. low = y[0];
  1206. y = y[1];
  1207. }
  1208. else if (isStacked) {
  1209. x = d.x;
  1210. y = d.stackY;
  1211. low = y - d.y;
  1212. }
  1213. if (yMin !== null &&
  1214. typeof yMin !== 'undefined' &&
  1215. yMax !== null &&
  1216. typeof yMax !== 'undefined') {
  1217. isYInside = y >= yMin && y <= yMax;
  1218. }
  1219. if (x > xMax && closestRight.x < xMax) {
  1220. closestRight.x = x;
  1221. closestRight.y = y;
  1222. }
  1223. if (x < xMin && closestLeft.x > xMin) {
  1224. closestLeft.x = x;
  1225. closestLeft.y = y;
  1226. }
  1227. if (y === null && connectNulls) {
  1228. continue;
  1229. }
  1230. // Cull points outside the extremes
  1231. if (y === null || (!isYInside && !nextInside && !prevInside)) {
  1232. beginSegment();
  1233. continue;
  1234. }
  1235. // The first point before and first after extremes should be
  1236. // rendered (#9962)
  1237. if ((nx >= xMin || x >= xMin) &&
  1238. (px <= xMax || x <= xMax)) {
  1239. isXInside = true;
  1240. }
  1241. if (!isXInside && !nextInside && !prevInside) {
  1242. continue;
  1243. }
  1244. if (gapSize && x - px > gapSize) {
  1245. beginSegment();
  1246. }
  1247. // Note: Boost requires that zones are sorted!
  1248. if (zones) {
  1249. pcolor = zoneDefColor.rgba.slice();
  1250. zones.some(function (// eslint-disable-line no-loop-func
  1251. zone, i) {
  1252. var last = zones[i - 1];
  1253. if (zoneAxis === 'x') {
  1254. if (typeof zone.value !== 'undefined' && x <= zone.value) {
  1255. if (!last || x >= last.value) {
  1256. pcolor = color(zone.color).rgba;
  1257. }
  1258. return true;
  1259. }
  1260. return false;
  1261. }
  1262. if (typeof zone.value !== 'undefined' && y <= zone.value) {
  1263. if (!last || y >= last.value) {
  1264. pcolor = color(zone.color).rgba;
  1265. }
  1266. return true;
  1267. }
  1268. return false;
  1269. });
  1270. pcolor[0] /= 255.0;
  1271. pcolor[1] /= 255.0;
  1272. pcolor[2] /= 255.0;
  1273. }
  1274. // Skip translations - temporary floating point fix
  1275. if (!settings.useGPUTranslations) {
  1276. inst.skipTranslation = true;
  1277. x = xAxis.toPixels(x, true);
  1278. y = yAxis.toPixels(y, true);
  1279. // Make sure we're not drawing outside of the chart area.
  1280. // See #6594. Update: this is no longer required as far as I
  1281. // can tell. Leaving in for git blame in case there are edge
  1282. // cases I've not found. Having this in breaks #10246.
  1283. // if (y > plotHeight) {
  1284. // y = plotHeight;
  1285. // }
  1286. if (x > plotWidth) {
  1287. // If this is rendered as a point, just skip drawing it
  1288. // entirely, as we're not dependandt on lineTo'ing to it.
  1289. // See #8197
  1290. if (inst.drawMode === 'points') {
  1291. continue;
  1292. }
  1293. // Having this here will clamp markers and make the angle
  1294. // of the last line wrong. See 9166.
  1295. // x = plotWidth;
  1296. }
  1297. }
  1298. // No markers on out of bounds things.
  1299. // Out of bound things are shown if and only if the next
  1300. // or previous point is inside the rect.
  1301. if (inst.hasMarkers && isXInside) {
  1302. // x = Highcharts.correctFloat(
  1303. // Math.min(Math.max(-1e5, xAxis.translate(
  1304. // x,
  1305. // 0,
  1306. // 0,
  1307. // 0,
  1308. // 1,
  1309. // 0.5,
  1310. // false
  1311. // )), 1e5)
  1312. // );
  1313. if (lastX !== false) {
  1314. series.closestPointRangePx = Math.min(series.closestPointRangePx, Math.abs(x - lastX));
  1315. }
  1316. }
  1317. // If the last _drawn_ point is closer to this point than the
  1318. // threshold, skip it. Shaves off 20-100ms in processing.
  1319. if (!settings.useGPUTranslations &&
  1320. !settings.usePreallocated &&
  1321. (lastX && Math.abs(x - lastX) < cullXThreshold) &&
  1322. (lastY && Math.abs(y - lastY) < cullYThreshold)) {
  1323. if (settings.debug.showSkipSummary) {
  1324. ++skipped;
  1325. }
  1326. continue;
  1327. }
  1328. if (drawAsBar) {
  1329. // maxVal = y;
  1330. minVal = low;
  1331. if (low === false || typeof low === 'undefined') {
  1332. if (y < 0) {
  1333. minVal = y;
  1334. }
  1335. else {
  1336. minVal = 0;
  1337. }
  1338. }
  1339. if (!isRange && !isStacked) {
  1340. minVal = Math.max(threshold === null ? yMin : threshold, // #5268
  1341. yMin); // #8731
  1342. }
  1343. if (!settings.useGPUTranslations) {
  1344. minVal = yAxis.toPixels(minVal, true);
  1345. }
  1346. // Need to add an extra point here
  1347. vertice(x, minVal, 0, 0, pcolor);
  1348. }
  1349. // Do step line if enabled.
  1350. // Draws an additional point at the old Y at the new X.
  1351. // See #6976.
  1352. if (options.step && !firstPoint) {
  1353. vertice(x, lastY, 0, 2, pcolor);
  1354. }
  1355. vertice(x, y, 0, series.type === 'bubble' ? (z || 1) : 2, pcolor);
  1356. // Uncomment this to support color axis.
  1357. // if (caxis) {
  1358. // pcolor = color(caxis.toColor(y)).rgba;
  1359. // inst.colorData.push(color[0] / 255.0);
  1360. // inst.colorData.push(color[1] / 255.0);
  1361. // inst.colorData.push(color[2] / 255.0);
  1362. // inst.colorData.push(color[3]);
  1363. // }
  1364. lastX = x;
  1365. lastY = y;
  1366. hadPoints = true;
  1367. firstPoint = false;
  1368. }
  1369. if (settings.debug.showSkipSummary) {
  1370. console.log('skipped points:', skipped); // eslint-disable-line no-console
  1371. }
  1372. /**
  1373. * @private
  1374. */
  1375. function pushSupplementPoint(point, atStart) {
  1376. if (!settings.useGPUTranslations) {
  1377. inst.skipTranslation = true;
  1378. point.x = xAxis.toPixels(point.x, true);
  1379. point.y = yAxis.toPixels(point.y, true);
  1380. }
  1381. // We should only do this for lines, and we should ignore markers
  1382. // since there's no point here that would have a marker.
  1383. if (atStart) {
  1384. data = [point.x, point.y, 0, 2].concat(data);
  1385. return;
  1386. }
  1387. vertice(point.x, point.y, 0, 2);
  1388. }
  1389. if (!hadPoints &&
  1390. connectNulls !== false &&
  1391. series.drawMode === 'line_strip') {
  1392. if (closestLeft.x < Number.MAX_VALUE) {
  1393. // We actually need to push this *before* the complete buffer.
  1394. pushSupplementPoint(closestLeft, true);
  1395. }
  1396. if (closestRight.x > -Number.MAX_VALUE) {
  1397. pushSupplementPoint(closestRight);
  1398. }
  1399. }
  1400. closeSegment();
  1401. }
  1402. /**
  1403. * Push a series to the renderer
  1404. * If we render the series immediatly, we don't have to loop later
  1405. * @private
  1406. * @param s {Highchart.Series} - the series to push
  1407. */
  1408. function pushSeries(s) {
  1409. if (series.length > 0) {
  1410. // series[series.length - 1].to = data.length;
  1411. if (series[series.length - 1].hasMarkers) {
  1412. series[series.length - 1].markerTo = markerData.length;
  1413. }
  1414. }
  1415. if (settings.debug.timeSeriesProcessing) {
  1416. console.time('building ' + s.type + ' series'); // eslint-disable-line no-console
  1417. }
  1418. var obj = {
  1419. segments: [],
  1420. // from: data.length,
  1421. markerFrom: markerData.length,
  1422. // Push RGBA values to this array to use per. point coloring.
  1423. // It should be 0-padded, so each component should be pushed in
  1424. // succession.
  1425. colorData: [],
  1426. series: s,
  1427. zMin: Number.MAX_VALUE,
  1428. zMax: -Number.MAX_VALUE,
  1429. hasMarkers: s.options.marker ?
  1430. s.options.marker.enabled !== false :
  1431. false,
  1432. showMarkers: true,
  1433. drawMode: {
  1434. 'area': 'lines',
  1435. 'arearange': 'lines',
  1436. 'areaspline': 'line_strip',
  1437. 'column': 'lines',
  1438. 'columnrange': 'lines',
  1439. 'bar': 'lines',
  1440. 'line': 'line_strip',
  1441. 'scatter': 'points',
  1442. 'heatmap': 'triangles',
  1443. 'treemap': 'triangles',
  1444. 'bubble': 'points'
  1445. }[s.type] || 'line_strip'
  1446. };
  1447. if (s.index >= series.length) {
  1448. series.push(obj);
  1449. }
  1450. else {
  1451. series[s.index] = obj;
  1452. }
  1453. // Add the series data to our buffer(s)
  1454. pushSeriesData(s, obj);
  1455. if (settings.debug.timeSeriesProcessing) {
  1456. console.timeEnd('building ' + s.type + ' series'); // eslint-disable-line no-console
  1457. }
  1458. }
  1459. /**
  1460. * Flush the renderer.
  1461. * This removes pushed series and vertices.
  1462. * Should be called after clearing and before rendering
  1463. * @private
  1464. */
  1465. function flush() {
  1466. series = [];
  1467. exports.data = data = [];
  1468. markerData = [];
  1469. if (vbuffer) {
  1470. vbuffer.destroy();
  1471. }
  1472. }
  1473. /**
  1474. * Pass x-axis to shader
  1475. * @private
  1476. * @param axis {Highcharts.Axis} - the x-axis
  1477. */
  1478. function setXAxis(axis) {
  1479. if (!shader) {
  1480. return;
  1481. }
  1482. shader.setUniform('xAxisTrans', axis.transA);
  1483. shader.setUniform('xAxisMin', axis.min);
  1484. shader.setUniform('xAxisMinPad', axis.minPixelPadding);
  1485. shader.setUniform('xAxisPointRange', axis.pointRange);
  1486. shader.setUniform('xAxisLen', axis.len);
  1487. shader.setUniform('xAxisPos', axis.pos);
  1488. shader.setUniform('xAxisCVSCoord', (!axis.horiz));
  1489. shader.setUniform('xAxisIsLog', (!!axis.logarithmic));
  1490. shader.setUniform('xAxisReversed', (!!axis.reversed));
  1491. }
  1492. /**
  1493. * Pass y-axis to shader
  1494. * @private
  1495. * @param axis {Highcharts.Axis} - the y-axis
  1496. */
  1497. function setYAxis(axis) {
  1498. if (!shader) {
  1499. return;
  1500. }
  1501. shader.setUniform('yAxisTrans', axis.transA);
  1502. shader.setUniform('yAxisMin', axis.min);
  1503. shader.setUniform('yAxisMinPad', axis.minPixelPadding);
  1504. shader.setUniform('yAxisPointRange', axis.pointRange);
  1505. shader.setUniform('yAxisLen', axis.len);
  1506. shader.setUniform('yAxisPos', axis.pos);
  1507. shader.setUniform('yAxisCVSCoord', (!axis.horiz));
  1508. shader.setUniform('yAxisIsLog', (!!axis.logarithmic));
  1509. shader.setUniform('yAxisReversed', (!!axis.reversed));
  1510. }
  1511. /**
  1512. * Set the translation threshold
  1513. * @private
  1514. * @param has {boolean} - has threshold flag
  1515. * @param translation {Float} - the threshold
  1516. */
  1517. function setThreshold(has, translation) {
  1518. shader.setUniform('hasThreshold', has);
  1519. shader.setUniform('translatedThreshold', translation);
  1520. }
  1521. /**
  1522. * Render the data
  1523. * This renders all pushed series.
  1524. * @private
  1525. */
  1526. function render(chart) {
  1527. if (chart) {
  1528. if (!chart.chartHeight || !chart.chartWidth) {
  1529. // chart.setChartSize();
  1530. }
  1531. width = chart.chartWidth || 800;
  1532. height = chart.chartHeight || 400;
  1533. }
  1534. else {
  1535. return false;
  1536. }
  1537. if (!gl || !width || !height || !shader) {
  1538. return false;
  1539. }
  1540. if (settings.debug.timeRendering) {
  1541. console.time('gl rendering'); // eslint-disable-line no-console
  1542. }
  1543. gl.canvas.width = width;
  1544. gl.canvas.height = height;
  1545. shader.bind();
  1546. gl.viewport(0, 0, width, height);
  1547. shader.setPMatrix(orthoMatrix(width, height));
  1548. if (settings.lineWidth > 1 && !H.isMS) {
  1549. gl.lineWidth(settings.lineWidth);
  1550. }
  1551. vbuffer.build(exports.data, 'aVertexPosition', 4);
  1552. vbuffer.bind();
  1553. shader.setInverted(chart.inverted);
  1554. // Render the series
  1555. series.forEach(function (s, si) {
  1556. var options = s.series.options,
  1557. shapeOptions = options.marker,
  1558. sindex,
  1559. lineWidth = (typeof options.lineWidth !== 'undefined' ?
  1560. options.lineWidth :
  1561. 1),
  1562. threshold = options.threshold,
  1563. hasThreshold = isNumber(threshold),
  1564. yBottom = s.series.yAxis.getThreshold(threshold),
  1565. translatedThreshold = yBottom,
  1566. cbuffer,
  1567. showMarkers = pick(options.marker ? options.marker.enabled : null,
  1568. s.series.xAxis.isRadial ? true : null,
  1569. s.series.closestPointRangePx >
  1570. 2 * ((options.marker ?
  1571. options.marker.radius :
  1572. 10) || 10)),
  1573. fillColor,
  1574. shapeTexture = textureHandles[(shapeOptions && shapeOptions.symbol) ||
  1575. s.series.symbol] || textureHandles.circle,
  1576. scolor = [];
  1577. if (s.segments.length === 0 ||
  1578. (s.segmentslength &&
  1579. s.segments[0].from === s.segments[0].to)) {
  1580. return;
  1581. }
  1582. if (shapeTexture.isReady) {
  1583. gl.bindTexture(gl.TEXTURE_2D, shapeTexture.handle);
  1584. shader.setTexture(shapeTexture.handle);
  1585. }
  1586. if (chart.styledMode) {
  1587. fillColor = (s.series.markerGroup &&
  1588. s.series.markerGroup.getStyle('fill'));
  1589. }
  1590. else {
  1591. fillColor =
  1592. (s.drawMode === 'points' && // #14260
  1593. s.series.pointAttribs &&
  1594. s.series.pointAttribs().fill) ||
  1595. s.series.color;
  1596. if (options.colorByPoint) {
  1597. fillColor = s.series.chart.options.colors[si];
  1598. }
  1599. }
  1600. if (s.series.fillOpacity && options.fillOpacity) {
  1601. fillColor = new Color(fillColor).setOpacity(pick(options.fillOpacity, 1.0)).get();
  1602. }
  1603. scolor = color(fillColor).rgba;
  1604. if (!settings.useAlpha) {
  1605. scolor[3] = 1.0;
  1606. }
  1607. // This is very much temporary
  1608. if (s.drawMode === 'lines' &&
  1609. settings.useAlpha &&
  1610. scolor[3] < 1) {
  1611. scolor[3] /= 10;
  1612. }
  1613. // Blending
  1614. if (options.boostBlending === 'add') {
  1615. gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  1616. gl.blendEquation(gl.FUNC_ADD);
  1617. }
  1618. else if (options.boostBlending === 'mult' ||
  1619. options.boostBlending === 'multiply') {
  1620. gl.blendFunc(gl.DST_COLOR, gl.ZERO);
  1621. }
  1622. else if (options.boostBlending === 'darken') {
  1623. gl.blendFunc(gl.ONE, gl.ONE);
  1624. gl.blendEquation(gl.FUNC_MIN);
  1625. }
  1626. else {
  1627. // gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
  1628. // gl.blendEquation(gl.FUNC_ADD);
  1629. gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  1630. }
  1631. shader.reset();
  1632. // If there are entries in the colorData buffer, build and bind it.
  1633. if (s.colorData.length > 0) {
  1634. shader.setUniform('hasColor', 1.0);
  1635. cbuffer = GLVertexBuffer(gl, shader); // eslint-disable-line new-cap
  1636. cbuffer.build(s.colorData, 'aColor', 4);
  1637. cbuffer.bind();
  1638. }
  1639. // Set series specific uniforms
  1640. shader.setColor(scolor);
  1641. setXAxis(s.series.xAxis);
  1642. setYAxis(s.series.yAxis);
  1643. setThreshold(hasThreshold, translatedThreshold);
  1644. if (s.drawMode === 'points') {
  1645. if (options.marker && isNumber(options.marker.radius)) {
  1646. shader.setPointSize(options.marker.radius * 2.0);
  1647. }
  1648. else {
  1649. shader.setPointSize(1);
  1650. }
  1651. }
  1652. // If set to true, the toPixels translations in the shader
  1653. // is skipped, i.e it's assumed that the value is a pixel coord.
  1654. shader.setSkipTranslation(s.skipTranslation);
  1655. if (s.series.type === 'bubble') {
  1656. shader.setBubbleUniforms(s.series, s.zMin, s.zMax);
  1657. }
  1658. shader.setDrawAsCircle(asCircle[s.series.type] || false);
  1659. // Do the actual rendering
  1660. // If the line width is < 0, skip rendering of the lines. See #7833.
  1661. if (lineWidth > 0 || s.drawMode !== 'line_strip') {
  1662. for (sindex = 0; sindex < s.segments.length; sindex++) {
  1663. // if (s.segments[sindex].from < s.segments[sindex].to) {
  1664. vbuffer.render(s.segments[sindex].from, s.segments[sindex].to, s.drawMode);
  1665. // }
  1666. }
  1667. }
  1668. if (s.hasMarkers && showMarkers) {
  1669. if (options.marker && isNumber(options.marker.radius)) {
  1670. shader.setPointSize(options.marker.radius * 2.0);
  1671. }
  1672. else {
  1673. shader.setPointSize(10);
  1674. }
  1675. shader.setDrawAsCircle(true);
  1676. for (sindex = 0; sindex < s.segments.length; sindex++) {
  1677. // if (s.segments[sindex].from < s.segments[sindex].to) {
  1678. vbuffer.render(s.segments[sindex].from, s.segments[sindex].to, 'POINTS');
  1679. // }
  1680. }
  1681. }
  1682. });
  1683. if (settings.debug.timeRendering) {
  1684. console.timeEnd('gl rendering'); // eslint-disable-line no-console
  1685. }
  1686. if (postRenderCallback) {
  1687. postRenderCallback();
  1688. }
  1689. flush();
  1690. }
  1691. /**
  1692. * Render the data when ready
  1693. * @private
  1694. */
  1695. function renderWhenReady(chart) {
  1696. clear();
  1697. if (chart.renderer.forExport) {
  1698. return render(chart);
  1699. }
  1700. if (isInited) {
  1701. render(chart);
  1702. }
  1703. else {
  1704. setTimeout(function () {
  1705. renderWhenReady(chart);
  1706. }, 1);
  1707. }
  1708. }
  1709. /**
  1710. * Set the viewport size in pixels
  1711. * Creates an orthographic perspective matrix and applies it.
  1712. * @private
  1713. * @param w {Integer} - the width of the viewport
  1714. * @param h {Integer} - the height of the viewport
  1715. */
  1716. function setSize(w, h) {
  1717. // Skip if there's no change, or if we have no valid shader
  1718. if ((width === w && height === h) || !shader) {
  1719. return;
  1720. }
  1721. width = w;
  1722. height = h;
  1723. shader.bind();
  1724. shader.setPMatrix(orthoMatrix(width, height));
  1725. }
  1726. /**
  1727. * Init OpenGL
  1728. * @private
  1729. * @param canvas {HTMLCanvas} - the canvas to render to
  1730. */
  1731. function init(canvas, noFlush) {
  1732. var i = 0,
  1733. contexts = [
  1734. 'webgl',
  1735. 'experimental-webgl',
  1736. 'moz-webgl',
  1737. 'webkit-3d'
  1738. ];
  1739. isInited = false;
  1740. if (!canvas) {
  1741. return false;
  1742. }
  1743. if (settings.debug.timeSetup) {
  1744. console.time('gl setup'); // eslint-disable-line no-console
  1745. }
  1746. for (; i < contexts.length; i++) {
  1747. gl = canvas.getContext(contexts[i], {
  1748. // premultipliedAlpha: false
  1749. });
  1750. if (gl) {
  1751. break;
  1752. }
  1753. }
  1754. if (gl) {
  1755. if (!noFlush) {
  1756. flush();
  1757. }
  1758. }
  1759. else {
  1760. return false;
  1761. }
  1762. gl.enable(gl.BLEND);
  1763. // gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  1764. gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
  1765. gl.disable(gl.DEPTH_TEST);
  1766. // gl.depthMask(gl.FALSE);
  1767. gl.depthFunc(gl.LESS);
  1768. shader = GLShader(gl); // eslint-disable-line new-cap
  1769. if (!shader) {
  1770. // We need to abort, there's no shader context
  1771. return false;
  1772. }
  1773. vbuffer = GLVertexBuffer(gl, shader); // eslint-disable-line new-cap
  1774. /**
  1775. * @private
  1776. */
  1777. function createTexture(name, fn) {
  1778. var props = {
  1779. isReady: false,
  1780. texture: doc.createElement('canvas'),
  1781. handle: gl.createTexture()
  1782. },
  1783. ctx = props.texture.getContext('2d');
  1784. textureHandles[name] = props;
  1785. props.texture.width = 512;
  1786. props.texture.height = 512;
  1787. ctx.mozImageSmoothingEnabled = false;
  1788. ctx.webkitImageSmoothingEnabled = false;
  1789. ctx.msImageSmoothingEnabled = false;
  1790. ctx.imageSmoothingEnabled = false;
  1791. ctx.strokeStyle = 'rgba(255, 255, 255, 0)';
  1792. ctx.fillStyle = '#FFF';
  1793. fn(ctx);
  1794. try {
  1795. gl.activeTexture(gl.TEXTURE0);
  1796. gl.bindTexture(gl.TEXTURE_2D, props.handle);
  1797. // gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
  1798. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, props.texture);
  1799. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  1800. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  1801. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1802. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  1803. // gl.generateMipmap(gl.TEXTURE_2D);
  1804. gl.bindTexture(gl.TEXTURE_2D, null);
  1805. props.isReady = true;
  1806. }
  1807. catch (e) {
  1808. // silent error
  1809. }
  1810. }
  1811. // Circle shape
  1812. createTexture('circle', function (ctx) {
  1813. ctx.beginPath();
  1814. ctx.arc(256, 256, 256, 0, 2 * Math.PI);
  1815. ctx.stroke();
  1816. ctx.fill();
  1817. });
  1818. // Square shape
  1819. createTexture('square', function (ctx) {
  1820. ctx.fillRect(0, 0, 512, 512);
  1821. });
  1822. // Diamond shape
  1823. createTexture('diamond', function (ctx) {
  1824. ctx.beginPath();
  1825. ctx.moveTo(256, 0);
  1826. ctx.lineTo(512, 256);
  1827. ctx.lineTo(256, 512);
  1828. ctx.lineTo(0, 256);
  1829. ctx.lineTo(256, 0);
  1830. ctx.fill();
  1831. });
  1832. // Triangle shape
  1833. createTexture('triangle', function (ctx) {
  1834. ctx.beginPath();
  1835. ctx.moveTo(0, 512);
  1836. ctx.lineTo(256, 0);
  1837. ctx.lineTo(512, 512);
  1838. ctx.lineTo(0, 512);
  1839. ctx.fill();
  1840. });
  1841. // Triangle shape (rotated)
  1842. createTexture('triangle-down', function (ctx) {
  1843. ctx.beginPath();
  1844. ctx.moveTo(0, 0);
  1845. ctx.lineTo(256, 512);
  1846. ctx.lineTo(512, 0);
  1847. ctx.lineTo(0, 0);
  1848. ctx.fill();
  1849. });
  1850. isInited = true;
  1851. if (settings.debug.timeSetup) {
  1852. console.timeEnd('gl setup'); // eslint-disable-line no-console
  1853. }
  1854. return true;
  1855. }
  1856. /**
  1857. * Check if we have a valid OGL context
  1858. * @private
  1859. * @returns {Boolean} - true if the context is valid
  1860. */
  1861. function valid() {
  1862. return gl !== false;
  1863. }
  1864. /**
  1865. * Check if the renderer has been initialized
  1866. * @private
  1867. * @returns {Boolean} - true if it has, false if not
  1868. */
  1869. function inited() {
  1870. return isInited;
  1871. }
  1872. /**
  1873. * @private
  1874. */
  1875. function destroy() {
  1876. flush();
  1877. vbuffer.destroy();
  1878. shader.destroy();
  1879. if (gl) {
  1880. objectEach(textureHandles, function (texture) {
  1881. if (texture.handle) {
  1882. gl.deleteTexture(texture.handle);
  1883. }
  1884. });
  1885. gl.canvas.width = 1;
  1886. gl.canvas.height = 1;
  1887. }
  1888. }
  1889. // /////////////////////////////////////////////////////////////////////////
  1890. exports = {
  1891. allocateBufferForSingleSeries: allocateBufferForSingleSeries,
  1892. pushSeries: pushSeries,
  1893. setSize: setSize,
  1894. inited: inited,
  1895. setThreshold: setThreshold,
  1896. init: init,
  1897. render: renderWhenReady,
  1898. settings: settings,
  1899. valid: valid,
  1900. clear: clear,
  1901. flush: flush,
  1902. setXAxis: setXAxis,
  1903. setYAxis: setYAxis,
  1904. data: data,
  1905. gl: getGL,
  1906. allocateBuffer: allocateBuffer,
  1907. destroy: destroy,
  1908. setOptions: setOptions
  1909. };
  1910. return exports;
  1911. }
  1912. return GLRenderer;
  1913. });
  1914. _registerModule(_modules, 'Extensions/Boost/BoostAttach.js', [_modules['Core/Chart/Chart.js'], _modules['Extensions/Boost/WGLRenderer.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (Chart, GLRenderer, H, U) {
  1915. /* *
  1916. *
  1917. * Copyright (c) 2019-2021 Highsoft AS
  1918. *
  1919. * Boost module: stripped-down renderer for higher performance
  1920. *
  1921. * License: highcharts.com/license
  1922. *
  1923. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1924. *
  1925. * */
  1926. var doc = H.doc;
  1927. var error = U.error;
  1928. var mainCanvas;
  1929. /**
  1930. * Create a canvas + context and attach it to the target
  1931. *
  1932. * @private
  1933. * @function createAndAttachRenderer
  1934. *
  1935. * @param {Highcharts.Chart} chart
  1936. * the chart
  1937. *
  1938. * @param {Highcharts.Series} series
  1939. * the series
  1940. *
  1941. * @return {Highcharts.BoostGLRenderer}
  1942. * the canvas renderer
  1943. */
  1944. function createAndAttachRenderer(chart, series) {
  1945. var width = chart.chartWidth, height = chart.chartHeight, target = chart, targetGroup = chart.seriesGroup || series.group, alpha = 1, foSupported = doc.implementation.hasFeature('www.http://w3.org/TR/SVG11/feature#Extensibility', '1.1');
  1946. if (chart.isChartSeriesBoosting()) {
  1947. target = chart;
  1948. }
  1949. else {
  1950. target = series;
  1951. }
  1952. // Support for foreignObject is flimsy as best.
  1953. // IE does not support it, and Chrome has a bug which messes up
  1954. // the canvas draw order.
  1955. // As such, we force the Image fallback for now, but leaving the
  1956. // actual Canvas path in-place in case this changes in the future.
  1957. foSupported = false;
  1958. if (!mainCanvas) {
  1959. mainCanvas = doc.createElement('canvas');
  1960. }
  1961. if (!target.renderTarget) {
  1962. target.canvas = mainCanvas;
  1963. // Fall back to image tag if foreignObject isn't supported,
  1964. // or if we're exporting.
  1965. if (chart.renderer.forExport || !foSupported) {
  1966. target.renderTarget = chart.renderer.image('', 0, 0, width, height)
  1967. .addClass('highcharts-boost-canvas')
  1968. .add(targetGroup);
  1969. target.boostClear = function () {
  1970. target.renderTarget.attr({ href: '' });
  1971. };
  1972. target.boostCopy = function () {
  1973. target.boostResizeTarget();
  1974. target.renderTarget.attr({
  1975. href: target.canvas.toDataURL('image/png')
  1976. });
  1977. };
  1978. }
  1979. else {
  1980. target.renderTargetFo = chart.renderer
  1981. .createElement('foreignObject')
  1982. .add(targetGroup);
  1983. target.renderTarget = doc.createElement('canvas');
  1984. target.renderTargetCtx =
  1985. target.renderTarget.getContext('2d');
  1986. target.renderTargetFo.element.appendChild(target.renderTarget);
  1987. target.boostClear = function () {
  1988. target.renderTarget.width =
  1989. target.canvas.width;
  1990. target.renderTarget.height =
  1991. target.canvas.height;
  1992. };
  1993. target.boostCopy = function () {
  1994. target.renderTarget.width =
  1995. target.canvas.width;
  1996. target.renderTarget.height =
  1997. target.canvas.height;
  1998. target.renderTargetCtx
  1999. .drawImage(target.canvas, 0, 0);
  2000. };
  2001. }
  2002. target.boostResizeTarget = function () {
  2003. width = chart.chartWidth;
  2004. height = chart.chartHeight;
  2005. (target.renderTargetFo || target.renderTarget)
  2006. .attr({
  2007. x: 0,
  2008. y: 0,
  2009. width: width,
  2010. height: height
  2011. })
  2012. .css({
  2013. pointerEvents: 'none',
  2014. mixedBlendMode: 'normal',
  2015. opacity: alpha
  2016. });
  2017. if (target instanceof Chart) {
  2018. target.markerGroup.translate(chart.plotLeft, chart.plotTop);
  2019. }
  2020. };
  2021. target.boostClipRect = chart.renderer.clipRect();
  2022. (target.renderTargetFo || target.renderTarget)
  2023. .clip(target.boostClipRect);
  2024. if (target instanceof Chart) {
  2025. target.markerGroup = target.renderer.g().add(targetGroup);
  2026. target.markerGroup.translate(series.xAxis.pos, series.yAxis.pos);
  2027. }
  2028. }
  2029. target.canvas.width = width;
  2030. target.canvas.height = height;
  2031. target.boostClipRect.attr(chart.getBoostClipRect(target));
  2032. target.boostResizeTarget();
  2033. target.boostClear();
  2034. if (!target.ogl) {
  2035. target.ogl = GLRenderer(function () {
  2036. if (target.ogl.settings.debug.timeBufferCopy) {
  2037. console.time('buffer copy'); // eslint-disable-line no-console
  2038. }
  2039. target.boostCopy();
  2040. if (target.ogl.settings.debug.timeBufferCopy) {
  2041. console.timeEnd('buffer copy'); // eslint-disable-line no-console
  2042. }
  2043. });
  2044. if (!target.ogl.init(target.canvas)) {
  2045. // The OGL renderer couldn't be inited.
  2046. // This likely means a shader error as we wouldn't get to this point
  2047. // if there was no WebGL support.
  2048. error('[highcharts boost] - unable to init WebGL renderer');
  2049. }
  2050. // target.ogl.clear();
  2051. target.ogl.setOptions(chart.options.boost || {});
  2052. if (target instanceof Chart) {
  2053. target.ogl.allocateBuffer(chart);
  2054. }
  2055. }
  2056. target.ogl.setSize(width, height);
  2057. return target.ogl;
  2058. }
  2059. return createAndAttachRenderer;
  2060. });
  2061. _registerModule(_modules, 'Extensions/Boost/BoostUtils.js', [_modules['Core/Globals.js'], _modules['Extensions/Boost/BoostableMap.js'], _modules['Extensions/Boost/BoostAttach.js'], _modules['Core/Utilities.js']], function (H, boostableMap, createAndAttachRenderer, U) {
  2062. /* *
  2063. *
  2064. * Copyright (c) 2019-2021 Highsoft AS
  2065. *
  2066. * Boost module: stripped-down renderer for higher performance
  2067. *
  2068. * License: highcharts.com/license
  2069. *
  2070. * This files contains generic utility functions used by the boost module.
  2071. *
  2072. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2073. *
  2074. * */
  2075. var win = H.win,
  2076. doc = H.doc;
  2077. var pick = U.pick;
  2078. // This should be a const.
  2079. var CHUNK_SIZE = 3000;
  2080. /**
  2081. * Tolerant max() function.
  2082. *
  2083. * @private
  2084. * @function patientMax
  2085. *
  2086. * @param {...Array<Array<unknown>>} args
  2087. * Max arguments
  2088. *
  2089. * @return {number}
  2090. * Max value
  2091. */
  2092. function patientMax() {
  2093. var args = [];
  2094. for (var _i = 0; _i < arguments.length; _i++) {
  2095. args[_i] = arguments[_i];
  2096. }
  2097. var r = -Number.MAX_VALUE;
  2098. args.forEach(function (t) {
  2099. if (typeof t !== 'undefined' &&
  2100. t !== null &&
  2101. typeof t.length !== 'undefined') {
  2102. // r = r < t.length ? t.length : r;
  2103. if (t.length > 0) {
  2104. r = t.length;
  2105. return true;
  2106. }
  2107. }
  2108. });
  2109. return r;
  2110. }
  2111. /**
  2112. * Return true if ths boost.enabled option is true
  2113. *
  2114. * @private
  2115. * @function boostEnabled
  2116. *
  2117. * @param {Highcharts.Chart} chart
  2118. * The chart
  2119. *
  2120. * @return {boolean}
  2121. * True, if boost is enabled.
  2122. */
  2123. function boostEnabled(chart) {
  2124. return pick((chart &&
  2125. chart.options &&
  2126. chart.options.boost &&
  2127. chart.options.boost.enabled), true);
  2128. }
  2129. /**
  2130. * Returns true if we should force boosting the chart
  2131. * @private
  2132. * @function shouldForceChartSeriesBoosting
  2133. *
  2134. * @param {Highcharts.Chart} chart
  2135. * The chart to check for forcing on
  2136. *
  2137. * @return {boolean}
  2138. * True, if boosting should be forced.
  2139. */
  2140. function shouldForceChartSeriesBoosting(chart) {
  2141. // If there are more than five series currently boosting,
  2142. // we should boost the whole chart to avoid running out of webgl contexts.
  2143. var sboostCount = 0,
  2144. canBoostCount = 0,
  2145. allowBoostForce = pick(chart.options.boost && chart.options.boost.allowForce,
  2146. true),
  2147. series;
  2148. if (typeof chart.boostForceChartBoost !== 'undefined') {
  2149. return chart.boostForceChartBoost;
  2150. }
  2151. if (chart.series.length > 1) {
  2152. for (var i = 0; i < chart.series.length; i++) {
  2153. series = chart.series[i];
  2154. // Don't count series with boostThreshold set to 0
  2155. // See #8950
  2156. // Also don't count if the series is hidden.
  2157. // See #9046
  2158. if (series.options.boostThreshold === 0 ||
  2159. series.visible === false) {
  2160. continue;
  2161. }
  2162. // Don't count heatmap series as they are handled differently.
  2163. // In the future we should make the heatmap/treemap path compatible
  2164. // with forcing. See #9636.
  2165. if (series.type === 'heatmap') {
  2166. continue;
  2167. }
  2168. if (boostableMap[series.type]) {
  2169. ++canBoostCount;
  2170. }
  2171. if (patientMax(series.processedXData, series.options.data,
  2172. // series.xData,
  2173. series.points) >= (series.options.boostThreshold || Number.MAX_VALUE)) {
  2174. ++sboostCount;
  2175. }
  2176. }
  2177. }
  2178. chart.boostForceChartBoost = allowBoostForce && ((canBoostCount === chart.series.length &&
  2179. sboostCount > 0) ||
  2180. sboostCount > 5);
  2181. return chart.boostForceChartBoost;
  2182. }
  2183. /* eslint-disable valid-jsdoc */
  2184. /**
  2185. * Performs the actual render if the renderer is
  2186. * attached to the series.
  2187. * @private
  2188. * @param renderer {OGLRenderer} - the renderer
  2189. * @param series {Highcharts.Series} - the series
  2190. */
  2191. function renderIfNotSeriesBoosting(renderer, series, chart) {
  2192. if (renderer &&
  2193. series.renderTarget &&
  2194. series.canvas &&
  2195. !(chart || series.chart).isChartSeriesBoosting()) {
  2196. renderer.render(chart || series.chart);
  2197. }
  2198. }
  2199. /**
  2200. * @private
  2201. */
  2202. function allocateIfNotSeriesBoosting(renderer, series) {
  2203. if (renderer &&
  2204. series.renderTarget &&
  2205. series.canvas &&
  2206. !series.chart.isChartSeriesBoosting()) {
  2207. renderer.allocateBufferForSingleSeries(series);
  2208. }
  2209. }
  2210. /**
  2211. * An "async" foreach loop. Uses a setTimeout to keep the loop from blocking the
  2212. * UI thread.
  2213. *
  2214. * @private
  2215. *
  2216. * @param arr {Array} - the array to loop through
  2217. * @param fn {Function} - the callback to call for each item
  2218. * @param finalFunc {Function} - the callback to call when done
  2219. * @param chunkSize {Number} - the number of iterations per timeout
  2220. * @param i {Number} - the current index
  2221. * @param noTimeout {Boolean} - set to true to skip timeouts
  2222. */
  2223. function eachAsync(arr, fn, finalFunc, chunkSize, i, noTimeout) {
  2224. i = i || 0;
  2225. chunkSize = chunkSize || CHUNK_SIZE;
  2226. var threshold = i + chunkSize,
  2227. proceed = true;
  2228. while (proceed && i < threshold && i < arr.length) {
  2229. proceed = fn(arr[i], i);
  2230. ++i;
  2231. }
  2232. if (proceed) {
  2233. if (i < arr.length) {
  2234. if (noTimeout) {
  2235. eachAsync(arr, fn, finalFunc, chunkSize, i, noTimeout);
  2236. }
  2237. else if (win.requestAnimationFrame) {
  2238. // If available, do requestAnimationFrame - shaves off a few ms
  2239. win.requestAnimationFrame(function () {
  2240. eachAsync(arr, fn, finalFunc, chunkSize, i);
  2241. });
  2242. }
  2243. else {
  2244. setTimeout(function () {
  2245. eachAsync(arr, fn, finalFunc, chunkSize, i);
  2246. });
  2247. }
  2248. }
  2249. else if (finalFunc) {
  2250. finalFunc();
  2251. }
  2252. }
  2253. }
  2254. /**
  2255. * Returns true if the current browser supports webgl
  2256. *
  2257. * @private
  2258. * @function hasWebGLSupport
  2259. *
  2260. * @return {boolean}
  2261. */
  2262. function hasWebGLSupport() {
  2263. var i = 0, canvas, contexts = ['webgl', 'experimental-webgl', 'moz-webgl', 'webkit-3d'], context = false;
  2264. if (typeof win.WebGLRenderingContext !== 'undefined') {
  2265. canvas = doc.createElement('canvas');
  2266. for (; i < contexts.length; i++) {
  2267. try {
  2268. context = canvas.getContext(contexts[i]);
  2269. if (typeof context !== 'undefined' && context !== null) {
  2270. return true;
  2271. }
  2272. }
  2273. catch (e) {
  2274. // silent error
  2275. }
  2276. }
  2277. }
  2278. return false;
  2279. }
  2280. /* eslint-disable no-invalid-this */
  2281. /**
  2282. * Used for treemap|heatmap.drawPoints
  2283. *
  2284. * @private
  2285. * @function pointDrawHandler
  2286. *
  2287. * @param {Function} proceed
  2288. *
  2289. * @return {*}
  2290. */
  2291. function pointDrawHandler(proceed) {
  2292. var enabled = true,
  2293. renderer;
  2294. if (this.chart.options && this.chart.options.boost) {
  2295. enabled = typeof this.chart.options.boost.enabled === 'undefined' ?
  2296. true :
  2297. this.chart.options.boost.enabled;
  2298. }
  2299. if (!enabled || !this.isSeriesBoosting) {
  2300. return proceed.call(this);
  2301. }
  2302. this.chart.isBoosting = true;
  2303. // Make sure we have a valid OGL context
  2304. renderer = createAndAttachRenderer(this.chart, this);
  2305. if (renderer) {
  2306. allocateIfNotSeriesBoosting(renderer, this);
  2307. renderer.pushSeries(this);
  2308. }
  2309. renderIfNotSeriesBoosting(renderer, this);
  2310. }
  2311. /* eslint-enable no-invalid-this, valid-jsdoc */
  2312. var funs = {
  2313. patientMax: patientMax,
  2314. boostEnabled: boostEnabled,
  2315. shouldForceChartSeriesBoosting: shouldForceChartSeriesBoosting,
  2316. renderIfNotSeriesBoosting: renderIfNotSeriesBoosting,
  2317. allocateIfNotSeriesBoosting: allocateIfNotSeriesBoosting,
  2318. eachAsync: eachAsync,
  2319. hasWebGLSupport: hasWebGLSupport,
  2320. pointDrawHandler: pointDrawHandler
  2321. };
  2322. // This needs to be fixed.
  2323. H.hasWebGLSupport = hasWebGLSupport;
  2324. return funs;
  2325. });
  2326. _registerModule(_modules, 'Extensions/Boost/BoostInit.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Series/Series.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js'], _modules['Extensions/Boost/BoostUtils.js'], _modules['Extensions/Boost/BoostAttach.js']], function (Chart, H, Series, SeriesRegistry, U, butils, createAndAttachRenderer) {
  2327. /* *
  2328. *
  2329. * Copyright (c) 2019-2021 Highsoft AS
  2330. *
  2331. * Boost module: stripped-down renderer for higher performance
  2332. *
  2333. * License: highcharts.com/license
  2334. *
  2335. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2336. *
  2337. * */
  2338. var noop = H.noop;
  2339. var seriesTypes = SeriesRegistry.seriesTypes;
  2340. var addEvent = U.addEvent,
  2341. extend = U.extend,
  2342. fireEvent = U.fireEvent,
  2343. wrap = U.wrap;
  2344. var eachAsync = butils.eachAsync,
  2345. pointDrawHandler = butils.pointDrawHandler,
  2346. allocateIfNotSeriesBoosting = butils.allocateIfNotSeriesBoosting,
  2347. renderIfNotSeriesBoosting = butils.renderIfNotSeriesBoosting,
  2348. shouldForceChartSeriesBoosting = butils.shouldForceChartSeriesBoosting,
  2349. index;
  2350. /* eslint-disable valid-jsdoc */
  2351. /**
  2352. * Initialize the boot module.
  2353. *
  2354. * @private
  2355. * @return {void}
  2356. */
  2357. function init() {
  2358. extend(Series.prototype, {
  2359. /**
  2360. * @private
  2361. * @function Highcharts.Series#renderCanvas
  2362. */
  2363. renderCanvas: function () {
  2364. var series = this, options = series.options || {}, renderer = false, chart = series.chart, xAxis = this.xAxis, yAxis = this.yAxis, xData = options.xData || series.processedXData, yData = options.yData || series.processedYData, rawData = options.data, xExtremes = xAxis.getExtremes(), xMin = xExtremes.min, xMax = xExtremes.max, yExtremes = yAxis.getExtremes(), yMin = yExtremes.min, yMax = yExtremes.max, pointTaken = {}, lastClientX, sampling = !!series.sampling, points, enableMouseTracking = options.enableMouseTracking !== false, threshold = options.threshold, yBottom = yAxis.getThreshold(threshold), isRange = series.pointArrayMap &&
  2365. series.pointArrayMap.join(',') === 'low,high', isStacked = !!options.stacking, cropStart = series.cropStart || 0, requireSorting = series.requireSorting, useRaw = !xData, minVal, maxVal, minI, maxI, boostOptions, compareX = options.findNearestPointBy === 'x', xDataFull = (this.xData ||
  2366. this.options.xData ||
  2367. this.processedXData ||
  2368. false), addKDPoint = function (clientX, plotY, i) {
  2369. // We need to do ceil on the clientX to make things
  2370. // snap to pixel values. The renderer will frequently
  2371. // draw stuff on "sub-pixels".
  2372. clientX = Math.ceil(clientX);
  2373. // Shaves off about 60ms compared to repeated concatenation
  2374. index = compareX ? clientX : clientX + ',' + plotY;
  2375. // The k-d tree requires series points.
  2376. // Reduce the amount of points, since the time to build the
  2377. // tree increases exponentially.
  2378. if (enableMouseTracking && !pointTaken[index]) {
  2379. pointTaken[index] = true;
  2380. if (chart.inverted) {
  2381. clientX = xAxis.len - clientX;
  2382. plotY = yAxis.len - plotY;
  2383. }
  2384. points.push({
  2385. x: xDataFull ? xDataFull[cropStart + i] : false,
  2386. clientX: clientX,
  2387. plotX: clientX,
  2388. plotY: plotY,
  2389. i: cropStart + i
  2390. });
  2391. }
  2392. };
  2393. // Get or create the renderer
  2394. renderer = createAndAttachRenderer(chart, series);
  2395. chart.isBoosting = true;
  2396. boostOptions = renderer.settings;
  2397. if (!this.visible) {
  2398. return;
  2399. }
  2400. // If we are zooming out from SVG mode, destroy the graphics
  2401. if (this.points || this.graph) {
  2402. this.destroyGraphics();
  2403. }
  2404. // If we're rendering per. series we should create the marker groups
  2405. // as usual.
  2406. if (!chart.isChartSeriesBoosting()) {
  2407. // If all series were boosting, but are not anymore
  2408. // restore private markerGroup
  2409. if (this.markerGroup === chart.markerGroup) {
  2410. this.markerGroup = void 0;
  2411. }
  2412. this.markerGroup = series.plotGroup('markerGroup', 'markers', true, 1, chart.seriesGroup);
  2413. }
  2414. else {
  2415. // If series has a private markeGroup, remove that
  2416. // and use common markerGroup
  2417. if (this.markerGroup &&
  2418. this.markerGroup !== chart.markerGroup) {
  2419. this.markerGroup.destroy();
  2420. }
  2421. // Use a single group for the markers
  2422. this.markerGroup = chart.markerGroup;
  2423. // When switching from chart boosting mode, destroy redundant
  2424. // series boosting targets
  2425. if (this.renderTarget) {
  2426. this.renderTarget = this.renderTarget.destroy();
  2427. }
  2428. }
  2429. points = this.points = [];
  2430. // Do not start building while drawing
  2431. series.buildKDTree = noop;
  2432. if (renderer) {
  2433. allocateIfNotSeriesBoosting(renderer, this);
  2434. renderer.pushSeries(series);
  2435. // Perform the actual renderer if we're on series level
  2436. renderIfNotSeriesBoosting(renderer, this, chart);
  2437. }
  2438. /**
  2439. * This builds the KD-tree
  2440. * @private
  2441. */
  2442. function processPoint(d, i) {
  2443. var x,
  2444. y,
  2445. clientX,
  2446. plotY,
  2447. isNull,
  2448. low = false,
  2449. chartDestroyed = typeof chart.index === 'undefined',
  2450. isYInside = true;
  2451. if (typeof d === 'undefined') {
  2452. return true;
  2453. }
  2454. if (!chartDestroyed) {
  2455. if (useRaw) {
  2456. x = d[0];
  2457. y = d[1];
  2458. }
  2459. else {
  2460. x = d;
  2461. y = yData[i];
  2462. }
  2463. // Resolve low and high for range series
  2464. if (isRange) {
  2465. if (useRaw) {
  2466. y = d.slice(1, 3);
  2467. }
  2468. low = y[0];
  2469. y = y[1];
  2470. }
  2471. else if (isStacked) {
  2472. x = d.x;
  2473. y = d.stackY;
  2474. low = y - d.y;
  2475. }
  2476. isNull = y === null;
  2477. // Optimize for scatter zooming
  2478. if (!requireSorting) {
  2479. isYInside = y >= yMin && y <= yMax;
  2480. }
  2481. if (!isNull && x >= xMin && x <= xMax && isYInside) {
  2482. clientX = xAxis.toPixels(x, true);
  2483. if (sampling) {
  2484. if (typeof minI === 'undefined' ||
  2485. clientX === lastClientX) {
  2486. if (!isRange) {
  2487. low = y;
  2488. }
  2489. if (typeof maxI === 'undefined' ||
  2490. y > maxVal) {
  2491. maxVal = y;
  2492. maxI = i;
  2493. }
  2494. if (typeof minI === 'undefined' ||
  2495. low < minVal) {
  2496. minVal = low;
  2497. minI = i;
  2498. }
  2499. }
  2500. // Add points and reset
  2501. if (clientX !== lastClientX) {
  2502. // maxI is number too:
  2503. if (typeof minI !== 'undefined') {
  2504. plotY =
  2505. yAxis.toPixels(maxVal, true);
  2506. yBottom =
  2507. yAxis.toPixels(minVal, true);
  2508. addKDPoint(clientX, plotY, maxI);
  2509. if (yBottom !== plotY) {
  2510. addKDPoint(clientX, yBottom, minI);
  2511. }
  2512. }
  2513. minI = maxI = void 0;
  2514. lastClientX = clientX;
  2515. }
  2516. }
  2517. else {
  2518. plotY = Math.ceil(yAxis.toPixels(y, true));
  2519. addKDPoint(clientX, plotY, i);
  2520. }
  2521. }
  2522. }
  2523. return !chartDestroyed;
  2524. }
  2525. /**
  2526. * @private
  2527. */
  2528. function doneProcessing() {
  2529. fireEvent(series, 'renderedCanvas');
  2530. // Go back to prototype, ready to build
  2531. delete series.buildKDTree;
  2532. series.buildKDTree();
  2533. if (boostOptions.debug.timeKDTree) {
  2534. console.timeEnd('kd tree building'); // eslint-disable-line no-console
  2535. }
  2536. }
  2537. // Loop over the points to build the k-d tree - skip this if
  2538. // exporting
  2539. if (!chart.renderer.forExport) {
  2540. if (boostOptions.debug.timeKDTree) {
  2541. console.time('kd tree building'); // eslint-disable-line no-console
  2542. }
  2543. eachAsync(isStacked ? series.data : (xData || rawData), processPoint, doneProcessing);
  2544. }
  2545. }
  2546. });
  2547. /*
  2548. * We need to handle heatmaps separatly, since we can't perform the
  2549. * size/color calculations in the shader easily.
  2550. *
  2551. * This likely needs future optimization.
  2552. */
  2553. ['heatmap', 'treemap'].forEach(function (t) {
  2554. if (seriesTypes[t]) {
  2555. wrap(seriesTypes[t].prototype, 'drawPoints', pointDrawHandler);
  2556. }
  2557. });
  2558. /* eslint-disable no-invalid-this */
  2559. if (seriesTypes.bubble) {
  2560. // By default, the bubble series does not use the KD-tree, so force it
  2561. // to.
  2562. delete seriesTypes.bubble.prototype.buildKDTree;
  2563. // seriesTypes.bubble.prototype.directTouch = false;
  2564. // Needed for markers to work correctly
  2565. wrap(seriesTypes.bubble.prototype, 'markerAttribs', function (proceed) {
  2566. if (this.isSeriesBoosting) {
  2567. return false;
  2568. }
  2569. return proceed.apply(this, [].slice.call(arguments, 1));
  2570. });
  2571. }
  2572. seriesTypes.scatter.prototype.fill = true;
  2573. extend(seriesTypes.area.prototype, {
  2574. fill: true,
  2575. fillOpacity: true,
  2576. sampling: true
  2577. });
  2578. extend(seriesTypes.column.prototype, {
  2579. fill: true,
  2580. sampling: true
  2581. });
  2582. Chart.prototype.propsRequireUpdateSeries.push('boost');
  2583. // Take care of the canvas blitting
  2584. Chart.prototype.callbacks.push(function (chart) {
  2585. /**
  2586. * Convert chart-level canvas to image.
  2587. * @private
  2588. */
  2589. function canvasToSVG() {
  2590. if (chart.ogl && chart.isChartSeriesBoosting()) {
  2591. chart.ogl.render(chart);
  2592. }
  2593. }
  2594. /**
  2595. * Clear chart-level canvas.
  2596. * @private
  2597. */
  2598. function preRender() {
  2599. // Reset force state
  2600. chart.boostForceChartBoost = void 0;
  2601. chart.boostForceChartBoost = shouldForceChartSeriesBoosting(chart);
  2602. chart.isBoosting = false;
  2603. if (!chart.isChartSeriesBoosting() && chart.didBoost) {
  2604. chart.didBoost = false;
  2605. }
  2606. // Clear the canvas
  2607. if (chart.boostClear) {
  2608. chart.boostClear();
  2609. }
  2610. if (chart.canvas && chart.ogl && chart.isChartSeriesBoosting()) {
  2611. chart.didBoost = true;
  2612. // Allocate
  2613. chart.ogl.allocateBuffer(chart);
  2614. }
  2615. // see #6518 + #6739
  2616. if (chart.markerGroup &&
  2617. chart.xAxis &&
  2618. chart.xAxis.length > 0 &&
  2619. chart.yAxis &&
  2620. chart.yAxis.length > 0) {
  2621. chart.markerGroup.translate(chart.xAxis[0].pos, chart.yAxis[0].pos);
  2622. }
  2623. }
  2624. addEvent(chart, 'predraw', preRender);
  2625. addEvent(chart, 'render', canvasToSVG);
  2626. // addEvent(chart, 'zoom', function () {
  2627. // chart.boostForceChartBoost =
  2628. // shouldForceChartSeriesBoosting(chart);
  2629. // });
  2630. var prevX = -1;
  2631. var prevY = -1;
  2632. addEvent(chart.pointer, 'afterGetHoverData', function () {
  2633. var series = chart.hoverSeries;
  2634. if (chart.markerGroup && series) {
  2635. var xAxis = chart.inverted ? series.yAxis : series.xAxis;
  2636. var yAxis = chart.inverted ? series.xAxis : series.yAxis;
  2637. if ((xAxis && xAxis.pos !== prevX) ||
  2638. (yAxis && yAxis.pos !== prevY)) {
  2639. // #10464: Keep the marker group position in sync with the
  2640. // position of the hovered series axes since there is only
  2641. // one shared marker group when boosting.
  2642. chart.markerGroup.translate(xAxis.pos, yAxis.pos);
  2643. prevX = xAxis.pos;
  2644. prevY = yAxis.pos;
  2645. }
  2646. }
  2647. });
  2648. });
  2649. /* eslint-enable no-invalid-this */
  2650. }
  2651. return init;
  2652. });
  2653. _registerModule(_modules, 'Extensions/BoostCanvas.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Color/Color.js'], _modules['Core/Globals.js'], _modules['Core/Color/Palette.js'], _modules['Core/Series/Series.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (Chart, Color, H, palette, Series, SeriesRegistry, U) {
  2654. /* *
  2655. *
  2656. * License: www.highcharts.com/license
  2657. * Author: Torstein Honsi, Christer Vasseng
  2658. *
  2659. * This module serves as a fallback for the Boost module in IE9 and IE10. Newer
  2660. * browsers support WebGL which is faster.
  2661. *
  2662. * It is recommended to include this module in conditional comments targeting
  2663. * IE9 and IE10.
  2664. *
  2665. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2666. *
  2667. * */
  2668. var color = Color.parse;
  2669. var doc = H.doc,
  2670. noop = H.noop;
  2671. var seriesTypes = SeriesRegistry.seriesTypes;
  2672. var addEvent = U.addEvent,
  2673. extend = U.extend,
  2674. fireEvent = U.fireEvent,
  2675. isNumber = U.isNumber,
  2676. merge = U.merge,
  2677. pick = U.pick,
  2678. wrap = U.wrap;
  2679. var CHUNK_SIZE = 50000,
  2680. destroyLoadingDiv;
  2681. /* eslint-disable no-invalid-this, valid-jsdoc */
  2682. /**
  2683. * Initialize the canvas boost.
  2684. *
  2685. * @function Highcharts.initCanvasBoost
  2686. */
  2687. var initCanvasBoost = function () {
  2688. if (H.seriesTypes.heatmap) {
  2689. wrap(H.seriesTypes.heatmap.prototype, 'drawPoints',
  2690. function () {
  2691. var chart = this.chart,
  2692. ctx = this.getContext(),
  2693. inverted = this.chart.inverted,
  2694. xAxis = this.xAxis,
  2695. yAxis = this.yAxis;
  2696. if (ctx) {
  2697. // draw the columns
  2698. this.points.forEach(function (point) {
  2699. var plotY = point.plotY,
  2700. pointAttr;
  2701. if (typeof plotY !== 'undefined' &&
  2702. !isNaN(plotY) &&
  2703. point.y !== null &&
  2704. ctx) {
  2705. var _a = point.shapeArgs || {},
  2706. _b = _a.x,
  2707. x = _b === void 0 ? 0 : _b,
  2708. _c = _a.y,
  2709. y = _c === void 0 ? 0 : _c,
  2710. _d = _a.width,
  2711. width = _d === void 0 ? 0 : _d,
  2712. _e = _a.height,
  2713. height = _e === void 0 ? 0 : _e;
  2714. if (!chart.styledMode) {
  2715. pointAttr = point.series.pointAttribs(point);
  2716. }
  2717. else {
  2718. pointAttr = point.series.colorAttribs(point);
  2719. }
  2720. ctx.fillStyle = pointAttr.fill;
  2721. if (inverted) {
  2722. ctx.fillRect(yAxis.len - y + xAxis.left, xAxis.len - x + yAxis.top, -height, -width);
  2723. }
  2724. else {
  2725. ctx.fillRect(x + xAxis.left, y + yAxis.top, width, height);
  2726. }
  2727. }
  2728. });
  2729. this.canvasToSVG();
  2730. }
  2731. else {
  2732. this.chart.showLoading('Your browser doesn\'t support HTML5 canvas, <br>' +
  2733. 'please use a modern browser');
  2734. // Uncomment this to provide low-level (slow) support in oldIE.
  2735. // It will cause script errors on charts with more than a few
  2736. // thousand points.
  2737. // arguments[0].call(this);
  2738. }
  2739. });
  2740. }
  2741. extend(Series.prototype, {
  2742. /**
  2743. * Create a hidden canvas to draw the graph on. The contents is later
  2744. * copied over to an SVG image element.
  2745. *
  2746. * @private
  2747. * @function Highcharts.Series#getContext
  2748. */
  2749. getContext: function () {
  2750. var chart = this.chart,
  2751. width = chart.chartWidth,
  2752. height = chart.chartHeight,
  2753. targetGroup = chart.seriesGroup || this.group,
  2754. target = this,
  2755. ctx,
  2756. swapXY = function (proceed,
  2757. x,
  2758. y,
  2759. a,
  2760. b,
  2761. c,
  2762. d) {
  2763. proceed.call(this,
  2764. y,
  2765. x,
  2766. a,
  2767. b,
  2768. c,
  2769. d);
  2770. };
  2771. if (chart.isChartSeriesBoosting()) {
  2772. target = chart;
  2773. targetGroup = chart.seriesGroup;
  2774. }
  2775. ctx = target.ctx;
  2776. if (!target.canvas) {
  2777. target.canvas = doc.createElement('canvas');
  2778. target.renderTarget = chart.renderer
  2779. .image('', 0, 0, width, height)
  2780. .addClass('highcharts-boost-canvas')
  2781. .add(targetGroup);
  2782. target.ctx = ctx = target.canvas.getContext('2d');
  2783. if (chart.inverted) {
  2784. ['moveTo', 'lineTo', 'rect', 'arc'].forEach(function (fn) {
  2785. wrap(ctx, fn, swapXY);
  2786. });
  2787. }
  2788. target.boostCopy = function () {
  2789. target.renderTarget.attr({
  2790. href: target.canvas.toDataURL('image/png')
  2791. });
  2792. };
  2793. target.boostClear = function () {
  2794. ctx.clearRect(0, 0, target.canvas.width, target.canvas.height);
  2795. if (target === this) {
  2796. target.renderTarget.attr({ href: '' });
  2797. }
  2798. };
  2799. target.boostClipRect = chart.renderer.clipRect();
  2800. target.renderTarget.clip(target.boostClipRect);
  2801. }
  2802. else if (!(target instanceof H.Chart)) {
  2803. // ctx.clearRect(0, 0, width, height);
  2804. }
  2805. if (target.canvas.width !== width) {
  2806. target.canvas.width = width;
  2807. }
  2808. if (target.canvas.height !== height) {
  2809. target.canvas.height = height;
  2810. }
  2811. target.renderTarget.attr({
  2812. x: 0,
  2813. y: 0,
  2814. width: width,
  2815. height: height,
  2816. style: 'pointer-events: none',
  2817. href: ''
  2818. });
  2819. target.boostClipRect.attr(chart.getBoostClipRect(target));
  2820. return ctx;
  2821. },
  2822. /**
  2823. * Draw the canvas image inside an SVG image
  2824. *
  2825. * @private
  2826. * @function Highcharts.Series#canvasToSVG
  2827. */
  2828. canvasToSVG: function () {
  2829. if (!this.chart.isChartSeriesBoosting()) {
  2830. if (this.boostCopy || this.chart.boostCopy) {
  2831. (this.boostCopy || this.chart.boostCopy)();
  2832. }
  2833. }
  2834. else {
  2835. if (this.boostClear) {
  2836. this.boostClear();
  2837. }
  2838. }
  2839. },
  2840. cvsLineTo: function (ctx, clientX, plotY) {
  2841. ctx.lineTo(clientX, plotY);
  2842. },
  2843. renderCanvas: function () {
  2844. var series = this, options = series.options, chart = series.chart, xAxis = this.xAxis, yAxis = this.yAxis, activeBoostSettings = chart.options.boost || {}, boostSettings = {
  2845. timeRendering: activeBoostSettings.timeRendering || false,
  2846. timeSeriesProcessing: activeBoostSettings.timeSeriesProcessing || false,
  2847. timeSetup: activeBoostSettings.timeSetup || false
  2848. }, ctx, c = 0, xData = series.processedXData, yData = series.processedYData, rawData = options.data, xExtremes = xAxis.getExtremes(), xMin = xExtremes.min, xMax = xExtremes.max, yExtremes = yAxis.getExtremes(), yMin = yExtremes.min, yMax = yExtremes.max, pointTaken = {}, lastClientX, sampling = !!series.sampling, points, r = options.marker && options.marker.radius, cvsDrawPoint = this.cvsDrawPoint, cvsLineTo = options.lineWidth ? this.cvsLineTo : void 0, cvsMarker = (r && r <= 1 ?
  2849. this.cvsMarkerSquare :
  2850. this.cvsMarkerCircle), strokeBatch = this.cvsStrokeBatch || 1000, enableMouseTracking = options.enableMouseTracking !== false, lastPoint, threshold = options.threshold, yBottom = yAxis.getThreshold(threshold), hasThreshold = isNumber(threshold), translatedThreshold = yBottom, doFill = this.fill, isRange = (series.pointArrayMap &&
  2851. series.pointArrayMap.join(',') === 'low,high'), isStacked = !!options.stacking, cropStart = series.cropStart || 0, loadingOptions = chart.options.loading, requireSorting = series.requireSorting, wasNull, connectNulls = options.connectNulls, useRaw = !xData, minVal, maxVal, minI, maxI, index, sdata = (isStacked ?
  2852. series.data :
  2853. (xData || rawData)), fillColor = (series.fillOpacity ?
  2854. new Color(series.color).setOpacity(pick(options.fillOpacity, 0.75)).get() :
  2855. series.color),
  2856. //
  2857. stroke = function () {
  2858. if (doFill) {
  2859. ctx.fillStyle = fillColor;
  2860. ctx.fill();
  2861. }
  2862. else {
  2863. ctx.strokeStyle = series.color;
  2864. ctx.lineWidth = options.lineWidth;
  2865. ctx.stroke();
  2866. }
  2867. },
  2868. //
  2869. drawPoint = function (clientX, plotY, yBottom, i) {
  2870. if (c === 0) {
  2871. ctx.beginPath();
  2872. if (cvsLineTo) {
  2873. ctx.lineJoin = 'round';
  2874. }
  2875. }
  2876. if (chart.scroller &&
  2877. series.options.className ===
  2878. 'highcharts-navigator-series') {
  2879. plotY += chart.scroller.top;
  2880. if (yBottom) {
  2881. yBottom += chart.scroller.top;
  2882. }
  2883. }
  2884. else {
  2885. plotY += chart.plotTop;
  2886. }
  2887. clientX += chart.plotLeft;
  2888. if (wasNull) {
  2889. ctx.moveTo(clientX, plotY);
  2890. }
  2891. else {
  2892. if (cvsDrawPoint) {
  2893. cvsDrawPoint(ctx, clientX, plotY, yBottom, lastPoint);
  2894. }
  2895. else if (cvsLineTo) {
  2896. cvsLineTo(ctx, clientX, plotY);
  2897. }
  2898. else if (cvsMarker) {
  2899. cvsMarker.call(series, ctx, clientX, plotY, r, i);
  2900. }
  2901. }
  2902. // We need to stroke the line for every 1000 pixels. It will
  2903. // crash the browser memory use if we stroke too
  2904. // infrequently.
  2905. c = c + 1;
  2906. if (c === strokeBatch) {
  2907. stroke();
  2908. c = 0;
  2909. }
  2910. // Area charts need to keep track of the last point
  2911. lastPoint = {
  2912. clientX: clientX,
  2913. plotY: plotY,
  2914. yBottom: yBottom
  2915. };
  2916. },
  2917. //
  2918. compareX = options.findNearestPointBy === 'x',
  2919. //
  2920. xDataFull = (this.xData ||
  2921. this.options.xData ||
  2922. this.processedXData ||
  2923. false),
  2924. //
  2925. addKDPoint = function (clientX, plotY, i) {
  2926. // Shaves off about 60ms compared to repeated concatenation
  2927. index = compareX ? clientX : clientX + ',' + plotY;
  2928. // The k-d tree requires series points.
  2929. // Reduce the amount of points, since the time to build the
  2930. // tree increases exponentially.
  2931. if (enableMouseTracking && !pointTaken[index]) {
  2932. pointTaken[index] = true;
  2933. if (chart.inverted) {
  2934. clientX = xAxis.len - clientX;
  2935. plotY = yAxis.len - plotY;
  2936. }
  2937. points.push({
  2938. x: xDataFull ?
  2939. xDataFull[cropStart + i] :
  2940. false,
  2941. clientX: clientX,
  2942. plotX: clientX,
  2943. plotY: plotY,
  2944. i: cropStart + i
  2945. });
  2946. }
  2947. };
  2948. if (this.renderTarget) {
  2949. this.renderTarget.attr({ 'href': '' });
  2950. }
  2951. // If we are zooming out from SVG mode, destroy the graphics
  2952. if (this.points || this.graph) {
  2953. this.destroyGraphics();
  2954. }
  2955. // The group
  2956. series.plotGroup('group', 'series', series.visible ? 'visible' : 'hidden', options.zIndex, chart.seriesGroup);
  2957. series.markerGroup = series.group;
  2958. addEvent(series, 'destroy', function () {
  2959. // Prevent destroy twice
  2960. series.markerGroup = null;
  2961. });
  2962. points = this.points = [];
  2963. ctx = this.getContext();
  2964. series.buildKDTree = noop; // Do not start building while drawing
  2965. if (this.boostClear) {
  2966. this.boostClear();
  2967. }
  2968. // if (this.canvas) {
  2969. // ctx.clearRect(
  2970. // 0,
  2971. // 0,
  2972. // this.canvas.width,
  2973. // this.canvas.height
  2974. // );
  2975. // }
  2976. if (!this.visible) {
  2977. return;
  2978. }
  2979. // Display a loading indicator
  2980. if (rawData.length > 99999) {
  2981. chart.options.loading = merge(loadingOptions, {
  2982. labelStyle: {
  2983. backgroundColor: color(palette.backgroundColor).setOpacity(0.75).get(),
  2984. padding: '1em',
  2985. borderRadius: '0.5em'
  2986. },
  2987. style: {
  2988. backgroundColor: 'none',
  2989. opacity: 1
  2990. }
  2991. });
  2992. U.clearTimeout(destroyLoadingDiv);
  2993. chart.showLoading('Drawing...');
  2994. chart.options.loading = loadingOptions; // reset
  2995. }
  2996. if (boostSettings.timeRendering) {
  2997. console.time('canvas rendering'); // eslint-disable-line no-console
  2998. }
  2999. // Loop over the points
  3000. H.eachAsync(sdata, function (d, i) {
  3001. var x,
  3002. y,
  3003. clientX,
  3004. plotY,
  3005. isNull,
  3006. low,
  3007. isNextInside = false,
  3008. isPrevInside = false,
  3009. nx = false,
  3010. px = false,
  3011. chartDestroyed = typeof chart.index === 'undefined',
  3012. isYInside = true;
  3013. if (!chartDestroyed) {
  3014. if (useRaw) {
  3015. x = d[0];
  3016. y = d[1];
  3017. if (sdata[i + 1]) {
  3018. nx = sdata[i + 1][0];
  3019. }
  3020. if (sdata[i - 1]) {
  3021. px = sdata[i - 1][0];
  3022. }
  3023. }
  3024. else {
  3025. x = d;
  3026. y = yData[i];
  3027. if (sdata[i + 1]) {
  3028. nx = sdata[i + 1];
  3029. }
  3030. if (sdata[i - 1]) {
  3031. px = sdata[i - 1];
  3032. }
  3033. }
  3034. if (nx && nx >= xMin && nx <= xMax) {
  3035. isNextInside = true;
  3036. }
  3037. if (px && px >= xMin && px <= xMax) {
  3038. isPrevInside = true;
  3039. }
  3040. // Resolve low and high for range series
  3041. if (isRange) {
  3042. if (useRaw) {
  3043. y = d.slice(1, 3);
  3044. }
  3045. low = y[0];
  3046. y = y[1];
  3047. }
  3048. else if (isStacked) {
  3049. x = d.x;
  3050. y = d.stackY;
  3051. low = y - d.y;
  3052. }
  3053. isNull = y === null;
  3054. // Optimize for scatter zooming
  3055. if (!requireSorting) {
  3056. isYInside = y >= yMin && y <= yMax;
  3057. }
  3058. if (!isNull &&
  3059. ((x >= xMin && x <= xMax && isYInside) ||
  3060. (isNextInside || isPrevInside))) {
  3061. clientX = Math.round(xAxis.toPixels(x, true));
  3062. if (sampling) {
  3063. if (typeof minI === 'undefined' ||
  3064. clientX === lastClientX) {
  3065. if (!isRange) {
  3066. low = y;
  3067. }
  3068. if (typeof maxI === 'undefined' || y > maxVal) {
  3069. maxVal = y;
  3070. maxI = i;
  3071. }
  3072. if (typeof minI === 'undefined' ||
  3073. low < minVal) {
  3074. minVal = low;
  3075. minI = i;
  3076. }
  3077. }
  3078. // Add points and reset
  3079. if (clientX !== lastClientX) {
  3080. // maxI also a number:
  3081. if (typeof minI !== 'undefined') {
  3082. plotY = yAxis.toPixels(maxVal, true);
  3083. yBottom = yAxis.toPixels(minVal, true);
  3084. drawPoint(clientX, hasThreshold ?
  3085. Math.min(plotY, translatedThreshold) : plotY, hasThreshold ?
  3086. Math.max(yBottom, translatedThreshold) : yBottom, i);
  3087. addKDPoint(clientX, plotY, maxI);
  3088. if (yBottom !== plotY) {
  3089. addKDPoint(clientX, yBottom, minI);
  3090. }
  3091. }
  3092. minI = maxI = void 0;
  3093. lastClientX = clientX;
  3094. }
  3095. }
  3096. else {
  3097. plotY = Math.round(yAxis.toPixels(y, true));
  3098. drawPoint(clientX, plotY, yBottom, i);
  3099. addKDPoint(clientX, plotY, i);
  3100. }
  3101. }
  3102. wasNull = isNull && !connectNulls;
  3103. if (i % CHUNK_SIZE === 0) {
  3104. if (series.boostCopy || series.chart.boostCopy) {
  3105. (series.boostCopy || series.chart.boostCopy)();
  3106. }
  3107. }
  3108. }
  3109. return !chartDestroyed;
  3110. }, function () {
  3111. var loadingDiv = chart.loadingDiv,
  3112. loadingShown = chart.loadingShown;
  3113. stroke();
  3114. // if (series.boostCopy || series.chart.boostCopy) {
  3115. // (series.boostCopy || series.chart.boostCopy)();
  3116. // }
  3117. series.canvasToSVG();
  3118. if (boostSettings.timeRendering) {
  3119. console.timeEnd('canvas rendering'); // eslint-disable-line no-console
  3120. }
  3121. fireEvent(series, 'renderedCanvas');
  3122. // Do not use chart.hideLoading, as it runs JS animation and
  3123. // will be blocked by buildKDTree. CSS animation looks good, but
  3124. // then it must be deleted in timeout. If we add the module to
  3125. // core, change hideLoading so we can skip this block.
  3126. if (loadingShown) {
  3127. extend(loadingDiv.style, {
  3128. transition: 'opacity 250ms',
  3129. opacity: 0
  3130. });
  3131. chart.loadingShown = false;
  3132. destroyLoadingDiv = setTimeout(function () {
  3133. if (loadingDiv.parentNode) { // In exporting it is falsy
  3134. loadingDiv.parentNode.removeChild(loadingDiv);
  3135. }
  3136. chart.loadingDiv = chart.loadingSpan = null;
  3137. }, 250);
  3138. }
  3139. // Go back to prototype, ready to build
  3140. delete series.buildKDTree;
  3141. series.buildKDTree();
  3142. // Don't do async on export, the exportChart, getSVGForExport and
  3143. // getSVG methods are not chained for it.
  3144. }, chart.renderer.forExport ? Number.MAX_VALUE : void 0);
  3145. }
  3146. });
  3147. seriesTypes.scatter.prototype.cvsMarkerCircle = function (ctx, clientX, plotY, r) {
  3148. ctx.moveTo(clientX, plotY);
  3149. ctx.arc(clientX, plotY, r, 0, 2 * Math.PI, false);
  3150. };
  3151. // Rect is twice as fast as arc, should be used for small markers
  3152. seriesTypes.scatter.prototype.cvsMarkerSquare = function (ctx, clientX, plotY, r) {
  3153. ctx.rect(clientX - r, plotY - r, r * 2, r * 2);
  3154. };
  3155. seriesTypes.scatter.prototype.fill = true;
  3156. if (seriesTypes.bubble) {
  3157. seriesTypes.bubble.prototype.cvsMarkerCircle = function (ctx, clientX, plotY, r, i) {
  3158. ctx.moveTo(clientX, plotY);
  3159. ctx.arc(clientX, plotY, this.radii && this.radii[i], 0, 2 * Math.PI, false);
  3160. };
  3161. seriesTypes.bubble.prototype.cvsStrokeBatch = 1;
  3162. }
  3163. extend(seriesTypes.area.prototype, {
  3164. cvsDrawPoint: function (ctx, clientX, plotY, yBottom, lastPoint) {
  3165. if (lastPoint && clientX !== lastPoint.clientX) {
  3166. ctx.moveTo(lastPoint.clientX, lastPoint.yBottom);
  3167. ctx.lineTo(lastPoint.clientX, lastPoint.plotY);
  3168. ctx.lineTo(clientX, plotY);
  3169. ctx.lineTo(clientX, yBottom);
  3170. }
  3171. },
  3172. fill: true,
  3173. fillOpacity: true,
  3174. sampling: true
  3175. });
  3176. extend(seriesTypes.column.prototype, {
  3177. cvsDrawPoint: function (ctx, clientX, plotY, yBottom) {
  3178. ctx.rect(clientX - 1, plotY, 1, yBottom - plotY);
  3179. },
  3180. fill: true,
  3181. sampling: true
  3182. });
  3183. Chart.prototype.callbacks.push(function (chart) {
  3184. /**
  3185. * @private
  3186. */
  3187. function canvasToSVG() {
  3188. if (chart.boostCopy) {
  3189. chart.boostCopy();
  3190. }
  3191. }
  3192. /**
  3193. * @private
  3194. */
  3195. function clear() {
  3196. if (chart.renderTarget) {
  3197. chart.renderTarget.attr({ href: '' });
  3198. }
  3199. if (chart.canvas) {
  3200. chart.canvas.getContext('2d').clearRect(0, 0, chart.canvas.width, chart.canvas.height);
  3201. }
  3202. }
  3203. addEvent(chart, 'predraw', clear);
  3204. addEvent(chart, 'render', canvasToSVG);
  3205. });
  3206. };
  3207. return initCanvasBoost;
  3208. });
  3209. _registerModule(_modules, 'Extensions/Boost/BoostOverrides.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Options.js'], _modules['Core/Series/Point.js'], _modules['Core/Series/Series.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js'], _modules['Extensions/Boost/BoostUtils.js'], _modules['Extensions/Boost/Boostables.js'], _modules['Extensions/Boost/BoostableMap.js']], function (Chart, O, Point, Series, SeriesRegistry, U, butils, boostable, boostableMap) {
  3210. /* *
  3211. *
  3212. * Copyright (c) 2019-2021 Highsoft AS
  3213. *
  3214. * Boost module: stripped-down renderer for higher performance
  3215. *
  3216. * License: highcharts.com/license
  3217. *
  3218. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3219. *
  3220. * */
  3221. var getOptions = O.getOptions;
  3222. var seriesTypes = SeriesRegistry.seriesTypes;
  3223. var addEvent = U.addEvent,
  3224. error = U.error,
  3225. isArray = U.isArray,
  3226. isNumber = U.isNumber,
  3227. pick = U.pick,
  3228. wrap = U.wrap;
  3229. var boostEnabled = butils.boostEnabled,
  3230. shouldForceChartSeriesBoosting = butils.shouldForceChartSeriesBoosting,
  3231. plotOptions = getOptions().plotOptions;
  3232. /**
  3233. * Returns true if the chart is in series boost mode.
  3234. *
  3235. * @function Highcharts.Chart#isChartSeriesBoosting
  3236. *
  3237. * @param {Highcharts.Chart} chart
  3238. * the chart to check
  3239. *
  3240. * @return {boolean}
  3241. * true if the chart is in series boost mode
  3242. */
  3243. Chart.prototype.isChartSeriesBoosting = function () {
  3244. var isSeriesBoosting,
  3245. threshold = pick(this.options.boost && this.options.boost.seriesThreshold, 50);
  3246. isSeriesBoosting = threshold <= this.series.length ||
  3247. shouldForceChartSeriesBoosting(this);
  3248. return isSeriesBoosting;
  3249. };
  3250. /* eslint-disable valid-jsdoc */
  3251. /**
  3252. * Get the clip rectangle for a target, either a series or the chart. For the
  3253. * chart, we need to consider the maximum extent of its Y axes, in case of
  3254. * Highcharts Stock panes and navigator.
  3255. *
  3256. * @private
  3257. * @function Highcharts.Chart#getBoostClipRect
  3258. *
  3259. * @param {Highcharts.Chart} target
  3260. *
  3261. * @return {Highcharts.BBoxObject}
  3262. */
  3263. Chart.prototype.getBoostClipRect = function (target) {
  3264. var clipBox = {
  3265. x: this.plotLeft,
  3266. y: this.plotTop,
  3267. width: this.plotWidth,
  3268. height: this.plotHeight
  3269. };
  3270. if (target === this) {
  3271. var verticalAxes = this.inverted ? this.xAxis : this.yAxis; // #14444
  3272. if (verticalAxes.length <= 1) {
  3273. clipBox.y = Math.min(verticalAxes[0].pos,
  3274. clipBox.y);
  3275. clipBox.height = verticalAxes[0].pos - this.plotTop + verticalAxes[0].len;
  3276. }
  3277. else {
  3278. clipBox.height = this.plotHeight;
  3279. }
  3280. }
  3281. return clipBox;
  3282. };
  3283. /**
  3284. * Return a full Point object based on the index.
  3285. * The boost module uses stripped point objects for performance reasons.
  3286. *
  3287. * @function Highcharts.Series#getPoint
  3288. *
  3289. * @param {object|Highcharts.Point} boostPoint
  3290. * A stripped-down point object
  3291. *
  3292. * @return {Highcharts.Point}
  3293. * A Point object as per https://api.highcharts.com/highcharts#Point
  3294. */
  3295. Series.prototype.getPoint = function (boostPoint) {
  3296. var point = boostPoint,
  3297. xData = (this.xData || this.options.xData || this.processedXData ||
  3298. false);
  3299. if (boostPoint && !(boostPoint instanceof this.pointClass)) {
  3300. point = (new this.pointClass()).init(// eslint-disable-line new-cap
  3301. this, this.options.data[boostPoint.i], xData ? xData[boostPoint.i] : void 0);
  3302. point.category = pick(this.xAxis.categories ?
  3303. this.xAxis.categories[point.x] :
  3304. point.x, // @todo simplify
  3305. point.x);
  3306. point.dist = boostPoint.dist;
  3307. point.distX = boostPoint.distX;
  3308. point.plotX = boostPoint.plotX;
  3309. point.plotY = boostPoint.plotY;
  3310. point.index = boostPoint.i;
  3311. point.isInside = this.isPointInside(boostPoint);
  3312. }
  3313. return point;
  3314. };
  3315. /* eslint-disable no-invalid-this */
  3316. // Return a point instance from the k-d-tree
  3317. wrap(Series.prototype, 'searchPoint', function (proceed) {
  3318. return this.getPoint(proceed.apply(this, [].slice.call(arguments, 1)));
  3319. });
  3320. // For inverted series, we need to swap X-Y values before running base methods
  3321. wrap(Point.prototype, 'haloPath', function (proceed) {
  3322. var halo,
  3323. point = this,
  3324. series = point.series,
  3325. chart = series.chart,
  3326. plotX = point.plotX,
  3327. plotY = point.plotY,
  3328. inverted = chart.inverted;
  3329. if (series.isSeriesBoosting && inverted) {
  3330. point.plotX = series.yAxis.len - plotY;
  3331. point.plotY = series.xAxis.len - plotX;
  3332. }
  3333. halo = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3334. if (series.isSeriesBoosting && inverted) {
  3335. point.plotX = plotX;
  3336. point.plotY = plotY;
  3337. }
  3338. return halo;
  3339. });
  3340. wrap(Series.prototype, 'markerAttribs', function (proceed, point) {
  3341. var attribs,
  3342. series = this,
  3343. chart = series.chart,
  3344. plotX = point.plotX,
  3345. plotY = point.plotY,
  3346. inverted = chart.inverted;
  3347. if (series.isSeriesBoosting && inverted) {
  3348. point.plotX = series.yAxis.len - plotY;
  3349. point.plotY = series.xAxis.len - plotX;
  3350. }
  3351. attribs = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3352. if (series.isSeriesBoosting && inverted) {
  3353. point.plotX = plotX;
  3354. point.plotY = plotY;
  3355. }
  3356. return attribs;
  3357. });
  3358. /*
  3359. * Extend series.destroy to also remove the fake k-d-tree points (#5137).
  3360. * Normally this is handled by Series.destroy that calls Point.destroy,
  3361. * but the fake search points are not registered like that.
  3362. */
  3363. addEvent(Series, 'destroy', function () {
  3364. var series = this,
  3365. chart = series.chart;
  3366. if (chart.markerGroup === series.markerGroup) {
  3367. series.markerGroup = null;
  3368. }
  3369. if (chart.hoverPoints) {
  3370. chart.hoverPoints = chart.hoverPoints.filter(function (point) {
  3371. return point.series === series;
  3372. });
  3373. }
  3374. if (chart.hoverPoint && chart.hoverPoint.series === series) {
  3375. chart.hoverPoint = null;
  3376. }
  3377. });
  3378. /*
  3379. * Do not compute extremes when min and max are set.
  3380. * If we use this in the core, we can add the hook
  3381. * to hasExtremes to the methods directly.
  3382. */
  3383. wrap(Series.prototype, 'getExtremes', function (proceed) {
  3384. if (!this.isSeriesBoosting || (!this.hasExtremes || !this.hasExtremes())) {
  3385. return proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3386. }
  3387. return {};
  3388. });
  3389. /*
  3390. * Override a bunch of methods the same way. If the number of points is
  3391. * below the threshold, run the original method. If not, check for a
  3392. * canvas version or do nothing.
  3393. *
  3394. * Note that we're not overriding any of these for heatmaps.
  3395. */
  3396. [
  3397. 'translate',
  3398. 'generatePoints',
  3399. 'drawTracker',
  3400. 'drawPoints',
  3401. 'render'
  3402. ].forEach(function (method) {
  3403. /**
  3404. * @private
  3405. */
  3406. function branch(proceed) {
  3407. var letItPass = this.options.stacking &&
  3408. (method === 'translate' || method === 'generatePoints');
  3409. if (!this.isSeriesBoosting ||
  3410. letItPass ||
  3411. !boostEnabled(this.chart) ||
  3412. this.type === 'heatmap' ||
  3413. this.type === 'treemap' ||
  3414. !boostableMap[this.type] ||
  3415. this.options.boostThreshold === 0) {
  3416. proceed.call(this);
  3417. // If a canvas version of the method exists, like renderCanvas(), run
  3418. }
  3419. else if (this[method + 'Canvas']) {
  3420. this[method + 'Canvas']();
  3421. }
  3422. }
  3423. wrap(Series.prototype, method, branch);
  3424. // A special case for some types - their translate method is already wrapped
  3425. if (method === 'translate') {
  3426. [
  3427. 'column',
  3428. 'bar',
  3429. 'arearange',
  3430. 'columnrange',
  3431. 'heatmap',
  3432. 'treemap'
  3433. ].forEach(function (type) {
  3434. if (seriesTypes[type]) {
  3435. wrap(seriesTypes[type].prototype, method, branch);
  3436. }
  3437. });
  3438. }
  3439. });
  3440. // If the series is a heatmap or treemap, or if the series is not boosting
  3441. // do the default behaviour. Otherwise, process if the series has no extremes.
  3442. wrap(Series.prototype, 'processData', function (proceed) {
  3443. var series = this,
  3444. dataToMeasure = this.options.data,
  3445. firstPoint;
  3446. /**
  3447. * Used twice in this function, first on this.options.data, the second
  3448. * time it runs the check again after processedXData is built.
  3449. * @private
  3450. * @todo Check what happens with data grouping
  3451. */
  3452. function getSeriesBoosting(data) {
  3453. return series.chart.isChartSeriesBoosting() || ((data ? data.length : 0) >=
  3454. (series.options.boostThreshold || Number.MAX_VALUE));
  3455. }
  3456. if (boostEnabled(this.chart) && boostableMap[this.type]) {
  3457. // If there are no extremes given in the options, we also need to
  3458. // process the data to read the data extremes. If this is a heatmap, do
  3459. // default behaviour.
  3460. if (!getSeriesBoosting(dataToMeasure) || // First pass with options.data
  3461. this.type === 'heatmap' ||
  3462. this.type === 'treemap' ||
  3463. this.options.stacking || // processedYData for the stack (#7481)
  3464. !this.hasExtremes ||
  3465. !this.hasExtremes(true)) {
  3466. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3467. dataToMeasure = this.processedXData;
  3468. }
  3469. // Set the isBoosting flag, second pass with processedXData to see if we
  3470. // have zoomed.
  3471. this.isSeriesBoosting = getSeriesBoosting(dataToMeasure);
  3472. // Enter or exit boost mode
  3473. if (this.isSeriesBoosting) {
  3474. // Force turbo-mode:
  3475. if (this.options.data && this.options.data.length) {
  3476. firstPoint = this.getFirstValidPoint(this.options.data);
  3477. if (!isNumber(firstPoint) && !isArray(firstPoint)) {
  3478. error(12, false, this.chart);
  3479. }
  3480. }
  3481. this.enterBoost();
  3482. }
  3483. else if (this.exitBoost) {
  3484. this.exitBoost();
  3485. }
  3486. // The series type is not boostable
  3487. }
  3488. else {
  3489. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3490. }
  3491. });
  3492. addEvent(Series, 'hide', function () {
  3493. if (this.canvas && this.renderTarget) {
  3494. if (this.ogl) {
  3495. this.ogl.clear();
  3496. }
  3497. this.boostClear();
  3498. }
  3499. });
  3500. /**
  3501. * Enter boost mode and apply boost-specific properties.
  3502. *
  3503. * @function Highcharts.Series#enterBoost
  3504. */
  3505. Series.prototype.enterBoost = function () {
  3506. this.alteredByBoost = [];
  3507. // Save the original values, including whether it was an own property or
  3508. // inherited from the prototype.
  3509. ['allowDG', 'directTouch', 'stickyTracking'].forEach(function (prop) {
  3510. this.alteredByBoost.push({
  3511. prop: prop,
  3512. val: this[prop],
  3513. own: Object.hasOwnProperty.call(this, prop)
  3514. });
  3515. }, this);
  3516. this.allowDG = false;
  3517. this.directTouch = false;
  3518. this.stickyTracking = true;
  3519. // Prevent animation when zooming in on boosted series(#13421).
  3520. this.finishedAnimating = true;
  3521. // Hide series label if any
  3522. if (this.labelBySeries) {
  3523. this.labelBySeries = this.labelBySeries.destroy();
  3524. }
  3525. };
  3526. /**
  3527. * Exit from boost mode and restore non-boost properties.
  3528. *
  3529. * @function Highcharts.Series#exitBoost
  3530. */
  3531. Series.prototype.exitBoost = function () {
  3532. // Reset instance properties and/or delete instance properties and go back
  3533. // to prototype
  3534. (this.alteredByBoost || []).forEach(function (setting) {
  3535. if (setting.own) {
  3536. this[setting.prop] = setting.val;
  3537. }
  3538. else {
  3539. // Revert to prototype
  3540. delete this[setting.prop];
  3541. }
  3542. }, this);
  3543. // Clear previous run
  3544. if (this.boostClear) {
  3545. this.boostClear();
  3546. }
  3547. };
  3548. /**
  3549. * @private
  3550. * @function Highcharts.Series#hasExtremes
  3551. *
  3552. * @param {boolean} checkX
  3553. *
  3554. * @return {boolean}
  3555. */
  3556. Series.prototype.hasExtremes = function (checkX) {
  3557. var options = this.options,
  3558. data = options.data,
  3559. xAxis = this.xAxis && this.xAxis.options,
  3560. yAxis = this.yAxis && this.yAxis.options,
  3561. colorAxis = this.colorAxis && this.colorAxis.options;
  3562. return data.length > (options.boostThreshold || Number.MAX_VALUE) &&
  3563. // Defined yAxis extremes
  3564. isNumber(yAxis.min) &&
  3565. isNumber(yAxis.max) &&
  3566. // Defined (and required) xAxis extremes
  3567. (!checkX ||
  3568. (isNumber(xAxis.min) && isNumber(xAxis.max))) &&
  3569. // Defined (e.g. heatmap) colorAxis extremes
  3570. (!colorAxis ||
  3571. (isNumber(colorAxis.min) && isNumber(colorAxis.max)));
  3572. };
  3573. /**
  3574. * If implemented in the core, parts of this can probably be
  3575. * shared with other similar methods in Highcharts.
  3576. *
  3577. * @function Highcharts.Series#destroyGraphics
  3578. */
  3579. Series.prototype.destroyGraphics = function () {
  3580. var _this = this;
  3581. var series = this,
  3582. points = this.points,
  3583. point,
  3584. i;
  3585. if (points) {
  3586. for (i = 0; i < points.length; i = i + 1) {
  3587. point = points[i];
  3588. if (point && point.destroyElements) {
  3589. point.destroyElements(); // #7557
  3590. }
  3591. }
  3592. }
  3593. ['graph', 'area', 'tracker'].forEach(function (prop) {
  3594. if (series[prop]) {
  3595. series[prop] = series[prop].destroy();
  3596. }
  3597. });
  3598. if (this.getZonesGraphs) {
  3599. var props = this.getZonesGraphs([['graph', 'highcharts-graph']]);
  3600. props.forEach(function (prop) {
  3601. var zoneGraph = _this[prop[0]];
  3602. if (zoneGraph) {
  3603. _this[prop[0]] = zoneGraph.destroy();
  3604. }
  3605. });
  3606. }
  3607. };
  3608. // Set default options
  3609. boostable.forEach(function (type) {
  3610. if (plotOptions[type]) {
  3611. plotOptions[type].boostThreshold = 5000;
  3612. plotOptions[type].boostData = [];
  3613. seriesTypes[type].prototype.fillOpacity = true;
  3614. }
  3615. });
  3616. });
  3617. _registerModule(_modules, 'Extensions/Boost/NamedColors.js', [_modules['Core/Color/Color.js']], function (Color) {
  3618. /* *
  3619. *
  3620. * Copyright (c) 2019-2021 Highsoft AS
  3621. *
  3622. * Boost module: stripped-down renderer for higher performance
  3623. *
  3624. * License: highcharts.com/license
  3625. *
  3626. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3627. *
  3628. * */
  3629. // Register color names since GL can't render those directly.
  3630. // TODO: When supporting modern syntax, make this a const and a named export
  3631. var defaultHTMLColorMap = {
  3632. aliceblue: '#f0f8ff',
  3633. antiquewhite: '#faebd7',
  3634. aqua: '#00ffff',
  3635. aquamarine: '#7fffd4',
  3636. azure: '#f0ffff',
  3637. beige: '#f5f5dc',
  3638. bisque: '#ffe4c4',
  3639. black: '#000000',
  3640. blanchedalmond: '#ffebcd',
  3641. blue: '#0000ff',
  3642. blueviolet: '#8a2be2',
  3643. brown: '#a52a2a',
  3644. burlywood: '#deb887',
  3645. cadetblue: '#5f9ea0',
  3646. chartreuse: '#7fff00',
  3647. chocolate: '#d2691e',
  3648. coral: '#ff7f50',
  3649. cornflowerblue: '#6495ed',
  3650. cornsilk: '#fff8dc',
  3651. crimson: '#dc143c',
  3652. cyan: '#00ffff',
  3653. darkblue: '#00008b',
  3654. darkcyan: '#008b8b',
  3655. darkgoldenrod: '#b8860b',
  3656. darkgray: '#a9a9a9',
  3657. darkgreen: '#006400',
  3658. darkkhaki: '#bdb76b',
  3659. darkmagenta: '#8b008b',
  3660. darkolivegreen: '#556b2f',
  3661. darkorange: '#ff8c00',
  3662. darkorchid: '#9932cc',
  3663. darkred: '#8b0000',
  3664. darksalmon: '#e9967a',
  3665. darkseagreen: '#8fbc8f',
  3666. darkslateblue: '#483d8b',
  3667. darkslategray: '#2f4f4f',
  3668. darkturquoise: '#00ced1',
  3669. darkviolet: '#9400d3',
  3670. deeppink: '#ff1493',
  3671. deepskyblue: '#00bfff',
  3672. dimgray: '#696969',
  3673. dodgerblue: '#1e90ff',
  3674. feldspar: '#d19275',
  3675. firebrick: '#b22222',
  3676. floralwhite: '#fffaf0',
  3677. forestgreen: '#228b22',
  3678. fuchsia: '#ff00ff',
  3679. gainsboro: '#dcdcdc',
  3680. ghostwhite: '#f8f8ff',
  3681. gold: '#ffd700',
  3682. goldenrod: '#daa520',
  3683. gray: '#808080',
  3684. green: '#008000',
  3685. greenyellow: '#adff2f',
  3686. honeydew: '#f0fff0',
  3687. hotpink: '#ff69b4',
  3688. indianred: '#cd5c5c',
  3689. indigo: '#4b0082',
  3690. ivory: '#fffff0',
  3691. khaki: '#f0e68c',
  3692. lavender: '#e6e6fa',
  3693. lavenderblush: '#fff0f5',
  3694. lawngreen: '#7cfc00',
  3695. lemonchiffon: '#fffacd',
  3696. lightblue: '#add8e6',
  3697. lightcoral: '#f08080',
  3698. lightcyan: '#e0ffff',
  3699. lightgoldenrodyellow: '#fafad2',
  3700. lightgrey: '#d3d3d3',
  3701. lightgreen: '#90ee90',
  3702. lightpink: '#ffb6c1',
  3703. lightsalmon: '#ffa07a',
  3704. lightseagreen: '#20b2aa',
  3705. lightskyblue: '#87cefa',
  3706. lightslateblue: '#8470ff',
  3707. lightslategray: '#778899',
  3708. lightsteelblue: '#b0c4de',
  3709. lightyellow: '#ffffe0',
  3710. lime: '#00ff00',
  3711. limegreen: '#32cd32',
  3712. linen: '#faf0e6',
  3713. magenta: '#ff00ff',
  3714. maroon: '#800000',
  3715. mediumaquamarine: '#66cdaa',
  3716. mediumblue: '#0000cd',
  3717. mediumorchid: '#ba55d3',
  3718. mediumpurple: '#9370d8',
  3719. mediumseagreen: '#3cb371',
  3720. mediumslateblue: '#7b68ee',
  3721. mediumspringgreen: '#00fa9a',
  3722. mediumturquoise: '#48d1cc',
  3723. mediumvioletred: '#c71585',
  3724. midnightblue: '#191970',
  3725. mintcream: '#f5fffa',
  3726. mistyrose: '#ffe4e1',
  3727. moccasin: '#ffe4b5',
  3728. navajowhite: '#ffdead',
  3729. navy: '#000080',
  3730. oldlace: '#fdf5e6',
  3731. olive: '#808000',
  3732. olivedrab: '#6b8e23',
  3733. orange: '#ffa500',
  3734. orangered: '#ff4500',
  3735. orchid: '#da70d6',
  3736. palegoldenrod: '#eee8aa',
  3737. palegreen: '#98fb98',
  3738. paleturquoise: '#afeeee',
  3739. palevioletred: '#d87093',
  3740. papayawhip: '#ffefd5',
  3741. peachpuff: '#ffdab9',
  3742. peru: '#cd853f',
  3743. pink: '#ffc0cb',
  3744. plum: '#dda0dd',
  3745. powderblue: '#b0e0e6',
  3746. purple: '#800080',
  3747. red: '#ff0000',
  3748. rosybrown: '#bc8f8f',
  3749. royalblue: '#4169e1',
  3750. saddlebrown: '#8b4513',
  3751. salmon: '#fa8072',
  3752. sandybrown: '#f4a460',
  3753. seagreen: '#2e8b57',
  3754. seashell: '#fff5ee',
  3755. sienna: '#a0522d',
  3756. silver: '#c0c0c0',
  3757. skyblue: '#87ceeb',
  3758. slateblue: '#6a5acd',
  3759. slategray: '#708090',
  3760. snow: '#fffafa',
  3761. springgreen: '#00ff7f',
  3762. steelblue: '#4682b4',
  3763. tan: '#d2b48c',
  3764. teal: '#008080',
  3765. thistle: '#d8bfd8',
  3766. tomato: '#ff6347',
  3767. turquoise: '#40e0d0',
  3768. violet: '#ee82ee',
  3769. violetred: '#d02090',
  3770. wheat: '#f5deb3',
  3771. white: '#ffffff',
  3772. whitesmoke: '#f5f5f5',
  3773. yellow: '#ffff00',
  3774. yellowgreen: '#9acd32'
  3775. };
  3776. Color.names = defaultHTMLColorMap;
  3777. return defaultHTMLColorMap;
  3778. });
  3779. _registerModule(_modules, 'Extensions/Boost/Boost.js', [_modules['Extensions/Boost/BoostUtils.js'], _modules['Extensions/Boost/BoostInit.js'], _modules['Extensions/BoostCanvas.js'], _modules['Core/Utilities.js']], function (butils, init, initCanvasBoost, U) {
  3780. /* *
  3781. *
  3782. * Copyright (c) 2019-2021 Highsoft AS
  3783. *
  3784. * Boost module: stripped-down renderer for higher performance
  3785. *
  3786. * License: highcharts.com/license
  3787. *
  3788. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3789. *
  3790. * */
  3791. var error = U.error;
  3792. // These need to be fixed when we support named imports
  3793. var hasWebGLSupport = butils.hasWebGLSupport;
  3794. if (!hasWebGLSupport()) {
  3795. if (typeof initCanvasBoost !== 'undefined') {
  3796. // Fallback to canvas boost
  3797. initCanvasBoost();
  3798. }
  3799. else {
  3800. error(26);
  3801. }
  3802. }
  3803. else {
  3804. // WebGL support is alright, and we're good to go.
  3805. init();
  3806. }
  3807. });
  3808. _registerModule(_modules, 'masters/modules/boost.src.js', [], function () {
  3809. });
  3810. }));