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.

2430 lines
59 KiB

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