coloraxis.src.js 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. /**
  2. * @license Highcharts JS v8.2.0 (2020-08-20)
  3. *
  4. * ColorAxis module
  5. *
  6. * (c) 2012-2019 Pawel Potaczek
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/modules/color-axis', ['highcharts'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'Mixins/ColorSeries.js', [_modules['Core/Globals.js']], function (H) {
  32. /* *
  33. *
  34. * (c) 2010-2020 Torstein Honsi
  35. *
  36. * License: www.highcharts.com/license
  37. *
  38. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  39. *
  40. * */
  41. /**
  42. * Mixin for maps and heatmaps
  43. *
  44. * @private
  45. * @mixin Highcharts.colorPointMixin
  46. */
  47. H.colorPointMixin = {
  48. /* eslint-disable valid-jsdoc */
  49. /**
  50. * Set the visibility of a single point
  51. * @private
  52. * @function Highcharts.colorPointMixin.setVisible
  53. * @param {boolean} visible
  54. * @return {void}
  55. */
  56. setVisible: function (vis) {
  57. var point = this,
  58. method = vis ? 'show' : 'hide';
  59. point.visible = point.options.visible = Boolean(vis);
  60. // Show and hide associated elements
  61. ['graphic', 'dataLabel'].forEach(function (key) {
  62. if (point[key]) {
  63. point[key][method]();
  64. }
  65. });
  66. this.series.buildKDTree(); // rebuild kdtree #13195
  67. }
  68. /* eslint-enable valid-jsdoc */
  69. };
  70. /**
  71. * @private
  72. * @mixin Highcharts.colorSeriesMixin
  73. */
  74. H.colorSeriesMixin = {
  75. optionalAxis: 'colorAxis',
  76. colorAxis: 0,
  77. /* eslint-disable valid-jsdoc */
  78. /**
  79. * In choropleth maps, the color is a result of the value, so this needs
  80. * translation too
  81. * @private
  82. * @function Highcharts.colorSeriesMixin.translateColors
  83. * @return {void}
  84. */
  85. translateColors: function () {
  86. var series = this,
  87. points = this.data.length ? this.data : this.points,
  88. nullColor = this.options.nullColor,
  89. colorAxis = this.colorAxis,
  90. colorKey = this.colorKey;
  91. points.forEach(function (point) {
  92. var value = point.getNestedProperty(colorKey),
  93. color;
  94. color = point.options.color ||
  95. (point.isNull || point.value === null ?
  96. nullColor :
  97. (colorAxis && typeof value !== 'undefined') ?
  98. colorAxis.toColor(value, point) :
  99. point.color || series.color);
  100. if (color && point.color !== color) {
  101. point.color = color;
  102. if (series.options.legendType === 'point' && point.legendItem) {
  103. series.chart.legend.colorizeItem(point, point.visible);
  104. }
  105. }
  106. });
  107. }
  108. /* eslint-enable valid-jsdoc */
  109. };
  110. });
  111. _registerModule(_modules, 'Core/Axis/ColorAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Color.js'], _modules['Core/Globals.js'], _modules['Core/Legend.js'], _modules['Mixins/LegendSymbol.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js']], function (Axis, Chart, Color, H, Legend, LegendSymbolMixin, Point, U) {
  112. /* *
  113. *
  114. * (c) 2010-2020 Torstein Honsi
  115. *
  116. * License: www.highcharts.com/license
  117. *
  118. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  119. *
  120. * */
  121. var __extends = (this && this.__extends) || (function () {
  122. var extendStatics = function (d,
  123. b) {
  124. extendStatics = Object.setPrototypeOf ||
  125. ({ __proto__: [] } instanceof Array && function (d,
  126. b) { d.__proto__ = b; }) ||
  127. function (d,
  128. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  129. return extendStatics(d, b);
  130. };
  131. return function (d, b) {
  132. extendStatics(d, b);
  133. function __() { this.constructor = d; }
  134. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  135. };
  136. })();
  137. var color = Color.parse;
  138. var noop = H.noop;
  139. var addEvent = U.addEvent,
  140. erase = U.erase,
  141. extend = U.extend,
  142. Fx = U.Fx,
  143. isNumber = U.isNumber,
  144. merge = U.merge,
  145. pick = U.pick,
  146. splat = U.splat;
  147. /**
  148. * Color axis types
  149. *
  150. * @typedef {"linear"|"logarithmic"} Highcharts.ColorAxisTypeValue
  151. */
  152. ''; // detach doclet above
  153. var Series = H.Series,
  154. colorPointMixin = H.colorPointMixin,
  155. colorSeriesMixin = H.colorSeriesMixin;
  156. extend(Series.prototype, colorSeriesMixin);
  157. extend(Point.prototype, colorPointMixin);
  158. Chart.prototype.collectionsWithUpdate.push('colorAxis');
  159. Chart.prototype.collectionsWithInit.colorAxis = [Chart.prototype.addColorAxis];
  160. /* eslint-disable no-invalid-this, valid-jsdoc */
  161. /**
  162. * The ColorAxis object for inclusion in gradient legends.
  163. *
  164. * @class
  165. * @name Highcharts.ColorAxis
  166. * @augments Highcharts.Axis
  167. *
  168. * @param {Highcharts.Chart} chart
  169. * The related chart of the color axis.
  170. *
  171. * @param {Highcharts.ColorAxisOptions} userOptions
  172. * The color axis options for initialization.
  173. */
  174. var ColorAxis = /** @class */ (function (_super) {
  175. __extends(ColorAxis, _super);
  176. /* *
  177. *
  178. * Constructors
  179. *
  180. * */
  181. /**
  182. * @private
  183. */
  184. function ColorAxis(chart, userOptions) {
  185. var _this = _super.call(this,
  186. chart,
  187. userOptions) || this;
  188. _this.beforePadding = false; // Prevents unnecessary padding with `hc-more`
  189. _this.chart = void 0;
  190. _this.coll = 'colorAxis';
  191. _this.dataClasses = void 0;
  192. _this.legendItem = void 0;
  193. _this.legendItems = void 0;
  194. _this.name = ''; // Prevents 'undefined' in legend in IE8
  195. _this.options = void 0;
  196. _this.stops = void 0;
  197. _this.visible = true;
  198. _this.init(chart, userOptions);
  199. return _this;
  200. }
  201. /* *
  202. *
  203. * Static Functions
  204. *
  205. * */
  206. /**
  207. * Build options to keep layout params on init and update.
  208. * @private
  209. */
  210. ColorAxis.buildOptions = function (chart, options, userOptions) {
  211. var legend = chart.options.legend || {},
  212. horiz = userOptions.layout ?
  213. userOptions.layout !== 'vertical' :
  214. legend.layout !== 'vertical';
  215. return merge(options, {
  216. side: horiz ? 2 : 1,
  217. reversed: !horiz
  218. }, userOptions, {
  219. opposite: !horiz,
  220. showEmpty: false,
  221. title: null,
  222. visible: legend.enabled &&
  223. (userOptions ? userOptions.visible !== false : true)
  224. });
  225. };
  226. /* *
  227. *
  228. * Functions
  229. *
  230. * */
  231. /**
  232. * Initializes the color axis.
  233. *
  234. * @function Highcharts.ColorAxis#init
  235. *
  236. * @param {Highcharts.Chart} chart
  237. * The related chart of the color axis.
  238. *
  239. * @param {Highcharts.ColorAxisOptions} userOptions
  240. * The color axis options for initialization.
  241. */
  242. ColorAxis.prototype.init = function (chart, userOptions) {
  243. var axis = this;
  244. var options = ColorAxis.buildOptions(// Build the options
  245. chart,
  246. ColorAxis.defaultOptions,
  247. userOptions);
  248. axis.coll = 'colorAxis';
  249. _super.prototype.init.call(this, chart, options);
  250. // Base init() pushes it to the xAxis array, now pop it again
  251. // chart[this.isXAxis ? 'xAxis' : 'yAxis'].pop();
  252. // Prepare data classes
  253. if (userOptions.dataClasses) {
  254. axis.initDataClasses(userOptions);
  255. }
  256. axis.initStops();
  257. // Override original axis properties
  258. axis.horiz = !options.opposite;
  259. axis.zoomEnabled = false;
  260. };
  261. /**
  262. * @private
  263. */
  264. ColorAxis.prototype.initDataClasses = function (userOptions) {
  265. var axis = this;
  266. var chart = axis.chart,
  267. dataClasses,
  268. colorCounter = 0,
  269. colorCount = chart.options.chart.colorCount,
  270. options = axis.options,
  271. len = userOptions.dataClasses.length;
  272. axis.dataClasses = dataClasses = [];
  273. axis.legendItems = [];
  274. userOptions.dataClasses.forEach(function (dataClass, i) {
  275. var colors;
  276. dataClass = merge(dataClass);
  277. dataClasses.push(dataClass);
  278. if (!chart.styledMode && dataClass.color) {
  279. return;
  280. }
  281. if (options.dataClassColor === 'category') {
  282. if (!chart.styledMode) {
  283. colors = chart.options.colors;
  284. colorCount = colors.length;
  285. dataClass.color = colors[colorCounter];
  286. }
  287. dataClass.colorIndex = colorCounter;
  288. // increase and loop back to zero
  289. colorCounter++;
  290. if (colorCounter === colorCount) {
  291. colorCounter = 0;
  292. }
  293. }
  294. else {
  295. dataClass.color = color(options.minColor).tweenTo(color(options.maxColor), len < 2 ? 0.5 : i / (len - 1) // #3219
  296. );
  297. }
  298. });
  299. };
  300. /**
  301. * Returns true if the series has points at all.
  302. *
  303. * @function Highcharts.ColorAxis#hasData
  304. *
  305. * @return {boolean}
  306. * True, if the series has points, otherwise false.
  307. */
  308. ColorAxis.prototype.hasData = function () {
  309. return !!(this.tickPositions || []).length;
  310. };
  311. /**
  312. * Override so that ticks are not added in data class axes (#6914)
  313. * @private
  314. */
  315. ColorAxis.prototype.setTickPositions = function () {
  316. if (!this.dataClasses) {
  317. return _super.prototype.setTickPositions.call(this);
  318. }
  319. };
  320. /**
  321. * @private
  322. */
  323. ColorAxis.prototype.initStops = function () {
  324. var axis = this;
  325. axis.stops = axis.options.stops || [
  326. [0, axis.options.minColor],
  327. [1, axis.options.maxColor]
  328. ];
  329. axis.stops.forEach(function (stop) {
  330. stop.color = color(stop[1]);
  331. });
  332. };
  333. /**
  334. * Extend the setOptions method to process extreme colors and color stops.
  335. * @private
  336. */
  337. ColorAxis.prototype.setOptions = function (userOptions) {
  338. var axis = this;
  339. _super.prototype.setOptions.call(this, userOptions);
  340. axis.options.crosshair = axis.options.marker;
  341. };
  342. /**
  343. * @private
  344. */
  345. ColorAxis.prototype.setAxisSize = function () {
  346. var axis = this;
  347. var symbol = axis.legendSymbol;
  348. var chart = axis.chart;
  349. var legendOptions = chart.options.legend || {};
  350. var x,
  351. y,
  352. width,
  353. height;
  354. if (symbol) {
  355. this.left = x = symbol.attr('x');
  356. this.top = y = symbol.attr('y');
  357. this.width = width = symbol.attr('width');
  358. this.height = height = symbol.attr('height');
  359. this.right = chart.chartWidth - x - width;
  360. this.bottom = chart.chartHeight - y - height;
  361. this.len = this.horiz ? width : height;
  362. this.pos = this.horiz ? x : y;
  363. }
  364. else {
  365. // Fake length for disabled legend to avoid tick issues
  366. // and such (#5205)
  367. this.len = (this.horiz ?
  368. legendOptions.symbolWidth :
  369. legendOptions.symbolHeight) || ColorAxis.defaultLegendLength;
  370. }
  371. };
  372. /**
  373. * @private
  374. */
  375. ColorAxis.prototype.normalizedValue = function (value) {
  376. var axis = this;
  377. if (axis.logarithmic) {
  378. value = axis.logarithmic.log2lin(value);
  379. }
  380. return 1 - ((axis.max - value) /
  381. ((axis.max - axis.min) || 1));
  382. };
  383. /**
  384. * Translate from a value to a color.
  385. * @private
  386. */
  387. ColorAxis.prototype.toColor = function (value, point) {
  388. var axis = this;
  389. var dataClasses = axis.dataClasses;
  390. var stops = axis.stops;
  391. var pos,
  392. from,
  393. to,
  394. color,
  395. dataClass,
  396. i;
  397. if (dataClasses) {
  398. i = dataClasses.length;
  399. while (i--) {
  400. dataClass = dataClasses[i];
  401. from = dataClass.from;
  402. to = dataClass.to;
  403. if ((typeof from === 'undefined' || value >= from) &&
  404. (typeof to === 'undefined' || value <= to)) {
  405. color = dataClass.color;
  406. if (point) {
  407. point.dataClass = i;
  408. point.colorIndex = dataClass.colorIndex;
  409. }
  410. break;
  411. }
  412. }
  413. }
  414. else {
  415. pos = axis.normalizedValue(value);
  416. i = stops.length;
  417. while (i--) {
  418. if (pos > stops[i][0]) {
  419. break;
  420. }
  421. }
  422. from = stops[i] || stops[i + 1];
  423. to = stops[i + 1] || from;
  424. // The position within the gradient
  425. pos = 1 - (to[0] - pos) / ((to[0] - from[0]) || 1);
  426. color = from.color.tweenTo(to.color, pos);
  427. }
  428. return color;
  429. };
  430. /**
  431. * Override the getOffset method to add the whole axis groups inside the
  432. * legend.
  433. * @private
  434. */
  435. ColorAxis.prototype.getOffset = function () {
  436. var axis = this;
  437. var group = axis.legendGroup;
  438. var sideOffset = axis.chart.axisOffset[axis.side];
  439. if (group) {
  440. // Hook for the getOffset method to add groups to this parent
  441. // group
  442. axis.axisParent = group;
  443. // Call the base
  444. _super.prototype.getOffset.call(this);
  445. // First time only
  446. if (!axis.added) {
  447. axis.added = true;
  448. axis.labelLeft = 0;
  449. axis.labelRight = axis.width;
  450. }
  451. // Reset it to avoid color axis reserving space
  452. axis.chart.axisOffset[axis.side] = sideOffset;
  453. }
  454. };
  455. /**
  456. * Create the color gradient.
  457. * @private
  458. */
  459. ColorAxis.prototype.setLegendColor = function () {
  460. var axis = this;
  461. var horiz = axis.horiz;
  462. var reversed = axis.reversed;
  463. var one = reversed ? 1 : 0;
  464. var zero = reversed ? 0 : 1;
  465. var grad = horiz ? [one, 0,
  466. zero, 0] : [0,
  467. zero, 0,
  468. one]; // #3190
  469. axis.legendColor = {
  470. linearGradient: {
  471. x1: grad[0],
  472. y1: grad[1],
  473. x2: grad[2],
  474. y2: grad[3]
  475. },
  476. stops: axis.stops
  477. };
  478. };
  479. /**
  480. * The color axis appears inside the legend and has its own legend symbol.
  481. * @private
  482. */
  483. ColorAxis.prototype.drawLegendSymbol = function (legend, item) {
  484. var axis = this;
  485. var padding = legend.padding;
  486. var legendOptions = legend.options;
  487. var horiz = axis.horiz;
  488. var width = pick(legendOptions.symbolWidth,
  489. horiz ? ColorAxis.defaultLegendLength : 12);
  490. var height = pick(legendOptions.symbolHeight,
  491. horiz ? 12 : ColorAxis.defaultLegendLength);
  492. var labelPadding = pick(legendOptions.labelPadding,
  493. horiz ? 16 : 30);
  494. var itemDistance = pick(legendOptions.itemDistance, 10);
  495. this.setLegendColor();
  496. // Create the gradient
  497. item.legendSymbol = this.chart.renderer.rect(0, legend.baseline - 11, width, height).attr({
  498. zIndex: 1
  499. }).add(item.legendGroup);
  500. // Set how much space this legend item takes up
  501. axis.legendItemWidth = width + padding + (horiz ? itemDistance : labelPadding);
  502. axis.legendItemHeight = height + padding + (horiz ? labelPadding : 0);
  503. };
  504. /**
  505. * Fool the legend.
  506. * @private
  507. */
  508. ColorAxis.prototype.setState = function (state) {
  509. this.series.forEach(function (series) {
  510. series.setState(state);
  511. });
  512. };
  513. /**
  514. * @private
  515. */
  516. ColorAxis.prototype.setVisible = function () {
  517. };
  518. /**
  519. * @private
  520. */
  521. ColorAxis.prototype.getSeriesExtremes = function () {
  522. var axis = this;
  523. var series = axis.series;
  524. var colorValArray,
  525. colorKey,
  526. colorValIndex,
  527. pointArrayMap,
  528. calculatedExtremes,
  529. cSeries,
  530. i = series.length,
  531. yData,
  532. j;
  533. this.dataMin = Infinity;
  534. this.dataMax = -Infinity;
  535. while (i--) { // x, y, value, other
  536. cSeries = series[i];
  537. colorKey = cSeries.colorKey = pick(cSeries.options.colorKey, cSeries.colorKey, cSeries.pointValKey, cSeries.zoneAxis, 'y');
  538. pointArrayMap = cSeries.pointArrayMap;
  539. calculatedExtremes = cSeries[colorKey + 'Min'] &&
  540. cSeries[colorKey + 'Max'];
  541. if (cSeries[colorKey + 'Data']) {
  542. colorValArray = cSeries[colorKey + 'Data'];
  543. }
  544. else {
  545. if (!pointArrayMap) {
  546. colorValArray = cSeries.yData;
  547. }
  548. else {
  549. colorValArray = [];
  550. colorValIndex = pointArrayMap.indexOf(colorKey);
  551. yData = cSeries.yData;
  552. if (colorValIndex >= 0 && yData) {
  553. for (j = 0; j < yData.length; j++) {
  554. colorValArray.push(pick(yData[j][colorValIndex], yData[j]));
  555. }
  556. }
  557. }
  558. }
  559. // If color key extremes are already calculated, use them.
  560. if (calculatedExtremes) {
  561. cSeries.minColorValue = cSeries[colorKey + 'Min'];
  562. cSeries.maxColorValue = cSeries[colorKey + 'Max'];
  563. }
  564. else {
  565. var cExtremes = Series.prototype.getExtremes.call(cSeries,
  566. colorValArray);
  567. cSeries.minColorValue = cExtremes.dataMin;
  568. cSeries.maxColorValue = cExtremes.dataMax;
  569. }
  570. if (typeof cSeries.minColorValue !== 'undefined') {
  571. this.dataMin =
  572. Math.min(this.dataMin, cSeries.minColorValue);
  573. this.dataMax =
  574. Math.max(this.dataMax, cSeries.maxColorValue);
  575. }
  576. if (!calculatedExtremes) {
  577. Series.prototype.applyExtremes.call(cSeries);
  578. }
  579. }
  580. };
  581. /**
  582. * Internal function to draw a crosshair.
  583. *
  584. * @function Highcharts.ColorAxis#drawCrosshair
  585. *
  586. * @param {Highcharts.PointerEventObject} [e]
  587. * The event arguments from the modified pointer event, extended with
  588. * `chartX` and `chartY`
  589. *
  590. * @param {Highcharts.Point} [point]
  591. * The Point object if the crosshair snaps to points.
  592. *
  593. * @fires Highcharts.ColorAxis#event:afterDrawCrosshair
  594. * @fires Highcharts.ColorAxis#event:drawCrosshair
  595. */
  596. ColorAxis.prototype.drawCrosshair = function (e, point) {
  597. var axis = this;
  598. var plotX = point && point.plotX;
  599. var plotY = point && point.plotY;
  600. var axisPos = axis.pos;
  601. var axisLen = axis.len;
  602. var crossPos;
  603. if (point) {
  604. crossPos = axis.toPixels(point.getNestedProperty(point.series.colorKey));
  605. if (crossPos < axisPos) {
  606. crossPos = axisPos - 2;
  607. }
  608. else if (crossPos > axisPos + axisLen) {
  609. crossPos = axisPos + axisLen + 2;
  610. }
  611. point.plotX = crossPos;
  612. point.plotY = axis.len - crossPos;
  613. _super.prototype.drawCrosshair.call(this, e, point);
  614. point.plotX = plotX;
  615. point.plotY = plotY;
  616. if (axis.cross &&
  617. !axis.cross.addedToColorAxis &&
  618. axis.legendGroup) {
  619. axis.cross
  620. .addClass('highcharts-coloraxis-marker')
  621. .add(axis.legendGroup);
  622. axis.cross.addedToColorAxis = true;
  623. if (!axis.chart.styledMode &&
  624. axis.crosshair) {
  625. axis.cross.attr({
  626. fill: axis.crosshair.color
  627. });
  628. }
  629. }
  630. }
  631. };
  632. /**
  633. * @private
  634. */
  635. ColorAxis.prototype.getPlotLinePath = function (options) {
  636. var axis = this,
  637. left = axis.left,
  638. pos = options.translatedValue,
  639. top = axis.top;
  640. // crosshairs only
  641. return isNumber(pos) ? // pos can be 0 (#3969)
  642. (axis.horiz ? [
  643. ['M', pos - 4, top - 6],
  644. ['L', pos + 4, top - 6],
  645. ['L', pos, top],
  646. ['Z']
  647. ] : [
  648. ['M', left, pos],
  649. ['L', left - 6, pos + 6],
  650. ['L', left - 6, pos - 6],
  651. ['Z']
  652. ]) :
  653. _super.prototype.getPlotLinePath.call(this, options);
  654. };
  655. /**
  656. * Updates a color axis instance with a new set of options. The options are
  657. * merged with the existing options, so only new or altered options need to
  658. * be specified.
  659. *
  660. * @function Highcharts.ColorAxis#update
  661. *
  662. * @param {Highcharts.ColorAxisOptions} newOptions
  663. * The new options that will be merged in with existing options on the color
  664. * axis.
  665. *
  666. * @param {boolean} [redraw]
  667. * Whether to redraw the chart after the color axis is altered. If doing
  668. * more operations on the chart, it is a good idea to set redraw to `false`
  669. * and call {@link Highcharts.Chart#redraw} after.
  670. */
  671. ColorAxis.prototype.update = function (newOptions, redraw) {
  672. var axis = this,
  673. chart = axis.chart,
  674. legend = chart.legend,
  675. updatedOptions = ColorAxis.buildOptions(chart, {},
  676. newOptions);
  677. this.series.forEach(function (series) {
  678. // Needed for Axis.update when choropleth colors change
  679. series.isDirtyData = true;
  680. });
  681. // When updating data classes, destroy old items and make sure new
  682. // ones are created (#3207)
  683. if (newOptions.dataClasses && legend.allItems || axis.dataClasses) {
  684. axis.destroyItems();
  685. }
  686. // Keep the options structure updated for export. Unlike xAxis and
  687. // yAxis, the colorAxis is not an array. (#3207)
  688. chart.options[axis.coll] =
  689. merge(axis.userOptions, updatedOptions);
  690. _super.prototype.update.call(this, updatedOptions, redraw);
  691. if (axis.legendItem) {
  692. axis.setLegendColor();
  693. legend.colorizeItem(this, true);
  694. }
  695. };
  696. /**
  697. * Destroy color axis legend items.
  698. * @private
  699. */
  700. ColorAxis.prototype.destroyItems = function () {
  701. var axis = this;
  702. var chart = axis.chart;
  703. if (axis.legendItem) {
  704. chart.legend.destroyItem(axis);
  705. }
  706. else if (axis.legendItems) {
  707. axis.legendItems.forEach(function (item) {
  708. chart.legend.destroyItem(item);
  709. });
  710. }
  711. chart.isDirtyLegend = true;
  712. };
  713. /**
  714. * Removes the color axis and the related legend item.
  715. *
  716. * @function Highcharts.ColorAxis#remove
  717. *
  718. * @param {boolean} [redraw=true]
  719. * Whether to redraw the chart following the remove.
  720. */
  721. ColorAxis.prototype.remove = function (redraw) {
  722. this.destroyItems();
  723. _super.prototype.remove.call(this, redraw);
  724. };
  725. /**
  726. * Get the legend item symbols for data classes.
  727. * @private
  728. */
  729. ColorAxis.prototype.getDataClassLegendSymbols = function () {
  730. var axis = this;
  731. var chart = axis.chart;
  732. var legendItems = axis.legendItems;
  733. var legendOptions = chart.options.legend;
  734. var valueDecimals = legendOptions.valueDecimals;
  735. var valueSuffix = legendOptions.valueSuffix || '';
  736. var name;
  737. if (!legendItems.length) {
  738. axis.dataClasses.forEach(function (dataClass, i) {
  739. var vis = true,
  740. from = dataClass.from,
  741. to = dataClass.to;
  742. var numberFormatter = chart.numberFormatter;
  743. // Assemble the default name. This can be overridden
  744. // by legend.options.labelFormatter
  745. name = '';
  746. if (typeof from === 'undefined') {
  747. name = '< ';
  748. }
  749. else if (typeof to === 'undefined') {
  750. name = '> ';
  751. }
  752. if (typeof from !== 'undefined') {
  753. name += numberFormatter(from, valueDecimals) + valueSuffix;
  754. }
  755. if (typeof from !== 'undefined' && typeof to !== 'undefined') {
  756. name += ' - ';
  757. }
  758. if (typeof to !== 'undefined') {
  759. name += numberFormatter(to, valueDecimals) + valueSuffix;
  760. }
  761. // Add a mock object to the legend items
  762. legendItems.push(extend({
  763. chart: chart,
  764. name: name,
  765. options: {},
  766. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  767. visible: true,
  768. setState: noop,
  769. isDataClass: true,
  770. setVisible: function () {
  771. vis = axis.visible = !vis;
  772. axis.series.forEach(function (series) {
  773. series.points.forEach(function (point) {
  774. if (point.dataClass === i) {
  775. point.setVisible(vis);
  776. }
  777. });
  778. });
  779. chart.legend.colorizeItem(this, vis);
  780. }
  781. }, dataClass));
  782. });
  783. }
  784. return legendItems;
  785. };
  786. /* *
  787. *
  788. * Static Functions
  789. *
  790. * */
  791. ColorAxis.defaultLegendLength = 200;
  792. /**
  793. * A color axis for series. Visually, the color
  794. * axis will appear as a gradient or as separate items inside the
  795. * legend, depending on whether the axis is scalar or based on data
  796. * classes.
  797. *
  798. * For supported color formats, see the
  799. * [docs article about colors](https://www.highcharts.com/docs/chart-design-and-style/colors).
  800. *
  801. * A scalar color axis is represented by a gradient. The colors either
  802. * range between the [minColor](#colorAxis.minColor) and the
  803. * [maxColor](#colorAxis.maxColor), or for more fine grained control the
  804. * colors can be defined in [stops](#colorAxis.stops). Often times, the
  805. * color axis needs to be adjusted to get the right color spread for the
  806. * data. In addition to stops, consider using a logarithmic
  807. * [axis type](#colorAxis.type), or setting [min](#colorAxis.min) and
  808. * [max](#colorAxis.max) to avoid the colors being determined by
  809. * outliers.
  810. *
  811. * When [dataClasses](#colorAxis.dataClasses) are used, the ranges are
  812. * subdivided into separate classes like categories based on their
  813. * values. This can be used for ranges between two values, but also for
  814. * a true category. However, when your data is categorized, it may be as
  815. * convenient to add each category to a separate series.
  816. *
  817. * Color axis does not work with: `sankey`, `sunburst`, `dependencywheel`,
  818. * `networkgraph`, `wordcloud`, `venn`, `gauge` and `solidgauge` series
  819. * types.
  820. *
  821. * Since v7.2.0 `colorAxis` can also be an array of options objects.
  822. *
  823. * See [the Axis object](/class-reference/Highcharts.Axis) for
  824. * programmatic access to the axis.
  825. *
  826. * @sample {highcharts} highcharts/coloraxis/custom-color-key
  827. * Column chart with color axis
  828. * @sample {highcharts} highcharts/coloraxis/horizontal-layout
  829. * Horizontal layout
  830. * @sample {highmaps} maps/coloraxis/dataclasscolor
  831. * With data classes
  832. * @sample {highmaps} maps/coloraxis/mincolor-maxcolor
  833. * Min color and max color
  834. *
  835. * @extends xAxis
  836. * @excluding alignTicks, allowDecimals, alternateGridColor, breaks,
  837. * categories, crosshair, dateTimeLabelFormats, height, left,
  838. * lineWidth, linkedTo, maxZoom, minRange, minTickInterval,
  839. * offset, opposite, pane, plotBands, plotLines,
  840. * reversedStacks, showEmpty, title, top, width, zoomEnabled
  841. * @product highcharts highstock highmaps
  842. * @type {*|Array<*>}
  843. * @optionparent colorAxis
  844. * @ignore
  845. */
  846. ColorAxis.defaultOptions = {
  847. /**
  848. * Whether to allow decimals on the color axis.
  849. * @type {boolean}
  850. * @default true
  851. * @product highcharts highstock highmaps
  852. * @apioption colorAxis.allowDecimals
  853. */
  854. /**
  855. * Determines how to set each data class' color if no individual
  856. * color is set. The default value, `tween`, computes intermediate
  857. * colors between `minColor` and `maxColor`. The other possible
  858. * value, `category`, pulls colors from the global or chart specific
  859. * [colors](#colors) array.
  860. *
  861. * @sample {highmaps} maps/coloraxis/dataclasscolor/
  862. * Category colors
  863. *
  864. * @type {string}
  865. * @default tween
  866. * @product highcharts highstock highmaps
  867. * @validvalue ["tween", "category"]
  868. * @apioption colorAxis.dataClassColor
  869. */
  870. /**
  871. * An array of data classes or ranges for the choropleth map. If
  872. * none given, the color axis is scalar and values are distributed
  873. * as a gradient between the minimum and maximum colors.
  874. *
  875. * @sample {highmaps} maps/demo/data-class-ranges/
  876. * Multiple ranges
  877. *
  878. * @sample {highmaps} maps/demo/data-class-two-ranges/
  879. * Two ranges
  880. *
  881. * @type {Array<*>}
  882. * @product highcharts highstock highmaps
  883. * @apioption colorAxis.dataClasses
  884. */
  885. /**
  886. * The layout of the color axis. Can be `'horizontal'` or `'vertical'`.
  887. * If none given, the color axis has the same layout as the legend.
  888. *
  889. * @sample highcharts/coloraxis/horizontal-layout/
  890. * Horizontal color axis layout with vertical legend
  891. *
  892. * @type {string|undefined}
  893. * @since 7.2.0
  894. * @product highcharts highstock highmaps
  895. * @apioption colorAxis.layout
  896. */
  897. /**
  898. * The color of each data class. If not set, the color is pulled
  899. * from the global or chart-specific [colors](#colors) array. In
  900. * styled mode, this option is ignored. Instead, use colors defined
  901. * in CSS.
  902. *
  903. * @sample {highmaps} maps/demo/data-class-two-ranges/
  904. * Explicit colors
  905. *
  906. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  907. * @product highcharts highstock highmaps
  908. * @apioption colorAxis.dataClasses.color
  909. */
  910. /**
  911. * The start of the value range that the data class represents,
  912. * relating to the point value.
  913. *
  914. * The range of each `dataClass` is closed in both ends, but can be
  915. * overridden by the next `dataClass`.
  916. *
  917. * @type {number}
  918. * @product highcharts highstock highmaps
  919. * @apioption colorAxis.dataClasses.from
  920. */
  921. /**
  922. * The name of the data class as it appears in the legend.
  923. * If no name is given, it is automatically created based on the
  924. * `from` and `to` values. For full programmatic control,
  925. * [legend.labelFormatter](#legend.labelFormatter) can be used.
  926. * In the formatter, `this.from` and `this.to` can be accessed.
  927. *
  928. * @sample {highmaps} maps/coloraxis/dataclasses-name/
  929. * Named data classes
  930. *
  931. * @sample {highmaps} maps/coloraxis/dataclasses-labelformatter/
  932. * Formatted data classes
  933. *
  934. * @type {string}
  935. * @product highcharts highstock highmaps
  936. * @apioption colorAxis.dataClasses.name
  937. */
  938. /**
  939. * The end of the value range that the data class represents,
  940. * relating to the point value.
  941. *
  942. * The range of each `dataClass` is closed in both ends, but can be
  943. * overridden by the next `dataClass`.
  944. *
  945. * @type {number}
  946. * @product highcharts highstock highmaps
  947. * @apioption colorAxis.dataClasses.to
  948. */
  949. /** @ignore-option */
  950. lineWidth: 0,
  951. /**
  952. * Padding of the min value relative to the length of the axis. A
  953. * padding of 0.05 will make a 100px axis 5px longer.
  954. *
  955. * @product highcharts highstock highmaps
  956. */
  957. minPadding: 0,
  958. /**
  959. * The maximum value of the axis in terms of map point values. If
  960. * `null`, the max value is automatically calculated. If the
  961. * `endOnTick` option is true, the max value might be rounded up.
  962. *
  963. * @sample {highmaps} maps/coloraxis/gridlines/
  964. * Explicit min and max to reduce the effect of outliers
  965. *
  966. * @type {number}
  967. * @product highcharts highstock highmaps
  968. * @apioption colorAxis.max
  969. */
  970. /**
  971. * The minimum value of the axis in terms of map point values. If
  972. * `null`, the min value is automatically calculated. If the
  973. * `startOnTick` option is true, the min value might be rounded
  974. * down.
  975. *
  976. * @sample {highmaps} maps/coloraxis/gridlines/
  977. * Explicit min and max to reduce the effect of outliers
  978. *
  979. * @type {number}
  980. * @product highcharts highstock highmaps
  981. * @apioption colorAxis.min
  982. */
  983. /**
  984. * Padding of the max value relative to the length of the axis. A
  985. * padding of 0.05 will make a 100px axis 5px longer.
  986. *
  987. * @product highcharts highstock highmaps
  988. */
  989. maxPadding: 0,
  990. /**
  991. * Color of the grid lines extending from the axis across the
  992. * gradient.
  993. *
  994. * @sample {highmaps} maps/coloraxis/gridlines/
  995. * Grid lines demonstrated
  996. *
  997. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  998. * @default #e6e6e6
  999. * @product highcharts highstock highmaps
  1000. * @apioption colorAxis.gridLineColor
  1001. */
  1002. /**
  1003. * The width of the grid lines extending from the axis across the
  1004. * gradient of a scalar color axis.
  1005. *
  1006. * @sample {highmaps} maps/coloraxis/gridlines/
  1007. * Grid lines demonstrated
  1008. *
  1009. * @product highcharts highstock highmaps
  1010. */
  1011. gridLineWidth: 1,
  1012. /**
  1013. * The interval of the tick marks in axis units. When `null`, the
  1014. * tick interval is computed to approximately follow the
  1015. * `tickPixelInterval`.
  1016. *
  1017. * @type {number}
  1018. * @product highcharts highstock highmaps
  1019. * @apioption colorAxis.tickInterval
  1020. */
  1021. /**
  1022. * If [tickInterval](#colorAxis.tickInterval) is `null` this option
  1023. * sets the approximate pixel interval of the tick marks.
  1024. *
  1025. * @product highcharts highstock highmaps
  1026. */
  1027. tickPixelInterval: 72,
  1028. /**
  1029. * Whether to force the axis to start on a tick. Use this option
  1030. * with the `maxPadding` option to control the axis start.
  1031. *
  1032. * @product highcharts highstock highmaps
  1033. */
  1034. startOnTick: true,
  1035. /**
  1036. * Whether to force the axis to end on a tick. Use this option with
  1037. * the [maxPadding](#colorAxis.maxPadding) option to control the
  1038. * axis end.
  1039. *
  1040. * @product highcharts highstock highmaps
  1041. */
  1042. endOnTick: true,
  1043. /** @ignore */
  1044. offset: 0,
  1045. /**
  1046. * The triangular marker on a scalar color axis that points to the
  1047. * value of the hovered area. To disable the marker, set
  1048. * `marker: null`.
  1049. *
  1050. * @sample {highmaps} maps/coloraxis/marker/
  1051. * Black marker
  1052. *
  1053. * @declare Highcharts.PointMarkerOptionsObject
  1054. * @product highcharts highstock highmaps
  1055. */
  1056. marker: {
  1057. /**
  1058. * Animation for the marker as it moves between values. Set to
  1059. * `false` to disable animation. Defaults to `{ duration: 50 }`.
  1060. *
  1061. * @type {boolean|Partial<Highcharts.AnimationOptionsObject>}
  1062. * @product highcharts highstock highmaps
  1063. */
  1064. animation: {
  1065. /** @internal */
  1066. duration: 50
  1067. },
  1068. /** @internal */
  1069. width: 0.01,
  1070. /**
  1071. * The color of the marker.
  1072. *
  1073. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1074. * @product highcharts highstock highmaps
  1075. */
  1076. color: '#999999'
  1077. },
  1078. /**
  1079. * The axis labels show the number for each tick.
  1080. *
  1081. * For more live examples on label options, see [xAxis.labels in the
  1082. * Highcharts API.](/highcharts#xAxis.labels)
  1083. *
  1084. * @extends xAxis.labels
  1085. * @product highcharts highstock highmaps
  1086. */
  1087. labels: {
  1088. /**
  1089. * How to handle overflowing labels on horizontal color axis. If set
  1090. * to `"allow"`, it will not be aligned at all. By default it
  1091. * `"justify"` labels inside the chart area. If there is room to
  1092. * move it, it will be aligned to the edge, else it will be removed.
  1093. *
  1094. * @validvalue ["allow", "justify"]
  1095. * @product highcharts highstock highmaps
  1096. */
  1097. overflow: 'justify',
  1098. rotation: 0
  1099. },
  1100. /**
  1101. * The color to represent the minimum of the color axis. Unless
  1102. * [dataClasses](#colorAxis.dataClasses) or
  1103. * [stops](#colorAxis.stops) are set, the gradient starts at this
  1104. * value.
  1105. *
  1106. * If dataClasses are set, the color is based on minColor and
  1107. * maxColor unless a color is set for each data class, or the
  1108. * [dataClassColor](#colorAxis.dataClassColor) is set.
  1109. *
  1110. * @sample {highmaps} maps/coloraxis/mincolor-maxcolor/
  1111. * Min and max colors on scalar (gradient) axis
  1112. * @sample {highmaps} maps/coloraxis/mincolor-maxcolor-dataclasses/
  1113. * On data classes
  1114. *
  1115. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1116. * @product highcharts highstock highmaps
  1117. */
  1118. minColor: '#e6ebf5',
  1119. /**
  1120. * The color to represent the maximum of the color axis. Unless
  1121. * [dataClasses](#colorAxis.dataClasses) or
  1122. * [stops](#colorAxis.stops) are set, the gradient ends at this
  1123. * value.
  1124. *
  1125. * If dataClasses are set, the color is based on minColor and
  1126. * maxColor unless a color is set for each data class, or the
  1127. * [dataClassColor](#colorAxis.dataClassColor) is set.
  1128. *
  1129. * @sample {highmaps} maps/coloraxis/mincolor-maxcolor/
  1130. * Min and max colors on scalar (gradient) axis
  1131. * @sample {highmaps} maps/coloraxis/mincolor-maxcolor-dataclasses/
  1132. * On data classes
  1133. *
  1134. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1135. * @product highcharts highstock highmaps
  1136. */
  1137. maxColor: '#003399',
  1138. /**
  1139. * Color stops for the gradient of a scalar color axis. Use this in
  1140. * cases where a linear gradient between a `minColor` and `maxColor`
  1141. * is not sufficient. The stops is an array of tuples, where the
  1142. * first item is a float between 0 and 1 assigning the relative
  1143. * position in the gradient, and the second item is the color.
  1144. *
  1145. * @sample {highmaps} maps/demo/heatmap/
  1146. * Heatmap with three color stops
  1147. *
  1148. * @type {Array<Array<number,Highcharts.ColorString>>}
  1149. * @product highcharts highstock highmaps
  1150. * @apioption colorAxis.stops
  1151. */
  1152. /**
  1153. * The pixel length of the main tick marks on the color axis.
  1154. */
  1155. tickLength: 5,
  1156. /**
  1157. * The type of interpolation to use for the color axis. Can be
  1158. * `linear` or `logarithmic`.
  1159. *
  1160. * @sample highcharts/coloraxis/logarithmic-with-emulate-negative-values/
  1161. * Logarithmic color axis with extension to emulate negative
  1162. * values
  1163. *
  1164. * @type {Highcharts.ColorAxisTypeValue}
  1165. * @default linear
  1166. * @product highcharts highstock highmaps
  1167. * @apioption colorAxis.type
  1168. */
  1169. /**
  1170. * Whether to reverse the axis so that the highest number is closest
  1171. * to the origin. Defaults to `false` in a horizontal legend and
  1172. * `true` in a vertical legend, where the smallest value starts on
  1173. * top.
  1174. *
  1175. * @type {boolean}
  1176. * @product highcharts highstock highmaps
  1177. * @apioption colorAxis.reversed
  1178. */
  1179. /**
  1180. * @product highcharts highstock highmaps
  1181. * @excluding afterBreaks, pointBreak, pointInBreak
  1182. * @apioption colorAxis.events
  1183. */
  1184. /**
  1185. * Fires when the legend item belonging to the colorAxis is clicked.
  1186. * One parameter, `event`, is passed to the function.
  1187. *
  1188. * @type {Function}
  1189. * @product highcharts highstock highmaps
  1190. * @apioption colorAxis.events.legendItemClick
  1191. */
  1192. /**
  1193. * Whether to display the colorAxis in the legend.
  1194. *
  1195. * @sample highcharts/coloraxis/hidden-coloraxis-with-3d-chart/
  1196. * Hidden color axis with 3d chart
  1197. *
  1198. * @see [heatmap.showInLegend](#series.heatmap.showInLegend)
  1199. *
  1200. * @since 4.2.7
  1201. * @product highcharts highstock highmaps
  1202. */
  1203. showInLegend: true
  1204. };
  1205. /**
  1206. * @private
  1207. */
  1208. ColorAxis.keepProps = [
  1209. 'legendGroup',
  1210. 'legendItemHeight',
  1211. 'legendItemWidth',
  1212. 'legendItem',
  1213. 'legendSymbol'
  1214. ];
  1215. return ColorAxis;
  1216. }(Axis));
  1217. // Properties to preserve after destroy, for Axis.update (#5881, #6025).
  1218. Array.prototype.push.apply(Axis.keepProps, ColorAxis.keepProps);
  1219. H.ColorAxis = ColorAxis;
  1220. /**
  1221. * Handle animation of the color attributes directly
  1222. *
  1223. * @private
  1224. * @function Highcharts.Fx#fillSetter
  1225. */ /**
  1226. * Handle animation of the color attributes directly
  1227. *
  1228. * @private
  1229. * @function Highcharts.Fx#strokeSetter
  1230. */
  1231. ['fill', 'stroke'].forEach(function (prop) {
  1232. Fx.prototype[prop + 'Setter'] = function () {
  1233. this.elem.attr(prop, color(this.start).tweenTo(color(this.end), this.pos), null, true);
  1234. };
  1235. });
  1236. // Extend the chart getAxes method to also get the color axis
  1237. addEvent(Chart, 'afterGetAxes', function () {
  1238. var chart = this,
  1239. options = chart.options;
  1240. this.colorAxis = [];
  1241. if (options.colorAxis) {
  1242. options.colorAxis = splat(options.colorAxis);
  1243. options.colorAxis.forEach(function (axisOptions, i) {
  1244. axisOptions.index = i;
  1245. new ColorAxis(chart, axisOptions); // eslint-disable-line no-new
  1246. });
  1247. }
  1248. });
  1249. // Add colorAxis to series axisTypes
  1250. addEvent(Series, 'bindAxes', function () {
  1251. var axisTypes = this.axisTypes;
  1252. if (!axisTypes) {
  1253. this.axisTypes = ['colorAxis'];
  1254. }
  1255. else if (axisTypes.indexOf('colorAxis') === -1) {
  1256. axisTypes.push('colorAxis');
  1257. }
  1258. });
  1259. // Add the color axis. This also removes the axis' own series to prevent
  1260. // them from showing up individually.
  1261. addEvent(Legend, 'afterGetAllItems', function (e) {
  1262. var colorAxisItems = [],
  1263. colorAxes = this.chart.colorAxis || [],
  1264. options,
  1265. i;
  1266. colorAxes.forEach(function (colorAxis) {
  1267. options = colorAxis.options;
  1268. if (options && options.showInLegend) {
  1269. // Data classes
  1270. if (options.dataClasses && options.visible) {
  1271. colorAxisItems = colorAxisItems.concat(colorAxis.getDataClassLegendSymbols());
  1272. // Gradient legend
  1273. }
  1274. else if (options.visible) {
  1275. // Add this axis on top
  1276. colorAxisItems.push(colorAxis);
  1277. }
  1278. // If dataClasses are defined or showInLegend option is not set to
  1279. // true, do not add color axis' series to legend.
  1280. colorAxis.series.forEach(function (series) {
  1281. if (!series.options.showInLegend || options.dataClasses) {
  1282. if (series.options.legendType === 'point') {
  1283. series.points.forEach(function (point) {
  1284. erase(e.allItems, point);
  1285. });
  1286. }
  1287. else {
  1288. erase(e.allItems, series);
  1289. }
  1290. }
  1291. });
  1292. }
  1293. });
  1294. i = colorAxisItems.length;
  1295. while (i--) {
  1296. e.allItems.unshift(colorAxisItems[i]);
  1297. }
  1298. });
  1299. addEvent(Legend, 'afterColorizeItem', function (e) {
  1300. if (e.visible && e.item.legendColor) {
  1301. e.item.legendSymbol.attr({
  1302. fill: e.item.legendColor
  1303. });
  1304. }
  1305. });
  1306. // Updates in the legend need to be reflected in the color axis (6888)
  1307. addEvent(Legend, 'afterUpdate', function () {
  1308. var colorAxes = this.chart.colorAxis;
  1309. if (colorAxes) {
  1310. colorAxes.forEach(function (colorAxis) {
  1311. colorAxis.update({}, arguments[2]);
  1312. });
  1313. }
  1314. });
  1315. // Calculate and set colors for points
  1316. addEvent(Series, 'afterTranslate', function () {
  1317. if (this.chart.colorAxis &&
  1318. this.chart.colorAxis.length ||
  1319. this.colorAttribs) {
  1320. this.translateColors();
  1321. }
  1322. });
  1323. return ColorAxis;
  1324. });
  1325. _registerModule(_modules, 'masters/modules/coloraxis.src.js', [], function () {
  1326. });
  1327. }));