highcharts-3d.src.js 209 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892
  1. /**
  2. * @license Highcharts JS v8.2.0 (2020-08-20)
  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/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 (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 color = Color.parse;
  306. var perspective = Math3D.perspective,
  307. shapeArea = Math3D.shapeArea;
  308. var animObject = U.animObject,
  309. 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. });
  1276. _registerModule(_modules, 'Core/Axis/Tick3D.js', [_modules['Core/Utilities.js']], function (U) {
  1277. /* *
  1278. *
  1279. * (c) 2010-2020 Torstein Honsi
  1280. *
  1281. * Extenstion for 3d axes
  1282. *
  1283. * License: www.highcharts.com/license
  1284. *
  1285. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1286. *
  1287. * */
  1288. var addEvent = U.addEvent,
  1289. extend = U.extend,
  1290. wrap = U.wrap;
  1291. /* eslint-disable valid-jsdoc */
  1292. /**
  1293. * Tick with 3D support
  1294. * @private
  1295. * @class
  1296. */
  1297. var Tick3D = /** @class */ (function () {
  1298. function Tick3D() {
  1299. }
  1300. /* *
  1301. *
  1302. * Static Functions
  1303. *
  1304. * */
  1305. /**
  1306. * @private
  1307. */
  1308. Tick3D.compose = function (TickClass) {
  1309. addEvent(TickClass, 'afterGetLabelPosition', Tick3D.onAfterGetLabelPosition);
  1310. var tickProto = TickClass.prototype;
  1311. wrap(tickProto, 'getMarkPath', Tick3D.wrapGetMarkPath);
  1312. };
  1313. /**
  1314. * @private
  1315. */
  1316. Tick3D.onAfterGetLabelPosition = function (e) {
  1317. var axis3D = this.axis.axis3D;
  1318. if (axis3D) {
  1319. extend(e.pos, axis3D.fix3dPosition(e.pos));
  1320. }
  1321. };
  1322. /**
  1323. * @private
  1324. */
  1325. Tick3D.wrapGetMarkPath = function (proceed) {
  1326. var chart = this.axis.chart;
  1327. var axis3D = this.axis.axis3D;
  1328. var path = proceed.apply(this,
  1329. [].slice.call(arguments, 1));
  1330. if (axis3D) {
  1331. var start = path[0];
  1332. var end = path[1];
  1333. if (start[0] === 'M' && end[0] === 'L') {
  1334. var pArr = [
  1335. axis3D.fix3dPosition({ x: start[1],
  1336. y: start[2],
  1337. z: 0 }),
  1338. axis3D.fix3dPosition({ x: end[1],
  1339. y: end[2],
  1340. z: 0 })
  1341. ];
  1342. return this.axis.chart.renderer.toLineSegments(pArr);
  1343. }
  1344. }
  1345. return path;
  1346. };
  1347. return Tick3D;
  1348. }());
  1349. return Tick3D;
  1350. });
  1351. _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) {
  1352. /* *
  1353. *
  1354. * (c) 2010-2020 Torstein Honsi
  1355. *
  1356. * Extenstion for 3d axes
  1357. *
  1358. * License: www.highcharts.com/license
  1359. *
  1360. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1361. *
  1362. * */
  1363. var perspective = Math3D.perspective,
  1364. perspective3D = Math3D.perspective3D,
  1365. shapeArea = Math3D.shapeArea;
  1366. var addEvent = U.addEvent,
  1367. merge = U.merge,
  1368. pick = U.pick,
  1369. wrap = U.wrap;
  1370. var deg2rad = H.deg2rad;
  1371. /* eslint-disable valid-jsdoc */
  1372. /**
  1373. * Adds 3D support to axes.
  1374. * @private
  1375. * @class
  1376. */
  1377. var Axis3DAdditions = /** @class */ (function () {
  1378. /* *
  1379. *
  1380. * Constructors
  1381. *
  1382. * */
  1383. /**
  1384. * @private
  1385. */
  1386. function Axis3DAdditions(axis) {
  1387. this.axis = axis;
  1388. }
  1389. /* *
  1390. *
  1391. * Functions
  1392. *
  1393. * */
  1394. /**
  1395. * @private
  1396. * @param {Highcharts.Axis} axis
  1397. * Related axis.
  1398. * @param {Highcharts.Position3dObject} pos
  1399. * Position to fix.
  1400. * @param {boolean} [isTitle]
  1401. * Whether this is a title position.
  1402. * @return {Highcharts.Position3dObject}
  1403. * Fixed position.
  1404. */
  1405. Axis3DAdditions.prototype.fix3dPosition = function (pos, isTitle) {
  1406. var axis3D = this;
  1407. var axis = axis3D.axis;
  1408. var chart = axis.chart;
  1409. // Do not do this if the chart is not 3D
  1410. if (axis.coll === 'colorAxis' ||
  1411. !chart.chart3d ||
  1412. !chart.is3d()) {
  1413. return pos;
  1414. }
  1415. var alpha = deg2rad * chart.options.chart.options3d.alpha,
  1416. beta = deg2rad * chart.options.chart.options3d.beta,
  1417. positionMode = pick(isTitle && axis.options.title.position3d,
  1418. axis.options.labels.position3d),
  1419. skew = pick(isTitle && axis.options.title.skew3d,
  1420. axis.options.labels.skew3d),
  1421. frame = chart.chart3d.frame3d,
  1422. plotLeft = chart.plotLeft,
  1423. plotRight = chart.plotWidth + plotLeft,
  1424. plotTop = chart.plotTop,
  1425. plotBottom = chart.plotHeight + plotTop,
  1426. // Indicates that we are labelling an X or Z axis on the "back" of
  1427. // the chart
  1428. reverseFlap = false,
  1429. offsetX = 0,
  1430. offsetY = 0,
  1431. vecX,
  1432. vecY = { x: 0,
  1433. y: 1,
  1434. z: 0 };
  1435. pos = axis.axis3D.swapZ({ x: pos.x, y: pos.y, z: 0 });
  1436. if (axis.isZAxis) { // Z Axis
  1437. if (axis.opposite) {
  1438. if (frame.axes.z.top === null) {
  1439. return {};
  1440. }
  1441. offsetY = pos.y - plotTop;
  1442. pos.x = frame.axes.z.top.x;
  1443. pos.y = frame.axes.z.top.y;
  1444. vecX = frame.axes.z.top.xDir;
  1445. reverseFlap = !frame.top.frontFacing;
  1446. }
  1447. else {
  1448. if (frame.axes.z.bottom === null) {
  1449. return {};
  1450. }
  1451. offsetY = pos.y - plotBottom;
  1452. pos.x = frame.axes.z.bottom.x;
  1453. pos.y = frame.axes.z.bottom.y;
  1454. vecX = frame.axes.z.bottom.xDir;
  1455. reverseFlap = !frame.bottom.frontFacing;
  1456. }
  1457. }
  1458. else if (axis.horiz) { // X Axis
  1459. if (axis.opposite) {
  1460. if (frame.axes.x.top === null) {
  1461. return {};
  1462. }
  1463. offsetY = pos.y - plotTop;
  1464. pos.y = frame.axes.x.top.y;
  1465. pos.z = frame.axes.x.top.z;
  1466. vecX = frame.axes.x.top.xDir;
  1467. reverseFlap = !frame.top.frontFacing;
  1468. }
  1469. else {
  1470. if (frame.axes.x.bottom === null) {
  1471. return {};
  1472. }
  1473. offsetY = pos.y - plotBottom;
  1474. pos.y = frame.axes.x.bottom.y;
  1475. pos.z = frame.axes.x.bottom.z;
  1476. vecX = frame.axes.x.bottom.xDir;
  1477. reverseFlap = !frame.bottom.frontFacing;
  1478. }
  1479. }
  1480. else { // Y Axis
  1481. if (axis.opposite) {
  1482. if (frame.axes.y.right === null) {
  1483. return {};
  1484. }
  1485. offsetX = pos.x - plotRight;
  1486. pos.x = frame.axes.y.right.x;
  1487. pos.z = frame.axes.y.right.z;
  1488. vecX = frame.axes.y.right.xDir;
  1489. // Rotate 90º on opposite edge
  1490. vecX = { x: vecX.z, y: vecX.y, z: -vecX.x };
  1491. }
  1492. else {
  1493. if (frame.axes.y.left === null) {
  1494. return {};
  1495. }
  1496. offsetX = pos.x - plotLeft;
  1497. pos.x = frame.axes.y.left.x;
  1498. pos.z = frame.axes.y.left.z;
  1499. vecX = frame.axes.y.left.xDir;
  1500. }
  1501. }
  1502. if (positionMode === 'chart') {
  1503. // Labels preserve their direction relative to the chart
  1504. // nothing to do
  1505. }
  1506. else if (positionMode === 'flap') {
  1507. // Labels are rotated around the axis direction to face the screen
  1508. if (!axis.horiz) { // Y Axis
  1509. vecX = { x: Math.cos(beta), y: 0, z: Math.sin(beta) };
  1510. }
  1511. else { // X and Z Axis
  1512. var sin = Math.sin(alpha);
  1513. var cos = Math.cos(alpha);
  1514. if (axis.opposite) {
  1515. sin = -sin;
  1516. }
  1517. if (reverseFlap) {
  1518. sin = -sin;
  1519. }
  1520. vecY = { x: vecX.z * sin, y: cos, z: -vecX.x * sin };
  1521. }
  1522. }
  1523. else if (positionMode === 'ortho') {
  1524. // Labels will be rotated to be ortogonal to the axis
  1525. if (!axis.horiz) { // Y Axis
  1526. vecX = { x: Math.cos(beta), y: 0, z: Math.sin(beta) };
  1527. }
  1528. else { // X and Z Axis
  1529. var sina = Math.sin(alpha);
  1530. var cosa = Math.cos(alpha);
  1531. var sinb = Math.sin(beta);
  1532. var cosb = Math.cos(beta);
  1533. var vecZ = { x: sinb * cosa,
  1534. y: -sina,
  1535. z: -cosa * cosb };
  1536. vecY = {
  1537. x: vecX.y * vecZ.z - vecX.z * vecZ.y,
  1538. y: vecX.z * vecZ.x - vecX.x * vecZ.z,
  1539. z: vecX.x * vecZ.y - vecX.y * vecZ.x
  1540. };
  1541. var scale = 1 / Math.sqrt(vecY.x * vecY.x + vecY.y * vecY.y + vecY.z * vecY.z);
  1542. if (reverseFlap) {
  1543. scale = -scale;
  1544. }
  1545. vecY = { x: scale * vecY.x, y: scale * vecY.y, z: scale * vecY.z };
  1546. }
  1547. }
  1548. else { // positionMode == 'offset'
  1549. // Labels will be skewd to maintain vertical / horizontal offsets
  1550. // from axis
  1551. if (!axis.horiz) { // Y Axis
  1552. vecX = { x: Math.cos(beta), y: 0, z: Math.sin(beta) };
  1553. }
  1554. else { // X and Z Axis
  1555. vecY = {
  1556. x: Math.sin(beta) * Math.sin(alpha),
  1557. y: Math.cos(alpha),
  1558. z: -Math.cos(beta) * Math.sin(alpha)
  1559. };
  1560. }
  1561. }
  1562. pos.x += offsetX * vecX.x + offsetY * vecY.x;
  1563. pos.y += offsetX * vecX.y + offsetY * vecY.y;
  1564. pos.z += offsetX * vecX.z + offsetY * vecY.z;
  1565. var projected = perspective([pos],
  1566. axis.chart)[0];
  1567. if (skew) {
  1568. // Check if the label text would be mirrored
  1569. var isMirrored = shapeArea(perspective([
  1570. pos,
  1571. { x: pos.x + vecX.x,
  1572. y: pos.y + vecX.y,
  1573. z: pos.z + vecX.z },
  1574. { x: pos.x + vecY.x,
  1575. y: pos.y + vecY.y,
  1576. z: pos.z + vecY.z }
  1577. ],
  1578. axis.chart)) < 0;
  1579. if (isMirrored) {
  1580. vecX = { x: -vecX.x, y: -vecX.y, z: -vecX.z };
  1581. }
  1582. var pointsProjected = perspective([
  1583. { x: pos.x,
  1584. y: pos.y,
  1585. z: pos.z },
  1586. { x: pos.x + vecX.x,
  1587. y: pos.y + vecX.y,
  1588. z: pos.z + vecX.z },
  1589. { x: pos.x + vecY.x,
  1590. y: pos.y + vecY.y,
  1591. z: pos.z + vecY.z }
  1592. ],
  1593. axis.chart);
  1594. projected.matrix = [
  1595. pointsProjected[1].x - pointsProjected[0].x,
  1596. pointsProjected[1].y - pointsProjected[0].y,
  1597. pointsProjected[2].x - pointsProjected[0].x,
  1598. pointsProjected[2].y - pointsProjected[0].y,
  1599. projected.x,
  1600. projected.y
  1601. ];
  1602. projected.matrix[4] -= projected.x * projected.matrix[0] +
  1603. projected.y * projected.matrix[2];
  1604. projected.matrix[5] -= projected.x * projected.matrix[1] +
  1605. projected.y * projected.matrix[3];
  1606. }
  1607. return projected;
  1608. };
  1609. /**
  1610. * @private
  1611. */
  1612. Axis3DAdditions.prototype.swapZ = function (p, insidePlotArea) {
  1613. var axis = this.axis;
  1614. if (axis.isZAxis) {
  1615. var plotLeft = insidePlotArea ? 0 : axis.chart.plotLeft;
  1616. return {
  1617. x: plotLeft + p.z,
  1618. y: p.y,
  1619. z: p.x - plotLeft
  1620. };
  1621. }
  1622. return p;
  1623. };
  1624. return Axis3DAdditions;
  1625. }());
  1626. /**
  1627. * Axis with 3D support.
  1628. * @private
  1629. * @class
  1630. */
  1631. var Axis3D = /** @class */ (function () {
  1632. function Axis3D() {
  1633. }
  1634. /* *
  1635. *
  1636. * Static Functions
  1637. *
  1638. * */
  1639. /**
  1640. * Extends axis class with 3D support.
  1641. * @private
  1642. */
  1643. Axis3D.compose = function (AxisClass) {
  1644. merge(true, AxisClass.defaultOptions, Axis3D.defaultOptions);
  1645. AxisClass.keepProps.push('axis3D');
  1646. addEvent(AxisClass, 'init', Axis3D.onInit);
  1647. addEvent(AxisClass, 'afterSetOptions', Axis3D.onAfterSetOptions);
  1648. addEvent(AxisClass, 'drawCrosshair', Axis3D.onDrawCrosshair);
  1649. addEvent(AxisClass, 'destroy', Axis3D.onDestroy);
  1650. var axisProto = AxisClass.prototype;
  1651. wrap(axisProto, 'getLinePath', Axis3D.wrapGetLinePath);
  1652. wrap(axisProto, 'getPlotBandPath', Axis3D.wrapGetPlotBandPath);
  1653. wrap(axisProto, 'getPlotLinePath', Axis3D.wrapGetPlotLinePath);
  1654. wrap(axisProto, 'getSlotWidth', Axis3D.wrapGetSlotWidth);
  1655. wrap(axisProto, 'getTitlePosition', Axis3D.wrapGetTitlePosition);
  1656. Tick3D.compose(Tick);
  1657. };
  1658. /**
  1659. * @private
  1660. */
  1661. Axis3D.onAfterSetOptions = function () {
  1662. var axis = this;
  1663. var chart = axis.chart;
  1664. var options = axis.options;
  1665. if (chart.is3d && chart.is3d() && axis.coll !== 'colorAxis') {
  1666. options.tickWidth = pick(options.tickWidth, 0);
  1667. options.gridLineWidth = pick(options.gridLineWidth, 1);
  1668. }
  1669. };
  1670. /**
  1671. * @private
  1672. */
  1673. Axis3D.onDestroy = function () {
  1674. ['backFrame', 'bottomFrame', 'sideFrame'].forEach(function (prop) {
  1675. if (this[prop]) {
  1676. this[prop] = this[prop].destroy();
  1677. }
  1678. }, this);
  1679. };
  1680. /**
  1681. * @private
  1682. */
  1683. Axis3D.onDrawCrosshair = function (e) {
  1684. var axis = this;
  1685. if (axis.chart.is3d() &&
  1686. axis.coll !== 'colorAxis') {
  1687. if (e.point) {
  1688. e.point.crosshairPos = axis.isXAxis ?
  1689. e.point.axisXpos :
  1690. axis.len - e.point.axisYpos;
  1691. }
  1692. }
  1693. };
  1694. /**
  1695. * @private
  1696. */
  1697. Axis3D.onInit = function () {
  1698. var axis = this;
  1699. if (!axis.axis3D) {
  1700. axis.axis3D = new Axis3DAdditions(axis);
  1701. }
  1702. };
  1703. /**
  1704. * Do not draw axislines in 3D.
  1705. * @private
  1706. */
  1707. Axis3D.wrapGetLinePath = function (proceed) {
  1708. var axis = this;
  1709. // Do not do this if the chart is not 3D
  1710. if (!axis.chart.is3d() || axis.coll === 'colorAxis') {
  1711. return proceed.apply(axis, [].slice.call(arguments, 1));
  1712. }
  1713. return [];
  1714. };
  1715. /**
  1716. * @private
  1717. */
  1718. Axis3D.wrapGetPlotBandPath = function (proceed) {
  1719. // Do not do this if the chart is not 3D
  1720. if (!this.chart.is3d() || this.coll === 'colorAxis') {
  1721. return proceed.apply(this, [].slice.call(arguments, 1));
  1722. }
  1723. var args = arguments,
  1724. from = args[1],
  1725. to = args[2],
  1726. path = [],
  1727. fromPath = this.getPlotLinePath({ value: from }),
  1728. toPath = this.getPlotLinePath({ value: to });
  1729. if (fromPath && toPath) {
  1730. for (var i = 0; i < fromPath.length; i += 2) {
  1731. var fromStartSeg = fromPath[i],
  1732. fromEndSeg = fromPath[i + 1],
  1733. toStartSeg = toPath[i],
  1734. toEndSeg = toPath[i + 1];
  1735. if (fromStartSeg[0] === 'M' &&
  1736. fromEndSeg[0] === 'L' &&
  1737. toStartSeg[0] === 'M' &&
  1738. toEndSeg[0] === 'L') {
  1739. path.push(fromStartSeg, fromEndSeg, toEndSeg,
  1740. // lineTo instead of moveTo
  1741. ['L', toStartSeg[1], toStartSeg[2]], ['Z']);
  1742. }
  1743. }
  1744. }
  1745. return path;
  1746. };
  1747. /**
  1748. * @private
  1749. */
  1750. Axis3D.wrapGetPlotLinePath = function (proceed) {
  1751. var axis = this;
  1752. var axis3D = axis.axis3D;
  1753. var chart = axis.chart;
  1754. var path = proceed.apply(axis,
  1755. [].slice.call(arguments, 1));
  1756. // Do not do this if the chart is not 3D
  1757. if (axis.coll === 'colorAxis' ||
  1758. !chart.chart3d ||
  1759. !chart.is3d()) {
  1760. return path;
  1761. }
  1762. if (path === null) {
  1763. return path;
  1764. }
  1765. var options3d = chart.options.chart.options3d,
  1766. d = axis.isZAxis ? chart.plotWidth : options3d.depth,
  1767. frame = chart.chart3d.frame3d,
  1768. startSegment = path[0],
  1769. endSegment = path[1],
  1770. pArr,
  1771. pathSegments = [];
  1772. if (startSegment[0] === 'M' && endSegment[0] === 'L') {
  1773. pArr = [
  1774. axis3D.swapZ({ x: startSegment[1], y: startSegment[2], z: 0 }),
  1775. axis3D.swapZ({ x: startSegment[1], y: startSegment[2], z: d }),
  1776. axis3D.swapZ({ x: endSegment[1], y: endSegment[2], z: 0 }),
  1777. axis3D.swapZ({ x: endSegment[1], y: endSegment[2], z: d })
  1778. ];
  1779. if (!this.horiz) { // Y-Axis
  1780. if (frame.front.visible) {
  1781. pathSegments.push(pArr[0], pArr[2]);
  1782. }
  1783. if (frame.back.visible) {
  1784. pathSegments.push(pArr[1], pArr[3]);
  1785. }
  1786. if (frame.left.visible) {
  1787. pathSegments.push(pArr[0], pArr[1]);
  1788. }
  1789. if (frame.right.visible) {
  1790. pathSegments.push(pArr[2], pArr[3]);
  1791. }
  1792. }
  1793. else if (this.isZAxis) { // Z-Axis
  1794. if (frame.left.visible) {
  1795. pathSegments.push(pArr[0], pArr[2]);
  1796. }
  1797. if (frame.right.visible) {
  1798. pathSegments.push(pArr[1], pArr[3]);
  1799. }
  1800. if (frame.top.visible) {
  1801. pathSegments.push(pArr[0], pArr[1]);
  1802. }
  1803. if (frame.bottom.visible) {
  1804. pathSegments.push(pArr[2], pArr[3]);
  1805. }
  1806. }
  1807. else { // X-Axis
  1808. if (frame.front.visible) {
  1809. pathSegments.push(pArr[0], pArr[2]);
  1810. }
  1811. if (frame.back.visible) {
  1812. pathSegments.push(pArr[1], pArr[3]);
  1813. }
  1814. if (frame.top.visible) {
  1815. pathSegments.push(pArr[0], pArr[1]);
  1816. }
  1817. if (frame.bottom.visible) {
  1818. pathSegments.push(pArr[2], pArr[3]);
  1819. }
  1820. }
  1821. pathSegments = perspective(pathSegments, this.chart, false);
  1822. }
  1823. return chart.renderer.toLineSegments(pathSegments);
  1824. };
  1825. /**
  1826. * Wrap getSlotWidth function to calculate individual width value for each
  1827. * slot (#8042).
  1828. * @private
  1829. */
  1830. Axis3D.wrapGetSlotWidth = function (proceed, tick) {
  1831. var axis = this;
  1832. var chart = axis.chart;
  1833. var ticks = axis.ticks;
  1834. var gridGroup = axis.gridGroup;
  1835. if (axis.categories &&
  1836. chart.frameShapes &&
  1837. chart.is3d() &&
  1838. gridGroup &&
  1839. tick &&
  1840. tick.label) {
  1841. var firstGridLine = gridGroup.element.childNodes[0].getBBox(),
  1842. frame3DLeft = chart.frameShapes.left.getBBox(),
  1843. options3d = chart.options.chart.options3d,
  1844. origin = {
  1845. x: chart.plotWidth / 2,
  1846. y: chart.plotHeight / 2,
  1847. z: options3d.depth / 2,
  1848. vd: pick(options3d.depth, 1) * pick(options3d.viewDistance, 0)
  1849. },
  1850. labelPos,
  1851. prevLabelPos,
  1852. nextLabelPos,
  1853. slotWidth,
  1854. tickId = tick.pos,
  1855. prevTick = ticks[tickId - 1],
  1856. nextTick = ticks[tickId + 1];
  1857. // Check whether the tick is not the first one and previous tick
  1858. // exists, then calculate position of previous label.
  1859. if (tickId !== 0 && prevTick && prevTick.label.xy) {
  1860. prevLabelPos = perspective3D({
  1861. x: prevTick.label.xy.x,
  1862. y: prevTick.label.xy.y,
  1863. z: null
  1864. }, origin, origin.vd);
  1865. }
  1866. // If next label position is defined, then recalculate its position
  1867. // basing on the perspective.
  1868. if (nextTick && nextTick.label.xy) {
  1869. nextLabelPos = perspective3D({
  1870. x: nextTick.label.xy.x,
  1871. y: nextTick.label.xy.y,
  1872. z: null
  1873. }, origin, origin.vd);
  1874. }
  1875. labelPos = {
  1876. x: tick.label.xy.x,
  1877. y: tick.label.xy.y,
  1878. z: null
  1879. };
  1880. labelPos = perspective3D(labelPos, origin, origin.vd);
  1881. // If tick is first one, check whether next label position is
  1882. // already calculated, then return difference between the first and
  1883. // the second label. If there is no next label position calculated,
  1884. // return the difference between the first grid line and left 3d
  1885. // frame.
  1886. slotWidth = Math.abs(prevLabelPos ?
  1887. labelPos.x - prevLabelPos.x : nextLabelPos ?
  1888. nextLabelPos.x - labelPos.x :
  1889. firstGridLine.x - frame3DLeft.x);
  1890. return slotWidth;
  1891. }
  1892. return proceed.apply(axis, [].slice.call(arguments, 1));
  1893. };
  1894. /**
  1895. * @private
  1896. */
  1897. Axis3D.wrapGetTitlePosition = function (proceed) {
  1898. var pos = proceed.apply(this,
  1899. [].slice.call(arguments, 1));
  1900. return this.axis3D ?
  1901. this.axis3D.fix3dPosition(pos, true) :
  1902. pos;
  1903. };
  1904. /* *
  1905. *
  1906. * Static Properties
  1907. *
  1908. * */
  1909. /**
  1910. * @optionparent xAxis
  1911. */
  1912. Axis3D.defaultOptions = {
  1913. labels: {
  1914. /**
  1915. * Defines how the labels are be repositioned according to the 3D
  1916. * chart orientation.
  1917. *
  1918. * - `'offset'`: Maintain a fixed horizontal/vertical distance from
  1919. * the tick marks, despite the chart orientation. This is the
  1920. * backwards compatible behavior, and causes skewing of X and Z
  1921. * axes.
  1922. *
  1923. * - `'chart'`: Preserve 3D position relative to the chart. This
  1924. * looks nice, but hard to read if the text isn't forward-facing.
  1925. *
  1926. * - `'flap'`: Rotated text along the axis to compensate for the
  1927. * chart orientation. This tries to maintain text as legible as
  1928. * possible on all orientations.
  1929. *
  1930. * - `'ortho'`: Rotated text along the axis direction so that the
  1931. * labels are orthogonal to the axis. This is very similar to
  1932. * `'flap'`, but prevents skewing the labels (X and Y scaling are
  1933. * still present).
  1934. *
  1935. * @sample highcharts/3d/skewed-labels/
  1936. * Skewed labels
  1937. *
  1938. * @since 5.0.15
  1939. * @validvalue ['offset', 'chart', 'flap', 'ortho']
  1940. * @product highcharts
  1941. * @requires highcharts-3d
  1942. */
  1943. position3d: 'offset',
  1944. /**
  1945. * If enabled, the axis labels will skewed to follow the
  1946. * perspective.
  1947. *
  1948. * This will fix overlapping labels and titles, but texts become
  1949. * less legible due to the distortion.
  1950. *
  1951. * The final appearance depends heavily on `labels.position3d`.
  1952. *
  1953. * @sample highcharts/3d/skewed-labels/
  1954. * Skewed labels
  1955. *
  1956. * @since 5.0.15
  1957. * @product highcharts
  1958. * @requires highcharts-3d
  1959. */
  1960. skew3d: false
  1961. },
  1962. title: {
  1963. /**
  1964. * Defines how the title is repositioned according to the 3D chart
  1965. * orientation.
  1966. *
  1967. * - `'offset'`: Maintain a fixed horizontal/vertical distance from
  1968. * the tick marks, despite the chart orientation. This is the
  1969. * backwards compatible behavior, and causes skewing of X and Z
  1970. * axes.
  1971. *
  1972. * - `'chart'`: Preserve 3D position relative to the chart. This
  1973. * looks nice, but hard to read if the text isn't forward-facing.
  1974. *
  1975. * - `'flap'`: Rotated text along the axis to compensate for the
  1976. * chart orientation. This tries to maintain text as legible as
  1977. * possible on all orientations.
  1978. *
  1979. * - `'ortho'`: Rotated text along the axis direction so that the
  1980. * labels are orthogonal to the axis. This is very similar to
  1981. * `'flap'`, but prevents skewing the labels (X and Y scaling are
  1982. * still present).
  1983. *
  1984. * - `undefined`: Will use the config from `labels.position3d`
  1985. *
  1986. * @sample highcharts/3d/skewed-labels/
  1987. * Skewed labels
  1988. *
  1989. * @type {"offset"|"chart"|"flap"|"ortho"|null}
  1990. * @since 5.0.15
  1991. * @product highcharts
  1992. * @requires highcharts-3d
  1993. */
  1994. position3d: null,
  1995. /**
  1996. * If enabled, the axis title will skewed to follow the perspective.
  1997. *
  1998. * This will fix overlapping labels and titles, but texts become
  1999. * less legible due to the distortion.
  2000. *
  2001. * The final appearance depends heavily on `title.position3d`.
  2002. *
  2003. * A `null` value will use the config from `labels.skew3d`.
  2004. *
  2005. * @sample highcharts/3d/skewed-labels/
  2006. * Skewed labels
  2007. *
  2008. * @type {boolean|null}
  2009. * @since 5.0.15
  2010. * @product highcharts
  2011. * @requires highcharts-3d
  2012. */
  2013. skew3d: null
  2014. }
  2015. };
  2016. return Axis3D;
  2017. }());
  2018. return Axis3D;
  2019. });
  2020. _registerModule(_modules, 'Core/Axis/ZAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Utilities.js']], function (Axis, U) {
  2021. /* *
  2022. *
  2023. * (c) 2010-2020 Torstein Honsi
  2024. *
  2025. * License: www.highcharts.com/license
  2026. *
  2027. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2028. *
  2029. * */
  2030. var __extends = (this && this.__extends) || (function () {
  2031. var extendStatics = function (d,
  2032. b) {
  2033. extendStatics = Object.setPrototypeOf ||
  2034. ({ __proto__: [] } instanceof Array && function (d,
  2035. b) { d.__proto__ = b; }) ||
  2036. function (d,
  2037. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2038. return extendStatics(d, b);
  2039. };
  2040. return function (d, b) {
  2041. extendStatics(d, b);
  2042. function __() { this.constructor = d; }
  2043. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2044. };
  2045. })();
  2046. var addEvent = U.addEvent,
  2047. merge = U.merge,
  2048. pick = U.pick,
  2049. splat = U.splat;
  2050. /* eslint-disable valid-jsdoc */
  2051. /**
  2052. * 3D chart with support of z coordinates.
  2053. * @private
  2054. * @class
  2055. */
  2056. var ZChart = /** @class */ (function () {
  2057. function ZChart() {
  2058. }
  2059. /* *
  2060. *
  2061. * Static Functions
  2062. *
  2063. * */
  2064. ZChart.compose = function (ChartClass) {
  2065. addEvent(ChartClass, 'afterGetAxes', ZChart.onAfterGetAxes);
  2066. var chartProto = ChartClass.prototype;
  2067. chartProto.addZAxis = ZChart.wrapAddZAxis;
  2068. chartProto.collectionsWithInit.zAxis = [chartProto.addZAxis];
  2069. chartProto.collectionsWithUpdate.push('zAxis');
  2070. };
  2071. /**
  2072. * Get the Z axis in addition to the default X and Y.
  2073. * @private
  2074. */
  2075. ZChart.onAfterGetAxes = function () {
  2076. var chart = this;
  2077. var options = this.options;
  2078. var zAxisOptions = options.zAxis = splat(options.zAxis || {});
  2079. if (!chart.is3d()) {
  2080. return;
  2081. }
  2082. chart.zAxis = [];
  2083. zAxisOptions.forEach(function (axisOptions, i) {
  2084. axisOptions.index = i;
  2085. // Z-Axis is shown horizontally, so it's kind of a X-Axis
  2086. axisOptions.isX = true;
  2087. chart
  2088. .addZAxis(axisOptions)
  2089. .setScale();
  2090. });
  2091. };
  2092. /**
  2093. * @private
  2094. */
  2095. ZChart.wrapAddZAxis = function (options) {
  2096. return new ZAxis(this, options);
  2097. };
  2098. return ZChart;
  2099. }());
  2100. /**
  2101. * 3D axis for z coordinates.
  2102. */
  2103. var ZAxis = /** @class */ (function (_super) {
  2104. __extends(ZAxis, _super);
  2105. /* *
  2106. *
  2107. * Constructors
  2108. *
  2109. * */
  2110. function ZAxis(chart, userOptions) {
  2111. var _this = _super.call(this,
  2112. chart,
  2113. userOptions) || this;
  2114. _this.isZAxis = true;
  2115. return _this;
  2116. }
  2117. /* *
  2118. *
  2119. * Functions
  2120. *
  2121. * */
  2122. ZAxis.prototype.getSeriesExtremes = function () {
  2123. var axis = this;
  2124. var chart = axis.chart;
  2125. axis.hasVisibleSeries = false;
  2126. // Reset properties in case we're redrawing (#3353)
  2127. axis.dataMin = axis.dataMax = axis.ignoreMinPadding = axis.ignoreMaxPadding = void 0;
  2128. if (axis.stacking) {
  2129. axis.stacking.buildStacks();
  2130. }
  2131. // loop through this axis' series
  2132. axis.series.forEach(function (series) {
  2133. if (series.visible ||
  2134. !(chart.options.chart &&
  2135. chart.options.chart.ignoreHiddenSeries)) {
  2136. var seriesOptions = series.options,
  2137. zData,
  2138. threshold = seriesOptions.threshold;
  2139. axis.hasVisibleSeries = true;
  2140. // Validate threshold in logarithmic axes
  2141. if (axis.positiveValuesOnly && threshold <= 0) {
  2142. threshold = void 0;
  2143. }
  2144. zData = series.zData;
  2145. if (zData.length) {
  2146. axis.dataMin = Math.min(pick(axis.dataMin, zData[0]), Math.min.apply(null, zData));
  2147. axis.dataMax = Math.max(pick(axis.dataMax, zData[0]), Math.max.apply(null, zData));
  2148. }
  2149. }
  2150. });
  2151. };
  2152. /**
  2153. * @private
  2154. */
  2155. ZAxis.prototype.setAxisSize = function () {
  2156. var axis = this;
  2157. var chart = axis.chart;
  2158. _super.prototype.setAxisSize.call(this);
  2159. axis.width = axis.len = (chart.options.chart &&
  2160. chart.options.chart.options3d &&
  2161. chart.options.chart.options3d.depth) || 0;
  2162. axis.right = chart.chartWidth - axis.width - axis.left;
  2163. };
  2164. /**
  2165. * @private
  2166. */
  2167. ZAxis.prototype.setOptions = function (userOptions) {
  2168. userOptions = merge({
  2169. offset: 0,
  2170. lineWidth: 0
  2171. }, userOptions);
  2172. _super.prototype.setOptions.call(this, userOptions);
  2173. this.coll = 'zAxis';
  2174. };
  2175. /* *
  2176. *
  2177. * Static Properties
  2178. *
  2179. * */
  2180. ZAxis.ZChartComposition = ZChart;
  2181. return ZAxis;
  2182. }(Axis));
  2183. return ZAxis;
  2184. });
  2185. _registerModule(_modules, 'Core/Chart/Chart3D.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Axis/Axis3D.js'], _modules['Core/Chart/Chart.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, H, Math3D, O, U, ZAxis) {
  2186. /* *
  2187. *
  2188. * (c) 2010-2020 Torstein Honsi
  2189. *
  2190. * Extension for 3D charts
  2191. *
  2192. * License: www.highcharts.com/license
  2193. *
  2194. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2195. *
  2196. * */
  2197. var perspective = Math3D.perspective,
  2198. shapeArea3D = Math3D.shapeArea3D;
  2199. var genericDefaultOptions = O.defaultOptions;
  2200. var addEvent = U.addEvent,
  2201. Fx = U.Fx,
  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/Globals.js'], _modules['Extensions/Math3D.js'], _modules['Extensions/Stacking.js'], _modules['Core/Utilities.js']], function (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. seriesTypes = H.seriesTypes,
  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(seriesTypes.column.prototype, '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. seriesTypes.column.prototype.translate3dPoints = function () { };
  4084. seriesTypes.column.prototype.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(seriesTypes.column.prototype, '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(seriesTypes.column.prototype, '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(seriesTypes.column.prototype, '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. seriesTypes.column.prototype
  4279. .handle3dGrouping = true;
  4280. addEvent(Series, 'afterInit', function () {
  4281. if (this.chart.is3d() &&
  4282. this.handle3dGrouping) {
  4283. var series = this,
  4284. seriesOptions = this.options,
  4285. grouping = seriesOptions.grouping,
  4286. stacking = seriesOptions.stacking,
  4287. reversedStacks = pick(this.yAxis.options.reversedStacks,
  4288. true),
  4289. z = 0;
  4290. // @todo grouping === true ?
  4291. if (!(typeof grouping !== 'undefined' && !grouping)) {
  4292. var stacks = retrieveStacks(this.chart,
  4293. stacking),
  4294. stack = seriesOptions.stack || 0,
  4295. i; // position within the stack
  4296. for (i = 0; i < stacks[stack].series.length; i++) {
  4297. if (stacks[stack].series[i] === this) {
  4298. break;
  4299. }
  4300. }
  4301. z = (10 * (stacks.totalStacks - stacks[stack].position)) +
  4302. (reversedStacks ? i : -i); // #4369
  4303. // In case when axis is reversed, columns are also reversed inside
  4304. // the group (#3737)
  4305. if (!this.xAxis.reversed) {
  4306. z = (stacks.totalStacks * 10) - z;
  4307. }
  4308. }
  4309. seriesOptions.depth = seriesOptions.depth || 25;
  4310. series.z = series.z || 0;
  4311. seriesOptions.zIndex = z;
  4312. }
  4313. });
  4314. // eslint-disable-next-line valid-jsdoc
  4315. /**
  4316. * @private
  4317. */
  4318. function pointAttribs(proceed) {
  4319. var attr = proceed.apply(this,
  4320. [].slice.call(arguments, 1));
  4321. if (this.chart.is3d && this.chart.is3d()) {
  4322. // Set the fill color to the fill color to provide a smooth edge
  4323. attr.stroke = this.options.edgeColor || attr.fill;
  4324. attr['stroke-width'] = pick(this.options.edgeWidth, 1); // #4055
  4325. }
  4326. return attr;
  4327. }
  4328. // eslint-disable-next-line valid-jsdoc
  4329. /**
  4330. * In 3D mode, all column-series are rendered in one main group. Because of that
  4331. * we need to apply inactive state on all points.
  4332. * @private
  4333. */
  4334. function setState(proceed, state, inherit) {
  4335. var is3d = this.chart.is3d && this.chart.is3d();
  4336. if (is3d) {
  4337. this.options.inactiveOtherPoints = true;
  4338. }
  4339. proceed.call(this, state, inherit);
  4340. if (is3d) {
  4341. this.options.inactiveOtherPoints = false;
  4342. }
  4343. }
  4344. // eslint-disable-next-line valid-jsdoc
  4345. /**
  4346. * In 3D mode, simple checking for a new shape to animate is not enough.
  4347. * Additionally check if graphic is a group of elements
  4348. * @private
  4349. */
  4350. function hasNewShapeType(proceed) {
  4351. var args = [];
  4352. for (var _i = 1; _i < arguments.length; _i++) {
  4353. args[_i - 1] = arguments[_i];
  4354. }
  4355. return this.series.chart.is3d() ?
  4356. this.graphic && this.graphic.element.nodeName !== 'g' :
  4357. proceed.apply(this, args);
  4358. }
  4359. wrap(seriesTypes.column.prototype, 'pointAttribs', pointAttribs);
  4360. wrap(seriesTypes.column.prototype, 'setState', setState);
  4361. wrap(seriesTypes.column.prototype.pointClass.prototype, 'hasNewShapeType', hasNewShapeType);
  4362. if (seriesTypes.columnrange) {
  4363. wrap(seriesTypes.columnrange.prototype, 'pointAttribs', pointAttribs);
  4364. wrap(seriesTypes.columnrange.prototype, 'setState', setState);
  4365. wrap(seriesTypes.columnrange.prototype.pointClass.prototype, 'hasNewShapeType', hasNewShapeType);
  4366. seriesTypes.columnrange.prototype.plotGroup =
  4367. seriesTypes.column.prototype.plotGroup;
  4368. seriesTypes.columnrange.prototype.setVisible =
  4369. seriesTypes.column.prototype.setVisible;
  4370. }
  4371. wrap(Series.prototype, 'alignDataLabel', function (proceed, point, dataLabel, options, alignTo) {
  4372. var chart = this.chart;
  4373. // In 3D we need to pass point.outsidePlot option to the justifyDataLabel
  4374. // method for disabling justifying dataLabels in columns outside plot
  4375. options.outside3dPlot = point.outside3dPlot;
  4376. // Only do this for 3D columns and it's derived series
  4377. if (chart.is3d() &&
  4378. this.is('column')) {
  4379. var series = this,
  4380. seriesOptions = series.options,
  4381. inside = pick(options.inside, !!series.options.stacking),
  4382. options3d = chart.options.chart.options3d,
  4383. xOffset = point.pointWidth / 2 || 0;
  4384. var dLPosition = {
  4385. x: alignTo.x + xOffset,
  4386. y: alignTo.y,
  4387. z: series.z + seriesOptions.depth / 2
  4388. };
  4389. if (chart.inverted) {
  4390. // Inside dataLabels are positioned according to above
  4391. // logic and there is no need to position them using
  4392. // non-3D algorighm (that use alignTo.width)
  4393. if (inside) {
  4394. alignTo.width = 0;
  4395. dLPosition.x += point.shapeArgs.height / 2;
  4396. }
  4397. // When chart is upside down
  4398. // (alpha angle between 180 and 360 degrees)
  4399. // it is needed to add column width to calculated value.
  4400. if (options3d.alpha >= 90 && options3d.alpha <= 270) {
  4401. dLPosition.y += point.shapeArgs.width;
  4402. }
  4403. }
  4404. // dLPosition is recalculated for 3D graphs
  4405. dLPosition = perspective([dLPosition], chart, true, false)[0];
  4406. alignTo.x = dLPosition.x - xOffset;
  4407. // #7103 If point is outside of plotArea, hide data label.
  4408. alignTo.y = point.outside3dPlot ? -9e9 : dLPosition.y;
  4409. }
  4410. proceed.apply(this, [].slice.call(arguments, 1));
  4411. });
  4412. // Added stackLabels position calculation for 3D charts.
  4413. wrap(StackItem.prototype, 'getStackBox', function (proceed, chart, stackItem, x, y, xWidth, h, axis) {
  4414. var stackBox = proceed.apply(this,
  4415. [].slice.call(arguments, 1));
  4416. // Only do this for 3D graph
  4417. if (chart.is3d() && stackItem.base) {
  4418. // First element of stackItem.base is an index of base series.
  4419. var baseSeriesInd = +(stackItem.base).split(',')[0];
  4420. var columnSeries = chart.series[baseSeriesInd];
  4421. var options3d = chart.options.chart.options3d;
  4422. // Only do this if base series is a column or inherited type,
  4423. // use its barW, z and depth parameters
  4424. // for correct stackLabels position calculation
  4425. if (columnSeries &&
  4426. columnSeries instanceof seriesTypes.column) {
  4427. var dLPosition = {
  4428. x: stackBox.x + (chart.inverted ? h : xWidth / 2),
  4429. y: stackBox.y,
  4430. z: columnSeries.options.depth / 2
  4431. };
  4432. if (chart.inverted) {
  4433. // Do not use default offset calculation logic
  4434. // for 3D inverted stackLabels.
  4435. stackBox.width = 0;
  4436. // When chart is upside down
  4437. // (alpha angle between 180 and 360 degrees)
  4438. // it is needed to add column width to calculated value.
  4439. if (options3d.alpha >= 90 && options3d.alpha <= 270) {
  4440. dLPosition.y += xWidth;
  4441. }
  4442. }
  4443. dLPosition = perspective([dLPosition], chart, true, false)[0];
  4444. stackBox.x = dLPosition.x - xWidth / 2;
  4445. stackBox.y = dLPosition.y;
  4446. }
  4447. }
  4448. return stackBox;
  4449. });
  4450. });
  4451. _registerModule(_modules, 'Series/Pie3DSeries.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  4452. /* *
  4453. *
  4454. * (c) 2010-2020 Torstein Honsi
  4455. *
  4456. * 3D pie series
  4457. *
  4458. * License: www.highcharts.com/license
  4459. *
  4460. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4461. *
  4462. * */
  4463. var pick = U.pick,
  4464. wrap = U.wrap;
  4465. var deg2rad = H.deg2rad,
  4466. seriesTypes = H.seriesTypes,
  4467. svg = H.svg;
  4468. /**
  4469. * The thickness of a 3D pie.
  4470. *
  4471. * @type {number}
  4472. * @default 0
  4473. * @since 4.0
  4474. * @product highcharts
  4475. * @requires highcharts-3d
  4476. * @apioption plotOptions.pie.depth
  4477. */
  4478. /* eslint-disable no-invalid-this */
  4479. wrap(seriesTypes.pie.prototype, 'translate', function (proceed) {
  4480. proceed.apply(this, [].slice.call(arguments, 1));
  4481. // Do not do this if the chart is not 3D
  4482. if (!this.chart.is3d()) {
  4483. return;
  4484. }
  4485. var series = this,
  4486. seriesOptions = series.options,
  4487. depth = seriesOptions.depth || 0,
  4488. options3d = series.chart.options.chart.options3d,
  4489. alpha = options3d.alpha,
  4490. beta = options3d.beta,
  4491. z = seriesOptions.stacking ?
  4492. (seriesOptions.stack || 0) * depth :
  4493. series._i * depth;
  4494. z += depth / 2;
  4495. if (seriesOptions.grouping !== false) {
  4496. z = 0;
  4497. }
  4498. series.data.forEach(function (point) {
  4499. var shapeArgs = point.shapeArgs,
  4500. angle;
  4501. point.shapeType = 'arc3d';
  4502. shapeArgs.z = z;
  4503. shapeArgs.depth = depth * 0.75;
  4504. shapeArgs.alpha = alpha;
  4505. shapeArgs.beta = beta;
  4506. shapeArgs.center = series.center;
  4507. angle = (shapeArgs.end + shapeArgs.start) / 2;
  4508. point.slicedTranslation = {
  4509. translateX: Math.round(Math.cos(angle) *
  4510. seriesOptions.slicedOffset *
  4511. Math.cos(alpha * deg2rad)),
  4512. translateY: Math.round(Math.sin(angle) *
  4513. seriesOptions.slicedOffset *
  4514. Math.cos(alpha * deg2rad))
  4515. };
  4516. });
  4517. });
  4518. wrap(seriesTypes.pie.prototype.pointClass.prototype, 'haloPath', function (proceed) {
  4519. var args = arguments;
  4520. return this.series.chart.is3d() ? [] : proceed.call(this, args[1]);
  4521. });
  4522. wrap(seriesTypes.pie.prototype, 'pointAttribs', function (proceed, point, state) {
  4523. var attr = proceed.call(this,
  4524. point,
  4525. state),
  4526. options = this.options;
  4527. if (this.chart.is3d() && !this.chart.styledMode) {
  4528. attr.stroke = options.edgeColor || point.color || this.color;
  4529. attr['stroke-width'] = pick(options.edgeWidth, 1);
  4530. }
  4531. return attr;
  4532. });
  4533. wrap(seriesTypes.pie.prototype, 'drawDataLabels', function (proceed) {
  4534. if (this.chart.is3d()) {
  4535. var series = this,
  4536. chart = series.chart,
  4537. options3d = chart.options.chart.options3d;
  4538. series.data.forEach(function (point) {
  4539. var shapeArgs = point.shapeArgs,
  4540. r = shapeArgs.r,
  4541. // #3240 issue with datalabels for 0 and null values
  4542. a1 = (shapeArgs.alpha || options3d.alpha) * deg2rad,
  4543. b1 = (shapeArgs.beta || options3d.beta) * deg2rad,
  4544. a2 = (shapeArgs.start + shapeArgs.end) / 2,
  4545. labelPosition = point.labelPosition,
  4546. connectorPosition = labelPosition.connectorPosition,
  4547. yOffset = (-r * (1 - Math.cos(a1)) * Math.sin(a2)),
  4548. xOffset = r * (Math.cos(b1) - 1) * Math.cos(a2);
  4549. // Apply perspective on label positions
  4550. [
  4551. labelPosition.natural,
  4552. connectorPosition.breakAt,
  4553. connectorPosition.touchingSliceAt
  4554. ].forEach(function (coordinates) {
  4555. coordinates.x += xOffset;
  4556. coordinates.y += yOffset;
  4557. });
  4558. });
  4559. }
  4560. proceed.apply(this, [].slice.call(arguments, 1));
  4561. });
  4562. wrap(seriesTypes.pie.prototype, 'addPoint', function (proceed) {
  4563. proceed.apply(this, [].slice.call(arguments, 1));
  4564. if (this.chart.is3d()) {
  4565. // destroy (and rebuild) everything!!!
  4566. this.update(this.userOptions, true); // #3845 pass the old options
  4567. }
  4568. });
  4569. wrap(seriesTypes.pie.prototype, 'animate', function (proceed) {
  4570. if (!this.chart.is3d()) {
  4571. proceed.apply(this, [].slice.call(arguments, 1));
  4572. }
  4573. else {
  4574. var args = arguments,
  4575. init = args[1],
  4576. animation = this.options.animation,
  4577. attribs,
  4578. center = this.center,
  4579. group = this.group,
  4580. markerGroup = this.markerGroup;
  4581. if (svg) { // VML is too slow anyway
  4582. if (animation === true) {
  4583. animation = {};
  4584. }
  4585. // Initialize the animation
  4586. if (init) {
  4587. // Scale down the group and place it in the center
  4588. group.oldtranslateX = pick(group.oldtranslateX, group.translateX);
  4589. group.oldtranslateY = pick(group.oldtranslateY, group.translateY);
  4590. attribs = {
  4591. translateX: center[0],
  4592. translateY: center[1],
  4593. scaleX: 0.001,
  4594. scaleY: 0.001
  4595. };
  4596. group.attr(attribs);
  4597. if (markerGroup) {
  4598. markerGroup.attrSetters = group.attrSetters;
  4599. markerGroup.attr(attribs);
  4600. }
  4601. // Run the animation
  4602. }
  4603. else {
  4604. attribs = {
  4605. translateX: group.oldtranslateX,
  4606. translateY: group.oldtranslateY,
  4607. scaleX: 1,
  4608. scaleY: 1
  4609. };
  4610. group.animate(attribs, animation);
  4611. if (markerGroup) {
  4612. markerGroup.animate(attribs, animation);
  4613. }
  4614. }
  4615. }
  4616. }
  4617. });
  4618. });
  4619. _registerModule(_modules, 'Series/Scatter3DSeries.js', [_modules['Core/Globals.js'], _modules['Extensions/Math3D.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js']], function (H, Math3D, Point, U) {
  4620. /* *
  4621. *
  4622. * (c) 2010-2020 Torstein Honsi
  4623. *
  4624. * Scatter 3D series.
  4625. *
  4626. * License: www.highcharts.com/license
  4627. *
  4628. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4629. *
  4630. * */
  4631. var pointCameraDistance = Math3D.pointCameraDistance;
  4632. var seriesType = U.seriesType;
  4633. var seriesTypes = H.seriesTypes;
  4634. /**
  4635. * @private
  4636. * @class
  4637. * @name Highcharts.seriesTypes.scatter3d
  4638. *
  4639. * @augments Highcharts.Series
  4640. */
  4641. seriesType('scatter3d', 'scatter',
  4642. /**
  4643. * A 3D scatter plot uses x, y and z coordinates to display values for three
  4644. * variables for a set of data.
  4645. *
  4646. * @sample {highcharts} highcharts/3d/scatter/
  4647. * Simple 3D scatter
  4648. * @sample {highcharts} highcharts/demo/3d-scatter-draggable
  4649. * Draggable 3d scatter
  4650. *
  4651. * @extends plotOptions.scatter
  4652. * @excluding dragDrop, cluster, boostThreshold, boostBlending
  4653. * @product highcharts
  4654. * @requires highcharts-3d
  4655. * @optionparent plotOptions.scatter3d
  4656. */
  4657. {
  4658. tooltip: {
  4659. pointFormat: 'x: <b>{point.x}</b><br/>y: <b>{point.y}</b><br/>z: <b>{point.z}</b><br/>'
  4660. }
  4661. // Series class
  4662. }, {
  4663. pointAttribs: function (point) {
  4664. var attribs = seriesTypes.scatter.prototype.pointAttribs
  4665. .apply(this,
  4666. arguments);
  4667. if (this.chart.is3d() && point) {
  4668. attribs.zIndex =
  4669. pointCameraDistance(point, this.chart);
  4670. }
  4671. return attribs;
  4672. },
  4673. axisTypes: ['xAxis', 'yAxis', 'zAxis'],
  4674. pointArrayMap: ['x', 'y', 'z'],
  4675. parallelArrays: ['x', 'y', 'z'],
  4676. // Require direct touch rather than using the k-d-tree, because the
  4677. // k-d-tree currently doesn't take the xyz coordinate system into
  4678. // account (#4552)
  4679. directTouch: true
  4680. // Point class
  4681. }, {
  4682. applyOptions: function () {
  4683. Point.prototype.applyOptions.apply(this, arguments);
  4684. if (typeof this.z === 'undefined') {
  4685. this.z = 0;
  4686. }
  4687. return this;
  4688. }
  4689. });
  4690. /**
  4691. * A `scatter3d` series. If the [type](#series.scatter3d.type) option is
  4692. * not specified, it is inherited from [chart.type](#chart.type).
  4693. *
  4694. * scatter3d](#plotOptions.scatter3d).
  4695. *
  4696. * @extends series,plotOptions.scatter3d
  4697. * @excluding boostThreshold, boostBlending
  4698. * @product highcharts
  4699. * @requires highcharts-3d
  4700. * @apioption series.scatter3d
  4701. */
  4702. /**
  4703. * An array of data points for the series. For the `scatter3d` series
  4704. * type, points can be given in the following ways:
  4705. *
  4706. * 1. An array of arrays with 3 values. In this case, the values correspond
  4707. * to `x,y,z`. If the first value is a string, it is applied as the name
  4708. * of the point, and the `x` value is inferred.
  4709. *
  4710. * ```js
  4711. * data: [
  4712. * [0, 0, 1],
  4713. * [1, 8, 7],
  4714. * [2, 9, 2]
  4715. * ]
  4716. * ```
  4717. *
  4718. * 3. An array of objects with named values. The following snippet shows only a
  4719. * few settings, see the complete options set below. If the total number of data
  4720. * points exceeds the series'
  4721. * [turboThreshold](#series.scatter3d.turboThreshold), this option is not
  4722. * available.
  4723. *
  4724. * ```js
  4725. * data: [{
  4726. * x: 1,
  4727. * y: 2,
  4728. * z: 24,
  4729. * name: "Point2",
  4730. * color: "#00FF00"
  4731. * }, {
  4732. * x: 1,
  4733. * y: 4,
  4734. * z: 12,
  4735. * name: "Point1",
  4736. * color: "#FF00FF"
  4737. * }]
  4738. * ```
  4739. *
  4740. * @sample {highcharts} highcharts/chart/reflow-true/
  4741. * Numerical values
  4742. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  4743. * Arrays of numeric x and y
  4744. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  4745. * Arrays of datetime x and y
  4746. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  4747. * Arrays of point.name and y
  4748. * @sample {highcharts} highcharts/series/data-array-of-objects/
  4749. * Config objects
  4750. *
  4751. * @type {Array<Array<number>|*>}
  4752. * @extends series.scatter.data
  4753. * @product highcharts
  4754. * @apioption series.scatter3d.data
  4755. */
  4756. /**
  4757. * The z value for each data point.
  4758. *
  4759. * @type {number}
  4760. * @product highcharts
  4761. * @apioption series.scatter3d.data.z
  4762. */
  4763. ''; // adds doclets above to transpiled file
  4764. });
  4765. _registerModule(_modules, 'Core/Axis/VMLAxis3D.js', [_modules['Core/Utilities.js']], function (U) {
  4766. /* *
  4767. *
  4768. * (c) 2010-2020 Torstein Honsi
  4769. *
  4770. * Extension to the VML Renderer
  4771. *
  4772. * License: www.highcharts.com/license
  4773. *
  4774. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4775. *
  4776. * */
  4777. var addEvent = U.addEvent;
  4778. /* eslint-disable valid-jsdoc */
  4779. var VMLAxis3DAdditions = /** @class */ (function () {
  4780. /* *
  4781. *
  4782. * Constructors
  4783. *
  4784. * */
  4785. function VMLAxis3DAdditions(axis) {
  4786. this.axis = axis;
  4787. }
  4788. return VMLAxis3DAdditions;
  4789. }());
  4790. var VMLAxis3D = /** @class */ (function () {
  4791. function VMLAxis3D() {
  4792. }
  4793. /* *
  4794. *
  4795. * Static Properties
  4796. *
  4797. * */
  4798. VMLAxis3D.compose = function (AxisClass) {
  4799. AxisClass.keepProps.push('vml');
  4800. addEvent(AxisClass, 'init', VMLAxis3D.onInit);
  4801. addEvent(AxisClass, 'render', VMLAxis3D.onRender);
  4802. };
  4803. /**
  4804. * @private
  4805. */
  4806. VMLAxis3D.onInit = function () {
  4807. var axis = this;
  4808. if (!axis.vml) {
  4809. axis.vml = new VMLAxis3DAdditions(axis);
  4810. }
  4811. };
  4812. /**
  4813. * @private
  4814. */
  4815. VMLAxis3D.onRender = function () {
  4816. var axis = this;
  4817. var vml = axis.vml;
  4818. // VML doesn't support a negative z-index
  4819. if (vml.sideFrame) {
  4820. vml.sideFrame.css({ zIndex: 0 });
  4821. vml.sideFrame.front.attr({
  4822. fill: vml.sideFrame.color
  4823. });
  4824. }
  4825. if (vml.bottomFrame) {
  4826. vml.bottomFrame.css({ zIndex: 1 });
  4827. vml.bottomFrame.front.attr({
  4828. fill: vml.bottomFrame.color
  4829. });
  4830. }
  4831. if (vml.backFrame) {
  4832. vml.backFrame.css({ zIndex: 0 });
  4833. vml.backFrame.front.attr({
  4834. fill: vml.backFrame.color
  4835. });
  4836. }
  4837. };
  4838. return VMLAxis3D;
  4839. }());
  4840. return VMLAxis3D;
  4841. });
  4842. _registerModule(_modules, 'Core/Renderer/VML/VMLRenderer3D.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Globals.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Utilities.js'], _modules['Core/Axis/VMLAxis3D.js']], function (Axis, H, SVGRenderer, U, VMLAxis3D) {
  4843. /* *
  4844. *
  4845. * (c) 2010-2020 Torstein Honsi
  4846. *
  4847. * Extension to the VML Renderer
  4848. *
  4849. * License: www.highcharts.com/license
  4850. *
  4851. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4852. *
  4853. * */
  4854. var setOptions = U.setOptions;
  4855. var VMLRenderer = H.VMLRenderer;
  4856. if (VMLRenderer) {
  4857. setOptions({ animate: false });
  4858. VMLRenderer.prototype.face3d = SVGRenderer.prototype.face3d;
  4859. VMLRenderer.prototype.polyhedron = SVGRenderer.prototype.polyhedron;
  4860. VMLRenderer.prototype.elements3d = SVGRenderer.prototype.elements3d;
  4861. VMLRenderer.prototype.element3d = SVGRenderer.prototype.element3d;
  4862. VMLRenderer.prototype.cuboid = SVGRenderer.prototype.cuboid;
  4863. VMLRenderer.prototype.cuboidPath = SVGRenderer.prototype.cuboidPath;
  4864. VMLRenderer.prototype.toLinePath = SVGRenderer.prototype.toLinePath;
  4865. VMLRenderer.prototype.toLineSegments = SVGRenderer.prototype.toLineSegments;
  4866. VMLRenderer.prototype.arc3d = function (shapeArgs) {
  4867. var result = SVGRenderer.prototype.arc3d.call(this,
  4868. shapeArgs);
  4869. result.css({ zIndex: result.zIndex });
  4870. return result;
  4871. };
  4872. H.VMLRenderer.prototype.arc3dPath = SVGRenderer.prototype.arc3dPath;
  4873. VMLAxis3D.compose(Axis);
  4874. }
  4875. });
  4876. _registerModule(_modules, 'masters/highcharts-3d.src.js', [], function () {
  4877. });
  4878. }));