ColumnSeries.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. /* *
  2. *
  3. * (c) 2010-2021 Torstein Honsi
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8. *
  9. * */
  10. 'use strict';
  11. var __extends = (this && this.__extends) || (function () {
  12. var extendStatics = function (d, b) {
  13. extendStatics = Object.setPrototypeOf ||
  14. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  15. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  16. return extendStatics(d, b);
  17. };
  18. return function (d, b) {
  19. extendStatics(d, b);
  20. function __() { this.constructor = d; }
  21. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  22. };
  23. })();
  24. import A from '../../Core/Animation/AnimationUtilities.js';
  25. var animObject = A.animObject;
  26. import Color from '../../Core/Color/Color.js';
  27. var color = Color.parse;
  28. import H from '../../Core/Globals.js';
  29. var hasTouch = H.hasTouch, noop = H.noop;
  30. import LegendSymbolMixin from '../../Mixins/LegendSymbol.js';
  31. import palette from '../../Core/Color/Palette.js';
  32. import Series from '../../Core/Series/Series.js';
  33. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  34. import U from '../../Core/Utilities.js';
  35. var clamp = U.clamp, css = U.css, defined = U.defined, extend = U.extend, fireEvent = U.fireEvent, isArray = U.isArray, isNumber = U.isNumber, merge = U.merge, pick = U.pick, objectEach = U.objectEach;
  36. /**
  37. * The column series type.
  38. *
  39. * @private
  40. * @class
  41. * @name Highcharts.seriesTypes.column
  42. *
  43. * @augments Highcharts.Series
  44. */
  45. var ColumnSeries = /** @class */ (function (_super) {
  46. __extends(ColumnSeries, _super);
  47. function ColumnSeries() {
  48. /* *
  49. *
  50. * Static Properties
  51. *
  52. * */
  53. var _this = _super !== null && _super.apply(this, arguments) || this;
  54. /* *
  55. *
  56. * Properties
  57. *
  58. * */
  59. _this.borderWidth = void 0;
  60. _this.data = void 0;
  61. _this.group = void 0;
  62. _this.options = void 0;
  63. _this.points = void 0;
  64. return _this;
  65. /* eslint-enable valid-jsdoc */
  66. }
  67. /* *
  68. *
  69. * Functions
  70. *
  71. * */
  72. /* eslint-disable valid-jsdoc */
  73. /**
  74. * Animate the column heights one by one from zero.
  75. *
  76. * @private
  77. * @function Highcharts.seriesTypes.column#animate
  78. *
  79. * @param {boolean} init
  80. * Whether to initialize the animation or run it
  81. */
  82. ColumnSeries.prototype.animate = function (init) {
  83. var series = this, yAxis = this.yAxis, options = series.options, inverted = this.chart.inverted, attr = {}, translateProp = inverted ? 'translateX' : 'translateY', translateStart, translatedThreshold;
  84. if (init) {
  85. attr.scaleY = 0.001;
  86. translatedThreshold = clamp(yAxis.toPixels(options.threshold), yAxis.pos, yAxis.pos + yAxis.len);
  87. if (inverted) {
  88. attr.translateX = translatedThreshold - yAxis.len;
  89. }
  90. else {
  91. attr.translateY = translatedThreshold;
  92. }
  93. // apply finnal clipping (used in Highcharts Stock) (#7083)
  94. // animation is done by scaleY, so cliping is for panes
  95. if (series.clipBox) {
  96. series.setClip();
  97. }
  98. series.group.attr(attr);
  99. }
  100. else { // run the animation
  101. translateStart = Number(series.group.attr(translateProp));
  102. series.group.animate({ scaleY: 1 }, extend(animObject(series.options.animation), {
  103. // Do the scale synchronously to ensure smooth
  104. // updating (#5030, #7228)
  105. step: function (val, fx) {
  106. if (series.group) {
  107. attr[translateProp] = translateStart +
  108. fx.pos * (yAxis.pos - translateStart);
  109. series.group.attr(attr);
  110. }
  111. }
  112. }));
  113. }
  114. };
  115. /**
  116. * Initialize the series. Extends the basic Series.init method by
  117. * marking other series of the same type as dirty.
  118. *
  119. * @private
  120. * @function Highcharts.seriesTypes.column#init
  121. */
  122. ColumnSeries.prototype.init = function (chart, options) {
  123. _super.prototype.init.apply(this, arguments);
  124. var series = this;
  125. chart = series.chart;
  126. // if the series is added dynamically, force redraw of other
  127. // series affected by a new column
  128. if (chart.hasRendered) {
  129. chart.series.forEach(function (otherSeries) {
  130. if (otherSeries.type === series.type) {
  131. otherSeries.isDirty = true;
  132. }
  133. });
  134. }
  135. };
  136. /**
  137. * Return the width and x offset of the columns adjusted for grouping,
  138. * groupPadding, pointPadding, pointWidth etc.
  139. *
  140. * @private
  141. * @function Highcharts.seriesTypes.column#getColumnMetrics
  142. * @return {Highcharts.ColumnMetricsObject}
  143. */
  144. ColumnSeries.prototype.getColumnMetrics = function () {
  145. var series = this, options = series.options, xAxis = series.xAxis, yAxis = series.yAxis, reversedStacks = xAxis.options.reversedStacks,
  146. // Keep backward compatibility: reversed xAxis had reversed
  147. // stacks
  148. reverseStacks = (xAxis.reversed && !reversedStacks) ||
  149. (!xAxis.reversed && reversedStacks), stackKey, stackGroups = {}, columnCount = 0;
  150. // Get the total number of column type series. This is called on
  151. // every series. Consider moving this logic to a chart.orderStacks()
  152. // function and call it on init, addSeries and removeSeries
  153. if (options.grouping === false) {
  154. columnCount = 1;
  155. }
  156. else {
  157. series.chart.series.forEach(function (otherSeries) {
  158. var otherYAxis = otherSeries.yAxis, otherOptions = otherSeries.options, columnIndex;
  159. if (otherSeries.type === series.type &&
  160. (otherSeries.visible ||
  161. !series.chart.options.chart.ignoreHiddenSeries) &&
  162. yAxis.len === otherYAxis.len &&
  163. yAxis.pos === otherYAxis.pos) { // #642, #2086
  164. if (otherOptions.stacking && otherOptions.stacking !== 'group') {
  165. stackKey = otherSeries.stackKey;
  166. if (typeof stackGroups[stackKey] ===
  167. 'undefined') {
  168. stackGroups[stackKey] = columnCount++;
  169. }
  170. columnIndex = stackGroups[stackKey];
  171. }
  172. else if (otherOptions.grouping !== false) { // #1162
  173. columnIndex = columnCount++;
  174. }
  175. otherSeries.columnIndex = columnIndex;
  176. }
  177. });
  178. }
  179. var categoryWidth = Math.min(Math.abs(xAxis.transA) * ((xAxis.ordinal && xAxis.ordinal.slope) ||
  180. options.pointRange ||
  181. xAxis.closestPointRange ||
  182. xAxis.tickInterval ||
  183. 1), // #2610
  184. xAxis.len // #1535
  185. ), groupPadding = categoryWidth * options.groupPadding, groupWidth = categoryWidth - 2 * groupPadding, pointOffsetWidth = groupWidth / (columnCount || 1), pointWidth = Math.min(options.maxPointWidth || xAxis.len, pick(options.pointWidth, pointOffsetWidth * (1 - 2 * options.pointPadding))), pointPadding = (pointOffsetWidth - pointWidth) / 2,
  186. // #1251, #3737
  187. colIndex = (series.columnIndex || 0) + (reverseStacks ? 1 : 0), pointXOffset = pointPadding +
  188. (groupPadding +
  189. colIndex * pointOffsetWidth -
  190. (categoryWidth / 2)) * (reverseStacks ? -1 : 1);
  191. // Save it for reading in linked series (Error bars particularly)
  192. series.columnMetrics = {
  193. width: pointWidth,
  194. offset: pointXOffset,
  195. paddedWidth: pointOffsetWidth,
  196. columnCount: columnCount
  197. };
  198. return series.columnMetrics;
  199. };
  200. /**
  201. * Make the columns crisp. The edges are rounded to the nearest full
  202. * pixel.
  203. *
  204. * @private
  205. * @function Highcharts.seriesTypes.column#crispCol
  206. */
  207. ColumnSeries.prototype.crispCol = function (x, y, w, h) {
  208. var chart = this.chart, borderWidth = this.borderWidth, xCrisp = -(borderWidth % 2 ? 0.5 : 0), yCrisp = borderWidth % 2 ? 0.5 : 1, right, bottom, fromTop;
  209. if (chart.inverted && chart.renderer.isVML) {
  210. yCrisp += 1;
  211. }
  212. // Horizontal. We need to first compute the exact right edge, then
  213. // round it and compute the width from there.
  214. if (this.options.crisp) {
  215. right = Math.round(x + w) + xCrisp;
  216. x = Math.round(x) + xCrisp;
  217. w = right - x;
  218. }
  219. // Vertical
  220. bottom = Math.round(y + h) + yCrisp;
  221. fromTop = Math.abs(y) <= 0.5 && bottom > 0.5; // #4504, #4656
  222. y = Math.round(y) + yCrisp;
  223. h = bottom - y;
  224. // Top edges are exceptions
  225. if (fromTop && h) { // #5146
  226. y -= 1;
  227. h += 1;
  228. }
  229. return {
  230. x: x,
  231. y: y,
  232. width: w,
  233. height: h
  234. };
  235. };
  236. /**
  237. * Adjust for missing columns, according to the `centerInCategory`
  238. * option. Missing columns are either single points or stacks where the
  239. * point or points are either missing or null.
  240. *
  241. * @private
  242. * @function Highcharts.seriesTypes.column#adjustForMissingColumns
  243. * @param {number} x
  244. * The x coordinate of the column, left side
  245. *
  246. * @param {number} pointWidth
  247. * The pointWidth, already computed upstream
  248. *
  249. * @param {Highcharts.ColumnPoint} point
  250. * The point instance
  251. *
  252. * @param {Highcharts.ColumnMetricsObject} metrics
  253. * The series-wide column metrics
  254. *
  255. * @return {number}
  256. * The adjusted x position, or the original if not adjusted
  257. */
  258. ColumnSeries.prototype.adjustForMissingColumns = function (x, pointWidth, point, metrics) {
  259. var _this = this;
  260. var stacking = this.options.stacking;
  261. if (!point.isNull && metrics.columnCount > 1) {
  262. var indexInCategory_1 = 0;
  263. var totalInCategory_1 = 0;
  264. // Loop over all the stacks on the Y axis. When stacking is
  265. // enabled, these are real point stacks. When stacking is not
  266. // enabled, but `centerInCategory` is true, there is one stack
  267. // handling the grouping of points in each category. This is
  268. // done in the `setGroupedPoints` function.
  269. objectEach(this.yAxis.stacking && this.yAxis.stacking.stacks, function (stack) {
  270. if (typeof point.x === 'number') {
  271. var stackItem = stack[point.x.toString()];
  272. if (stackItem) {
  273. var pointValues = stackItem.points[_this.index], total = stackItem.total;
  274. // If true `stacking` is enabled, count the
  275. // total number of non-null stacks in the
  276. // category, and note which index this point is
  277. // within those stacks.
  278. if (stacking) {
  279. if (pointValues) {
  280. indexInCategory_1 = totalInCategory_1;
  281. }
  282. if (stackItem.hasValidPoints) {
  283. totalInCategory_1++;
  284. }
  285. // If `stacking` is not enabled, look for the
  286. // index and total of the `group` stack.
  287. }
  288. else if (isArray(pointValues)) {
  289. indexInCategory_1 = pointValues[1];
  290. totalInCategory_1 = total || 0;
  291. }
  292. }
  293. }
  294. });
  295. // Compute the adjusted x position
  296. var boxWidth = (totalInCategory_1 - 1) * metrics.paddedWidth +
  297. pointWidth;
  298. x = (point.plotX || 0) + boxWidth / 2 - pointWidth -
  299. indexInCategory_1 * metrics.paddedWidth;
  300. }
  301. return x;
  302. };
  303. /**
  304. * Translate each point to the plot area coordinate system and find
  305. * shape positions
  306. *
  307. * @private
  308. * @function Highcharts.seriesTypes.column#translate
  309. */
  310. ColumnSeries.prototype.translate = function () {
  311. var series = this, chart = series.chart, options = series.options, dense = series.dense =
  312. series.closestPointRange * series.xAxis.transA < 2, borderWidth = series.borderWidth = pick(options.borderWidth, dense ? 0 : 1 // #3635
  313. ), xAxis = series.xAxis, yAxis = series.yAxis, threshold = options.threshold, translatedThreshold = series.translatedThreshold =
  314. yAxis.getThreshold(threshold), minPointLength = pick(options.minPointLength, 5), metrics = series.getColumnMetrics(), seriesPointWidth = metrics.width,
  315. // postprocessed for border width
  316. seriesBarW = series.barW =
  317. Math.max(seriesPointWidth, 1 + 2 * borderWidth), seriesXOffset = series.pointXOffset = metrics.offset, dataMin = series.dataMin, dataMax = series.dataMax;
  318. if (chart.inverted) {
  319. translatedThreshold -= 0.5; // #3355
  320. }
  321. // When the pointPadding is 0, we want the columns to be packed
  322. // tightly, so we allow individual columns to have individual sizes.
  323. // When pointPadding is greater, we strive for equal-width columns
  324. // (#2694).
  325. if (options.pointPadding) {
  326. seriesBarW = Math.ceil(seriesBarW);
  327. }
  328. Series.prototype.translate.apply(series);
  329. // Record the new values
  330. series.points.forEach(function (point) {
  331. var yBottom = pick(point.yBottom, translatedThreshold), safeDistance = 999 + Math.abs(yBottom), pointWidth = seriesPointWidth, plotX = point.plotX || 0,
  332. // Don't draw too far outside plot area (#1303, #2241,
  333. // #4264)
  334. plotY = clamp(point.plotY, -safeDistance, yAxis.len + safeDistance), barX = plotX + seriesXOffset, barW = seriesBarW, barY = Math.min(plotY, yBottom), up, barH = Math.max(plotY, yBottom) - barY;
  335. // Handle options.minPointLength
  336. if (minPointLength && Math.abs(barH) < minPointLength) {
  337. barH = minPointLength;
  338. up = (!yAxis.reversed && !point.negative) ||
  339. (yAxis.reversed && point.negative);
  340. // Reverse zeros if there's no positive value in the series
  341. // in visible range (#7046)
  342. if (isNumber(threshold) &&
  343. isNumber(dataMax) &&
  344. point.y === threshold &&
  345. dataMax <= threshold &&
  346. // and if there's room for it (#7311)
  347. (yAxis.min || 0) < threshold &&
  348. // if all points are the same value (i.e zero) not draw
  349. // as negative points (#10646), but only if there's room
  350. // for it (#14876)
  351. (dataMin !== dataMax || (yAxis.max || 0) <= threshold)) {
  352. up = !up;
  353. }
  354. // If stacked...
  355. barY = (Math.abs(barY - translatedThreshold) > minPointLength ?
  356. // ...keep position
  357. yBottom - minPointLength :
  358. // #1485, #4051
  359. translatedThreshold -
  360. (up ? minPointLength : 0));
  361. }
  362. // Handle point.options.pointWidth
  363. // @todo Handle grouping/stacking too. Calculate offset properly
  364. if (defined(point.options.pointWidth)) {
  365. pointWidth = barW =
  366. Math.ceil(point.options.pointWidth);
  367. barX -= Math.round((pointWidth - seriesPointWidth) / 2);
  368. }
  369. // Adjust for null or missing points
  370. if (options.centerInCategory) {
  371. barX = series.adjustForMissingColumns(barX, pointWidth, point, metrics);
  372. }
  373. // Cache for access in polar
  374. point.barX = barX;
  375. point.pointWidth = pointWidth;
  376. // Fix the tooltip on center of grouped columns (#1216, #424,
  377. // #3648)
  378. point.tooltipPos = chart.inverted ?
  379. [
  380. clamp(yAxis.len + yAxis.pos - chart.plotLeft - plotY, yAxis.pos - chart.plotLeft, yAxis.len + yAxis.pos - chart.plotLeft),
  381. xAxis.len + xAxis.pos - chart.plotTop - barX - barW / 2,
  382. barH
  383. ] :
  384. [
  385. xAxis.left - chart.plotLeft + barX + barW / 2,
  386. clamp(plotY + yAxis.pos -
  387. chart.plotTop, yAxis.pos - chart.plotTop, yAxis.len + yAxis.pos - chart.plotTop),
  388. barH
  389. ];
  390. // Register shape type and arguments to be used in drawPoints
  391. // Allow shapeType defined on pointClass level
  392. point.shapeType = series.pointClass.prototype.shapeType || 'rect';
  393. point.shapeArgs = series.crispCol.apply(series, point.isNull ?
  394. // #3169, drilldown from null must have a position to work
  395. // from #6585, dataLabel should be placed on xAxis, not
  396. // floating in the middle of the chart
  397. [barX, translatedThreshold, barW, 0] :
  398. [barX, barY, barW, barH]);
  399. });
  400. };
  401. /**
  402. * Columns have no graph
  403. *
  404. * @private
  405. * @function Highcharts.seriesTypes.column#drawGraph
  406. */
  407. ColumnSeries.prototype.drawGraph = function () {
  408. this.group[this.dense ? 'addClass' : 'removeClass']('highcharts-dense-data');
  409. };
  410. /**
  411. * Get presentational attributes
  412. *
  413. * @private
  414. * @function Highcharts.seriesTypes.column#pointAttribs
  415. */
  416. ColumnSeries.prototype.pointAttribs = function (point, state) {
  417. var options = this.options, stateOptions, ret, p2o = this.pointAttrToOptions || {}, strokeOption = p2o.stroke || 'borderColor', strokeWidthOption = p2o['stroke-width'] || 'borderWidth', fill = (point && point.color) || this.color,
  418. // set to fill when borderColor null:
  419. stroke = ((point && point[strokeOption]) ||
  420. options[strokeOption] ||
  421. fill), strokeWidth = (point && point[strokeWidthOption]) ||
  422. options[strokeWidthOption] ||
  423. this[strokeWidthOption] || 0, dashstyle = (point && point.options.dashStyle) || options.dashStyle, opacity = pick(point && point.opacity, options.opacity, 1), zone, brightness;
  424. // Handle zone colors
  425. if (point && this.zones.length) {
  426. zone = point.getZone();
  427. // When zones are present, don't use point.color (#4267).
  428. // Changed order (#6527), added support for colorAxis (#10670)
  429. fill = (point.options.color ||
  430. (zone && (zone.color || point.nonZonedColor)) ||
  431. this.color);
  432. if (zone) {
  433. stroke = zone.borderColor || stroke;
  434. dashstyle = zone.dashStyle || dashstyle;
  435. strokeWidth = zone.borderWidth || strokeWidth;
  436. }
  437. }
  438. // Select or hover states
  439. if (state && point) {
  440. stateOptions = merge(options.states[state],
  441. // #6401
  442. point.options.states &&
  443. point.options.states[state] ||
  444. {});
  445. brightness = stateOptions.brightness;
  446. fill =
  447. stateOptions.color || (typeof brightness !== 'undefined' &&
  448. color(fill)
  449. .brighten(stateOptions.brightness)
  450. .get()) || fill;
  451. stroke = stateOptions[strokeOption] || stroke;
  452. strokeWidth =
  453. stateOptions[strokeWidthOption] || strokeWidth;
  454. dashstyle = stateOptions.dashStyle || dashstyle;
  455. opacity = pick(stateOptions.opacity, opacity);
  456. }
  457. ret = {
  458. fill: fill,
  459. stroke: stroke,
  460. 'stroke-width': strokeWidth,
  461. opacity: opacity
  462. };
  463. if (dashstyle) {
  464. ret.dashstyle = dashstyle;
  465. }
  466. return ret;
  467. };
  468. /**
  469. * Draw the columns. For bars, the series.group is rotated, so the same
  470. * coordinates apply for columns and bars. This method is inherited by
  471. * scatter series.
  472. *
  473. * @private
  474. * @function Highcharts.seriesTypes.column#drawPoints
  475. */
  476. ColumnSeries.prototype.drawPoints = function () {
  477. var series = this, chart = this.chart, options = series.options, renderer = chart.renderer, animationLimit = options.animationLimit || 250, shapeArgs;
  478. // draw the columns
  479. series.points.forEach(function (point) {
  480. var plotY = point.plotY, graphic = point.graphic, hasGraphic = !!graphic, verb = graphic && chart.pointCount < animationLimit ?
  481. 'animate' : 'attr';
  482. if (isNumber(plotY) && point.y !== null) {
  483. shapeArgs = point.shapeArgs;
  484. // When updating a series between 2d and 3d or cartesian and
  485. // polar, the shape type changes.
  486. if (graphic && point.hasNewShapeType()) {
  487. graphic = graphic.destroy();
  488. }
  489. // Set starting position for point sliding animation.
  490. if (series.enabledDataSorting) {
  491. point.startXPos = series.xAxis.reversed ?
  492. -(shapeArgs ? (shapeArgs.width || 0) : 0) :
  493. series.xAxis.width;
  494. }
  495. if (!graphic) {
  496. point.graphic = graphic =
  497. renderer[point.shapeType](shapeArgs)
  498. .add(point.group || series.group);
  499. if (graphic &&
  500. series.enabledDataSorting &&
  501. chart.hasRendered &&
  502. chart.pointCount < animationLimit) {
  503. graphic.attr({
  504. x: point.startXPos
  505. });
  506. hasGraphic = true;
  507. verb = 'animate';
  508. }
  509. }
  510. if (graphic && hasGraphic) { // update
  511. graphic[verb](merge(shapeArgs));
  512. }
  513. // Border radius is not stylable (#6900)
  514. if (options.borderRadius) {
  515. graphic[verb]({
  516. r: options.borderRadius
  517. });
  518. }
  519. // Presentational
  520. if (!chart.styledMode) {
  521. graphic[verb](series.pointAttribs(point, (point.selected && 'select')))
  522. .shadow(point.allowShadow !== false && options.shadow, null, options.stacking && !options.borderRadius);
  523. }
  524. if (graphic) {
  525. graphic.addClass(point.getClassName(), true);
  526. graphic.attr({
  527. visibility: point.visible ? 'inherit' : 'hidden'
  528. });
  529. }
  530. }
  531. else if (graphic) {
  532. point.graphic = graphic.destroy(); // #1269
  533. }
  534. });
  535. };
  536. /**
  537. * Draw the tracker for a point.
  538. * @private
  539. */
  540. ColumnSeries.prototype.drawTracker = function () {
  541. var series = this, chart = series.chart, pointer = chart.pointer, onMouseOver = function (e) {
  542. var point = pointer.getPointFromEvent(e);
  543. // undefined on graph in scatterchart
  544. if (typeof point !== 'undefined') {
  545. pointer.isDirectTouch = true;
  546. point.onMouseOver(e);
  547. }
  548. }, dataLabels;
  549. // Add reference to the point
  550. series.points.forEach(function (point) {
  551. dataLabels = (isArray(point.dataLabels) ?
  552. point.dataLabels :
  553. (point.dataLabel ? [point.dataLabel] : []));
  554. if (point.graphic) {
  555. point.graphic.element.point = point;
  556. }
  557. dataLabels.forEach(function (dataLabel) {
  558. if (dataLabel.div) {
  559. dataLabel.div.point = point;
  560. }
  561. else {
  562. dataLabel.element.point = point;
  563. }
  564. });
  565. });
  566. // Add the event listeners, we need to do this only once
  567. if (!series._hasTracking) {
  568. series.trackerGroups.forEach(function (key) {
  569. if (series[key]) {
  570. // we don't always have dataLabelsGroup
  571. series[key]
  572. .addClass('highcharts-tracker')
  573. .on('mouseover', onMouseOver)
  574. .on('mouseout', function (e) {
  575. pointer.onTrackerMouseOut(e);
  576. });
  577. if (hasTouch) {
  578. series[key].on('touchstart', onMouseOver);
  579. }
  580. if (!chart.styledMode && series.options.cursor) {
  581. series[key]
  582. .css(css)
  583. .css({ cursor: series.options.cursor });
  584. }
  585. }
  586. });
  587. series._hasTracking = true;
  588. }
  589. fireEvent(this, 'afterDrawTracker');
  590. };
  591. /**
  592. * Remove this series from the chart
  593. *
  594. * @private
  595. * @function Highcharts.seriesTypes.column#remove
  596. */
  597. ColumnSeries.prototype.remove = function () {
  598. var series = this, chart = series.chart;
  599. // column and bar series affects other series of the same type
  600. // as they are either stacked or grouped
  601. if (chart.hasRendered) {
  602. chart.series.forEach(function (otherSeries) {
  603. if (otherSeries.type === series.type) {
  604. otherSeries.isDirty = true;
  605. }
  606. });
  607. }
  608. Series.prototype.remove.apply(series, arguments);
  609. };
  610. /**
  611. * Column series display one column per value along an X axis.
  612. *
  613. * @sample {highcharts} highcharts/demo/column-basic/
  614. * Column chart
  615. * @sample {highstock} stock/demo/column/
  616. * Column chart
  617. *
  618. * @extends plotOptions.line
  619. * @excluding connectEnds, connectNulls, gapSize, gapUnit, linecap,
  620. * lineWidth, marker, step, useOhlcData
  621. * @product highcharts highstock
  622. * @optionparent plotOptions.column
  623. */
  624. ColumnSeries.defaultOptions = merge(Series.defaultOptions, {
  625. /**
  626. * The corner radius of the border surrounding each column or bar.
  627. *
  628. * @sample {highcharts} highcharts/plotoptions/column-borderradius/
  629. * Rounded columns
  630. *
  631. * @product highcharts highstock gantt
  632. *
  633. * @private
  634. */
  635. borderRadius: 0,
  636. /**
  637. * When using automatic point colors pulled from the global
  638. * [colors](colors) or series-specific
  639. * [plotOptions.column.colors](series.colors) collections, this option
  640. * determines whether the chart should receive one color per series or
  641. * one color per point.
  642. *
  643. * In styled mode, the `colors` or `series.colors` arrays are not
  644. * supported, and instead this option gives the points individual color
  645. * class names on the form `highcharts-color-{n}`.
  646. *
  647. * @see [series colors](#plotOptions.column.colors)
  648. *
  649. * @sample {highcharts} highcharts/plotoptions/column-colorbypoint-false/
  650. * False by default
  651. * @sample {highcharts} highcharts/plotoptions/column-colorbypoint-true/
  652. * True
  653. *
  654. * @type {boolean}
  655. * @default false
  656. * @since 2.0
  657. * @product highcharts highstock gantt
  658. * @apioption plotOptions.column.colorByPoint
  659. */
  660. /**
  661. * A series specific or series type specific color set to apply instead
  662. * of the global [colors](#colors) when [colorByPoint](
  663. * #plotOptions.column.colorByPoint) is true.
  664. *
  665. * @type {Array<Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject>}
  666. * @since 3.0
  667. * @product highcharts highstock gantt
  668. * @apioption plotOptions.column.colors
  669. */
  670. /**
  671. * When `true`, the columns will center in the category, ignoring null
  672. * or missing points. When `false`, space will be reserved for null or
  673. * missing points.
  674. *
  675. * @sample {highcharts} highcharts/series-column/centerincategory/
  676. * Center in category
  677. *
  678. * @since 8.0.1
  679. * @product highcharts highstock gantt
  680. *
  681. * @private
  682. */
  683. centerInCategory: false,
  684. /**
  685. * Padding between each value groups, in x axis units.
  686. *
  687. * @sample {highcharts} highcharts/plotoptions/column-grouppadding-default/
  688. * 0.2 by default
  689. * @sample {highcharts} highcharts/plotoptions/column-grouppadding-none/
  690. * No group padding - all columns are evenly spaced
  691. *
  692. * @product highcharts highstock gantt
  693. *
  694. * @private
  695. */
  696. groupPadding: 0.2,
  697. /**
  698. * Whether to group non-stacked columns or to let them render
  699. * independent of each other. Non-grouped columns will be laid out
  700. * individually and overlap each other.
  701. *
  702. * @sample {highcharts} highcharts/plotoptions/column-grouping-false/
  703. * Grouping disabled
  704. * @sample {highstock} highcharts/plotoptions/column-grouping-false/
  705. * Grouping disabled
  706. *
  707. * @type {boolean}
  708. * @default true
  709. * @since 2.3.0
  710. * @product highcharts highstock gantt
  711. * @apioption plotOptions.column.grouping
  712. */
  713. /**
  714. * @ignore-option
  715. * @private
  716. */
  717. marker: null,
  718. /**
  719. * The maximum allowed pixel width for a column, translated to the
  720. * height of a bar in a bar chart. This prevents the columns from
  721. * becoming too wide when there is a small number of points in the
  722. * chart.
  723. *
  724. * @see [pointWidth](#plotOptions.column.pointWidth)
  725. *
  726. * @sample {highcharts} highcharts/plotoptions/column-maxpointwidth-20/
  727. * Limited to 50
  728. * @sample {highstock} highcharts/plotoptions/column-maxpointwidth-20/
  729. * Limited to 50
  730. *
  731. * @type {number}
  732. * @since 4.1.8
  733. * @product highcharts highstock gantt
  734. * @apioption plotOptions.column.maxPointWidth
  735. */
  736. /**
  737. * Padding between each column or bar, in x axis units.
  738. *
  739. * @sample {highcharts} highcharts/plotoptions/column-pointpadding-default/
  740. * 0.1 by default
  741. * @sample {highcharts} highcharts/plotoptions/column-pointpadding-025/
  742. * 0.25
  743. * @sample {highcharts} highcharts/plotoptions/column-pointpadding-none/
  744. * 0 for tightly packed columns
  745. *
  746. * @product highcharts highstock gantt
  747. *
  748. * @private
  749. */
  750. pointPadding: 0.1,
  751. /**
  752. * A pixel value specifying a fixed width for each column or bar point.
  753. * When set to `undefined`, the width is calculated from the
  754. * `pointPadding` and `groupPadding`. The width effects the dimension
  755. * that is not based on the point value. For column series it is the
  756. * hoizontal length and for bar series it is the vertical length.
  757. *
  758. * @see [maxPointWidth](#plotOptions.column.maxPointWidth)
  759. *
  760. * @sample {highcharts} highcharts/plotoptions/column-pointwidth-20/
  761. * 20px wide columns regardless of chart width or the amount of
  762. * data points
  763. *
  764. * @type {number}
  765. * @since 1.2.5
  766. * @product highcharts highstock gantt
  767. * @apioption plotOptions.column.pointWidth
  768. */
  769. /**
  770. * A pixel value specifying a fixed width for the column or bar.
  771. * Overrides pointWidth on the series.
  772. *
  773. * @see [series.pointWidth](#plotOptions.column.pointWidth)
  774. *
  775. * @type {number}
  776. * @default undefined
  777. * @since 7.0.0
  778. * @product highcharts highstock gantt
  779. * @apioption series.column.data.pointWidth
  780. */
  781. /**
  782. * The minimal height for a column or width for a bar. By default,
  783. * 0 values are not shown. To visualize a 0 (or close to zero) point,
  784. * set the minimal point length to a pixel value like 3\. In stacked
  785. * column charts, minPointLength might not be respected for tightly
  786. * packed values.
  787. *
  788. * @sample {highcharts} highcharts/plotoptions/column-minpointlength/
  789. * Zero base value
  790. * @sample {highcharts} highcharts/plotoptions/column-minpointlength-pos-and-neg/
  791. * Positive and negative close to zero values
  792. *
  793. * @product highcharts highstock gantt
  794. *
  795. * @private
  796. */
  797. minPointLength: 0,
  798. /**
  799. * When the series contains less points than the crop threshold, all
  800. * points are drawn, event if the points fall outside the visible plot
  801. * area at the current zoom. The advantage of drawing all points
  802. * (including markers and columns), is that animation is performed on
  803. * updates. On the other hand, when the series contains more points than
  804. * the crop threshold, the series data is cropped to only contain points
  805. * that fall within the plot area. The advantage of cropping away
  806. * invisible points is to increase performance on large series.
  807. *
  808. * @product highcharts highstock gantt
  809. *
  810. * @private
  811. */
  812. cropThreshold: 50,
  813. /**
  814. * The X axis range that each point is valid for. This determines the
  815. * width of the column. On a categorized axis, the range will be 1
  816. * by default (one category unit). On linear and datetime axes, the
  817. * range will be computed as the distance between the two closest data
  818. * points.
  819. *
  820. * The default `null` means it is computed automatically, but this
  821. * option can be used to override the automatic value.
  822. *
  823. * This option is set by default to 1 if data sorting is enabled.
  824. *
  825. * @sample {highcharts} highcharts/plotoptions/column-pointrange/
  826. * Set the point range to one day on a data set with one week
  827. * between the points
  828. *
  829. * @type {number|null}
  830. * @since 2.3
  831. * @product highcharts highstock gantt
  832. *
  833. * @private
  834. */
  835. pointRange: null,
  836. states: {
  837. /**
  838. * Options for the hovered point. These settings override the normal
  839. * state options when a point is moused over or touched.
  840. *
  841. * @extends plotOptions.series.states.hover
  842. * @excluding halo, lineWidth, lineWidthPlus, marker
  843. * @product highcharts highstock gantt
  844. */
  845. hover: {
  846. /** @ignore-option */
  847. halo: false,
  848. /**
  849. * A specific border color for the hovered point. Defaults to
  850. * inherit the normal state border color.
  851. *
  852. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  853. * @product highcharts gantt
  854. * @apioption plotOptions.column.states.hover.borderColor
  855. */
  856. /**
  857. * A specific color for the hovered point.
  858. *
  859. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  860. * @product highcharts gantt
  861. * @apioption plotOptions.column.states.hover.color
  862. */
  863. /**
  864. * How much to brighten the point on interaction. Requires the
  865. * main color to be defined in hex or rgb(a) format.
  866. *
  867. * In styled mode, the hover brightening is by default replaced
  868. * with a fill-opacity set in the `.highcharts-point:hover`
  869. * rule.
  870. *
  871. * @sample {highcharts} highcharts/plotoptions/column-states-hover-brightness/
  872. * Brighten by 0.5
  873. *
  874. * @product highcharts highstock gantt
  875. */
  876. brightness: 0.1
  877. },
  878. /**
  879. * Options for the selected point. These settings override the
  880. * normal state options when a point is selected.
  881. *
  882. * @extends plotOptions.series.states.select
  883. * @excluding halo, lineWidth, lineWidthPlus, marker
  884. * @product highcharts highstock gantt
  885. */
  886. select: {
  887. /**
  888. * A specific color for the selected point.
  889. *
  890. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  891. * @default #cccccc
  892. * @product highcharts highstock gantt
  893. */
  894. color: palette.neutralColor20,
  895. /**
  896. * A specific border color for the selected point.
  897. *
  898. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  899. * @default #000000
  900. * @product highcharts highstock gantt
  901. */
  902. borderColor: palette.neutralColor100
  903. }
  904. },
  905. dataLabels: {
  906. align: void 0,
  907. verticalAlign: void 0,
  908. /**
  909. * The y position offset of the label relative to the point in
  910. * pixels.
  911. *
  912. * @type {number}
  913. */
  914. y: void 0
  915. },
  916. // false doesn't work well: https://jsfiddle.net/highcharts/hz8fopan/14/
  917. /**
  918. * @ignore-option
  919. * @private
  920. */
  921. startFromThreshold: true,
  922. stickyTracking: false,
  923. tooltip: {
  924. distance: 6
  925. },
  926. /**
  927. * The Y axis value to serve as the base for the columns, for
  928. * distinguishing between values above and below a threshold. If `null`,
  929. * the columns extend from the padding Y axis minimum.
  930. *
  931. * @type {number|null}
  932. * @since 2.0
  933. * @product highcharts
  934. *
  935. * @private
  936. */
  937. threshold: 0,
  938. /**
  939. * The width of the border surrounding each column or bar. Defaults to
  940. * `1` when there is room for a border, but to `0` when the columns are
  941. * so dense that a border would cover the next column.
  942. *
  943. * In styled mode, the stroke width can be set with the
  944. * `.highcharts-point` rule.
  945. *
  946. * @sample {highcharts} highcharts/plotoptions/column-borderwidth/
  947. * 2px black border
  948. *
  949. * @type {number}
  950. * @default undefined
  951. * @product highcharts highstock gantt
  952. * @apioption plotOptions.column.borderWidth
  953. */
  954. /**
  955. * The color of the border surrounding each column or bar.
  956. *
  957. * In styled mode, the border stroke can be set with the
  958. * `.highcharts-point` rule.
  959. *
  960. * @sample {highcharts} highcharts/plotoptions/column-bordercolor/
  961. * Dark gray border
  962. *
  963. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  964. * @default #ffffff
  965. * @product highcharts highstock gantt
  966. *
  967. * @private
  968. */
  969. borderColor: palette.backgroundColor
  970. });
  971. return ColumnSeries;
  972. }(Series));
  973. extend(ColumnSeries.prototype, {
  974. cropShoulder: 0,
  975. // When tooltip is not shared, this series (and derivatives) requires
  976. // direct touch/hover. KD-tree does not apply.
  977. directTouch: true,
  978. /**
  979. * Use a solid rectangle like the area series types
  980. *
  981. * @private
  982. * @function Highcharts.seriesTypes.column#drawLegendSymbol
  983. *
  984. * @param {Highcharts.Legend} legend
  985. * The legend object
  986. *
  987. * @param {Highcharts.Series|Highcharts.Point} item
  988. * The series (this) or point
  989. */
  990. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  991. getSymbol: noop,
  992. // use separate negative stacks, unlike area stacks where a negative
  993. // point is substracted from previous (#1910)
  994. negStacks: true,
  995. trackerGroups: ['group', 'dataLabelsGroup']
  996. });
  997. SeriesRegistry.registerSeriesType('column', ColumnSeries);
  998. /* *
  999. *
  1000. * Export
  1001. *
  1002. * */
  1003. export default ColumnSeries;
  1004. /* *
  1005. *
  1006. * API Declarations
  1007. *
  1008. * */
  1009. /**
  1010. * Adjusted width and x offset of the columns for grouping.
  1011. *
  1012. * @private
  1013. * @interface Highcharts.ColumnMetricsObject
  1014. */ /**
  1015. * Width of the columns.
  1016. * @name Highcharts.ColumnMetricsObject#width
  1017. * @type {number}
  1018. */ /**
  1019. * Offset of the columns.
  1020. * @name Highcharts.ColumnMetricsObject#offset
  1021. * @type {number}
  1022. */
  1023. ''; // detach doclets above
  1024. /* *
  1025. *
  1026. * API Options
  1027. *
  1028. * */
  1029. /**
  1030. * A `column` series. If the [type](#series.column.type) option is
  1031. * not specified, it is inherited from [chart.type](#chart.type).
  1032. *
  1033. * @extends series,plotOptions.column
  1034. * @excluding connectNulls, dataParser, dataURL, gapSize, gapUnit, linecap,
  1035. * lineWidth, marker, connectEnds, step
  1036. * @product highcharts highstock
  1037. * @apioption series.column
  1038. */
  1039. /**
  1040. * An array of data points for the series. For the `column` series type,
  1041. * points can be given in the following ways:
  1042. *
  1043. * 1. An array of numerical values. In this case, the numerical values will be
  1044. * interpreted as `y` options. The `x` values will be automatically
  1045. * calculated, either starting at 0 and incremented by 1, or from
  1046. * `pointStart` and `pointInterval` given in the series options. If the axis
  1047. * has categories, these will be used. Example:
  1048. * ```js
  1049. * data: [0, 5, 3, 5]
  1050. * ```
  1051. *
  1052. * 2. An array of arrays with 2 values. In this case, the values correspond to
  1053. * `x,y`. If the first value is a string, it is applied as the name of the
  1054. * point, and the `x` value is inferred.
  1055. * ```js
  1056. * data: [
  1057. * [0, 6],
  1058. * [1, 2],
  1059. * [2, 6]
  1060. * ]
  1061. * ```
  1062. *
  1063. * 3. An array of objects with named values. The following snippet shows only a
  1064. * few settings, see the complete options set below. If the total number of
  1065. * data points exceeds the series'
  1066. * [turboThreshold](#series.column.turboThreshold), this option is not
  1067. * available.
  1068. * ```js
  1069. * data: [{
  1070. * x: 1,
  1071. * y: 9,
  1072. * name: "Point2",
  1073. * color: "#00FF00"
  1074. * }, {
  1075. * x: 1,
  1076. * y: 6,
  1077. * name: "Point1",
  1078. * color: "#FF00FF"
  1079. * }]
  1080. * ```
  1081. *
  1082. * @sample {highcharts} highcharts/chart/reflow-true/
  1083. * Numerical values
  1084. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  1085. * Arrays of numeric x and y
  1086. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  1087. * Arrays of datetime x and y
  1088. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  1089. * Arrays of point.name and y
  1090. * @sample {highcharts} highcharts/series/data-array-of-objects/
  1091. * Config objects
  1092. *
  1093. * @type {Array<number|Array<(number|string),(number|null)>|null|*>}
  1094. * @extends series.line.data
  1095. * @excluding marker
  1096. * @product highcharts highstock
  1097. * @apioption series.column.data
  1098. */
  1099. /**
  1100. * The color of the border surrounding the column or bar.
  1101. *
  1102. * In styled mode, the border stroke can be set with the `.highcharts-point`
  1103. * rule.
  1104. *
  1105. * @sample {highcharts} highcharts/plotoptions/column-bordercolor/
  1106. * Dark gray border
  1107. *
  1108. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1109. * @product highcharts highstock
  1110. * @apioption series.column.data.borderColor
  1111. */
  1112. /**
  1113. * The width of the border surrounding the column or bar.
  1114. *
  1115. * In styled mode, the stroke width can be set with the `.highcharts-point`
  1116. * rule.
  1117. *
  1118. * @sample {highcharts} highcharts/plotoptions/column-borderwidth/
  1119. * 2px black border
  1120. *
  1121. * @type {number}
  1122. * @product highcharts highstock
  1123. * @apioption series.column.data.borderWidth
  1124. */
  1125. /**
  1126. * A name for the dash style to use for the column or bar. Overrides
  1127. * dashStyle on the series.
  1128. *
  1129. * In styled mode, the stroke dash-array can be set with the same classes as
  1130. * listed under [data.color](#series.column.data.color).
  1131. *
  1132. * @see [series.pointWidth](#plotOptions.column.dashStyle)
  1133. *
  1134. * @type {Highcharts.DashStyleValue}
  1135. * @apioption series.column.data.dashStyle
  1136. */
  1137. /**
  1138. * A pixel value specifying a fixed width for the column or bar. Overrides
  1139. * pointWidth on the series. The width effects the dimension that is not based
  1140. * on the point value.
  1141. *
  1142. * @see [series.pointWidth](#plotOptions.column.pointWidth)
  1143. *
  1144. * @type {number}
  1145. * @apioption series.column.data.pointWidth
  1146. */
  1147. /**
  1148. * @excluding halo, lineWidth, lineWidthPlus, marker
  1149. * @product highcharts highstock
  1150. * @apioption series.column.states.hover
  1151. */
  1152. /**
  1153. * @excluding halo, lineWidth, lineWidthPlus, marker
  1154. * @product highcharts highstock
  1155. * @apioption series.column.states.select
  1156. */
  1157. ''; // includes above doclets in transpilat