boost.src.js 135 KB

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