選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

2651 行
66 KiB

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