highcharts-3d.src.js 142 KB

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