Chart.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753
  1. /* *
  2. * (c) 2010-2019 Torstein Honsi
  3. *
  4. * Extension for 3D charts
  5. *
  6. * License: www.highcharts.com/license
  7. */
  8. 'use strict';
  9. import H from '../parts/Globals.js';
  10. import '../parts/Utilities.js';
  11. import '../parts/Chart.js';
  12. var addEvent = H.addEvent,
  13. Chart = H.Chart,
  14. merge = H.merge,
  15. perspective = H.perspective,
  16. pick = H.pick,
  17. wrap = H.wrap;
  18. // Shorthand to check the is3d flag
  19. Chart.prototype.is3d = function () {
  20. return (
  21. this.options.chart.options3d &&
  22. this.options.chart.options3d.enabled
  23. ); // #4280
  24. };
  25. Chart.prototype.propsRequireDirtyBox.push('chart.options3d');
  26. Chart.prototype.propsRequireUpdateSeries.push('chart.options3d');
  27. // Legacy support for HC < 6 to make 'scatter' series in a 3D chart route to the
  28. // real 'scatter3d' series type.
  29. addEvent(Chart, 'afterInit', function () {
  30. var options = this.options;
  31. if (this.is3d()) {
  32. (options.series || []).forEach(function (s) {
  33. var type = s.type ||
  34. options.chart.type ||
  35. options.chart.defaultSeriesType;
  36. if (type === 'scatter') {
  37. s.type = 'scatter3d';
  38. }
  39. });
  40. }
  41. });
  42. // And do it on dynamic add (#8407)
  43. addEvent(Chart, 'addSeries', function (e) {
  44. if (this.is3d()) {
  45. if (e.options.type === 'scatter') {
  46. e.options.type = 'scatter3d';
  47. }
  48. }
  49. });
  50. /**
  51. * Calculate scale of the 3D view. That is required to
  52. * fit chart's 3D projection into the actual plotting area. Reported as #4933.
  53. * @notice This function should ideally take the plot values instead of a chart
  54. * object, but since the chart object is needed for perspective it is
  55. * not practical. Possible to make both getScale and perspective more
  56. * logical and also immutable.
  57. *
  58. * @private
  59. * @function getScale
  60. *
  61. * @param {Highcharts.Chart} chart
  62. * Chart object
  63. *
  64. * @param {number} depth
  65. * The depth of the chart
  66. *
  67. * @return {number}
  68. * The scale to fit the 3D chart into the plotting area.
  69. */
  70. function getScale(chart, depth) {
  71. var plotLeft = chart.plotLeft,
  72. plotRight = chart.plotWidth + plotLeft,
  73. plotTop = chart.plotTop,
  74. plotBottom = chart.plotHeight + plotTop,
  75. originX = plotLeft + chart.plotWidth / 2,
  76. originY = plotTop + chart.plotHeight / 2,
  77. bbox3d = {
  78. minX: Number.MAX_VALUE,
  79. maxX: -Number.MAX_VALUE,
  80. minY: Number.MAX_VALUE,
  81. maxY: -Number.MAX_VALUE
  82. },
  83. corners,
  84. scale = 1;
  85. // Top left corners:
  86. corners = [{
  87. x: plotLeft,
  88. y: plotTop,
  89. z: 0
  90. }, {
  91. x: plotLeft,
  92. y: plotTop,
  93. z: depth
  94. }];
  95. // Top right corners:
  96. [0, 1].forEach(function (i) {
  97. corners.push({
  98. x: plotRight,
  99. y: corners[i].y,
  100. z: corners[i].z
  101. });
  102. });
  103. // All bottom corners:
  104. [0, 1, 2, 3].forEach(function (i) {
  105. corners.push({
  106. x: corners[i].x,
  107. y: plotBottom,
  108. z: corners[i].z
  109. });
  110. });
  111. // Calculate 3D corners:
  112. corners = perspective(corners, chart, false);
  113. // Get bounding box of 3D element:
  114. corners.forEach(function (corner) {
  115. bbox3d.minX = Math.min(bbox3d.minX, corner.x);
  116. bbox3d.maxX = Math.max(bbox3d.maxX, corner.x);
  117. bbox3d.minY = Math.min(bbox3d.minY, corner.y);
  118. bbox3d.maxY = Math.max(bbox3d.maxY, corner.y);
  119. });
  120. // Left edge:
  121. if (plotLeft > bbox3d.minX) {
  122. scale = Math.min(
  123. scale,
  124. 1 - Math.abs((plotLeft + originX) / (bbox3d.minX + originX)) % 1
  125. );
  126. }
  127. // Right edge:
  128. if (plotRight < bbox3d.maxX) {
  129. scale = Math.min(
  130. scale,
  131. (plotRight - originX) / (bbox3d.maxX - originX)
  132. );
  133. }
  134. // Top edge:
  135. if (plotTop > bbox3d.minY) {
  136. if (bbox3d.minY < 0) {
  137. scale = Math.min(
  138. scale,
  139. (plotTop + originY) / (-bbox3d.minY + plotTop + originY)
  140. );
  141. } else {
  142. scale = Math.min(
  143. scale,
  144. 1 - (plotTop + originY) / (bbox3d.minY + originY) % 1
  145. );
  146. }
  147. }
  148. // Bottom edge:
  149. if (plotBottom < bbox3d.maxY) {
  150. scale = Math.min(
  151. scale,
  152. Math.abs((plotBottom - originY) / (bbox3d.maxY - originY))
  153. );
  154. }
  155. return scale;
  156. }
  157. H.wrap(H.Chart.prototype, 'isInsidePlot', function (proceed) {
  158. return this.is3d() || proceed.apply(this, [].slice.call(arguments, 1));
  159. });
  160. var defaultOptions = H.getOptions();
  161. /**
  162. * @optionparent
  163. */
  164. var extendedOptions = {
  165. chart: {
  166. /**
  167. * Options to render charts in 3 dimensions. This feature requires
  168. * `highcharts-3d.js`, found in the download package or online at
  169. * [code.highcharts.com/highcharts-3d.js](http://code.highcharts.com/highcharts-3d.js).
  170. *
  171. * @since 4.0
  172. * @product highcharts
  173. */
  174. options3d: {
  175. /**
  176. * Wether to render the chart using the 3D functionality.
  177. *
  178. * @since 4.0
  179. * @product highcharts
  180. */
  181. enabled: false,
  182. /**
  183. * One of the two rotation angles for the chart.
  184. *
  185. * @since 4.0
  186. * @product highcharts
  187. */
  188. alpha: 0,
  189. /**
  190. * One of the two rotation angles for the chart.
  191. *
  192. * @since 4.0
  193. * @product highcharts
  194. */
  195. beta: 0,
  196. /**
  197. * The total depth of the chart.
  198. *
  199. * @since 4.0
  200. * @product highcharts
  201. */
  202. depth: 100,
  203. /**
  204. * Whether the 3d box should automatically adjust to the chart plot
  205. * area.
  206. *
  207. * @since 4.2.4
  208. * @product highcharts
  209. */
  210. fitToPlot: true,
  211. /**
  212. * Defines the distance the viewer is standing in front of the
  213. * chart, this setting is important to calculate the perspective
  214. * effect in column and scatter charts. It is not used for 3D pie
  215. * charts.
  216. *
  217. * @since 4.0
  218. * @product highcharts
  219. */
  220. viewDistance: 25,
  221. /**
  222. * Set it to `"auto"` to automatically move the labels to the best
  223. * edge.
  224. *
  225. * @type {"auto"|null}
  226. * @since 5.0.12
  227. * @product highcharts
  228. */
  229. axisLabelPosition: null,
  230. /**
  231. * Provides the option to draw a frame around the charts by defining
  232. * a bottom, front and back panel.
  233. *
  234. * @since 4.0
  235. * @product highcharts
  236. */
  237. frame: {
  238. /**
  239. * Whether the frames are visible.
  240. */
  241. visible: 'default',
  242. /**
  243. * General pixel thickness for the frame faces.
  244. */
  245. size: 1,
  246. /**
  247. * The bottom of the frame around a 3D chart.
  248. *
  249. * @since 4.0
  250. * @product highcharts
  251. */
  252. /**
  253. * The color of the panel.
  254. *
  255. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  256. * @default transparent
  257. * @since 4.0
  258. * @product highcharts
  259. * @apioption chart.options3d.frame.bottom.color
  260. */
  261. /**
  262. * The thickness of the panel.
  263. *
  264. * @type {number}
  265. * @default 1
  266. * @since 4.0
  267. * @product highcharts
  268. * @apioption chart.options3d.frame.bottom.size
  269. */
  270. /**
  271. * Whether to display the frame. Possible values are `true`,
  272. * `false`, `"auto"` to display only the frames behind the data,
  273. * and `"default"` to display faces behind the data based on the
  274. * axis layout, ignoring the point of view.
  275. *
  276. * @sample {highcharts} highcharts/3d/scatter-frame/
  277. * Auto frames
  278. *
  279. * @type {boolean|"default"|"auto"}
  280. * @default default
  281. * @since 5.0.12
  282. * @product highcharts
  283. * @apioption chart.options3d.frame.bottom.visible
  284. */
  285. /**
  286. * The bottom of the frame around a 3D chart.
  287. */
  288. bottom: {},
  289. /**
  290. * The top of the frame around a 3D chart.
  291. *
  292. * @extends chart.options3d.frame.bottom
  293. */
  294. top: {},
  295. /**
  296. * The left side of the frame around a 3D chart.
  297. *
  298. * @extends chart.options3d.frame.bottom
  299. */
  300. left: {},
  301. /**
  302. * The right of the frame around a 3D chart.
  303. *
  304. * @extends chart.options3d.frame.bottom
  305. */
  306. right: {},
  307. /**
  308. * The back side of the frame around a 3D chart.
  309. *
  310. * @extends chart.options3d.frame.bottom
  311. */
  312. back: {},
  313. /**
  314. * The front of the frame around a 3D chart.
  315. *
  316. * @extends chart.options3d.frame.bottom
  317. */
  318. front: {}
  319. }
  320. }
  321. }
  322. };
  323. merge(true, defaultOptions, extendedOptions);
  324. // Add the required CSS classes for column sides (#6018)
  325. addEvent(Chart, 'afterGetContainer', function () {
  326. if (this.styledMode) {
  327. this.renderer.definition({
  328. tagName: 'style',
  329. textContent:
  330. '.highcharts-3d-top{' +
  331. 'filter: url(#highcharts-brighter)' +
  332. '}\n' +
  333. '.highcharts-3d-side{' +
  334. 'filter: url(#highcharts-darker)' +
  335. '}\n'
  336. });
  337. // Add add definitions used by brighter and darker faces of the cuboids.
  338. [{
  339. name: 'darker',
  340. slope: 0.6
  341. }, {
  342. name: 'brighter',
  343. slope: 1.4
  344. }].forEach(function (cfg) {
  345. this.renderer.definition({
  346. tagName: 'filter',
  347. id: 'highcharts-' + cfg.name,
  348. children: [{
  349. tagName: 'feComponentTransfer',
  350. children: [{
  351. tagName: 'feFuncR',
  352. type: 'linear',
  353. slope: cfg.slope
  354. }, {
  355. tagName: 'feFuncG',
  356. type: 'linear',
  357. slope: cfg.slope
  358. }, {
  359. tagName: 'feFuncB',
  360. type: 'linear',
  361. slope: cfg.slope
  362. }]
  363. }]
  364. });
  365. }, this);
  366. }
  367. });
  368. wrap(Chart.prototype, 'setClassName', function (proceed) {
  369. proceed.apply(this, [].slice.call(arguments, 1));
  370. if (this.is3d()) {
  371. this.container.className += ' highcharts-3d-chart';
  372. }
  373. });
  374. addEvent(H.Chart, 'afterSetChartSize', function () {
  375. var chart = this,
  376. options3d = chart.options.chart.options3d;
  377. if (chart.is3d()) {
  378. var inverted = chart.inverted,
  379. clipBox = chart.clipBox,
  380. margin = chart.margin,
  381. x = inverted ? 'y' : 'x',
  382. y = inverted ? 'x' : 'y',
  383. w = inverted ? 'height' : 'width',
  384. h = inverted ? 'width' : 'height';
  385. clipBox[x] = -(margin[3] || 0);
  386. clipBox[y] = -(margin[0] || 0);
  387. clipBox[w] = chart.chartWidth + (margin[3] || 0) + (margin[1] || 0);
  388. clipBox[h] = chart.chartHeight + (margin[0] || 0) + (margin[2] || 0);
  389. // Set scale, used later in perspective method():
  390. // getScale uses perspective, so scale3d has to be reset.
  391. chart.scale3d = 1;
  392. if (options3d.fitToPlot === true) {
  393. chart.scale3d = getScale(chart, options3d.depth);
  394. }
  395. // Recalculate the 3d frame with every call of setChartSize,
  396. // instead of doing it after every redraw(). It avoids ticks
  397. // and axis title outside of chart.
  398. chart.frame3d = this.get3dFrame(); // #7942
  399. }
  400. });
  401. addEvent(Chart, 'beforeRedraw', function () {
  402. if (this.is3d()) {
  403. // Set to force a redraw of all elements
  404. this.isDirtyBox = true;
  405. }
  406. });
  407. addEvent(Chart, 'beforeRender', function () {
  408. if (this.is3d()) {
  409. this.frame3d = this.get3dFrame();
  410. }
  411. });
  412. // Draw the series in the reverse order (#3803, #3917)
  413. wrap(Chart.prototype, 'renderSeries', function (proceed) {
  414. var series,
  415. i = this.series.length;
  416. if (this.is3d()) {
  417. while (i--) {
  418. series = this.series[i];
  419. series.translate();
  420. series.render();
  421. }
  422. } else {
  423. proceed.call(this);
  424. }
  425. });
  426. addEvent(Chart, 'afterDrawChartBox', function () {
  427. if (this.is3d()) {
  428. var chart = this,
  429. renderer = chart.renderer,
  430. options3d = this.options.chart.options3d,
  431. frame = chart.get3dFrame(),
  432. xm = this.plotLeft,
  433. xp = this.plotLeft + this.plotWidth,
  434. ym = this.plotTop,
  435. yp = this.plotTop + this.plotHeight,
  436. zm = 0,
  437. zp = options3d.depth,
  438. xmm = xm - (frame.left.visible ? frame.left.size : 0),
  439. xpp = xp + (frame.right.visible ? frame.right.size : 0),
  440. ymm = ym - (frame.top.visible ? frame.top.size : 0),
  441. ypp = yp + (frame.bottom.visible ? frame.bottom.size : 0),
  442. zmm = zm - (frame.front.visible ? frame.front.size : 0),
  443. zpp = zp + (frame.back.visible ? frame.back.size : 0),
  444. verb = chart.hasRendered ? 'animate' : 'attr';
  445. this.frame3d = frame;
  446. if (!this.frameShapes) {
  447. this.frameShapes = {
  448. bottom: renderer.polyhedron().add(),
  449. top: renderer.polyhedron().add(),
  450. left: renderer.polyhedron().add(),
  451. right: renderer.polyhedron().add(),
  452. back: renderer.polyhedron().add(),
  453. front: renderer.polyhedron().add()
  454. };
  455. }
  456. this.frameShapes.bottom[verb]({
  457. 'class': 'highcharts-3d-frame highcharts-3d-frame-bottom',
  458. zIndex: frame.bottom.frontFacing ? -1000 : 1000,
  459. faces: [{ // bottom
  460. fill: H.color(frame.bottom.color).brighten(0.1).get(),
  461. vertexes: [{
  462. x: xmm,
  463. y: ypp,
  464. z: zmm
  465. }, {
  466. x: xpp,
  467. y: ypp,
  468. z: zmm
  469. }, {
  470. x: xpp,
  471. y: ypp,
  472. z: zpp
  473. }, {
  474. x: xmm,
  475. y: ypp,
  476. z: zpp
  477. }],
  478. enabled: frame.bottom.visible
  479. },
  480. { // top
  481. fill: H.color(frame.bottom.color).brighten(0.1).get(),
  482. vertexes: [{
  483. x: xm,
  484. y: yp,
  485. z: zp
  486. }, {
  487. x: xp,
  488. y: yp,
  489. z: zp
  490. }, {
  491. x: xp,
  492. y: yp,
  493. z: zm
  494. }, {
  495. x: xm,
  496. y: yp,
  497. z: zm
  498. }],
  499. enabled: frame.bottom.visible
  500. },
  501. { // left
  502. fill: H.color(frame.bottom.color).brighten(-0.1).get(),
  503. vertexes: [{
  504. x: xmm,
  505. y: ypp,
  506. z: zmm
  507. }, {
  508. x: xmm,
  509. y: ypp,
  510. z: zpp
  511. }, {
  512. x: xm,
  513. y: yp,
  514. z: zp
  515. }, {
  516. x: xm,
  517. y: yp,
  518. z: zm
  519. }],
  520. enabled: frame.bottom.visible && !frame.left.visible
  521. },
  522. { // right
  523. fill: H.color(frame.bottom.color).brighten(-0.1).get(),
  524. vertexes: [{
  525. x: xpp,
  526. y: ypp,
  527. z: zpp
  528. }, {
  529. x: xpp,
  530. y: ypp,
  531. z: zmm
  532. }, {
  533. x: xp,
  534. y: yp,
  535. z: zm
  536. }, {
  537. x: xp,
  538. y: yp,
  539. z: zp
  540. }],
  541. enabled: frame.bottom.visible && !frame.right.visible
  542. },
  543. { // front
  544. fill: H.color(frame.bottom.color).get(),
  545. vertexes: [{
  546. x: xpp,
  547. y: ypp,
  548. z: zmm
  549. }, {
  550. x: xmm,
  551. y: ypp,
  552. z: zmm
  553. }, {
  554. x: xm,
  555. y: yp,
  556. z: zm
  557. }, {
  558. x: xp,
  559. y: yp,
  560. z: zm
  561. }],
  562. enabled: frame.bottom.visible && !frame.front.visible
  563. },
  564. { // back
  565. fill: H.color(frame.bottom.color).get(),
  566. vertexes: [{
  567. x: xmm,
  568. y: ypp,
  569. z: zpp
  570. }, {
  571. x: xpp,
  572. y: ypp,
  573. z: zpp
  574. }, {
  575. x: xp,
  576. y: yp,
  577. z: zp
  578. }, {
  579. x: xm,
  580. y: yp,
  581. z: zp
  582. }],
  583. enabled: frame.bottom.visible && !frame.back.visible
  584. }]
  585. });
  586. this.frameShapes.top[verb]({
  587. 'class': 'highcharts-3d-frame highcharts-3d-frame-top',
  588. zIndex: frame.top.frontFacing ? -1000 : 1000,
  589. faces: [{ // bottom
  590. fill: H.color(frame.top.color).brighten(0.1).get(),
  591. vertexes: [{
  592. x: xmm,
  593. y: ymm,
  594. z: zpp
  595. }, {
  596. x: xpp,
  597. y: ymm,
  598. z: zpp
  599. }, {
  600. x: xpp,
  601. y: ymm,
  602. z: zmm
  603. }, {
  604. x: xmm,
  605. y: ymm,
  606. z: zmm
  607. }],
  608. enabled: frame.top.visible
  609. },
  610. { // top
  611. fill: H.color(frame.top.color).brighten(0.1).get(),
  612. vertexes: [{
  613. x: xm,
  614. y: ym,
  615. z: zm
  616. }, {
  617. x: xp,
  618. y: ym,
  619. z: zm
  620. }, {
  621. x: xp,
  622. y: ym,
  623. z: zp
  624. }, {
  625. x: xm,
  626. y: ym,
  627. z: zp
  628. }],
  629. enabled: frame.top.visible
  630. },
  631. { // left
  632. fill: H.color(frame.top.color).brighten(-0.1).get(),
  633. vertexes: [{
  634. x: xmm,
  635. y: ymm,
  636. z: zpp
  637. }, {
  638. x: xmm,
  639. y: ymm,
  640. z: zmm
  641. }, {
  642. x: xm,
  643. y: ym,
  644. z: zm
  645. }, {
  646. x: xm,
  647. y: ym,
  648. z: zp
  649. }],
  650. enabled: frame.top.visible && !frame.left.visible
  651. },
  652. { // right
  653. fill: H.color(frame.top.color).brighten(-0.1).get(),
  654. vertexes: [{
  655. x: xpp,
  656. y: ymm,
  657. z: zmm
  658. }, {
  659. x: xpp,
  660. y: ymm,
  661. z: zpp
  662. }, {
  663. x: xp,
  664. y: ym,
  665. z: zp
  666. }, {
  667. x: xp,
  668. y: ym,
  669. z: zm
  670. }],
  671. enabled: frame.top.visible && !frame.right.visible
  672. },
  673. { // front
  674. fill: H.color(frame.top.color).get(),
  675. vertexes: [{
  676. x: xmm,
  677. y: ymm,
  678. z: zmm
  679. }, {
  680. x: xpp,
  681. y: ymm,
  682. z: zmm
  683. }, {
  684. x: xp,
  685. y: ym,
  686. z: zm
  687. }, {
  688. x: xm,
  689. y: ym,
  690. z: zm
  691. }],
  692. enabled: frame.top.visible && !frame.front.visible
  693. },
  694. { // back
  695. fill: H.color(frame.top.color).get(),
  696. vertexes: [{
  697. x: xpp,
  698. y: ymm,
  699. z: zpp
  700. }, {
  701. x: xmm,
  702. y: ymm,
  703. z: zpp
  704. }, {
  705. x: xm,
  706. y: ym,
  707. z: zp
  708. }, {
  709. x: xp,
  710. y: ym,
  711. z: zp
  712. }],
  713. enabled: frame.top.visible && !frame.back.visible
  714. }]
  715. });
  716. this.frameShapes.left[verb]({
  717. 'class': 'highcharts-3d-frame highcharts-3d-frame-left',
  718. zIndex: frame.left.frontFacing ? -1000 : 1000,
  719. faces: [{ // bottom
  720. fill: H.color(frame.left.color).brighten(0.1).get(),
  721. vertexes: [{
  722. x: xmm,
  723. y: ypp,
  724. z: zmm
  725. }, {
  726. x: xm,
  727. y: yp,
  728. z: zm
  729. }, {
  730. x: xm,
  731. y: yp,
  732. z: zp
  733. }, {
  734. x: xmm,
  735. y: ypp,
  736. z: zpp
  737. }],
  738. enabled: frame.left.visible && !frame.bottom.visible
  739. },
  740. { // top
  741. fill: H.color(frame.left.color).brighten(0.1).get(),
  742. vertexes: [{
  743. x: xmm,
  744. y: ymm,
  745. z: zpp
  746. }, {
  747. x: xm,
  748. y: ym,
  749. z: zp
  750. }, {
  751. x: xm,
  752. y: ym,
  753. z: zm
  754. }, {
  755. x: xmm,
  756. y: ymm,
  757. z: zmm
  758. }],
  759. enabled: frame.left.visible && !frame.top.visible
  760. },
  761. { // left
  762. fill: H.color(frame.left.color).brighten(-0.1).get(),
  763. vertexes: [{
  764. x: xmm,
  765. y: ypp,
  766. z: zpp
  767. }, {
  768. x: xmm,
  769. y: ymm,
  770. z: zpp
  771. }, {
  772. x: xmm,
  773. y: ymm,
  774. z: zmm
  775. }, {
  776. x: xmm,
  777. y: ypp,
  778. z: zmm
  779. }],
  780. enabled: frame.left.visible
  781. },
  782. { // right
  783. fill: H.color(frame.left.color).brighten(-0.1).get(),
  784. vertexes: [{
  785. x: xm,
  786. y: ym,
  787. z: zp
  788. }, {
  789. x: xm,
  790. y: yp,
  791. z: zp
  792. }, {
  793. x: xm,
  794. y: yp,
  795. z: zm
  796. }, {
  797. x: xm,
  798. y: ym,
  799. z: zm
  800. }],
  801. enabled: frame.left.visible
  802. },
  803. { // front
  804. fill: H.color(frame.left.color).get(),
  805. vertexes: [{
  806. x: xmm,
  807. y: ypp,
  808. z: zmm
  809. }, {
  810. x: xmm,
  811. y: ymm,
  812. z: zmm
  813. }, {
  814. x: xm,
  815. y: ym,
  816. z: zm
  817. }, {
  818. x: xm,
  819. y: yp,
  820. z: zm
  821. }],
  822. enabled: frame.left.visible && !frame.front.visible
  823. },
  824. { // back
  825. fill: H.color(frame.left.color).get(),
  826. vertexes: [{
  827. x: xmm,
  828. y: ymm,
  829. z: zpp
  830. }, {
  831. x: xmm,
  832. y: ypp,
  833. z: zpp
  834. }, {
  835. x: xm,
  836. y: yp,
  837. z: zp
  838. }, {
  839. x: xm,
  840. y: ym,
  841. z: zp
  842. }],
  843. enabled: frame.left.visible && !frame.back.visible
  844. }]
  845. });
  846. this.frameShapes.right[verb]({
  847. 'class': 'highcharts-3d-frame highcharts-3d-frame-right',
  848. zIndex: frame.right.frontFacing ? -1000 : 1000,
  849. faces: [{ // bottom
  850. fill: H.color(frame.right.color).brighten(0.1).get(),
  851. vertexes: [{
  852. x: xpp,
  853. y: ypp,
  854. z: zpp
  855. }, {
  856. x: xp,
  857. y: yp,
  858. z: zp
  859. }, {
  860. x: xp,
  861. y: yp,
  862. z: zm
  863. }, {
  864. x: xpp,
  865. y: ypp,
  866. z: zmm
  867. }],
  868. enabled: frame.right.visible && !frame.bottom.visible
  869. },
  870. { // top
  871. fill: H.color(frame.right.color).brighten(0.1).get(),
  872. vertexes: [{
  873. x: xpp,
  874. y: ymm,
  875. z: zmm
  876. }, {
  877. x: xp,
  878. y: ym,
  879. z: zm
  880. }, {
  881. x: xp,
  882. y: ym,
  883. z: zp
  884. }, {
  885. x: xpp,
  886. y: ymm,
  887. z: zpp
  888. }],
  889. enabled: frame.right.visible && !frame.top.visible
  890. },
  891. { // left
  892. fill: H.color(frame.right.color).brighten(-0.1).get(),
  893. vertexes: [{
  894. x: xp,
  895. y: ym,
  896. z: zm
  897. }, {
  898. x: xp,
  899. y: yp,
  900. z: zm
  901. }, {
  902. x: xp,
  903. y: yp,
  904. z: zp
  905. }, {
  906. x: xp,
  907. y: ym,
  908. z: zp
  909. }],
  910. enabled: frame.right.visible
  911. },
  912. { // right
  913. fill: H.color(frame.right.color).brighten(-0.1).get(),
  914. vertexes: [{
  915. x: xpp,
  916. y: ypp,
  917. z: zmm
  918. }, {
  919. x: xpp,
  920. y: ymm,
  921. z: zmm
  922. }, {
  923. x: xpp,
  924. y: ymm,
  925. z: zpp
  926. }, {
  927. x: xpp,
  928. y: ypp,
  929. z: zpp
  930. }],
  931. enabled: frame.right.visible
  932. },
  933. { // front
  934. fill: H.color(frame.right.color).get(),
  935. vertexes: [{
  936. x: xpp,
  937. y: ymm,
  938. z: zmm
  939. }, {
  940. x: xpp,
  941. y: ypp,
  942. z: zmm
  943. }, {
  944. x: xp,
  945. y: yp,
  946. z: zm
  947. }, {
  948. x: xp,
  949. y: ym,
  950. z: zm
  951. }],
  952. enabled: frame.right.visible && !frame.front.visible
  953. },
  954. { // back
  955. fill: H.color(frame.right.color).get(),
  956. vertexes: [{
  957. x: xpp,
  958. y: ypp,
  959. z: zpp
  960. }, {
  961. x: xpp,
  962. y: ymm,
  963. z: zpp
  964. }, {
  965. x: xp,
  966. y: ym,
  967. z: zp
  968. }, {
  969. x: xp,
  970. y: yp,
  971. z: zp
  972. }],
  973. enabled: frame.right.visible && !frame.back.visible
  974. }]
  975. });
  976. this.frameShapes.back[verb]({
  977. 'class': 'highcharts-3d-frame highcharts-3d-frame-back',
  978. zIndex: frame.back.frontFacing ? -1000 : 1000,
  979. faces: [{ // bottom
  980. fill: H.color(frame.back.color).brighten(0.1).get(),
  981. vertexes: [{
  982. x: xpp,
  983. y: ypp,
  984. z: zpp
  985. }, {
  986. x: xmm,
  987. y: ypp,
  988. z: zpp
  989. }, {
  990. x: xm,
  991. y: yp,
  992. z: zp
  993. }, {
  994. x: xp,
  995. y: yp,
  996. z: zp
  997. }],
  998. enabled: frame.back.visible && !frame.bottom.visible
  999. },
  1000. { // top
  1001. fill: H.color(frame.back.color).brighten(0.1).get(),
  1002. vertexes: [{
  1003. x: xmm,
  1004. y: ymm,
  1005. z: zpp
  1006. }, {
  1007. x: xpp,
  1008. y: ymm,
  1009. z: zpp
  1010. }, {
  1011. x: xp,
  1012. y: ym,
  1013. z: zp
  1014. }, {
  1015. x: xm,
  1016. y: ym,
  1017. z: zp
  1018. }],
  1019. enabled: frame.back.visible && !frame.top.visible
  1020. },
  1021. { // left
  1022. fill: H.color(frame.back.color).brighten(-0.1).get(),
  1023. vertexes: [{
  1024. x: xmm,
  1025. y: ypp,
  1026. z: zpp
  1027. }, {
  1028. x: xmm,
  1029. y: ymm,
  1030. z: zpp
  1031. }, {
  1032. x: xm,
  1033. y: ym,
  1034. z: zp
  1035. }, {
  1036. x: xm,
  1037. y: yp,
  1038. z: zp
  1039. }],
  1040. enabled: frame.back.visible && !frame.left.visible
  1041. },
  1042. { // right
  1043. fill: H.color(frame.back.color).brighten(-0.1).get(),
  1044. vertexes: [{
  1045. x: xpp,
  1046. y: ymm,
  1047. z: zpp
  1048. }, {
  1049. x: xpp,
  1050. y: ypp,
  1051. z: zpp
  1052. }, {
  1053. x: xp,
  1054. y: yp,
  1055. z: zp
  1056. }, {
  1057. x: xp,
  1058. y: ym,
  1059. z: zp
  1060. }],
  1061. enabled: frame.back.visible && !frame.right.visible
  1062. },
  1063. { // front
  1064. fill: H.color(frame.back.color).get(),
  1065. vertexes: [{
  1066. x: xm,
  1067. y: ym,
  1068. z: zp
  1069. }, {
  1070. x: xp,
  1071. y: ym,
  1072. z: zp
  1073. }, {
  1074. x: xp,
  1075. y: yp,
  1076. z: zp
  1077. }, {
  1078. x: xm,
  1079. y: yp,
  1080. z: zp
  1081. }],
  1082. enabled: frame.back.visible
  1083. },
  1084. { // back
  1085. fill: H.color(frame.back.color).get(),
  1086. vertexes: [{
  1087. x: xmm,
  1088. y: ypp,
  1089. z: zpp
  1090. }, {
  1091. x: xpp,
  1092. y: ypp,
  1093. z: zpp
  1094. }, {
  1095. x: xpp,
  1096. y: ymm,
  1097. z: zpp
  1098. }, {
  1099. x: xmm,
  1100. y: ymm,
  1101. z: zpp
  1102. }],
  1103. enabled: frame.back.visible
  1104. }]
  1105. });
  1106. this.frameShapes.front[verb]({
  1107. 'class': 'highcharts-3d-frame highcharts-3d-frame-front',
  1108. zIndex: frame.front.frontFacing ? -1000 : 1000,
  1109. faces: [{ // bottom
  1110. fill: H.color(frame.front.color).brighten(0.1).get(),
  1111. vertexes: [{
  1112. x: xmm,
  1113. y: ypp,
  1114. z: zmm
  1115. }, {
  1116. x: xpp,
  1117. y: ypp,
  1118. z: zmm
  1119. }, {
  1120. x: xp,
  1121. y: yp,
  1122. z: zm
  1123. }, {
  1124. x: xm,
  1125. y: yp,
  1126. z: zm
  1127. }],
  1128. enabled: frame.front.visible && !frame.bottom.visible
  1129. },
  1130. { // top
  1131. fill: H.color(frame.front.color).brighten(0.1).get(),
  1132. vertexes: [{
  1133. x: xpp,
  1134. y: ymm,
  1135. z: zmm
  1136. }, {
  1137. x: xmm,
  1138. y: ymm,
  1139. z: zmm
  1140. }, {
  1141. x: xm,
  1142. y: ym,
  1143. z: zm
  1144. }, {
  1145. x: xp,
  1146. y: ym,
  1147. z: zm
  1148. }],
  1149. enabled: frame.front.visible && !frame.top.visible
  1150. },
  1151. { // left
  1152. fill: H.color(frame.front.color).brighten(-0.1).get(),
  1153. vertexes: [{
  1154. x: xmm,
  1155. y: ymm,
  1156. z: zmm
  1157. }, {
  1158. x: xmm,
  1159. y: ypp,
  1160. z: zmm
  1161. }, {
  1162. x: xm,
  1163. y: yp,
  1164. z: zm
  1165. }, {
  1166. x: xm,
  1167. y: ym,
  1168. z: zm
  1169. }],
  1170. enabled: frame.front.visible && !frame.left.visible
  1171. },
  1172. { // right
  1173. fill: H.color(frame.front.color).brighten(-0.1).get(),
  1174. vertexes: [{
  1175. x: xpp,
  1176. y: ypp,
  1177. z: zmm
  1178. }, {
  1179. x: xpp,
  1180. y: ymm,
  1181. z: zmm
  1182. }, {
  1183. x: xp,
  1184. y: ym,
  1185. z: zm
  1186. }, {
  1187. x: xp,
  1188. y: yp,
  1189. z: zm
  1190. }],
  1191. enabled: frame.front.visible && !frame.right.visible
  1192. },
  1193. { // front
  1194. fill: H.color(frame.front.color).get(),
  1195. vertexes: [{
  1196. x: xp,
  1197. y: ym,
  1198. z: zm
  1199. }, {
  1200. x: xm,
  1201. y: ym,
  1202. z: zm
  1203. }, {
  1204. x: xm,
  1205. y: yp,
  1206. z: zm
  1207. }, {
  1208. x: xp,
  1209. y: yp,
  1210. z: zm
  1211. }],
  1212. enabled: frame.front.visible
  1213. },
  1214. { // back
  1215. fill: H.color(frame.front.color).get(),
  1216. vertexes: [{
  1217. x: xpp,
  1218. y: ypp,
  1219. z: zmm
  1220. }, {
  1221. x: xmm,
  1222. y: ypp,
  1223. z: zmm
  1224. }, {
  1225. x: xmm,
  1226. y: ymm,
  1227. z: zmm
  1228. }, {
  1229. x: xpp,
  1230. y: ymm,
  1231. z: zmm
  1232. }],
  1233. enabled: frame.front.visible
  1234. }]
  1235. });
  1236. }
  1237. });
  1238. Chart.prototype.retrieveStacks = function (stacking) {
  1239. var series = this.series,
  1240. stacks = {},
  1241. stackNumber,
  1242. i = 1;
  1243. this.series.forEach(function (s) {
  1244. stackNumber = pick(
  1245. s.options.stack,
  1246. (stacking ? 0 : series.length - 1 - s.index)
  1247. ); // #3841, #4532
  1248. if (!stacks[stackNumber]) {
  1249. stacks[stackNumber] = { series: [s], position: i };
  1250. i++;
  1251. } else {
  1252. stacks[stackNumber].series.push(s);
  1253. }
  1254. });
  1255. stacks.totalStacks = i + 1;
  1256. return stacks;
  1257. };
  1258. Chart.prototype.get3dFrame = function () {
  1259. var chart = this,
  1260. options3d = chart.options.chart.options3d,
  1261. frameOptions = options3d.frame,
  1262. xm = chart.plotLeft,
  1263. xp = chart.plotLeft + chart.plotWidth,
  1264. ym = chart.plotTop,
  1265. yp = chart.plotTop + chart.plotHeight,
  1266. zm = 0,
  1267. zp = options3d.depth,
  1268. faceOrientation = function (vertexes) {
  1269. var area = H.shapeArea3d(vertexes, chart);
  1270. // Give it 0.5 squared-pixel as a margin for rounding errors.
  1271. if (area > 0.5) {
  1272. return 1;
  1273. }
  1274. if (area < -0.5) {
  1275. return -1;
  1276. }
  1277. return 0;
  1278. },
  1279. bottomOrientation = faceOrientation([
  1280. { x: xm, y: yp, z: zp },
  1281. { x: xp, y: yp, z: zp },
  1282. { x: xp, y: yp, z: zm },
  1283. { x: xm, y: yp, z: zm }
  1284. ]),
  1285. topOrientation = faceOrientation([
  1286. { x: xm, y: ym, z: zm },
  1287. { x: xp, y: ym, z: zm },
  1288. { x: xp, y: ym, z: zp },
  1289. { x: xm, y: ym, z: zp }
  1290. ]),
  1291. leftOrientation = faceOrientation([
  1292. { x: xm, y: ym, z: zm },
  1293. { x: xm, y: ym, z: zp },
  1294. { x: xm, y: yp, z: zp },
  1295. { x: xm, y: yp, z: zm }
  1296. ]),
  1297. rightOrientation = faceOrientation([
  1298. { x: xp, y: ym, z: zp },
  1299. { x: xp, y: ym, z: zm },
  1300. { x: xp, y: yp, z: zm },
  1301. { x: xp, y: yp, z: zp }
  1302. ]),
  1303. frontOrientation = faceOrientation([
  1304. { x: xm, y: yp, z: zm },
  1305. { x: xp, y: yp, z: zm },
  1306. { x: xp, y: ym, z: zm },
  1307. { x: xm, y: ym, z: zm }
  1308. ]),
  1309. backOrientation = faceOrientation([
  1310. { x: xm, y: ym, z: zp },
  1311. { x: xp, y: ym, z: zp },
  1312. { x: xp, y: yp, z: zp },
  1313. { x: xm, y: yp, z: zp }
  1314. ]),
  1315. defaultShowBottom = false,
  1316. defaultShowTop = false,
  1317. defaultShowLeft = false,
  1318. defaultShowRight = false,
  1319. defaultShowFront = false,
  1320. defaultShowBack = true;
  1321. // The 'default' criteria to visible faces of the frame is looking up every
  1322. // axis to decide whenever the left/right//top/bottom sides of the frame
  1323. // will be shown
  1324. [].concat(chart.xAxis, chart.yAxis, chart.zAxis).forEach(function (axis) {
  1325. if (axis) {
  1326. if (axis.horiz) {
  1327. if (axis.opposite) {
  1328. defaultShowTop = true;
  1329. } else {
  1330. defaultShowBottom = true;
  1331. }
  1332. } else {
  1333. if (axis.opposite) {
  1334. defaultShowRight = true;
  1335. } else {
  1336. defaultShowLeft = true;
  1337. }
  1338. }
  1339. }
  1340. });
  1341. var getFaceOptions = function (sources, faceOrientation, defaultVisible) {
  1342. var faceAttrs = ['size', 'color', 'visible'];
  1343. var options = {};
  1344. for (var i = 0; i < faceAttrs.length; i++) {
  1345. var attr = faceAttrs[i];
  1346. for (var j = 0; j < sources.length; j++) {
  1347. if (typeof sources[j] === 'object') {
  1348. var val = sources[j][attr];
  1349. if (val !== undefined && val !== null) {
  1350. options[attr] = val;
  1351. break;
  1352. }
  1353. }
  1354. }
  1355. }
  1356. var isVisible = defaultVisible;
  1357. if (options.visible === true || options.visible === false) {
  1358. isVisible = options.visible;
  1359. } else if (options.visible === 'auto') {
  1360. isVisible = faceOrientation > 0;
  1361. }
  1362. return {
  1363. size: pick(options.size, 1),
  1364. color: pick(options.color, 'none'),
  1365. frontFacing: faceOrientation > 0,
  1366. visible: isVisible
  1367. };
  1368. };
  1369. // docs @TODO: Add all frame options (left, right, top, bottom, front, back)
  1370. // to apioptions JSDoc once the new system is up.
  1371. var ret = {
  1372. // FIXME: Previously, left/right, top/bottom and front/back pairs shared
  1373. // size and color.
  1374. // For compatibility and consistency sake, when one face have
  1375. // size/color/visibility set, the opposite face will default to the same
  1376. // values. Also, left/right used to be called 'side', so that's also
  1377. // added as a fallback
  1378. bottom: getFaceOptions(
  1379. [frameOptions.bottom, frameOptions.top, frameOptions],
  1380. bottomOrientation,
  1381. defaultShowBottom
  1382. ),
  1383. top: getFaceOptions(
  1384. [frameOptions.top, frameOptions.bottom, frameOptions],
  1385. topOrientation,
  1386. defaultShowTop
  1387. ),
  1388. left: getFaceOptions(
  1389. [
  1390. frameOptions.left,
  1391. frameOptions.right,
  1392. frameOptions.side,
  1393. frameOptions
  1394. ],
  1395. leftOrientation,
  1396. defaultShowLeft
  1397. ),
  1398. right: getFaceOptions(
  1399. [
  1400. frameOptions.right,
  1401. frameOptions.left,
  1402. frameOptions.side,
  1403. frameOptions
  1404. ],
  1405. rightOrientation,
  1406. defaultShowRight
  1407. ),
  1408. back: getFaceOptions(
  1409. [frameOptions.back, frameOptions.front, frameOptions],
  1410. backOrientation,
  1411. defaultShowBack
  1412. ),
  1413. front: getFaceOptions(
  1414. [frameOptions.front, frameOptions.back, frameOptions],
  1415. frontOrientation,
  1416. defaultShowFront
  1417. )
  1418. };
  1419. // Decide the bast place to put axis title/labels based on the visible
  1420. // faces. Ideally, The labels can only be on the edge between a visible face
  1421. // and an invisble one. Also, the Y label should be one the left-most edge
  1422. // (right-most if opposite),
  1423. if (options3d.axisLabelPosition === 'auto') {
  1424. var isValidEdge = function (face1, face2) {
  1425. return (
  1426. (face1.visible !== face2.visible) ||
  1427. (
  1428. face1.visible &&
  1429. face2.visible &&
  1430. (face1.frontFacing !== face2.frontFacing)
  1431. )
  1432. );
  1433. };
  1434. var yEdges = [];
  1435. if (isValidEdge(ret.left, ret.front)) {
  1436. yEdges.push({
  1437. y: (ym + yp) / 2,
  1438. x: xm,
  1439. z: zm,
  1440. xDir: { x: 1, y: 0, z: 0 }
  1441. });
  1442. }
  1443. if (isValidEdge(ret.left, ret.back)) {
  1444. yEdges.push({
  1445. y: (ym + yp) / 2,
  1446. x: xm,
  1447. z: zp,
  1448. xDir: { x: 0, y: 0, z: -1 }
  1449. });
  1450. }
  1451. if (isValidEdge(ret.right, ret.front)) {
  1452. yEdges.push({
  1453. y: (ym + yp) / 2,
  1454. x: xp,
  1455. z: zm,
  1456. xDir: { x: 0, y: 0, z: 1 }
  1457. });
  1458. }
  1459. if (isValidEdge(ret.right, ret.back)) {
  1460. yEdges.push({
  1461. y: (ym + yp) / 2,
  1462. x: xp,
  1463. z: zp,
  1464. xDir: { x: -1, y: 0, z: 0 }
  1465. });
  1466. }
  1467. var xBottomEdges = [];
  1468. if (isValidEdge(ret.bottom, ret.front)) {
  1469. xBottomEdges.push({
  1470. x: (xm + xp) / 2,
  1471. y: yp,
  1472. z: zm,
  1473. xDir: { x: 1, y: 0, z: 0 }
  1474. });
  1475. }
  1476. if (isValidEdge(ret.bottom, ret.back)) {
  1477. xBottomEdges.push({
  1478. x: (xm + xp) / 2,
  1479. y: yp,
  1480. z: zp,
  1481. xDir: { x: -1, y: 0, z: 0 }
  1482. });
  1483. }
  1484. var xTopEdges = [];
  1485. if (isValidEdge(ret.top, ret.front)) {
  1486. xTopEdges.push({
  1487. x: (xm + xp) / 2,
  1488. y: ym,
  1489. z: zm,
  1490. xDir: { x: 1, y: 0, z: 0 }
  1491. });
  1492. }
  1493. if (isValidEdge(ret.top, ret.back)) {
  1494. xTopEdges.push({
  1495. x: (xm + xp) / 2,
  1496. y: ym,
  1497. z: zp,
  1498. xDir: { x: -1, y: 0, z: 0 }
  1499. });
  1500. }
  1501. var zBottomEdges = [];
  1502. if (isValidEdge(ret.bottom, ret.left)) {
  1503. zBottomEdges.push({
  1504. z: (zm + zp) / 2,
  1505. y: yp,
  1506. x: xm,
  1507. xDir: { x: 0, y: 0, z: -1 }
  1508. });
  1509. }
  1510. if (isValidEdge(ret.bottom, ret.right)) {
  1511. zBottomEdges.push({
  1512. z: (zm + zp) / 2,
  1513. y: yp,
  1514. x: xp,
  1515. xDir: { x: 0, y: 0, z: 1 }
  1516. });
  1517. }
  1518. var zTopEdges = [];
  1519. if (isValidEdge(ret.top, ret.left)) {
  1520. zTopEdges.push({
  1521. z: (zm + zp) / 2,
  1522. y: ym,
  1523. x: xm,
  1524. xDir: { x: 0, y: 0, z: -1 }
  1525. });
  1526. }
  1527. if (isValidEdge(ret.top, ret.right)) {
  1528. zTopEdges.push({
  1529. z: (zm + zp) / 2,
  1530. y: ym,
  1531. x: xp,
  1532. xDir: { x: 0, y: 0, z: 1 }
  1533. });
  1534. }
  1535. var pickEdge = function (edges, axis, mult) {
  1536. if (edges.length === 0) {
  1537. return null;
  1538. }
  1539. if (edges.length === 1) {
  1540. return edges[0];
  1541. }
  1542. var best = 0,
  1543. projections = perspective(edges, chart, false);
  1544. for (var i = 1; i < projections.length; i++) {
  1545. if (
  1546. mult * projections[i][axis] >
  1547. mult * projections[best][axis]
  1548. ) {
  1549. best = i;
  1550. } else if (
  1551. (
  1552. mult * projections[i][axis] ===
  1553. mult * projections[best][axis]
  1554. ) &&
  1555. (projections[i].z < projections[best].z)
  1556. ) {
  1557. best = i;
  1558. }
  1559. }
  1560. return edges[best];
  1561. };
  1562. ret.axes = {
  1563. y: {
  1564. 'left': pickEdge(yEdges, 'x', -1),
  1565. 'right': pickEdge(yEdges, 'x', +1)
  1566. },
  1567. x: {
  1568. 'top': pickEdge(xTopEdges, 'y', -1),
  1569. 'bottom': pickEdge(xBottomEdges, 'y', +1)
  1570. },
  1571. z: {
  1572. 'top': pickEdge(zTopEdges, 'y', -1),
  1573. 'bottom': pickEdge(zBottomEdges, 'y', +1)
  1574. }
  1575. };
  1576. } else {
  1577. ret.axes = {
  1578. y: {
  1579. 'left': { x: xm, z: zm, xDir: { x: 1, y: 0, z: 0 } },
  1580. 'right': { x: xp, z: zm, xDir: { x: 0, y: 0, z: 1 } }
  1581. },
  1582. x: {
  1583. 'top': { y: ym, z: zm, xDir: { x: 1, y: 0, z: 0 } },
  1584. 'bottom': { y: yp, z: zm, xDir: { x: 1, y: 0, z: 0 } }
  1585. },
  1586. z: {
  1587. 'top': {
  1588. x: defaultShowLeft ? xp : xm,
  1589. y: ym,
  1590. xDir: defaultShowLeft ?
  1591. { x: 0, y: 0, z: 1 } :
  1592. { x: 0, y: 0, z: -1 }
  1593. },
  1594. 'bottom': {
  1595. x: defaultShowLeft ? xp : xm,
  1596. y: yp,
  1597. xDir: defaultShowLeft ?
  1598. { x: 0, y: 0, z: 1 } :
  1599. { x: 0, y: 0, z: -1 }
  1600. }
  1601. }
  1602. };
  1603. }
  1604. return ret;
  1605. };
  1606. // Animation setter for matrix property.
  1607. H.Fx.prototype.matrixSetter = function () {
  1608. var interpolated;
  1609. if (this.pos < 1 &&
  1610. (H.isArray(this.start) || H.isArray(this.end))) {
  1611. var start = this.start || [1, 0, 0, 1, 0, 0];
  1612. var end = this.end || [1, 0, 0, 1, 0, 0];
  1613. interpolated = [];
  1614. for (var i = 0; i < 6; i++) {
  1615. interpolated.push(this.pos * end[i] + (1 - this.pos) * start[i]);
  1616. }
  1617. } else {
  1618. interpolated = this.end;
  1619. }
  1620. this.elem.attr(
  1621. this.prop,
  1622. interpolated,
  1623. null,
  1624. true
  1625. );
  1626. };
  1627. /**
  1628. * Note: As of v5.0.12, `frame.left` or `frame.right` should be used instead.
  1629. *
  1630. * The side for the frame around a 3D chart.
  1631. *
  1632. * @deprecated
  1633. * @since 4.0
  1634. * @product highcharts
  1635. * @apioption chart.options3d.frame.side
  1636. */
  1637. /**
  1638. * The color of the panel.
  1639. *
  1640. * @deprecated
  1641. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1642. * @default transparent
  1643. * @since 4.0
  1644. * @product highcharts
  1645. * @apioption chart.options3d.frame.side.color
  1646. */
  1647. /**
  1648. * The thickness of the panel.
  1649. *
  1650. * @deprecated
  1651. * @type {number}
  1652. * @default 1
  1653. * @since 4.0
  1654. * @product highcharts
  1655. * @apioption chart.options3d.frame.side.size
  1656. */