boost.src.js 165 KB

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