highcharts-3d.src.js 134 KB

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