boost.src.js 134 KB

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