Series.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* *
  2. * (c) 2010-2019 Torstein Honsi
  3. *
  4. * Extension to the Series object in 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. var addEvent = H.addEvent,
  12. perspective = H.perspective,
  13. pick = H.pick;
  14. // Wrap the translate method to post-translate points into 3D perspective
  15. addEvent(H.Series, 'afterTranslate', function () {
  16. if (this.chart.is3d()) {
  17. this.translate3dPoints();
  18. }
  19. });
  20. // Translate the plotX, plotY properties and add plotZ.
  21. H.Series.prototype.translate3dPoints = function () {
  22. var series = this,
  23. chart = series.chart,
  24. zAxis = pick(series.zAxis, chart.options.zAxis[0]),
  25. rawPoints = [],
  26. rawPoint,
  27. projectedPoints,
  28. projectedPoint,
  29. zValue,
  30. i;
  31. for (i = 0; i < series.data.length; i++) {
  32. rawPoint = series.data[i];
  33. if (zAxis && zAxis.translate) {
  34. zValue = zAxis.isLog && zAxis.val2lin ?
  35. zAxis.val2lin(rawPoint.z) :
  36. rawPoint.z; // #4562
  37. rawPoint.plotZ = zAxis.translate(zValue);
  38. rawPoint.isInside = rawPoint.isInside ?
  39. (zValue >= zAxis.min && zValue <= zAxis.max) :
  40. false;
  41. } else {
  42. rawPoint.plotZ = 0;
  43. }
  44. rawPoint.axisXpos = rawPoint.plotX;
  45. rawPoint.axisYpos = rawPoint.plotY;
  46. rawPoint.axisZpos = rawPoint.plotZ;
  47. rawPoints.push({
  48. x: rawPoint.plotX,
  49. y: rawPoint.plotY,
  50. z: rawPoint.plotZ
  51. });
  52. }
  53. projectedPoints = perspective(rawPoints, chart, true);
  54. for (i = 0; i < series.data.length; i++) {
  55. rawPoint = series.data[i];
  56. projectedPoint = projectedPoints[i];
  57. rawPoint.plotX = projectedPoint.x;
  58. rawPoint.plotY = projectedPoint.y;
  59. rawPoint.plotZ = projectedPoint.z;
  60. }
  61. };