纽威
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.

2520 lines
62 KiB

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