highcharts-3d.src.js 207 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831
  1. /**
  2. * @license Highcharts JS v8.2.2 (2020-10-22)
  3. *
  4. * 3D features for Highcharts JS
  5. *
  6. * License: www.highcharts.com/license
  7. */
  8. 'use strict';
  9. (function (factory) {
  10. if (typeof module === 'object' && module.exports) {
  11. factory['default'] = factory;
  12. module.exports = factory;
  13. } else if (typeof define === 'function' && define.amd) {
  14. define('highcharts/highcharts-3d', ['highcharts'], function (Highcharts) {
  15. factory(Highcharts);
  16. factory.Highcharts = Highcharts;
  17. return factory;
  18. });
  19. } else {
  20. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  21. }
  22. }(function (Highcharts) {
  23. var _modules = Highcharts ? Highcharts._modules : {};
  24. function _registerModule(obj, path, args, fn) {
  25. if (!obj.hasOwnProperty(path)) {
  26. obj[path] = fn.apply(null, args);
  27. }
  28. }
  29. _registerModule(_modules, 'Extensions/Math3D.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  30. /* *
  31. *
  32. * (c) 2010-2020 Torstein Honsi
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. *
  38. * */
  39. var pick = U.pick;
  40. // Mathematical Functionility
  41. var deg2rad = H.deg2rad;
  42. /* eslint-disable max-len */
  43. /**
  44. * Apply 3-D rotation
  45. * Euler Angles (XYZ):
  46. * cosA = cos(Alfa|Roll)
  47. * cosB = cos(Beta|Pitch)
  48. * cosG = cos(Gamma|Yaw)
  49. *
  50. * Composite rotation:
  51. * | cosB * cosG | cosB * sinG | -sinB |
  52. * | sinA * sinB * cosG - cosA * sinG | sinA * sinB * sinG + cosA * cosG | sinA * cosB |
  53. * | cosA * sinB * cosG + sinA * sinG | cosA * sinB * sinG - sinA * cosG | cosA * cosB |
  54. *
  55. * Now, Gamma/Yaw is not used (angle=0), so we assume cosG = 1 and sinG = 0, so
  56. * we get:
  57. * | cosB | 0 | - sinB |
  58. * | sinA * sinB | cosA | sinA * cosB |
  59. * | cosA * sinB | - sinA | cosA * cosB |
  60. *
  61. * But in browsers, y is reversed, so we get sinA => -sinA. The general result
  62. * is:
  63. * | cosB | 0 | - sinB | | x | | px |
  64. * | - sinA * sinB | cosA | - sinA * cosB | x | y | = | py |
  65. * | cosA * sinB | sinA | cosA * cosB | | z | | pz |
  66. *
  67. * @private
  68. * @function rotate3D
  69. */
  70. /* eslint-enable max-len */
  71. /**
  72. * @private
  73. * @param {number} x
  74. * X coordinate
  75. * @param {number} y
  76. * Y coordinate
  77. * @param {number} z
  78. * Z coordinate
  79. * @param {Highcharts.Rotation3dObject} angles
  80. * Rotation angles
  81. * @return {Highcharts.Rotation3dObject}
  82. * Rotated position
  83. */
  84. function rotate3D(x, y, z, angles) {
  85. return {
  86. x: angles.cosB * x - angles.sinB * z,
  87. y: -angles.sinA * angles.sinB * x + angles.cosA * y -
  88. angles.cosB * angles.sinA * z,
  89. z: angles.cosA * angles.sinB * x + angles.sinA * y +
  90. angles.cosA * angles.cosB * z
  91. };
  92. }
  93. /**
  94. * Perspective3D function is available in global Highcharts scope because is
  95. * needed also outside of perspective() function (#8042).
  96. * @private
  97. * @function Highcharts.perspective3D
  98. *
  99. * @param {Highcharts.Position3dObject} coordinate
  100. * 3D position
  101. *
  102. * @param {Highcharts.Position3dObject} origin
  103. * 3D root position
  104. *
  105. * @param {number} distance
  106. * Perspective distance
  107. *
  108. * @return {Highcharts.PositionObject}
  109. * Perspective 3D Position
  110. *
  111. * @requires highcharts-3d
  112. */
  113. var perspective3D = H.perspective3D = function (coordinate,
  114. origin,
  115. distance) {
  116. var projection = ((distance > 0) && (distance < Number.POSITIVE_INFINITY)) ?
  117. distance / (coordinate.z + origin.z + distance) :
  118. 1;
  119. return {
  120. x: coordinate.x * projection,
  121. y: coordinate.y * projection
  122. };
  123. };
  124. /**
  125. * Transforms a given array of points according to the angles in chart.options.
  126. *
  127. * @private
  128. * @function Highcharts.perspective
  129. *
  130. * @param {Array<Highcharts.Position3dObject>} points
  131. * The array of points
  132. *
  133. * @param {Highcharts.Chart} chart
  134. * The chart
  135. *
  136. * @param {boolean} [insidePlotArea]
  137. * Whether to verifiy that the points are inside the plotArea
  138. *
  139. * @param {boolean} [useInvertedPersp]
  140. * Whether to use inverted perspective in calculations
  141. *
  142. * @return {Array<Highcharts.Position3dObject>}
  143. * An array of transformed points
  144. *
  145. * @requires highcharts-3d
  146. */
  147. var perspective = H.perspective = function (points,
  148. chart,
  149. insidePlotArea,
  150. useInvertedPersp) {
  151. var options3d = chart.options.chart.options3d,
  152. /* The useInvertedPersp argument is used for
  153. * inverted charts with already inverted elements,
  154. * such as dataLabels or tooltip positions.
  155. */
  156. inverted = pick(useInvertedPersp,
  157. insidePlotArea ? chart.inverted : false),
  158. origin = {
  159. x: chart.plotWidth / 2,
  160. y: chart.plotHeight / 2,
  161. z: options3d.depth / 2,
  162. vd: pick(options3d.depth, 1) * pick(options3d.viewDistance, 0)
  163. },
  164. scale = chart.scale3d || 1,
  165. beta = deg2rad * options3d.beta * (inverted ? -1 : 1),
  166. alpha = deg2rad * options3d.alpha * (inverted ? -1 : 1),
  167. angles = {
  168. cosA: Math.cos(alpha),
  169. cosB: Math.cos(-beta),
  170. sinA: Math.sin(alpha),
  171. sinB: Math.sin(-beta)
  172. };
  173. if (!insidePlotArea) {
  174. origin.x += chart.plotLeft;
  175. origin.y += chart.plotTop;
  176. }
  177. // Transform each point
  178. return points.map(function (point) {
  179. var rotated = rotate3D((inverted ? point.y : point.x) - origin.x, (inverted ? point.x : point.y) - origin.y, (point.z || 0) - origin.z,
  180. angles),
  181. // Apply perspective
  182. coordinate = perspective3D(rotated,
  183. origin,
  184. origin.vd);
  185. // Apply translation
  186. coordinate.x = coordinate.x * scale + origin.x;
  187. coordinate.y = coordinate.y * scale + origin.y;
  188. coordinate.z = rotated.z * scale + origin.z;
  189. return {
  190. x: (inverted ? coordinate.y : coordinate.x),
  191. y: (inverted ? coordinate.x : coordinate.y),
  192. z: coordinate.z
  193. };
  194. });
  195. };
  196. /**
  197. * Calculate a distance from camera to points - made for calculating zIndex of
  198. * scatter points.
  199. *
  200. * @private
  201. * @function Highcharts.pointCameraDistance
  202. *
  203. * @param {Highcharts.Dictionary<number>} coordinates
  204. * Coordinates of the specific point
  205. *
  206. * @param {Highcharts.Chart} chart
  207. * Related chart
  208. *
  209. * @return {number}
  210. * Distance from camera to point
  211. *
  212. * @requires highcharts-3d
  213. */
  214. var pointCameraDistance = H.pointCameraDistance = function (coordinates,
  215. chart) {
  216. var options3d = chart.options.chart.options3d,
  217. cameraPosition = {
  218. x: chart.plotWidth / 2,
  219. y: chart.plotHeight / 2,
  220. z: pick(options3d.depth, 1) * pick(options3d.viewDistance, 0) +
  221. options3d.depth
  222. },
  223. // Added support for objects with plotX or x coordinates.
  224. distance = Math.sqrt(Math.pow(cameraPosition.x - pick(coordinates.plotX,
  225. coordinates.x), 2) +
  226. Math.pow(cameraPosition.y - pick(coordinates.plotY,
  227. coordinates.y), 2) +
  228. Math.pow(cameraPosition.z - pick(coordinates.plotZ,
  229. coordinates.z), 2));
  230. return distance;
  231. };
  232. /**
  233. * Calculate area of a 2D polygon using Shoelace algorithm
  234. * https://en.wikipedia.org/wiki/Shoelace_formula
  235. *
  236. * @private
  237. * @function Highcharts.shapeArea
  238. *
  239. * @param {Array<Highcharts.PositionObject>} vertexes
  240. * 2D Polygon
  241. *
  242. * @return {number}
  243. * Calculated area
  244. *
  245. * @requires highcharts-3d
  246. */
  247. var shapeArea = H.shapeArea = function (vertexes) {
  248. var area = 0,
  249. i,
  250. j;
  251. for (i = 0; i < vertexes.length; i++) {
  252. j = (i + 1) % vertexes.length;
  253. area += vertexes[i].x * vertexes[j].y - vertexes[j].x * vertexes[i].y;
  254. }
  255. return area / 2;
  256. };
  257. /**
  258. * Calculate area of a 3D polygon after perspective projection
  259. *
  260. * @private
  261. * @function Highcharts.shapeArea3d
  262. *
  263. * @param {Array<Highcharts.Position3dObject>} vertexes
  264. * 3D Polygon
  265. *
  266. * @param {Highcharts.Chart} chart
  267. * Related chart
  268. *
  269. * @param {boolean} [insidePlotArea]
  270. * Whether to verifiy that the points are inside the plotArea
  271. *
  272. * @return {number}
  273. * Calculated area
  274. *
  275. * @requires highcharts-3d
  276. */
  277. var shapeArea3D = H.shapeArea3d = function (vertexes,
  278. chart,
  279. insidePlotArea) {
  280. return shapeArea(perspective(vertexes,
  281. chart,
  282. insidePlotArea));
  283. };
  284. var mathModule = {
  285. perspective: perspective,
  286. perspective3D: perspective3D,
  287. pointCameraDistance: pointCameraDistance,
  288. shapeArea: shapeArea,
  289. shapeArea3D: shapeArea3D
  290. };
  291. return mathModule;
  292. });
  293. _registerModule(_modules, 'Core/Renderer/SVG/SVGRenderer3D.js', [_modules['Core/Animation/AnimationUtilities.js'], _modules['Core/Color/Color.js'], _modules['Core/Globals.js'], _modules['Extensions/Math3D.js'], _modules['Core/Renderer/SVG/SVGElement.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Utilities.js']], function (A, Color, H, Math3D, SVGElement, SVGRenderer, U) {
  294. /* *
  295. *
  296. * (c) 2010-2020 Torstein Honsi
  297. *
  298. * Extensions to the SVGRenderer class to enable 3D shapes
  299. *
  300. * License: www.highcharts.com/license
  301. *
  302. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  303. *
  304. * */
  305. var animObject = A.animObject;
  306. var color = Color.parse;
  307. var perspective = Math3D.perspective,
  308. shapeArea = Math3D.shapeArea;
  309. var defined = U.defined,
  310. extend = U.extend,
  311. merge = U.merge,
  312. objectEach = U.objectEach,
  313. pick = U.pick;
  314. var cos = Math.cos,
  315. PI = Math.PI,
  316. sin = Math.sin;
  317. var charts = H.charts,
  318. deg2rad = H.deg2rad,
  319. // internal:
  320. dFactor,
  321. element3dMethods,
  322. cuboidMethods;
  323. /*
  324. EXTENSION TO THE SVG-RENDERER TO ENABLE 3D SHAPES
  325. */
  326. // HELPER METHODS
  327. dFactor = (4 * (Math.sqrt(2) - 1) / 3) / (PI / 2);
  328. /* eslint-disable no-invalid-this, valid-jsdoc */
  329. /**
  330. * Method to construct a curved path. Can 'wrap' around more then 180 degrees.
  331. * @private
  332. */
  333. function curveTo(cx, cy, rx, ry, start, end, dx, dy) {
  334. var result = [],
  335. arcAngle = end - start;
  336. if ((end > start) && (end - start > Math.PI / 2 + 0.0001)) {
  337. result = result.concat(curveTo(cx, cy, rx, ry, start, start + (Math.PI / 2), dx, dy));
  338. result = result.concat(curveTo(cx, cy, rx, ry, start + (Math.PI / 2), end, dx, dy));
  339. return result;
  340. }
  341. if ((end < start) && (start - end > Math.PI / 2 + 0.0001)) {
  342. result = result.concat(curveTo(cx, cy, rx, ry, start, start - (Math.PI / 2), dx, dy));
  343. result = result.concat(curveTo(cx, cy, rx, ry, start - (Math.PI / 2), end, dx, dy));
  344. return result;
  345. }
  346. return [[
  347. 'C',
  348. cx + (rx * Math.cos(start)) -
  349. ((rx * dFactor * arcAngle) * Math.sin(start)) + dx,
  350. cy + (ry * Math.sin(start)) +
  351. ((ry * dFactor * arcAngle) * Math.cos(start)) + dy,
  352. cx + (rx * Math.cos(end)) +
  353. ((rx * dFactor * arcAngle) * Math.sin(end)) + dx,
  354. cy + (ry * Math.sin(end)) -
  355. ((ry * dFactor * arcAngle) * Math.cos(end)) + dy,
  356. cx + (rx * Math.cos(end)) + dx,
  357. cy + (ry * Math.sin(end)) + dy
  358. ]];
  359. }
  360. SVGRenderer.prototype.toLinePath = function (points, closed) {
  361. var result = [];
  362. // Put "L x y" for each point
  363. points.forEach(function (point) {
  364. result.push(['L', point.x, point.y]);
  365. });
  366. if (points.length) {
  367. // Set the first element to M
  368. result[0][0] = 'M';
  369. // If it is a closed line, add Z
  370. if (closed) {
  371. result.push(['Z']);
  372. }
  373. }
  374. return result;
  375. };
  376. SVGRenderer.prototype.toLineSegments = function (points) {
  377. var result = [],
  378. m = true;
  379. points.forEach(function (point) {
  380. result.push(m ? ['M', point.x, point.y] : ['L', point.x, point.y]);
  381. m = !m;
  382. });
  383. return result;
  384. };
  385. // A 3-D Face is defined by it's 3D vertexes, and is only visible if it's
  386. // vertexes are counter-clockwise (Back-face culling). It is used as a
  387. // polyhedron Element
  388. SVGRenderer.prototype.face3d = function (args) {
  389. var renderer = this,
  390. ret = this.createElement('path');
  391. ret.vertexes = [];
  392. ret.insidePlotArea = false;
  393. ret.enabled = true;
  394. ret.attr = function (hash) {
  395. if (typeof hash === 'object' &&
  396. (defined(hash.enabled) ||
  397. defined(hash.vertexes) ||
  398. defined(hash.insidePlotArea))) {
  399. this.enabled = pick(hash.enabled, this.enabled);
  400. this.vertexes = pick(hash.vertexes, this.vertexes);
  401. this.insidePlotArea = pick(hash.insidePlotArea, this.insidePlotArea);
  402. delete hash.enabled;
  403. delete hash.vertexes;
  404. delete hash.insidePlotArea;
  405. var chart = charts[renderer.chartIndex],
  406. vertexes2d = perspective(this.vertexes,
  407. chart,
  408. this.insidePlotArea),
  409. path = renderer.toLinePath(vertexes2d,
  410. true),
  411. area = shapeArea(vertexes2d),
  412. visibility = (this.enabled && area > 0) ? 'visible' : 'hidden';
  413. hash.d = path;
  414. hash.visibility = visibility;
  415. }
  416. return SVGElement.prototype.attr.apply(this, arguments);
  417. };
  418. ret.animate = function (params) {
  419. if (typeof params === 'object' &&
  420. (defined(params.enabled) ||
  421. defined(params.vertexes) ||
  422. defined(params.insidePlotArea))) {
  423. this.enabled = pick(params.enabled, this.enabled);
  424. this.vertexes = pick(params.vertexes, this.vertexes);
  425. this.insidePlotArea = pick(params.insidePlotArea, this.insidePlotArea);
  426. delete params.enabled;
  427. delete params.vertexes;
  428. delete params.insidePlotArea;
  429. var chart = charts[renderer.chartIndex],
  430. vertexes2d = perspective(this.vertexes,
  431. chart,
  432. this.insidePlotArea),
  433. path = renderer.toLinePath(vertexes2d,
  434. true),
  435. area = shapeArea(vertexes2d),
  436. visibility = (this.enabled && area > 0) ? 'visible' : 'hidden';
  437. params.d = path;
  438. this.attr('visibility', visibility);
  439. }
  440. return SVGElement.prototype.animate.apply(this, arguments);
  441. };
  442. return ret.attr(args);
  443. };
  444. // A Polyhedron is a handy way of defining a group of 3-D faces. It's only
  445. // attribute is `faces`, an array of attributes of each one of it's Face3D
  446. // instances.
  447. SVGRenderer.prototype.polyhedron = function (args) {
  448. var renderer = this,
  449. result = this.g(),
  450. destroy = result.destroy;
  451. if (!this.styledMode) {
  452. result.attr({
  453. 'stroke-linejoin': 'round'
  454. });
  455. }
  456. result.faces = [];
  457. // destroy all children
  458. result.destroy = function () {
  459. for (var i = 0; i < result.faces.length; i++) {
  460. result.faces[i].destroy();
  461. }
  462. return destroy.call(this);
  463. };
  464. result.attr = function (hash, val, complete, continueAnimation) {
  465. if (typeof hash === 'object' && defined(hash.faces)) {
  466. while (result.faces.length > hash.faces.length) {
  467. result.faces.pop().destroy();
  468. }
  469. while (result.faces.length < hash.faces.length) {
  470. result.faces.push(renderer.face3d().add(result));
  471. }
  472. for (var i = 0; i < hash.faces.length; i++) {
  473. if (renderer.styledMode) {
  474. delete hash.faces[i].fill;
  475. }
  476. result.faces[i].attr(hash.faces[i], null, complete, continueAnimation);
  477. }
  478. delete hash.faces;
  479. }
  480. return SVGElement.prototype.attr.apply(this, arguments);
  481. };
  482. result.animate = function (params, duration, complete) {
  483. if (params && params.faces) {
  484. while (result.faces.length > params.faces.length) {
  485. result.faces.pop().destroy();
  486. }
  487. while (result.faces.length < params.faces.length) {
  488. result.faces.push(renderer.face3d().add(result));
  489. }
  490. for (var i = 0; i < params.faces.length; i++) {
  491. result.faces[i].animate(params.faces[i], duration, complete);
  492. }
  493. delete params.faces;
  494. }
  495. return SVGElement.prototype.animate.apply(this, arguments);
  496. };
  497. return result.attr(args);
  498. };
  499. // Base, abstract prototype member for 3D elements
  500. element3dMethods = {
  501. /**
  502. * The init is used by base - renderer.Element
  503. * @private
  504. */
  505. initArgs: function (args) {
  506. var elem3d = this,
  507. renderer = elem3d.renderer,
  508. paths = renderer[elem3d.pathType + 'Path'](args),
  509. zIndexes = paths.zIndexes;
  510. // build parts
  511. elem3d.parts.forEach(function (part) {
  512. elem3d[part] = renderer.path(paths[part]).attr({
  513. 'class': 'highcharts-3d-' + part,
  514. zIndex: zIndexes[part] || 0
  515. }).add(elem3d);
  516. });
  517. elem3d.attr({
  518. 'stroke-linejoin': 'round',
  519. zIndex: zIndexes.group
  520. });
  521. // store original destroy
  522. elem3d.originalDestroy = elem3d.destroy;
  523. elem3d.destroy = elem3d.destroyParts;
  524. // Store information if any side of element was rendered by force.
  525. elem3d.forcedSides = paths.forcedSides;
  526. },
  527. /**
  528. * Single property setter that applies options to each part
  529. * @private
  530. */
  531. singleSetterForParts: function (prop, val, values, verb, duration, complete) {
  532. var elem3d = this,
  533. newAttr = {},
  534. optionsToApply = [null,
  535. null, (verb || 'attr'),
  536. duration,
  537. complete],
  538. hasZIndexes = values && values.zIndexes;
  539. if (!values) {
  540. newAttr[prop] = val;
  541. optionsToApply[0] = newAttr;
  542. }
  543. else {
  544. // It is needed to deal with the whole group zIndexing
  545. // in case of graph rotation
  546. if (hasZIndexes && hasZIndexes.group) {
  547. this.attr({
  548. zIndex: hasZIndexes.group
  549. });
  550. }
  551. objectEach(values, function (partVal, part) {
  552. newAttr[part] = {};
  553. newAttr[part][prop] = partVal;
  554. // include zIndexes if provided
  555. if (hasZIndexes) {
  556. newAttr[part].zIndex = values.zIndexes[part] || 0;
  557. }
  558. });
  559. optionsToApply[1] = newAttr;
  560. }
  561. return elem3d.processParts.apply(elem3d, optionsToApply);
  562. },
  563. /**
  564. * Calls function for each part. Used for attr, animate and destroy.
  565. * @private
  566. */
  567. processParts: function (props, partsProps, verb, duration, complete) {
  568. var elem3d = this;
  569. elem3d.parts.forEach(function (part) {
  570. // if different props for different parts
  571. if (partsProps) {
  572. props = pick(partsProps[part], false);
  573. }
  574. // only if something to set, but allow undefined
  575. if (props !== false) {
  576. elem3d[part][verb](props, duration, complete);
  577. }
  578. });
  579. return elem3d;
  580. },
  581. /**
  582. * Destroy all parts
  583. * @private
  584. */
  585. destroyParts: function () {
  586. this.processParts(null, null, 'destroy');
  587. return this.originalDestroy();
  588. }
  589. };
  590. // CUBOID
  591. cuboidMethods = merge(element3dMethods, {
  592. parts: ['front', 'top', 'side'],
  593. pathType: 'cuboid',
  594. attr: function (args, val, complete, continueAnimation) {
  595. // Resolve setting attributes by string name
  596. if (typeof args === 'string' && typeof val !== 'undefined') {
  597. var key = args;
  598. args = {};
  599. args[key] = val;
  600. }
  601. if (args.shapeArgs || defined(args.x)) {
  602. return this.singleSetterForParts('d', null, this.renderer[this.pathType + 'Path'](args.shapeArgs || args));
  603. }
  604. return SVGElement.prototype.attr.call(this, args, void 0, complete, continueAnimation);
  605. },
  606. animate: function (args, duration, complete) {
  607. if (defined(args.x) && defined(args.y)) {
  608. var paths = this.renderer[this.pathType + 'Path'](args),
  609. forcedSides = paths.forcedSides;
  610. this.singleSetterForParts('d', null, paths, 'animate', duration, complete);
  611. this.attr({
  612. zIndex: paths.zIndexes.group
  613. });
  614. // If sides that are forced to render changed, recalculate colors.
  615. if (forcedSides !== this.forcedSides) {
  616. this.forcedSides = forcedSides;
  617. cuboidMethods.fillSetter.call(this, this.fill);
  618. }
  619. }
  620. else {
  621. SVGElement.prototype.animate.call(this, args, duration, complete);
  622. }
  623. return this;
  624. },
  625. fillSetter: function (fill) {
  626. var elem3d = this;
  627. elem3d.forcedSides = elem3d.forcedSides || [];
  628. elem3d.singleSetterForParts('fill', null, {
  629. front: fill,
  630. // Do not change color if side was forced to render.
  631. top: color(fill).brighten(elem3d.forcedSides.indexOf('top') >= 0 ? 0 : 0.1).get(),
  632. side: color(fill).brighten(elem3d.forcedSides.indexOf('side') >= 0 ? 0 : -0.1).get()
  633. });
  634. // fill for animation getter (#6776)
  635. elem3d.color = elem3d.fill = fill;
  636. return elem3d;
  637. }
  638. });
  639. // set them up
  640. SVGRenderer.prototype.elements3d = {
  641. base: element3dMethods,
  642. cuboid: cuboidMethods
  643. };
  644. /**
  645. * return result, generalization
  646. * @private
  647. * @requires highcharts-3d
  648. */
  649. SVGRenderer.prototype.element3d = function (type, shapeArgs) {
  650. // base
  651. var ret = this.g();
  652. // extend
  653. extend(ret, this.elements3d[type]);
  654. // init
  655. ret.initArgs(shapeArgs);
  656. // return
  657. return ret;
  658. };
  659. // generelized, so now use simply
  660. SVGRenderer.prototype.cuboid = function (shapeArgs) {
  661. return this.element3d('cuboid', shapeArgs);
  662. };
  663. // Generates a cuboid path and zIndexes
  664. SVGRenderer.prototype.cuboidPath = function (shapeArgs) {
  665. var x = shapeArgs.x,
  666. y = shapeArgs.y,
  667. z = shapeArgs.z || 0,
  668. // For side calculation (right/left)
  669. // there is a need for height (and other shapeArgs arguments)
  670. // to be at least 1px
  671. h = shapeArgs.height,
  672. w = shapeArgs.width,
  673. d = shapeArgs.depth,
  674. chart = charts[this.chartIndex],
  675. front,
  676. back,
  677. top,
  678. bottom,
  679. left,
  680. right,
  681. shape,
  682. path1,
  683. path2,
  684. path3,
  685. isFront,
  686. isTop,
  687. isRight,
  688. options3d = chart.options.chart.options3d,
  689. alpha = options3d.alpha,
  690. // Priority for x axis is the biggest,
  691. // because of x direction has biggest influence on zIndex
  692. incrementX = 1000000,
  693. // y axis has the smallest priority in case of our charts
  694. // (needs to be set because of stacking)
  695. incrementY = 10,
  696. incrementZ = 100,
  697. zIndex = 0,
  698. // The 8 corners of the cube
  699. pArr = [{
  700. x: x,
  701. y: y,
  702. z: z
  703. }, {
  704. x: x + w,
  705. y: y,
  706. z: z
  707. }, {
  708. x: x + w,
  709. y: y + h,
  710. z: z
  711. }, {
  712. x: x,
  713. y: y + h,
  714. z: z
  715. }, {
  716. x: x,
  717. y: y + h,
  718. z: z + d
  719. }, {
  720. x: x + w,
  721. y: y + h,
  722. z: z + d
  723. }, {
  724. x: x + w,
  725. y: y,
  726. z: z + d
  727. }, {
  728. x: x,
  729. y: y,
  730. z: z + d
  731. }],
  732. forcedSides = [],
  733. pickShape;
  734. // apply perspective
  735. pArr = perspective(pArr, chart, shapeArgs.insidePlotArea);
  736. /**
  737. * helper method to decide which side is visible
  738. * @private
  739. */
  740. function mapSidePath(i) {
  741. // Added support for 0 value in columns, where height is 0
  742. // but the shape is rendered.
  743. // Height is used from 1st to 6th element of pArr
  744. if (h === 0 && i > 1 && i < 6) { // [2, 3, 4, 5]
  745. return {
  746. x: pArr[i].x,
  747. // when height is 0 instead of cuboid we render plane
  748. // so it is needed to add fake 10 height to imitate cuboid
  749. // for side calculation
  750. y: pArr[i].y + 10,
  751. z: pArr[i].z
  752. };
  753. }
  754. // It is needed to calculate dummy sides (front/back) for breaking
  755. // points in case of x and depth values. If column has side,
  756. // it means that x values of front and back side are different.
  757. if (pArr[0].x === pArr[7].x && i >= 4) { // [4, 5, 6, 7]
  758. return {
  759. x: pArr[i].x + 10,
  760. // when height is 0 instead of cuboid we render plane
  761. // so it is needed to add fake 10 height to imitate cuboid
  762. // for side calculation
  763. y: pArr[i].y,
  764. z: pArr[i].z
  765. };
  766. }
  767. // Added dummy depth
  768. if (d === 0 && i < 2 || i > 5) { // [0, 1, 6, 7]
  769. return {
  770. x: pArr[i].x,
  771. // when height is 0 instead of cuboid we render plane
  772. // so it is needed to add fake 10 height to imitate cuboid
  773. // for side calculation
  774. y: pArr[i].y,
  775. z: pArr[i].z + 10
  776. };
  777. }
  778. return pArr[i];
  779. }
  780. /**
  781. * method creating the final side
  782. * @private
  783. */
  784. function mapPath(i) {
  785. return pArr[i];
  786. }
  787. /**
  788. * First value - path with specific face
  789. * Second value - added information about side for later calculations.
  790. * Possible second values are 0 for path1, 1 for path2 and -1 for no path
  791. * chosen.
  792. * Third value - string containing information about current side
  793. * of cuboid for forcing side rendering.
  794. * @private
  795. */
  796. pickShape = function (verticesIndex1, verticesIndex2, side) {
  797. var ret = [[], -1],
  798. // An array of vertices for cuboid face
  799. face1 = verticesIndex1.map(mapPath),
  800. face2 = verticesIndex2.map(mapPath),
  801. // dummy face is calculated the same way as standard face,
  802. // but if cuboid height is 0 additional height is added so it is
  803. // possible to use this vertices array for visible face calculation
  804. dummyFace1 = verticesIndex1.map(mapSidePath),
  805. dummyFace2 = verticesIndex2.map(mapSidePath);
  806. if (shapeArea(face1) < 0) {
  807. ret = [face1, 0];
  808. }
  809. else if (shapeArea(face2) < 0) {
  810. ret = [face2, 1];
  811. }
  812. else if (side) {
  813. forcedSides.push(side);
  814. if (shapeArea(dummyFace1) < 0) {
  815. ret = [face1, 0];
  816. }
  817. else if (shapeArea(dummyFace2) < 0) {
  818. ret = [face2, 1];
  819. }
  820. else {
  821. ret = [face1, 0]; // force side calculation.
  822. }
  823. }
  824. return ret;
  825. };
  826. // front or back
  827. front = [3, 2, 1, 0];
  828. back = [7, 6, 5, 4];
  829. shape = pickShape(front, back, 'front');
  830. path1 = shape[0];
  831. isFront = shape[1];
  832. // top or bottom
  833. top = [1, 6, 7, 0];
  834. bottom = [4, 5, 2, 3];
  835. shape = pickShape(top, bottom, 'top');
  836. path2 = shape[0];
  837. isTop = shape[1];
  838. // side
  839. right = [1, 2, 5, 6];
  840. left = [0, 7, 4, 3];
  841. shape = pickShape(right, left, 'side');
  842. path3 = shape[0];
  843. isRight = shape[1];
  844. /* New block used for calculating zIndex. It is basing on X, Y and Z
  845. position of specific columns. All zIndexes (for X, Y and Z values) are
  846. added to the final zIndex, where every value has different priority. The
  847. biggest priority is in X and Z directions, the lowest index is for
  848. stacked columns (Y direction and the same X and Z positions). Big
  849. differences between priorities is made because we need to ensure that
  850. even for big changes in Y and Z parameters all columns will be drawn
  851. correctly. */
  852. if (isRight === 1) {
  853. // It is needed to connect value with current chart width
  854. // for big chart size.
  855. zIndex += incrementX * (chart.plotWidth - x);
  856. }
  857. else if (!isRight) {
  858. zIndex += incrementX * x;
  859. }
  860. zIndex += incrementY * (!isTop ||
  861. // Numbers checked empirically
  862. (alpha >= 0 && alpha <= 180 || alpha < 360 && alpha > 357.5) ?
  863. chart.plotHeight - y : 10 + y);
  864. if (isFront === 1) {
  865. zIndex += incrementZ * (z);
  866. }
  867. else if (!isFront) {
  868. zIndex += incrementZ * (1000 - z);
  869. }
  870. return {
  871. front: this.toLinePath(path1, true),
  872. top: this.toLinePath(path2, true),
  873. side: this.toLinePath(path3, true),
  874. zIndexes: {
  875. group: Math.round(zIndex)
  876. },
  877. forcedSides: forcedSides,
  878. // additional info about zIndexes
  879. isFront: isFront,
  880. isTop: isTop
  881. }; // #4774
  882. };
  883. // SECTORS //
  884. SVGRenderer.prototype.arc3d = function (attribs) {
  885. var wrapper = this.g(), renderer = wrapper.renderer, customAttribs = ['x', 'y', 'r', 'innerR', 'start', 'end', 'depth'];
  886. /**
  887. * Get custom attributes. Don't mutate the original object and return an
  888. * object with only custom attr.
  889. * @private
  890. */
  891. function suckOutCustom(params) {
  892. var hasCA = false,
  893. ca = {},
  894. key;
  895. params = merge(params); // Don't mutate the original object
  896. for (key in params) {
  897. if (customAttribs.indexOf(key) !== -1) {
  898. ca[key] = params[key];
  899. delete params[key];
  900. hasCA = true;
  901. }
  902. }
  903. return hasCA ? [ca, params] : false;
  904. }
  905. attribs = merge(attribs);
  906. attribs.alpha = (attribs.alpha || 0) * deg2rad;
  907. attribs.beta = (attribs.beta || 0) * deg2rad;
  908. // Create the different sub sections of the shape
  909. wrapper.top = renderer.path();
  910. wrapper.side1 = renderer.path();
  911. wrapper.side2 = renderer.path();
  912. wrapper.inn = renderer.path();
  913. wrapper.out = renderer.path();
  914. // Add all faces
  915. wrapper.onAdd = function () {
  916. var parent = wrapper.parentGroup,
  917. className = wrapper.attr('class');
  918. wrapper.top.add(wrapper);
  919. // These faces are added outside the wrapper group because the z index
  920. // relates to neighbour elements as well
  921. ['out', 'inn', 'side1', 'side2'].forEach(function (face) {
  922. wrapper[face]
  923. .attr({
  924. 'class': className + ' highcharts-3d-side'
  925. })
  926. .add(parent);
  927. });
  928. };
  929. // Cascade to faces
  930. ['addClass', 'removeClass'].forEach(function (fn) {
  931. wrapper[fn] = function () {
  932. var args = arguments;
  933. ['top', 'out', 'inn', 'side1', 'side2'].forEach(function (face) {
  934. wrapper[face][fn].apply(wrapper[face], args);
  935. });
  936. };
  937. });
  938. /**
  939. * Compute the transformed paths and set them to the composite shapes
  940. * @private
  941. */
  942. wrapper.setPaths = function (attribs) {
  943. var paths = wrapper.renderer.arc3dPath(attribs),
  944. zIndex = paths.zTop * 100;
  945. wrapper.attribs = attribs;
  946. wrapper.top.attr({ d: paths.top, zIndex: paths.zTop });
  947. wrapper.inn.attr({ d: paths.inn, zIndex: paths.zInn });
  948. wrapper.out.attr({ d: paths.out, zIndex: paths.zOut });
  949. wrapper.side1.attr({ d: paths.side1, zIndex: paths.zSide1 });
  950. wrapper.side2.attr({ d: paths.side2, zIndex: paths.zSide2 });
  951. // show all children
  952. wrapper.zIndex = zIndex;
  953. wrapper.attr({ zIndex: zIndex });
  954. // Set the radial gradient center the first time
  955. if (attribs.center) {
  956. wrapper.top.setRadialReference(attribs.center);
  957. delete attribs.center;
  958. }
  959. };
  960. wrapper.setPaths(attribs);
  961. /**
  962. * Apply the fill to the top and a darker shade to the sides
  963. * @private
  964. */
  965. wrapper.fillSetter = function (value) {
  966. var darker = color(value).brighten(-0.1).get();
  967. this.fill = value;
  968. this.side1.attr({ fill: darker });
  969. this.side2.attr({ fill: darker });
  970. this.inn.attr({ fill: darker });
  971. this.out.attr({ fill: darker });
  972. this.top.attr({ fill: value });
  973. return this;
  974. };
  975. // Apply the same value to all. These properties cascade down to the
  976. // children when set to the composite arc3d.
  977. ['opacity', 'translateX', 'translateY', 'visibility'].forEach(function (setter) {
  978. wrapper[setter + 'Setter'] = function (value, key) {
  979. wrapper[key] = value;
  980. ['out', 'inn', 'side1', 'side2', 'top'].forEach(function (el) {
  981. wrapper[el].attr(key, value);
  982. });
  983. };
  984. });
  985. // Override attr to remove shape attributes and use those to set child paths
  986. wrapper.attr = function (params) {
  987. var ca,
  988. paramArr;
  989. if (typeof params === 'object') {
  990. paramArr = suckOutCustom(params);
  991. if (paramArr) {
  992. ca = paramArr[0];
  993. arguments[0] = paramArr[1];
  994. extend(wrapper.attribs, ca);
  995. wrapper.setPaths(wrapper.attribs);
  996. }
  997. }
  998. return SVGElement.prototype.attr.apply(wrapper, arguments);
  999. };
  1000. // Override the animate function by sucking out custom parameters related to
  1001. // the shapes directly, and update the shapes from the animation step.
  1002. wrapper.animate = function (params, animation, complete) {
  1003. var paramArr,
  1004. from = this.attribs,
  1005. to,
  1006. anim,
  1007. randomProp = 'data-' + Math.random().toString(26).substring(2, 9);
  1008. // Attribute-line properties connected to 3D. These shouldn't have been
  1009. // in the attribs collection in the first place.
  1010. delete params.center;
  1011. delete params.z;
  1012. delete params.alpha;
  1013. delete params.beta;
  1014. anim = animObject(pick(animation, this.renderer.globalAnimation));
  1015. if (anim.duration) {
  1016. paramArr = suckOutCustom(params);
  1017. // Params need to have a property in order for the step to run
  1018. // (#5765, #7097, #7437)
  1019. wrapper[randomProp] = 0;
  1020. params[randomProp] = 1;
  1021. wrapper[randomProp + 'Setter'] = H.noop;
  1022. if (paramArr) {
  1023. to = paramArr[0]; // custom attr
  1024. anim.step = function (a, fx) {
  1025. /**
  1026. * @private
  1027. */
  1028. function interpolate(key) {
  1029. return from[key] + (pick(to[key], from[key]) -
  1030. from[key]) * fx.pos;
  1031. }
  1032. if (fx.prop === randomProp) {
  1033. fx.elem.setPaths(merge(from, {
  1034. x: interpolate('x'),
  1035. y: interpolate('y'),
  1036. r: interpolate('r'),
  1037. innerR: interpolate('innerR'),
  1038. start: interpolate('start'),
  1039. end: interpolate('end'),
  1040. depth: interpolate('depth')
  1041. }));
  1042. }
  1043. };
  1044. }
  1045. animation = anim; // Only when duration (#5572)
  1046. }
  1047. return SVGElement.prototype.animate.call(this, params, animation, complete);
  1048. };
  1049. // destroy all children
  1050. wrapper.destroy = function () {
  1051. this.top.destroy();
  1052. this.out.destroy();
  1053. this.inn.destroy();
  1054. this.side1.destroy();
  1055. this.side2.destroy();
  1056. return SVGElement.prototype.destroy.call(this);
  1057. };
  1058. // hide all children
  1059. wrapper.hide = function () {
  1060. this.top.hide();
  1061. this.out.hide();
  1062. this.inn.hide();
  1063. this.side1.hide();
  1064. this.side2.hide();
  1065. };
  1066. wrapper.show = function (inherit) {
  1067. this.top.show(inherit);
  1068. this.out.show(inherit);
  1069. this.inn.show(inherit);
  1070. this.side1.show(inherit);
  1071. this.side2.show(inherit);
  1072. };
  1073. return wrapper;
  1074. };
  1075. // Generate the paths required to draw a 3D arc
  1076. SVGRenderer.prototype.arc3dPath = function (shapeArgs) {
  1077. var cx = shapeArgs.x, // x coordinate of the center
  1078. cy = shapeArgs.y, // y coordinate of the center
  1079. start = shapeArgs.start, // start angle
  1080. end = shapeArgs.end - 0.00001, // end angle
  1081. r = shapeArgs.r, // radius
  1082. ir = shapeArgs.innerR || 0, // inner radius
  1083. d = shapeArgs.depth || 0, // depth
  1084. alpha = shapeArgs.alpha, // alpha rotation of the chart
  1085. beta = shapeArgs.beta; // beta rotation of the chart
  1086. // Derived Variables
  1087. var cs = Math.cos(start), // cosinus of the start angle
  1088. ss = Math.sin(start), // sinus of the start angle
  1089. ce = Math.cos(end), // cosinus of the end angle
  1090. se = Math.sin(end), // sinus of the end angle
  1091. rx = r * Math.cos(beta), // x-radius
  1092. ry = r * Math.cos(alpha), // y-radius
  1093. irx = ir * Math.cos(beta), // x-radius (inner)
  1094. iry = ir * Math.cos(alpha), // y-radius (inner)
  1095. dx = d * Math.sin(beta), // distance between top and bottom in x
  1096. dy = d * Math.sin(alpha); // distance between top and bottom in y
  1097. // TOP
  1098. var top = [
  1099. ['M',
  1100. cx + (rx * cs),
  1101. cy + (ry * ss)]
  1102. ];
  1103. top = top.concat(curveTo(cx, cy, rx, ry, start, end, 0, 0));
  1104. top.push([
  1105. 'L', cx + (irx * ce), cy + (iry * se)
  1106. ]);
  1107. top = top.concat(curveTo(cx, cy, irx, iry, end, start, 0, 0));
  1108. top.push(['Z']);
  1109. // OUTSIDE
  1110. var b = (beta > 0 ? Math.PI / 2 : 0),
  1111. a = (alpha > 0 ? 0 : Math.PI / 2);
  1112. var start2 = start > -b ? start : (end > -b ? -b : start),
  1113. end2 = end < PI - a ? end : (start < PI - a ? PI - a : end),
  1114. midEnd = 2 * PI - a;
  1115. // When slice goes over bottom middle, need to add both, left and right
  1116. // outer side. Additionally, when we cross right hand edge, create sharp
  1117. // edge. Outer shape/wall:
  1118. //
  1119. // -------
  1120. // / ^ \
  1121. // 4) / / \ \ 1)
  1122. // / / \ \
  1123. // / / \ \
  1124. // (c)=> ==== ==== <=(d)
  1125. // \ \ / /
  1126. // \ \<=(a)/ /
  1127. // \ \ / / <=(b)
  1128. // 3) \ v / 2)
  1129. // -------
  1130. //
  1131. // (a) - inner side
  1132. // (b) - outer side
  1133. // (c) - left edge (sharp)
  1134. // (d) - right edge (sharp)
  1135. // 1..n - rendering order for startAngle = 0, when set to e.g 90, order
  1136. // changes clockwise (1->2, 2->3, n->1) and counterclockwise for negative
  1137. // startAngle
  1138. var out = [
  1139. ['M',
  1140. cx + (rx * cos(start2)),
  1141. cy + (ry * sin(start2))]
  1142. ];
  1143. out = out.concat(curveTo(cx, cy, rx, ry, start2, end2, 0, 0));
  1144. // When shape is wide, it can cross both, (c) and (d) edges, when using
  1145. // startAngle
  1146. if (end > midEnd && start < midEnd) {
  1147. // Go to outer side
  1148. out.push([
  1149. 'L', cx + (rx * cos(end2)) + dx, cy + (ry * sin(end2)) + dy
  1150. ]);
  1151. // Curve to the right edge of the slice (d)
  1152. out = out.concat(curveTo(cx, cy, rx, ry, end2, midEnd, dx, dy));
  1153. // Go to the inner side
  1154. out.push([
  1155. 'L', cx + (rx * cos(midEnd)), cy + (ry * sin(midEnd))
  1156. ]);
  1157. // Curve to the true end of the slice
  1158. out = out.concat(curveTo(cx, cy, rx, ry, midEnd, end, 0, 0));
  1159. // Go to the outer side
  1160. out.push([
  1161. 'L', cx + (rx * cos(end)) + dx, cy + (ry * sin(end)) + dy
  1162. ]);
  1163. // Go back to middle (d)
  1164. out = out.concat(curveTo(cx, cy, rx, ry, end, midEnd, dx, dy));
  1165. out.push([
  1166. 'L', cx + (rx * cos(midEnd)), cy + (ry * sin(midEnd))
  1167. ]);
  1168. // Go back to the left edge
  1169. out = out.concat(curveTo(cx, cy, rx, ry, midEnd, end2, 0, 0));
  1170. // But shape can cross also only (c) edge:
  1171. }
  1172. else if (end > PI - a && start < PI - a) {
  1173. // Go to outer side
  1174. out.push([
  1175. 'L',
  1176. cx + (rx * Math.cos(end2)) + dx,
  1177. cy + (ry * Math.sin(end2)) + dy
  1178. ]);
  1179. // Curve to the true end of the slice
  1180. out = out.concat(curveTo(cx, cy, rx, ry, end2, end, dx, dy));
  1181. // Go to the inner side
  1182. out.push([
  1183. 'L', cx + (rx * Math.cos(end)), cy + (ry * Math.sin(end))
  1184. ]);
  1185. // Go back to the artifical end2
  1186. out = out.concat(curveTo(cx, cy, rx, ry, end, end2, 0, 0));
  1187. }
  1188. out.push([
  1189. 'L', cx + (rx * Math.cos(end2)) + dx, cy + (ry * Math.sin(end2)) + dy
  1190. ]);
  1191. out = out.concat(curveTo(cx, cy, rx, ry, end2, start2, dx, dy));
  1192. out.push(['Z']);
  1193. // INSIDE
  1194. var inn = [
  1195. ['M',
  1196. cx + (irx * cs),
  1197. cy + (iry * ss)]
  1198. ];
  1199. inn = inn.concat(curveTo(cx, cy, irx, iry, start, end, 0, 0));
  1200. inn.push([
  1201. 'L', cx + (irx * Math.cos(end)) + dx, cy + (iry * Math.sin(end)) + dy
  1202. ]);
  1203. inn = inn.concat(curveTo(cx, cy, irx, iry, end, start, dx, dy));
  1204. inn.push(['Z']);
  1205. // SIDES
  1206. var side1 = [
  1207. ['M',
  1208. cx + (rx * cs),
  1209. cy + (ry * ss)],
  1210. ['L',
  1211. cx + (rx * cs) + dx,
  1212. cy + (ry * ss) + dy],
  1213. ['L',
  1214. cx + (irx * cs) + dx,
  1215. cy + (iry * ss) + dy],
  1216. ['L',
  1217. cx + (irx * cs),
  1218. cy + (iry * ss)],
  1219. ['Z']
  1220. ];
  1221. var side2 = [
  1222. ['M',
  1223. cx + (rx * ce),
  1224. cy + (ry * se)],
  1225. ['L',
  1226. cx + (rx * ce) + dx,
  1227. cy + (ry * se) + dy],
  1228. ['L',
  1229. cx + (irx * ce) + dx,
  1230. cy + (iry * se) + dy],
  1231. ['L',
  1232. cx + (irx * ce),
  1233. cy + (iry * se)],
  1234. ['Z']
  1235. ];
  1236. // correction for changed position of vanishing point caused by alpha and
  1237. // beta rotations
  1238. var angleCorr = Math.atan2(dy, -dx),
  1239. angleEnd = Math.abs(end + angleCorr),
  1240. angleStart = Math.abs(start + angleCorr),
  1241. angleMid = Math.abs((start + end) / 2 + angleCorr);
  1242. /**
  1243. * set to 0-PI range
  1244. * @private
  1245. */
  1246. function toZeroPIRange(angle) {
  1247. angle = angle % (2 * Math.PI);
  1248. if (angle > Math.PI) {
  1249. angle = 2 * Math.PI - angle;
  1250. }
  1251. return angle;
  1252. }
  1253. angleEnd = toZeroPIRange(angleEnd);
  1254. angleStart = toZeroPIRange(angleStart);
  1255. angleMid = toZeroPIRange(angleMid);
  1256. // *1e5 is to compensate pInt in zIndexSetter
  1257. var incPrecision = 1e5,
  1258. a1 = angleMid * incPrecision,
  1259. a2 = angleStart * incPrecision,
  1260. a3 = angleEnd * incPrecision;
  1261. return {
  1262. top: top,
  1263. // max angle is PI, so this is always higher
  1264. zTop: Math.PI * incPrecision + 1,
  1265. out: out,
  1266. zOut: Math.max(a1, a2, a3),
  1267. inn: inn,
  1268. zInn: Math.max(a1, a2, a3),
  1269. side1: side1,
  1270. zSide1: a3 * 0.99,
  1271. side2: side2,
  1272. zSide2: a2 * 0.99
  1273. };
  1274. };
  1275. return SVGRenderer;
  1276. });
  1277. _registerModule(_modules, 'Core/Axis/Tick3D.js', [_modules['Core/Utilities.js']], function (U) {
  1278. /* *
  1279. *
  1280. * (c) 2010-2020 Torstein Honsi
  1281. *
  1282. * Extenstion for 3d axes
  1283. *
  1284. * License: www.highcharts.com/license
  1285. *
  1286. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1287. *
  1288. * */
  1289. var addEvent = U.addEvent,
  1290. extend = U.extend,
  1291. wrap = U.wrap;
  1292. /* eslint-disable valid-jsdoc */
  1293. /**
  1294. * Tick with 3D support
  1295. * @private
  1296. * @class
  1297. */
  1298. var Tick3D = /** @class */ (function () {
  1299. function Tick3D() {
  1300. }
  1301. /* *
  1302. *
  1303. * Static Functions
  1304. *
  1305. * */
  1306. /**
  1307. * @private
  1308. */
  1309. Tick3D.compose = function (TickClass) {
  1310. addEvent(TickClass, 'afterGetLabelPosition', Tick3D.onAfterGetLabelPosition);
  1311. var tickProto = TickClass.prototype;
  1312. wrap(tickProto, 'getMarkPath', Tick3D.wrapGetMarkPath);
  1313. };
  1314. /**
  1315. * @private
  1316. */
  1317. Tick3D.onAfterGetLabelPosition = function (e) {
  1318. var axis3D = this.axis.axis3D;
  1319. if (axis3D) {
  1320. extend(e.pos, axis3D.fix3dPosition(e.pos));
  1321. }
  1322. };
  1323. /**
  1324. * @private
  1325. */
  1326. Tick3D.wrapGetMarkPath = function (proceed) {
  1327. var chart = this.axis.chart;
  1328. var axis3D = this.axis.axis3D;
  1329. var path = proceed.apply(this,
  1330. [].slice.call(arguments, 1));
  1331. if (axis3D) {
  1332. var start = path[0];
  1333. var end = path[1];
  1334. if (start[0] === 'M' && end[0] === 'L') {
  1335. var pArr = [
  1336. axis3D.fix3dPosition({ x: start[1],
  1337. y: start[2],
  1338. z: 0 }),
  1339. axis3D.fix3dPosition({ x: end[1],
  1340. y: end[2],
  1341. z: 0 })
  1342. ];
  1343. return this.axis.chart.renderer.toLineSegments(pArr);
  1344. }
  1345. }
  1346. return path;
  1347. };
  1348. return Tick3D;
  1349. }());
  1350. return Tick3D;
  1351. });
  1352. _registerModule(_modules, 'Core/Axis/Axis3D.js', [_modules['Core/Globals.js'], _modules['Extensions/Math3D.js'], _modules['Core/Axis/Tick.js'], _modules['Core/Axis/Tick3D.js'], _modules['Core/Utilities.js']], function (H, Math3D, Tick, Tick3D, U) {
  1353. /* *
  1354. *
  1355. * (c) 2010-2020 Torstein Honsi
  1356. *
  1357. * Extenstion for 3d axes
  1358. *
  1359. * License: www.highcharts.com/license
  1360. *
  1361. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1362. *
  1363. * */
  1364. var perspective = Math3D.perspective,
  1365. perspective3D = Math3D.perspective3D,
  1366. shapeArea = Math3D.shapeArea;
  1367. var addEvent = U.addEvent,
  1368. merge = U.merge,
  1369. pick = U.pick,
  1370. wrap = U.wrap;
  1371. var deg2rad = H.deg2rad;
  1372. /* eslint-disable valid-jsdoc */
  1373. /**
  1374. * Adds 3D support to axes.
  1375. * @private
  1376. * @class
  1377. */
  1378. var Axis3DAdditions = /** @class */ (function () {
  1379. /* *
  1380. *
  1381. * Constructors
  1382. *
  1383. * */
  1384. /**
  1385. * @private
  1386. */
  1387. function Axis3DAdditions(axis) {
  1388. this.axis = axis;
  1389. }
  1390. /* *
  1391. *
  1392. * Functions
  1393. *
  1394. * */
  1395. /**
  1396. * @private
  1397. * @param {Highcharts.Axis} axis
  1398. * Related axis.
  1399. * @param {Highcharts.Position3dObject} pos
  1400. * Position to fix.
  1401. * @param {boolean} [isTitle]
  1402. * Whether this is a title position.
  1403. * @return {Highcharts.Position3dObject}
  1404. * Fixed position.
  1405. */
  1406. Axis3DAdditions.prototype.fix3dPosition = function (pos, isTitle) {
  1407. var axis3D = this;
  1408. var axis = axis3D.axis;
  1409. var chart = axis.chart;
  1410. // Do not do this if the chart is not 3D
  1411. if (axis.coll === 'colorAxis' ||
  1412. !chart.chart3d ||
  1413. !chart.is3d()) {
  1414. return pos;
  1415. }
  1416. var alpha = deg2rad * chart.options.chart.options3d.alpha,
  1417. beta = deg2rad * chart.options.chart.options3d.beta,
  1418. positionMode = pick(isTitle && axis.options.title.position3d,
  1419. axis.options.labels.position3d),
  1420. skew = pick(isTitle && axis.options.title.skew3d,
  1421. axis.options.labels.skew3d),
  1422. frame = chart.chart3d.frame3d,
  1423. plotLeft = chart.plotLeft,
  1424. plotRight = chart.plotWidth + plotLeft,
  1425. plotTop = chart.plotTop,
  1426. plotBottom = chart.plotHeight + plotTop,
  1427. // Indicates that we are labelling an X or Z axis on the "back" of
  1428. // the chart
  1429. reverseFlap = false,
  1430. offsetX = 0,
  1431. offsetY = 0,
  1432. vecX,
  1433. vecY = { x: 0,
  1434. y: 1,
  1435. z: 0 };
  1436. pos = axis.axis3D.swapZ({ x: pos.x, y: pos.y, z: 0 });
  1437. if (axis.isZAxis) { // Z Axis
  1438. if (axis.opposite) {
  1439. if (frame.axes.z.top === null) {
  1440. return {};
  1441. }
  1442. offsetY = pos.y - plotTop;
  1443. pos.x = frame.axes.z.top.x;
  1444. pos.y = frame.axes.z.top.y;
  1445. vecX = frame.axes.z.top.xDir;
  1446. reverseFlap = !frame.top.frontFacing;
  1447. }
  1448. else {
  1449. if (frame.axes.z.bottom === null) {
  1450. return {};
  1451. }
  1452. offsetY = pos.y - plotBottom;
  1453. pos.x = frame.axes.z.bottom.x;
  1454. pos.y = frame.axes.z.bottom.y;
  1455. vecX = frame.axes.z.bottom.xDir;
  1456. reverseFlap = !frame.bottom.frontFacing;
  1457. }
  1458. }
  1459. else if (axis.horiz) { // X Axis
  1460. if (axis.opposite) {
  1461. if (frame.axes.x.top === null) {
  1462. return {};
  1463. }
  1464. offsetY = pos.y - plotTop;
  1465. pos.y = frame.axes.x.top.y;
  1466. pos.z = frame.axes.x.top.z;
  1467. vecX = frame.axes.x.top.xDir;
  1468. reverseFlap = !frame.top.frontFacing;
  1469. }
  1470. else {
  1471. if (frame.axes.x.bottom === null) {
  1472. return {};
  1473. }
  1474. offsetY = pos.y - plotBottom;
  1475. pos.y = frame.axes.x.bottom.y;
  1476. pos.z = frame.axes.x.bottom.z;
  1477. vecX = frame.axes.x.bottom.xDir;
  1478. reverseFlap = !frame.bottom.frontFacing;
  1479. }
  1480. }
  1481. else { // Y Axis
  1482. if (axis.opposite) {
  1483. if (frame.axes.y.right === null) {
  1484. return {};
  1485. }
  1486. offsetX = pos.x - plotRight;
  1487. pos.x = frame.axes.y.right.x;
  1488. pos.z = frame.axes.y.right.z;
  1489. vecX = frame.axes.y.right.xDir;
  1490. // Rotate 90º on opposite edge
  1491. vecX = { x: vecX.z, y: vecX.y, z: -vecX.x };
  1492. }
  1493. else {
  1494. if (frame.axes.y.left === null) {
  1495. return {};
  1496. }
  1497. offsetX = pos.x - plotLeft;
  1498. pos.x = frame.axes.y.left.x;
  1499. pos.z = frame.axes.y.left.z;
  1500. vecX = frame.axes.y.left.xDir;
  1501. }
  1502. }
  1503. if (positionMode === 'chart') {
  1504. // Labels preserve their direction relative to the chart
  1505. // nothing to do
  1506. }
  1507. else if (positionMode === 'flap') {
  1508. // Labels are rotated around the axis direction to face the screen
  1509. if (!axis.horiz) { // Y Axis
  1510. vecX = { x: Math.cos(beta), y: 0, z: Math.sin(beta) };
  1511. }
  1512. else { // X and Z Axis
  1513. var sin = Math.sin(alpha);
  1514. var cos = Math.cos(alpha);
  1515. if (axis.opposite) {
  1516. sin = -sin;
  1517. }
  1518. if (reverseFlap) {
  1519. sin = -sin;
  1520. }
  1521. vecY = { x: vecX.z * sin, y: cos, z: -vecX.x * sin };
  1522. }
  1523. }
  1524. else if (positionMode === 'ortho') {
  1525. // Labels will be rotated to be ortogonal to the axis
  1526. if (!axis.horiz) { // Y Axis
  1527. vecX = { x: Math.cos(beta), y: 0, z: Math.sin(beta) };
  1528. }
  1529. else { // X and Z Axis
  1530. var sina = Math.sin(alpha);
  1531. var cosa = Math.cos(alpha);
  1532. var sinb = Math.sin(beta);
  1533. var cosb = Math.cos(beta);
  1534. var vecZ = { x: sinb * cosa,
  1535. y: -sina,
  1536. z: -cosa * cosb };
  1537. vecY = {
  1538. x: vecX.y * vecZ.z - vecX.z * vecZ.y,
  1539. y: vecX.z * vecZ.x - vecX.x * vecZ.z,
  1540. z: vecX.x * vecZ.y - vecX.y * vecZ.x
  1541. };
  1542. var scale = 1 / Math.sqrt(vecY.x * vecY.x + vecY.y * vecY.y + vecY.z * vecY.z);
  1543. if (reverseFlap) {
  1544. scale = -scale;
  1545. }
  1546. vecY = { x: scale * vecY.x, y: scale * vecY.y, z: scale * vecY.z };
  1547. }
  1548. }
  1549. else { // positionMode == 'offset'
  1550. // Labels will be skewd to maintain vertical / horizontal offsets
  1551. // from axis
  1552. if (!axis.horiz) { // Y Axis
  1553. vecX = { x: Math.cos(beta), y: 0, z: Math.sin(beta) };
  1554. }
  1555. else { // X and Z Axis
  1556. vecY = {
  1557. x: Math.sin(beta) * Math.sin(alpha),
  1558. y: Math.cos(alpha),
  1559. z: -Math.cos(beta) * Math.sin(alpha)
  1560. };
  1561. }
  1562. }
  1563. pos.x += offsetX * vecX.x + offsetY * vecY.x;
  1564. pos.y += offsetX * vecX.y + offsetY * vecY.y;
  1565. pos.z += offsetX * vecX.z + offsetY * vecY.z;
  1566. var projected = perspective([pos],
  1567. axis.chart)[0];
  1568. if (skew) {
  1569. // Check if the label text would be mirrored
  1570. var isMirrored = shapeArea(perspective([
  1571. pos,
  1572. { x: pos.x + vecX.x,
  1573. y: pos.y + vecX.y,
  1574. z: pos.z + vecX.z },
  1575. { x: pos.x + vecY.x,
  1576. y: pos.y + vecY.y,
  1577. z: pos.z + vecY.z }
  1578. ],
  1579. axis.chart)) < 0;
  1580. if (isMirrored) {
  1581. vecX = { x: -vecX.x, y: -vecX.y, z: -vecX.z };
  1582. }
  1583. var pointsProjected = perspective([
  1584. { x: pos.x,
  1585. y: pos.y,
  1586. z: pos.z },
  1587. { x: pos.x + vecX.x,
  1588. y: pos.y + vecX.y,
  1589. z: pos.z + vecX.z },
  1590. { x: pos.x + vecY.x,
  1591. y: pos.y + vecY.y,
  1592. z: pos.z + vecY.z }
  1593. ],
  1594. axis.chart);
  1595. projected.matrix = [
  1596. pointsProjected[1].x - pointsProjected[0].x,
  1597. pointsProjected[1].y - pointsProjected[0].y,
  1598. pointsProjected[2].x - pointsProjected[0].x,
  1599. pointsProjected[2].y - pointsProjected[0].y,
  1600. projected.x,
  1601. projected.y
  1602. ];
  1603. projected.matrix[4] -= projected.x * projected.matrix[0] +
  1604. projected.y * projected.matrix[2];
  1605. projected.matrix[5] -= projected.x * projected.matrix[1] +
  1606. projected.y * projected.matrix[3];
  1607. }
  1608. return projected;
  1609. };
  1610. /**
  1611. * @private
  1612. */
  1613. Axis3DAdditions.prototype.swapZ = function (p, insidePlotArea) {
  1614. var axis = this.axis;
  1615. if (axis.isZAxis) {
  1616. var plotLeft = insidePlotArea ? 0 : axis.chart.plotLeft;
  1617. return {
  1618. x: plotLeft + p.z,
  1619. y: p.y,
  1620. z: p.x - plotLeft
  1621. };
  1622. }
  1623. return p;
  1624. };
  1625. return Axis3DAdditions;
  1626. }());
  1627. /**
  1628. * Axis with 3D support.
  1629. * @private
  1630. * @class
  1631. */
  1632. var Axis3D = /** @class */ (function () {
  1633. function Axis3D() {
  1634. }
  1635. /* *
  1636. *
  1637. * Static Functions
  1638. *
  1639. * */
  1640. /**
  1641. * Extends axis class with 3D support.
  1642. * @private
  1643. */
  1644. Axis3D.compose = function (AxisClass) {
  1645. merge(true, AxisClass.defaultOptions, Axis3D.defaultOptions);
  1646. AxisClass.keepProps.push('axis3D');
  1647. addEvent(AxisClass, 'init', Axis3D.onInit);
  1648. addEvent(AxisClass, 'afterSetOptions', Axis3D.onAfterSetOptions);
  1649. addEvent(AxisClass, 'drawCrosshair', Axis3D.onDrawCrosshair);
  1650. addEvent(AxisClass, 'destroy', Axis3D.onDestroy);
  1651. var axisProto = AxisClass.prototype;
  1652. wrap(axisProto, 'getLinePath', Axis3D.wrapGetLinePath);
  1653. wrap(axisProto, 'getPlotBandPath', Axis3D.wrapGetPlotBandPath);
  1654. wrap(axisProto, 'getPlotLinePath', Axis3D.wrapGetPlotLinePath);
  1655. wrap(axisProto, 'getSlotWidth', Axis3D.wrapGetSlotWidth);
  1656. wrap(axisProto, 'getTitlePosition', Axis3D.wrapGetTitlePosition);
  1657. Tick3D.compose(Tick);
  1658. };
  1659. /**
  1660. * @private
  1661. */
  1662. Axis3D.onAfterSetOptions = function () {
  1663. var axis = this;
  1664. var chart = axis.chart;
  1665. var options = axis.options;
  1666. if (chart.is3d && chart.is3d() && axis.coll !== 'colorAxis') {
  1667. options.tickWidth = pick(options.tickWidth, 0);
  1668. options.gridLineWidth = pick(options.gridLineWidth, 1);
  1669. }
  1670. };
  1671. /**
  1672. * @private
  1673. */
  1674. Axis3D.onDestroy = function () {
  1675. ['backFrame', 'bottomFrame', 'sideFrame'].forEach(function (prop) {
  1676. if (this[prop]) {
  1677. this[prop] = this[prop].destroy();
  1678. }
  1679. }, this);
  1680. };
  1681. /**
  1682. * @private
  1683. */
  1684. Axis3D.onDrawCrosshair = function (e) {
  1685. var axis = this;
  1686. if (axis.chart.is3d() &&
  1687. axis.coll !== 'colorAxis') {
  1688. if (e.point) {
  1689. e.point.crosshairPos = axis.isXAxis ?
  1690. e.point.axisXpos :
  1691. axis.len - e.point.axisYpos;
  1692. }
  1693. }
  1694. };
  1695. /**
  1696. * @private
  1697. */
  1698. Axis3D.onInit = function () {
  1699. var axis = this;
  1700. if (!axis.axis3D) {
  1701. axis.axis3D = new Axis3DAdditions(axis);
  1702. }
  1703. };
  1704. /**
  1705. * Do not draw axislines in 3D.
  1706. * @private
  1707. */
  1708. Axis3D.wrapGetLinePath = function (proceed) {
  1709. var axis = this;
  1710. // Do not do this if the chart is not 3D
  1711. if (!axis.chart.is3d() || axis.coll === 'colorAxis') {
  1712. return proceed.apply(axis, [].slice.call(arguments, 1));
  1713. }
  1714. return [];
  1715. };
  1716. /**
  1717. * @private
  1718. */
  1719. Axis3D.wrapGetPlotBandPath = function (proceed) {
  1720. // Do not do this if the chart is not 3D
  1721. if (!this.chart.is3d() || this.coll === 'colorAxis') {
  1722. return proceed.apply(this, [].slice.call(arguments, 1));
  1723. }
  1724. var args = arguments,
  1725. from = args[1],
  1726. to = args[2],
  1727. path = [],
  1728. fromPath = this.getPlotLinePath({ value: from }),
  1729. toPath = this.getPlotLinePath({ value: to });
  1730. if (fromPath && toPath) {
  1731. for (var i = 0; i < fromPath.length; i += 2) {
  1732. var fromStartSeg = fromPath[i],
  1733. fromEndSeg = fromPath[i + 1],
  1734. toStartSeg = toPath[i],
  1735. toEndSeg = toPath[i + 1];
  1736. if (fromStartSeg[0] === 'M' &&
  1737. fromEndSeg[0] === 'L' &&
  1738. toStartSeg[0] === 'M' &&
  1739. toEndSeg[0] === 'L') {
  1740. path.push(fromStartSeg, fromEndSeg, toEndSeg,
  1741. // lineTo instead of moveTo
  1742. ['L', toStartSeg[1], toStartSeg[2]], ['Z']);
  1743. }
  1744. }
  1745. }
  1746. return path;
  1747. };
  1748. /**
  1749. * @private
  1750. */
  1751. Axis3D.wrapGetPlotLinePath = function (proceed) {
  1752. var axis = this;
  1753. var axis3D = axis.axis3D;
  1754. var chart = axis.chart;
  1755. var path = proceed.apply(axis,
  1756. [].slice.call(arguments, 1));
  1757. // Do not do this if the chart is not 3D
  1758. if (axis.coll === 'colorAxis' ||
  1759. !chart.chart3d ||
  1760. !chart.is3d()) {
  1761. return path;
  1762. }
  1763. if (path === null) {
  1764. return path;
  1765. }
  1766. var options3d = chart.options.chart.options3d,
  1767. d = axis.isZAxis ? chart.plotWidth : options3d.depth,
  1768. frame = chart.chart3d.frame3d,
  1769. startSegment = path[0],
  1770. endSegment = path[1],
  1771. pArr,
  1772. pathSegments = [];
  1773. if (startSegment[0] === 'M' && endSegment[0] === 'L') {
  1774. pArr = [
  1775. axis3D.swapZ({ x: startSegment[1], y: startSegment[2], z: 0 }),
  1776. axis3D.swapZ({ x: startSegment[1], y: startSegment[2], z: d }),
  1777. axis3D.swapZ({ x: endSegment[1], y: endSegment[2], z: 0 }),
  1778. axis3D.swapZ({ x: endSegment[1], y: endSegment[2], z: d })
  1779. ];
  1780. if (!this.horiz) { // Y-Axis
  1781. if (frame.front.visible) {
  1782. pathSegments.push(pArr[0], pArr[2]);
  1783. }
  1784. if (frame.back.visible) {
  1785. pathSegments.push(pArr[1], pArr[3]);
  1786. }
  1787. if (frame.left.visible) {
  1788. pathSegments.push(pArr[0], pArr[1]);
  1789. }
  1790. if (frame.right.visible) {
  1791. pathSegments.push(pArr[2], pArr[3]);
  1792. }
  1793. }
  1794. else if (this.isZAxis) { // Z-Axis
  1795. if (frame.left.visible) {
  1796. pathSegments.push(pArr[0], pArr[2]);
  1797. }
  1798. if (frame.right.visible) {
  1799. pathSegments.push(pArr[1], pArr[3]);
  1800. }
  1801. if (frame.top.visible) {
  1802. pathSegments.push(pArr[0], pArr[1]);
  1803. }
  1804. if (frame.bottom.visible) {
  1805. pathSegments.push(pArr[2], pArr[3]);
  1806. }
  1807. }
  1808. else { // X-Axis
  1809. if (frame.front.visible) {
  1810. pathSegments.push(pArr[0], pArr[2]);
  1811. }
  1812. if (frame.back.visible) {
  1813. pathSegments.push(pArr[1], pArr[3]);
  1814. }
  1815. if (frame.top.visible) {
  1816. pathSegments.push(pArr[0], pArr[1]);
  1817. }
  1818. if (frame.bottom.visible) {
  1819. pathSegments.push(pArr[2], pArr[3]);
  1820. }
  1821. }
  1822. pathSegments = perspective(pathSegments, this.chart, false);
  1823. }
  1824. return chart.renderer.toLineSegments(pathSegments);
  1825. };
  1826. /**
  1827. * Wrap getSlotWidth function to calculate individual width value for each
  1828. * slot (#8042).
  1829. * @private
  1830. */
  1831. Axis3D.wrapGetSlotWidth = function (proceed, tick) {
  1832. var axis = this;
  1833. var chart = axis.chart;
  1834. var ticks = axis.ticks;
  1835. var gridGroup = axis.gridGroup;
  1836. if (axis.categories &&
  1837. chart.frameShapes &&
  1838. chart.is3d() &&
  1839. gridGroup &&
  1840. tick &&
  1841. tick.label) {
  1842. var firstGridLine = gridGroup.element.childNodes[0].getBBox(),
  1843. frame3DLeft = chart.frameShapes.left.getBBox(),
  1844. options3d = chart.options.chart.options3d,
  1845. origin = {
  1846. x: chart.plotWidth / 2,
  1847. y: chart.plotHeight / 2,
  1848. z: options3d.depth / 2,
  1849. vd: pick(options3d.depth, 1) * pick(options3d.viewDistance, 0)
  1850. },
  1851. labelPos,
  1852. prevLabelPos,
  1853. nextLabelPos,
  1854. slotWidth,
  1855. tickId = tick.pos,
  1856. prevTick = ticks[tickId - 1],
  1857. nextTick = ticks[tickId + 1];
  1858. // Check whether the tick is not the first one and previous tick
  1859. // exists, then calculate position of previous label.
  1860. if (tickId !== 0 && prevTick && prevTick.label.xy) {
  1861. prevLabelPos = perspective3D({
  1862. x: prevTick.label.xy.x,
  1863. y: prevTick.label.xy.y,
  1864. z: null
  1865. }, origin, origin.vd);
  1866. }
  1867. // If next label position is defined, then recalculate its position
  1868. // basing on the perspective.
  1869. if (nextTick && nextTick.label.xy) {
  1870. nextLabelPos = perspective3D({
  1871. x: nextTick.label.xy.x,
  1872. y: nextTick.label.xy.y,
  1873. z: null
  1874. }, origin, origin.vd);
  1875. }
  1876. labelPos = {
  1877. x: tick.label.xy.x,
  1878. y: tick.label.xy.y,
  1879. z: null
  1880. };
  1881. labelPos = perspective3D(labelPos, origin, origin.vd);
  1882. // If tick is first one, check whether next label position is
  1883. // already calculated, then return difference between the first and
  1884. // the second label. If there is no next label position calculated,
  1885. // return the difference between the first grid line and left 3d
  1886. // frame.
  1887. slotWidth = Math.abs(prevLabelPos ?
  1888. labelPos.x - prevLabelPos.x : nextLabelPos ?
  1889. nextLabelPos.x - labelPos.x :
  1890. firstGridLine.x - frame3DLeft.x);
  1891. return slotWidth;
  1892. }
  1893. return proceed.apply(axis, [].slice.call(arguments, 1));
  1894. };
  1895. /**
  1896. * @private
  1897. */
  1898. Axis3D.wrapGetTitlePosition = function (proceed) {
  1899. var pos = proceed.apply(this,
  1900. [].slice.call(arguments, 1));
  1901. return this.axis3D ?
  1902. this.axis3D.fix3dPosition(pos, true) :
  1903. pos;
  1904. };
  1905. /* *
  1906. *
  1907. * Static Properties
  1908. *
  1909. * */
  1910. /**
  1911. * @optionparent xAxis
  1912. */
  1913. Axis3D.defaultOptions = {
  1914. labels: {
  1915. /**
  1916. * Defines how the labels are be repositioned according to the 3D
  1917. * chart orientation.
  1918. *
  1919. * - `'offset'`: Maintain a fixed horizontal/vertical distance from
  1920. * the tick marks, despite the chart orientation. This is the
  1921. * backwards compatible behavior, and causes skewing of X and Z
  1922. * axes.
  1923. *
  1924. * - `'chart'`: Preserve 3D position relative to the chart. This
  1925. * looks nice, but hard to read if the text isn't forward-facing.
  1926. *
  1927. * - `'flap'`: Rotated text along the axis to compensate for the
  1928. * chart orientation. This tries to maintain text as legible as
  1929. * possible on all orientations.
  1930. *
  1931. * - `'ortho'`: Rotated text along the axis direction so that the
  1932. * labels are orthogonal to the axis. This is very similar to
  1933. * `'flap'`, but prevents skewing the labels (X and Y scaling are
  1934. * still present).
  1935. *
  1936. * @sample highcharts/3d/skewed-labels/
  1937. * Skewed labels
  1938. *
  1939. * @since 5.0.15
  1940. * @validvalue ['offset', 'chart', 'flap', 'ortho']
  1941. * @product highcharts
  1942. * @requires highcharts-3d
  1943. */
  1944. position3d: 'offset',
  1945. /**
  1946. * If enabled, the axis labels will skewed to follow the
  1947. * perspective.
  1948. *
  1949. * This will fix overlapping labels and titles, but texts become
  1950. * less legible due to the distortion.
  1951. *
  1952. * The final appearance depends heavily on `labels.position3d`.
  1953. *
  1954. * @sample highcharts/3d/skewed-labels/
  1955. * Skewed labels
  1956. *
  1957. * @since 5.0.15
  1958. * @product highcharts
  1959. * @requires highcharts-3d
  1960. */
  1961. skew3d: false
  1962. },
  1963. title: {
  1964. /**
  1965. * Defines how the title is repositioned according to the 3D chart
  1966. * orientation.
  1967. *
  1968. * - `'offset'`: Maintain a fixed horizontal/vertical distance from
  1969. * the tick marks, despite the chart orientation. This is the
  1970. * backwards compatible behavior, and causes skewing of X and Z
  1971. * axes.
  1972. *
  1973. * - `'chart'`: Preserve 3D position relative to the chart. This
  1974. * looks nice, but hard to read if the text isn't forward-facing.
  1975. *
  1976. * - `'flap'`: Rotated text along the axis to compensate for the
  1977. * chart orientation. This tries to maintain text as legible as
  1978. * possible on all orientations.
  1979. *
  1980. * - `'ortho'`: Rotated text along the axis direction so that the
  1981. * labels are orthogonal to the axis. This is very similar to
  1982. * `'flap'`, but prevents skewing the labels (X and Y scaling are
  1983. * still present).
  1984. *
  1985. * - `undefined`: Will use the config from `labels.position3d`
  1986. *
  1987. * @sample highcharts/3d/skewed-labels/
  1988. * Skewed labels
  1989. *
  1990. * @type {"offset"|"chart"|"flap"|"ortho"|null}
  1991. * @since 5.0.15
  1992. * @product highcharts
  1993. * @requires highcharts-3d
  1994. */
  1995. position3d: null,
  1996. /**
  1997. * If enabled, the axis title will skewed to follow the perspective.
  1998. *
  1999. * This will fix overlapping labels and titles, but texts become
  2000. * less legible due to the distortion.
  2001. *
  2002. * The final appearance depends heavily on `title.position3d`.
  2003. *
  2004. * A `null` value will use the config from `labels.skew3d`.
  2005. *
  2006. * @sample highcharts/3d/skewed-labels/
  2007. * Skewed labels
  2008. *
  2009. * @type {boolean|null}
  2010. * @since 5.0.15
  2011. * @product highcharts
  2012. * @requires highcharts-3d
  2013. */
  2014. skew3d: null
  2015. }
  2016. };
  2017. return Axis3D;
  2018. }());
  2019. return Axis3D;
  2020. });
  2021. _registerModule(_modules, 'Core/Axis/ZAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Utilities.js']], function (Axis, U) {
  2022. /* *
  2023. *
  2024. * (c) 2010-2020 Torstein Honsi
  2025. *
  2026. * License: www.highcharts.com/license
  2027. *
  2028. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2029. *
  2030. * */
  2031. var __extends = (this && this.__extends) || (function () {
  2032. var extendStatics = function (d,
  2033. b) {
  2034. extendStatics = Object.setPrototypeOf ||
  2035. ({ __proto__: [] } instanceof Array && function (d,
  2036. b) { d.__proto__ = b; }) ||
  2037. function (d,
  2038. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2039. return extendStatics(d, b);
  2040. };
  2041. return function (d, b) {
  2042. extendStatics(d, b);
  2043. function __() { this.constructor = d; }
  2044. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2045. };
  2046. })();
  2047. var addEvent = U.addEvent,
  2048. merge = U.merge,
  2049. pick = U.pick,
  2050. splat = U.splat;
  2051. /* eslint-disable valid-jsdoc */
  2052. /**
  2053. * 3D chart with support of z coordinates.
  2054. * @private
  2055. * @class
  2056. */
  2057. var ZChart = /** @class */ (function () {
  2058. function ZChart() {
  2059. }
  2060. /* *
  2061. *
  2062. * Static Functions
  2063. *
  2064. * */
  2065. ZChart.compose = function (ChartClass) {
  2066. addEvent(ChartClass, 'afterGetAxes', ZChart.onAfterGetAxes);
  2067. var chartProto = ChartClass.prototype;
  2068. chartProto.addZAxis = ZChart.wrapAddZAxis;
  2069. chartProto.collectionsWithInit.zAxis = [chartProto.addZAxis];
  2070. chartProto.collectionsWithUpdate.push('zAxis');
  2071. };
  2072. /**
  2073. * Get the Z axis in addition to the default X and Y.
  2074. * @private
  2075. */
  2076. ZChart.onAfterGetAxes = function () {
  2077. var chart = this;
  2078. var options = this.options;
  2079. var zAxisOptions = options.zAxis = splat(options.zAxis || {});
  2080. if (!chart.is3d()) {
  2081. return;
  2082. }
  2083. chart.zAxis = [];
  2084. zAxisOptions.forEach(function (axisOptions, i) {
  2085. axisOptions.index = i;
  2086. // Z-Axis is shown horizontally, so it's kind of a X-Axis
  2087. axisOptions.isX = true;
  2088. chart
  2089. .addZAxis(axisOptions)
  2090. .setScale();
  2091. });
  2092. };
  2093. /**
  2094. * @private
  2095. */
  2096. ZChart.wrapAddZAxis = function (options) {
  2097. return new ZAxis(this, options);
  2098. };
  2099. return ZChart;
  2100. }());
  2101. /**
  2102. * 3D axis for z coordinates.
  2103. */
  2104. var ZAxis = /** @class */ (function (_super) {
  2105. __extends(ZAxis, _super);
  2106. /* *
  2107. *
  2108. * Constructors
  2109. *
  2110. * */
  2111. function ZAxis(chart, userOptions) {
  2112. var _this = _super.call(this,
  2113. chart,
  2114. userOptions) || this;
  2115. _this.isZAxis = true;
  2116. return _this;
  2117. }
  2118. /* *
  2119. *
  2120. * Functions
  2121. *
  2122. * */
  2123. ZAxis.prototype.getSeriesExtremes = function () {
  2124. var axis = this;
  2125. var chart = axis.chart;
  2126. axis.hasVisibleSeries = false;
  2127. // Reset properties in case we're redrawing (#3353)
  2128. axis.dataMin = axis.dataMax = axis.ignoreMinPadding = axis.ignoreMaxPadding = void 0;
  2129. if (axis.stacking) {
  2130. axis.stacking.buildStacks();
  2131. }
  2132. // loop through this axis' series
  2133. axis.series.forEach(function (series) {
  2134. if (series.visible ||
  2135. !(chart.options.chart &&
  2136. chart.options.chart.ignoreHiddenSeries)) {
  2137. var seriesOptions = series.options,
  2138. zData,
  2139. threshold = seriesOptions.threshold;
  2140. axis.hasVisibleSeries = true;
  2141. // Validate threshold in logarithmic axes
  2142. if (axis.positiveValuesOnly && threshold <= 0) {
  2143. threshold = void 0;
  2144. }
  2145. zData = series.zData;
  2146. if (zData.length) {
  2147. axis.dataMin = Math.min(pick(axis.dataMin, zData[0]), Math.min.apply(null, zData));
  2148. axis.dataMax = Math.max(pick(axis.dataMax, zData[0]), Math.max.apply(null, zData));
  2149. }
  2150. }
  2151. });
  2152. };
  2153. /**
  2154. * @private
  2155. */
  2156. ZAxis.prototype.setAxisSize = function () {
  2157. var axis = this;
  2158. var chart = axis.chart;
  2159. _super.prototype.setAxisSize.call(this);
  2160. axis.width = axis.len = (chart.options.chart &&
  2161. chart.options.chart.options3d &&
  2162. chart.options.chart.options3d.depth) || 0;
  2163. axis.right = chart.chartWidth - axis.width - axis.left;
  2164. };
  2165. /**
  2166. * @private
  2167. */
  2168. ZAxis.prototype.setOptions = function (userOptions) {
  2169. userOptions = merge({
  2170. offset: 0,
  2171. lineWidth: 0
  2172. }, userOptions);
  2173. _super.prototype.setOptions.call(this, userOptions);
  2174. this.coll = 'zAxis';
  2175. };
  2176. /* *
  2177. *
  2178. * Static Properties
  2179. *
  2180. * */
  2181. ZAxis.ZChartComposition = ZChart;
  2182. return ZAxis;
  2183. }(Axis));
  2184. return ZAxis;
  2185. });
  2186. _registerModule(_modules, 'Core/Chart/Chart3D.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Axis/Axis3D.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Animation/Fx.js'], _modules['Core/Globals.js'], _modules['Extensions/Math3D.js'], _modules['Core/Options.js'], _modules['Core/Utilities.js'], _modules['Core/Axis/ZAxis.js']], function (Axis, Axis3D, Chart, Fx, H, Math3D, O, U, ZAxis) {
  2187. /* *
  2188. *
  2189. * (c) 2010-2020 Torstein Honsi
  2190. *
  2191. * Extension for 3D charts
  2192. *
  2193. * License: www.highcharts.com/license
  2194. *
  2195. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2196. *
  2197. * */
  2198. var perspective = Math3D.perspective,
  2199. shapeArea3D = Math3D.shapeArea3D;
  2200. var genericDefaultOptions = O.defaultOptions;
  2201. var addEvent = U.addEvent,
  2202. isArray = U.isArray,
  2203. merge = U.merge,
  2204. pick = U.pick,
  2205. wrap = U.wrap;
  2206. var Chart3D;
  2207. (function (Chart3D) {
  2208. /* *
  2209. *
  2210. * Interfaces
  2211. *
  2212. * */
  2213. /* *
  2214. *
  2215. * Classes
  2216. *
  2217. * */
  2218. var Composition = /** @class */ (function () {
  2219. /* *
  2220. *
  2221. * Constructors
  2222. *
  2223. * */
  2224. /**
  2225. * @private
  2226. */
  2227. function Composition(chart) {
  2228. this.frame3d = void 0;
  2229. this.chart = chart;
  2230. }
  2231. /* *
  2232. *
  2233. * Functions
  2234. *
  2235. * */
  2236. Composition.prototype.get3dFrame = function () {
  2237. var chart = this.chart,
  2238. options3d = chart.options.chart.options3d,
  2239. frameOptions = options3d.frame,
  2240. xm = chart.plotLeft,
  2241. xp = chart.plotLeft + chart.plotWidth,
  2242. ym = chart.plotTop,
  2243. yp = chart.plotTop + chart.plotHeight,
  2244. zm = 0,
  2245. zp = options3d.depth,
  2246. faceOrientation = function (vertexes) {
  2247. var area = shapeArea3D(vertexes,
  2248. chart);
  2249. // Give it 0.5 squared-pixel as a margin for rounding errors
  2250. if (area > 0.5) {
  2251. return 1;
  2252. }
  2253. if (area < -0.5) {
  2254. return -1;
  2255. }
  2256. return 0;
  2257. }, bottomOrientation = faceOrientation([
  2258. { x: xm, y: yp, z: zp },
  2259. { x: xp, y: yp, z: zp },
  2260. { x: xp, y: yp, z: zm },
  2261. { x: xm, y: yp, z: zm }
  2262. ]), topOrientation = faceOrientation([
  2263. { x: xm, y: ym, z: zm },
  2264. { x: xp, y: ym, z: zm },
  2265. { x: xp, y: ym, z: zp },
  2266. { x: xm, y: ym, z: zp }
  2267. ]), leftOrientation = faceOrientation([
  2268. { x: xm, y: ym, z: zm },
  2269. { x: xm, y: ym, z: zp },
  2270. { x: xm, y: yp, z: zp },
  2271. { x: xm, y: yp, z: zm }
  2272. ]), rightOrientation = faceOrientation([
  2273. { x: xp, y: ym, z: zp },
  2274. { x: xp, y: ym, z: zm },
  2275. { x: xp, y: yp, z: zm },
  2276. { x: xp, y: yp, z: zp }
  2277. ]), frontOrientation = faceOrientation([
  2278. { x: xm, y: yp, z: zm },
  2279. { x: xp, y: yp, z: zm },
  2280. { x: xp, y: ym, z: zm },
  2281. { x: xm, y: ym, z: zm }
  2282. ]), backOrientation = faceOrientation([
  2283. { x: xm, y: ym, z: zp },
  2284. { x: xp, y: ym, z: zp },
  2285. { x: xp, y: yp, z: zp },
  2286. { x: xm, y: yp, z: zp }
  2287. ]), defaultShowBottom = false, defaultShowTop = false, defaultShowLeft = false, defaultShowRight = false, defaultShowFront = false, defaultShowBack = true;
  2288. // The 'default' criteria to visible faces of the frame is looking
  2289. // up every axis to decide whenever the left/right//top/bottom sides
  2290. // of the frame will be shown
  2291. []
  2292. .concat(chart.xAxis, chart.yAxis, chart.zAxis)
  2293. .forEach(function (axis) {
  2294. if (axis) {
  2295. if (axis.horiz) {
  2296. if (axis.opposite) {
  2297. defaultShowTop = true;
  2298. }
  2299. else {
  2300. defaultShowBottom = true;
  2301. }
  2302. }
  2303. else {
  2304. if (axis.opposite) {
  2305. defaultShowRight = true;
  2306. }
  2307. else {
  2308. defaultShowLeft = true;
  2309. }
  2310. }
  2311. }
  2312. });
  2313. var getFaceOptions = function (sources, faceOrientation, defaultVisible) {
  2314. var faceAttrs = ['size', 'color', 'visible'];
  2315. var options = {};
  2316. for (var i = 0; i < faceAttrs.length; i++) {
  2317. var attr = faceAttrs[i];
  2318. for (var j = 0; j < sources.length; j++) {
  2319. if (typeof sources[j] === 'object') {
  2320. var val = sources[j][attr];
  2321. if (typeof val !== 'undefined' && val !== null) {
  2322. options[attr] = val;
  2323. break;
  2324. }
  2325. }
  2326. }
  2327. }
  2328. var isVisible = defaultVisible;
  2329. if (options.visible === true || options.visible === false) {
  2330. isVisible = options.visible;
  2331. }
  2332. else if (options.visible === 'auto') {
  2333. isVisible = faceOrientation > 0;
  2334. }
  2335. return {
  2336. size: pick(options.size, 1),
  2337. color: pick(options.color, 'none'),
  2338. frontFacing: faceOrientation > 0,
  2339. visible: isVisible
  2340. };
  2341. };
  2342. // docs @TODO: Add all frame options (left, right, top, bottom,
  2343. // front, back) to apioptions JSDoc once the new system is up.
  2344. var ret = {
  2345. axes: {},
  2346. // FIXME: Previously, left/right, top/bottom and front/back
  2347. // pairs shared size and color.
  2348. // For compatibility and consistency sake, when one face have
  2349. // size/color/visibility set, the opposite face will default to
  2350. // the same values. Also, left/right used to be called 'side',
  2351. // so that's also added as a fallback.
  2352. bottom: getFaceOptions([frameOptions.bottom,
  2353. frameOptions.top,
  2354. frameOptions],
  2355. bottomOrientation,
  2356. defaultShowBottom),
  2357. top: getFaceOptions([frameOptions.top,
  2358. frameOptions.bottom,
  2359. frameOptions],
  2360. topOrientation,
  2361. defaultShowTop),
  2362. left: getFaceOptions([
  2363. frameOptions.left,
  2364. frameOptions.right,
  2365. frameOptions.side,
  2366. frameOptions
  2367. ],
  2368. leftOrientation,
  2369. defaultShowLeft),
  2370. right: getFaceOptions([
  2371. frameOptions.right,
  2372. frameOptions.left,
  2373. frameOptions.side,
  2374. frameOptions
  2375. ],
  2376. rightOrientation,
  2377. defaultShowRight),
  2378. back: getFaceOptions([frameOptions.back,
  2379. frameOptions.front,
  2380. frameOptions],
  2381. backOrientation,
  2382. defaultShowBack),
  2383. front: getFaceOptions([frameOptions.front,
  2384. frameOptions.back,
  2385. frameOptions],
  2386. frontOrientation,
  2387. defaultShowFront)
  2388. };
  2389. // Decide the bast place to put axis title/labels based on the
  2390. // visible faces. Ideally, The labels can only be on the edge
  2391. // between a visible face and an invisble one. Also, the Y label
  2392. // should be one the left-most edge (right-most if opposite).
  2393. if (options3d.axisLabelPosition === 'auto') {
  2394. var isValidEdge = function (face1,
  2395. face2) {
  2396. return ((face1.visible !== face2.visible) ||
  2397. (face1.visible &&
  2398. face2.visible &&
  2399. (face1.frontFacing !== face2.frontFacing)));
  2400. };
  2401. var yEdges = [];
  2402. if (isValidEdge(ret.left, ret.front)) {
  2403. yEdges.push({
  2404. y: (ym + yp) / 2,
  2405. x: xm,
  2406. z: zm,
  2407. xDir: { x: 1, y: 0, z: 0 }
  2408. });
  2409. }
  2410. if (isValidEdge(ret.left, ret.back)) {
  2411. yEdges.push({
  2412. y: (ym + yp) / 2,
  2413. x: xm,
  2414. z: zp,
  2415. xDir: { x: 0, y: 0, z: -1 }
  2416. });
  2417. }
  2418. if (isValidEdge(ret.right, ret.front)) {
  2419. yEdges.push({
  2420. y: (ym + yp) / 2,
  2421. x: xp,
  2422. z: zm,
  2423. xDir: { x: 0, y: 0, z: 1 }
  2424. });
  2425. }
  2426. if (isValidEdge(ret.right, ret.back)) {
  2427. yEdges.push({
  2428. y: (ym + yp) / 2,
  2429. x: xp,
  2430. z: zp,
  2431. xDir: { x: -1, y: 0, z: 0 }
  2432. });
  2433. }
  2434. var xBottomEdges = [];
  2435. if (isValidEdge(ret.bottom, ret.front)) {
  2436. xBottomEdges.push({
  2437. x: (xm + xp) / 2,
  2438. y: yp,
  2439. z: zm,
  2440. xDir: { x: 1, y: 0, z: 0 }
  2441. });
  2442. }
  2443. if (isValidEdge(ret.bottom, ret.back)) {
  2444. xBottomEdges.push({
  2445. x: (xm + xp) / 2,
  2446. y: yp,
  2447. z: zp,
  2448. xDir: { x: -1, y: 0, z: 0 }
  2449. });
  2450. }
  2451. var xTopEdges = [];
  2452. if (isValidEdge(ret.top, ret.front)) {
  2453. xTopEdges.push({
  2454. x: (xm + xp) / 2,
  2455. y: ym,
  2456. z: zm,
  2457. xDir: { x: 1, y: 0, z: 0 }
  2458. });
  2459. }
  2460. if (isValidEdge(ret.top, ret.back)) {
  2461. xTopEdges.push({
  2462. x: (xm + xp) / 2,
  2463. y: ym,
  2464. z: zp,
  2465. xDir: { x: -1, y: 0, z: 0 }
  2466. });
  2467. }
  2468. var zBottomEdges = [];
  2469. if (isValidEdge(ret.bottom, ret.left)) {
  2470. zBottomEdges.push({
  2471. z: (zm + zp) / 2,
  2472. y: yp,
  2473. x: xm,
  2474. xDir: { x: 0, y: 0, z: -1 }
  2475. });
  2476. }
  2477. if (isValidEdge(ret.bottom, ret.right)) {
  2478. zBottomEdges.push({
  2479. z: (zm + zp) / 2,
  2480. y: yp,
  2481. x: xp,
  2482. xDir: { x: 0, y: 0, z: 1 }
  2483. });
  2484. }
  2485. var zTopEdges = [];
  2486. if (isValidEdge(ret.top, ret.left)) {
  2487. zTopEdges.push({
  2488. z: (zm + zp) / 2,
  2489. y: ym,
  2490. x: xm,
  2491. xDir: { x: 0, y: 0, z: -1 }
  2492. });
  2493. }
  2494. if (isValidEdge(ret.top, ret.right)) {
  2495. zTopEdges.push({
  2496. z: (zm + zp) / 2,
  2497. y: ym,
  2498. x: xp,
  2499. xDir: { x: 0, y: 0, z: 1 }
  2500. });
  2501. }
  2502. var pickEdge = function (edges,
  2503. axis,
  2504. mult) {
  2505. if (edges.length === 0) {
  2506. return null;
  2507. }
  2508. if (edges.length === 1) {
  2509. return edges[0];
  2510. }
  2511. var best = 0,
  2512. projections = perspective(edges,
  2513. chart,
  2514. false);
  2515. for (var i = 1; i < projections.length; i++) {
  2516. if (mult * projections[i][axis] >
  2517. mult * projections[best][axis]) {
  2518. best = i;
  2519. }
  2520. else if ((mult * projections[i][axis] ===
  2521. mult * projections[best][axis]) &&
  2522. (projections[i].z < projections[best].z)) {
  2523. best = i;
  2524. }
  2525. }
  2526. return edges[best];
  2527. };
  2528. ret.axes = {
  2529. y: {
  2530. 'left': pickEdge(yEdges, 'x', -1),
  2531. 'right': pickEdge(yEdges, 'x', +1)
  2532. },
  2533. x: {
  2534. 'top': pickEdge(xTopEdges, 'y', -1),
  2535. 'bottom': pickEdge(xBottomEdges, 'y', +1)
  2536. },
  2537. z: {
  2538. 'top': pickEdge(zTopEdges, 'y', -1),
  2539. 'bottom': pickEdge(zBottomEdges, 'y', +1)
  2540. }
  2541. };
  2542. }
  2543. else {
  2544. ret.axes = {
  2545. y: {
  2546. 'left': { x: xm, z: zm, xDir: { x: 1, y: 0, z: 0 } },
  2547. 'right': { x: xp, z: zm, xDir: { x: 0, y: 0, z: 1 } }
  2548. },
  2549. x: {
  2550. 'top': { y: ym, z: zm, xDir: { x: 1, y: 0, z: 0 } },
  2551. 'bottom': { y: yp, z: zm, xDir: { x: 1, y: 0, z: 0 } }
  2552. },
  2553. z: {
  2554. 'top': {
  2555. x: defaultShowLeft ? xp : xm,
  2556. y: ym,
  2557. xDir: defaultShowLeft ?
  2558. { x: 0, y: 0, z: 1 } :
  2559. { x: 0, y: 0, z: -1 }
  2560. },
  2561. 'bottom': {
  2562. x: defaultShowLeft ? xp : xm,
  2563. y: yp,
  2564. xDir: defaultShowLeft ?
  2565. { x: 0, y: 0, z: 1 } :
  2566. { x: 0, y: 0, z: -1 }
  2567. }
  2568. }
  2569. };
  2570. }
  2571. return ret;
  2572. };
  2573. /**
  2574. * Calculate scale of the 3D view. That is required to fit chart's 3D
  2575. * projection into the actual plotting area. Reported as #4933.
  2576. *
  2577. * @notice
  2578. * This function should ideally take the plot values instead of a chart
  2579. * object, but since the chart object is needed for perspective it is
  2580. * not practical. Possible to make both getScale and perspective more
  2581. * logical and also immutable.
  2582. *
  2583. * @private
  2584. * @function getScale
  2585. *
  2586. * @param {number} depth
  2587. * The depth of the chart
  2588. *
  2589. * @return {number}
  2590. * The scale to fit the 3D chart into the plotting area.
  2591. *
  2592. * @requires highcharts-3d
  2593. */
  2594. Composition.prototype.getScale = function (depth) {
  2595. var chart = this.chart,
  2596. plotLeft = chart.plotLeft,
  2597. plotRight = chart.plotWidth + plotLeft,
  2598. plotTop = chart.plotTop,
  2599. plotBottom = chart.plotHeight + plotTop,
  2600. originX = plotLeft + chart.plotWidth / 2,
  2601. originY = plotTop + chart.plotHeight / 2,
  2602. bbox3d = {
  2603. minX: Number.MAX_VALUE,
  2604. maxX: -Number.MAX_VALUE,
  2605. minY: Number.MAX_VALUE,
  2606. maxY: -Number.MAX_VALUE
  2607. },
  2608. corners,
  2609. scale = 1;
  2610. // Top left corners:
  2611. corners = [{
  2612. x: plotLeft,
  2613. y: plotTop,
  2614. z: 0
  2615. }, {
  2616. x: plotLeft,
  2617. y: plotTop,
  2618. z: depth
  2619. }];
  2620. // Top right corners:
  2621. [0, 1].forEach(function (i) {
  2622. corners.push({
  2623. x: plotRight,
  2624. y: corners[i].y,
  2625. z: corners[i].z
  2626. });
  2627. });
  2628. // All bottom corners:
  2629. [0, 1, 2, 3].forEach(function (i) {
  2630. corners.push({
  2631. x: corners[i].x,
  2632. y: plotBottom,
  2633. z: corners[i].z
  2634. });
  2635. });
  2636. // Calculate 3D corners:
  2637. corners = perspective(corners, chart, false);
  2638. // Get bounding box of 3D element:
  2639. corners.forEach(function (corner) {
  2640. bbox3d.minX = Math.min(bbox3d.minX, corner.x);
  2641. bbox3d.maxX = Math.max(bbox3d.maxX, corner.x);
  2642. bbox3d.minY = Math.min(bbox3d.minY, corner.y);
  2643. bbox3d.maxY = Math.max(bbox3d.maxY, corner.y);
  2644. });
  2645. // Left edge:
  2646. if (plotLeft > bbox3d.minX) {
  2647. scale = Math.min(scale, 1 - Math.abs((plotLeft + originX) / (bbox3d.minX + originX)) % 1);
  2648. }
  2649. // Right edge:
  2650. if (plotRight < bbox3d.maxX) {
  2651. scale = Math.min(scale, (plotRight - originX) / (bbox3d.maxX - originX));
  2652. }
  2653. // Top edge:
  2654. if (plotTop > bbox3d.minY) {
  2655. if (bbox3d.minY < 0) {
  2656. scale = Math.min(scale, (plotTop + originY) / (-bbox3d.minY + plotTop + originY));
  2657. }
  2658. else {
  2659. scale = Math.min(scale, 1 - (plotTop + originY) / (bbox3d.minY + originY) % 1);
  2660. }
  2661. }
  2662. // Bottom edge:
  2663. if (plotBottom < bbox3d.maxY) {
  2664. scale = Math.min(scale, Math.abs((plotBottom - originY) / (bbox3d.maxY - originY)));
  2665. }
  2666. return scale;
  2667. };
  2668. return Composition;
  2669. }());
  2670. Chart3D.Composition = Composition;
  2671. /* *
  2672. *
  2673. * Constants
  2674. *
  2675. * */
  2676. /**
  2677. * @optionparent
  2678. * @private
  2679. */
  2680. Chart3D.defaultOptions = {
  2681. chart: {
  2682. /**
  2683. * Options to render charts in 3 dimensions. This feature requires
  2684. * `highcharts-3d.js`, found in the download package or online at
  2685. * [code.highcharts.com/highcharts-3d.js](https://code.highcharts.com/highcharts-3d.js).
  2686. *
  2687. * @since 4.0
  2688. * @product highcharts
  2689. * @requires highcharts-3d
  2690. */
  2691. options3d: {
  2692. /**
  2693. * Wether to render the chart using the 3D functionality.
  2694. *
  2695. * @since 4.0
  2696. * @product highcharts
  2697. */
  2698. enabled: false,
  2699. /**
  2700. * One of the two rotation angles for the chart.
  2701. *
  2702. * @since 4.0
  2703. * @product highcharts
  2704. */
  2705. alpha: 0,
  2706. /**
  2707. * One of the two rotation angles for the chart.
  2708. *
  2709. * @since 4.0
  2710. * @product highcharts
  2711. */
  2712. beta: 0,
  2713. /**
  2714. * The total depth of the chart.
  2715. *
  2716. * @since 4.0
  2717. * @product highcharts
  2718. */
  2719. depth: 100,
  2720. /**
  2721. * Whether the 3d box should automatically adjust to the chart
  2722. * plot area.
  2723. *
  2724. * @since 4.2.4
  2725. * @product highcharts
  2726. */
  2727. fitToPlot: true,
  2728. /**
  2729. * Defines the distance the viewer is standing in front of the
  2730. * chart, this setting is important to calculate the perspective
  2731. * effect in column and scatter charts. It is not used for 3D
  2732. * pie charts.
  2733. *
  2734. * @since 4.0
  2735. * @product highcharts
  2736. */
  2737. viewDistance: 25,
  2738. /**
  2739. * Set it to `"auto"` to automatically move the labels to the
  2740. * best edge.
  2741. *
  2742. * @type {"auto"|null}
  2743. * @since 5.0.12
  2744. * @product highcharts
  2745. */
  2746. axisLabelPosition: null,
  2747. /**
  2748. * Provides the option to draw a frame around the charts by
  2749. * defining a bottom, front and back panel.
  2750. *
  2751. * @since 4.0
  2752. * @product highcharts
  2753. * @requires highcharts-3d
  2754. */
  2755. frame: {
  2756. /**
  2757. * Whether the frames are visible.
  2758. */
  2759. visible: 'default',
  2760. /**
  2761. * General pixel thickness for the frame faces.
  2762. */
  2763. size: 1,
  2764. /**
  2765. * The bottom of the frame around a 3D chart.
  2766. *
  2767. * @since 4.0
  2768. * @product highcharts
  2769. * @requires highcharts-3d
  2770. */
  2771. /**
  2772. * The color of the panel.
  2773. *
  2774. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  2775. * @default transparent
  2776. * @since 4.0
  2777. * @product highcharts
  2778. * @apioption chart.options3d.frame.bottom.color
  2779. */
  2780. /**
  2781. * The thickness of the panel.
  2782. *
  2783. * @type {number}
  2784. * @default 1
  2785. * @since 4.0
  2786. * @product highcharts
  2787. * @apioption chart.options3d.frame.bottom.size
  2788. */
  2789. /**
  2790. * Whether to display the frame. Possible values are `true`,
  2791. * `false`, `"auto"` to display only the frames behind the
  2792. * data, and `"default"` to display faces behind the data
  2793. * based on the axis layout, ignoring the point of view.
  2794. *
  2795. * @sample {highcharts} highcharts/3d/scatter-frame/
  2796. * Auto frames
  2797. *
  2798. * @type {boolean|"default"|"auto"}
  2799. * @default default
  2800. * @since 5.0.12
  2801. * @product highcharts
  2802. * @apioption chart.options3d.frame.bottom.visible
  2803. */
  2804. /**
  2805. * The bottom of the frame around a 3D chart.
  2806. */
  2807. bottom: {},
  2808. /**
  2809. * The top of the frame around a 3D chart.
  2810. *
  2811. * @extends chart.options3d.frame.bottom
  2812. */
  2813. top: {},
  2814. /**
  2815. * The left side of the frame around a 3D chart.
  2816. *
  2817. * @extends chart.options3d.frame.bottom
  2818. */
  2819. left: {},
  2820. /**
  2821. * The right of the frame around a 3D chart.
  2822. *
  2823. * @extends chart.options3d.frame.bottom
  2824. */
  2825. right: {},
  2826. /**
  2827. * The back side of the frame around a 3D chart.
  2828. *
  2829. * @extends chart.options3d.frame.bottom
  2830. */
  2831. back: {},
  2832. /**
  2833. * The front of the frame around a 3D chart.
  2834. *
  2835. * @extends chart.options3d.frame.bottom
  2836. */
  2837. front: {}
  2838. }
  2839. }
  2840. }
  2841. };
  2842. /* *
  2843. *
  2844. * Functions
  2845. *
  2846. * */
  2847. /**
  2848. * @private
  2849. */
  2850. function compose(ChartClass, FxClass) {
  2851. var chartProto = ChartClass.prototype;
  2852. var fxProto = FxClass.prototype;
  2853. /**
  2854. * Shorthand to check the is3d flag.
  2855. * @private
  2856. * @return {boolean}
  2857. * Whether it is a 3D chart.
  2858. */
  2859. chartProto.is3d = function () {
  2860. return (this.options.chart.options3d &&
  2861. this.options.chart.options3d.enabled); // #4280
  2862. };
  2863. chartProto.propsRequireDirtyBox.push('chart.options3d');
  2864. chartProto.propsRequireUpdateSeries.push('chart.options3d');
  2865. /**
  2866. * Animation setter for matrix property.
  2867. * @private
  2868. */
  2869. fxProto.matrixSetter = function () {
  2870. var interpolated;
  2871. if (this.pos < 1 &&
  2872. (isArray(this.start) || isArray(this.end))) {
  2873. var start = this.start || [1, 0, 0, 1, 0, 0];
  2874. var end = this.end || [1, 0, 0, 1, 0, 0];
  2875. interpolated = [];
  2876. for (var i = 0; i < 6; i++) {
  2877. interpolated.push(this.pos * end[i] + (1 - this.pos) * start[i]);
  2878. }
  2879. }
  2880. else {
  2881. interpolated = this.end;
  2882. }
  2883. this.elem.attr(this.prop, interpolated, null, true);
  2884. };
  2885. merge(true, genericDefaultOptions, Chart3D.defaultOptions);
  2886. addEvent(ChartClass, 'init', onInit);
  2887. addEvent(ChartClass, 'addSeries', onAddSeries);
  2888. addEvent(ChartClass, 'afterDrawChartBox', onAfterDrawChartBox);
  2889. addEvent(ChartClass, 'afterGetContainer', onAfterGetContainer);
  2890. addEvent(ChartClass, 'afterInit', onAfterInit);
  2891. addEvent(ChartClass, 'afterSetChartSize', onAfterSetChartSize);
  2892. addEvent(ChartClass, 'beforeRedraw', onBeforeRedraw);
  2893. addEvent(ChartClass, 'beforeRender', onBeforeRender);
  2894. wrap(H.Chart.prototype, 'isInsidePlot', wrapIsInsidePlot);
  2895. wrap(ChartClass, 'renderSeries', wrapRenderSeries);
  2896. wrap(ChartClass, 'setClassName', wrapSetClassName);
  2897. }
  2898. Chart3D.compose = compose;
  2899. /**
  2900. * Legacy support for HC < 6 to make 'scatter' series in a 3D chart route to
  2901. * the real 'scatter3d' series type. (#8407)
  2902. * @private
  2903. */
  2904. function onAddSeries(e) {
  2905. if (this.is3d()) {
  2906. if (e.options.type === 'scatter') {
  2907. e.options.type = 'scatter3d';
  2908. }
  2909. }
  2910. }
  2911. /**
  2912. * @private
  2913. */
  2914. function onAfterDrawChartBox() {
  2915. if (this.chart3d &&
  2916. this.is3d()) {
  2917. var chart = this,
  2918. renderer = chart.renderer,
  2919. options3d = this.options.chart.options3d,
  2920. frame = this.chart3d.get3dFrame(),
  2921. xm = this.plotLeft,
  2922. xp = this.plotLeft + this.plotWidth,
  2923. ym = this.plotTop,
  2924. yp = this.plotTop + this.plotHeight,
  2925. zm = 0,
  2926. zp = options3d.depth,
  2927. xmm = xm - (frame.left.visible ? frame.left.size : 0),
  2928. xpp = xp + (frame.right.visible ? frame.right.size : 0),
  2929. ymm = ym - (frame.top.visible ? frame.top.size : 0),
  2930. ypp = yp + (frame.bottom.visible ? frame.bottom.size : 0),
  2931. zmm = zm - (frame.front.visible ? frame.front.size : 0),
  2932. zpp = zp + (frame.back.visible ? frame.back.size : 0),
  2933. verb = chart.hasRendered ? 'animate' : 'attr';
  2934. this.chart3d.frame3d = frame;
  2935. if (!this.frameShapes) {
  2936. this.frameShapes = {
  2937. bottom: renderer.polyhedron().add(),
  2938. top: renderer.polyhedron().add(),
  2939. left: renderer.polyhedron().add(),
  2940. right: renderer.polyhedron().add(),
  2941. back: renderer.polyhedron().add(),
  2942. front: renderer.polyhedron().add()
  2943. };
  2944. }
  2945. this.frameShapes.bottom[verb]({
  2946. 'class': 'highcharts-3d-frame highcharts-3d-frame-bottom',
  2947. zIndex: frame.bottom.frontFacing ? -1000 : 1000,
  2948. faces: [{
  2949. fill: H.color(frame.bottom.color).brighten(0.1).get(),
  2950. vertexes: [{
  2951. x: xmm,
  2952. y: ypp,
  2953. z: zmm
  2954. }, {
  2955. x: xpp,
  2956. y: ypp,
  2957. z: zmm
  2958. }, {
  2959. x: xpp,
  2960. y: ypp,
  2961. z: zpp
  2962. }, {
  2963. x: xmm,
  2964. y: ypp,
  2965. z: zpp
  2966. }],
  2967. enabled: frame.bottom.visible
  2968. },
  2969. {
  2970. fill: H.color(frame.bottom.color).brighten(0.1).get(),
  2971. vertexes: [{
  2972. x: xm,
  2973. y: yp,
  2974. z: zp
  2975. }, {
  2976. x: xp,
  2977. y: yp,
  2978. z: zp
  2979. }, {
  2980. x: xp,
  2981. y: yp,
  2982. z: zm
  2983. }, {
  2984. x: xm,
  2985. y: yp,
  2986. z: zm
  2987. }],
  2988. enabled: frame.bottom.visible
  2989. },
  2990. {
  2991. fill: H.color(frame.bottom.color).brighten(-0.1).get(),
  2992. vertexes: [{
  2993. x: xmm,
  2994. y: ypp,
  2995. z: zmm
  2996. }, {
  2997. x: xmm,
  2998. y: ypp,
  2999. z: zpp
  3000. }, {
  3001. x: xm,
  3002. y: yp,
  3003. z: zp
  3004. }, {
  3005. x: xm,
  3006. y: yp,
  3007. z: zm
  3008. }],
  3009. enabled: frame.bottom.visible && !frame.left.visible
  3010. },
  3011. {
  3012. fill: H.color(frame.bottom.color).brighten(-0.1).get(),
  3013. vertexes: [{
  3014. x: xpp,
  3015. y: ypp,
  3016. z: zpp
  3017. }, {
  3018. x: xpp,
  3019. y: ypp,
  3020. z: zmm
  3021. }, {
  3022. x: xp,
  3023. y: yp,
  3024. z: zm
  3025. }, {
  3026. x: xp,
  3027. y: yp,
  3028. z: zp
  3029. }],
  3030. enabled: frame.bottom.visible && !frame.right.visible
  3031. },
  3032. {
  3033. fill: H.color(frame.bottom.color).get(),
  3034. vertexes: [{
  3035. x: xpp,
  3036. y: ypp,
  3037. z: zmm
  3038. }, {
  3039. x: xmm,
  3040. y: ypp,
  3041. z: zmm
  3042. }, {
  3043. x: xm,
  3044. y: yp,
  3045. z: zm
  3046. }, {
  3047. x: xp,
  3048. y: yp,
  3049. z: zm
  3050. }],
  3051. enabled: frame.bottom.visible && !frame.front.visible
  3052. },
  3053. {
  3054. fill: H.color(frame.bottom.color).get(),
  3055. vertexes: [{
  3056. x: xmm,
  3057. y: ypp,
  3058. z: zpp
  3059. }, {
  3060. x: xpp,
  3061. y: ypp,
  3062. z: zpp
  3063. }, {
  3064. x: xp,
  3065. y: yp,
  3066. z: zp
  3067. }, {
  3068. x: xm,
  3069. y: yp,
  3070. z: zp
  3071. }],
  3072. enabled: frame.bottom.visible && !frame.back.visible
  3073. }]
  3074. });
  3075. this.frameShapes.top[verb]({
  3076. 'class': 'highcharts-3d-frame highcharts-3d-frame-top',
  3077. zIndex: frame.top.frontFacing ? -1000 : 1000,
  3078. faces: [{
  3079. fill: H.color(frame.top.color).brighten(0.1).get(),
  3080. vertexes: [{
  3081. x: xmm,
  3082. y: ymm,
  3083. z: zpp
  3084. }, {
  3085. x: xpp,
  3086. y: ymm,
  3087. z: zpp
  3088. }, {
  3089. x: xpp,
  3090. y: ymm,
  3091. z: zmm
  3092. }, {
  3093. x: xmm,
  3094. y: ymm,
  3095. z: zmm
  3096. }],
  3097. enabled: frame.top.visible
  3098. },
  3099. {
  3100. fill: H.color(frame.top.color).brighten(0.1).get(),
  3101. vertexes: [{
  3102. x: xm,
  3103. y: ym,
  3104. z: zm
  3105. }, {
  3106. x: xp,
  3107. y: ym,
  3108. z: zm
  3109. }, {
  3110. x: xp,
  3111. y: ym,
  3112. z: zp
  3113. }, {
  3114. x: xm,
  3115. y: ym,
  3116. z: zp
  3117. }],
  3118. enabled: frame.top.visible
  3119. },
  3120. {
  3121. fill: H.color(frame.top.color).brighten(-0.1).get(),
  3122. vertexes: [{
  3123. x: xmm,
  3124. y: ymm,
  3125. z: zpp
  3126. }, {
  3127. x: xmm,
  3128. y: ymm,
  3129. z: zmm
  3130. }, {
  3131. x: xm,
  3132. y: ym,
  3133. z: zm
  3134. }, {
  3135. x: xm,
  3136. y: ym,
  3137. z: zp
  3138. }],
  3139. enabled: frame.top.visible && !frame.left.visible
  3140. },
  3141. {
  3142. fill: H.color(frame.top.color).brighten(-0.1).get(),
  3143. vertexes: [{
  3144. x: xpp,
  3145. y: ymm,
  3146. z: zmm
  3147. }, {
  3148. x: xpp,
  3149. y: ymm,
  3150. z: zpp
  3151. }, {
  3152. x: xp,
  3153. y: ym,
  3154. z: zp
  3155. }, {
  3156. x: xp,
  3157. y: ym,
  3158. z: zm
  3159. }],
  3160. enabled: frame.top.visible && !frame.right.visible
  3161. },
  3162. {
  3163. fill: H.color(frame.top.color).get(),
  3164. vertexes: [{
  3165. x: xmm,
  3166. y: ymm,
  3167. z: zmm
  3168. }, {
  3169. x: xpp,
  3170. y: ymm,
  3171. z: zmm
  3172. }, {
  3173. x: xp,
  3174. y: ym,
  3175. z: zm
  3176. }, {
  3177. x: xm,
  3178. y: ym,
  3179. z: zm
  3180. }],
  3181. enabled: frame.top.visible && !frame.front.visible
  3182. },
  3183. {
  3184. fill: H.color(frame.top.color).get(),
  3185. vertexes: [{
  3186. x: xpp,
  3187. y: ymm,
  3188. z: zpp
  3189. }, {
  3190. x: xmm,
  3191. y: ymm,
  3192. z: zpp
  3193. }, {
  3194. x: xm,
  3195. y: ym,
  3196. z: zp
  3197. }, {
  3198. x: xp,
  3199. y: ym,
  3200. z: zp
  3201. }],
  3202. enabled: frame.top.visible && !frame.back.visible
  3203. }]
  3204. });
  3205. this.frameShapes.left[verb]({
  3206. 'class': 'highcharts-3d-frame highcharts-3d-frame-left',
  3207. zIndex: frame.left.frontFacing ? -1000 : 1000,
  3208. faces: [{
  3209. fill: H.color(frame.left.color).brighten(0.1).get(),
  3210. vertexes: [{
  3211. x: xmm,
  3212. y: ypp,
  3213. z: zmm
  3214. }, {
  3215. x: xm,
  3216. y: yp,
  3217. z: zm
  3218. }, {
  3219. x: xm,
  3220. y: yp,
  3221. z: zp
  3222. }, {
  3223. x: xmm,
  3224. y: ypp,
  3225. z: zpp
  3226. }],
  3227. enabled: frame.left.visible && !frame.bottom.visible
  3228. },
  3229. {
  3230. fill: H.color(frame.left.color).brighten(0.1).get(),
  3231. vertexes: [{
  3232. x: xmm,
  3233. y: ymm,
  3234. z: zpp
  3235. }, {
  3236. x: xm,
  3237. y: ym,
  3238. z: zp
  3239. }, {
  3240. x: xm,
  3241. y: ym,
  3242. z: zm
  3243. }, {
  3244. x: xmm,
  3245. y: ymm,
  3246. z: zmm
  3247. }],
  3248. enabled: frame.left.visible && !frame.top.visible
  3249. },
  3250. {
  3251. fill: H.color(frame.left.color).brighten(-0.1).get(),
  3252. vertexes: [{
  3253. x: xmm,
  3254. y: ypp,
  3255. z: zpp
  3256. }, {
  3257. x: xmm,
  3258. y: ymm,
  3259. z: zpp
  3260. }, {
  3261. x: xmm,
  3262. y: ymm,
  3263. z: zmm
  3264. }, {
  3265. x: xmm,
  3266. y: ypp,
  3267. z: zmm
  3268. }],
  3269. enabled: frame.left.visible
  3270. },
  3271. {
  3272. fill: H.color(frame.left.color).brighten(-0.1).get(),
  3273. vertexes: [{
  3274. x: xm,
  3275. y: ym,
  3276. z: zp
  3277. }, {
  3278. x: xm,
  3279. y: yp,
  3280. z: zp
  3281. }, {
  3282. x: xm,
  3283. y: yp,
  3284. z: zm
  3285. }, {
  3286. x: xm,
  3287. y: ym,
  3288. z: zm
  3289. }],
  3290. enabled: frame.left.visible
  3291. },
  3292. {
  3293. fill: H.color(frame.left.color).get(),
  3294. vertexes: [{
  3295. x: xmm,
  3296. y: ypp,
  3297. z: zmm
  3298. }, {
  3299. x: xmm,
  3300. y: ymm,
  3301. z: zmm
  3302. }, {
  3303. x: xm,
  3304. y: ym,
  3305. z: zm
  3306. }, {
  3307. x: xm,
  3308. y: yp,
  3309. z: zm
  3310. }],
  3311. enabled: frame.left.visible && !frame.front.visible
  3312. },
  3313. {
  3314. fill: H.color(frame.left.color).get(),
  3315. vertexes: [{
  3316. x: xmm,
  3317. y: ymm,
  3318. z: zpp
  3319. }, {
  3320. x: xmm,
  3321. y: ypp,
  3322. z: zpp
  3323. }, {
  3324. x: xm,
  3325. y: yp,
  3326. z: zp
  3327. }, {
  3328. x: xm,
  3329. y: ym,
  3330. z: zp
  3331. }],
  3332. enabled: frame.left.visible && !frame.back.visible
  3333. }]
  3334. });
  3335. this.frameShapes.right[verb]({
  3336. 'class': 'highcharts-3d-frame highcharts-3d-frame-right',
  3337. zIndex: frame.right.frontFacing ? -1000 : 1000,
  3338. faces: [{
  3339. fill: H.color(frame.right.color).brighten(0.1).get(),
  3340. vertexes: [{
  3341. x: xpp,
  3342. y: ypp,
  3343. z: zpp
  3344. }, {
  3345. x: xp,
  3346. y: yp,
  3347. z: zp
  3348. }, {
  3349. x: xp,
  3350. y: yp,
  3351. z: zm
  3352. }, {
  3353. x: xpp,
  3354. y: ypp,
  3355. z: zmm
  3356. }],
  3357. enabled: frame.right.visible && !frame.bottom.visible
  3358. },
  3359. {
  3360. fill: H.color(frame.right.color).brighten(0.1).get(),
  3361. vertexes: [{
  3362. x: xpp,
  3363. y: ymm,
  3364. z: zmm
  3365. }, {
  3366. x: xp,
  3367. y: ym,
  3368. z: zm
  3369. }, {
  3370. x: xp,
  3371. y: ym,
  3372. z: zp
  3373. }, {
  3374. x: xpp,
  3375. y: ymm,
  3376. z: zpp
  3377. }],
  3378. enabled: frame.right.visible && !frame.top.visible
  3379. },
  3380. {
  3381. fill: H.color(frame.right.color).brighten(-0.1).get(),
  3382. vertexes: [{
  3383. x: xp,
  3384. y: ym,
  3385. z: zm
  3386. }, {
  3387. x: xp,
  3388. y: yp,
  3389. z: zm
  3390. }, {
  3391. x: xp,
  3392. y: yp,
  3393. z: zp
  3394. }, {
  3395. x: xp,
  3396. y: ym,
  3397. z: zp
  3398. }],
  3399. enabled: frame.right.visible
  3400. },
  3401. {
  3402. fill: H.color(frame.right.color).brighten(-0.1).get(),
  3403. vertexes: [{
  3404. x: xpp,
  3405. y: ypp,
  3406. z: zmm
  3407. }, {
  3408. x: xpp,
  3409. y: ymm,
  3410. z: zmm
  3411. }, {
  3412. x: xpp,
  3413. y: ymm,
  3414. z: zpp
  3415. }, {
  3416. x: xpp,
  3417. y: ypp,
  3418. z: zpp
  3419. }],
  3420. enabled: frame.right.visible
  3421. },
  3422. {
  3423. fill: H.color(frame.right.color).get(),
  3424. vertexes: [{
  3425. x: xpp,
  3426. y: ymm,
  3427. z: zmm
  3428. }, {
  3429. x: xpp,
  3430. y: ypp,
  3431. z: zmm
  3432. }, {
  3433. x: xp,
  3434. y: yp,
  3435. z: zm
  3436. }, {
  3437. x: xp,
  3438. y: ym,
  3439. z: zm
  3440. }],
  3441. enabled: frame.right.visible && !frame.front.visible
  3442. },
  3443. {
  3444. fill: H.color(frame.right.color).get(),
  3445. vertexes: [{
  3446. x: xpp,
  3447. y: ypp,
  3448. z: zpp
  3449. }, {
  3450. x: xpp,
  3451. y: ymm,
  3452. z: zpp
  3453. }, {
  3454. x: xp,
  3455. y: ym,
  3456. z: zp
  3457. }, {
  3458. x: xp,
  3459. y: yp,
  3460. z: zp
  3461. }],
  3462. enabled: frame.right.visible && !frame.back.visible
  3463. }]
  3464. });
  3465. this.frameShapes.back[verb]({
  3466. 'class': 'highcharts-3d-frame highcharts-3d-frame-back',
  3467. zIndex: frame.back.frontFacing ? -1000 : 1000,
  3468. faces: [{
  3469. fill: H.color(frame.back.color).brighten(0.1).get(),
  3470. vertexes: [{
  3471. x: xpp,
  3472. y: ypp,
  3473. z: zpp
  3474. }, {
  3475. x: xmm,
  3476. y: ypp,
  3477. z: zpp
  3478. }, {
  3479. x: xm,
  3480. y: yp,
  3481. z: zp
  3482. }, {
  3483. x: xp,
  3484. y: yp,
  3485. z: zp
  3486. }],
  3487. enabled: frame.back.visible && !frame.bottom.visible
  3488. },
  3489. {
  3490. fill: H.color(frame.back.color).brighten(0.1).get(),
  3491. vertexes: [{
  3492. x: xmm,
  3493. y: ymm,
  3494. z: zpp
  3495. }, {
  3496. x: xpp,
  3497. y: ymm,
  3498. z: zpp
  3499. }, {
  3500. x: xp,
  3501. y: ym,
  3502. z: zp
  3503. }, {
  3504. x: xm,
  3505. y: ym,
  3506. z: zp
  3507. }],
  3508. enabled: frame.back.visible && !frame.top.visible
  3509. },
  3510. {
  3511. fill: H.color(frame.back.color).brighten(-0.1).get(),
  3512. vertexes: [{
  3513. x: xmm,
  3514. y: ypp,
  3515. z: zpp
  3516. }, {
  3517. x: xmm,
  3518. y: ymm,
  3519. z: zpp
  3520. }, {
  3521. x: xm,
  3522. y: ym,
  3523. z: zp
  3524. }, {
  3525. x: xm,
  3526. y: yp,
  3527. z: zp
  3528. }],
  3529. enabled: frame.back.visible && !frame.left.visible
  3530. },
  3531. {
  3532. fill: H.color(frame.back.color).brighten(-0.1).get(),
  3533. vertexes: [{
  3534. x: xpp,
  3535. y: ymm,
  3536. z: zpp
  3537. }, {
  3538. x: xpp,
  3539. y: ypp,
  3540. z: zpp
  3541. }, {
  3542. x: xp,
  3543. y: yp,
  3544. z: zp
  3545. }, {
  3546. x: xp,
  3547. y: ym,
  3548. z: zp
  3549. }],
  3550. enabled: frame.back.visible && !frame.right.visible
  3551. },
  3552. {
  3553. fill: H.color(frame.back.color).get(),
  3554. vertexes: [{
  3555. x: xm,
  3556. y: ym,
  3557. z: zp
  3558. }, {
  3559. x: xp,
  3560. y: ym,
  3561. z: zp
  3562. }, {
  3563. x: xp,
  3564. y: yp,
  3565. z: zp
  3566. }, {
  3567. x: xm,
  3568. y: yp,
  3569. z: zp
  3570. }],
  3571. enabled: frame.back.visible
  3572. },
  3573. {
  3574. fill: H.color(frame.back.color).get(),
  3575. vertexes: [{
  3576. x: xmm,
  3577. y: ypp,
  3578. z: zpp
  3579. }, {
  3580. x: xpp,
  3581. y: ypp,
  3582. z: zpp
  3583. }, {
  3584. x: xpp,
  3585. y: ymm,
  3586. z: zpp
  3587. }, {
  3588. x: xmm,
  3589. y: ymm,
  3590. z: zpp
  3591. }],
  3592. enabled: frame.back.visible
  3593. }]
  3594. });
  3595. this.frameShapes.front[verb]({
  3596. 'class': 'highcharts-3d-frame highcharts-3d-frame-front',
  3597. zIndex: frame.front.frontFacing ? -1000 : 1000,
  3598. faces: [{
  3599. fill: H.color(frame.front.color).brighten(0.1).get(),
  3600. vertexes: [{
  3601. x: xmm,
  3602. y: ypp,
  3603. z: zmm
  3604. }, {
  3605. x: xpp,
  3606. y: ypp,
  3607. z: zmm
  3608. }, {
  3609. x: xp,
  3610. y: yp,
  3611. z: zm
  3612. }, {
  3613. x: xm,
  3614. y: yp,
  3615. z: zm
  3616. }],
  3617. enabled: frame.front.visible && !frame.bottom.visible
  3618. },
  3619. {
  3620. fill: H.color(frame.front.color).brighten(0.1).get(),
  3621. vertexes: [{
  3622. x: xpp,
  3623. y: ymm,
  3624. z: zmm
  3625. }, {
  3626. x: xmm,
  3627. y: ymm,
  3628. z: zmm
  3629. }, {
  3630. x: xm,
  3631. y: ym,
  3632. z: zm
  3633. }, {
  3634. x: xp,
  3635. y: ym,
  3636. z: zm
  3637. }],
  3638. enabled: frame.front.visible && !frame.top.visible
  3639. },
  3640. {
  3641. fill: H.color(frame.front.color).brighten(-0.1).get(),
  3642. vertexes: [{
  3643. x: xmm,
  3644. y: ymm,
  3645. z: zmm
  3646. }, {
  3647. x: xmm,
  3648. y: ypp,
  3649. z: zmm
  3650. }, {
  3651. x: xm,
  3652. y: yp,
  3653. z: zm
  3654. }, {
  3655. x: xm,
  3656. y: ym,
  3657. z: zm
  3658. }],
  3659. enabled: frame.front.visible && !frame.left.visible
  3660. },
  3661. {
  3662. fill: H.color(frame.front.color).brighten(-0.1).get(),
  3663. vertexes: [{
  3664. x: xpp,
  3665. y: ypp,
  3666. z: zmm
  3667. }, {
  3668. x: xpp,
  3669. y: ymm,
  3670. z: zmm
  3671. }, {
  3672. x: xp,
  3673. y: ym,
  3674. z: zm
  3675. }, {
  3676. x: xp,
  3677. y: yp,
  3678. z: zm
  3679. }],
  3680. enabled: frame.front.visible && !frame.right.visible
  3681. },
  3682. {
  3683. fill: H.color(frame.front.color).get(),
  3684. vertexes: [{
  3685. x: xp,
  3686. y: ym,
  3687. z: zm
  3688. }, {
  3689. x: xm,
  3690. y: ym,
  3691. z: zm
  3692. }, {
  3693. x: xm,
  3694. y: yp,
  3695. z: zm
  3696. }, {
  3697. x: xp,
  3698. y: yp,
  3699. z: zm
  3700. }],
  3701. enabled: frame.front.visible
  3702. },
  3703. {
  3704. fill: H.color(frame.front.color).get(),
  3705. vertexes: [{
  3706. x: xpp,
  3707. y: ypp,
  3708. z: zmm
  3709. }, {
  3710. x: xmm,
  3711. y: ypp,
  3712. z: zmm
  3713. }, {
  3714. x: xmm,
  3715. y: ymm,
  3716. z: zmm
  3717. }, {
  3718. x: xpp,
  3719. y: ymm,
  3720. z: zmm
  3721. }],
  3722. enabled: frame.front.visible
  3723. }]
  3724. });
  3725. }
  3726. }
  3727. /**
  3728. * Add the required CSS classes for column sides (#6018)
  3729. * @private
  3730. */
  3731. function onAfterGetContainer() {
  3732. if (this.styledMode) {
  3733. this.renderer.definition({
  3734. tagName: 'style',
  3735. textContent: '.highcharts-3d-top{' +
  3736. 'filter: url(#highcharts-brighter)' +
  3737. '}\n' +
  3738. '.highcharts-3d-side{' +
  3739. 'filter: url(#highcharts-darker)' +
  3740. '}\n'
  3741. });
  3742. // Add add definitions used by brighter and darker faces of the
  3743. // cuboids.
  3744. [{
  3745. name: 'darker',
  3746. slope: 0.6
  3747. }, {
  3748. name: 'brighter',
  3749. slope: 1.4
  3750. }].forEach(function (cfg) {
  3751. this.renderer.definition({
  3752. tagName: 'filter',
  3753. id: 'highcharts-' + cfg.name,
  3754. children: [{
  3755. tagName: 'feComponentTransfer',
  3756. children: [{
  3757. tagName: 'feFuncR',
  3758. type: 'linear',
  3759. slope: cfg.slope
  3760. }, {
  3761. tagName: 'feFuncG',
  3762. type: 'linear',
  3763. slope: cfg.slope
  3764. }, {
  3765. tagName: 'feFuncB',
  3766. type: 'linear',
  3767. slope: cfg.slope
  3768. }]
  3769. }]
  3770. });
  3771. }, this);
  3772. }
  3773. }
  3774. /**
  3775. * Legacy support for HC < 6 to make 'scatter' series in a 3D chart route to
  3776. * the real 'scatter3d' series type. (#8407)
  3777. * @private
  3778. */
  3779. function onAfterInit() {
  3780. var options = this.options;
  3781. if (this.is3d()) {
  3782. (options.series || []).forEach(function (s) {
  3783. var type = s.type ||
  3784. options.chart.type ||
  3785. options.chart.defaultSeriesType;
  3786. if (type === 'scatter') {
  3787. s.type = 'scatter3d';
  3788. }
  3789. });
  3790. }
  3791. }
  3792. /**
  3793. * @private
  3794. */
  3795. function onAfterSetChartSize() {
  3796. var chart = this,
  3797. options3d = chart.options.chart.options3d;
  3798. if (chart.chart3d &&
  3799. chart.is3d()) {
  3800. // Add a 0-360 normalisation for alfa and beta angles in 3d graph
  3801. if (options3d) {
  3802. options3d.alpha = options3d.alpha % 360 + (options3d.alpha >= 0 ? 0 : 360);
  3803. options3d.beta = options3d.beta % 360 + (options3d.beta >= 0 ? 0 : 360);
  3804. }
  3805. var inverted = chart.inverted, clipBox = chart.clipBox, margin = chart.margin, x = inverted ? 'y' : 'x', y = inverted ? 'x' : 'y', w = inverted ? 'height' : 'width', h = inverted ? 'width' : 'height';
  3806. clipBox[x] = -(margin[3] || 0);
  3807. clipBox[y] = -(margin[0] || 0);
  3808. clipBox[w] =
  3809. chart.chartWidth + (margin[3] || 0) + (margin[1] || 0);
  3810. clipBox[h] =
  3811. chart.chartHeight + (margin[0] || 0) + (margin[2] || 0);
  3812. // Set scale, used later in perspective method():
  3813. // getScale uses perspective, so scale3d has to be reset.
  3814. chart.scale3d = 1;
  3815. if (options3d.fitToPlot === true) {
  3816. chart.scale3d = chart.chart3d.getScale(options3d.depth);
  3817. }
  3818. // Recalculate the 3d frame with every call of setChartSize,
  3819. // instead of doing it after every redraw(). It avoids ticks
  3820. // and axis title outside of chart.
  3821. chart.chart3d.frame3d = chart.chart3d.get3dFrame(); // #7942
  3822. }
  3823. }
  3824. /**
  3825. * @private
  3826. */
  3827. function onBeforeRedraw() {
  3828. if (this.is3d()) {
  3829. // Set to force a redraw of all elements
  3830. this.isDirtyBox = true;
  3831. }
  3832. }
  3833. /**
  3834. * @private
  3835. */
  3836. function onBeforeRender() {
  3837. if (this.chart3d && this.is3d()) {
  3838. this.chart3d.frame3d = this.chart3d.get3dFrame();
  3839. }
  3840. }
  3841. /**
  3842. * @private
  3843. */
  3844. function onInit() {
  3845. if (!this.chart3d) {
  3846. this.chart3d = new Composition(this);
  3847. }
  3848. }
  3849. /**
  3850. * @private
  3851. */
  3852. function wrapIsInsidePlot(proceed) {
  3853. return this.is3d() || proceed.apply(this, [].slice.call(arguments, 1));
  3854. }
  3855. /**
  3856. * Draw the series in the reverse order (#3803, #3917)
  3857. * @private
  3858. */
  3859. function wrapRenderSeries(proceed) {
  3860. var series,
  3861. i = this.series.length;
  3862. if (this.is3d()) {
  3863. while (i--) {
  3864. series = this.series[i];
  3865. series.translate();
  3866. series.render();
  3867. }
  3868. }
  3869. else {
  3870. proceed.call(this);
  3871. }
  3872. }
  3873. /**
  3874. * @private
  3875. */
  3876. function wrapSetClassName(proceed) {
  3877. proceed.apply(this, [].slice.call(arguments, 1));
  3878. if (this.is3d()) {
  3879. this.container.className += ' highcharts-3d-chart';
  3880. }
  3881. }
  3882. })(Chart3D || (Chart3D = {}));
  3883. Chart3D.compose(Chart, Fx);
  3884. ZAxis.ZChartComposition.compose(Chart);
  3885. Axis3D.compose(Axis);
  3886. /**
  3887. * Note: As of v5.0.12, `frame.left` or `frame.right` should be used instead.
  3888. *
  3889. * The side for the frame around a 3D chart.
  3890. *
  3891. * @deprecated
  3892. * @since 4.0
  3893. * @product highcharts
  3894. * @requires highcharts-3d
  3895. * @apioption chart.options3d.frame.side
  3896. */
  3897. /**
  3898. * The color of the panel.
  3899. *
  3900. * @deprecated
  3901. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3902. * @default transparent
  3903. * @since 4.0
  3904. * @product highcharts
  3905. * @apioption chart.options3d.frame.side.color
  3906. */
  3907. /**
  3908. * The thickness of the panel.
  3909. *
  3910. * @deprecated
  3911. * @type {number}
  3912. * @default 1
  3913. * @since 4.0
  3914. * @product highcharts
  3915. * @apioption chart.options3d.frame.side.size
  3916. */
  3917. ''; // adds doclets above to transpiled file
  3918. return Chart3D;
  3919. });
  3920. _registerModule(_modules, 'Core/Series/Series3D.js', [_modules['Core/Globals.js'], _modules['Extensions/Math3D.js'], _modules['Core/Utilities.js']], function (H, Math3D, U) {
  3921. /* *
  3922. *
  3923. * (c) 2010-2020 Torstein Honsi
  3924. *
  3925. * Extension to the Series object in 3D charts.
  3926. *
  3927. * License: www.highcharts.com/license
  3928. *
  3929. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3930. *
  3931. * */
  3932. var perspective = Math3D.perspective;
  3933. var addEvent = U.addEvent,
  3934. pick = U.pick;
  3935. /* eslint-disable no-invalid-this */
  3936. // Wrap the translate method to post-translate points into 3D perspective
  3937. addEvent(H.Series, 'afterTranslate', function () {
  3938. if (this.chart.is3d()) {
  3939. this.translate3dPoints();
  3940. }
  3941. });
  3942. // Translate the plotX, plotY properties and add plotZ.
  3943. H.Series.prototype.translate3dPoints = function () {
  3944. var series = this,
  3945. chart = series.chart,
  3946. zAxis = pick(series.zAxis,
  3947. chart.options.zAxis[0]),
  3948. rawPoints = [],
  3949. rawPoint,
  3950. projectedPoints,
  3951. projectedPoint,
  3952. zValue,
  3953. i;
  3954. for (i = 0; i < series.data.length; i++) {
  3955. rawPoint = series.data[i];
  3956. if (zAxis && zAxis.translate) {
  3957. zValue = zAxis.logarithmic && zAxis.val2lin ?
  3958. zAxis.val2lin(rawPoint.z) :
  3959. rawPoint.z; // #4562
  3960. rawPoint.plotZ = zAxis.translate(zValue);
  3961. rawPoint.isInside = rawPoint.isInside ?
  3962. (zValue >= zAxis.min &&
  3963. zValue <= zAxis.max) :
  3964. false;
  3965. }
  3966. else {
  3967. rawPoint.plotZ = 0;
  3968. }
  3969. rawPoint.axisXpos = rawPoint.plotX;
  3970. rawPoint.axisYpos = rawPoint.plotY;
  3971. rawPoint.axisZpos = rawPoint.plotZ;
  3972. rawPoints.push({
  3973. x: rawPoint.plotX,
  3974. y: rawPoint.plotY,
  3975. z: rawPoint.plotZ
  3976. });
  3977. }
  3978. projectedPoints = perspective(rawPoints, chart, true);
  3979. for (i = 0; i < series.data.length; i++) {
  3980. rawPoint = series.data[i];
  3981. projectedPoint = projectedPoints[i];
  3982. rawPoint.plotX = projectedPoint.x;
  3983. rawPoint.plotY = projectedPoint.y;
  3984. rawPoint.plotZ = projectedPoint.z;
  3985. }
  3986. };
  3987. });
  3988. _registerModule(_modules, 'Series/Column3DSeries.js', [_modules['Core/Series/Series.js'], _modules['Core/Globals.js'], _modules['Extensions/Math3D.js'], _modules['Extensions/Stacking.js'], _modules['Core/Utilities.js']], function (BaseSeries, H, Math3D, StackItem, U) {
  3989. /* *
  3990. *
  3991. * (c) 2010-2020 Torstein Honsi
  3992. *
  3993. * License: www.highcharts.com/license
  3994. *
  3995. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3996. *
  3997. * */
  3998. var perspective = Math3D.perspective;
  3999. var addEvent = U.addEvent,
  4000. pick = U.pick,
  4001. wrap = U.wrap;
  4002. var Series = H.Series,
  4003. columnProto = BaseSeries.seriesTypes.column.prototype,
  4004. svg = H.svg;
  4005. /**
  4006. * Depth of the columns in a 3D column chart.
  4007. *
  4008. * @type {number}
  4009. * @default 25
  4010. * @since 4.0
  4011. * @product highcharts
  4012. * @requires highcharts-3d
  4013. * @apioption plotOptions.column.depth
  4014. */
  4015. /**
  4016. * 3D columns only. The color of the edges. Similar to `borderColor`, except it
  4017. * defaults to the same color as the column.
  4018. *
  4019. * @type {Highcharts.ColorString}
  4020. * @product highcharts
  4021. * @requires highcharts-3d
  4022. * @apioption plotOptions.column.edgeColor
  4023. */
  4024. /**
  4025. * 3D columns only. The width of the colored edges.
  4026. *
  4027. * @type {number}
  4028. * @default 1
  4029. * @product highcharts
  4030. * @requires highcharts-3d
  4031. * @apioption plotOptions.column.edgeWidth
  4032. */
  4033. /**
  4034. * The spacing between columns on the Z Axis in a 3D chart.
  4035. *
  4036. * @type {number}
  4037. * @default 1
  4038. * @since 4.0
  4039. * @product highcharts
  4040. * @requires highcharts-3d
  4041. * @apioption plotOptions.column.groupZPadding
  4042. */
  4043. /* eslint-disable no-invalid-this */
  4044. /**
  4045. * @private
  4046. * @param {Highcharts.Chart} chart
  4047. * Chart with stacks
  4048. * @param {string} stacking
  4049. * Stacking option
  4050. * @return {Highcharts.Stack3dDictionary}
  4051. */
  4052. function retrieveStacks(chart, stacking) {
  4053. var series = chart.series,
  4054. stacks = {};
  4055. var stackNumber,
  4056. i = 1;
  4057. series.forEach(function (s) {
  4058. stackNumber = pick(s.options.stack, (stacking ? 0 : series.length - 1 - s.index)); // #3841, #4532
  4059. if (!stacks[stackNumber]) {
  4060. stacks[stackNumber] = { series: [s], position: i };
  4061. i++;
  4062. }
  4063. else {
  4064. stacks[stackNumber].series.push(s);
  4065. }
  4066. });
  4067. stacks.totalStacks = i + 1;
  4068. return stacks;
  4069. }
  4070. wrap(columnProto, 'translate', function (proceed) {
  4071. proceed.apply(this, [].slice.call(arguments, 1));
  4072. // Do not do this if the chart is not 3D
  4073. if (this.chart.is3d()) {
  4074. this.translate3dShapes();
  4075. }
  4076. });
  4077. // Don't use justifyDataLabel when point is outsidePlot
  4078. wrap(Series.prototype, 'justifyDataLabel', function (proceed) {
  4079. return !(arguments[2].outside3dPlot) ?
  4080. proceed.apply(this, [].slice.call(arguments, 1)) :
  4081. false;
  4082. });
  4083. columnProto.translate3dPoints = function () { };
  4084. columnProto.translate3dShapes = function () {
  4085. var series = this,
  4086. chart = series.chart,
  4087. seriesOptions = series.options,
  4088. depth = seriesOptions.depth,
  4089. stack = seriesOptions.stacking ?
  4090. (seriesOptions.stack || 0) :
  4091. series.index, // #4743
  4092. z = stack * (depth + (seriesOptions.groupZPadding || 1)),
  4093. borderCrisp = series.borderWidth % 2 ? 0.5 : 0,
  4094. point2dPos; // Position of point in 2D, used for 3D position calculation.
  4095. if (chart.inverted && !series.yAxis.reversed) {
  4096. borderCrisp *= -1;
  4097. }
  4098. if (seriesOptions.grouping !== false) {
  4099. z = 0;
  4100. }
  4101. z += (seriesOptions.groupZPadding || 1);
  4102. series.data.forEach(function (point) {
  4103. // #7103 Reset outside3dPlot flag
  4104. point.outside3dPlot = null;
  4105. if (point.y !== null) {
  4106. var shapeArgs = point.shapeArgs, tooltipPos = point.tooltipPos,
  4107. // Array for final shapeArgs calculation.
  4108. // We are checking two dimensions (x and y).
  4109. dimensions = [['x', 'width'], ['y', 'height']], borderlessBase; // Crisped rects can have +/- 0.5 pixels offset.
  4110. // #3131 We need to check if column is inside plotArea.
  4111. dimensions.forEach(function (d) {
  4112. borderlessBase = shapeArgs[d[0]] - borderCrisp;
  4113. if (borderlessBase < 0) {
  4114. // If borderLessBase is smaller than 0, it is needed to set
  4115. // its value to 0 or 0.5 depending on borderWidth
  4116. // borderWidth may be even or odd.
  4117. shapeArgs[d[1]] +=
  4118. shapeArgs[d[0]] + borderCrisp;
  4119. shapeArgs[d[0]] = -borderCrisp;
  4120. borderlessBase = 0;
  4121. }
  4122. if ((borderlessBase + shapeArgs[d[1]] >
  4123. series[d[0] + 'Axis'].len) &&
  4124. // Do not change height/width of column if 0 (#6708)
  4125. shapeArgs[d[1]] !== 0) {
  4126. shapeArgs[d[1]] =
  4127. series[d[0] + 'Axis'].len -
  4128. shapeArgs[d[0]];
  4129. }
  4130. if (
  4131. // Do not remove columns with zero height/width.
  4132. (shapeArgs[d[1]] !== 0) &&
  4133. (shapeArgs[d[0]] >=
  4134. series[d[0] + 'Axis'].len ||
  4135. shapeArgs[d[0]] + shapeArgs[d[1]] <=
  4136. borderCrisp)) {
  4137. // Set args to 0 if column is outside the chart.
  4138. for (var key in shapeArgs) { // eslint-disable-line guard-for-in
  4139. shapeArgs[key] = 0;
  4140. }
  4141. // #7103 outside3dPlot flag is set on Points which are
  4142. // currently outside of plot.
  4143. point.outside3dPlot = true;
  4144. }
  4145. });
  4146. // Change from 2d to 3d
  4147. if (point.shapeType === 'rect') {
  4148. point.shapeType = 'cuboid';
  4149. }
  4150. shapeArgs.z = z;
  4151. shapeArgs.depth = depth;
  4152. shapeArgs.insidePlotArea = true;
  4153. // Point's position in 2D
  4154. point2dPos = {
  4155. x: shapeArgs.x + shapeArgs.width / 2,
  4156. y: shapeArgs.y,
  4157. z: z + depth / 2 // The center of column in Z dimension
  4158. };
  4159. // Recalculate point positions for inverted graphs
  4160. if (chart.inverted) {
  4161. point2dPos.x = shapeArgs.height;
  4162. point2dPos.y = point.clientX;
  4163. }
  4164. // Calculate and store point's position in 3D,
  4165. // using perspective method.
  4166. point.plot3d = perspective([point2dPos], chart, true, false)[0];
  4167. // Translate the tooltip position in 3d space
  4168. tooltipPos = perspective([{
  4169. x: tooltipPos[0],
  4170. y: tooltipPos[1],
  4171. z: z + depth / 2 // The center of column in Z dimension
  4172. }], chart, true, false)[0];
  4173. point.tooltipPos = [tooltipPos.x, tooltipPos.y];
  4174. }
  4175. });
  4176. // store for later use #4067
  4177. series.z = z;
  4178. };
  4179. wrap(columnProto, 'animate', function (proceed) {
  4180. if (!this.chart.is3d()) {
  4181. proceed.apply(this, [].slice.call(arguments, 1));
  4182. }
  4183. else {
  4184. var args = arguments,
  4185. init = args[1],
  4186. yAxis = this.yAxis,
  4187. series = this,
  4188. reversed = this.yAxis.reversed;
  4189. if (svg) { // VML is too slow anyway
  4190. if (init) {
  4191. series.data.forEach(function (point) {
  4192. if (point.y !== null) {
  4193. point.height = point.shapeArgs.height;
  4194. point.shapey = point.shapeArgs.y; // #2968
  4195. point.shapeArgs.height = 1;
  4196. if (!reversed) {
  4197. if (point.stackY) {
  4198. point.shapeArgs.y =
  4199. point.plotY +
  4200. yAxis.translate(point.stackY);
  4201. }
  4202. else {
  4203. point.shapeArgs.y =
  4204. point.plotY +
  4205. (point.negative ?
  4206. -point.height :
  4207. point.height);
  4208. }
  4209. }
  4210. }
  4211. });
  4212. }
  4213. else { // run the animation
  4214. series.data.forEach(function (point) {
  4215. if (point.y !== null) {
  4216. point.shapeArgs.height = point.height;
  4217. point.shapeArgs.y = point.shapey; // #2968
  4218. // null value do not have a graphic
  4219. if (point.graphic) {
  4220. point.graphic.animate(point.shapeArgs, series.options.animation);
  4221. }
  4222. }
  4223. });
  4224. // redraw datalabels to the correct position
  4225. this.drawDataLabels();
  4226. }
  4227. }
  4228. }
  4229. });
  4230. // In case of 3d columns there is no sense to add this columns to a specific
  4231. // series group - if series is added to a group all columns will have the same
  4232. // zIndex in comparison with different series.
  4233. wrap(columnProto, 'plotGroup', function (proceed, prop, name, visibility, zIndex, parent) {
  4234. if (prop !== 'dataLabelsGroup') {
  4235. if (this.chart.is3d()) {
  4236. if (this[prop]) {
  4237. delete this[prop];
  4238. }
  4239. if (parent) {
  4240. if (!this.chart.columnGroup) {
  4241. this.chart.columnGroup =
  4242. this.chart.renderer.g('columnGroup').add(parent);
  4243. }
  4244. this[prop] = this.chart.columnGroup;
  4245. this.chart.columnGroup.attr(this.getPlotBox());
  4246. this[prop].survive = true;
  4247. if (prop === 'group' || prop === 'markerGroup') {
  4248. arguments[3] = 'visible';
  4249. // For 3D column group and markerGroup should be visible
  4250. }
  4251. }
  4252. }
  4253. }
  4254. return proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  4255. });
  4256. // When series is not added to group it is needed to change setVisible method to
  4257. // allow correct Legend funcionality. This wrap is basing on pie chart series.
  4258. wrap(columnProto, 'setVisible', function (proceed, vis) {
  4259. var series = this,
  4260. pointVis;
  4261. if (series.chart.is3d()) {
  4262. series.data.forEach(function (point) {
  4263. point.visible = point.options.visible = vis =
  4264. typeof vis === 'undefined' ?
  4265. !pick(series.visible, point.visible) : vis;
  4266. pointVis = vis ? 'visible' : 'hidden';
  4267. series.options.data[series.data.indexOf(point)] =
  4268. point.options;
  4269. if (point.graphic) {
  4270. point.graphic.attr({
  4271. visibility: pointVis
  4272. });
  4273. }
  4274. });
  4275. }
  4276. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  4277. });
  4278. columnProto.handle3dGrouping = true;
  4279. addEvent(Series, 'afterInit', function () {
  4280. if (this.chart.is3d() &&
  4281. this.handle3dGrouping) {
  4282. var series = this,
  4283. seriesOptions = this.options,
  4284. grouping = seriesOptions.grouping,
  4285. stacking = seriesOptions.stacking,
  4286. reversedStacks = pick(this.yAxis.options.reversedStacks,
  4287. true),
  4288. z = 0;
  4289. // @todo grouping === true ?
  4290. if (!(typeof grouping !== 'undefined' && !grouping)) {
  4291. var stacks = retrieveStacks(this.chart,
  4292. stacking),
  4293. stack = seriesOptions.stack || 0,
  4294. i; // position within the stack
  4295. for (i = 0; i < stacks[stack].series.length; i++) {
  4296. if (stacks[stack].series[i] === this) {
  4297. break;
  4298. }
  4299. }
  4300. z = (10 * (stacks.totalStacks - stacks[stack].position)) +
  4301. (reversedStacks ? i : -i); // #4369
  4302. // In case when axis is reversed, columns are also reversed inside
  4303. // the group (#3737)
  4304. if (!this.xAxis.reversed) {
  4305. z = (stacks.totalStacks * 10) - z;
  4306. }
  4307. }
  4308. seriesOptions.depth = seriesOptions.depth || 25;
  4309. series.z = series.z || 0;
  4310. seriesOptions.zIndex = z;
  4311. }
  4312. });
  4313. // eslint-disable-next-line valid-jsdoc
  4314. /**
  4315. * @private
  4316. */
  4317. function pointAttribs(proceed) {
  4318. var attr = proceed.apply(this,
  4319. [].slice.call(arguments, 1));
  4320. if (this.chart.is3d && this.chart.is3d()) {
  4321. // Set the fill color to the fill color to provide a smooth edge
  4322. attr.stroke = this.options.edgeColor || attr.fill;
  4323. attr['stroke-width'] = pick(this.options.edgeWidth, 1); // #4055
  4324. }
  4325. return attr;
  4326. }
  4327. // eslint-disable-next-line valid-jsdoc
  4328. /**
  4329. * In 3D mode, all column-series are rendered in one main group. Because of that
  4330. * we need to apply inactive state on all points.
  4331. * @private
  4332. */
  4333. function setState(proceed, state, inherit) {
  4334. var is3d = this.chart.is3d && this.chart.is3d();
  4335. if (is3d) {
  4336. this.options.inactiveOtherPoints = true;
  4337. }
  4338. proceed.call(this, state, inherit);
  4339. if (is3d) {
  4340. this.options.inactiveOtherPoints = false;
  4341. }
  4342. }
  4343. // eslint-disable-next-line valid-jsdoc
  4344. /**
  4345. * In 3D mode, simple checking for a new shape to animate is not enough.
  4346. * Additionally check if graphic is a group of elements
  4347. * @private
  4348. */
  4349. function hasNewShapeType(proceed) {
  4350. var args = [];
  4351. for (var _i = 1; _i < arguments.length; _i++) {
  4352. args[_i - 1] = arguments[_i];
  4353. }
  4354. return this.series.chart.is3d() ?
  4355. this.graphic && this.graphic.element.nodeName !== 'g' :
  4356. proceed.apply(this, args);
  4357. }
  4358. wrap(columnProto, 'pointAttribs', pointAttribs);
  4359. wrap(columnProto, 'setState', setState);
  4360. wrap(columnProto.pointClass.prototype, 'hasNewShapeType', hasNewShapeType);
  4361. if (BaseSeries.seriesTypes.columnRange) {
  4362. var columnRangeProto = BaseSeries.seriesTypes.columnrange.prototype;
  4363. wrap(columnRangeProto, 'pointAttribs', pointAttribs);
  4364. wrap(columnRangeProto, 'setState', setState);
  4365. wrap(columnRangeProto.pointClass.prototype, 'hasNewShapeType', hasNewShapeType);
  4366. columnRangeProto.plotGroup = columnProto.plotGroup;
  4367. columnRangeProto.setVisible = columnProto.setVisible;
  4368. }
  4369. wrap(Series.prototype, 'alignDataLabel', function (proceed, point, dataLabel, options, alignTo) {
  4370. var chart = this.chart;
  4371. // In 3D we need to pass point.outsidePlot option to the justifyDataLabel
  4372. // method for disabling justifying dataLabels in columns outside plot
  4373. options.outside3dPlot = point.outside3dPlot;
  4374. // Only do this for 3D columns and it's derived series
  4375. if (chart.is3d() &&
  4376. this.is('column')) {
  4377. var series = this,
  4378. seriesOptions = series.options,
  4379. inside = pick(options.inside, !!series.options.stacking),
  4380. options3d = chart.options.chart.options3d,
  4381. xOffset = point.pointWidth / 2 || 0;
  4382. var dLPosition = {
  4383. x: alignTo.x + xOffset,
  4384. y: alignTo.y,
  4385. z: series.z + seriesOptions.depth / 2
  4386. };
  4387. if (chart.inverted) {
  4388. // Inside dataLabels are positioned according to above
  4389. // logic and there is no need to position them using
  4390. // non-3D algorighm (that use alignTo.width)
  4391. if (inside) {
  4392. alignTo.width = 0;
  4393. dLPosition.x += point.shapeArgs.height / 2;
  4394. }
  4395. // When chart is upside down
  4396. // (alpha angle between 180 and 360 degrees)
  4397. // it is needed to add column width to calculated value.
  4398. if (options3d.alpha >= 90 && options3d.alpha <= 270) {
  4399. dLPosition.y += point.shapeArgs.width;
  4400. }
  4401. }
  4402. // dLPosition is recalculated for 3D graphs
  4403. dLPosition = perspective([dLPosition], chart, true, false)[0];
  4404. alignTo.x = dLPosition.x - xOffset;
  4405. // #7103 If point is outside of plotArea, hide data label.
  4406. alignTo.y = point.outside3dPlot ? -9e9 : dLPosition.y;
  4407. }
  4408. proceed.apply(this, [].slice.call(arguments, 1));
  4409. });
  4410. // Added stackLabels position calculation for 3D charts.
  4411. wrap(StackItem.prototype, 'getStackBox', function (proceed, chart, stackItem, x, y, xWidth, h, axis) {
  4412. var stackBox = proceed.apply(this,
  4413. [].slice.call(arguments, 1));
  4414. // Only do this for 3D graph
  4415. if (chart.is3d() && stackItem.base) {
  4416. // First element of stackItem.base is an index of base series.
  4417. var baseSeriesInd = +(stackItem.base).split(',')[0];
  4418. var columnSeries = chart.series[baseSeriesInd];
  4419. var options3d = chart.options.chart.options3d;
  4420. // Only do this if base series is a column or inherited type,
  4421. // use its barW, z and depth parameters
  4422. // for correct stackLabels position calculation
  4423. if (columnSeries &&
  4424. columnSeries instanceof BaseSeries.seriesTypes.column) {
  4425. var dLPosition = {
  4426. x: stackBox.x + (chart.inverted ? h : xWidth / 2),
  4427. y: stackBox.y,
  4428. z: columnSeries.options.depth / 2
  4429. };
  4430. if (chart.inverted) {
  4431. // Do not use default offset calculation logic
  4432. // for 3D inverted stackLabels.
  4433. stackBox.width = 0;
  4434. // When chart is upside down
  4435. // (alpha angle between 180 and 360 degrees)
  4436. // it is needed to add column width to calculated value.
  4437. if (options3d.alpha >= 90 && options3d.alpha <= 270) {
  4438. dLPosition.y += xWidth;
  4439. }
  4440. }
  4441. dLPosition = perspective([dLPosition], chart, true, false)[0];
  4442. stackBox.x = dLPosition.x - xWidth / 2;
  4443. stackBox.y = dLPosition.y;
  4444. }
  4445. }
  4446. return stackBox;
  4447. });
  4448. /*
  4449. @merge v6.2
  4450. @todo
  4451. EXTENSION FOR 3D CYLINDRICAL COLUMNS
  4452. Not supported
  4453. */
  4454. /*
  4455. var defaultOptions = H.getOptions();
  4456. defaultOptions.plotOptions.cylinder =
  4457. merge(defaultOptions.plotOptions.column);
  4458. var CylinderSeries = extendClass(seriesTypes.column, {
  4459. type: 'cylinder'
  4460. });
  4461. seriesTypes.cylinder = CylinderSeries;
  4462. wrap(seriesTypes.cylinder.prototype, 'translate', function (proceed) {
  4463. proceed.apply(this, [].slice.call(arguments, 1));
  4464. // Do not do this if the chart is not 3D
  4465. if (!this.chart.is3d()) {
  4466. return;
  4467. }
  4468. var series = this,
  4469. chart = series.chart,
  4470. options = chart.options,
  4471. cylOptions = options.plotOptions.cylinder,
  4472. options3d = options.chart.options3d,
  4473. depth = cylOptions.depth || 0,
  4474. alpha = chart.alpha3d;
  4475. var z = cylOptions.stacking ?
  4476. (this.options.stack || 0) * depth :
  4477. series._i * depth;
  4478. z += depth / 2;
  4479. if (cylOptions.grouping !== false) { z = 0; }
  4480. each(series.data, function (point) {
  4481. var shapeArgs = point.shapeArgs,
  4482. deg2rad = H.deg2rad;
  4483. point.shapeType = 'arc3d';
  4484. shapeArgs.x += depth / 2;
  4485. shapeArgs.z = z;
  4486. shapeArgs.start = 0;
  4487. shapeArgs.end = 2 * PI;
  4488. shapeArgs.r = depth * 0.95;
  4489. shapeArgs.innerR = 0;
  4490. shapeArgs.depth =
  4491. shapeArgs.height * (1 / sin((90 - alpha) * deg2rad)) - z;
  4492. shapeArgs.alpha = 90 - alpha;
  4493. shapeArgs.beta = 0;
  4494. });
  4495. });
  4496. */
  4497. });
  4498. _registerModule(_modules, 'Series/Pie3DSeries.js', [_modules['Core/Series/Series.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (BaseSeries, H, U) {
  4499. /* *
  4500. *
  4501. * (c) 2010-2020 Torstein Honsi
  4502. *
  4503. * 3D pie series
  4504. *
  4505. * License: www.highcharts.com/license
  4506. *
  4507. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4508. *
  4509. * */
  4510. var deg2rad = H.deg2rad,
  4511. svg = H.svg;
  4512. var pick = U.pick,
  4513. wrap = U.wrap;
  4514. var seriesTypes = BaseSeries.seriesTypes;
  4515. /**
  4516. * The thickness of a 3D pie.
  4517. *
  4518. * @type {number}
  4519. * @default 0
  4520. * @since 4.0
  4521. * @product highcharts
  4522. * @requires highcharts-3d
  4523. * @apioption plotOptions.pie.depth
  4524. */
  4525. /* eslint-disable no-invalid-this */
  4526. wrap(seriesTypes.pie.prototype, 'translate', function (proceed) {
  4527. proceed.apply(this, [].slice.call(arguments, 1));
  4528. // Do not do this if the chart is not 3D
  4529. if (!this.chart.is3d()) {
  4530. return;
  4531. }
  4532. var series = this,
  4533. seriesOptions = series.options,
  4534. depth = seriesOptions.depth || 0,
  4535. options3d = series.chart.options.chart.options3d,
  4536. alpha = options3d.alpha,
  4537. beta = options3d.beta,
  4538. z = seriesOptions.stacking ?
  4539. (seriesOptions.stack || 0) * depth :
  4540. series._i * depth;
  4541. z += depth / 2;
  4542. if (seriesOptions.grouping !== false) {
  4543. z = 0;
  4544. }
  4545. series.data.forEach(function (point) {
  4546. var shapeArgs = point.shapeArgs,
  4547. angle;
  4548. point.shapeType = 'arc3d';
  4549. shapeArgs.z = z;
  4550. shapeArgs.depth = depth * 0.75;
  4551. shapeArgs.alpha = alpha;
  4552. shapeArgs.beta = beta;
  4553. shapeArgs.center = series.center;
  4554. angle = (shapeArgs.end + shapeArgs.start) / 2;
  4555. point.slicedTranslation = {
  4556. translateX: Math.round(Math.cos(angle) *
  4557. seriesOptions.slicedOffset *
  4558. Math.cos(alpha * deg2rad)),
  4559. translateY: Math.round(Math.sin(angle) *
  4560. seriesOptions.slicedOffset *
  4561. Math.cos(alpha * deg2rad))
  4562. };
  4563. });
  4564. });
  4565. wrap(seriesTypes.pie.prototype.pointClass.prototype, 'haloPath', function (proceed) {
  4566. var args = arguments;
  4567. return this.series.chart.is3d() ? [] : proceed.call(this, args[1]);
  4568. });
  4569. wrap(seriesTypes.pie.prototype, 'pointAttribs', function (proceed, point, state) {
  4570. var attr = proceed.call(this,
  4571. point,
  4572. state),
  4573. options = this.options;
  4574. if (this.chart.is3d() && !this.chart.styledMode) {
  4575. attr.stroke = options.edgeColor || point.color || this.color;
  4576. attr['stroke-width'] = pick(options.edgeWidth, 1);
  4577. }
  4578. return attr;
  4579. });
  4580. wrap(seriesTypes.pie.prototype, 'drawDataLabels', function (proceed) {
  4581. if (this.chart.is3d()) {
  4582. var series = this,
  4583. chart = series.chart,
  4584. options3d = chart.options.chart.options3d;
  4585. series.data.forEach(function (point) {
  4586. var shapeArgs = point.shapeArgs,
  4587. r = shapeArgs.r,
  4588. // #3240 issue with datalabels for 0 and null values
  4589. a1 = (shapeArgs.alpha || options3d.alpha) * deg2rad,
  4590. b1 = (shapeArgs.beta || options3d.beta) * deg2rad,
  4591. a2 = (shapeArgs.start + shapeArgs.end) / 2,
  4592. labelPosition = point.labelPosition,
  4593. connectorPosition = labelPosition.connectorPosition,
  4594. yOffset = (-r * (1 - Math.cos(a1)) * Math.sin(a2)),
  4595. xOffset = r * (Math.cos(b1) - 1) * Math.cos(a2);
  4596. // Apply perspective on label positions
  4597. [
  4598. labelPosition.natural,
  4599. connectorPosition.breakAt,
  4600. connectorPosition.touchingSliceAt
  4601. ].forEach(function (coordinates) {
  4602. coordinates.x += xOffset;
  4603. coordinates.y += yOffset;
  4604. });
  4605. });
  4606. }
  4607. proceed.apply(this, [].slice.call(arguments, 1));
  4608. });
  4609. wrap(seriesTypes.pie.prototype, 'addPoint', function (proceed) {
  4610. proceed.apply(this, [].slice.call(arguments, 1));
  4611. if (this.chart.is3d()) {
  4612. // destroy (and rebuild) everything!!!
  4613. this.update(this.userOptions, true); // #3845 pass the old options
  4614. }
  4615. });
  4616. wrap(seriesTypes.pie.prototype, 'animate', function (proceed) {
  4617. if (!this.chart.is3d()) {
  4618. proceed.apply(this, [].slice.call(arguments, 1));
  4619. }
  4620. else {
  4621. var args = arguments,
  4622. init = args[1],
  4623. animation = this.options.animation,
  4624. attribs,
  4625. center = this.center,
  4626. group = this.group,
  4627. markerGroup = this.markerGroup;
  4628. if (svg) { // VML is too slow anyway
  4629. if (animation === true) {
  4630. animation = {};
  4631. }
  4632. // Initialize the animation
  4633. if (init) {
  4634. // Scale down the group and place it in the center
  4635. group.oldtranslateX = pick(group.oldtranslateX, group.translateX);
  4636. group.oldtranslateY = pick(group.oldtranslateY, group.translateY);
  4637. attribs = {
  4638. translateX: center[0],
  4639. translateY: center[1],
  4640. scaleX: 0.001,
  4641. scaleY: 0.001
  4642. };
  4643. group.attr(attribs);
  4644. if (markerGroup) {
  4645. markerGroup.attrSetters = group.attrSetters;
  4646. markerGroup.attr(attribs);
  4647. }
  4648. // Run the animation
  4649. }
  4650. else {
  4651. attribs = {
  4652. translateX: group.oldtranslateX,
  4653. translateY: group.oldtranslateY,
  4654. scaleX: 1,
  4655. scaleY: 1
  4656. };
  4657. group.animate(attribs, animation);
  4658. if (markerGroup) {
  4659. markerGroup.animate(attribs, animation);
  4660. }
  4661. }
  4662. }
  4663. }
  4664. });
  4665. });
  4666. _registerModule(_modules, 'Series/Scatter3DSeries.js', [_modules['Core/Series/Series.js'], _modules['Extensions/Math3D.js'], _modules['Core/Series/Point.js']], function (BaseSeries, Math3D, Point) {
  4667. /* *
  4668. *
  4669. * (c) 2010-2020 Torstein Honsi
  4670. *
  4671. * Scatter 3D series.
  4672. *
  4673. * License: www.highcharts.com/license
  4674. *
  4675. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4676. *
  4677. * */
  4678. var seriesTypes = BaseSeries.seriesTypes;
  4679. var pointCameraDistance = Math3D.pointCameraDistance;
  4680. /**
  4681. * @private
  4682. * @class
  4683. * @name Highcharts.seriesTypes.scatter3d
  4684. *
  4685. * @augments Highcharts.Series
  4686. */
  4687. BaseSeries.seriesType('scatter3d', 'scatter',
  4688. /**
  4689. * A 3D scatter plot uses x, y and z coordinates to display values for three
  4690. * variables for a set of data.
  4691. *
  4692. * @sample {highcharts} highcharts/3d/scatter/
  4693. * Simple 3D scatter
  4694. * @sample {highcharts} highcharts/demo/3d-scatter-draggable
  4695. * Draggable 3d scatter
  4696. *
  4697. * @extends plotOptions.scatter
  4698. * @excluding dragDrop, cluster, boostThreshold, boostBlending
  4699. * @product highcharts
  4700. * @requires highcharts-3d
  4701. * @optionparent plotOptions.scatter3d
  4702. */
  4703. {
  4704. tooltip: {
  4705. pointFormat: 'x: <b>{point.x}</b><br/>y: <b>{point.y}</b><br/>z: <b>{point.z}</b><br/>'
  4706. }
  4707. // Series class
  4708. }, {
  4709. pointAttribs: function (point) {
  4710. var attribs = seriesTypes.scatter.prototype.pointAttribs
  4711. .apply(this,
  4712. arguments);
  4713. if (this.chart.is3d() && point) {
  4714. attribs.zIndex =
  4715. pointCameraDistance(point, this.chart);
  4716. }
  4717. return attribs;
  4718. },
  4719. axisTypes: ['xAxis', 'yAxis', 'zAxis'],
  4720. pointArrayMap: ['x', 'y', 'z'],
  4721. parallelArrays: ['x', 'y', 'z'],
  4722. // Require direct touch rather than using the k-d-tree, because the
  4723. // k-d-tree currently doesn't take the xyz coordinate system into
  4724. // account (#4552)
  4725. directTouch: true
  4726. // Point class
  4727. }, {
  4728. applyOptions: function () {
  4729. Point.prototype.applyOptions.apply(this, arguments);
  4730. if (typeof this.z === 'undefined') {
  4731. this.z = 0;
  4732. }
  4733. return this;
  4734. }
  4735. });
  4736. /**
  4737. * A `scatter3d` series. If the [type](#series.scatter3d.type) option is
  4738. * not specified, it is inherited from [chart.type](#chart.type).
  4739. *
  4740. * scatter3d](#plotOptions.scatter3d).
  4741. *
  4742. * @extends series,plotOptions.scatter3d
  4743. * @excluding boostThreshold, boostBlending
  4744. * @product highcharts
  4745. * @requires highcharts-3d
  4746. * @apioption series.scatter3d
  4747. */
  4748. /**
  4749. * An array of data points for the series. For the `scatter3d` series
  4750. * type, points can be given in the following ways:
  4751. *
  4752. * 1. An array of arrays with 3 values. In this case, the values correspond
  4753. * to `x,y,z`. If the first value is a string, it is applied as the name
  4754. * of the point, and the `x` value is inferred.
  4755. *
  4756. * ```js
  4757. * data: [
  4758. * [0, 0, 1],
  4759. * [1, 8, 7],
  4760. * [2, 9, 2]
  4761. * ]
  4762. * ```
  4763. *
  4764. * 3. An array of objects with named values. The following snippet shows only a
  4765. * few settings, see the complete options set below. If the total number of data
  4766. * points exceeds the series'
  4767. * [turboThreshold](#series.scatter3d.turboThreshold), this option is not
  4768. * available.
  4769. *
  4770. * ```js
  4771. * data: [{
  4772. * x: 1,
  4773. * y: 2,
  4774. * z: 24,
  4775. * name: "Point2",
  4776. * color: "#00FF00"
  4777. * }, {
  4778. * x: 1,
  4779. * y: 4,
  4780. * z: 12,
  4781. * name: "Point1",
  4782. * color: "#FF00FF"
  4783. * }]
  4784. * ```
  4785. *
  4786. * @sample {highcharts} highcharts/chart/reflow-true/
  4787. * Numerical values
  4788. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  4789. * Arrays of numeric x and y
  4790. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  4791. * Arrays of datetime x and y
  4792. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  4793. * Arrays of point.name and y
  4794. * @sample {highcharts} highcharts/series/data-array-of-objects/
  4795. * Config objects
  4796. *
  4797. * @type {Array<Array<number>|*>}
  4798. * @extends series.scatter.data
  4799. * @product highcharts
  4800. * @apioption series.scatter3d.data
  4801. */
  4802. /**
  4803. * The z value for each data point.
  4804. *
  4805. * @type {number}
  4806. * @product highcharts
  4807. * @apioption series.scatter3d.data.z
  4808. */
  4809. ''; // adds doclets above to transpiled file
  4810. });
  4811. _registerModule(_modules, 'masters/highcharts-3d.src.js', [], function () {
  4812. });
  4813. }));