You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2626 lines
65 KiB

9 years ago
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license Highcharts JS v4.1.8 (2015-08-20)
  5. *
  6. * (c) 2009-2014 Torstein Honsi
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. // JSLint options:
  11. /*global Highcharts, HighchartsAdapter, document, window, navigator, setInterval, clearInterval, clearTimeout, setTimeout, location, jQuery, $, console */
  12. (function (Highcharts, UNDEFINED) {
  13. var arrayMin = Highcharts.arrayMin,
  14. arrayMax = Highcharts.arrayMax,
  15. each = Highcharts.each,
  16. extend = Highcharts.extend,
  17. merge = Highcharts.merge,
  18. map = Highcharts.map,
  19. pick = Highcharts.pick,
  20. pInt = Highcharts.pInt,
  21. defaultPlotOptions = Highcharts.getOptions().plotOptions,
  22. seriesTypes = Highcharts.seriesTypes,
  23. extendClass = Highcharts.extendClass,
  24. splat = Highcharts.splat,
  25. wrap = Highcharts.wrap,
  26. Axis = Highcharts.Axis,
  27. Tick = Highcharts.Tick,
  28. Point = Highcharts.Point,
  29. Pointer = Highcharts.Pointer,
  30. CenteredSeriesMixin = Highcharts.CenteredSeriesMixin,
  31. TrackerMixin = Highcharts.TrackerMixin,
  32. Series = Highcharts.Series,
  33. math = Math,
  34. mathRound = math.round,
  35. mathFloor = math.floor,
  36. mathMax = math.max,
  37. Color = Highcharts.Color,
  38. noop = function () {};/**
  39. * The Pane object allows options that are common to a set of X and Y axes.
  40. *
  41. * In the future, this can be extended to basic Highcharts and Highstock.
  42. */
  43. function Pane(options, chart, firstAxis) {
  44. this.init.call(this, options, chart, firstAxis);
  45. }
  46. // Extend the Pane prototype
  47. extend(Pane.prototype, {
  48. /**
  49. * Initiate the Pane object
  50. */
  51. init: function (options, chart, firstAxis) {
  52. var pane = this,
  53. backgroundOption,
  54. defaultOptions = pane.defaultOptions;
  55. pane.chart = chart;
  56. // Set options. Angular charts have a default background (#3318)
  57. pane.options = options = merge(defaultOptions, chart.angular ? { background: {} } : undefined, options);
  58. backgroundOption = options.background;
  59. // To avoid having weighty logic to place, update and remove the backgrounds,
  60. // push them to the first axis' plot bands and borrow the existing logic there.
  61. if (backgroundOption) {
  62. each([].concat(splat(backgroundOption)).reverse(), function (config) {
  63. var backgroundColor = config.backgroundColor, // if defined, replace the old one (specific for gradients)
  64. axisUserOptions = firstAxis.userOptions;
  65. config = merge(pane.defaultBackgroundOptions, config);
  66. if (backgroundColor) {
  67. config.backgroundColor = backgroundColor;
  68. }
  69. config.color = config.backgroundColor; // due to naming in plotBands
  70. firstAxis.options.plotBands.unshift(config);
  71. axisUserOptions.plotBands = axisUserOptions.plotBands || []; // #3176
  72. axisUserOptions.plotBands.unshift(config);
  73. });
  74. }
  75. },
  76. /**
  77. * The default options object
  78. */
  79. defaultOptions: {
  80. // background: {conditional},
  81. center: ['50%', '50%'],
  82. size: '85%',
  83. startAngle: 0
  84. //endAngle: startAngle + 360
  85. },
  86. /**
  87. * The default background options
  88. */
  89. defaultBackgroundOptions: {
  90. shape: 'circle',
  91. borderWidth: 1,
  92. borderColor: 'silver',
  93. backgroundColor: {
  94. linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
  95. stops: [
  96. [0, '#FFF'],
  97. [1, '#DDD']
  98. ]
  99. },
  100. from: -Number.MAX_VALUE, // corrected to axis min
  101. innerRadius: 0,
  102. to: Number.MAX_VALUE, // corrected to axis max
  103. outerRadius: '105%'
  104. }
  105. });
  106. var axisProto = Axis.prototype,
  107. tickProto = Tick.prototype;
  108. /**
  109. * Augmented methods for the x axis in order to hide it completely, used for the X axis in gauges
  110. */
  111. var hiddenAxisMixin = {
  112. getOffset: noop,
  113. redraw: function () {
  114. this.isDirty = false; // prevent setting Y axis dirty
  115. },
  116. render: function () {
  117. this.isDirty = false; // prevent setting Y axis dirty
  118. },
  119. setScale: noop,
  120. setCategories: noop,
  121. setTitle: noop
  122. };
  123. /**
  124. * Augmented methods for the value axis
  125. */
  126. /*jslint unparam: true*/
  127. var radialAxisMixin = {
  128. isRadial: true,
  129. /**
  130. * The default options extend defaultYAxisOptions
  131. */
  132. defaultRadialGaugeOptions: {
  133. labels: {
  134. align: 'center',
  135. x: 0,
  136. y: null // auto
  137. },
  138. minorGridLineWidth: 0,
  139. minorTickInterval: 'auto',
  140. minorTickLength: 10,
  141. minorTickPosition: 'inside',
  142. minorTickWidth: 1,
  143. tickLength: 10,
  144. tickPosition: 'inside',
  145. tickWidth: 2,
  146. title: {
  147. rotation: 0
  148. },
  149. zIndex: 2 // behind dials, points in the series group
  150. },
  151. // Circular axis around the perimeter of a polar chart
  152. defaultRadialXOptions: {
  153. gridLineWidth: 1, // spokes
  154. labels: {
  155. align: null, // auto
  156. distance: 15,
  157. x: 0,
  158. y: null // auto
  159. },
  160. maxPadding: 0,
  161. minPadding: 0,
  162. showLastLabel: false,
  163. tickLength: 0
  164. },
  165. // Radial axis, like a spoke in a polar chart
  166. defaultRadialYOptions: {
  167. gridLineInterpolation: 'circle',
  168. labels: {
  169. align: 'right',
  170. x: -3,
  171. y: -2
  172. },
  173. showLastLabel: false,
  174. title: {
  175. x: 4,
  176. text: null,
  177. rotation: 90
  178. }
  179. },
  180. /**
  181. * Merge and set options
  182. */
  183. setOptions: function (userOptions) {
  184. var options = this.options = merge(
  185. this.defaultOptions,
  186. this.defaultRadialOptions,
  187. userOptions
  188. );
  189. // Make sure the plotBands array is instanciated for each Axis (#2649)
  190. if (!options.plotBands) {
  191. options.plotBands = [];
  192. }
  193. },
  194. /**
  195. * Wrap the getOffset method to return zero offset for title or labels in a radial
  196. * axis
  197. */
  198. getOffset: function () {
  199. // Call the Axis prototype method (the method we're in now is on the instance)
  200. axisProto.getOffset.call(this);
  201. // Title or label offsets are not counted
  202. this.chart.axisOffset[this.side] = 0;
  203. // Set the center array
  204. this.center = this.pane.center = CenteredSeriesMixin.getCenter.call(this.pane);
  205. },
  206. /**
  207. * Get the path for the axis line. This method is also referenced in the getPlotLinePath
  208. * method.
  209. */
  210. getLinePath: function (lineWidth, radius) {
  211. var center = this.center;
  212. radius = pick(radius, center[2] / 2 - this.offset);
  213. return this.chart.renderer.symbols.arc(
  214. this.left + center[0],
  215. this.top + center[1],
  216. radius,
  217. radius,
  218. {
  219. start: this.startAngleRad,
  220. end: this.endAngleRad,
  221. open: true,
  222. innerR: 0
  223. }
  224. );
  225. },
  226. /**
  227. * Override setAxisTranslation by setting the translation to the difference
  228. * in rotation. This allows the translate method to return angle for
  229. * any given value.
  230. */
  231. setAxisTranslation: function () {
  232. // Call uber method
  233. axisProto.setAxisTranslation.call(this);
  234. // Set transA and minPixelPadding
  235. if (this.center) { // it's not defined the first time
  236. if (this.isCircular) {
  237. this.transA = (this.endAngleRad - this.startAngleRad) /
  238. ((this.max - this.min) || 1);
  239. } else {
  240. this.transA = (this.center[2] / 2) / ((this.max - this.min) || 1);
  241. }
  242. if (this.isXAxis) {
  243. this.minPixelPadding = this.transA * this.minPointOffset;
  244. } else {
  245. // This is a workaround for regression #2593, but categories still don't position correctly.
  246. // TODO: Implement true handling of Y axis categories on gauges.
  247. this.minPixelPadding = 0;
  248. }
  249. }
  250. },
  251. /**
  252. * In case of auto connect, add one closestPointRange to the max value right before
  253. * tickPositions are computed, so that ticks will extend passed the real max.
  254. */
  255. beforeSetTickPositions: function () {
  256. if (this.autoConnect) {
  257. this.max += (this.categories && 1) || this.pointRange || this.closestPointRange || 0; // #1197, #2260
  258. }
  259. },
  260. /**
  261. * Override the setAxisSize method to use the arc's circumference as length. This
  262. * allows tickPixelInterval to apply to pixel lengths along the perimeter
  263. */
  264. setAxisSize: function () {
  265. axisProto.setAxisSize.call(this);
  266. if (this.isRadial) {
  267. // Set the center array
  268. this.center = this.pane.center = Highcharts.CenteredSeriesMixin.getCenter.call(this.pane);
  269. // The sector is used in Axis.translate to compute the translation of reversed axis points (#2570)
  270. if (this.isCircular) {
  271. this.sector = this.endAngleRad - this.startAngleRad;
  272. }
  273. // Axis len is used to lay out the ticks
  274. this.len = this.width = this.height = this.center[2] * pick(this.sector, 1) / 2;
  275. }
  276. },
  277. /**
  278. * Returns the x, y coordinate of a point given by a value and a pixel distance
  279. * from center
  280. */
  281. getPosition: function (value, length) {
  282. return this.postTranslate(
  283. this.isCircular ? this.translate(value) : 0, // #2848
  284. pick(this.isCircular ? length : this.translate(value), this.center[2] / 2) - this.offset
  285. );
  286. },
  287. /**
  288. * Translate from intermediate plotX (angle), plotY (axis.len - radius) to final chart coordinates.
  289. */
  290. postTranslate: function (angle, radius) {
  291. var chart = this.chart,
  292. center = this.center;
  293. angle = this.startAngleRad + angle;
  294. return {
  295. x: chart.plotLeft + center[0] + Math.cos(angle) * radius,
  296. y: chart.plotTop + center[1] + Math.sin(angle) * radius
  297. };
  298. },
  299. /**
  300. * Find the path for plot bands along the radial axis
  301. */
  302. getPlotBandPath: function (from, to, options) {
  303. var center = this.center,
  304. startAngleRad = this.startAngleRad,
  305. fullRadius = center[2] / 2,
  306. radii = [
  307. pick(options.outerRadius, '100%'),
  308. options.innerRadius,
  309. pick(options.thickness, 10)
  310. ],
  311. percentRegex = /%$/,
  312. start,
  313. end,
  314. open,
  315. isCircular = this.isCircular, // X axis in a polar chart
  316. ret;
  317. // Polygonal plot bands
  318. if (this.options.gridLineInterpolation === 'polygon') {
  319. ret = this.getPlotLinePath(from).concat(this.getPlotLinePath(to, true));
  320. // Circular grid bands
  321. } else {
  322. // Keep within bounds
  323. from = Math.max(from, this.min);
  324. to = Math.min(to, this.max);
  325. // Plot bands on Y axis (radial axis) - inner and outer radius depend on to and from
  326. if (!isCircular) {
  327. radii[0] = this.translate(from);
  328. radii[1] = this.translate(to);
  329. }
  330. // Convert percentages to pixel values
  331. radii = map(radii, function (radius) {
  332. if (percentRegex.test(radius)) {
  333. radius = (pInt(radius, 10) * fullRadius) / 100;
  334. }
  335. return radius;
  336. });
  337. // Handle full circle
  338. if (options.shape === 'circle' || !isCircular) {
  339. start = -Math.PI / 2;
  340. end = Math.PI * 1.5;
  341. open = true;
  342. } else {
  343. start = startAngleRad + this.translate(from);
  344. end = startAngleRad + this.translate(to);
  345. }
  346. ret = this.chart.renderer.symbols.arc(
  347. this.left + center[0],
  348. this.top + center[1],
  349. radii[0],
  350. radii[0],
  351. {
  352. start: Math.min(start, end), // Math is for reversed yAxis (#3606)
  353. end: Math.max(start, end),
  354. innerR: pick(radii[1], radii[0] - radii[2]),
  355. open: open
  356. }
  357. );
  358. }
  359. return ret;
  360. },
  361. /**
  362. * Find the path for plot lines perpendicular to the radial axis.
  363. */
  364. getPlotLinePath: function (value, reverse) {
  365. var axis = this,
  366. center = axis.center,
  367. chart = axis.chart,
  368. end = axis.getPosition(value),
  369. xAxis,
  370. xy,
  371. tickPositions,
  372. ret;
  373. // Spokes
  374. if (axis.isCircular) {
  375. ret = ['M', center[0] + chart.plotLeft, center[1] + chart.plotTop, 'L', end.x, end.y];
  376. // Concentric circles
  377. } else if (axis.options.gridLineInterpolation === 'circle') {
  378. value = axis.translate(value);
  379. if (value) { // a value of 0 is in the center
  380. ret = axis.getLinePath(0, value);
  381. }
  382. // Concentric polygons
  383. } else {
  384. // Find the X axis in the same pane
  385. each(chart.xAxis, function (a) {
  386. if (a.pane === axis.pane) {
  387. xAxis = a;
  388. }
  389. });
  390. ret = [];
  391. value = axis.translate(value);
  392. tickPositions = xAxis.tickPositions;
  393. if (xAxis.autoConnect) {
  394. tickPositions = tickPositions.concat([tickPositions[0]]);
  395. }
  396. // Reverse the positions for concatenation of polygonal plot bands
  397. if (reverse) {
  398. tickPositions = [].concat(tickPositions).reverse();
  399. }
  400. each(tickPositions, function (pos, i) {
  401. xy = xAxis.getPosition(pos, value);
  402. ret.push(i ? 'L' : 'M', xy.x, xy.y);
  403. });
  404. }
  405. return ret;
  406. },
  407. /**
  408. * Find the position for the axis title, by default inside the gauge
  409. */
  410. getTitlePosition: function () {
  411. var center = this.center,
  412. chart = this.chart,
  413. titleOptions = this.options.title;
  414. return {
  415. x: chart.plotLeft + center[0] + (titleOptions.x || 0),
  416. y: chart.plotTop + center[1] - ({ high: 0.5, middle: 0.25, low: 0 }[titleOptions.align] *
  417. center[2]) + (titleOptions.y || 0)
  418. };
  419. }
  420. };
  421. /*jslint unparam: false*/
  422. /**
  423. * Override axisProto.init to mix in special axis instance functions and function overrides
  424. */
  425. wrap(axisProto, 'init', function (proceed, chart, userOptions) {
  426. var axis = this,
  427. angular = chart.angular,
  428. polar = chart.polar,
  429. isX = userOptions.isX,
  430. isHidden = angular && isX,
  431. isCircular,
  432. startAngleRad,
  433. endAngleRad,
  434. options,
  435. chartOptions = chart.options,
  436. paneIndex = userOptions.pane || 0,
  437. pane,
  438. paneOptions;
  439. // Before prototype.init
  440. if (angular) {
  441. extend(this, isHidden ? hiddenAxisMixin : radialAxisMixin);
  442. isCircular = !isX;
  443. if (isCircular) {
  444. this.defaultRadialOptions = this.defaultRadialGaugeOptions;
  445. }
  446. } else if (polar) {
  447. //extend(this, userOptions.isX ? radialAxisMixin : radialAxisMixin);
  448. extend(this, radialAxisMixin);
  449. isCircular = isX;
  450. this.defaultRadialOptions = isX ? this.defaultRadialXOptions : merge(this.defaultYAxisOptions, this.defaultRadialYOptions);
  451. }
  452. // Run prototype.init
  453. proceed.call(this, chart, userOptions);
  454. if (!isHidden && (angular || polar)) {
  455. options = this.options;
  456. // Create the pane and set the pane options.
  457. if (!chart.panes) {
  458. chart.panes = [];
  459. }
  460. this.pane = pane = chart.panes[paneIndex] = chart.panes[paneIndex] || new Pane(
  461. splat(chartOptions.pane)[paneIndex],
  462. chart,
  463. axis
  464. );
  465. paneOptions = pane.options;
  466. // Disable certain features on angular and polar axes
  467. chart.inverted = false;
  468. chartOptions.chart.zoomType = null;
  469. // Start and end angle options are
  470. // given in degrees relative to top, while internal computations are
  471. // in radians relative to right (like SVG).
  472. this.startAngleRad = startAngleRad = (paneOptions.startAngle - 90) * Math.PI / 180;
  473. this.endAngleRad = endAngleRad = (pick(paneOptions.endAngle, paneOptions.startAngle + 360) - 90) * Math.PI / 180;
  474. this.offset = options.offset || 0;
  475. this.isCircular = isCircular;
  476. // Automatically connect grid lines?
  477. if (isCircular && userOptions.max === UNDEFINED && endAngleRad - startAngleRad === 2 * Math.PI) {
  478. this.autoConnect = true;
  479. }
  480. }
  481. });
  482. /**
  483. * Add special cases within the Tick class' methods for radial axes.
  484. */
  485. wrap(tickProto, 'getPosition', function (proceed, horiz, pos, tickmarkOffset, old) {
  486. var axis = this.axis;
  487. return axis.getPosition ?
  488. axis.getPosition(pos) :
  489. proceed.call(this, horiz, pos, tickmarkOffset, old);
  490. });
  491. /**
  492. * Wrap the getLabelPosition function to find the center position of the label
  493. * based on the distance option
  494. */
  495. wrap(tickProto, 'getLabelPosition', function (proceed, x, y, label, horiz, labelOptions, tickmarkOffset, index, step) {
  496. var axis = this.axis,
  497. optionsY = labelOptions.y,
  498. ret,
  499. centerSlot = 20, // 20 degrees to each side at the top and bottom
  500. align = labelOptions.align,
  501. angle = ((axis.translate(this.pos) + axis.startAngleRad + Math.PI / 2) / Math.PI * 180) % 360;
  502. if (axis.isRadial) {
  503. ret = axis.getPosition(this.pos, (axis.center[2] / 2) + pick(labelOptions.distance, -25));
  504. // Automatically rotated
  505. if (labelOptions.rotation === 'auto') {
  506. label.attr({
  507. rotation: angle
  508. });
  509. // Vertically centered
  510. } else if (optionsY === null) {
  511. optionsY = axis.chart.renderer.fontMetrics(label.styles.fontSize).b - label.getBBox().height / 2;
  512. }
  513. // Automatic alignment
  514. if (align === null) {
  515. if (axis.isCircular) {
  516. if (this.label.getBBox().width > axis.len * axis.tickInterval / (axis.max - axis.min)) { // #3506
  517. centerSlot = 0;
  518. }
  519. if (angle > centerSlot && angle < 180 - centerSlot) {
  520. align = 'left'; // right hemisphere
  521. } else if (angle > 180 + centerSlot && angle < 360 - centerSlot) {
  522. align = 'right'; // left hemisphere
  523. } else {
  524. align = 'center'; // top or bottom
  525. }
  526. } else {
  527. align = 'center';
  528. }
  529. label.attr({
  530. align: align
  531. });
  532. }
  533. ret.x += labelOptions.x;
  534. ret.y += optionsY;
  535. } else {
  536. ret = proceed.call(this, x, y, label, horiz, labelOptions, tickmarkOffset, index, step);
  537. }
  538. return ret;
  539. });
  540. /**
  541. * Wrap the getMarkPath function to return the path of the radial marker
  542. */
  543. wrap(tickProto, 'getMarkPath', function (proceed, x, y, tickLength, tickWidth, horiz, renderer) {
  544. var axis = this.axis,
  545. endPoint,
  546. ret;
  547. if (axis.isRadial) {
  548. endPoint = axis.getPosition(this.pos, axis.center[2] / 2 + tickLength);
  549. ret = [
  550. 'M',
  551. x,
  552. y,
  553. 'L',
  554. endPoint.x,
  555. endPoint.y
  556. ];
  557. } else {
  558. ret = proceed.call(this, x, y, tickLength, tickWidth, horiz, renderer);
  559. }
  560. return ret;
  561. });/*
  562. * The AreaRangeSeries class
  563. *
  564. */
  565. /**
  566. * Extend the default options with map options
  567. */
  568. defaultPlotOptions.arearange = merge(defaultPlotOptions.area, {
  569. lineWidth: 1,
  570. marker: null,
  571. threshold: null,
  572. tooltip: {
  573. pointFormat: '<span style="color:{series.color}">\u25CF</span> {series.name}: <b>{point.low}</b> - <b>{point.high}</b><br/>'
  574. },
  575. trackByArea: true,
  576. dataLabels: {
  577. align: null,
  578. verticalAlign: null,
  579. xLow: 0,
  580. xHigh: 0,
  581. yLow: 0,
  582. yHigh: 0
  583. },
  584. states: {
  585. hover: {
  586. halo: false
  587. }
  588. }
  589. });
  590. /**
  591. * Add the series type
  592. */
  593. seriesTypes.arearange = extendClass(seriesTypes.area, {
  594. type: 'arearange',
  595. pointArrayMap: ['low', 'high'],
  596. dataLabelCollections: ['dataLabel', 'dataLabelUpper'],
  597. toYData: function (point) {
  598. return [point.low, point.high];
  599. },
  600. pointValKey: 'low',
  601. deferTranslatePolar: true,
  602. /**
  603. * Translate a point's plotHigh from the internal angle and radius measures to
  604. * true plotHigh coordinates. This is an addition of the toXY method found in
  605. * Polar.js, because it runs too early for arearanges to be considered (#3419).
  606. */
  607. highToXY: function (point) {
  608. // Find the polar plotX and plotY
  609. var chart = this.chart,
  610. xy = this.xAxis.postTranslate(point.rectPlotX, this.yAxis.len - point.plotHigh);
  611. point.plotHighX = xy.x - chart.plotLeft;
  612. point.plotHigh = xy.y - chart.plotTop;
  613. },
  614. /**
  615. * Extend getSegments to force null points if the higher value is null. #1703.
  616. */
  617. getSegments: function () {
  618. var series = this;
  619. each(series.points, function (point) {
  620. if (!series.options.connectNulls && (point.low === null || point.high === null)) {
  621. point.y = null;
  622. } else if (point.low === null && point.high !== null) {
  623. point.y = point.high;
  624. }
  625. });
  626. Series.prototype.getSegments.call(this);
  627. },
  628. /**
  629. * Translate data points from raw values x and y to plotX and plotY
  630. */
  631. translate: function () {
  632. var series = this,
  633. yAxis = series.yAxis;
  634. seriesTypes.area.prototype.translate.apply(series);
  635. // Set plotLow and plotHigh
  636. each(series.points, function (point) {
  637. var low = point.low,
  638. high = point.high,
  639. plotY = point.plotY;
  640. if (high === null && low === null) {
  641. point.y = null;
  642. } else if (low === null) {
  643. point.plotLow = point.plotY = null;
  644. point.plotHigh = yAxis.translate(high, 0, 1, 0, 1);
  645. } else if (high === null) {
  646. point.plotLow = plotY;
  647. point.plotHigh = null;
  648. } else {
  649. point.plotLow = plotY;
  650. point.plotHigh = yAxis.translate(high, 0, 1, 0, 1);
  651. }
  652. });
  653. // Postprocess plotHigh
  654. if (this.chart.polar) {
  655. each(this.points, function (point) {
  656. series.highToXY(point);
  657. });
  658. }
  659. },
  660. /**
  661. * Extend the line series' getSegmentPath method by applying the segment
  662. * path to both lower and higher values of the range
  663. */
  664. getSegmentPath: function (segment) {
  665. var lowSegment,
  666. highSegment = [],
  667. i = segment.length,
  668. baseGetSegmentPath = Series.prototype.getSegmentPath,
  669. point,
  670. linePath,
  671. lowerPath,
  672. options = this.options,
  673. step = options.step,
  674. higherPath;
  675. // Remove nulls from low segment
  676. lowSegment = HighchartsAdapter.grep(segment, function (point) {
  677. return point.plotLow !== null;
  678. });
  679. // Make a segment with plotX and plotY for the top values
  680. while (i--) {
  681. point = segment[i];
  682. if (point.plotHigh !== null) {
  683. highSegment.push({
  684. plotX: point.plotHighX || point.plotX, // plotHighX is for polar charts
  685. plotY: point.plotHigh
  686. });
  687. }
  688. }
  689. // Get the paths
  690. lowerPath = baseGetSegmentPath.call(this, lowSegment);
  691. if (step) {
  692. if (step === true) {
  693. step = 'left';
  694. }
  695. options.step = { left: 'right', center: 'center', right: 'left' }[step]; // swap for reading in getSegmentPath
  696. }
  697. higherPath = baseGetSegmentPath.call(this, highSegment);
  698. options.step = step;
  699. // Create a line on both top and bottom of the range
  700. linePath = [].concat(lowerPath, higherPath);
  701. // For the area path, we need to change the 'move' statement into 'lineTo' or 'curveTo'
  702. if (!this.chart.polar) {
  703. higherPath[0] = 'L'; // this probably doesn't work for spline
  704. }
  705. this.areaPath = this.areaPath.concat(lowerPath, higherPath);
  706. return linePath;
  707. },
  708. /**
  709. * Extend the basic drawDataLabels method by running it for both lower and higher
  710. * values.
  711. */
  712. drawDataLabels: function () {
  713. var data = this.data,
  714. length = data.length,
  715. i,
  716. originalDataLabels = [],
  717. seriesProto = Series.prototype,
  718. dataLabelOptions = this.options.dataLabels,
  719. align = dataLabelOptions.align,
  720. point,
  721. up,
  722. inverted = this.chart.inverted;
  723. if (dataLabelOptions.enabled || this._hasPointLabels) {
  724. // Step 1: set preliminary values for plotY and dataLabel and draw the upper labels
  725. i = length;
  726. while (i--) {
  727. point = data[i];
  728. if (point) {
  729. up = point.plotHigh > point.plotLow;
  730. // Set preliminary values
  731. point.y = point.high;
  732. point._plotY = point.plotY;
  733. point.plotY = point.plotHigh;
  734. // Store original data labels and set preliminary label objects to be picked up
  735. // in the uber method
  736. originalDataLabels[i] = point.dataLabel;
  737. point.dataLabel = point.dataLabelUpper;
  738. // Set the default offset
  739. point.below = up;
  740. if (inverted) {
  741. if (!align) {
  742. dataLabelOptions.align = up ? 'right' : 'left';
  743. }
  744. dataLabelOptions.x = dataLabelOptions.xHigh;
  745. } else {
  746. dataLabelOptions.y = dataLabelOptions.yHigh;
  747. }
  748. }
  749. }
  750. if (seriesProto.drawDataLabels) {
  751. seriesProto.drawDataLabels.apply(this, arguments); // #1209
  752. }
  753. // Step 2: reorganize and handle data labels for the lower values
  754. i = length;
  755. while (i--) {
  756. point = data[i];
  757. if (point) {
  758. up = point.plotHigh > point.plotLow;
  759. // Move the generated labels from step 1, and reassign the original data labels
  760. point.dataLabelUpper = point.dataLabel;
  761. point.dataLabel = originalDataLabels[i];
  762. // Reset values
  763. point.y = point.low;
  764. point.plotY = point._plotY;
  765. // Set the default offset
  766. point.below = !up;
  767. if (inverted) {
  768. if (!align) {
  769. dataLabelOptions.align = up ? 'left' : 'right';
  770. }
  771. dataLabelOptions.x = dataLabelOptions.xLow;
  772. } else {
  773. dataLabelOptions.y = dataLabelOptions.yLow;
  774. }
  775. }
  776. }
  777. if (seriesProto.drawDataLabels) {
  778. seriesProto.drawDataLabels.apply(this, arguments);
  779. }
  780. }
  781. dataLabelOptions.align = align;
  782. },
  783. alignDataLabel: function () {
  784. seriesTypes.column.prototype.alignDataLabel.apply(this, arguments);
  785. },
  786. setStackedPoints: noop,
  787. getSymbol: noop,
  788. drawPoints: noop
  789. });/**
  790. * The AreaSplineRangeSeries class
  791. */
  792. defaultPlotOptions.areasplinerange = merge(defaultPlotOptions.arearange);
  793. /**
  794. * AreaSplineRangeSeries object
  795. */
  796. seriesTypes.areasplinerange = extendClass(seriesTypes.arearange, {
  797. type: 'areasplinerange',
  798. getPointSpline: seriesTypes.spline.prototype.getPointSpline
  799. });
  800. (function () {
  801. var colProto = seriesTypes.column.prototype;
  802. /**
  803. * The ColumnRangeSeries class
  804. */
  805. defaultPlotOptions.columnrange = merge(defaultPlotOptions.column, defaultPlotOptions.arearange, {
  806. lineWidth: 1,
  807. pointRange: null
  808. });
  809. /**
  810. * ColumnRangeSeries object
  811. */
  812. seriesTypes.columnrange = extendClass(seriesTypes.arearange, {
  813. type: 'columnrange',
  814. /**
  815. * Translate data points from raw values x and y to plotX and plotY
  816. */
  817. translate: function () {
  818. var series = this,
  819. yAxis = series.yAxis,
  820. plotHigh;
  821. colProto.translate.apply(series);
  822. // Set plotLow and plotHigh
  823. each(series.points, function (point) {
  824. var shapeArgs = point.shapeArgs,
  825. minPointLength = series.options.minPointLength,
  826. heightDifference,
  827. height,
  828. y;
  829. point.tooltipPos = null; // don't inherit from column
  830. point.plotHigh = plotHigh = yAxis.translate(point.high, 0, 1, 0, 1);
  831. point.plotLow = point.plotY;
  832. // adjust shape
  833. y = plotHigh;
  834. height = point.plotY - plotHigh;
  835. // Adjust for minPointLength
  836. if (Math.abs(height) < minPointLength) {
  837. heightDifference = (minPointLength - height);
  838. height += heightDifference;
  839. y -= heightDifference / 2;
  840. // Adjust for negative ranges or reversed Y axis (#1457)
  841. } else if (height < 0) {
  842. height *= -1;
  843. y -= height;
  844. }
  845. shapeArgs.height = height;
  846. shapeArgs.y = y;
  847. });
  848. },
  849. directTouch: true,
  850. trackerGroups: ['group', 'dataLabelsGroup'],
  851. drawGraph: noop,
  852. pointAttrToOptions: colProto.pointAttrToOptions,
  853. drawPoints: colProto.drawPoints,
  854. drawTracker: colProto.drawTracker,
  855. animate: colProto.animate,
  856. getColumnMetrics: colProto.getColumnMetrics
  857. });
  858. }());
  859. /*
  860. * The GaugeSeries class
  861. */
  862. /**
  863. * Extend the default options
  864. */
  865. defaultPlotOptions.gauge = merge(defaultPlotOptions.line, {
  866. dataLabels: {
  867. enabled: true,
  868. defer: false,
  869. y: 15,
  870. borderWidth: 1,
  871. borderColor: 'silver',
  872. borderRadius: 3,
  873. crop: false,
  874. verticalAlign: 'top',
  875. zIndex: 2
  876. },
  877. dial: {
  878. // radius: '80%',
  879. // backgroundColor: 'black',
  880. // borderColor: 'silver',
  881. // borderWidth: 0,
  882. // baseWidth: 3,
  883. // topWidth: 1,
  884. // baseLength: '70%' // of radius
  885. // rearLength: '10%'
  886. },
  887. pivot: {
  888. //radius: 5,
  889. //borderWidth: 0
  890. //borderColor: 'silver',
  891. //backgroundColor: 'black'
  892. },
  893. tooltip: {
  894. headerFormat: ''
  895. },
  896. showInLegend: false
  897. });
  898. /**
  899. * Extend the point object
  900. */
  901. var GaugePoint = extendClass(Point, {
  902. /**
  903. * Don't do any hover colors or anything
  904. */
  905. setState: function (state) {
  906. this.state = state;
  907. }
  908. });
  909. /**
  910. * Add the series type
  911. */
  912. var GaugeSeries = {
  913. type: 'gauge',
  914. pointClass: GaugePoint,
  915. // chart.angular will be set to true when a gauge series is present, and this will
  916. // be used on the axes
  917. angular: true,
  918. drawGraph: noop,
  919. fixedBox: true,
  920. forceDL: true,
  921. trackerGroups: ['group', 'dataLabelsGroup'],
  922. /**
  923. * Calculate paths etc
  924. */
  925. translate: function () {
  926. var series = this,
  927. yAxis = series.yAxis,
  928. options = series.options,
  929. center = yAxis.center;
  930. series.generatePoints();
  931. each(series.points, function (point) {
  932. var dialOptions = merge(options.dial, point.dial),
  933. radius = (pInt(pick(dialOptions.radius, 80)) * center[2]) / 200,
  934. baseLength = (pInt(pick(dialOptions.baseLength, 70)) * radius) / 100,
  935. rearLength = (pInt(pick(dialOptions.rearLength, 10)) * radius) / 100,
  936. baseWidth = dialOptions.baseWidth || 3,
  937. topWidth = dialOptions.topWidth || 1,
  938. overshoot = options.overshoot,
  939. rotation = yAxis.startAngleRad + yAxis.translate(point.y, null, null, null, true);
  940. // Handle the wrap and overshoot options
  941. if (overshoot && typeof overshoot === 'number') {
  942. overshoot = overshoot / 180 * Math.PI;
  943. rotation = Math.max(yAxis.startAngleRad - overshoot, Math.min(yAxis.endAngleRad + overshoot, rotation));
  944. } else if (options.wrap === false) {
  945. rotation = Math.max(yAxis.startAngleRad, Math.min(yAxis.endAngleRad, rotation));
  946. }
  947. rotation = rotation * 180 / Math.PI;
  948. point.shapeType = 'path';
  949. point.shapeArgs = {
  950. d: dialOptions.path || [
  951. 'M',
  952. -rearLength, -baseWidth / 2,
  953. 'L',
  954. baseLength, -baseWidth / 2,
  955. radius, -topWidth / 2,
  956. radius, topWidth / 2,
  957. baseLength, baseWidth / 2,
  958. -rearLength, baseWidth / 2,
  959. 'z'
  960. ],
  961. translateX: center[0],
  962. translateY: center[1],
  963. rotation: rotation
  964. };
  965. // Positions for data label
  966. point.plotX = center[0];
  967. point.plotY = center[1];
  968. });
  969. },
  970. /**
  971. * Draw the points where each point is one needle
  972. */
  973. drawPoints: function () {
  974. var series = this,
  975. center = series.yAxis.center,
  976. pivot = series.pivot,
  977. options = series.options,
  978. pivotOptions = options.pivot,
  979. renderer = series.chart.renderer;
  980. each(series.points, function (point) {
  981. var graphic = point.graphic,
  982. shapeArgs = point.shapeArgs,
  983. d = shapeArgs.d,
  984. dialOptions = merge(options.dial, point.dial); // #1233
  985. if (graphic) {
  986. graphic.animate(shapeArgs);
  987. shapeArgs.d = d; // animate alters it
  988. } else {
  989. point.graphic = renderer[point.shapeType](shapeArgs)
  990. .attr({
  991. stroke: dialOptions.borderColor || 'none',
  992. 'stroke-width': dialOptions.borderWidth || 0,
  993. fill: dialOptions.backgroundColor || 'black',
  994. rotation: shapeArgs.rotation // required by VML when animation is false
  995. })
  996. .add(series.group);
  997. }
  998. });
  999. // Add or move the pivot
  1000. if (pivot) {
  1001. pivot.animate({ // #1235
  1002. translateX: center[0],
  1003. translateY: center[1]
  1004. });
  1005. } else {
  1006. series.pivot = renderer.circle(0, 0, pick(pivotOptions.radius, 5))
  1007. .attr({
  1008. 'stroke-width': pivotOptions.borderWidth || 0,
  1009. stroke: pivotOptions.borderColor || 'silver',
  1010. fill: pivotOptions.backgroundColor || 'black'
  1011. })
  1012. .translate(center[0], center[1])
  1013. .add(series.group);
  1014. }
  1015. },
  1016. /**
  1017. * Animate the arrow up from startAngle
  1018. */
  1019. animate: function (init) {
  1020. var series = this;
  1021. if (!init) {
  1022. each(series.points, function (point) {
  1023. var graphic = point.graphic;
  1024. if (graphic) {
  1025. // start value
  1026. graphic.attr({
  1027. rotation: series.yAxis.startAngleRad * 180 / Math.PI
  1028. });
  1029. // animate
  1030. graphic.animate({
  1031. rotation: point.shapeArgs.rotation
  1032. }, series.options.animation);
  1033. }
  1034. });
  1035. // delete this function to allow it only once
  1036. series.animate = null;
  1037. }
  1038. },
  1039. render: function () {
  1040. this.group = this.plotGroup(
  1041. 'group',
  1042. 'series',
  1043. this.visible ? 'visible' : 'hidden',
  1044. this.options.zIndex,
  1045. this.chart.seriesGroup
  1046. );
  1047. Series.prototype.render.call(this);
  1048. this.group.clip(this.chart.clipRect);
  1049. },
  1050. /**
  1051. * Extend the basic setData method by running processData and generatePoints immediately,
  1052. * in order to access the points from the legend.
  1053. */
  1054. setData: function (data, redraw) {
  1055. Series.prototype.setData.call(this, data, false);
  1056. this.processData();
  1057. this.generatePoints();
  1058. if (pick(redraw, true)) {
  1059. this.chart.redraw();
  1060. }
  1061. },
  1062. /**
  1063. * If the tracking module is loaded, add the point tracker
  1064. */
  1065. drawTracker: TrackerMixin && TrackerMixin.drawTrackerPoint
  1066. };
  1067. seriesTypes.gauge = extendClass(seriesTypes.line, GaugeSeries);
  1068. /* ****************************************************************************
  1069. * Start Box plot series code *
  1070. *****************************************************************************/
  1071. // Set default options
  1072. defaultPlotOptions.boxplot = merge(defaultPlotOptions.column, {
  1073. fillColor: '#FFFFFF',
  1074. lineWidth: 1,
  1075. //medianColor: null,
  1076. medianWidth: 2,
  1077. states: {
  1078. hover: {
  1079. brightness: -0.3
  1080. }
  1081. },
  1082. //stemColor: null,
  1083. //stemDashStyle: 'solid'
  1084. //stemWidth: null,
  1085. threshold: null,
  1086. tooltip: {
  1087. pointFormat: '<span style="color:{point.color}">\u25CF</span> <b> {series.name}</b><br/>' + // docs
  1088. 'Maximum: {point.high}<br/>' +
  1089. 'Upper quartile: {point.q3}<br/>' +
  1090. 'Median: {point.median}<br/>' +
  1091. 'Lower quartile: {point.q1}<br/>' +
  1092. 'Minimum: {point.low}<br/>'
  1093. },
  1094. //whiskerColor: null,
  1095. whiskerLength: '50%',
  1096. whiskerWidth: 2
  1097. });
  1098. // Create the series object
  1099. seriesTypes.boxplot = extendClass(seriesTypes.column, {
  1100. type: 'boxplot',
  1101. pointArrayMap: ['low', 'q1', 'median', 'q3', 'high'], // array point configs are mapped to this
  1102. toYData: function (point) { // return a plain array for speedy calculation
  1103. return [point.low, point.q1, point.median, point.q3, point.high];
  1104. },
  1105. pointValKey: 'high', // defines the top of the tracker
  1106. /**
  1107. * One-to-one mapping from options to SVG attributes
  1108. */
  1109. pointAttrToOptions: { // mapping between SVG attributes and the corresponding options
  1110. fill: 'fillColor',
  1111. stroke: 'color',
  1112. 'stroke-width': 'lineWidth'
  1113. },
  1114. /**
  1115. * Disable data labels for box plot
  1116. */
  1117. drawDataLabels: noop,
  1118. /**
  1119. * Translate data points from raw values x and y to plotX and plotY
  1120. */
  1121. translate: function () {
  1122. var series = this,
  1123. yAxis = series.yAxis,
  1124. pointArrayMap = series.pointArrayMap;
  1125. seriesTypes.column.prototype.translate.apply(series);
  1126. // do the translation on each point dimension
  1127. each(series.points, function (point) {
  1128. each(pointArrayMap, function (key) {
  1129. if (point[key] !== null) {
  1130. point[key + 'Plot'] = yAxis.translate(point[key], 0, 1, 0, 1);
  1131. }
  1132. });
  1133. });
  1134. },
  1135. /**
  1136. * Draw the data points
  1137. */
  1138. drawPoints: function () {
  1139. var series = this, //state = series.state,
  1140. points = series.points,
  1141. options = series.options,
  1142. chart = series.chart,
  1143. renderer = chart.renderer,
  1144. pointAttr,
  1145. q1Plot,
  1146. q3Plot,
  1147. highPlot,
  1148. lowPlot,
  1149. medianPlot,
  1150. crispCorr,
  1151. crispX,
  1152. graphic,
  1153. stemPath,
  1154. stemAttr,
  1155. boxPath,
  1156. whiskersPath,
  1157. whiskersAttr,
  1158. medianPath,
  1159. medianAttr,
  1160. width,
  1161. left,
  1162. right,
  1163. halfWidth,
  1164. shapeArgs,
  1165. color,
  1166. doQuartiles = series.doQuartiles !== false, // error bar inherits this series type but doesn't do quartiles
  1167. whiskerLength = parseInt(series.options.whiskerLength, 10) / 100;
  1168. each(points, function (point) {
  1169. graphic = point.graphic;
  1170. shapeArgs = point.shapeArgs; // the box
  1171. stemAttr = {};
  1172. whiskersAttr = {};
  1173. medianAttr = {};
  1174. color = point.color || series.color;
  1175. if (point.plotY !== UNDEFINED) {
  1176. pointAttr = point.pointAttr[point.selected ? 'selected' : ''];
  1177. // crisp vector coordinates
  1178. width = shapeArgs.width;
  1179. left = mathFloor(shapeArgs.x);
  1180. right = left + width;
  1181. halfWidth = mathRound(width / 2);
  1182. //crispX = mathRound(left + halfWidth) + crispCorr;
  1183. q1Plot = mathFloor(doQuartiles ? point.q1Plot : point.lowPlot);// + crispCorr;
  1184. q3Plot = mathFloor(doQuartiles ? point.q3Plot : point.lowPlot);// + crispCorr;
  1185. highPlot = mathFloor(point.highPlot);// + crispCorr;
  1186. lowPlot = mathFloor(point.lowPlot);// + crispCorr;
  1187. // Stem attributes
  1188. stemAttr.stroke = point.stemColor || options.stemColor || color;
  1189. stemAttr['stroke-width'] = pick(point.stemWidth, options.stemWidth, options.lineWidth);
  1190. stemAttr.dashstyle = point.stemDashStyle || options.stemDashStyle;
  1191. // Whiskers attributes
  1192. whiskersAttr.stroke = point.whiskerColor || options.whiskerColor || color;
  1193. whiskersAttr['stroke-width'] = pick(point.whiskerWidth, options.whiskerWidth, options.lineWidth);
  1194. // Median attributes
  1195. medianAttr.stroke = point.medianColor || options.medianColor || color;
  1196. medianAttr['stroke-width'] = pick(point.medianWidth, options.medianWidth, options.lineWidth);
  1197. // The stem
  1198. crispCorr = (stemAttr['stroke-width'] % 2) / 2;
  1199. crispX = left + halfWidth + crispCorr;
  1200. stemPath = [
  1201. // stem up
  1202. 'M',
  1203. crispX, q3Plot,
  1204. 'L',
  1205. crispX, highPlot,
  1206. // stem down
  1207. 'M',
  1208. crispX, q1Plot,
  1209. 'L',
  1210. crispX, lowPlot
  1211. ];
  1212. // The box
  1213. if (doQuartiles) {
  1214. crispCorr = (pointAttr['stroke-width'] % 2) / 2;
  1215. crispX = mathFloor(crispX) + crispCorr;
  1216. q1Plot = mathFloor(q1Plot) + crispCorr;
  1217. q3Plot = mathFloor(q3Plot) + crispCorr;
  1218. left += crispCorr;
  1219. right += crispCorr;
  1220. boxPath = [
  1221. 'M',
  1222. left, q3Plot,
  1223. 'L',
  1224. left, q1Plot,
  1225. 'L',
  1226. right, q1Plot,
  1227. 'L',
  1228. right, q3Plot,
  1229. 'L',
  1230. left, q3Plot,
  1231. 'z'
  1232. ];
  1233. }
  1234. // The whiskers
  1235. if (whiskerLength) {
  1236. crispCorr = (whiskersAttr['stroke-width'] % 2) / 2;
  1237. highPlot = highPlot + crispCorr;
  1238. lowPlot = lowPlot + crispCorr;
  1239. whiskersPath = [
  1240. // High whisker
  1241. 'M',
  1242. crispX - halfWidth * whiskerLength,
  1243. highPlot,
  1244. 'L',
  1245. crispX + halfWidth * whiskerLength,
  1246. highPlot,
  1247. // Low whisker
  1248. 'M',
  1249. crispX - halfWidth * whiskerLength,
  1250. lowPlot,
  1251. 'L',
  1252. crispX + halfWidth * whiskerLength,
  1253. lowPlot
  1254. ];
  1255. }
  1256. // The median
  1257. crispCorr = (medianAttr['stroke-width'] % 2) / 2;
  1258. medianPlot = mathRound(point.medianPlot) + crispCorr;
  1259. medianPath = [
  1260. 'M',
  1261. left,
  1262. medianPlot,
  1263. 'L',
  1264. right,
  1265. medianPlot
  1266. ];
  1267. // Create or update the graphics
  1268. if (graphic) { // update
  1269. point.stem.animate({ d: stemPath });
  1270. if (whiskerLength) {
  1271. point.whiskers.animate({ d: whiskersPath });
  1272. }
  1273. if (doQuartiles) {
  1274. point.box.animate({ d: boxPath });
  1275. }
  1276. point.medianShape.animate({ d: medianPath });
  1277. } else { // create new
  1278. point.graphic = graphic = renderer.g()
  1279. .add(series.group);
  1280. point.stem = renderer.path(stemPath)
  1281. .attr(stemAttr)
  1282. .add(graphic);
  1283. if (whiskerLength) {
  1284. point.whiskers = renderer.path(whiskersPath)
  1285. .attr(whiskersAttr)
  1286. .add(graphic);
  1287. }
  1288. if (doQuartiles) {
  1289. point.box = renderer.path(boxPath)
  1290. .attr(pointAttr)
  1291. .add(graphic);
  1292. }
  1293. point.medianShape = renderer.path(medianPath)
  1294. .attr(medianAttr)
  1295. .add(graphic);
  1296. }
  1297. }
  1298. });
  1299. },
  1300. setStackedPoints: noop // #3890
  1301. });
  1302. /* ****************************************************************************
  1303. * End Box plot series code *
  1304. *****************************************************************************/
  1305. /* ****************************************************************************
  1306. * Start error bar series code *
  1307. *****************************************************************************/
  1308. // 1 - set default options
  1309. defaultPlotOptions.errorbar = merge(defaultPlotOptions.boxplot, {
  1310. color: '#000000',
  1311. grouping: false,
  1312. linkedTo: ':previous',
  1313. tooltip: {
  1314. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.low}</b> - <b>{point.high}</b><br/>' // docs
  1315. },
  1316. whiskerWidth: null
  1317. });
  1318. // 2 - Create the series object
  1319. seriesTypes.errorbar = extendClass(seriesTypes.boxplot, {
  1320. type: 'errorbar',
  1321. pointArrayMap: ['low', 'high'], // array point configs are mapped to this
  1322. toYData: function (point) { // return a plain array for speedy calculation
  1323. return [point.low, point.high];
  1324. },
  1325. pointValKey: 'high', // defines the top of the tracker
  1326. doQuartiles: false,
  1327. drawDataLabels: seriesTypes.arearange ? seriesTypes.arearange.prototype.drawDataLabels : noop,
  1328. /**
  1329. * Get the width and X offset, either on top of the linked series column
  1330. * or standalone
  1331. */
  1332. getColumnMetrics: function () {
  1333. return (this.linkedParent && this.linkedParent.columnMetrics) ||
  1334. seriesTypes.column.prototype.getColumnMetrics.call(this);
  1335. }
  1336. });
  1337. /* ****************************************************************************
  1338. * End error bar series code *
  1339. *****************************************************************************/
  1340. /* ****************************************************************************
  1341. * Start Waterfall series code *
  1342. *****************************************************************************/
  1343. // 1 - set default options
  1344. defaultPlotOptions.waterfall = merge(defaultPlotOptions.column, {
  1345. lineWidth: 1,
  1346. lineColor: '#333',
  1347. dashStyle: 'dot',
  1348. borderColor: '#333',
  1349. dataLabels: {
  1350. inside: true
  1351. },
  1352. states: {
  1353. hover: {
  1354. lineWidthPlus: 0 // #3126
  1355. }
  1356. }
  1357. });
  1358. // 2 - Create the series object
  1359. seriesTypes.waterfall = extendClass(seriesTypes.column, {
  1360. type: 'waterfall',
  1361. upColorProp: 'fill',
  1362. pointValKey: 'y',
  1363. /**
  1364. * Translate data points from raw values
  1365. */
  1366. translate: function () {
  1367. var series = this,
  1368. options = series.options,
  1369. yAxis = series.yAxis,
  1370. len,
  1371. i,
  1372. points,
  1373. point,
  1374. shapeArgs,
  1375. stack,
  1376. y,
  1377. yValue,
  1378. previousY,
  1379. previousIntermediate,
  1380. range,
  1381. threshold = options.threshold,
  1382. stacking = options.stacking,
  1383. tooltipY;
  1384. // run column series translate
  1385. seriesTypes.column.prototype.translate.apply(this);
  1386. previousY = previousIntermediate = threshold;
  1387. points = series.points;
  1388. for (i = 0, len = points.length; i < len; i++) {
  1389. // cache current point object
  1390. point = points[i];
  1391. yValue = this.processedYData[i];
  1392. shapeArgs = point.shapeArgs;
  1393. // get current stack
  1394. stack = stacking && yAxis.stacks[(series.negStacks && yValue < threshold ? '-' : '') + series.stackKey];
  1395. range = stack ?
  1396. stack[point.x].points[series.index + ',' + i] :
  1397. [0, yValue];
  1398. // override point value for sums
  1399. // #3710 Update point does not propagate to sum
  1400. if (point.isSum) {
  1401. point.y = yValue;
  1402. } else if (point.isIntermediateSum) {
  1403. point.y = yValue - previousIntermediate; // #3840
  1404. }
  1405. // up points
  1406. y = mathMax(previousY, previousY + point.y) + range[0];
  1407. shapeArgs.y = yAxis.translate(y, 0, 1);
  1408. // sum points
  1409. if (point.isSum) {
  1410. shapeArgs.y = yAxis.translate(range[1], 0, 1);
  1411. shapeArgs.height = Math.min(yAxis.translate(range[0], 0, 1), yAxis.len) - shapeArgs.y; // #4256
  1412. } else if (point.isIntermediateSum) {
  1413. shapeArgs.y = yAxis.translate(range[1], 0, 1);
  1414. shapeArgs.height = Math.min(yAxis.translate(previousIntermediate, 0, 1), yAxis.len) - shapeArgs.y;
  1415. previousIntermediate = range[1];
  1416. // If it's not the sum point, update previous stack end position and get
  1417. // shape height (#3886)
  1418. } else {
  1419. if (previousY !== 0) { // Not the first point
  1420. shapeArgs.height = yValue > 0 ?
  1421. yAxis.translate(previousY, 0, 1) - shapeArgs.y :
  1422. yAxis.translate(previousY, 0, 1) - yAxis.translate(previousY - yValue, 0, 1);
  1423. }
  1424. previousY += yValue;
  1425. }
  1426. // #3952 Negative sum or intermediate sum not rendered correctly
  1427. if (shapeArgs.height < 0) {
  1428. shapeArgs.y += shapeArgs.height;
  1429. shapeArgs.height *= -1;
  1430. }
  1431. point.plotY = shapeArgs.y = mathRound(shapeArgs.y) - (series.borderWidth % 2) / 2;
  1432. shapeArgs.height = mathMax(mathRound(shapeArgs.height), 0.001); // #3151
  1433. point.yBottom = shapeArgs.y + shapeArgs.height;
  1434. // Correct tooltip placement (#3014)
  1435. tooltipY = point.plotY + (point.negative ? shapeArgs.height : 0);
  1436. if (series.chart.inverted) {
  1437. point.tooltipPos[0] = yAxis.len - tooltipY;
  1438. } else {
  1439. point.tooltipPos[1] = tooltipY;
  1440. }
  1441. }
  1442. },
  1443. /**
  1444. * Call default processData then override yData to reflect waterfall's extremes on yAxis
  1445. */
  1446. processData: function (force) {
  1447. var series = this,
  1448. options = series.options,
  1449. yData = series.yData,
  1450. points = series.options.data, // #3710 Update point does not propagate to sum
  1451. point,
  1452. dataLength = yData.length,
  1453. threshold = options.threshold || 0,
  1454. subSum,
  1455. sum,
  1456. dataMin,
  1457. dataMax,
  1458. y,
  1459. i;
  1460. sum = subSum = dataMin = dataMax = threshold;
  1461. for (i = 0; i < dataLength; i++) {
  1462. y = yData[i];
  1463. point = points && points[i] ? points[i] : {};
  1464. if (y === "sum" || point.isSum) {
  1465. yData[i] = sum;
  1466. } else if (y === "intermediateSum" || point.isIntermediateSum) {
  1467. yData[i] = subSum;
  1468. } else {
  1469. sum += y;
  1470. subSum += y;
  1471. }
  1472. dataMin = Math.min(sum, dataMin);
  1473. dataMax = Math.max(sum, dataMax);
  1474. }
  1475. Series.prototype.processData.call(this, force);
  1476. // Record extremes
  1477. series.dataMin = dataMin;
  1478. series.dataMax = dataMax;
  1479. },
  1480. /**
  1481. * Return y value or string if point is sum
  1482. */
  1483. toYData: function (pt) {
  1484. if (pt.isSum) {
  1485. return (pt.x === 0 ? null : "sum"); //#3245 Error when first element is Sum or Intermediate Sum
  1486. } else if (pt.isIntermediateSum) {
  1487. return (pt.x === 0 ? null : "intermediateSum"); //#3245
  1488. }
  1489. return pt.y;
  1490. },
  1491. /**
  1492. * Postprocess mapping between options and SVG attributes
  1493. */
  1494. getAttribs: function () {
  1495. seriesTypes.column.prototype.getAttribs.apply(this, arguments);
  1496. var series = this,
  1497. options = series.options,
  1498. stateOptions = options.states,
  1499. upColor = options.upColor || series.color,
  1500. hoverColor = Highcharts.Color(upColor).brighten(0.1).get(),
  1501. seriesDownPointAttr = merge(series.pointAttr),
  1502. upColorProp = series.upColorProp;
  1503. seriesDownPointAttr[''][upColorProp] = upColor;
  1504. seriesDownPointAttr.hover[upColorProp] = stateOptions.hover.upColor || hoverColor;
  1505. seriesDownPointAttr.select[upColorProp] = stateOptions.select.upColor || upColor;
  1506. each(series.points, function (point) {
  1507. if (!point.options.color) {
  1508. // Up color
  1509. if (point.y > 0) {
  1510. point.pointAttr = seriesDownPointAttr;
  1511. point.color = upColor;
  1512. // Down color (#3710, update to negative)
  1513. } else {
  1514. point.pointAttr = series.pointAttr;
  1515. }
  1516. }
  1517. });
  1518. },
  1519. /**
  1520. * Draw columns' connector lines
  1521. */
  1522. getGraphPath: function () {
  1523. var data = this.data,
  1524. length = data.length,
  1525. lineWidth = this.options.lineWidth + this.borderWidth,
  1526. normalizer = mathRound(lineWidth) % 2 / 2,
  1527. path = [],
  1528. M = 'M',
  1529. L = 'L',
  1530. prevArgs,
  1531. pointArgs,
  1532. i,
  1533. d;
  1534. for (i = 1; i < length; i++) {
  1535. pointArgs = data[i].shapeArgs;
  1536. prevArgs = data[i - 1].shapeArgs;
  1537. d = [
  1538. M,
  1539. prevArgs.x + prevArgs.width, prevArgs.y + normalizer,
  1540. L,
  1541. pointArgs.x, prevArgs.y + normalizer
  1542. ];
  1543. if (data[i - 1].y < 0) {
  1544. d[2] += prevArgs.height;
  1545. d[5] += prevArgs.height;
  1546. }
  1547. path = path.concat(d);
  1548. }
  1549. return path;
  1550. },
  1551. /**
  1552. * Extremes are recorded in processData
  1553. */
  1554. getExtremes: noop,
  1555. drawGraph: Series.prototype.drawGraph
  1556. });
  1557. /* ****************************************************************************
  1558. * End Waterfall series code *
  1559. *****************************************************************************/
  1560. /**
  1561. * Set the default options for polygon
  1562. */
  1563. defaultPlotOptions.polygon = merge(defaultPlotOptions.scatter, {
  1564. marker: {
  1565. enabled: false
  1566. }
  1567. });
  1568. /**
  1569. * The polygon series class
  1570. */
  1571. seriesTypes.polygon = extendClass(seriesTypes.scatter, {
  1572. type: 'polygon',
  1573. fillGraph: true,
  1574. // Close all segments
  1575. getSegmentPath: function (segment) {
  1576. return Series.prototype.getSegmentPath.call(this, segment).concat('z');
  1577. },
  1578. drawGraph: Series.prototype.drawGraph,
  1579. drawLegendSymbol: Highcharts.LegendSymbolMixin.drawRectangle
  1580. });
  1581. /* ****************************************************************************
  1582. * Start Bubble series code *
  1583. *****************************************************************************/
  1584. // 1 - set default options
  1585. defaultPlotOptions.bubble = merge(defaultPlotOptions.scatter, {
  1586. dataLabels: {
  1587. formatter: function () { // #2945
  1588. return this.point.z;
  1589. },
  1590. inside: true,
  1591. verticalAlign: 'middle'
  1592. },
  1593. // displayNegative: true,
  1594. marker: {
  1595. // fillOpacity: 0.5,
  1596. lineColor: null, // inherit from series.color
  1597. lineWidth: 1
  1598. },
  1599. minSize: 8,
  1600. maxSize: '20%',
  1601. // negativeColor: null,
  1602. // sizeBy: 'area'
  1603. states: {
  1604. hover: {
  1605. halo: {
  1606. size: 5
  1607. }
  1608. }
  1609. },
  1610. tooltip: {
  1611. pointFormat: '({point.x}, {point.y}), Size: {point.z}'
  1612. },
  1613. turboThreshold: 0,
  1614. zThreshold: 0,
  1615. zoneAxis: 'z'
  1616. });
  1617. var BubblePoint = extendClass(Point, {
  1618. haloPath: function () {
  1619. return Point.prototype.haloPath.call(this, this.shapeArgs.r + this.series.options.states.hover.halo.size);
  1620. },
  1621. ttBelow: false
  1622. });
  1623. // 2 - Create the series object
  1624. seriesTypes.bubble = extendClass(seriesTypes.scatter, {
  1625. type: 'bubble',
  1626. pointClass: BubblePoint,
  1627. pointArrayMap: ['y', 'z'],
  1628. parallelArrays: ['x', 'y', 'z'],
  1629. trackerGroups: ['group', 'dataLabelsGroup'],
  1630. bubblePadding: true,
  1631. zoneAxis: 'z',
  1632. /**
  1633. * Mapping between SVG attributes and the corresponding options
  1634. */
  1635. pointAttrToOptions: {
  1636. stroke: 'lineColor',
  1637. 'stroke-width': 'lineWidth',
  1638. fill: 'fillColor'
  1639. },
  1640. /**
  1641. * Apply the fillOpacity to all fill positions
  1642. */
  1643. applyOpacity: function (fill) {
  1644. var markerOptions = this.options.marker,
  1645. fillOpacity = pick(markerOptions.fillOpacity, 0.5);
  1646. // When called from Legend.colorizeItem, the fill isn't predefined
  1647. fill = fill || markerOptions.fillColor || this.color;
  1648. if (fillOpacity !== 1) {
  1649. fill = Color(fill).setOpacity(fillOpacity).get('rgba');
  1650. }
  1651. return fill;
  1652. },
  1653. /**
  1654. * Extend the convertAttribs method by applying opacity to the fill
  1655. */
  1656. convertAttribs: function () {
  1657. var obj = Series.prototype.convertAttribs.apply(this, arguments);
  1658. obj.fill = this.applyOpacity(obj.fill);
  1659. return obj;
  1660. },
  1661. /**
  1662. * Get the radius for each point based on the minSize, maxSize and each point's Z value. This
  1663. * must be done prior to Series.translate because the axis needs to add padding in
  1664. * accordance with the point sizes.
  1665. */
  1666. getRadii: function (zMin, zMax, minSize, maxSize) {
  1667. var len,
  1668. i,
  1669. pos,
  1670. zData = this.zData,
  1671. radii = [],
  1672. sizeByArea = this.options.sizeBy !== 'width',
  1673. zRange = zMax - zMin;
  1674. // Set the shape type and arguments to be picked up in drawPoints
  1675. for (i = 0, len = zData.length; i < len; i++) {
  1676. // Issue #4419 - if value is less than zMin, push a radius that's always smaller than the minimum size
  1677. if (zData[i] < zMin) {
  1678. radii.push(minSize / 2 - 1);
  1679. } else {
  1680. // Relative size, a number between 0 and 1
  1681. pos = zRange > 0 ? (zData[i] - zMin) / zRange : 0.5;
  1682. if (sizeByArea && pos >= 0) {
  1683. pos = Math.sqrt(pos);
  1684. }
  1685. radii.push(math.ceil(minSize + pos * (maxSize - minSize)) / 2);
  1686. }
  1687. }
  1688. this.radii = radii;
  1689. },
  1690. /**
  1691. * Perform animation on the bubbles
  1692. */
  1693. animate: function (init) {
  1694. var animation = this.options.animation;
  1695. if (!init) { // run the animation
  1696. each(this.points, function (point) {
  1697. var graphic = point.graphic,
  1698. shapeArgs = point.shapeArgs;
  1699. if (graphic && shapeArgs) {
  1700. // start values
  1701. graphic.attr('r', 1);
  1702. // animate
  1703. graphic.animate({
  1704. r: shapeArgs.r
  1705. }, animation);
  1706. }
  1707. });
  1708. // delete this function to allow it only once
  1709. this.animate = null;
  1710. }
  1711. },
  1712. /**
  1713. * Extend the base translate method to handle bubble size
  1714. */
  1715. translate: function () {
  1716. var i,
  1717. data = this.data,
  1718. point,
  1719. radius,
  1720. radii = this.radii;
  1721. // Run the parent method
  1722. seriesTypes.scatter.prototype.translate.call(this);
  1723. // Set the shape type and arguments to be picked up in drawPoints
  1724. i = data.length;
  1725. while (i--) {
  1726. point = data[i];
  1727. radius = radii ? radii[i] : 0; // #1737
  1728. if (radius >= this.minPxSize / 2) {
  1729. // Shape arguments
  1730. point.shapeType = 'circle';
  1731. point.shapeArgs = {
  1732. x: point.plotX,
  1733. y: point.plotY,
  1734. r: radius
  1735. };
  1736. // Alignment box for the data label
  1737. point.dlBox = {
  1738. x: point.plotX - radius,
  1739. y: point.plotY - radius,
  1740. width: 2 * radius,
  1741. height: 2 * radius
  1742. };
  1743. } else { // below zThreshold
  1744. point.shapeArgs = point.plotY = point.dlBox = UNDEFINED; // #1691
  1745. }
  1746. }
  1747. },
  1748. /**
  1749. * Get the series' symbol in the legend
  1750. *
  1751. * @param {Object} legend The legend object
  1752. * @param {Object} item The series (this) or point
  1753. */
  1754. drawLegendSymbol: function (legend, item) {
  1755. var radius = pInt(legend.itemStyle.fontSize) / 2;
  1756. item.legendSymbol = this.chart.renderer.circle(
  1757. radius,
  1758. legend.baseline - radius,
  1759. radius
  1760. ).attr({
  1761. zIndex: 3
  1762. }).add(item.legendGroup);
  1763. item.legendSymbol.isMarker = true;
  1764. },
  1765. drawPoints: seriesTypes.column.prototype.drawPoints,
  1766. alignDataLabel: seriesTypes.column.prototype.alignDataLabel,
  1767. buildKDTree: noop,
  1768. applyZones: noop
  1769. });
  1770. /**
  1771. * Add logic to pad each axis with the amount of pixels
  1772. * necessary to avoid the bubbles to overflow.
  1773. */
  1774. Axis.prototype.beforePadding = function () {
  1775. var axis = this,
  1776. axisLength = this.len,
  1777. chart = this.chart,
  1778. pxMin = 0,
  1779. pxMax = axisLength,
  1780. isXAxis = this.isXAxis,
  1781. dataKey = isXAxis ? 'xData' : 'yData',
  1782. min = this.min,
  1783. extremes = {},
  1784. smallestSize = math.min(chart.plotWidth, chart.plotHeight),
  1785. zMin = Number.MAX_VALUE,
  1786. zMax = -Number.MAX_VALUE,
  1787. range = this.max - min,
  1788. transA = axisLength / range,
  1789. activeSeries = [];
  1790. // Handle padding on the second pass, or on redraw
  1791. each(this.series, function (series) {
  1792. var seriesOptions = series.options,
  1793. zData;
  1794. if (series.bubblePadding && (series.visible || !chart.options.chart.ignoreHiddenSeries)) {
  1795. // Correction for #1673
  1796. axis.allowZoomOutside = true;
  1797. // Cache it
  1798. activeSeries.push(series);
  1799. if (isXAxis) { // because X axis is evaluated first
  1800. // For each series, translate the size extremes to pixel values
  1801. each(['minSize', 'maxSize'], function (prop) {
  1802. var length = seriesOptions[prop],
  1803. isPercent = /%$/.test(length);
  1804. length = pInt(length);
  1805. extremes[prop] = isPercent ?
  1806. smallestSize * length / 100 :
  1807. length;
  1808. });
  1809. series.minPxSize = extremes.minSize;
  1810. series.maxPxSize = extremes.maxSize;
  1811. // Find the min and max Z
  1812. zData = series.zData;
  1813. if (zData.length) { // #1735
  1814. zMin = pick(seriesOptions.zMin, math.min(
  1815. zMin,
  1816. math.max(
  1817. arrayMin(zData),
  1818. seriesOptions.displayNegative === false ? seriesOptions.zThreshold : -Number.MAX_VALUE
  1819. )
  1820. ));
  1821. zMax = pick(seriesOptions.zMax, math.max(zMax, arrayMax(zData)));
  1822. }
  1823. }
  1824. }
  1825. });
  1826. each(activeSeries, function (series) {
  1827. var data = series[dataKey],
  1828. i = data.length,
  1829. radius;
  1830. if (isXAxis) {
  1831. series.getRadii(zMin, zMax, series.minPxSize, series.maxPxSize);
  1832. }
  1833. if (range > 0) {
  1834. while (i--) {
  1835. if (typeof data[i] === 'number') {
  1836. radius = series.radii[i];
  1837. pxMin = Math.min(((data[i] - min) * transA) - radius, pxMin);
  1838. pxMax = Math.max(((data[i] - min) * transA) + radius, pxMax);
  1839. }
  1840. }
  1841. }
  1842. });
  1843. if (activeSeries.length && range > 0 && !this.isLog) {
  1844. pxMax -= axisLength;
  1845. transA *= (axisLength + pxMin - pxMax) / axisLength;
  1846. each([['min', 'userMin', pxMin], ['max', 'userMax', pxMax]], function (keys) {
  1847. if (pick(axis.options[keys[0]], axis[keys[1]]) === UNDEFINED) {
  1848. axis[keys[0]] += keys[2] / transA;
  1849. }
  1850. });
  1851. }
  1852. };
  1853. /* ****************************************************************************
  1854. * End Bubble series code *
  1855. *****************************************************************************/
  1856. (function () {
  1857. /**
  1858. * Extensions for polar charts. Additionally, much of the geometry required for polar charts is
  1859. * gathered in RadialAxes.js.
  1860. *
  1861. */
  1862. var seriesProto = Series.prototype,
  1863. pointerProto = Pointer.prototype,
  1864. colProto;
  1865. /**
  1866. * Search a k-d tree by the point angle, used for shared tooltips in polar charts
  1867. */
  1868. seriesProto.searchPointByAngle = function (e) {
  1869. var series = this,
  1870. chart = series.chart,
  1871. xAxis = series.xAxis,
  1872. center = xAxis.pane.center,
  1873. plotX = e.chartX - center[0] - chart.plotLeft,
  1874. plotY = e.chartY - center[1] - chart.plotTop;
  1875. return this.searchKDTree({
  1876. clientX: 180 + (Math.atan2(plotX, plotY) * (-180 / Math.PI))
  1877. });
  1878. };
  1879. /**
  1880. * Wrap the buildKDTree function so that it searches by angle (clientX) in case of shared tooltip,
  1881. * and by two dimensional distance in case of non-shared.
  1882. */
  1883. wrap(seriesProto, 'buildKDTree', function (proceed) {
  1884. if (this.chart.polar) {
  1885. if (this.kdByAngle) {
  1886. this.searchPoint = this.searchPointByAngle;
  1887. } else {
  1888. this.kdDimensions = 2;
  1889. }
  1890. }
  1891. proceed.apply(this);
  1892. });
  1893. /**
  1894. * Translate a point's plotX and plotY from the internal angle and radius measures to
  1895. * true plotX, plotY coordinates
  1896. */
  1897. seriesProto.toXY = function (point) {
  1898. var xy,
  1899. chart = this.chart,
  1900. plotX = point.plotX,
  1901. plotY = point.plotY,
  1902. clientX;
  1903. // Save rectangular plotX, plotY for later computation
  1904. point.rectPlotX = plotX;
  1905. point.rectPlotY = plotY;
  1906. // Find the polar plotX and plotY
  1907. xy = this.xAxis.postTranslate(point.plotX, this.yAxis.len - plotY);
  1908. point.plotX = point.polarPlotX = xy.x - chart.plotLeft;
  1909. point.plotY = point.polarPlotY = xy.y - chart.plotTop;
  1910. // If shared tooltip, record the angle in degrees in order to align X points. Otherwise,
  1911. // use a standard k-d tree to get the nearest point in two dimensions.
  1912. if (this.kdByAngle) {
  1913. clientX = ((plotX / Math.PI * 180) + this.xAxis.pane.options.startAngle) % 360;
  1914. if (clientX < 0) { // #2665
  1915. clientX += 360;
  1916. }
  1917. point.clientX = clientX;
  1918. } else {
  1919. point.clientX = point.plotX;
  1920. }
  1921. };
  1922. /**
  1923. * Add some special init logic to areas and areasplines
  1924. */
  1925. function initArea(proceed, chart, options) {
  1926. proceed.call(this, chart, options);
  1927. if (this.chart.polar) {
  1928. /**
  1929. * Overridden method to close a segment path. While in a cartesian plane the area
  1930. * goes down to the threshold, in the polar chart it goes to the center.
  1931. */
  1932. this.closeSegment = function (path) {
  1933. var center = this.xAxis.center;
  1934. path.push(
  1935. 'L',
  1936. center[0],
  1937. center[1]
  1938. );
  1939. };
  1940. // Instead of complicated logic to draw an area around the inner area in a stack,
  1941. // just draw it behind
  1942. this.closedStacks = true;
  1943. }
  1944. }
  1945. if (seriesTypes.area) {
  1946. wrap(seriesTypes.area.prototype, 'init', initArea);
  1947. }
  1948. if (seriesTypes.areaspline) {
  1949. wrap(seriesTypes.areaspline.prototype, 'init', initArea);
  1950. }
  1951. if (seriesTypes.spline) {
  1952. /**
  1953. * Overridden method for calculating a spline from one point to the next
  1954. */
  1955. wrap(seriesTypes.spline.prototype, 'getPointSpline', function (proceed, segment, point, i) {
  1956. var ret,
  1957. smoothing = 1.5, // 1 means control points midway between points, 2 means 1/3 from the point, 3 is 1/4 etc;
  1958. denom = smoothing + 1,
  1959. plotX,
  1960. plotY,
  1961. lastPoint,
  1962. nextPoint,
  1963. lastX,
  1964. lastY,
  1965. nextX,
  1966. nextY,
  1967. leftContX,
  1968. leftContY,
  1969. rightContX,
  1970. rightContY,
  1971. distanceLeftControlPoint,
  1972. distanceRightControlPoint,
  1973. leftContAngle,
  1974. rightContAngle,
  1975. jointAngle;
  1976. if (this.chart.polar) {
  1977. plotX = point.plotX;
  1978. plotY = point.plotY;
  1979. lastPoint = segment[i - 1];
  1980. nextPoint = segment[i + 1];
  1981. // Connect ends
  1982. if (this.connectEnds) {
  1983. if (!lastPoint) {
  1984. lastPoint = segment[segment.length - 2]; // not the last but the second last, because the segment is already connected
  1985. }
  1986. if (!nextPoint) {
  1987. nextPoint = segment[1];
  1988. }
  1989. }
  1990. // find control points
  1991. if (lastPoint && nextPoint) {
  1992. lastX = lastPoint.plotX;
  1993. lastY = lastPoint.plotY;
  1994. nextX = nextPoint.plotX;
  1995. nextY = nextPoint.plotY;
  1996. leftContX = (smoothing * plotX + lastX) / denom;
  1997. leftContY = (smoothing * plotY + lastY) / denom;
  1998. rightContX = (smoothing * plotX + nextX) / denom;
  1999. rightContY = (smoothing * plotY + nextY) / denom;
  2000. distanceLeftControlPoint = Math.sqrt(Math.pow(leftContX - plotX, 2) + Math.pow(leftContY - plotY, 2));
  2001. distanceRightControlPoint = Math.sqrt(Math.pow(rightContX - plotX, 2) + Math.pow(rightContY - plotY, 2));
  2002. leftContAngle = Math.atan2(leftContY - plotY, leftContX - plotX);
  2003. rightContAngle = Math.atan2(rightContY - plotY, rightContX - plotX);
  2004. jointAngle = (Math.PI / 2) + ((leftContAngle + rightContAngle) / 2);
  2005. // Ensure the right direction, jointAngle should be in the same quadrant as leftContAngle
  2006. if (Math.abs(leftContAngle - jointAngle) > Math.PI / 2) {
  2007. jointAngle -= Math.PI;
  2008. }
  2009. // Find the corrected control points for a spline straight through the point
  2010. leftContX = plotX + Math.cos(jointAngle) * distanceLeftControlPoint;
  2011. leftContY = plotY + Math.sin(jointAngle) * distanceLeftControlPoint;
  2012. rightContX = plotX + Math.cos(Math.PI + jointAngle) * distanceRightControlPoint;
  2013. rightContY = plotY + Math.sin(Math.PI + jointAngle) * distanceRightControlPoint;
  2014. // Record for drawing in next point
  2015. point.rightContX = rightContX;
  2016. point.rightContY = rightContY;
  2017. }
  2018. // moveTo or lineTo
  2019. if (!i) {
  2020. ret = ['M', plotX, plotY];
  2021. } else { // curve from last point to this
  2022. ret = [
  2023. 'C',
  2024. lastPoint.rightContX || lastPoint.plotX,
  2025. lastPoint.rightContY || lastPoint.plotY,
  2026. leftContX || plotX,
  2027. leftContY || plotY,
  2028. plotX,
  2029. plotY
  2030. ];
  2031. lastPoint.rightContX = lastPoint.rightContY = null; // reset for updating series later
  2032. }
  2033. } else {
  2034. ret = proceed.call(this, segment, point, i);
  2035. }
  2036. return ret;
  2037. });
  2038. }
  2039. /**
  2040. * Extend translate. The plotX and plotY values are computed as if the polar chart were a
  2041. * cartesian plane, where plotX denotes the angle in radians and (yAxis.len - plotY) is the pixel distance from
  2042. * center.
  2043. */
  2044. wrap(seriesProto, 'translate', function (proceed) {
  2045. var chart = this.chart,
  2046. points,
  2047. i;
  2048. // Run uber method
  2049. proceed.call(this);
  2050. // Postprocess plot coordinates
  2051. if (chart.polar) {
  2052. this.kdByAngle = chart.tooltip && chart.tooltip.shared;
  2053. if (!this.preventPostTranslate) {
  2054. points = this.points;
  2055. i = points.length;
  2056. while (i--) {
  2057. // Translate plotX, plotY from angle and radius to true plot coordinates
  2058. this.toXY(points[i]);
  2059. }
  2060. }
  2061. }
  2062. });
  2063. /**
  2064. * Extend getSegmentPath to allow connecting ends across 0 to provide a closed circle in
  2065. * line-like series.
  2066. */
  2067. wrap(seriesProto, 'getSegmentPath', function (proceed, segment) {
  2068. var points = this.points;
  2069. // Connect the path
  2070. if (this.chart.polar && this.options.connectEnds !== false &&
  2071. segment[segment.length - 1] === points[points.length - 1] && points[0].y !== null) {
  2072. this.connectEnds = true; // re-used in splines
  2073. segment = [].concat(segment, [points[0]]);
  2074. }
  2075. // Run uber method
  2076. return proceed.call(this, segment);
  2077. });
  2078. function polarAnimate(proceed, init) {
  2079. var chart = this.chart,
  2080. animation = this.options.animation,
  2081. group = this.group,
  2082. markerGroup = this.markerGroup,
  2083. center = this.xAxis.center,
  2084. plotLeft = chart.plotLeft,
  2085. plotTop = chart.plotTop,
  2086. attribs;
  2087. // Specific animation for polar charts
  2088. if (chart.polar) {
  2089. // Enable animation on polar charts only in SVG. In VML, the scaling is different, plus animation
  2090. // would be so slow it would't matter.
  2091. if (chart.renderer.isSVG) {
  2092. if (animation === true) {
  2093. animation = {};
  2094. }
  2095. // Initialize the animation
  2096. if (init) {
  2097. // Scale down the group and place it in the center
  2098. attribs = {
  2099. translateX: center[0] + plotLeft,
  2100. translateY: center[1] + plotTop,
  2101. scaleX: 0.001, // #1499
  2102. scaleY: 0.001
  2103. };
  2104. group.attr(attribs);
  2105. if (markerGroup) {
  2106. //markerGroup.attrSetters = group.attrSetters;
  2107. markerGroup.attr(attribs);
  2108. }
  2109. // Run the animation
  2110. } else {
  2111. attribs = {
  2112. translateX: plotLeft,
  2113. translateY: plotTop,
  2114. scaleX: 1,
  2115. scaleY: 1
  2116. };
  2117. group.animate(attribs, animation);
  2118. if (markerGroup) {
  2119. markerGroup.animate(attribs, animation);
  2120. }
  2121. // Delete this function to allow it only once
  2122. this.animate = null;
  2123. }
  2124. }
  2125. // For non-polar charts, revert to the basic animation
  2126. } else {
  2127. proceed.call(this, init);
  2128. }
  2129. }
  2130. // Define the animate method for regular series
  2131. wrap(seriesProto, 'animate', polarAnimate);
  2132. if (seriesTypes.column) {
  2133. colProto = seriesTypes.column.prototype;
  2134. /**
  2135. * Define the animate method for columnseries
  2136. */
  2137. wrap(colProto, 'animate', polarAnimate);
  2138. /**
  2139. * Extend the column prototype's translate method
  2140. */
  2141. wrap(colProto, 'translate', function (proceed) {
  2142. var xAxis = this.xAxis,
  2143. len = this.yAxis.len,
  2144. center = xAxis.center,
  2145. startAngleRad = xAxis.startAngleRad,
  2146. renderer = this.chart.renderer,
  2147. start,
  2148. points,
  2149. point,
  2150. i;
  2151. this.preventPostTranslate = true;
  2152. // Run uber method
  2153. proceed.call(this);
  2154. // Postprocess plot coordinates
  2155. if (xAxis.isRadial) {
  2156. points = this.points;
  2157. i = points.length;
  2158. while (i--) {
  2159. point = points[i];
  2160. start = point.barX + startAngleRad;
  2161. point.shapeType = 'path';
  2162. point.shapeArgs = {
  2163. d: renderer.symbols.arc(
  2164. center[0],
  2165. center[1],
  2166. len - point.plotY,
  2167. null,
  2168. {
  2169. start: start,
  2170. end: start + point.pointWidth,
  2171. innerR: len - pick(point.yBottom, len)
  2172. }
  2173. )
  2174. };
  2175. // Provide correct plotX, plotY for tooltip
  2176. this.toXY(point);
  2177. point.tooltipPos = [point.plotX, point.plotY];
  2178. point.ttBelow = point.plotY > center[1];
  2179. }
  2180. }
  2181. });
  2182. /**
  2183. * Align column data labels outside the columns. #1199.
  2184. */
  2185. wrap(colProto, 'alignDataLabel', function (proceed, point, dataLabel, options, alignTo, isNew) {
  2186. if (this.chart.polar) {
  2187. var angle = point.rectPlotX / Math.PI * 180,
  2188. align,
  2189. verticalAlign;
  2190. // Align nicely outside the perimeter of the columns
  2191. if (options.align === null) {
  2192. if (angle > 20 && angle < 160) {
  2193. align = 'left'; // right hemisphere
  2194. } else if (angle > 200 && angle < 340) {
  2195. align = 'right'; // left hemisphere
  2196. } else {
  2197. align = 'center'; // top or bottom
  2198. }
  2199. options.align = align;
  2200. }
  2201. if (options.verticalAlign === null) {
  2202. if (angle < 45 || angle > 315) {
  2203. verticalAlign = 'bottom'; // top part
  2204. } else if (angle > 135 && angle < 225) {
  2205. verticalAlign = 'top'; // bottom part
  2206. } else {
  2207. verticalAlign = 'middle'; // left or right
  2208. }
  2209. options.verticalAlign = verticalAlign;
  2210. }
  2211. seriesProto.alignDataLabel.call(this, point, dataLabel, options, alignTo, isNew);
  2212. } else {
  2213. proceed.call(this, point, dataLabel, options, alignTo, isNew);
  2214. }
  2215. });
  2216. }
  2217. /**
  2218. * Extend getCoordinates to prepare for polar axis values
  2219. */
  2220. wrap(pointerProto, 'getCoordinates', function (proceed, e) {
  2221. var chart = this.chart,
  2222. ret = {
  2223. xAxis: [],
  2224. yAxis: []
  2225. };
  2226. if (chart.polar) {
  2227. each(chart.axes, function (axis) {
  2228. var isXAxis = axis.isXAxis,
  2229. center = axis.center,
  2230. x = e.chartX - center[0] - chart.plotLeft,
  2231. y = e.chartY - center[1] - chart.plotTop;
  2232. ret[isXAxis ? 'xAxis' : 'yAxis'].push({
  2233. axis: axis,
  2234. value: axis.translate(
  2235. isXAxis ?
  2236. Math.PI - Math.atan2(x, y) : // angle
  2237. Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)), // distance from center
  2238. true
  2239. )
  2240. });
  2241. });
  2242. } else {
  2243. ret = proceed.call(this, e);
  2244. }
  2245. return ret;
  2246. });
  2247. }());
  2248. }(Highcharts));