boost.src.js 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768
  1. /**
  2. * @license Highcharts JS v9.0.1 (2021-02-16)
  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, pcolor, 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, 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. shapeArgs,
  1053. swidth,
  1054. pointAttr;
  1055. if (typeof plotY !== 'undefined' &&
  1056. !isNaN(plotY) &&
  1057. point.y !== null) {
  1058. shapeArgs = point.shapeArgs;
  1059. pointAttr = chart.styledMode ?
  1060. point.series
  1061. .colorAttribs(point) :
  1062. pointAttr = point.series.pointAttribs(point);
  1063. swidth = pointAttr['stroke-width'] || 0;
  1064. // Handle point colors
  1065. pcolor = color(pointAttr.fill).rgba;
  1066. pcolor[0] /= 255.0;
  1067. pcolor[1] /= 255.0;
  1068. pcolor[2] /= 255.0;
  1069. // So there are two ways of doing this. Either we can
  1070. // create a rectangle of two triangles, or we can do a
  1071. // point and use point size. Latter is faster, but
  1072. // only supports squares. So we're doing triangles.
  1073. // We could also use one color per. vertice to get
  1074. // better color interpolation.
  1075. // If there's stroking, we do an additional rect
  1076. if (series.type === 'treemap') {
  1077. swidth = swidth || 1;
  1078. scolor = color(pointAttr.stroke).rgba;
  1079. scolor[0] /= 255.0;
  1080. scolor[1] /= 255.0;
  1081. scolor[2] /= 255.0;
  1082. pushRect(shapeArgs.x, shapeArgs.y, shapeArgs.width, shapeArgs.height, scolor);
  1083. swidth /= 2;
  1084. }
  1085. // } else {
  1086. // swidth = 0;
  1087. // }
  1088. // Fixes issues with inverted heatmaps (see #6981)
  1089. // The root cause is that the coordinate system is flipped.
  1090. // In other words, instead of [0,0] being top-left, it's
  1091. // bottom-right. This causes a vertical and horizontal flip
  1092. // in the resulting image, making it rotated 180 degrees.
  1093. if (series.type === 'heatmap' && chart.inverted) {
  1094. shapeArgs.x = xAxis.len - shapeArgs.x;
  1095. shapeArgs.y = yAxis.len - shapeArgs.y;
  1096. shapeArgs.width = -shapeArgs.width;
  1097. shapeArgs.height = -shapeArgs.height;
  1098. }
  1099. pushRect(shapeArgs.x + swidth, shapeArgs.y + swidth, shapeArgs.width - (swidth * 2), shapeArgs.height - (swidth * 2), pcolor);
  1100. }
  1101. });
  1102. closeSegment();
  1103. return;
  1104. }
  1105. // Extract color axis
  1106. // (chart.axes || []).forEach(function (a) {
  1107. // if (H.ColorAxis && a instanceof H.ColorAxis) {
  1108. // caxis = a;
  1109. // }
  1110. // });
  1111. while (i < sdata.length - 1) {
  1112. d = sdata[++i];
  1113. // px = x = y = z = nx = low = false;
  1114. // chartDestroyed = typeof chart.index === 'undefined';
  1115. // nextInside = prevInside = pcolor = isXInside = isYInside = false;
  1116. // drawAsBar = asBar[series.type];
  1117. if (chartDestroyed) {
  1118. break;
  1119. }
  1120. // Uncomment this to enable color by point.
  1121. // This currently left disabled as the charts look really ugly
  1122. // when enabled and there's a lot of points.
  1123. // Leaving in for the future (tm).
  1124. // if (colorByPoint) {
  1125. // colorIndex = ++colorIndex %
  1126. // series.chart.options.colors.length;
  1127. // pcolor = toRGBAFast(series.chart.options.colors[colorIndex]);
  1128. // pcolor[0] /= 255.0;
  1129. // pcolor[1] /= 255.0;
  1130. // pcolor[2] /= 255.0;
  1131. // }
  1132. // Handle the point.color option (#5999)
  1133. var pointOptions = rawData && rawData[i];
  1134. if (!useRaw && isObject(pointOptions, true)) {
  1135. if (pointOptions.color) {
  1136. pcolor = color(pointOptions.color).rgba;
  1137. pcolor[0] /= 255.0;
  1138. pcolor[1] /= 255.0;
  1139. pcolor[2] /= 255.0;
  1140. }
  1141. }
  1142. if (useRaw) {
  1143. x = d[0];
  1144. y = d[1];
  1145. if (sdata[i + 1]) {
  1146. nx = sdata[i + 1][0];
  1147. }
  1148. if (sdata[i - 1]) {
  1149. px = sdata[i - 1][0];
  1150. }
  1151. if (d.length >= 3) {
  1152. z = d[2];
  1153. if (d[2] > inst.zMax) {
  1154. inst.zMax = d[2];
  1155. }
  1156. if (d[2] < inst.zMin) {
  1157. inst.zMin = d[2];
  1158. }
  1159. }
  1160. }
  1161. else {
  1162. x = d;
  1163. y = yData[i];
  1164. if (sdata[i + 1]) {
  1165. nx = sdata[i + 1];
  1166. }
  1167. if (sdata[i - 1]) {
  1168. px = sdata[i - 1];
  1169. }
  1170. if (zData && zData.length) {
  1171. z = zData[i];
  1172. if (zData[i] > inst.zMax) {
  1173. inst.zMax = zData[i];
  1174. }
  1175. if (zData[i] < inst.zMin) {
  1176. inst.zMin = zData[i];
  1177. }
  1178. }
  1179. }
  1180. if (!connectNulls && (x === null || y === null)) {
  1181. beginSegment();
  1182. continue;
  1183. }
  1184. if (nx && nx >= xMin && nx <= xMax) {
  1185. nextInside = true;
  1186. }
  1187. if (px && px >= xMin && px <= xMax) {
  1188. prevInside = true;
  1189. }
  1190. if (isRange) {
  1191. if (useRaw) {
  1192. y = d.slice(1, 3);
  1193. }
  1194. low = y[0];
  1195. y = y[1];
  1196. }
  1197. else if (isStacked) {
  1198. x = d.x;
  1199. y = d.stackY;
  1200. low = y - d.y;
  1201. }
  1202. if (yMin !== null &&
  1203. typeof yMin !== 'undefined' &&
  1204. yMax !== null &&
  1205. typeof yMax !== 'undefined') {
  1206. isYInside = y >= yMin && y <= yMax;
  1207. }
  1208. if (x > xMax && closestRight.x < xMax) {
  1209. closestRight.x = x;
  1210. closestRight.y = y;
  1211. }
  1212. if (x < xMin && closestLeft.x > xMin) {
  1213. closestLeft.x = x;
  1214. closestLeft.y = y;
  1215. }
  1216. if (y === null && connectNulls) {
  1217. continue;
  1218. }
  1219. // Cull points outside the extremes
  1220. if (y === null || (!isYInside && !nextInside && !prevInside)) {
  1221. beginSegment();
  1222. continue;
  1223. }
  1224. // The first point before and first after extremes should be
  1225. // rendered (#9962)
  1226. if ((nx >= xMin || x >= xMin) &&
  1227. (px <= xMax || x <= xMax)) {
  1228. isXInside = true;
  1229. }
  1230. if (!isXInside && !nextInside && !prevInside) {
  1231. continue;
  1232. }
  1233. if (gapSize && x - px > gapSize) {
  1234. beginSegment();
  1235. }
  1236. // Note: Boost requires that zones are sorted!
  1237. if (zones) {
  1238. pcolor = zoneDefColor.rgba;
  1239. zones.some(function (// eslint-disable-line no-loop-func
  1240. zone, i) {
  1241. var last = zones[i - 1];
  1242. if (typeof zone.value !== 'undefined' && y <= zone.value) {
  1243. if (!last || y >= last.value) {
  1244. pcolor = color(zone.color).rgba;
  1245. }
  1246. return true;
  1247. }
  1248. return false;
  1249. });
  1250. pcolor[0] /= 255.0;
  1251. pcolor[1] /= 255.0;
  1252. pcolor[2] /= 255.0;
  1253. }
  1254. // Skip translations - temporary floating point fix
  1255. if (!settings.useGPUTranslations) {
  1256. inst.skipTranslation = true;
  1257. x = xAxis.toPixels(x, true);
  1258. y = yAxis.toPixels(y, true);
  1259. // Make sure we're not drawing outside of the chart area.
  1260. // See #6594. Update: this is no longer required as far as I
  1261. // can tell. Leaving in for git blame in case there are edge
  1262. // cases I've not found. Having this in breaks #10246.
  1263. // if (y > plotHeight) {
  1264. // y = plotHeight;
  1265. // }
  1266. if (x > plotWidth) {
  1267. // If this is rendered as a point, just skip drawing it
  1268. // entirely, as we're not dependandt on lineTo'ing to it.
  1269. // See #8197
  1270. if (inst.drawMode === 'points') {
  1271. continue;
  1272. }
  1273. // Having this here will clamp markers and make the angle
  1274. // of the last line wrong. See 9166.
  1275. // x = plotWidth;
  1276. }
  1277. }
  1278. // No markers on out of bounds things.
  1279. // Out of bound things are shown if and only if the next
  1280. // or previous point is inside the rect.
  1281. if (inst.hasMarkers && isXInside) {
  1282. // x = Highcharts.correctFloat(
  1283. // Math.min(Math.max(-1e5, xAxis.translate(
  1284. // x,
  1285. // 0,
  1286. // 0,
  1287. // 0,
  1288. // 1,
  1289. // 0.5,
  1290. // false
  1291. // )), 1e5)
  1292. // );
  1293. if (lastX !== false) {
  1294. series.closestPointRangePx = Math.min(series.closestPointRangePx, Math.abs(x - lastX));
  1295. }
  1296. }
  1297. // If the last _drawn_ point is closer to this point than the
  1298. // threshold, skip it. Shaves off 20-100ms in processing.
  1299. if (!settings.useGPUTranslations &&
  1300. !settings.usePreallocated &&
  1301. (lastX && Math.abs(x - lastX) < cullXThreshold) &&
  1302. (lastY && Math.abs(y - lastY) < cullYThreshold)) {
  1303. if (settings.debug.showSkipSummary) {
  1304. ++skipped;
  1305. }
  1306. continue;
  1307. }
  1308. if (drawAsBar) {
  1309. // maxVal = y;
  1310. minVal = low;
  1311. if (low === false || typeof low === 'undefined') {
  1312. if (y < 0) {
  1313. minVal = y;
  1314. }
  1315. else {
  1316. minVal = 0;
  1317. }
  1318. }
  1319. if (!isRange && !isStacked) {
  1320. minVal = Math.max(threshold === null ? yMin : threshold, // #5268
  1321. yMin); // #8731
  1322. }
  1323. if (!settings.useGPUTranslations) {
  1324. minVal = yAxis.toPixels(minVal, true);
  1325. }
  1326. // Need to add an extra point here
  1327. vertice(x, minVal, 0, 0, pcolor);
  1328. }
  1329. // Do step line if enabled.
  1330. // Draws an additional point at the old Y at the new X.
  1331. // See #6976.
  1332. if (options.step && !firstPoint) {
  1333. vertice(x, lastY, 0, 2, pcolor);
  1334. }
  1335. vertice(x, y, 0, series.type === 'bubble' ? (z || 1) : 2, pcolor);
  1336. // Uncomment this to support color axis.
  1337. // if (caxis) {
  1338. // pcolor = color(caxis.toColor(y)).rgba;
  1339. // inst.colorData.push(color[0] / 255.0);
  1340. // inst.colorData.push(color[1] / 255.0);
  1341. // inst.colorData.push(color[2] / 255.0);
  1342. // inst.colorData.push(color[3]);
  1343. // }
  1344. lastX = x;
  1345. lastY = y;
  1346. hadPoints = true;
  1347. firstPoint = false;
  1348. }
  1349. if (settings.debug.showSkipSummary) {
  1350. console.log('skipped points:', skipped); // eslint-disable-line no-console
  1351. }
  1352. /**
  1353. * @private
  1354. */
  1355. function pushSupplementPoint(point, atStart) {
  1356. if (!settings.useGPUTranslations) {
  1357. inst.skipTranslation = true;
  1358. point.x = xAxis.toPixels(point.x, true);
  1359. point.y = yAxis.toPixels(point.y, true);
  1360. }
  1361. // We should only do this for lines, and we should ignore markers
  1362. // since there's no point here that would have a marker.
  1363. if (atStart) {
  1364. data = [point.x, point.y, 0, 2].concat(data);
  1365. return;
  1366. }
  1367. vertice(point.x, point.y, 0, 2);
  1368. }
  1369. if (!hadPoints &&
  1370. connectNulls !== false &&
  1371. series.drawMode === 'line_strip') {
  1372. if (closestLeft.x < Number.MAX_VALUE) {
  1373. // We actually need to push this *before* the complete buffer.
  1374. pushSupplementPoint(closestLeft, true);
  1375. }
  1376. if (closestRight.x > -Number.MAX_VALUE) {
  1377. pushSupplementPoint(closestRight);
  1378. }
  1379. }
  1380. closeSegment();
  1381. }
  1382. /**
  1383. * Push a series to the renderer
  1384. * If we render the series immediatly, we don't have to loop later
  1385. * @private
  1386. * @param s {Highchart.Series} - the series to push
  1387. */
  1388. function pushSeries(s) {
  1389. if (series.length > 0) {
  1390. // series[series.length - 1].to = data.length;
  1391. if (series[series.length - 1].hasMarkers) {
  1392. series[series.length - 1].markerTo = markerData.length;
  1393. }
  1394. }
  1395. if (settings.debug.timeSeriesProcessing) {
  1396. console.time('building ' + s.type + ' series'); // eslint-disable-line no-console
  1397. }
  1398. series.push({
  1399. segments: [],
  1400. // from: data.length,
  1401. markerFrom: markerData.length,
  1402. // Push RGBA values to this array to use per. point coloring.
  1403. // It should be 0-padded, so each component should be pushed in
  1404. // succession.
  1405. colorData: [],
  1406. series: s,
  1407. zMin: Number.MAX_VALUE,
  1408. zMax: -Number.MAX_VALUE,
  1409. hasMarkers: s.options.marker ?
  1410. s.options.marker.enabled !== false :
  1411. false,
  1412. showMarkers: true,
  1413. drawMode: {
  1414. 'area': 'lines',
  1415. 'arearange': 'lines',
  1416. 'areaspline': 'line_strip',
  1417. 'column': 'lines',
  1418. 'columnrange': 'lines',
  1419. 'bar': 'lines',
  1420. 'line': 'line_strip',
  1421. 'scatter': 'points',
  1422. 'heatmap': 'triangles',
  1423. 'treemap': 'triangles',
  1424. 'bubble': 'points'
  1425. }[s.type] || 'line_strip'
  1426. });
  1427. // Add the series data to our buffer(s)
  1428. pushSeriesData(s, series[series.length - 1]);
  1429. if (settings.debug.timeSeriesProcessing) {
  1430. console.timeEnd('building ' + s.type + ' series'); // eslint-disable-line no-console
  1431. }
  1432. }
  1433. /**
  1434. * Flush the renderer.
  1435. * This removes pushed series and vertices.
  1436. * Should be called after clearing and before rendering
  1437. * @private
  1438. */
  1439. function flush() {
  1440. series = [];
  1441. exports.data = data = [];
  1442. markerData = [];
  1443. if (vbuffer) {
  1444. vbuffer.destroy();
  1445. }
  1446. }
  1447. /**
  1448. * Pass x-axis to shader
  1449. * @private
  1450. * @param axis {Highcharts.Axis} - the x-axis
  1451. */
  1452. function setXAxis(axis) {
  1453. if (!shader) {
  1454. return;
  1455. }
  1456. shader.setUniform('xAxisTrans', axis.transA);
  1457. shader.setUniform('xAxisMin', axis.min);
  1458. shader.setUniform('xAxisMinPad', axis.minPixelPadding);
  1459. shader.setUniform('xAxisPointRange', axis.pointRange);
  1460. shader.setUniform('xAxisLen', axis.len);
  1461. shader.setUniform('xAxisPos', axis.pos);
  1462. shader.setUniform('xAxisCVSCoord', (!axis.horiz));
  1463. shader.setUniform('xAxisIsLog', (!!axis.logarithmic));
  1464. shader.setUniform('xAxisReversed', (!!axis.reversed));
  1465. }
  1466. /**
  1467. * Pass y-axis to shader
  1468. * @private
  1469. * @param axis {Highcharts.Axis} - the y-axis
  1470. */
  1471. function setYAxis(axis) {
  1472. if (!shader) {
  1473. return;
  1474. }
  1475. shader.setUniform('yAxisTrans', axis.transA);
  1476. shader.setUniform('yAxisMin', axis.min);
  1477. shader.setUniform('yAxisMinPad', axis.minPixelPadding);
  1478. shader.setUniform('yAxisPointRange', axis.pointRange);
  1479. shader.setUniform('yAxisLen', axis.len);
  1480. shader.setUniform('yAxisPos', axis.pos);
  1481. shader.setUniform('yAxisCVSCoord', (!axis.horiz));
  1482. shader.setUniform('yAxisIsLog', (!!axis.logarithmic));
  1483. shader.setUniform('yAxisReversed', (!!axis.reversed));
  1484. }
  1485. /**
  1486. * Set the translation threshold
  1487. * @private
  1488. * @param has {boolean} - has threshold flag
  1489. * @param translation {Float} - the threshold
  1490. */
  1491. function setThreshold(has, translation) {
  1492. shader.setUniform('hasThreshold', has);
  1493. shader.setUniform('translatedThreshold', translation);
  1494. }
  1495. /**
  1496. * Render the data
  1497. * This renders all pushed series.
  1498. * @private
  1499. */
  1500. function render(chart) {
  1501. if (chart) {
  1502. if (!chart.chartHeight || !chart.chartWidth) {
  1503. // chart.setChartSize();
  1504. }
  1505. width = chart.chartWidth || 800;
  1506. height = chart.chartHeight || 400;
  1507. }
  1508. else {
  1509. return false;
  1510. }
  1511. if (!gl || !width || !height || !shader) {
  1512. return false;
  1513. }
  1514. if (settings.debug.timeRendering) {
  1515. console.time('gl rendering'); // eslint-disable-line no-console
  1516. }
  1517. gl.canvas.width = width;
  1518. gl.canvas.height = height;
  1519. shader.bind();
  1520. gl.viewport(0, 0, width, height);
  1521. shader.setPMatrix(orthoMatrix(width, height));
  1522. if (settings.lineWidth > 1 && !H.isMS) {
  1523. gl.lineWidth(settings.lineWidth);
  1524. }
  1525. vbuffer.build(exports.data, 'aVertexPosition', 4);
  1526. vbuffer.bind();
  1527. shader.setInverted(chart.inverted);
  1528. // Render the series
  1529. series.forEach(function (s, si) {
  1530. var options = s.series.options,
  1531. shapeOptions = options.marker,
  1532. sindex,
  1533. lineWidth = (typeof options.lineWidth !== 'undefined' ?
  1534. options.lineWidth :
  1535. 1),
  1536. threshold = options.threshold,
  1537. hasThreshold = isNumber(threshold),
  1538. yBottom = s.series.yAxis.getThreshold(threshold),
  1539. translatedThreshold = yBottom,
  1540. cbuffer,
  1541. showMarkers = pick(options.marker ? options.marker.enabled : null,
  1542. s.series.xAxis.isRadial ? true : null,
  1543. s.series.closestPointRangePx >
  1544. 2 * ((options.marker ?
  1545. options.marker.radius :
  1546. 10) || 10)),
  1547. fillColor,
  1548. shapeTexture = textureHandles[(shapeOptions && shapeOptions.symbol) ||
  1549. s.series.symbol] || textureHandles.circle,
  1550. scolor = [];
  1551. if (s.segments.length === 0 ||
  1552. (s.segmentslength &&
  1553. s.segments[0].from === s.segments[0].to)) {
  1554. return;
  1555. }
  1556. if (shapeTexture.isReady) {
  1557. gl.bindTexture(gl.TEXTURE_2D, shapeTexture.handle);
  1558. shader.setTexture(shapeTexture.handle);
  1559. }
  1560. if (chart.styledMode) {
  1561. fillColor = (s.series.markerGroup &&
  1562. s.series.markerGroup.getStyle('fill'));
  1563. }
  1564. else {
  1565. fillColor =
  1566. (s.drawMode === 'points' && // #14260
  1567. s.series.pointAttribs &&
  1568. s.series.pointAttribs().fill) ||
  1569. s.series.color;
  1570. if (options.colorByPoint) {
  1571. fillColor = s.series.chart.options.colors[si];
  1572. }
  1573. }
  1574. if (s.series.fillOpacity && options.fillOpacity) {
  1575. fillColor = new Color(fillColor).setOpacity(pick(options.fillOpacity, 1.0)).get();
  1576. }
  1577. scolor = color(fillColor).rgba;
  1578. if (!settings.useAlpha) {
  1579. scolor[3] = 1.0;
  1580. }
  1581. // This is very much temporary
  1582. if (s.drawMode === 'lines' &&
  1583. settings.useAlpha &&
  1584. scolor[3] < 1) {
  1585. scolor[3] /= 10;
  1586. }
  1587. // Blending
  1588. if (options.boostBlending === 'add') {
  1589. gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  1590. gl.blendEquation(gl.FUNC_ADD);
  1591. }
  1592. else if (options.boostBlending === 'mult' ||
  1593. options.boostBlending === 'multiply') {
  1594. gl.blendFunc(gl.DST_COLOR, gl.ZERO);
  1595. }
  1596. else if (options.boostBlending === 'darken') {
  1597. gl.blendFunc(gl.ONE, gl.ONE);
  1598. gl.blendEquation(gl.FUNC_MIN);
  1599. }
  1600. else {
  1601. // gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
  1602. // gl.blendEquation(gl.FUNC_ADD);
  1603. gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  1604. }
  1605. shader.reset();
  1606. // If there are entries in the colorData buffer, build and bind it.
  1607. if (s.colorData.length > 0) {
  1608. shader.setUniform('hasColor', 1.0);
  1609. cbuffer = GLVertexBuffer(gl, shader); // eslint-disable-line new-cap
  1610. cbuffer.build(s.colorData, 'aColor', 4);
  1611. cbuffer.bind();
  1612. }
  1613. // Set series specific uniforms
  1614. shader.setColor(scolor);
  1615. setXAxis(s.series.xAxis);
  1616. setYAxis(s.series.yAxis);
  1617. setThreshold(hasThreshold, translatedThreshold);
  1618. if (s.drawMode === 'points') {
  1619. if (options.marker && isNumber(options.marker.radius)) {
  1620. shader.setPointSize(options.marker.radius * 2.0);
  1621. }
  1622. else {
  1623. shader.setPointSize(1);
  1624. }
  1625. }
  1626. // If set to true, the toPixels translations in the shader
  1627. // is skipped, i.e it's assumed that the value is a pixel coord.
  1628. shader.setSkipTranslation(s.skipTranslation);
  1629. if (s.series.type === 'bubble') {
  1630. shader.setBubbleUniforms(s.series, s.zMin, s.zMax);
  1631. }
  1632. shader.setDrawAsCircle(asCircle[s.series.type] || false);
  1633. // Do the actual rendering
  1634. // If the line width is < 0, skip rendering of the lines. See #7833.
  1635. if (lineWidth > 0 || s.drawMode !== 'line_strip') {
  1636. for (sindex = 0; sindex < s.segments.length; sindex++) {
  1637. // if (s.segments[sindex].from < s.segments[sindex].to) {
  1638. vbuffer.render(s.segments[sindex].from, s.segments[sindex].to, s.drawMode);
  1639. // }
  1640. }
  1641. }
  1642. if (s.hasMarkers && showMarkers) {
  1643. if (options.marker && isNumber(options.marker.radius)) {
  1644. shader.setPointSize(options.marker.radius * 2.0);
  1645. }
  1646. else {
  1647. shader.setPointSize(10);
  1648. }
  1649. shader.setDrawAsCircle(true);
  1650. for (sindex = 0; sindex < s.segments.length; sindex++) {
  1651. // if (s.segments[sindex].from < s.segments[sindex].to) {
  1652. vbuffer.render(s.segments[sindex].from, s.segments[sindex].to, 'POINTS');
  1653. // }
  1654. }
  1655. }
  1656. });
  1657. if (settings.debug.timeRendering) {
  1658. console.timeEnd('gl rendering'); // eslint-disable-line no-console
  1659. }
  1660. if (postRenderCallback) {
  1661. postRenderCallback();
  1662. }
  1663. flush();
  1664. }
  1665. /**
  1666. * Render the data when ready
  1667. * @private
  1668. */
  1669. function renderWhenReady(chart) {
  1670. clear();
  1671. if (chart.renderer.forExport) {
  1672. return render(chart);
  1673. }
  1674. if (isInited) {
  1675. render(chart);
  1676. }
  1677. else {
  1678. setTimeout(function () {
  1679. renderWhenReady(chart);
  1680. }, 1);
  1681. }
  1682. }
  1683. /**
  1684. * Set the viewport size in pixels
  1685. * Creates an orthographic perspective matrix and applies it.
  1686. * @private
  1687. * @param w {Integer} - the width of the viewport
  1688. * @param h {Integer} - the height of the viewport
  1689. */
  1690. function setSize(w, h) {
  1691. // Skip if there's no change, or if we have no valid shader
  1692. if ((width === w && height === h) || !shader) {
  1693. return;
  1694. }
  1695. width = w;
  1696. height = h;
  1697. shader.bind();
  1698. shader.setPMatrix(orthoMatrix(width, height));
  1699. }
  1700. /**
  1701. * Init OpenGL
  1702. * @private
  1703. * @param canvas {HTMLCanvas} - the canvas to render to
  1704. */
  1705. function init(canvas, noFlush) {
  1706. var i = 0,
  1707. contexts = [
  1708. 'webgl',
  1709. 'experimental-webgl',
  1710. 'moz-webgl',
  1711. 'webkit-3d'
  1712. ];
  1713. isInited = false;
  1714. if (!canvas) {
  1715. return false;
  1716. }
  1717. if (settings.debug.timeSetup) {
  1718. console.time('gl setup'); // eslint-disable-line no-console
  1719. }
  1720. for (; i < contexts.length; i++) {
  1721. gl = canvas.getContext(contexts[i], {
  1722. // premultipliedAlpha: false
  1723. });
  1724. if (gl) {
  1725. break;
  1726. }
  1727. }
  1728. if (gl) {
  1729. if (!noFlush) {
  1730. flush();
  1731. }
  1732. }
  1733. else {
  1734. return false;
  1735. }
  1736. gl.enable(gl.BLEND);
  1737. // gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  1738. gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
  1739. gl.disable(gl.DEPTH_TEST);
  1740. // gl.depthMask(gl.FALSE);
  1741. gl.depthFunc(gl.LESS);
  1742. shader = GLShader(gl); // eslint-disable-line new-cap
  1743. if (!shader) {
  1744. // We need to abort, there's no shader context
  1745. return false;
  1746. }
  1747. vbuffer = GLVertexBuffer(gl, shader); // eslint-disable-line new-cap
  1748. /**
  1749. * @private
  1750. */
  1751. function createTexture(name, fn) {
  1752. var props = {
  1753. isReady: false,
  1754. texture: doc.createElement('canvas'),
  1755. handle: gl.createTexture()
  1756. },
  1757. ctx = props.texture.getContext('2d');
  1758. textureHandles[name] = props;
  1759. props.texture.width = 512;
  1760. props.texture.height = 512;
  1761. ctx.mozImageSmoothingEnabled = false;
  1762. ctx.webkitImageSmoothingEnabled = false;
  1763. ctx.msImageSmoothingEnabled = false;
  1764. ctx.imageSmoothingEnabled = false;
  1765. ctx.strokeStyle = 'rgba(255, 255, 255, 0)';
  1766. ctx.fillStyle = '#FFF';
  1767. fn(ctx);
  1768. try {
  1769. gl.activeTexture(gl.TEXTURE0);
  1770. gl.bindTexture(gl.TEXTURE_2D, props.handle);
  1771. // gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
  1772. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, props.texture);
  1773. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  1774. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  1775. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1776. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  1777. // gl.generateMipmap(gl.TEXTURE_2D);
  1778. gl.bindTexture(gl.TEXTURE_2D, null);
  1779. props.isReady = true;
  1780. }
  1781. catch (e) {
  1782. // silent error
  1783. }
  1784. }
  1785. // Circle shape
  1786. createTexture('circle', function (ctx) {
  1787. ctx.beginPath();
  1788. ctx.arc(256, 256, 256, 0, 2 * Math.PI);
  1789. ctx.stroke();
  1790. ctx.fill();
  1791. });
  1792. // Square shape
  1793. createTexture('square', function (ctx) {
  1794. ctx.fillRect(0, 0, 512, 512);
  1795. });
  1796. // Diamond shape
  1797. createTexture('diamond', function (ctx) {
  1798. ctx.beginPath();
  1799. ctx.moveTo(256, 0);
  1800. ctx.lineTo(512, 256);
  1801. ctx.lineTo(256, 512);
  1802. ctx.lineTo(0, 256);
  1803. ctx.lineTo(256, 0);
  1804. ctx.fill();
  1805. });
  1806. // Triangle shape
  1807. createTexture('triangle', function (ctx) {
  1808. ctx.beginPath();
  1809. ctx.moveTo(0, 512);
  1810. ctx.lineTo(256, 0);
  1811. ctx.lineTo(512, 512);
  1812. ctx.lineTo(0, 512);
  1813. ctx.fill();
  1814. });
  1815. // Triangle shape (rotated)
  1816. createTexture('triangle-down', function (ctx) {
  1817. ctx.beginPath();
  1818. ctx.moveTo(0, 0);
  1819. ctx.lineTo(256, 512);
  1820. ctx.lineTo(512, 0);
  1821. ctx.lineTo(0, 0);
  1822. ctx.fill();
  1823. });
  1824. isInited = true;
  1825. if (settings.debug.timeSetup) {
  1826. console.timeEnd('gl setup'); // eslint-disable-line no-console
  1827. }
  1828. return true;
  1829. }
  1830. /**
  1831. * Check if we have a valid OGL context
  1832. * @private
  1833. * @returns {Boolean} - true if the context is valid
  1834. */
  1835. function valid() {
  1836. return gl !== false;
  1837. }
  1838. /**
  1839. * Check if the renderer has been initialized
  1840. * @private
  1841. * @returns {Boolean} - true if it has, false if not
  1842. */
  1843. function inited() {
  1844. return isInited;
  1845. }
  1846. /**
  1847. * @private
  1848. */
  1849. function destroy() {
  1850. flush();
  1851. vbuffer.destroy();
  1852. shader.destroy();
  1853. if (gl) {
  1854. objectEach(textureHandles, function (texture) {
  1855. if (texture.handle) {
  1856. gl.deleteTexture(texture.handle);
  1857. }
  1858. });
  1859. gl.canvas.width = 1;
  1860. gl.canvas.height = 1;
  1861. }
  1862. }
  1863. // /////////////////////////////////////////////////////////////////////////
  1864. exports = {
  1865. allocateBufferForSingleSeries: allocateBufferForSingleSeries,
  1866. pushSeries: pushSeries,
  1867. setSize: setSize,
  1868. inited: inited,
  1869. setThreshold: setThreshold,
  1870. init: init,
  1871. render: renderWhenReady,
  1872. settings: settings,
  1873. valid: valid,
  1874. clear: clear,
  1875. flush: flush,
  1876. setXAxis: setXAxis,
  1877. setYAxis: setYAxis,
  1878. data: data,
  1879. gl: getGL,
  1880. allocateBuffer: allocateBuffer,
  1881. destroy: destroy,
  1882. setOptions: setOptions
  1883. };
  1884. return exports;
  1885. }
  1886. return GLRenderer;
  1887. });
  1888. _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) {
  1889. /* *
  1890. *
  1891. * Copyright (c) 2019-2021 Highsoft AS
  1892. *
  1893. * Boost module: stripped-down renderer for higher performance
  1894. *
  1895. * License: highcharts.com/license
  1896. *
  1897. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1898. *
  1899. * */
  1900. var doc = H.doc;
  1901. var error = U.error;
  1902. var mainCanvas;
  1903. /**
  1904. * Create a canvas + context and attach it to the target
  1905. *
  1906. * @private
  1907. * @function createAndAttachRenderer
  1908. *
  1909. * @param {Highcharts.Chart} chart
  1910. * the chart
  1911. *
  1912. * @param {Highcharts.Series} series
  1913. * the series
  1914. *
  1915. * @return {Highcharts.BoostGLRenderer}
  1916. * the canvas renderer
  1917. */
  1918. function createAndAttachRenderer(chart, series) {
  1919. 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');
  1920. if (chart.isChartSeriesBoosting()) {
  1921. target = chart;
  1922. }
  1923. else {
  1924. target = series;
  1925. }
  1926. // Support for foreignObject is flimsy as best.
  1927. // IE does not support it, and Chrome has a bug which messes up
  1928. // the canvas draw order.
  1929. // As such, we force the Image fallback for now, but leaving the
  1930. // actual Canvas path in-place in case this changes in the future.
  1931. foSupported = false;
  1932. if (!mainCanvas) {
  1933. mainCanvas = doc.createElement('canvas');
  1934. }
  1935. if (!target.renderTarget) {
  1936. target.canvas = mainCanvas;
  1937. // Fall back to image tag if foreignObject isn't supported,
  1938. // or if we're exporting.
  1939. if (chart.renderer.forExport || !foSupported) {
  1940. target.renderTarget = chart.renderer.image('', 0, 0, width, height)
  1941. .addClass('highcharts-boost-canvas')
  1942. .add(targetGroup);
  1943. target.boostClear = function () {
  1944. target.renderTarget.attr({ href: '' });
  1945. };
  1946. target.boostCopy = function () {
  1947. target.boostResizeTarget();
  1948. target.renderTarget.attr({
  1949. href: target.canvas.toDataURL('image/png')
  1950. });
  1951. };
  1952. }
  1953. else {
  1954. target.renderTargetFo = chart.renderer
  1955. .createElement('foreignObject')
  1956. .add(targetGroup);
  1957. target.renderTarget = doc.createElement('canvas');
  1958. target.renderTargetCtx =
  1959. target.renderTarget.getContext('2d');
  1960. target.renderTargetFo.element.appendChild(target.renderTarget);
  1961. target.boostClear = function () {
  1962. target.renderTarget.width =
  1963. target.canvas.width;
  1964. target.renderTarget.height =
  1965. target.canvas.height;
  1966. };
  1967. target.boostCopy = function () {
  1968. target.renderTarget.width =
  1969. target.canvas.width;
  1970. target.renderTarget.height =
  1971. target.canvas.height;
  1972. target.renderTargetCtx
  1973. .drawImage(target.canvas, 0, 0);
  1974. };
  1975. }
  1976. target.boostResizeTarget = function () {
  1977. width = chart.chartWidth;
  1978. height = chart.chartHeight;
  1979. (target.renderTargetFo || target.renderTarget)
  1980. .attr({
  1981. x: 0,
  1982. y: 0,
  1983. width: width,
  1984. height: height
  1985. })
  1986. .css({
  1987. pointerEvents: 'none',
  1988. mixedBlendMode: 'normal',
  1989. opacity: alpha
  1990. });
  1991. if (target instanceof Chart) {
  1992. target.markerGroup.translate(chart.plotLeft, chart.plotTop);
  1993. }
  1994. };
  1995. target.boostClipRect = chart.renderer.clipRect();
  1996. (target.renderTargetFo || target.renderTarget)
  1997. .clip(target.boostClipRect);
  1998. if (target instanceof Chart) {
  1999. target.markerGroup = target.renderer.g().add(targetGroup);
  2000. target.markerGroup.translate(series.xAxis.pos, series.yAxis.pos);
  2001. }
  2002. }
  2003. target.canvas.width = width;
  2004. target.canvas.height = height;
  2005. target.boostClipRect.attr(chart.getBoostClipRect(target));
  2006. target.boostResizeTarget();
  2007. target.boostClear();
  2008. if (!target.ogl) {
  2009. target.ogl = GLRenderer(function () {
  2010. if (target.ogl.settings.debug.timeBufferCopy) {
  2011. console.time('buffer copy'); // eslint-disable-line no-console
  2012. }
  2013. target.boostCopy();
  2014. if (target.ogl.settings.debug.timeBufferCopy) {
  2015. console.timeEnd('buffer copy'); // eslint-disable-line no-console
  2016. }
  2017. });
  2018. if (!target.ogl.init(target.canvas)) {
  2019. // The OGL renderer couldn't be inited.
  2020. // This likely means a shader error as we wouldn't get to this point
  2021. // if there was no WebGL support.
  2022. error('[highcharts boost] - unable to init WebGL renderer');
  2023. }
  2024. // target.ogl.clear();
  2025. target.ogl.setOptions(chart.options.boost || {});
  2026. if (target instanceof Chart) {
  2027. target.ogl.allocateBuffer(chart);
  2028. }
  2029. }
  2030. target.ogl.setSize(width, height);
  2031. return target.ogl;
  2032. }
  2033. return createAndAttachRenderer;
  2034. });
  2035. _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) {
  2036. /* *
  2037. *
  2038. * Copyright (c) 2019-2021 Highsoft AS
  2039. *
  2040. * Boost module: stripped-down renderer for higher performance
  2041. *
  2042. * License: highcharts.com/license
  2043. *
  2044. * This files contains generic utility functions used by the boost module.
  2045. *
  2046. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2047. *
  2048. * */
  2049. var win = H.win,
  2050. doc = H.doc;
  2051. var pick = U.pick;
  2052. // This should be a const.
  2053. var CHUNK_SIZE = 3000;
  2054. /**
  2055. * Tolerant max() function.
  2056. *
  2057. * @private
  2058. * @function patientMax
  2059. *
  2060. * @param {...Array<Array<unknown>>} args
  2061. * Max arguments
  2062. *
  2063. * @return {number}
  2064. * Max value
  2065. */
  2066. function patientMax() {
  2067. var args = [];
  2068. for (var _i = 0; _i < arguments.length; _i++) {
  2069. args[_i] = arguments[_i];
  2070. }
  2071. var r = -Number.MAX_VALUE;
  2072. args.forEach(function (t) {
  2073. if (typeof t !== 'undefined' &&
  2074. t !== null &&
  2075. typeof t.length !== 'undefined') {
  2076. // r = r < t.length ? t.length : r;
  2077. if (t.length > 0) {
  2078. r = t.length;
  2079. return true;
  2080. }
  2081. }
  2082. });
  2083. return r;
  2084. }
  2085. /**
  2086. * Return true if ths boost.enabled option is true
  2087. *
  2088. * @private
  2089. * @function boostEnabled
  2090. *
  2091. * @param {Highcharts.Chart} chart
  2092. * The chart
  2093. *
  2094. * @return {boolean}
  2095. * True, if boost is enabled.
  2096. */
  2097. function boostEnabled(chart) {
  2098. return pick((chart &&
  2099. chart.options &&
  2100. chart.options.boost &&
  2101. chart.options.boost.enabled), true);
  2102. }
  2103. /**
  2104. * Returns true if we should force boosting the chart
  2105. * @private
  2106. * @function shouldForceChartSeriesBoosting
  2107. *
  2108. * @param {Highcharts.Chart} chart
  2109. * The chart to check for forcing on
  2110. *
  2111. * @return {boolean}
  2112. * True, if boosting should be forced.
  2113. */
  2114. function shouldForceChartSeriesBoosting(chart) {
  2115. // If there are more than five series currently boosting,
  2116. // we should boost the whole chart to avoid running out of webgl contexts.
  2117. var sboostCount = 0,
  2118. canBoostCount = 0,
  2119. allowBoostForce = pick(chart.options.boost && chart.options.boost.allowForce,
  2120. true),
  2121. series;
  2122. if (typeof chart.boostForceChartBoost !== 'undefined') {
  2123. return chart.boostForceChartBoost;
  2124. }
  2125. if (chart.series.length > 1) {
  2126. for (var i = 0; i < chart.series.length; i++) {
  2127. series = chart.series[i];
  2128. // Don't count series with boostThreshold set to 0
  2129. // See #8950
  2130. // Also don't count if the series is hidden.
  2131. // See #9046
  2132. if (series.options.boostThreshold === 0 ||
  2133. series.visible === false) {
  2134. continue;
  2135. }
  2136. // Don't count heatmap series as they are handled differently.
  2137. // In the future we should make the heatmap/treemap path compatible
  2138. // with forcing. See #9636.
  2139. if (series.type === 'heatmap') {
  2140. continue;
  2141. }
  2142. if (boostableMap[series.type]) {
  2143. ++canBoostCount;
  2144. }
  2145. if (patientMax(series.processedXData, series.options.data,
  2146. // series.xData,
  2147. series.points) >= (series.options.boostThreshold || Number.MAX_VALUE)) {
  2148. ++sboostCount;
  2149. }
  2150. }
  2151. }
  2152. chart.boostForceChartBoost = allowBoostForce && ((canBoostCount === chart.series.length &&
  2153. sboostCount > 0) ||
  2154. sboostCount > 5);
  2155. return chart.boostForceChartBoost;
  2156. }
  2157. /* eslint-disable valid-jsdoc */
  2158. /**
  2159. * Performs the actual render if the renderer is
  2160. * attached to the series.
  2161. * @private
  2162. * @param renderer {OGLRenderer} - the renderer
  2163. * @param series {Highcharts.Series} - the series
  2164. */
  2165. function renderIfNotSeriesBoosting(renderer, series, chart) {
  2166. if (renderer &&
  2167. series.renderTarget &&
  2168. series.canvas &&
  2169. !(chart || series.chart).isChartSeriesBoosting()) {
  2170. renderer.render(chart || series.chart);
  2171. }
  2172. }
  2173. /**
  2174. * @private
  2175. */
  2176. function allocateIfNotSeriesBoosting(renderer, series) {
  2177. if (renderer &&
  2178. series.renderTarget &&
  2179. series.canvas &&
  2180. !series.chart.isChartSeriesBoosting()) {
  2181. renderer.allocateBufferForSingleSeries(series);
  2182. }
  2183. }
  2184. /**
  2185. * An "async" foreach loop. Uses a setTimeout to keep the loop from blocking the
  2186. * UI thread.
  2187. *
  2188. * @private
  2189. *
  2190. * @param arr {Array} - the array to loop through
  2191. * @param fn {Function} - the callback to call for each item
  2192. * @param finalFunc {Function} - the callback to call when done
  2193. * @param chunkSize {Number} - the number of iterations per timeout
  2194. * @param i {Number} - the current index
  2195. * @param noTimeout {Boolean} - set to true to skip timeouts
  2196. */
  2197. function eachAsync(arr, fn, finalFunc, chunkSize, i, noTimeout) {
  2198. i = i || 0;
  2199. chunkSize = chunkSize || CHUNK_SIZE;
  2200. var threshold = i + chunkSize,
  2201. proceed = true;
  2202. while (proceed && i < threshold && i < arr.length) {
  2203. proceed = fn(arr[i], i);
  2204. ++i;
  2205. }
  2206. if (proceed) {
  2207. if (i < arr.length) {
  2208. if (noTimeout) {
  2209. eachAsync(arr, fn, finalFunc, chunkSize, i, noTimeout);
  2210. }
  2211. else if (win.requestAnimationFrame) {
  2212. // If available, do requestAnimationFrame - shaves off a few ms
  2213. win.requestAnimationFrame(function () {
  2214. eachAsync(arr, fn, finalFunc, chunkSize, i);
  2215. });
  2216. }
  2217. else {
  2218. setTimeout(function () {
  2219. eachAsync(arr, fn, finalFunc, chunkSize, i);
  2220. });
  2221. }
  2222. }
  2223. else if (finalFunc) {
  2224. finalFunc();
  2225. }
  2226. }
  2227. }
  2228. /**
  2229. * Returns true if the current browser supports webgl
  2230. *
  2231. * @private
  2232. * @function hasWebGLSupport
  2233. *
  2234. * @return {boolean}
  2235. */
  2236. function hasWebGLSupport() {
  2237. var i = 0, canvas, contexts = ['webgl', 'experimental-webgl', 'moz-webgl', 'webkit-3d'], context = false;
  2238. if (typeof win.WebGLRenderingContext !== 'undefined') {
  2239. canvas = doc.createElement('canvas');
  2240. for (; i < contexts.length; i++) {
  2241. try {
  2242. context = canvas.getContext(contexts[i]);
  2243. if (typeof context !== 'undefined' && context !== null) {
  2244. return true;
  2245. }
  2246. }
  2247. catch (e) {
  2248. // silent error
  2249. }
  2250. }
  2251. }
  2252. return false;
  2253. }
  2254. /* eslint-disable no-invalid-this */
  2255. /**
  2256. * Used for treemap|heatmap.drawPoints
  2257. *
  2258. * @private
  2259. * @function pointDrawHandler
  2260. *
  2261. * @param {Function} proceed
  2262. *
  2263. * @return {*}
  2264. */
  2265. function pointDrawHandler(proceed) {
  2266. var enabled = true,
  2267. renderer;
  2268. if (this.chart.options && this.chart.options.boost) {
  2269. enabled = typeof this.chart.options.boost.enabled === 'undefined' ?
  2270. true :
  2271. this.chart.options.boost.enabled;
  2272. }
  2273. if (!enabled || !this.isSeriesBoosting) {
  2274. return proceed.call(this);
  2275. }
  2276. this.chart.isBoosting = true;
  2277. // Make sure we have a valid OGL context
  2278. renderer = createAndAttachRenderer(this.chart, this);
  2279. if (renderer) {
  2280. allocateIfNotSeriesBoosting(renderer, this);
  2281. renderer.pushSeries(this);
  2282. }
  2283. renderIfNotSeriesBoosting(renderer, this);
  2284. }
  2285. /* eslint-enable no-invalid-this, valid-jsdoc */
  2286. var funs = {
  2287. patientMax: patientMax,
  2288. boostEnabled: boostEnabled,
  2289. shouldForceChartSeriesBoosting: shouldForceChartSeriesBoosting,
  2290. renderIfNotSeriesBoosting: renderIfNotSeriesBoosting,
  2291. allocateIfNotSeriesBoosting: allocateIfNotSeriesBoosting,
  2292. eachAsync: eachAsync,
  2293. hasWebGLSupport: hasWebGLSupport,
  2294. pointDrawHandler: pointDrawHandler
  2295. };
  2296. // This needs to be fixed.
  2297. H.hasWebGLSupport = hasWebGLSupport;
  2298. return funs;
  2299. });
  2300. _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) {
  2301. /* *
  2302. *
  2303. * Copyright (c) 2019-2021 Highsoft AS
  2304. *
  2305. * Boost module: stripped-down renderer for higher performance
  2306. *
  2307. * License: highcharts.com/license
  2308. *
  2309. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2310. *
  2311. * */
  2312. var noop = H.noop;
  2313. var seriesTypes = SeriesRegistry.seriesTypes;
  2314. var addEvent = U.addEvent,
  2315. extend = U.extend,
  2316. fireEvent = U.fireEvent,
  2317. wrap = U.wrap;
  2318. var eachAsync = butils.eachAsync,
  2319. pointDrawHandler = butils.pointDrawHandler,
  2320. allocateIfNotSeriesBoosting = butils.allocateIfNotSeriesBoosting,
  2321. renderIfNotSeriesBoosting = butils.renderIfNotSeriesBoosting,
  2322. shouldForceChartSeriesBoosting = butils.shouldForceChartSeriesBoosting,
  2323. index;
  2324. /* eslint-disable valid-jsdoc */
  2325. /**
  2326. * Initialize the boot module.
  2327. *
  2328. * @private
  2329. * @return {void}
  2330. */
  2331. function init() {
  2332. extend(Series.prototype, {
  2333. /**
  2334. * @private
  2335. * @function Highcharts.Series#renderCanvas
  2336. */
  2337. renderCanvas: function () {
  2338. 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 &&
  2339. 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 ||
  2340. this.options.xData ||
  2341. this.processedXData ||
  2342. false), addKDPoint = function (clientX, plotY, i) {
  2343. // We need to do ceil on the clientX to make things
  2344. // snap to pixel values. The renderer will frequently
  2345. // draw stuff on "sub-pixels".
  2346. clientX = Math.ceil(clientX);
  2347. // Shaves off about 60ms compared to repeated concatenation
  2348. index = compareX ? clientX : clientX + ',' + plotY;
  2349. // The k-d tree requires series points.
  2350. // Reduce the amount of points, since the time to build the
  2351. // tree increases exponentially.
  2352. if (enableMouseTracking && !pointTaken[index]) {
  2353. pointTaken[index] = true;
  2354. if (chart.inverted) {
  2355. clientX = xAxis.len - clientX;
  2356. plotY = yAxis.len - plotY;
  2357. }
  2358. points.push({
  2359. x: xDataFull ? xDataFull[cropStart + i] : false,
  2360. clientX: clientX,
  2361. plotX: clientX,
  2362. plotY: plotY,
  2363. i: cropStart + i
  2364. });
  2365. }
  2366. };
  2367. // Get or create the renderer
  2368. renderer = createAndAttachRenderer(chart, series);
  2369. chart.isBoosting = true;
  2370. boostOptions = renderer.settings;
  2371. if (!this.visible) {
  2372. return;
  2373. }
  2374. // If we are zooming out from SVG mode, destroy the graphics
  2375. if (this.points || this.graph) {
  2376. this.destroyGraphics();
  2377. }
  2378. // If we're rendering per. series we should create the marker groups
  2379. // as usual.
  2380. if (!chart.isChartSeriesBoosting()) {
  2381. // If all series were boosting, but are not anymore
  2382. // restore private markerGroup
  2383. if (this.markerGroup === chart.markerGroup) {
  2384. this.markerGroup = void 0;
  2385. }
  2386. this.markerGroup = series.plotGroup('markerGroup', 'markers', true, 1, chart.seriesGroup);
  2387. }
  2388. else {
  2389. // If series has a private markeGroup, remove that
  2390. // and use common markerGroup
  2391. if (this.markerGroup &&
  2392. this.markerGroup !== chart.markerGroup) {
  2393. this.markerGroup.destroy();
  2394. }
  2395. // Use a single group for the markers
  2396. this.markerGroup = chart.markerGroup;
  2397. // When switching from chart boosting mode, destroy redundant
  2398. // series boosting targets
  2399. if (this.renderTarget) {
  2400. this.renderTarget = this.renderTarget.destroy();
  2401. }
  2402. }
  2403. points = this.points = [];
  2404. // Do not start building while drawing
  2405. series.buildKDTree = noop;
  2406. if (renderer) {
  2407. allocateIfNotSeriesBoosting(renderer, this);
  2408. renderer.pushSeries(series);
  2409. // Perform the actual renderer if we're on series level
  2410. renderIfNotSeriesBoosting(renderer, this, chart);
  2411. }
  2412. /**
  2413. * This builds the KD-tree
  2414. * @private
  2415. */
  2416. function processPoint(d, i) {
  2417. var x,
  2418. y,
  2419. clientX,
  2420. plotY,
  2421. isNull,
  2422. low = false,
  2423. chartDestroyed = typeof chart.index === 'undefined',
  2424. isYInside = true;
  2425. if (!chartDestroyed) {
  2426. if (useRaw) {
  2427. x = d[0];
  2428. y = d[1];
  2429. }
  2430. else {
  2431. x = d;
  2432. y = yData[i];
  2433. }
  2434. // Resolve low and high for range series
  2435. if (isRange) {
  2436. if (useRaw) {
  2437. y = d.slice(1, 3);
  2438. }
  2439. low = y[0];
  2440. y = y[1];
  2441. }
  2442. else if (isStacked) {
  2443. x = d.x;
  2444. y = d.stackY;
  2445. low = y - d.y;
  2446. }
  2447. isNull = y === null;
  2448. // Optimize for scatter zooming
  2449. if (!requireSorting) {
  2450. isYInside = y >= yMin && y <= yMax;
  2451. }
  2452. if (!isNull && x >= xMin && x <= xMax && isYInside) {
  2453. clientX = xAxis.toPixels(x, true);
  2454. if (sampling) {
  2455. if (typeof minI === 'undefined' ||
  2456. clientX === lastClientX) {
  2457. if (!isRange) {
  2458. low = y;
  2459. }
  2460. if (typeof maxI === 'undefined' ||
  2461. y > maxVal) {
  2462. maxVal = y;
  2463. maxI = i;
  2464. }
  2465. if (typeof minI === 'undefined' ||
  2466. low < minVal) {
  2467. minVal = low;
  2468. minI = i;
  2469. }
  2470. }
  2471. // Add points and reset
  2472. if (clientX !== lastClientX) {
  2473. // maxI is number too:
  2474. if (typeof minI !== 'undefined') {
  2475. plotY =
  2476. yAxis.toPixels(maxVal, true);
  2477. yBottom =
  2478. yAxis.toPixels(minVal, true);
  2479. addKDPoint(clientX, plotY, maxI);
  2480. if (yBottom !== plotY) {
  2481. addKDPoint(clientX, yBottom, minI);
  2482. }
  2483. }
  2484. minI = maxI = void 0;
  2485. lastClientX = clientX;
  2486. }
  2487. }
  2488. else {
  2489. plotY = Math.ceil(yAxis.toPixels(y, true));
  2490. addKDPoint(clientX, plotY, i);
  2491. }
  2492. }
  2493. }
  2494. return !chartDestroyed;
  2495. }
  2496. /**
  2497. * @private
  2498. */
  2499. function doneProcessing() {
  2500. fireEvent(series, 'renderedCanvas');
  2501. // Go back to prototype, ready to build
  2502. delete series.buildKDTree;
  2503. series.buildKDTree();
  2504. if (boostOptions.debug.timeKDTree) {
  2505. console.timeEnd('kd tree building'); // eslint-disable-line no-console
  2506. }
  2507. }
  2508. // Loop over the points to build the k-d tree - skip this if
  2509. // exporting
  2510. if (!chart.renderer.forExport) {
  2511. if (boostOptions.debug.timeKDTree) {
  2512. console.time('kd tree building'); // eslint-disable-line no-console
  2513. }
  2514. eachAsync(isStacked ? series.data : (xData || rawData), processPoint, doneProcessing);
  2515. }
  2516. }
  2517. });
  2518. /*
  2519. * We need to handle heatmaps separatly, since we can't perform the
  2520. * size/color calculations in the shader easily.
  2521. *
  2522. * This likely needs future optimization.
  2523. */
  2524. ['heatmap', 'treemap'].forEach(function (t) {
  2525. if (seriesTypes[t]) {
  2526. wrap(seriesTypes[t].prototype, 'drawPoints', pointDrawHandler);
  2527. }
  2528. });
  2529. /* eslint-disable no-invalid-this */
  2530. if (seriesTypes.bubble) {
  2531. // By default, the bubble series does not use the KD-tree, so force it
  2532. // to.
  2533. delete seriesTypes.bubble.prototype.buildKDTree;
  2534. // seriesTypes.bubble.prototype.directTouch = false;
  2535. // Needed for markers to work correctly
  2536. wrap(seriesTypes.bubble.prototype, 'markerAttribs', function (proceed) {
  2537. if (this.isSeriesBoosting) {
  2538. return false;
  2539. }
  2540. return proceed.apply(this, [].slice.call(arguments, 1));
  2541. });
  2542. }
  2543. seriesTypes.scatter.prototype.fill = true;
  2544. extend(seriesTypes.area.prototype, {
  2545. fill: true,
  2546. fillOpacity: true,
  2547. sampling: true
  2548. });
  2549. extend(seriesTypes.column.prototype, {
  2550. fill: true,
  2551. sampling: true
  2552. });
  2553. Chart.prototype.propsRequireUpdateSeries.push('boost');
  2554. // Take care of the canvas blitting
  2555. Chart.prototype.callbacks.push(function (chart) {
  2556. /**
  2557. * Convert chart-level canvas to image.
  2558. * @private
  2559. */
  2560. function canvasToSVG() {
  2561. if (chart.ogl && chart.isChartSeriesBoosting()) {
  2562. chart.ogl.render(chart);
  2563. }
  2564. }
  2565. /**
  2566. * Clear chart-level canvas.
  2567. * @private
  2568. */
  2569. function preRender() {
  2570. // Reset force state
  2571. chart.boostForceChartBoost = void 0;
  2572. chart.boostForceChartBoost = shouldForceChartSeriesBoosting(chart);
  2573. chart.isBoosting = false;
  2574. if (!chart.isChartSeriesBoosting() && chart.didBoost) {
  2575. chart.didBoost = false;
  2576. }
  2577. // Clear the canvas
  2578. if (chart.boostClear) {
  2579. chart.boostClear();
  2580. }
  2581. if (chart.canvas && chart.ogl && chart.isChartSeriesBoosting()) {
  2582. chart.didBoost = true;
  2583. // Allocate
  2584. chart.ogl.allocateBuffer(chart);
  2585. }
  2586. // see #6518 + #6739
  2587. if (chart.markerGroup &&
  2588. chart.xAxis &&
  2589. chart.xAxis.length > 0 &&
  2590. chart.yAxis &&
  2591. chart.yAxis.length > 0) {
  2592. chart.markerGroup.translate(chart.xAxis[0].pos, chart.yAxis[0].pos);
  2593. }
  2594. }
  2595. addEvent(chart, 'predraw', preRender);
  2596. addEvent(chart, 'render', canvasToSVG);
  2597. // addEvent(chart, 'zoom', function () {
  2598. // chart.boostForceChartBoost =
  2599. // shouldForceChartSeriesBoosting(chart);
  2600. // });
  2601. });
  2602. /* eslint-enable no-invalid-this */
  2603. }
  2604. return init;
  2605. });
  2606. _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) {
  2607. /* *
  2608. *
  2609. * License: www.highcharts.com/license
  2610. * Author: Torstein Honsi, Christer Vasseng
  2611. *
  2612. * This module serves as a fallback for the Boost module in IE9 and IE10. Newer
  2613. * browsers support WebGL which is faster.
  2614. *
  2615. * It is recommended to include this module in conditional comments targeting
  2616. * IE9 and IE10.
  2617. *
  2618. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2619. *
  2620. * */
  2621. var color = Color.parse;
  2622. var doc = H.doc,
  2623. noop = H.noop;
  2624. var seriesTypes = SeriesRegistry.seriesTypes;
  2625. var addEvent = U.addEvent,
  2626. extend = U.extend,
  2627. fireEvent = U.fireEvent,
  2628. isNumber = U.isNumber,
  2629. merge = U.merge,
  2630. pick = U.pick,
  2631. wrap = U.wrap;
  2632. var CHUNK_SIZE = 50000,
  2633. destroyLoadingDiv;
  2634. /* eslint-disable no-invalid-this, valid-jsdoc */
  2635. /**
  2636. * Initialize the canvas boost.
  2637. *
  2638. * @function Highcharts.initCanvasBoost
  2639. */
  2640. var initCanvasBoost = function () {
  2641. if (H.seriesTypes.heatmap) {
  2642. wrap(H.seriesTypes.heatmap.prototype, 'drawPoints',
  2643. function () {
  2644. var chart = this.chart,
  2645. ctx = this.getContext(),
  2646. inverted = this.chart.inverted,
  2647. xAxis = this.xAxis,
  2648. yAxis = this.yAxis;
  2649. if (ctx) {
  2650. // draw the columns
  2651. this.points.forEach(function (point) {
  2652. var plotY = point.plotY,
  2653. shapeArgs,
  2654. pointAttr;
  2655. if (typeof plotY !== 'undefined' &&
  2656. !isNaN(plotY) &&
  2657. point.y !== null) {
  2658. shapeArgs = point.shapeArgs;
  2659. if (!chart.styledMode) {
  2660. pointAttr = point.series.pointAttribs(point);
  2661. }
  2662. else {
  2663. pointAttr = point.series.colorAttribs(point);
  2664. }
  2665. ctx.fillStyle = pointAttr.fill;
  2666. if (inverted) {
  2667. ctx.fillRect(yAxis.len - shapeArgs.y + xAxis.left, xAxis.len - shapeArgs.x + yAxis.top, -shapeArgs.height, -shapeArgs.width);
  2668. }
  2669. else {
  2670. ctx.fillRect(shapeArgs.x + xAxis.left, shapeArgs.y + yAxis.top, shapeArgs.width, shapeArgs.height);
  2671. }
  2672. }
  2673. });
  2674. this.canvasToSVG();
  2675. }
  2676. else {
  2677. this.chart.showLoading('Your browser doesn\'t support HTML5 canvas, <br>' +
  2678. 'please use a modern browser');
  2679. // Uncomment this to provide low-level (slow) support in oldIE.
  2680. // It will cause script errors on charts with more than a few
  2681. // thousand points.
  2682. // arguments[0].call(this);
  2683. }
  2684. });
  2685. }
  2686. extend(Series.prototype, {
  2687. /**
  2688. * Create a hidden canvas to draw the graph on. The contents is later
  2689. * copied over to an SVG image element.
  2690. *
  2691. * @private
  2692. * @function Highcharts.Series#getContext
  2693. */
  2694. getContext: function () {
  2695. var chart = this.chart,
  2696. width = chart.chartWidth,
  2697. height = chart.chartHeight,
  2698. targetGroup = chart.seriesGroup || this.group,
  2699. target = this,
  2700. ctx,
  2701. swapXY = function (proceed,
  2702. x,
  2703. y,
  2704. a,
  2705. b,
  2706. c,
  2707. d) {
  2708. proceed.call(this,
  2709. y,
  2710. x,
  2711. a,
  2712. b,
  2713. c,
  2714. d);
  2715. };
  2716. if (chart.isChartSeriesBoosting()) {
  2717. target = chart;
  2718. targetGroup = chart.seriesGroup;
  2719. }
  2720. ctx = target.ctx;
  2721. if (!target.canvas) {
  2722. target.canvas = doc.createElement('canvas');
  2723. target.renderTarget = chart.renderer
  2724. .image('', 0, 0, width, height)
  2725. .addClass('highcharts-boost-canvas')
  2726. .add(targetGroup);
  2727. target.ctx = ctx = target.canvas.getContext('2d');
  2728. if (chart.inverted) {
  2729. ['moveTo', 'lineTo', 'rect', 'arc'].forEach(function (fn) {
  2730. wrap(ctx, fn, swapXY);
  2731. });
  2732. }
  2733. target.boostCopy = function () {
  2734. target.renderTarget.attr({
  2735. href: target.canvas.toDataURL('image/png')
  2736. });
  2737. };
  2738. target.boostClear = function () {
  2739. ctx.clearRect(0, 0, target.canvas.width, target.canvas.height);
  2740. if (target === this) {
  2741. target.renderTarget.attr({ href: '' });
  2742. }
  2743. };
  2744. target.boostClipRect = chart.renderer.clipRect();
  2745. target.renderTarget.clip(target.boostClipRect);
  2746. }
  2747. else if (!(target instanceof H.Chart)) {
  2748. // ctx.clearRect(0, 0, width, height);
  2749. }
  2750. if (target.canvas.width !== width) {
  2751. target.canvas.width = width;
  2752. }
  2753. if (target.canvas.height !== height) {
  2754. target.canvas.height = height;
  2755. }
  2756. target.renderTarget.attr({
  2757. x: 0,
  2758. y: 0,
  2759. width: width,
  2760. height: height,
  2761. style: 'pointer-events: none',
  2762. href: ''
  2763. });
  2764. target.boostClipRect.attr(chart.getBoostClipRect(target));
  2765. return ctx;
  2766. },
  2767. /**
  2768. * Draw the canvas image inside an SVG image
  2769. *
  2770. * @private
  2771. * @function Highcharts.Series#canvasToSVG
  2772. */
  2773. canvasToSVG: function () {
  2774. if (!this.chart.isChartSeriesBoosting()) {
  2775. if (this.boostCopy || this.chart.boostCopy) {
  2776. (this.boostCopy || this.chart.boostCopy)();
  2777. }
  2778. }
  2779. else {
  2780. if (this.boostClear) {
  2781. this.boostClear();
  2782. }
  2783. }
  2784. },
  2785. cvsLineTo: function (ctx, clientX, plotY) {
  2786. ctx.lineTo(clientX, plotY);
  2787. },
  2788. renderCanvas: function () {
  2789. var series = this, options = series.options, chart = series.chart, xAxis = this.xAxis, yAxis = this.yAxis, activeBoostSettings = chart.options.boost || {}, boostSettings = {
  2790. timeRendering: activeBoostSettings.timeRendering || false,
  2791. timeSeriesProcessing: activeBoostSettings.timeSeriesProcessing || false,
  2792. timeSetup: activeBoostSettings.timeSetup || false
  2793. }, 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 ?
  2794. this.cvsMarkerSquare :
  2795. 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 &&
  2796. 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 ?
  2797. series.data :
  2798. (xData || rawData)), fillColor = (series.fillOpacity ?
  2799. new Color(series.color).setOpacity(pick(options.fillOpacity, 0.75)).get() :
  2800. series.color),
  2801. //
  2802. stroke = function () {
  2803. if (doFill) {
  2804. ctx.fillStyle = fillColor;
  2805. ctx.fill();
  2806. }
  2807. else {
  2808. ctx.strokeStyle = series.color;
  2809. ctx.lineWidth = options.lineWidth;
  2810. ctx.stroke();
  2811. }
  2812. },
  2813. //
  2814. drawPoint = function (clientX, plotY, yBottom, i) {
  2815. if (c === 0) {
  2816. ctx.beginPath();
  2817. if (cvsLineTo) {
  2818. ctx.lineJoin = 'round';
  2819. }
  2820. }
  2821. if (chart.scroller &&
  2822. series.options.className ===
  2823. 'highcharts-navigator-series') {
  2824. plotY += chart.scroller.top;
  2825. if (yBottom) {
  2826. yBottom += chart.scroller.top;
  2827. }
  2828. }
  2829. else {
  2830. plotY += chart.plotTop;
  2831. }
  2832. clientX += chart.plotLeft;
  2833. if (wasNull) {
  2834. ctx.moveTo(clientX, plotY);
  2835. }
  2836. else {
  2837. if (cvsDrawPoint) {
  2838. cvsDrawPoint(ctx, clientX, plotY, yBottom, lastPoint);
  2839. }
  2840. else if (cvsLineTo) {
  2841. cvsLineTo(ctx, clientX, plotY);
  2842. }
  2843. else if (cvsMarker) {
  2844. cvsMarker.call(series, ctx, clientX, plotY, r, i);
  2845. }
  2846. }
  2847. // We need to stroke the line for every 1000 pixels. It will
  2848. // crash the browser memory use if we stroke too
  2849. // infrequently.
  2850. c = c + 1;
  2851. if (c === strokeBatch) {
  2852. stroke();
  2853. c = 0;
  2854. }
  2855. // Area charts need to keep track of the last point
  2856. lastPoint = {
  2857. clientX: clientX,
  2858. plotY: plotY,
  2859. yBottom: yBottom
  2860. };
  2861. },
  2862. //
  2863. compareX = options.findNearestPointBy === 'x',
  2864. //
  2865. xDataFull = (this.xData ||
  2866. this.options.xData ||
  2867. this.processedXData ||
  2868. false),
  2869. //
  2870. addKDPoint = function (clientX, plotY, i) {
  2871. // Shaves off about 60ms compared to repeated concatenation
  2872. index = compareX ? clientX : clientX + ',' + plotY;
  2873. // The k-d tree requires series points.
  2874. // Reduce the amount of points, since the time to build the
  2875. // tree increases exponentially.
  2876. if (enableMouseTracking && !pointTaken[index]) {
  2877. pointTaken[index] = true;
  2878. if (chart.inverted) {
  2879. clientX = xAxis.len - clientX;
  2880. plotY = yAxis.len - plotY;
  2881. }
  2882. points.push({
  2883. x: xDataFull ?
  2884. xDataFull[cropStart + i] :
  2885. false,
  2886. clientX: clientX,
  2887. plotX: clientX,
  2888. plotY: plotY,
  2889. i: cropStart + i
  2890. });
  2891. }
  2892. };
  2893. if (this.renderTarget) {
  2894. this.renderTarget.attr({ 'href': '' });
  2895. }
  2896. // If we are zooming out from SVG mode, destroy the graphics
  2897. if (this.points || this.graph) {
  2898. this.destroyGraphics();
  2899. }
  2900. // The group
  2901. series.plotGroup('group', 'series', series.visible ? 'visible' : 'hidden', options.zIndex, chart.seriesGroup);
  2902. series.markerGroup = series.group;
  2903. addEvent(series, 'destroy', function () {
  2904. // Prevent destroy twice
  2905. series.markerGroup = null;
  2906. });
  2907. points = this.points = [];
  2908. ctx = this.getContext();
  2909. series.buildKDTree = noop; // Do not start building while drawing
  2910. if (this.boostClear) {
  2911. this.boostClear();
  2912. }
  2913. // if (this.canvas) {
  2914. // ctx.clearRect(
  2915. // 0,
  2916. // 0,
  2917. // this.canvas.width,
  2918. // this.canvas.height
  2919. // );
  2920. // }
  2921. if (!this.visible) {
  2922. return;
  2923. }
  2924. // Display a loading indicator
  2925. if (rawData.length > 99999) {
  2926. chart.options.loading = merge(loadingOptions, {
  2927. labelStyle: {
  2928. backgroundColor: color(palette.backgroundColor).setOpacity(0.75).get(),
  2929. padding: '1em',
  2930. borderRadius: '0.5em'
  2931. },
  2932. style: {
  2933. backgroundColor: 'none',
  2934. opacity: 1
  2935. }
  2936. });
  2937. U.clearTimeout(destroyLoadingDiv);
  2938. chart.showLoading('Drawing...');
  2939. chart.options.loading = loadingOptions; // reset
  2940. }
  2941. if (boostSettings.timeRendering) {
  2942. console.time('canvas rendering'); // eslint-disable-line no-console
  2943. }
  2944. // Loop over the points
  2945. H.eachAsync(sdata, function (d, i) {
  2946. var x,
  2947. y,
  2948. clientX,
  2949. plotY,
  2950. isNull,
  2951. low,
  2952. isNextInside = false,
  2953. isPrevInside = false,
  2954. nx = false,
  2955. px = false,
  2956. chartDestroyed = typeof chart.index === 'undefined',
  2957. isYInside = true;
  2958. if (!chartDestroyed) {
  2959. if (useRaw) {
  2960. x = d[0];
  2961. y = d[1];
  2962. if (sdata[i + 1]) {
  2963. nx = sdata[i + 1][0];
  2964. }
  2965. if (sdata[i - 1]) {
  2966. px = sdata[i - 1][0];
  2967. }
  2968. }
  2969. else {
  2970. x = d;
  2971. y = yData[i];
  2972. if (sdata[i + 1]) {
  2973. nx = sdata[i + 1];
  2974. }
  2975. if (sdata[i - 1]) {
  2976. px = sdata[i - 1];
  2977. }
  2978. }
  2979. if (nx && nx >= xMin && nx <= xMax) {
  2980. isNextInside = true;
  2981. }
  2982. if (px && px >= xMin && px <= xMax) {
  2983. isPrevInside = true;
  2984. }
  2985. // Resolve low and high for range series
  2986. if (isRange) {
  2987. if (useRaw) {
  2988. y = d.slice(1, 3);
  2989. }
  2990. low = y[0];
  2991. y = y[1];
  2992. }
  2993. else if (isStacked) {
  2994. x = d.x;
  2995. y = d.stackY;
  2996. low = y - d.y;
  2997. }
  2998. isNull = y === null;
  2999. // Optimize for scatter zooming
  3000. if (!requireSorting) {
  3001. isYInside = y >= yMin && y <= yMax;
  3002. }
  3003. if (!isNull &&
  3004. ((x >= xMin && x <= xMax && isYInside) ||
  3005. (isNextInside || isPrevInside))) {
  3006. clientX = Math.round(xAxis.toPixels(x, true));
  3007. if (sampling) {
  3008. if (typeof minI === 'undefined' ||
  3009. clientX === lastClientX) {
  3010. if (!isRange) {
  3011. low = y;
  3012. }
  3013. if (typeof maxI === 'undefined' || y > maxVal) {
  3014. maxVal = y;
  3015. maxI = i;
  3016. }
  3017. if (typeof minI === 'undefined' ||
  3018. low < minVal) {
  3019. minVal = low;
  3020. minI = i;
  3021. }
  3022. }
  3023. // Add points and reset
  3024. if (clientX !== lastClientX) {
  3025. // maxI also a number:
  3026. if (typeof minI !== 'undefined') {
  3027. plotY = yAxis.toPixels(maxVal, true);
  3028. yBottom = yAxis.toPixels(minVal, true);
  3029. drawPoint(clientX, hasThreshold ?
  3030. Math.min(plotY, translatedThreshold) : plotY, hasThreshold ?
  3031. Math.max(yBottom, translatedThreshold) : yBottom, i);
  3032. addKDPoint(clientX, plotY, maxI);
  3033. if (yBottom !== plotY) {
  3034. addKDPoint(clientX, yBottom, minI);
  3035. }
  3036. }
  3037. minI = maxI = void 0;
  3038. lastClientX = clientX;
  3039. }
  3040. }
  3041. else {
  3042. plotY = Math.round(yAxis.toPixels(y, true));
  3043. drawPoint(clientX, plotY, yBottom, i);
  3044. addKDPoint(clientX, plotY, i);
  3045. }
  3046. }
  3047. wasNull = isNull && !connectNulls;
  3048. if (i % CHUNK_SIZE === 0) {
  3049. if (series.boostCopy || series.chart.boostCopy) {
  3050. (series.boostCopy || series.chart.boostCopy)();
  3051. }
  3052. }
  3053. }
  3054. return !chartDestroyed;
  3055. }, function () {
  3056. var loadingDiv = chart.loadingDiv,
  3057. loadingShown = chart.loadingShown;
  3058. stroke();
  3059. // if (series.boostCopy || series.chart.boostCopy) {
  3060. // (series.boostCopy || series.chart.boostCopy)();
  3061. // }
  3062. series.canvasToSVG();
  3063. if (boostSettings.timeRendering) {
  3064. console.timeEnd('canvas rendering'); // eslint-disable-line no-console
  3065. }
  3066. fireEvent(series, 'renderedCanvas');
  3067. // Do not use chart.hideLoading, as it runs JS animation and
  3068. // will be blocked by buildKDTree. CSS animation looks good, but
  3069. // then it must be deleted in timeout. If we add the module to
  3070. // core, change hideLoading so we can skip this block.
  3071. if (loadingShown) {
  3072. extend(loadingDiv.style, {
  3073. transition: 'opacity 250ms',
  3074. opacity: 0
  3075. });
  3076. chart.loadingShown = false;
  3077. destroyLoadingDiv = setTimeout(function () {
  3078. if (loadingDiv.parentNode) { // In exporting it is falsy
  3079. loadingDiv.parentNode.removeChild(loadingDiv);
  3080. }
  3081. chart.loadingDiv = chart.loadingSpan = null;
  3082. }, 250);
  3083. }
  3084. // Go back to prototype, ready to build
  3085. delete series.buildKDTree;
  3086. series.buildKDTree();
  3087. // Don't do async on export, the exportChart, getSVGForExport and
  3088. // getSVG methods are not chained for it.
  3089. }, chart.renderer.forExport ? Number.MAX_VALUE : void 0);
  3090. }
  3091. });
  3092. seriesTypes.scatter.prototype.cvsMarkerCircle = function (ctx, clientX, plotY, r) {
  3093. ctx.moveTo(clientX, plotY);
  3094. ctx.arc(clientX, plotY, r, 0, 2 * Math.PI, false);
  3095. };
  3096. // Rect is twice as fast as arc, should be used for small markers
  3097. seriesTypes.scatter.prototype.cvsMarkerSquare = function (ctx, clientX, plotY, r) {
  3098. ctx.rect(clientX - r, plotY - r, r * 2, r * 2);
  3099. };
  3100. seriesTypes.scatter.prototype.fill = true;
  3101. if (seriesTypes.bubble) {
  3102. seriesTypes.bubble.prototype.cvsMarkerCircle = function (ctx, clientX, plotY, r, i) {
  3103. ctx.moveTo(clientX, plotY);
  3104. ctx.arc(clientX, plotY, this.radii && this.radii[i], 0, 2 * Math.PI, false);
  3105. };
  3106. seriesTypes.bubble.prototype.cvsStrokeBatch = 1;
  3107. }
  3108. extend(seriesTypes.area.prototype, {
  3109. cvsDrawPoint: function (ctx, clientX, plotY, yBottom, lastPoint) {
  3110. if (lastPoint && clientX !== lastPoint.clientX) {
  3111. ctx.moveTo(lastPoint.clientX, lastPoint.yBottom);
  3112. ctx.lineTo(lastPoint.clientX, lastPoint.plotY);
  3113. ctx.lineTo(clientX, plotY);
  3114. ctx.lineTo(clientX, yBottom);
  3115. }
  3116. },
  3117. fill: true,
  3118. fillOpacity: true,
  3119. sampling: true
  3120. });
  3121. extend(seriesTypes.column.prototype, {
  3122. cvsDrawPoint: function (ctx, clientX, plotY, yBottom) {
  3123. ctx.rect(clientX - 1, plotY, 1, yBottom - plotY);
  3124. },
  3125. fill: true,
  3126. sampling: true
  3127. });
  3128. Chart.prototype.callbacks.push(function (chart) {
  3129. /**
  3130. * @private
  3131. */
  3132. function canvasToSVG() {
  3133. if (chart.boostCopy) {
  3134. chart.boostCopy();
  3135. }
  3136. }
  3137. /**
  3138. * @private
  3139. */
  3140. function clear() {
  3141. if (chart.renderTarget) {
  3142. chart.renderTarget.attr({ href: '' });
  3143. }
  3144. if (chart.canvas) {
  3145. chart.canvas.getContext('2d').clearRect(0, 0, chart.canvas.width, chart.canvas.height);
  3146. }
  3147. }
  3148. addEvent(chart, 'predraw', clear);
  3149. addEvent(chart, 'render', canvasToSVG);
  3150. });
  3151. };
  3152. return initCanvasBoost;
  3153. });
  3154. _registerModule(_modules, 'Extensions/Boost/BoostOverrides.js', [_modules['Core/Chart/Chart.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, Point, Series, SeriesRegistry, U, butils, boostable, boostableMap) {
  3155. /* *
  3156. *
  3157. * Copyright (c) 2019-2021 Highsoft AS
  3158. *
  3159. * Boost module: stripped-down renderer for higher performance
  3160. *
  3161. * License: highcharts.com/license
  3162. *
  3163. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3164. *
  3165. * */
  3166. var seriesTypes = SeriesRegistry.seriesTypes;
  3167. var addEvent = U.addEvent,
  3168. error = U.error,
  3169. getOptions = U.getOptions,
  3170. isArray = U.isArray,
  3171. isNumber = U.isNumber,
  3172. pick = U.pick,
  3173. wrap = U.wrap;
  3174. var boostEnabled = butils.boostEnabled,
  3175. shouldForceChartSeriesBoosting = butils.shouldForceChartSeriesBoosting,
  3176. plotOptions = getOptions().plotOptions;
  3177. /**
  3178. * Returns true if the chart is in series boost mode.
  3179. *
  3180. * @function Highcharts.Chart#isChartSeriesBoosting
  3181. *
  3182. * @param {Highcharts.Chart} chart
  3183. * the chart to check
  3184. *
  3185. * @return {boolean}
  3186. * true if the chart is in series boost mode
  3187. */
  3188. Chart.prototype.isChartSeriesBoosting = function () {
  3189. var isSeriesBoosting,
  3190. threshold = pick(this.options.boost && this.options.boost.seriesThreshold, 50);
  3191. isSeriesBoosting = threshold <= this.series.length ||
  3192. shouldForceChartSeriesBoosting(this);
  3193. return isSeriesBoosting;
  3194. };
  3195. /* eslint-disable valid-jsdoc */
  3196. /**
  3197. * Get the clip rectangle for a target, either a series or the chart. For the
  3198. * chart, we need to consider the maximum extent of its Y axes, in case of
  3199. * Highstock panes and navigator.
  3200. *
  3201. * @private
  3202. * @function Highcharts.Chart#getBoostClipRect
  3203. *
  3204. * @param {Highcharts.Chart} target
  3205. *
  3206. * @return {Highcharts.BBoxObject}
  3207. */
  3208. Chart.prototype.getBoostClipRect = function (target) {
  3209. var clipBox = {
  3210. x: this.plotLeft,
  3211. y: this.plotTop,
  3212. width: this.plotWidth,
  3213. height: this.plotHeight
  3214. };
  3215. if (target === this) {
  3216. var verticalAxes = this.inverted ? this.xAxis : this.yAxis; // #14444
  3217. if (verticalAxes.length <= 1) {
  3218. clipBox.y = Math.min(verticalAxes[0].pos,
  3219. clipBox.y);
  3220. clipBox.height = verticalAxes[0].pos - this.plotTop + verticalAxes[0].len;
  3221. }
  3222. else {
  3223. clipBox.height = this.plotHeight;
  3224. }
  3225. }
  3226. return clipBox;
  3227. };
  3228. /**
  3229. * Return a full Point object based on the index.
  3230. * The boost module uses stripped point objects for performance reasons.
  3231. *
  3232. * @function Highcharts.Series#getPoint
  3233. *
  3234. * @param {object|Highcharts.Point} boostPoint
  3235. * A stripped-down point object
  3236. *
  3237. * @return {Highcharts.Point}
  3238. * A Point object as per https://api.highcharts.com/highcharts#Point
  3239. */
  3240. Series.prototype.getPoint = function (boostPoint) {
  3241. var point = boostPoint,
  3242. xData = (this.xData || this.options.xData || this.processedXData ||
  3243. false);
  3244. if (boostPoint && !(boostPoint instanceof this.pointClass)) {
  3245. point = (new this.pointClass()).init(// eslint-disable-line new-cap
  3246. this, this.options.data[boostPoint.i], xData ? xData[boostPoint.i] : void 0);
  3247. point.category = pick(this.xAxis.categories ?
  3248. this.xAxis.categories[point.x] :
  3249. point.x, // @todo simplify
  3250. point.x);
  3251. point.dist = boostPoint.dist;
  3252. point.distX = boostPoint.distX;
  3253. point.plotX = boostPoint.plotX;
  3254. point.plotY = boostPoint.plotY;
  3255. point.index = boostPoint.i;
  3256. point.isInside = this.isPointInside(boostPoint);
  3257. }
  3258. return point;
  3259. };
  3260. /* eslint-disable no-invalid-this */
  3261. // Return a point instance from the k-d-tree
  3262. wrap(Series.prototype, 'searchPoint', function (proceed) {
  3263. return this.getPoint(proceed.apply(this, [].slice.call(arguments, 1)));
  3264. });
  3265. // For inverted series, we need to swap X-Y values before running base methods
  3266. wrap(Point.prototype, 'haloPath', function (proceed) {
  3267. var halo,
  3268. point = this,
  3269. series = point.series,
  3270. chart = series.chart,
  3271. plotX = point.plotX,
  3272. plotY = point.plotY,
  3273. inverted = chart.inverted;
  3274. if (series.isSeriesBoosting && inverted) {
  3275. point.plotX = series.yAxis.len - plotY;
  3276. point.plotY = series.xAxis.len - plotX;
  3277. }
  3278. halo = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3279. if (series.isSeriesBoosting && inverted) {
  3280. point.plotX = plotX;
  3281. point.plotY = plotY;
  3282. }
  3283. return halo;
  3284. });
  3285. wrap(Series.prototype, 'markerAttribs', function (proceed, point) {
  3286. var attribs,
  3287. series = this,
  3288. chart = series.chart,
  3289. plotX = point.plotX,
  3290. plotY = point.plotY,
  3291. inverted = chart.inverted;
  3292. if (series.isSeriesBoosting && inverted) {
  3293. point.plotX = series.yAxis.len - plotY;
  3294. point.plotY = series.xAxis.len - plotX;
  3295. }
  3296. attribs = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3297. if (series.isSeriesBoosting && inverted) {
  3298. point.plotX = plotX;
  3299. point.plotY = plotY;
  3300. }
  3301. return attribs;
  3302. });
  3303. /*
  3304. * Extend series.destroy to also remove the fake k-d-tree points (#5137).
  3305. * Normally this is handled by Series.destroy that calls Point.destroy,
  3306. * but the fake search points are not registered like that.
  3307. */
  3308. addEvent(Series, 'destroy', function () {
  3309. var series = this,
  3310. chart = series.chart;
  3311. if (chart.markerGroup === series.markerGroup) {
  3312. series.markerGroup = null;
  3313. }
  3314. if (chart.hoverPoints) {
  3315. chart.hoverPoints = chart.hoverPoints.filter(function (point) {
  3316. return point.series === series;
  3317. });
  3318. }
  3319. if (chart.hoverPoint && chart.hoverPoint.series === series) {
  3320. chart.hoverPoint = null;
  3321. }
  3322. });
  3323. /*
  3324. * Do not compute extremes when min and max are set.
  3325. * If we use this in the core, we can add the hook
  3326. * to hasExtremes to the methods directly.
  3327. */
  3328. wrap(Series.prototype, 'getExtremes', function (proceed) {
  3329. if (!this.isSeriesBoosting || (!this.hasExtremes || !this.hasExtremes())) {
  3330. return proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3331. }
  3332. return {};
  3333. });
  3334. /*
  3335. * Override a bunch of methods the same way. If the number of points is
  3336. * below the threshold, run the original method. If not, check for a
  3337. * canvas version or do nothing.
  3338. *
  3339. * Note that we're not overriding any of these for heatmaps.
  3340. */
  3341. [
  3342. 'translate',
  3343. 'generatePoints',
  3344. 'drawTracker',
  3345. 'drawPoints',
  3346. 'render'
  3347. ].forEach(function (method) {
  3348. /**
  3349. * @private
  3350. */
  3351. function branch(proceed) {
  3352. var letItPass = this.options.stacking &&
  3353. (method === 'translate' || method === 'generatePoints');
  3354. if (!this.isSeriesBoosting ||
  3355. letItPass ||
  3356. !boostEnabled(this.chart) ||
  3357. this.type === 'heatmap' ||
  3358. this.type === 'treemap' ||
  3359. !boostableMap[this.type] ||
  3360. this.options.boostThreshold === 0) {
  3361. proceed.call(this);
  3362. // If a canvas version of the method exists, like renderCanvas(), run
  3363. }
  3364. else if (this[method + 'Canvas']) {
  3365. this[method + 'Canvas']();
  3366. }
  3367. }
  3368. wrap(Series.prototype, method, branch);
  3369. // A special case for some types - their translate method is already wrapped
  3370. if (method === 'translate') {
  3371. [
  3372. 'column',
  3373. 'bar',
  3374. 'arearange',
  3375. 'columnrange',
  3376. 'heatmap',
  3377. 'treemap'
  3378. ].forEach(function (type) {
  3379. if (seriesTypes[type]) {
  3380. wrap(seriesTypes[type].prototype, method, branch);
  3381. }
  3382. });
  3383. }
  3384. });
  3385. // If the series is a heatmap or treemap, or if the series is not boosting
  3386. // do the default behaviour. Otherwise, process if the series has no extremes.
  3387. wrap(Series.prototype, 'processData', function (proceed) {
  3388. var series = this,
  3389. dataToMeasure = this.options.data,
  3390. firstPoint;
  3391. /**
  3392. * Used twice in this function, first on this.options.data, the second
  3393. * time it runs the check again after processedXData is built.
  3394. * @private
  3395. * @todo Check what happens with data grouping
  3396. */
  3397. function getSeriesBoosting(data) {
  3398. return series.chart.isChartSeriesBoosting() || ((data ? data.length : 0) >=
  3399. (series.options.boostThreshold || Number.MAX_VALUE));
  3400. }
  3401. if (boostEnabled(this.chart) && boostableMap[this.type]) {
  3402. // If there are no extremes given in the options, we also need to
  3403. // process the data to read the data extremes. If this is a heatmap, do
  3404. // default behaviour.
  3405. if (!getSeriesBoosting(dataToMeasure) || // First pass with options.data
  3406. this.type === 'heatmap' ||
  3407. this.type === 'treemap' ||
  3408. this.options.stacking || // processedYData for the stack (#7481)
  3409. !this.hasExtremes ||
  3410. !this.hasExtremes(true)) {
  3411. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3412. dataToMeasure = this.processedXData;
  3413. }
  3414. // Set the isBoosting flag, second pass with processedXData to see if we
  3415. // have zoomed.
  3416. this.isSeriesBoosting = getSeriesBoosting(dataToMeasure);
  3417. // Enter or exit boost mode
  3418. if (this.isSeriesBoosting) {
  3419. // Force turbo-mode:
  3420. firstPoint = this.getFirstValidPoint(this.options.data);
  3421. if (!isNumber(firstPoint) && !isArray(firstPoint)) {
  3422. error(12, false, this.chart);
  3423. }
  3424. this.enterBoost();
  3425. }
  3426. else if (this.exitBoost) {
  3427. this.exitBoost();
  3428. }
  3429. // The series type is not boostable
  3430. }
  3431. else {
  3432. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3433. }
  3434. });
  3435. addEvent(Series, 'hide', function () {
  3436. if (this.canvas && this.renderTarget) {
  3437. if (this.ogl) {
  3438. this.ogl.clear();
  3439. }
  3440. this.boostClear();
  3441. }
  3442. });
  3443. /**
  3444. * Enter boost mode and apply boost-specific properties.
  3445. *
  3446. * @function Highcharts.Series#enterBoost
  3447. */
  3448. Series.prototype.enterBoost = function () {
  3449. this.alteredByBoost = [];
  3450. // Save the original values, including whether it was an own property or
  3451. // inherited from the prototype.
  3452. ['allowDG', 'directTouch', 'stickyTracking'].forEach(function (prop) {
  3453. this.alteredByBoost.push({
  3454. prop: prop,
  3455. val: this[prop],
  3456. own: Object.hasOwnProperty.call(this, prop)
  3457. });
  3458. }, this);
  3459. this.allowDG = false;
  3460. this.directTouch = false;
  3461. this.stickyTracking = true;
  3462. // Prevent animation when zooming in on boosted series(#13421).
  3463. this.finishedAnimating = true;
  3464. // Hide series label if any
  3465. if (this.labelBySeries) {
  3466. this.labelBySeries = this.labelBySeries.destroy();
  3467. }
  3468. };
  3469. /**
  3470. * Exit from boost mode and restore non-boost properties.
  3471. *
  3472. * @function Highcharts.Series#exitBoost
  3473. */
  3474. Series.prototype.exitBoost = function () {
  3475. // Reset instance properties and/or delete instance properties and go back
  3476. // to prototype
  3477. (this.alteredByBoost || []).forEach(function (setting) {
  3478. if (setting.own) {
  3479. this[setting.prop] = setting.val;
  3480. }
  3481. else {
  3482. // Revert to prototype
  3483. delete this[setting.prop];
  3484. }
  3485. }, this);
  3486. // Clear previous run
  3487. if (this.boostClear) {
  3488. this.boostClear();
  3489. }
  3490. };
  3491. /**
  3492. * @private
  3493. * @function Highcharts.Series#hasExtremes
  3494. *
  3495. * @param {boolean} checkX
  3496. *
  3497. * @return {boolean}
  3498. */
  3499. Series.prototype.hasExtremes = function (checkX) {
  3500. var options = this.options,
  3501. data = options.data,
  3502. xAxis = this.xAxis && this.xAxis.options,
  3503. yAxis = this.yAxis && this.yAxis.options,
  3504. colorAxis = this.colorAxis && this.colorAxis.options;
  3505. return data.length > (options.boostThreshold || Number.MAX_VALUE) &&
  3506. // Defined yAxis extremes
  3507. isNumber(yAxis.min) &&
  3508. isNumber(yAxis.max) &&
  3509. // Defined (and required) xAxis extremes
  3510. (!checkX ||
  3511. (isNumber(xAxis.min) && isNumber(xAxis.max))) &&
  3512. // Defined (e.g. heatmap) colorAxis extremes
  3513. (!colorAxis ||
  3514. (isNumber(colorAxis.min) && isNumber(colorAxis.max)));
  3515. };
  3516. /**
  3517. * If implemented in the core, parts of this can probably be
  3518. * shared with other similar methods in Highcharts.
  3519. *
  3520. * @function Highcharts.Series#destroyGraphics
  3521. */
  3522. Series.prototype.destroyGraphics = function () {
  3523. var _this = this;
  3524. var series = this,
  3525. points = this.points,
  3526. point,
  3527. i;
  3528. if (points) {
  3529. for (i = 0; i < points.length; i = i + 1) {
  3530. point = points[i];
  3531. if (point && point.destroyElements) {
  3532. point.destroyElements(); // #7557
  3533. }
  3534. }
  3535. }
  3536. ['graph', 'area', 'tracker'].forEach(function (prop) {
  3537. if (series[prop]) {
  3538. series[prop] = series[prop].destroy();
  3539. }
  3540. });
  3541. if (this.getZonesGraphs) {
  3542. var props = this.getZonesGraphs([['graph', 'highcharts-graph']]);
  3543. props.forEach(function (prop) {
  3544. var zoneGraph = _this[prop[0]];
  3545. if (zoneGraph) {
  3546. _this[prop[0]] = zoneGraph.destroy();
  3547. }
  3548. });
  3549. }
  3550. };
  3551. // Set default options
  3552. boostable.forEach(function (type) {
  3553. if (plotOptions[type]) {
  3554. plotOptions[type].boostThreshold = 5000;
  3555. plotOptions[type].boostData = [];
  3556. seriesTypes[type].prototype.fillOpacity = true;
  3557. }
  3558. });
  3559. });
  3560. _registerModule(_modules, 'Extensions/Boost/NamedColors.js', [_modules['Core/Color/Color.js']], function (Color) {
  3561. /* *
  3562. *
  3563. * Copyright (c) 2019-2021 Highsoft AS
  3564. *
  3565. * Boost module: stripped-down renderer for higher performance
  3566. *
  3567. * License: highcharts.com/license
  3568. *
  3569. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3570. *
  3571. * */
  3572. // Register color names since GL can't render those directly.
  3573. // TODO: When supporting modern syntax, make this a const and a named export
  3574. var defaultHTMLColorMap = {
  3575. aliceblue: '#f0f8ff',
  3576. antiquewhite: '#faebd7',
  3577. aqua: '#00ffff',
  3578. aquamarine: '#7fffd4',
  3579. azure: '#f0ffff',
  3580. beige: '#f5f5dc',
  3581. bisque: '#ffe4c4',
  3582. black: '#000000',
  3583. blanchedalmond: '#ffebcd',
  3584. blue: '#0000ff',
  3585. blueviolet: '#8a2be2',
  3586. brown: '#a52a2a',
  3587. burlywood: '#deb887',
  3588. cadetblue: '#5f9ea0',
  3589. chartreuse: '#7fff00',
  3590. chocolate: '#d2691e',
  3591. coral: '#ff7f50',
  3592. cornflowerblue: '#6495ed',
  3593. cornsilk: '#fff8dc',
  3594. crimson: '#dc143c',
  3595. cyan: '#00ffff',
  3596. darkblue: '#00008b',
  3597. darkcyan: '#008b8b',
  3598. darkgoldenrod: '#b8860b',
  3599. darkgray: '#a9a9a9',
  3600. darkgreen: '#006400',
  3601. darkkhaki: '#bdb76b',
  3602. darkmagenta: '#8b008b',
  3603. darkolivegreen: '#556b2f',
  3604. darkorange: '#ff8c00',
  3605. darkorchid: '#9932cc',
  3606. darkred: '#8b0000',
  3607. darksalmon: '#e9967a',
  3608. darkseagreen: '#8fbc8f',
  3609. darkslateblue: '#483d8b',
  3610. darkslategray: '#2f4f4f',
  3611. darkturquoise: '#00ced1',
  3612. darkviolet: '#9400d3',
  3613. deeppink: '#ff1493',
  3614. deepskyblue: '#00bfff',
  3615. dimgray: '#696969',
  3616. dodgerblue: '#1e90ff',
  3617. feldspar: '#d19275',
  3618. firebrick: '#b22222',
  3619. floralwhite: '#fffaf0',
  3620. forestgreen: '#228b22',
  3621. fuchsia: '#ff00ff',
  3622. gainsboro: '#dcdcdc',
  3623. ghostwhite: '#f8f8ff',
  3624. gold: '#ffd700',
  3625. goldenrod: '#daa520',
  3626. gray: '#808080',
  3627. green: '#008000',
  3628. greenyellow: '#adff2f',
  3629. honeydew: '#f0fff0',
  3630. hotpink: '#ff69b4',
  3631. indianred: '#cd5c5c',
  3632. indigo: '#4b0082',
  3633. ivory: '#fffff0',
  3634. khaki: '#f0e68c',
  3635. lavender: '#e6e6fa',
  3636. lavenderblush: '#fff0f5',
  3637. lawngreen: '#7cfc00',
  3638. lemonchiffon: '#fffacd',
  3639. lightblue: '#add8e6',
  3640. lightcoral: '#f08080',
  3641. lightcyan: '#e0ffff',
  3642. lightgoldenrodyellow: '#fafad2',
  3643. lightgrey: '#d3d3d3',
  3644. lightgreen: '#90ee90',
  3645. lightpink: '#ffb6c1',
  3646. lightsalmon: '#ffa07a',
  3647. lightseagreen: '#20b2aa',
  3648. lightskyblue: '#87cefa',
  3649. lightslateblue: '#8470ff',
  3650. lightslategray: '#778899',
  3651. lightsteelblue: '#b0c4de',
  3652. lightyellow: '#ffffe0',
  3653. lime: '#00ff00',
  3654. limegreen: '#32cd32',
  3655. linen: '#faf0e6',
  3656. magenta: '#ff00ff',
  3657. maroon: '#800000',
  3658. mediumaquamarine: '#66cdaa',
  3659. mediumblue: '#0000cd',
  3660. mediumorchid: '#ba55d3',
  3661. mediumpurple: '#9370d8',
  3662. mediumseagreen: '#3cb371',
  3663. mediumslateblue: '#7b68ee',
  3664. mediumspringgreen: '#00fa9a',
  3665. mediumturquoise: '#48d1cc',
  3666. mediumvioletred: '#c71585',
  3667. midnightblue: '#191970',
  3668. mintcream: '#f5fffa',
  3669. mistyrose: '#ffe4e1',
  3670. moccasin: '#ffe4b5',
  3671. navajowhite: '#ffdead',
  3672. navy: '#000080',
  3673. oldlace: '#fdf5e6',
  3674. olive: '#808000',
  3675. olivedrab: '#6b8e23',
  3676. orange: '#ffa500',
  3677. orangered: '#ff4500',
  3678. orchid: '#da70d6',
  3679. palegoldenrod: '#eee8aa',
  3680. palegreen: '#98fb98',
  3681. paleturquoise: '#afeeee',
  3682. palevioletred: '#d87093',
  3683. papayawhip: '#ffefd5',
  3684. peachpuff: '#ffdab9',
  3685. peru: '#cd853f',
  3686. pink: '#ffc0cb',
  3687. plum: '#dda0dd',
  3688. powderblue: '#b0e0e6',
  3689. purple: '#800080',
  3690. red: '#ff0000',
  3691. rosybrown: '#bc8f8f',
  3692. royalblue: '#4169e1',
  3693. saddlebrown: '#8b4513',
  3694. salmon: '#fa8072',
  3695. sandybrown: '#f4a460',
  3696. seagreen: '#2e8b57',
  3697. seashell: '#fff5ee',
  3698. sienna: '#a0522d',
  3699. silver: '#c0c0c0',
  3700. skyblue: '#87ceeb',
  3701. slateblue: '#6a5acd',
  3702. slategray: '#708090',
  3703. snow: '#fffafa',
  3704. springgreen: '#00ff7f',
  3705. steelblue: '#4682b4',
  3706. tan: '#d2b48c',
  3707. teal: '#008080',
  3708. thistle: '#d8bfd8',
  3709. tomato: '#ff6347',
  3710. turquoise: '#40e0d0',
  3711. violet: '#ee82ee',
  3712. violetred: '#d02090',
  3713. wheat: '#f5deb3',
  3714. white: '#ffffff',
  3715. whitesmoke: '#f5f5f5',
  3716. yellow: '#ffff00',
  3717. yellowgreen: '#9acd32'
  3718. };
  3719. Color.names = defaultHTMLColorMap;
  3720. return defaultHTMLColorMap;
  3721. });
  3722. _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) {
  3723. /* *
  3724. *
  3725. * Copyright (c) 2019-2021 Highsoft AS
  3726. *
  3727. * Boost module: stripped-down renderer for higher performance
  3728. *
  3729. * License: highcharts.com/license
  3730. *
  3731. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3732. *
  3733. * */
  3734. var error = U.error;
  3735. // These need to be fixed when we support named imports
  3736. var hasWebGLSupport = butils.hasWebGLSupport;
  3737. if (!hasWebGLSupport()) {
  3738. if (typeof initCanvasBoost !== 'undefined') {
  3739. // Fallback to canvas boost
  3740. initCanvasBoost();
  3741. }
  3742. else {
  3743. error(26);
  3744. }
  3745. }
  3746. else {
  3747. // WebGL support is alright, and we're good to go.
  3748. init();
  3749. }
  3750. });
  3751. _registerModule(_modules, 'masters/modules/boost.src.js', [], function () {
  3752. });
  3753. }));