aba13ac646eecc78d746a42279859246e1b1c094.svn-base 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license Highcharts JS v4.2.5 (2016-05-06)
  5. *
  6. * 3D features for Highcharts JS
  7. *
  8. * @license: www.highcharts.com/license
  9. */
  10. (function (factory) {
  11. if (typeof module === 'object' && module.exports) {
  12. module.exports = factory;
  13. } else {
  14. factory(Highcharts);
  15. }
  16. }(function (Highcharts) {
  17. /**
  18. Shorthands for often used function
  19. */
  20. var animObject = Highcharts.animObject,
  21. each = Highcharts.each,
  22. extend = Highcharts.extend,
  23. inArray = Highcharts.inArray,
  24. merge = Highcharts.merge,
  25. pick = Highcharts.pick,
  26. wrap = Highcharts.wrap;
  27. /**
  28. * Mathematical Functionility
  29. */
  30. var PI = Math.PI,
  31. deg2rad = (PI / 180), // degrees to radians
  32. sin = Math.sin,
  33. cos = Math.cos,
  34. round = Math.round;
  35. /**
  36. * Transforms a given array of points according to the angles in chart.options.
  37. * Parameters:
  38. * - points: the array of points
  39. * - chart: the chart
  40. * - insidePlotArea: wether to verifiy the points are inside the plotArea
  41. * Returns:
  42. * - an array of transformed points
  43. */
  44. function perspective(points, chart, insidePlotArea) {
  45. var options3d = chart.options.chart.options3d,
  46. inverted = false,
  47. origin,
  48. scale = chart.scale3d || 1;
  49. if (insidePlotArea) {
  50. inverted = chart.inverted;
  51. origin = {
  52. x: chart.plotWidth / 2,
  53. y: chart.plotHeight / 2,
  54. z: options3d.depth / 2,
  55. vd: pick(options3d.depth, 1) * pick(options3d.viewDistance, 0)
  56. };
  57. } else {
  58. origin = {
  59. x: chart.plotLeft + (chart.plotWidth / 2),
  60. y: chart.plotTop + (chart.plotHeight / 2),
  61. z: options3d.depth / 2,
  62. vd: pick(options3d.depth, 1) * pick(options3d.viewDistance, 0)
  63. };
  64. }
  65. var result = [],
  66. xe = origin.x,
  67. ye = origin.y,
  68. ze = origin.z,
  69. vd = origin.vd,
  70. angle1 = deg2rad * (inverted ? options3d.beta : -options3d.beta),
  71. angle2 = deg2rad * (inverted ? -options3d.alpha : options3d.alpha),
  72. s1 = sin(angle1),
  73. c1 = cos(angle1),
  74. s2 = sin(angle2),
  75. c2 = cos(angle2);
  76. var x, y, z, px, py, pz;
  77. // Transform each point
  78. each(points, function (point) {
  79. x = (inverted ? point.y : point.x) - xe;
  80. y = (inverted ? point.x : point.y) - ye;
  81. z = (point.z || 0) - ze;
  82. // Apply 3-D rotation
  83. // Euler Angles (XYZ): cosA = cos(Alfa|Roll), cosB = cos(Beta|Pitch), cosG = cos(Gamma|Yaw)
  84. //
  85. // Composite rotation:
  86. // | cosB * cosG | cosB * sinG | -sinB |
  87. // | sinA * sinB * cosG - cosA * sinG | sinA * sinB * sinG + cosA * cosG | sinA * cosB |
  88. // | cosA * sinB * cosG + sinA * sinG | cosA * sinB * sinG - sinA * cosG | cosA * cosB |
  89. //
  90. // Now, Gamma/Yaw is not used (angle=0), so we assume cosG = 1 and sinG = 0, so we get:
  91. // | cosB | 0 | - sinB |
  92. // | sinA * sinB | cosA | sinA * cosB |
  93. // | cosA * sinB | - sinA | cosA * cosB |
  94. //
  95. // But in browsers, y is reversed, so we get sinA => -sinA. The general result is:
  96. // | cosB | 0 | - sinB | | x | | px |
  97. // | - sinA * sinB | cosA | - sinA * cosB | x | y | = | py |
  98. // | cosA * sinB | sinA | cosA * cosB | | z | | pz |
  99. //
  100. // Result:
  101. px = c1 * x - s1 * z;
  102. py = -s1 * s2 * x + c2 * y - c1 * s2 * z;
  103. pz = s1 * c2 * x + s2 * y + c1 * c2 * z;
  104. // Apply perspective
  105. if ((vd > 0) && (vd < Number.POSITIVE_INFINITY)) {
  106. px = px * (vd / (pz + ze + vd));
  107. py = py * (vd / (pz + ze + vd));
  108. }
  109. //Apply translation
  110. px = px * scale + xe;
  111. py = py * scale + ye;
  112. pz = pz * scale + ze;
  113. result.push({
  114. x: (inverted ? py : px),
  115. y: (inverted ? px : py),
  116. z: pz
  117. });
  118. });
  119. return result;
  120. }
  121. // Make function acessible to plugins
  122. Highcharts.perspective = perspective;
  123. /***
  124. EXTENSION TO THE SVG-RENDERER TO ENABLE 3D SHAPES
  125. ***/
  126. ////// HELPER METHODS //////
  127. var dFactor = (4 * (Math.sqrt(2) - 1) / 3) / (PI / 2);
  128. function defined(obj) {
  129. return obj !== undefined && obj !== null;
  130. }
  131. //Shoelace algorithm -- http://en.wikipedia.org/wiki/Shoelace_formula
  132. function shapeArea(vertexes) {
  133. var area = 0,
  134. i,
  135. j;
  136. for (i = 0; i < vertexes.length; i++) {
  137. j = (i + 1) % vertexes.length;
  138. area += vertexes[i].x * vertexes[j].y - vertexes[j].x * vertexes[i].y;
  139. }
  140. return area / 2;
  141. }
  142. function averageZ(vertexes) {
  143. var z = 0,
  144. i;
  145. for (i = 0; i < vertexes.length; i++) {
  146. z += vertexes[i].z;
  147. }
  148. return vertexes.length ? z / vertexes.length : 0;
  149. }
  150. /** Method to construct a curved path
  151. * Can 'wrap' around more then 180 degrees
  152. */
  153. function curveTo(cx, cy, rx, ry, start, end, dx, dy) {
  154. var result = [];
  155. if ((end > start) && (end - start > PI / 2 + 0.0001)) {
  156. result = result.concat(curveTo(cx, cy, rx, ry, start, start + (PI / 2), dx, dy));
  157. result = result.concat(curveTo(cx, cy, rx, ry, start + (PI / 2), end, dx, dy));
  158. } else if ((end < start) && (start - end > PI / 2 + 0.0001)) {
  159. result = result.concat(curveTo(cx, cy, rx, ry, start, start - (PI / 2), dx, dy));
  160. result = result.concat(curveTo(cx, cy, rx, ry, start - (PI / 2), end, dx, dy));
  161. } else {
  162. var arcAngle = end - start;
  163. result = [
  164. 'C',
  165. cx + (rx * cos(start)) - ((rx * dFactor * arcAngle) * sin(start)) + dx,
  166. cy + (ry * sin(start)) + ((ry * dFactor * arcAngle) * cos(start)) + dy,
  167. cx + (rx * cos(end)) + ((rx * dFactor * arcAngle) * sin(end)) + dx,
  168. cy + (ry * sin(end)) - ((ry * dFactor * arcAngle) * cos(end)) + dy,
  169. cx + (rx * cos(end)) + dx,
  170. cy + (ry * sin(end)) + dy
  171. ];
  172. }
  173. return result;
  174. }
  175. Highcharts.SVGRenderer.prototype.toLinePath = function (points, closed) {
  176. var result = [];
  177. // Put "L x y" for each point
  178. Highcharts.each(points, function (point) {
  179. result.push('L', point.x, point.y);
  180. });
  181. if (points.length) {
  182. // Set the first element to M
  183. result[0] = 'M';
  184. // If it is a closed line, add Z
  185. if (closed) {
  186. result.push('Z');
  187. }
  188. }
  189. return result;
  190. };
  191. ////// CUBOIDS //////
  192. Highcharts.SVGRenderer.prototype.cuboid = function (shapeArgs) {
  193. var result = this.g(),
  194. paths = this.cuboidPath(shapeArgs);
  195. // create the 3 sides
  196. result.front = this.path(paths[0]).attr({ zIndex: paths[3], 'stroke-linejoin': 'round' }).add(result);
  197. result.top = this.path(paths[1]).attr({ zIndex: paths[4], 'stroke-linejoin': 'round' }).add(result);
  198. result.side = this.path(paths[2]).attr({ zIndex: paths[5], 'stroke-linejoin': 'round' }).add(result);
  199. // apply the fill everywhere, the top a bit brighter, the side a bit darker
  200. result.fillSetter = function (color) {
  201. var c0 = color,
  202. c1 = Highcharts.Color(color).brighten(0.1).get(),
  203. c2 = Highcharts.Color(color).brighten(-0.1).get();
  204. this.front.attr({ fill: c0 });
  205. this.top.attr({ fill: c1 });
  206. this.side.attr({ fill: c2 });
  207. this.color = color;
  208. return this;
  209. };
  210. // apply opacaity everywhere
  211. result.opacitySetter = function (opacity) {
  212. this.front.attr({ opacity: opacity });
  213. this.top.attr({ opacity: opacity });
  214. this.side.attr({ opacity: opacity });
  215. return this;
  216. };
  217. result.attr = function (args) {
  218. if (args.shapeArgs || defined(args.x)) {
  219. var shapeArgs = args.shapeArgs || args;
  220. var paths = this.renderer.cuboidPath(shapeArgs);
  221. this.front.attr({ d: paths[0], zIndex: paths[3] });
  222. this.top.attr({ d: paths[1], zIndex: paths[4] });
  223. this.side.attr({ d: paths[2], zIndex: paths[5] });
  224. } else {
  225. return Highcharts.SVGElement.prototype.attr.call(this, args); // getter returns value
  226. }
  227. return this;
  228. };
  229. result.animate = function (args, duration, complete) {
  230. if (defined(args.x) && defined(args.y)) {
  231. var paths = this.renderer.cuboidPath(args);
  232. this.front.attr({ zIndex: paths[3] }).animate({ d: paths[0] }, duration, complete);
  233. this.top.attr({ zIndex: paths[4] }).animate({ d: paths[1] }, duration, complete);
  234. this.side.attr({ zIndex: paths[5] }).animate({ d: paths[2] }, duration, complete);
  235. this.attr({
  236. zIndex: -paths[6] // #4774
  237. });
  238. } else if (args.opacity) {
  239. this.front.animate(args, duration, complete);
  240. this.top.animate(args, duration, complete);
  241. this.side.animate(args, duration, complete);
  242. } else {
  243. Highcharts.SVGElement.prototype.animate.call(this, args, duration, complete);
  244. }
  245. return this;
  246. };
  247. // destroy all children
  248. result.destroy = function () {
  249. this.front.destroy();
  250. this.top.destroy();
  251. this.side.destroy();
  252. return null;
  253. };
  254. // Apply the Z index to the cuboid group
  255. result.attr({ zIndex: -paths[6] });
  256. return result;
  257. };
  258. /**
  259. * Generates a cuboid
  260. */
  261. Highcharts.SVGRenderer.prototype.cuboidPath = function (shapeArgs) {
  262. var x = shapeArgs.x,
  263. y = shapeArgs.y,
  264. z = shapeArgs.z,
  265. h = shapeArgs.height,
  266. w = shapeArgs.width,
  267. d = shapeArgs.depth,
  268. chart = Highcharts.charts[this.chartIndex],
  269. map = Highcharts.map;
  270. // The 8 corners of the cube
  271. var pArr = [
  272. { x: x, y: y, z: z },
  273. { x: x + w, y: y, z: z },
  274. { x: x + w, y: y + h, z: z },
  275. { x: x, y: y + h, z: z },
  276. { x: x, y: y + h, z: z + d },
  277. { x: x + w, y: y + h, z: z + d },
  278. { x: x + w, y: y, z: z + d },
  279. { x: x, y: y, z: z + d }
  280. ];
  281. // apply perspective
  282. pArr = perspective(pArr, chart, shapeArgs.insidePlotArea);
  283. // helper method to decide which side is visible
  284. function mapPath(i) {
  285. return pArr[i];
  286. }
  287. var pickShape = function (path1, path2) {
  288. var ret = [];
  289. path1 = map(path1, mapPath);
  290. path2 = map(path2, mapPath);
  291. if (shapeArea(path1) < 0) {
  292. ret = path1;
  293. } else if (shapeArea(path2) < 0) {
  294. ret = path2;
  295. }
  296. return ret;
  297. };
  298. // front or back
  299. var front = [3, 2, 1, 0];
  300. var back = [7, 6, 5, 4];
  301. var path1 = pickShape(front, back);
  302. // top or bottom
  303. var top = [1, 6, 7, 0];
  304. var bottom = [4, 5, 2, 3];
  305. var path2 = pickShape(top, bottom);
  306. // side
  307. var right = [1, 2, 5, 6];
  308. var left = [0, 7, 4, 3];
  309. var path3 = pickShape(right, left);
  310. return [this.toLinePath(path1, true), this.toLinePath(path2, true), this.toLinePath(path3, true), averageZ(path1), averageZ(path2), averageZ(path3), averageZ(map(bottom, mapPath)) * 9e9]; // #4774
  311. };
  312. ////// SECTORS //////
  313. Highcharts.SVGRenderer.prototype.arc3d = function (attribs) {
  314. var wrapper = this.g(),
  315. renderer = wrapper.renderer,
  316. customAttribs = ['x', 'y', 'r', 'innerR', 'start', 'end'];
  317. /**
  318. * Get custom attributes. Mutate the original object and return an object with only custom attr.
  319. */
  320. function suckOutCustom(params) {
  321. var hasCA = false,
  322. ca = {};
  323. for (var key in params) {
  324. if (inArray(key, customAttribs) !== -1) {
  325. ca[key] = params[key];
  326. delete params[key];
  327. hasCA = true;
  328. }
  329. }
  330. return hasCA ? ca : false;
  331. }
  332. attribs = merge(attribs);
  333. attribs.alpha *= deg2rad;
  334. attribs.beta *= deg2rad;
  335. // Create the different sub sections of the shape
  336. wrapper.top = renderer.path();
  337. wrapper.side1 = renderer.path();
  338. wrapper.side2 = renderer.path();
  339. wrapper.inn = renderer.path();
  340. wrapper.out = renderer.path();
  341. /**
  342. * Add all faces
  343. */
  344. wrapper.onAdd = function () {
  345. var parent = wrapper.parentGroup;
  346. wrapper.top.add(wrapper);
  347. wrapper.out.add(parent);
  348. wrapper.inn.add(parent);
  349. wrapper.side1.add(parent);
  350. wrapper.side2.add(parent);
  351. };
  352. /**
  353. * Compute the transformed paths and set them to the composite shapes
  354. */
  355. wrapper.setPaths = function (attribs) {
  356. var paths = wrapper.renderer.arc3dPath(attribs),
  357. zIndex = paths.zTop * 100;
  358. wrapper.attribs = attribs;
  359. wrapper.top.attr({ d: paths.top, zIndex: paths.zTop });
  360. wrapper.inn.attr({ d: paths.inn, zIndex: paths.zInn });
  361. wrapper.out.attr({ d: paths.out, zIndex: paths.zOut });
  362. wrapper.side1.attr({ d: paths.side1, zIndex: paths.zSide1 });
  363. wrapper.side2.attr({ d: paths.side2, zIndex: paths.zSide2 });
  364. // show all children
  365. wrapper.zIndex = zIndex;
  366. wrapper.attr({ zIndex: zIndex });
  367. // Set the radial gradient center the first time
  368. if (attribs.center) {
  369. wrapper.top.setRadialReference(attribs.center);
  370. delete attribs.center;
  371. }
  372. };
  373. wrapper.setPaths(attribs);
  374. // Apply the fill to the top and a darker shade to the sides
  375. wrapper.fillSetter = function (value) {
  376. var darker = Highcharts.Color(value).brighten(-0.1).get();
  377. this.fill = value;
  378. this.side1.attr({ fill: darker });
  379. this.side2.attr({ fill: darker });
  380. this.inn.attr({ fill: darker });
  381. this.out.attr({ fill: darker });
  382. this.top.attr({ fill: value });
  383. return this;
  384. };
  385. // Apply the same value to all. These properties cascade down to the children
  386. // when set to the composite arc3d.
  387. each(['opacity', 'translateX', 'translateY', 'visibility'], function (setter) {
  388. wrapper[setter + 'Setter'] = function (value, key) {
  389. wrapper[key] = value;
  390. each(['out', 'inn', 'side1', 'side2', 'top'], function (el) {
  391. wrapper[el].attr(key, value);
  392. });
  393. };
  394. });
  395. /**
  396. * Override attr to remove shape attributes and use those to set child paths
  397. */
  398. wrap(wrapper, 'attr', function (proceed, params, val) {
  399. var ca;
  400. if (typeof params === 'object') {
  401. ca = suckOutCustom(params);
  402. if (ca) {
  403. extend(wrapper.attribs, ca);
  404. wrapper.setPaths(wrapper.attribs);
  405. }
  406. }
  407. return proceed.call(this, params, val);
  408. });
  409. /**
  410. * Override the animate function by sucking out custom parameters related to the shapes directly,
  411. * and update the shapes from the animation step.
  412. */
  413. wrap(wrapper, 'animate', function (proceed, params, animation, complete) {
  414. var ca,
  415. from = this.attribs,
  416. to;
  417. // Attribute-line properties connected to 3D. These shouldn't have been in the
  418. // attribs collection in the first place.
  419. delete params.center;
  420. delete params.z;
  421. delete params.depth;
  422. delete params.alpha;
  423. delete params.beta;
  424. animation = animObject(pick(animation, this.renderer.globalAnimation));
  425. if (animation.duration) {
  426. params = merge(params); // Don't mutate the original object
  427. ca = suckOutCustom(params);
  428. if (ca) {
  429. to = ca;
  430. animation.step = function (a, fx) {
  431. function interpolate(key) {
  432. return from[key] + (pick(to[key], from[key]) - from[key]) * fx.pos;
  433. }
  434. fx.elem.setPaths(merge(from, {
  435. x: interpolate('x'),
  436. y: interpolate('y'),
  437. r: interpolate('r'),
  438. innerR: interpolate('innerR'),
  439. start: interpolate('start'),
  440. end: interpolate('end')
  441. }));
  442. };
  443. }
  444. }
  445. return proceed.call(this, params, animation, complete);
  446. });
  447. // destroy all children
  448. wrapper.destroy = function () {
  449. this.top.destroy();
  450. this.out.destroy();
  451. this.inn.destroy();
  452. this.side1.destroy();
  453. this.side2.destroy();
  454. Highcharts.SVGElement.prototype.destroy.call(this);
  455. };
  456. // hide all children
  457. wrapper.hide = function () {
  458. this.top.hide();
  459. this.out.hide();
  460. this.inn.hide();
  461. this.side1.hide();
  462. this.side2.hide();
  463. };
  464. wrapper.show = function () {
  465. this.top.show();
  466. this.out.show();
  467. this.inn.show();
  468. this.side1.show();
  469. this.side2.show();
  470. };
  471. return wrapper;
  472. };
  473. /**
  474. * Generate the paths required to draw a 3D arc
  475. */
  476. Highcharts.SVGRenderer.prototype.arc3dPath = function (shapeArgs) {
  477. var cx = shapeArgs.x, // x coordinate of the center
  478. cy = shapeArgs.y, // y coordinate of the center
  479. start = shapeArgs.start, // start angle
  480. end = shapeArgs.end - 0.00001, // end angle
  481. r = shapeArgs.r, // radius
  482. ir = shapeArgs.innerR, // inner radius
  483. d = shapeArgs.depth, // depth
  484. alpha = shapeArgs.alpha, // alpha rotation of the chart
  485. beta = shapeArgs.beta; // beta rotation of the chart
  486. // Derived Variables
  487. var cs = cos(start), // cosinus of the start angle
  488. ss = sin(start), // sinus of the start angle
  489. ce = cos(end), // cosinus of the end angle
  490. se = sin(end), // sinus of the end angle
  491. rx = r * cos(beta), // x-radius
  492. ry = r * cos(alpha), // y-radius
  493. irx = ir * cos(beta), // x-radius (inner)
  494. iry = ir * cos(alpha), // y-radius (inner)
  495. dx = d * sin(beta), // distance between top and bottom in x
  496. dy = d * sin(alpha); // distance between top and bottom in y
  497. // TOP
  498. var top = ['M', cx + (rx * cs), cy + (ry * ss)];
  499. top = top.concat(curveTo(cx, cy, rx, ry, start, end, 0, 0));
  500. top = top.concat([
  501. 'L', cx + (irx * ce), cy + (iry * se)
  502. ]);
  503. top = top.concat(curveTo(cx, cy, irx, iry, end, start, 0, 0));
  504. top = top.concat(['Z']);
  505. // OUTSIDE
  506. var b = (beta > 0 ? PI / 2 : 0),
  507. a = (alpha > 0 ? 0 : PI / 2);
  508. var start2 = start > -b ? start : (end > -b ? -b : start),
  509. end2 = end < PI - a ? end : (start < PI - a ? PI - a : end),
  510. midEnd = 2 * PI - a;
  511. // When slice goes over bottom middle, need to add both, left and right outer side.
  512. // Additionally, when we cross right hand edge, create sharp edge. Outer shape/wall:
  513. //
  514. // -------
  515. // / ^ \
  516. // 4) / / \ \ 1)
  517. // / / \ \
  518. // / / \ \
  519. // (c)=> ==== ==== <=(d)
  520. // \ \ / /
  521. // \ \<=(a)/ /
  522. // \ \ / / <=(b)
  523. // 3) \ v / 2)
  524. // -------
  525. //
  526. // (a) - inner side
  527. // (b) - outer side
  528. // (c) - left edge (sharp)
  529. // (d) - right edge (sharp)
  530. // 1..n - rendering order for startAngle = 0, when set to e.g 90, order changes clockwise (1->2, 2->3, n->1) and counterclockwise for negative startAngle
  531. var out = ['M', cx + (rx * cos(start2)), cy + (ry * sin(start2))];
  532. out = out.concat(curveTo(cx, cy, rx, ry, start2, end2, 0, 0));
  533. if (end > midEnd && start < midEnd) { // When shape is wide, it can cross both, (c) and (d) edges, when using startAngle
  534. // Go to outer side
  535. out = out.concat([
  536. 'L', cx + (rx * cos(end2)) + dx, cy + (ry * sin(end2)) + dy
  537. ]);
  538. // Curve to the right edge of the slice (d)
  539. out = out.concat(curveTo(cx, cy, rx, ry, end2, midEnd, dx, dy));
  540. // Go to the inner side
  541. out = out.concat([
  542. 'L', cx + (rx * cos(midEnd)), cy + (ry * sin(midEnd))
  543. ]);
  544. // Curve to the true end of the slice
  545. out = out.concat(curveTo(cx, cy, rx, ry, midEnd, end, 0, 0));
  546. // Go to the outer side
  547. out = out.concat([
  548. 'L', cx + (rx * cos(end)) + dx, cy + (ry * sin(end)) + dy
  549. ]);
  550. // Go back to middle (d)
  551. out = out.concat(curveTo(cx, cy, rx, ry, end, midEnd, dx, dy));
  552. out = out.concat([
  553. 'L', cx + (rx * cos(midEnd)), cy + (ry * sin(midEnd))
  554. ]);
  555. // Go back to the left edge
  556. out = out.concat(curveTo(cx, cy, rx, ry, midEnd, end2, 0, 0));
  557. } else if (end > PI - a && start < PI - a) { // But shape can cross also only (c) edge:
  558. // Go to outer side
  559. out = out.concat([
  560. 'L', cx + (rx * cos(end2)) + dx, cy + (ry * sin(end2)) + dy
  561. ]);
  562. // Curve to the true end of the slice
  563. out = out.concat(curveTo(cx, cy, rx, ry, end2, end, dx, dy));
  564. // Go to the inner side
  565. out = out.concat([
  566. 'L', cx + (rx * cos(end)), cy + (ry * sin(end))
  567. ]);
  568. // Go back to the artifical end2
  569. out = out.concat(curveTo(cx, cy, rx, ry, end, end2, 0, 0));
  570. }
  571. out = out.concat([
  572. 'L', cx + (rx * cos(end2)) + dx, cy + (ry * sin(end2)) + dy
  573. ]);
  574. out = out.concat(curveTo(cx, cy, rx, ry, end2, start2, dx, dy));
  575. out = out.concat(['Z']);
  576. // INSIDE
  577. var inn = ['M', cx + (irx * cs), cy + (iry * ss)];
  578. inn = inn.concat(curveTo(cx, cy, irx, iry, start, end, 0, 0));
  579. inn = inn.concat([
  580. 'L', cx + (irx * cos(end)) + dx, cy + (iry * sin(end)) + dy
  581. ]);
  582. inn = inn.concat(curveTo(cx, cy, irx, iry, end, start, dx, dy));
  583. inn = inn.concat(['Z']);
  584. // SIDES
  585. var side1 = [
  586. 'M', cx + (rx * cs), cy + (ry * ss),
  587. 'L', cx + (rx * cs) + dx, cy + (ry * ss) + dy,
  588. 'L', cx + (irx * cs) + dx, cy + (iry * ss) + dy,
  589. 'L', cx + (irx * cs), cy + (iry * ss),
  590. 'Z'
  591. ];
  592. var side2 = [
  593. 'M', cx + (rx * ce), cy + (ry * se),
  594. 'L', cx + (rx * ce) + dx, cy + (ry * se) + dy,
  595. 'L', cx + (irx * ce) + dx, cy + (iry * se) + dy,
  596. 'L', cx + (irx * ce), cy + (iry * se),
  597. 'Z'
  598. ];
  599. // correction for changed position of vanishing point caused by alpha and beta rotations
  600. var angleCorr = Math.atan2(dy, -dx),
  601. angleEnd = Math.abs(end + angleCorr),
  602. angleStart = Math.abs(start + angleCorr),
  603. angleMid = Math.abs((start + end) / 2 + angleCorr);
  604. // set to 0-PI range
  605. function toZeroPIRange(angle) {
  606. angle = angle % (2 * PI);
  607. if (angle > PI) {
  608. angle = 2 * PI - angle;
  609. }
  610. return angle;
  611. }
  612. angleEnd = toZeroPIRange(angleEnd);
  613. angleStart = toZeroPIRange(angleStart);
  614. angleMid = toZeroPIRange(angleMid);
  615. // *1e5 is to compensate pInt in zIndexSetter
  616. var incPrecision = 1e5,
  617. a1 = angleMid * incPrecision,
  618. a2 = angleStart * incPrecision,
  619. a3 = angleEnd * incPrecision;
  620. return {
  621. top: top,
  622. zTop: PI * incPrecision + 1, // max angle is PI, so this is allways higher
  623. out: out,
  624. zOut: Math.max(a1, a2, a3),
  625. inn: inn,
  626. zInn: Math.max(a1, a2, a3),
  627. side1: side1,
  628. zSide1: a3 * 0.99, // to keep below zOut and zInn in case of same values
  629. side2: side2,
  630. zSide2: a2 * 0.99
  631. };
  632. };
  633. /***
  634. EXTENSION FOR 3D CHARTS
  635. ***/
  636. // Shorthand to check the is3d flag
  637. Highcharts.Chart.prototype.is3d = function () {
  638. return this.options.chart.options3d && this.options.chart.options3d.enabled; // #4280
  639. };
  640. /**
  641. * Extend the getMargins method to calculate scale of the 3D view. That is required to
  642. * fit chart's 3D projection into the actual plotting area. Reported as #4933.
  643. */
  644. Highcharts.wrap(Highcharts.Chart.prototype, 'getMargins', function (proceed) {
  645. var chart = this,
  646. options3d = chart.options.chart.options3d,
  647. bbox3d = {
  648. minX: Number.MAX_VALUE,
  649. maxX: -Number.MAX_VALUE,
  650. minY: Number.MAX_VALUE,
  651. maxY: -Number.MAX_VALUE
  652. },
  653. plotLeft = chart.plotLeft,
  654. plotRight = chart.plotWidth + plotLeft,
  655. plotTop = chart.plotTop,
  656. plotBottom = chart.plotHeight + plotTop,
  657. originX = plotLeft + chart.plotWidth / 2,
  658. originY = plotTop + chart.plotHeight / 2,
  659. scale = 1,
  660. corners = [],
  661. i;
  662. proceed.apply(this, [].slice.call(arguments, 1));
  663. if (this.is3d()) {
  664. if (options3d.fitToPlot === true) {
  665. // Clear previous scale in case of updates:
  666. chart.scale3d = 1;
  667. // Top left corners:
  668. corners = [{
  669. x: plotLeft,
  670. y: plotTop,
  671. z: 0
  672. }, {
  673. x: plotLeft,
  674. y: plotTop,
  675. z: options3d.depth
  676. }];
  677. // Top right corners:
  678. for (i = 0; i < 2; i++) {
  679. corners.push({
  680. x: plotRight,
  681. y: corners[i].y,
  682. z: corners[i].z
  683. });
  684. }
  685. // All bottom corners:
  686. for (i = 0; i < 4; i++) {
  687. corners.push({
  688. x: corners[i].x,
  689. y: plotBottom,
  690. z: corners[i].z
  691. });
  692. }
  693. // Calculate 3D corners:
  694. corners = perspective(corners, chart, false);
  695. // Get bounding box of 3D element:
  696. each(corners, function (corner) {
  697. bbox3d.minX = Math.min(bbox3d.minX, corner.x);
  698. bbox3d.maxX = Math.max(bbox3d.maxX, corner.x);
  699. bbox3d.minY = Math.min(bbox3d.minY, corner.y);
  700. bbox3d.maxY = Math.max(bbox3d.maxY, corner.y);
  701. });
  702. // Left edge:
  703. if (plotLeft > bbox3d.minX) {
  704. scale = Math.min(scale, 1 - Math.abs((plotLeft + originX) / (bbox3d.minX + originX)) % 1);
  705. }
  706. // Right edge:
  707. if (plotRight < bbox3d.maxX) {
  708. scale = Math.min(scale, (plotRight - originX) / (bbox3d.maxX - originX));
  709. }
  710. // Top edge:
  711. if (plotTop > bbox3d.minY) {
  712. if (bbox3d.minY < 0) {
  713. scale = Math.min(scale, (plotTop + originY) / (-bbox3d.minY + plotTop + originY));
  714. } else {
  715. scale = Math.min(scale, 1 - (plotTop + originY) / (bbox3d.minY + originY) % 1);
  716. }
  717. }
  718. // Bottom edge:
  719. if (plotBottom < bbox3d.maxY) {
  720. scale = Math.min(scale, Math.abs((plotBottom - originY) / (bbox3d.maxY - originY)));
  721. }
  722. // Set scale, used later in perspective method():
  723. chart.scale3d = scale;
  724. }
  725. }
  726. });
  727. Highcharts.wrap(Highcharts.Chart.prototype, 'isInsidePlot', function (proceed) {
  728. return this.is3d() || proceed.apply(this, [].slice.call(arguments, 1));
  729. });
  730. var defaultChartOptions = Highcharts.getOptions();
  731. defaultChartOptions.chart.options3d = {
  732. enabled: false,
  733. alpha: 0,
  734. beta: 0,
  735. depth: 100,
  736. fitToPlot: true,
  737. viewDistance: 25,
  738. frame: {
  739. bottom: { size: 1, color: 'rgba(255,255,255,0)' },
  740. side: { size: 1, color: 'rgba(255,255,255,0)' },
  741. back: { size: 1, color: 'rgba(255,255,255,0)' }
  742. }
  743. };
  744. Highcharts.wrap(Highcharts.Chart.prototype, 'init', function (proceed) {
  745. var args = [].slice.call(arguments, 1),
  746. plotOptions,
  747. pieOptions;
  748. if (args[0].chart && args[0].chart.options3d && args[0].chart.options3d.enabled) {
  749. // Normalize alpha and beta to (-360, 360) range
  750. args[0].chart.options3d.alpha = (args[0].chart.options3d.alpha || 0) % 360;
  751. args[0].chart.options3d.beta = (args[0].chart.options3d.beta || 0) % 360;
  752. plotOptions = args[0].plotOptions || {};
  753. pieOptions = plotOptions.pie || {};
  754. pieOptions.borderColor = Highcharts.pick(pieOptions.borderColor, undefined);
  755. }
  756. proceed.apply(this, args);
  757. });
  758. Highcharts.wrap(Highcharts.Chart.prototype, 'setChartSize', function (proceed) {
  759. proceed.apply(this, [].slice.call(arguments, 1));
  760. if (this.is3d()) {
  761. var inverted = this.inverted,
  762. clipBox = this.clipBox,
  763. margin = this.margin,
  764. x = inverted ? 'y' : 'x',
  765. y = inverted ? 'x' : 'y',
  766. w = inverted ? 'height' : 'width',
  767. h = inverted ? 'width' : 'height';
  768. clipBox[x] = -(margin[3] || 0);
  769. clipBox[y] = -(margin[0] || 0);
  770. clipBox[w] = this.chartWidth + (margin[3] || 0) + (margin[1] || 0);
  771. clipBox[h] = this.chartHeight + (margin[0] || 0) + (margin[2] || 0);
  772. }
  773. });
  774. Highcharts.wrap(Highcharts.Chart.prototype, 'redraw', function (proceed) {
  775. if (this.is3d()) {
  776. // Set to force a redraw of all elements
  777. this.isDirtyBox = true;
  778. }
  779. proceed.apply(this, [].slice.call(arguments, 1));
  780. });
  781. // Draw the series in the reverse order (#3803, #3917)
  782. Highcharts.wrap(Highcharts.Chart.prototype, 'renderSeries', function (proceed) {
  783. var series,
  784. i = this.series.length;
  785. if (this.is3d()) {
  786. while (i--) {
  787. series = this.series[i];
  788. series.translate();
  789. series.render();
  790. }
  791. } else {
  792. proceed.call(this);
  793. }
  794. });
  795. Highcharts.Chart.prototype.retrieveStacks = function (stacking) {
  796. var series = this.series,
  797. stacks = {},
  798. stackNumber,
  799. i = 1;
  800. Highcharts.each(this.series, function (s) {
  801. stackNumber = pick(s.options.stack, (stacking ? 0 : series.length - 1 - s.index)); // #3841, #4532
  802. if (!stacks[stackNumber]) {
  803. stacks[stackNumber] = { series: [s], position: i };
  804. i++;
  805. } else {
  806. stacks[stackNumber].series.push(s);
  807. }
  808. });
  809. stacks.totalStacks = i + 1;
  810. return stacks;
  811. };
  812. /***
  813. EXTENSION TO THE AXIS
  814. ***/
  815. Highcharts.wrap(Highcharts.Axis.prototype, 'setOptions', function (proceed, userOptions) {
  816. var options;
  817. proceed.call(this, userOptions);
  818. if (this.chart.is3d()) {
  819. options = this.options;
  820. options.tickWidth = Highcharts.pick(options.tickWidth, 0);
  821. options.gridLineWidth = Highcharts.pick(options.gridLineWidth, 1);
  822. }
  823. });
  824. Highcharts.wrap(Highcharts.Axis.prototype, 'render', function (proceed) {
  825. proceed.apply(this, [].slice.call(arguments, 1));
  826. // Do not do this if the chart is not 3D
  827. if (!this.chart.is3d()) {
  828. return;
  829. }
  830. var chart = this.chart,
  831. renderer = chart.renderer,
  832. options3d = chart.options.chart.options3d,
  833. frame = options3d.frame,
  834. fbottom = frame.bottom,
  835. fback = frame.back,
  836. fside = frame.side,
  837. depth = options3d.depth,
  838. height = this.height,
  839. width = this.width,
  840. left = this.left,
  841. top = this.top;
  842. if (this.isZAxis) {
  843. return;
  844. }
  845. if (this.horiz) {
  846. var bottomShape = {
  847. x: left,
  848. y: top + (chart.xAxis[0].opposite ? -fbottom.size : height),
  849. z: 0,
  850. width: width,
  851. height: fbottom.size,
  852. depth: depth,
  853. insidePlotArea: false
  854. };
  855. if (!this.bottomFrame) {
  856. this.bottomFrame = renderer.cuboid(bottomShape).attr({
  857. fill: fbottom.color,
  858. zIndex: (chart.yAxis[0].reversed && options3d.alpha > 0 ? 4 : -1)
  859. })
  860. .css({
  861. stroke: fbottom.color
  862. }).add();
  863. } else {
  864. this.bottomFrame.animate(bottomShape);
  865. }
  866. } else {
  867. // BACK
  868. var backShape = {
  869. x: left + (chart.yAxis[0].opposite ? 0 : -fside.size),
  870. y: top + (chart.xAxis[0].opposite ? -fbottom.size : 0),
  871. z: depth,
  872. width: width + fside.size,
  873. height: height + fbottom.size,
  874. depth: fback.size,
  875. insidePlotArea: false
  876. };
  877. if (!this.backFrame) {
  878. this.backFrame = renderer.cuboid(backShape).attr({
  879. fill: fback.color,
  880. zIndex: -3
  881. }).css({
  882. stroke: fback.color
  883. }).add();
  884. } else {
  885. this.backFrame.animate(backShape);
  886. }
  887. var sideShape = {
  888. x: left + (chart.yAxis[0].opposite ? width : -fside.size),
  889. y: top + (chart.xAxis[0].opposite ? -fbottom.size : 0),
  890. z: 0,
  891. width: fside.size,
  892. height: height + fbottom.size,
  893. depth: depth,
  894. insidePlotArea: false
  895. };
  896. if (!this.sideFrame) {
  897. this.sideFrame = renderer.cuboid(sideShape).attr({
  898. fill: fside.color,
  899. zIndex: -2
  900. }).css({
  901. stroke: fside.color
  902. }).add();
  903. } else {
  904. this.sideFrame.animate(sideShape);
  905. }
  906. }
  907. });
  908. Highcharts.wrap(Highcharts.Axis.prototype, 'getPlotLinePath', function (proceed) {
  909. var path = proceed.apply(this, [].slice.call(arguments, 1));
  910. // Do not do this if the chart is not 3D
  911. if (!this.chart.is3d()) {
  912. return path;
  913. }
  914. if (path === null) {
  915. return path;
  916. }
  917. var chart = this.chart,
  918. options3d = chart.options.chart.options3d,
  919. d = this.isZAxis ? chart.plotWidth : options3d.depth,
  920. opposite = this.opposite;
  921. if (this.horiz) {
  922. opposite = !opposite;
  923. }
  924. var pArr = [
  925. this.swapZ({ x: path[1], y: path[2], z: (opposite ? d : 0) }),
  926. this.swapZ({ x: path[1], y: path[2], z: d }),
  927. this.swapZ({ x: path[4], y: path[5], z: d }),
  928. this.swapZ({ x: path[4], y: path[5], z: (opposite ? 0 : d) })
  929. ];
  930. pArr = perspective(pArr, this.chart, false);
  931. path = this.chart.renderer.toLinePath(pArr, false);
  932. return path;
  933. });
  934. // Do not draw axislines in 3D
  935. Highcharts.wrap(Highcharts.Axis.prototype, 'getLinePath', function (proceed) {
  936. return this.chart.is3d() ? [] : proceed.apply(this, [].slice.call(arguments, 1));
  937. });
  938. Highcharts.wrap(Highcharts.Axis.prototype, 'getPlotBandPath', function (proceed) {
  939. // Do not do this if the chart is not 3D
  940. if (!this.chart.is3d()) {
  941. return proceed.apply(this, [].slice.call(arguments, 1));
  942. }
  943. var args = arguments,
  944. from = args[1],
  945. to = args[2],
  946. toPath = this.getPlotLinePath(to),
  947. path = this.getPlotLinePath(from);
  948. if (path && toPath) {
  949. path.push(
  950. 'L',
  951. toPath[10], // These two do not exist in the regular getPlotLine
  952. toPath[11], // ---- # 3005
  953. 'L',
  954. toPath[7],
  955. toPath[8],
  956. 'L',
  957. toPath[4],
  958. toPath[5],
  959. 'L',
  960. toPath[1],
  961. toPath[2]
  962. );
  963. } else { // outside the axis area
  964. path = null;
  965. }
  966. return path;
  967. });
  968. /***
  969. EXTENSION TO THE TICKS
  970. ***/
  971. Highcharts.wrap(Highcharts.Tick.prototype, 'getMarkPath', function (proceed) {
  972. var path = proceed.apply(this, [].slice.call(arguments, 1));
  973. // Do not do this if the chart is not 3D
  974. if (!this.axis.chart.is3d()) {
  975. return path;
  976. }
  977. var pArr = [
  978. this.axis.swapZ({ x: path[1], y: path[2], z: 0 }),
  979. this.axis.swapZ({ x: path[4], y: path[5], z: 0 })
  980. ];
  981. pArr = perspective(pArr, this.axis.chart, false);
  982. path = [
  983. 'M', pArr[0].x, pArr[0].y,
  984. 'L', pArr[1].x, pArr[1].y
  985. ];
  986. return path;
  987. });
  988. Highcharts.wrap(Highcharts.Tick.prototype, 'getLabelPosition', function (proceed) {
  989. var pos = proceed.apply(this, [].slice.call(arguments, 1));
  990. // Do not do this if the chart is not 3D
  991. if (!this.axis.chart.is3d()) {
  992. return pos;
  993. }
  994. var newPos = perspective([this.axis.swapZ({ x: pos.x, y: pos.y, z: 0 })], this.axis.chart, false)[0];
  995. newPos.x = newPos.x - (!this.axis.horiz && this.axis.opposite ? this.axis.transA : 0); //#3788
  996. newPos.old = pos;
  997. return newPos;
  998. });
  999. Highcharts.wrap(Highcharts.Tick.prototype, 'handleOverflow', function (proceed, xy) {
  1000. if (this.axis.chart.is3d()) {
  1001. xy = xy.old;
  1002. }
  1003. return proceed.call(this, xy);
  1004. });
  1005. Highcharts.wrap(Highcharts.Axis.prototype, 'getTitlePosition', function (proceed) {
  1006. var is3d = this.chart.is3d(),
  1007. pos,
  1008. axisTitleMargin;
  1009. // Pull out the axis title margin, that is not subject to the perspective
  1010. if (is3d) {
  1011. axisTitleMargin = this.axisTitleMargin;
  1012. this.axisTitleMargin = 0;
  1013. }
  1014. pos = proceed.apply(this, [].slice.call(arguments, 1));
  1015. if (is3d) {
  1016. pos = perspective([this.swapZ({ x: pos.x, y: pos.y, z: 0 })], this.chart, false)[0];
  1017. // Re-apply the axis title margin outside the perspective
  1018. pos[this.horiz ? 'y' : 'x'] += (this.horiz ? 1 : -1) * // horizontal axis reverses the margin ...
  1019. (this.opposite ? -1 : 1) * // ... so does opposite axes
  1020. axisTitleMargin;
  1021. this.axisTitleMargin = axisTitleMargin;
  1022. }
  1023. return pos;
  1024. });
  1025. Highcharts.wrap(Highcharts.Axis.prototype, 'drawCrosshair', function (proceed) {
  1026. var args = arguments;
  1027. if (this.chart.is3d()) {
  1028. if (args[2]) {
  1029. args[2] = {
  1030. plotX: args[2].plotXold || args[2].plotX,
  1031. plotY: args[2].plotYold || args[2].plotY
  1032. };
  1033. }
  1034. }
  1035. proceed.apply(this, [].slice.call(args, 1));
  1036. });
  1037. /***
  1038. Z-AXIS
  1039. ***/
  1040. Highcharts.Axis.prototype.swapZ = function (p, insidePlotArea) {
  1041. if (this.isZAxis) {
  1042. var plotLeft = insidePlotArea ? 0 : this.chart.plotLeft;
  1043. var chart = this.chart;
  1044. return {
  1045. x: plotLeft + (chart.yAxis[0].opposite ? p.z : chart.xAxis[0].width - p.z),
  1046. y: p.y,
  1047. z: p.x - plotLeft
  1048. };
  1049. }
  1050. return p;
  1051. };
  1052. var ZAxis = Highcharts.ZAxis = function () {
  1053. this.isZAxis = true;
  1054. this.init.apply(this, arguments);
  1055. };
  1056. Highcharts.extend(ZAxis.prototype, Highcharts.Axis.prototype);
  1057. Highcharts.extend(ZAxis.prototype, {
  1058. setOptions: function (userOptions) {
  1059. userOptions = Highcharts.merge({
  1060. offset: 0,
  1061. lineWidth: 0
  1062. }, userOptions);
  1063. Highcharts.Axis.prototype.setOptions.call(this, userOptions);
  1064. this.coll = 'zAxis';
  1065. },
  1066. setAxisSize: function () {
  1067. Highcharts.Axis.prototype.setAxisSize.call(this);
  1068. this.width = this.len = this.chart.options.chart.options3d.depth;
  1069. this.right = this.chart.chartWidth - this.width - this.left;
  1070. },
  1071. getSeriesExtremes: function () {
  1072. var axis = this,
  1073. chart = axis.chart;
  1074. axis.hasVisibleSeries = false;
  1075. // Reset properties in case we're redrawing (#3353)
  1076. axis.dataMin = axis.dataMax = axis.ignoreMinPadding = axis.ignoreMaxPadding = null;
  1077. if (axis.buildStacks) {
  1078. axis.buildStacks();
  1079. }
  1080. // loop through this axis' series
  1081. Highcharts.each(axis.series, function (series) {
  1082. if (series.visible || !chart.options.chart.ignoreHiddenSeries) {
  1083. var seriesOptions = series.options,
  1084. zData,
  1085. threshold = seriesOptions.threshold;
  1086. axis.hasVisibleSeries = true;
  1087. // Validate threshold in logarithmic axes
  1088. if (axis.isLog && threshold <= 0) {
  1089. threshold = null;
  1090. }
  1091. zData = series.zData;
  1092. if (zData.length) {
  1093. axis.dataMin = Math.min(pick(axis.dataMin, zData[0]), Math.min.apply(null, zData));
  1094. axis.dataMax = Math.max(pick(axis.dataMax, zData[0]), Math.max.apply(null, zData));
  1095. }
  1096. }
  1097. });
  1098. }
  1099. });
  1100. /**
  1101. * Extend the chart getAxes method to also get the color axis
  1102. */
  1103. Highcharts.wrap(Highcharts.Chart.prototype, 'getAxes', function (proceed) {
  1104. var chart = this,
  1105. options = this.options,
  1106. zAxisOptions = options.zAxis = Highcharts.splat(options.zAxis || {});
  1107. proceed.call(this);
  1108. if (!chart.is3d()) {
  1109. return;
  1110. }
  1111. this.zAxis = [];
  1112. Highcharts.each(zAxisOptions, function (axisOptions, i) {
  1113. axisOptions.index = i;
  1114. axisOptions.isX = true; //Z-Axis is shown horizontally, so it's kind of a X-Axis
  1115. var zAxis = new ZAxis(chart, axisOptions);
  1116. zAxis.setScale();
  1117. });
  1118. });
  1119. /***
  1120. EXTENSION FOR 3D COLUMNS
  1121. ***/
  1122. Highcharts.wrap(Highcharts.seriesTypes.column.prototype, 'translate', function (proceed) {
  1123. proceed.apply(this, [].slice.call(arguments, 1));
  1124. // Do not do this if the chart is not 3D
  1125. if (!this.chart.is3d()) {
  1126. return;
  1127. }
  1128. var series = this,
  1129. chart = series.chart,
  1130. seriesOptions = series.options,
  1131. depth = seriesOptions.depth || 25;
  1132. var stack = seriesOptions.stacking ? (seriesOptions.stack || 0) : series._i;
  1133. var z = stack * (depth + (seriesOptions.groupZPadding || 1));
  1134. if (seriesOptions.grouping !== false) {
  1135. z = 0;
  1136. }
  1137. z += (seriesOptions.groupZPadding || 1);
  1138. Highcharts.each(series.data, function (point) {
  1139. if (point.y !== null) {
  1140. var shapeArgs = point.shapeArgs,
  1141. tooltipPos = point.tooltipPos;
  1142. point.shapeType = 'cuboid';
  1143. shapeArgs.z = z;
  1144. shapeArgs.depth = depth;
  1145. shapeArgs.insidePlotArea = true;
  1146. // Translate the tooltip position in 3d space
  1147. tooltipPos = perspective([{ x: tooltipPos[0], y: tooltipPos[1], z: z }], chart, true)[0];
  1148. point.tooltipPos = [tooltipPos.x, tooltipPos.y];
  1149. }
  1150. });
  1151. // store for later use #4067
  1152. series.z = z;
  1153. });
  1154. Highcharts.wrap(Highcharts.seriesTypes.column.prototype, 'animate', function (proceed) {
  1155. if (!this.chart.is3d()) {
  1156. proceed.apply(this, [].slice.call(arguments, 1));
  1157. } else {
  1158. var args = arguments,
  1159. init = args[1],
  1160. yAxis = this.yAxis,
  1161. series = this,
  1162. reversed = this.yAxis.reversed;
  1163. if (Highcharts.svg) { // VML is too slow anyway
  1164. if (init) {
  1165. Highcharts.each(series.data, function (point) {
  1166. if (point.y !== null) {
  1167. point.height = point.shapeArgs.height;
  1168. point.shapey = point.shapeArgs.y; //#2968
  1169. point.shapeArgs.height = 1;
  1170. if (!reversed) {
  1171. if (point.stackY) {
  1172. point.shapeArgs.y = point.plotY + yAxis.translate(point.stackY);
  1173. } else {
  1174. point.shapeArgs.y = point.plotY + (point.negative ? -point.height : point.height);
  1175. }
  1176. }
  1177. }
  1178. });
  1179. } else { // run the animation
  1180. Highcharts.each(series.data, function (point) {
  1181. if (point.y !== null) {
  1182. point.shapeArgs.height = point.height;
  1183. point.shapeArgs.y = point.shapey; //#2968
  1184. // null value do not have a graphic
  1185. if (point.graphic) {
  1186. point.graphic.animate(point.shapeArgs, series.options.animation);
  1187. }
  1188. }
  1189. });
  1190. // redraw datalabels to the correct position
  1191. this.drawDataLabels();
  1192. // delete this function to allow it only once
  1193. series.animate = null;
  1194. }
  1195. }
  1196. }
  1197. });
  1198. Highcharts.wrap(Highcharts.seriesTypes.column.prototype, 'init', function (proceed) {
  1199. proceed.apply(this, [].slice.call(arguments, 1));
  1200. if (this.chart.is3d()) {
  1201. var seriesOptions = this.options,
  1202. grouping = seriesOptions.grouping,
  1203. stacking = seriesOptions.stacking,
  1204. reversedStacks = pick(this.yAxis.options.reversedStacks, true),
  1205. z = 0;
  1206. if (!(grouping !== undefined && !grouping)) {
  1207. var stacks = this.chart.retrieveStacks(stacking),
  1208. stack = seriesOptions.stack || 0,
  1209. i; // position within the stack
  1210. for (i = 0; i < stacks[stack].series.length; i++) {
  1211. if (stacks[stack].series[i] === this) {
  1212. break;
  1213. }
  1214. }
  1215. z = (10 * (stacks.totalStacks - stacks[stack].position)) + (reversedStacks ? i : -i); // #4369
  1216. // In case when axis is reversed, columns are also reversed inside the group (#3737)
  1217. if (!this.xAxis.reversed) {
  1218. z = (stacks.totalStacks * 10) - z;
  1219. }
  1220. }
  1221. seriesOptions.zIndex = z;
  1222. }
  1223. });
  1224. function draw3DPoints(proceed) {
  1225. // Do not do this if the chart is not 3D
  1226. if (this.chart.is3d()) {
  1227. var grouping = this.chart.options.plotOptions.column.grouping;
  1228. if (grouping !== undefined && !grouping && this.group.zIndex !== undefined && !this.zIndexSet) {
  1229. this.group.attr({ zIndex: this.group.zIndex * 10 });
  1230. this.zIndexSet = true; // #4062 set zindex only once
  1231. }
  1232. var options = this.options,
  1233. states = this.options.states;
  1234. this.borderWidth = options.borderWidth = defined(options.edgeWidth) ? options.edgeWidth : 1; //#4055
  1235. Highcharts.each(this.data, function (point) {
  1236. if (point.y !== null) {
  1237. var pointAttr = point.pointAttr;
  1238. // Set the border color to the fill color to provide a smooth edge
  1239. this.borderColor = Highcharts.pick(options.edgeColor, pointAttr[''].fill);
  1240. pointAttr[''].stroke = this.borderColor;
  1241. pointAttr.hover.stroke = Highcharts.pick(states.hover.edgeColor, this.borderColor);
  1242. pointAttr.select.stroke = Highcharts.pick(states.select.edgeColor, this.borderColor);
  1243. }
  1244. });
  1245. }
  1246. proceed.apply(this, [].slice.call(arguments, 1));
  1247. }
  1248. Highcharts.wrap(Highcharts.Series.prototype, 'alignDataLabel', function (proceed) {
  1249. // Only do this for 3D columns and columnranges
  1250. if (this.chart.is3d() && (this.type === 'column' || this.type === 'columnrange')) {
  1251. var series = this,
  1252. chart = series.chart;
  1253. var args = arguments,
  1254. alignTo = args[4];
  1255. var pos = ({ x: alignTo.x, y: alignTo.y, z: series.z });
  1256. pos = perspective([pos], chart, true)[0];
  1257. alignTo.x = pos.x;
  1258. alignTo.y = pos.y;
  1259. }
  1260. proceed.apply(this, [].slice.call(arguments, 1));
  1261. });
  1262. if (Highcharts.seriesTypes.columnrange) {
  1263. Highcharts.wrap(Highcharts.seriesTypes.columnrange.prototype, 'drawPoints', draw3DPoints);
  1264. }
  1265. Highcharts.wrap(Highcharts.seriesTypes.column.prototype, 'drawPoints', draw3DPoints);
  1266. /***
  1267. EXTENSION FOR 3D CYLINDRICAL COLUMNS
  1268. Not supported
  1269. ***/
  1270. /*
  1271. var defaultOptions = Highcharts.getOptions();
  1272. defaultOptions.plotOptions.cylinder = Highcharts.merge(defaultOptions.plotOptions.column);
  1273. var CylinderSeries = Highcharts.extendClass(Highcharts.seriesTypes.column, {
  1274. type: 'cylinder'
  1275. });
  1276. Highcharts.seriesTypes.cylinder = CylinderSeries;
  1277. Highcharts.wrap(Highcharts.seriesTypes.cylinder.prototype, 'translate', function (proceed) {
  1278. proceed.apply(this, [].slice.call(arguments, 1));
  1279. // Do not do this if the chart is not 3D
  1280. if (!this.chart.is3d()) {
  1281. return;
  1282. }
  1283. var series = this,
  1284. chart = series.chart,
  1285. options = chart.options,
  1286. cylOptions = options.plotOptions.cylinder,
  1287. options3d = options.chart.options3d,
  1288. depth = cylOptions.depth || 0,
  1289. alpha = options3d.alpha;
  1290. var z = cylOptions.stacking ? (this.options.stack || 0) * depth : series._i * depth;
  1291. z += depth / 2;
  1292. if (cylOptions.grouping !== false) { z = 0; }
  1293. Highcharts.each(series.data, function (point) {
  1294. var shapeArgs = point.shapeArgs;
  1295. point.shapeType = 'arc3d';
  1296. shapeArgs.x += depth / 2;
  1297. shapeArgs.z = z;
  1298. shapeArgs.start = 0;
  1299. shapeArgs.end = 2 * PI;
  1300. shapeArgs.r = depth * 0.95;
  1301. shapeArgs.innerR = 0;
  1302. shapeArgs.depth = shapeArgs.height * (1 / sin((90 - alpha) * deg2rad)) - z;
  1303. shapeArgs.alpha = 90 - alpha;
  1304. shapeArgs.beta = 0;
  1305. });
  1306. });
  1307. */
  1308. /***
  1309. EXTENSION FOR 3D PIES
  1310. ***/
  1311. Highcharts.wrap(Highcharts.seriesTypes.pie.prototype, 'translate', function (proceed) {
  1312. proceed.apply(this, [].slice.call(arguments, 1));
  1313. // Do not do this if the chart is not 3D
  1314. if (!this.chart.is3d()) {
  1315. return;
  1316. }
  1317. var series = this,
  1318. chart = series.chart,
  1319. options = chart.options,
  1320. seriesOptions = series.options,
  1321. depth = seriesOptions.depth || 0,
  1322. options3d = options.chart.options3d,
  1323. alpha = options3d.alpha,
  1324. beta = options3d.beta,
  1325. z = seriesOptions.stacking ? (seriesOptions.stack || 0) * depth : series._i * depth;
  1326. z += depth / 2;
  1327. if (seriesOptions.grouping !== false) {
  1328. z = 0;
  1329. }
  1330. each(series.data, function (point) {
  1331. var shapeArgs = point.shapeArgs,
  1332. angle;
  1333. point.shapeType = 'arc3d';
  1334. shapeArgs.z = z;
  1335. shapeArgs.depth = depth * 0.75;
  1336. shapeArgs.alpha = alpha;
  1337. shapeArgs.beta = beta;
  1338. shapeArgs.center = series.center;
  1339. angle = (shapeArgs.end + shapeArgs.start) / 2;
  1340. point.slicedTranslation = {
  1341. translateX: round(cos(angle) * seriesOptions.slicedOffset * cos(alpha * deg2rad)),
  1342. translateY: round(sin(angle) * seriesOptions.slicedOffset * cos(alpha * deg2rad))
  1343. };
  1344. });
  1345. });
  1346. Highcharts.wrap(Highcharts.seriesTypes.pie.prototype.pointClass.prototype, 'haloPath', function (proceed) {
  1347. var args = arguments;
  1348. return this.series.chart.is3d() ? [] : proceed.call(this, args[1]);
  1349. });
  1350. Highcharts.wrap(Highcharts.seriesTypes.pie.prototype, 'drawPoints', function (proceed) {
  1351. var options = this.options,
  1352. states = options.states;
  1353. // Do not do this if the chart is not 3D
  1354. if (this.chart.is3d()) {
  1355. // Set the border color to the fill color to provide a smooth edge
  1356. this.borderWidth = options.borderWidth = options.edgeWidth || 1;
  1357. this.borderColor = options.edgeColor = Highcharts.pick(options.edgeColor, options.borderColor, undefined);
  1358. states.hover.borderColor = Highcharts.pick(states.hover.edgeColor, this.borderColor);
  1359. states.hover.borderWidth = Highcharts.pick(states.hover.edgeWidth, this.borderWidth);
  1360. states.select.borderColor = Highcharts.pick(states.select.edgeColor, this.borderColor);
  1361. states.select.borderWidth = Highcharts.pick(states.select.edgeWidth, this.borderWidth);
  1362. each(this.data, function (point) {
  1363. var pointAttr = point.pointAttr;
  1364. pointAttr[''].stroke = point.series.borderColor || point.color;
  1365. pointAttr['']['stroke-width'] = point.series.borderWidth;
  1366. pointAttr.hover.stroke = states.hover.borderColor;
  1367. pointAttr.hover['stroke-width'] = states.hover.borderWidth;
  1368. pointAttr.select.stroke = states.select.borderColor;
  1369. pointAttr.select['stroke-width'] = states.select.borderWidth;
  1370. });
  1371. }
  1372. proceed.apply(this, [].slice.call(arguments, 1));
  1373. if (this.chart.is3d()) {
  1374. each(this.points, function (point) {
  1375. var graphic = point.graphic;
  1376. // #4584 Check if has graphic - null points don't have it
  1377. if (graphic) {
  1378. // Hide null or 0 points (#3006, 3650)
  1379. graphic[point.y && point.visible ? 'show' : 'hide']();
  1380. }
  1381. });
  1382. }
  1383. });
  1384. Highcharts.wrap(Highcharts.seriesTypes.pie.prototype, 'drawDataLabels', function (proceed) {
  1385. if (this.chart.is3d()) {
  1386. var series = this,
  1387. chart = series.chart,
  1388. options3d = chart.options.chart.options3d;
  1389. each(series.data, function (point) {
  1390. var shapeArgs = point.shapeArgs,
  1391. r = shapeArgs.r,
  1392. a1 = (shapeArgs.alpha || options3d.alpha) * deg2rad, //#3240 issue with datalabels for 0 and null values
  1393. b1 = (shapeArgs.beta || options3d.beta) * deg2rad,
  1394. a2 = (shapeArgs.start + shapeArgs.end) / 2,
  1395. labelPos = point.labelPos,
  1396. labelIndexes = [0, 2, 4], // [x1, y1, x2, y2, x3, y3]
  1397. yOffset = (-r * (1 - cos(a1)) * sin(a2)), // + (sin(a2) > 0 ? sin(a1) * d : 0)
  1398. xOffset = r * (cos(b1) - 1) * cos(a2);
  1399. // Apply perspective on label positions
  1400. each(labelIndexes, function (index) {
  1401. labelPos[index] += xOffset;
  1402. labelPos[index + 1] += yOffset;
  1403. });
  1404. });
  1405. }
  1406. proceed.apply(this, [].slice.call(arguments, 1));
  1407. });
  1408. Highcharts.wrap(Highcharts.seriesTypes.pie.prototype, 'addPoint', function (proceed) {
  1409. proceed.apply(this, [].slice.call(arguments, 1));
  1410. if (this.chart.is3d()) {
  1411. // destroy (and rebuild) everything!!!
  1412. this.update(this.userOptions, true); // #3845 pass the old options
  1413. }
  1414. });
  1415. Highcharts.wrap(Highcharts.seriesTypes.pie.prototype, 'animate', function (proceed) {
  1416. if (!this.chart.is3d()) {
  1417. proceed.apply(this, [].slice.call(arguments, 1));
  1418. } else {
  1419. var args = arguments,
  1420. init = args[1],
  1421. animation = this.options.animation,
  1422. attribs,
  1423. center = this.center,
  1424. group = this.group,
  1425. markerGroup = this.markerGroup;
  1426. if (Highcharts.svg) { // VML is too slow anyway
  1427. if (animation === true) {
  1428. animation = {};
  1429. }
  1430. // Initialize the animation
  1431. if (init) {
  1432. // Scale down the group and place it in the center
  1433. group.oldtranslateX = group.translateX;
  1434. group.oldtranslateY = group.translateY;
  1435. attribs = {
  1436. translateX: center[0],
  1437. translateY: center[1],
  1438. scaleX: 0.001, // #1499
  1439. scaleY: 0.001
  1440. };
  1441. group.attr(attribs);
  1442. if (markerGroup) {
  1443. markerGroup.attrSetters = group.attrSetters;
  1444. markerGroup.attr(attribs);
  1445. }
  1446. // Run the animation
  1447. } else {
  1448. attribs = {
  1449. translateX: group.oldtranslateX,
  1450. translateY: group.oldtranslateY,
  1451. scaleX: 1,
  1452. scaleY: 1
  1453. };
  1454. group.animate(attribs, animation);
  1455. if (markerGroup) {
  1456. markerGroup.animate(attribs, animation);
  1457. }
  1458. // Delete this function to allow it only once
  1459. this.animate = null;
  1460. }
  1461. }
  1462. }
  1463. });
  1464. /***
  1465. EXTENSION FOR 3D SCATTER CHART
  1466. ***/
  1467. Highcharts.wrap(Highcharts.seriesTypes.scatter.prototype, 'translate', function (proceed) {
  1468. //function translate3d(proceed) {
  1469. proceed.apply(this, [].slice.call(arguments, 1));
  1470. if (!this.chart.is3d()) {
  1471. return;
  1472. }
  1473. var series = this,
  1474. chart = series.chart,
  1475. zAxis = Highcharts.pick(series.zAxis, chart.options.zAxis[0]),
  1476. rawPoints = [],
  1477. rawPoint,
  1478. projectedPoints,
  1479. projectedPoint,
  1480. zValue,
  1481. i;
  1482. for (i = 0; i < series.data.length; i++) {
  1483. rawPoint = series.data[i];
  1484. zValue = zAxis.isLog && zAxis.val2lin ? zAxis.val2lin(rawPoint.z) : rawPoint.z; // #4562
  1485. rawPoint.plotZ = zAxis.translate(zValue);
  1486. rawPoint.isInside = rawPoint.isInside ? (zValue >= zAxis.min && zValue <= zAxis.max) : false;
  1487. rawPoints.push({
  1488. x: rawPoint.plotX,
  1489. y: rawPoint.plotY,
  1490. z: rawPoint.plotZ
  1491. });
  1492. }
  1493. projectedPoints = perspective(rawPoints, chart, true);
  1494. for (i = 0; i < series.data.length; i++) {
  1495. rawPoint = series.data[i];
  1496. projectedPoint = projectedPoints[i];
  1497. rawPoint.plotXold = rawPoint.plotX;
  1498. rawPoint.plotYold = rawPoint.plotY;
  1499. rawPoint.plotX = projectedPoint.x;
  1500. rawPoint.plotY = projectedPoint.y;
  1501. rawPoint.plotZ = projectedPoint.z;
  1502. }
  1503. });
  1504. Highcharts.wrap(Highcharts.seriesTypes.scatter.prototype, 'init', function (proceed, chart, options) {
  1505. if (chart.is3d()) {
  1506. // add a third coordinate
  1507. this.axisTypes = ['xAxis', 'yAxis', 'zAxis'];
  1508. this.pointArrayMap = ['x', 'y', 'z'];
  1509. this.parallelArrays = ['x', 'y', 'z'];
  1510. // Require direct touch rather than using the k-d-tree, because the k-d-tree currently doesn't
  1511. // take the xyz coordinate system into account (#4552)
  1512. this.directTouch = true;
  1513. }
  1514. var result = proceed.apply(this, [chart, options]);
  1515. if (this.chart.is3d()) {
  1516. // Set a new default tooltip formatter
  1517. var default3dScatterTooltip = 'x: <b>{point.x}</b><br/>y: <b>{point.y}</b><br/>z: <b>{point.z}</b><br/>';
  1518. if (this.userOptions.tooltip) {
  1519. this.tooltipOptions.pointFormat = this.userOptions.tooltip.pointFormat || default3dScatterTooltip;
  1520. } else {
  1521. this.tooltipOptions.pointFormat = default3dScatterTooltip;
  1522. }
  1523. }
  1524. return result;
  1525. });
  1526. /**
  1527. * Extension to the VML Renderer
  1528. */
  1529. if (Highcharts.VMLRenderer) {
  1530. Highcharts.setOptions({ animate: false });
  1531. Highcharts.VMLRenderer.prototype.cuboid = Highcharts.SVGRenderer.prototype.cuboid;
  1532. Highcharts.VMLRenderer.prototype.cuboidPath = Highcharts.SVGRenderer.prototype.cuboidPath;
  1533. Highcharts.VMLRenderer.prototype.toLinePath = Highcharts.SVGRenderer.prototype.toLinePath;
  1534. Highcharts.VMLRenderer.prototype.createElement3D = Highcharts.SVGRenderer.prototype.createElement3D;
  1535. Highcharts.VMLRenderer.prototype.arc3d = function (shapeArgs) {
  1536. var result = Highcharts.SVGRenderer.prototype.arc3d.call(this, shapeArgs);
  1537. result.css({ zIndex: result.zIndex });
  1538. return result;
  1539. };
  1540. Highcharts.VMLRenderer.prototype.arc3dPath = Highcharts.SVGRenderer.prototype.arc3dPath;
  1541. Highcharts.wrap(Highcharts.Axis.prototype, 'render', function (proceed) {
  1542. proceed.apply(this, [].slice.call(arguments, 1));
  1543. // VML doesn't support a negative z-index
  1544. if (this.sideFrame) {
  1545. this.sideFrame.css({ zIndex: 0 });
  1546. this.sideFrame.front.attr({ fill: this.sideFrame.color });
  1547. }
  1548. if (this.bottomFrame) {
  1549. this.bottomFrame.css({ zIndex: 1 });
  1550. this.bottomFrame.front.attr({ fill: this.bottomFrame.color });
  1551. }
  1552. if (this.backFrame) {
  1553. this.backFrame.css({ zIndex: 0 });
  1554. this.backFrame.front.attr({ fill: this.backFrame.color });
  1555. }
  1556. });
  1557. }
  1558. }));