tilemap.src.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. /**
  2. * @license Highmaps JS v9.1.1 (2021-06-04)
  3. *
  4. * Tilemap module
  5. *
  6. * (c) 2010-2021 Highsoft AS
  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/tilemap', ['highcharts', 'highcharts/modules/map'], 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, 'Series/Tilemap/TilemapPoint.js', [_modules['Mixins/ColorSeries.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (ColorSeriesModule, SeriesRegistry, U) {
  32. /* *
  33. *
  34. * Tilemaps module
  35. *
  36. * (c) 2010-2021 Highsoft AS
  37. * Author: Øystein Moseng
  38. *
  39. * License: www.highcharts.com/license
  40. *
  41. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  42. *
  43. * */
  44. var __extends = (this && this.__extends) || (function () {
  45. var extendStatics = function (d,
  46. b) {
  47. extendStatics = Object.setPrototypeOf ||
  48. ({ __proto__: [] } instanceof Array && function (d,
  49. b) { d.__proto__ = b; }) ||
  50. function (d,
  51. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  52. return extendStatics(d, b);
  53. };
  54. return function (d, b) {
  55. extendStatics(d, b);
  56. function __() { this.constructor = d; }
  57. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  58. };
  59. })();
  60. var colorPointMixin = ColorSeriesModule.colorPointMixin;
  61. var Point = SeriesRegistry.series.prototype.pointClass,
  62. HeatmapPoint = SeriesRegistry.seriesTypes.heatmap.prototype.pointClass;
  63. var extend = U.extend;
  64. /* *
  65. *
  66. * Class
  67. *
  68. * */
  69. var TilemapPoint = /** @class */ (function (_super) {
  70. __extends(TilemapPoint, _super);
  71. function TilemapPoint() {
  72. /* *
  73. *
  74. * Properties
  75. *
  76. * */
  77. var _this = _super !== null && _super.apply(this,
  78. arguments) || this;
  79. _this.options = void 0;
  80. _this.radius = void 0;
  81. _this.series = void 0;
  82. _this.tileEdges = void 0;
  83. return _this;
  84. /* eslint-enable valid-jsdoc */
  85. }
  86. /* *
  87. *
  88. * Functions
  89. *
  90. * */
  91. /* eslint-disable valid-jsdoc */
  92. /**
  93. * @private
  94. * @function Highcharts.Point#haloPath
  95. *
  96. * @return {Highcharts.SVGElement|Highcharts.SVGPathArray|Array<Highcharts.SVGElement>}
  97. */
  98. TilemapPoint.prototype.haloPath = function () {
  99. return this.series.tileShape.haloPath.apply(this, arguments);
  100. };
  101. return TilemapPoint;
  102. }(HeatmapPoint));
  103. extend(TilemapPoint.prototype, {
  104. setState: Point.prototype.setState,
  105. setVisible: colorPointMixin.setVisible
  106. });
  107. /* *
  108. *
  109. * Default Export
  110. *
  111. * */
  112. return TilemapPoint;
  113. });
  114. _registerModule(_modules, 'Series/Tilemap/TilemapShapes.js', [_modules['Core/Globals.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (H, SeriesRegistry, U) {
  115. /* *
  116. *
  117. * Tilemaps module
  118. *
  119. * (c) 2010-2021 Highsoft AS
  120. * Author: Øystein Moseng
  121. *
  122. * License: www.highcharts.com/license
  123. *
  124. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  125. *
  126. * */
  127. var noop = H.noop;
  128. var _a = SeriesRegistry.seriesTypes,
  129. HeatmapSeries = _a.heatmap,
  130. ScatterSeries = _a.scatter;
  131. var clamp = U.clamp,
  132. pick = U.pick;
  133. /**
  134. * Utility func to get padding definition from tile size division
  135. * @private
  136. * @param {Highcharts.TilemapSeries} series
  137. * series
  138. * @param {Highcharts.number} xDiv
  139. * xDiv
  140. * @param {Highcharts.number} yDiv
  141. * yDiv
  142. * @return {Highcharts.TilemapPaddingObject}
  143. */
  144. function tilePaddingFromTileSize(series, xDiv, yDiv) {
  145. var options = series.options;
  146. return {
  147. xPad: (options.colsize || 1) / -xDiv,
  148. yPad: (options.rowsize || 1) / -yDiv
  149. };
  150. }
  151. /* *
  152. *
  153. * Registry
  154. *
  155. * */
  156. /**
  157. * Map of shape types.
  158. * @private
  159. */
  160. var TilemapShapes = {
  161. // Hexagon shape type.
  162. hexagon: {
  163. alignDataLabel: ScatterSeries.prototype.alignDataLabel,
  164. getSeriesPadding: function (series) {
  165. return tilePaddingFromTileSize(series, 3, 2);
  166. },
  167. haloPath: function (size) {
  168. if (!size) {
  169. return [];
  170. }
  171. var hexagon = this.tileEdges;
  172. return [
  173. ['M', hexagon.x2 - size, hexagon.y1 + size],
  174. ['L', hexagon.x3 + size, hexagon.y1 + size],
  175. ['L', hexagon.x4 + size * 1.5, hexagon.y2],
  176. ['L', hexagon.x3 + size, hexagon.y3 - size],
  177. ['L', hexagon.x2 - size, hexagon.y3 - size],
  178. ['L', hexagon.x1 - size * 1.5, hexagon.y2],
  179. ['Z']
  180. ];
  181. },
  182. translate: function () {
  183. var series = this,
  184. options = series.options,
  185. xAxis = series.xAxis,
  186. yAxis = series.yAxis,
  187. seriesPointPadding = options.pointPadding || 0,
  188. xPad = (options.colsize || 1) / 3,
  189. yPad = (options.rowsize || 1) / 2,
  190. yShift;
  191. series.generatePoints();
  192. series.points.forEach(function (point) {
  193. var x1 = clamp(Math.floor(xAxis.len -
  194. xAxis.translate(point.x - xPad * 2, 0, 1, 0, 1)), -xAxis.len, 2 * xAxis.len),
  195. x2 = clamp(Math.floor(xAxis.len -
  196. xAxis.translate(point.x - xPad, 0, 1, 0, 1)), -xAxis.len, 2 * xAxis.len),
  197. x3 = clamp(Math.floor(xAxis.len -
  198. xAxis.translate(point.x + xPad, 0, 1, 0, 1)), -xAxis.len, 2 * xAxis.len),
  199. x4 = clamp(Math.floor(xAxis.len -
  200. xAxis.translate(point.x + xPad * 2, 0, 1, 0, 1)), -xAxis.len, 2 * xAxis.len),
  201. y1 = clamp(Math.floor(yAxis.translate(point.y - yPad, 0, 1, 0, 1)), -yAxis.len, 2 * yAxis.len),
  202. y2 = clamp(Math.floor(yAxis.translate(point.y, 0, 1, 0, 1)), -yAxis.len, 2 * yAxis.len),
  203. y3 = clamp(Math.floor(yAxis.translate(point.y + yPad, 0, 1, 0, 1)), -yAxis.len, 2 * yAxis.len),
  204. pointPadding = pick(point.pointPadding,
  205. seriesPointPadding),
  206. // We calculate the point padding of the midpoints to
  207. // preserve the angles of the shape.
  208. midPointPadding = pointPadding *
  209. Math.abs(x2 - x1) / Math.abs(y3 - y2),
  210. xMidPadding = xAxis.reversed ?
  211. -midPointPadding : midPointPadding,
  212. xPointPadding = xAxis.reversed ?
  213. -pointPadding : pointPadding,
  214. yPointPadding = yAxis.reversed ?
  215. -pointPadding : pointPadding;
  216. // Shift y-values for every second grid column
  217. if (point.x % 2) {
  218. yShift = yShift || Math.round(Math.abs(y3 - y1) / 2) *
  219. // We have to reverse the shift for reversed y-axes
  220. (yAxis.reversed ? -1 : 1);
  221. y1 += yShift;
  222. y2 += yShift;
  223. y3 += yShift;
  224. }
  225. // Set plotX and plotY for use in K-D-Tree and more
  226. point.plotX = point.clientX = (x2 + x3) / 2;
  227. point.plotY = y2;
  228. // Apply point padding to translated coordinates
  229. x1 += xMidPadding + xPointPadding;
  230. x2 += xPointPadding;
  231. x3 -= xPointPadding;
  232. x4 -= xMidPadding + xPointPadding;
  233. y1 -= yPointPadding;
  234. y3 += yPointPadding;
  235. // Store points for halo creation
  236. point.tileEdges = {
  237. x1: x1, x2: x2, x3: x3, x4: x4, y1: y1, y2: y2, y3: y3
  238. };
  239. // Finally set the shape for this point
  240. point.shapeType = 'path';
  241. point.shapeArgs = {
  242. d: [
  243. ['M', x2, y1],
  244. ['L', x3, y1],
  245. ['L', x4, y2],
  246. ['L', x3, y3],
  247. ['L', x2, y3],
  248. ['L', x1, y2],
  249. ['Z']
  250. ]
  251. };
  252. });
  253. series.translateColors();
  254. }
  255. },
  256. // Diamond shape type.
  257. diamond: {
  258. alignDataLabel: ScatterSeries.prototype.alignDataLabel,
  259. getSeriesPadding: function (series) {
  260. return tilePaddingFromTileSize(series, 2, 2);
  261. },
  262. haloPath: function (size) {
  263. if (!size) {
  264. return [];
  265. }
  266. var diamond = this.tileEdges;
  267. return [
  268. ['M', diamond.x2, diamond.y1 + size],
  269. ['L', diamond.x3 + size, diamond.y2],
  270. ['L', diamond.x2, diamond.y3 - size],
  271. ['L', diamond.x1 - size, diamond.y2],
  272. ['Z']
  273. ];
  274. },
  275. translate: function () {
  276. var series = this,
  277. options = series.options,
  278. xAxis = series.xAxis,
  279. yAxis = series.yAxis,
  280. seriesPointPadding = options.pointPadding || 0,
  281. xPad = (options.colsize || 1),
  282. yPad = (options.rowsize || 1) / 2,
  283. yShift;
  284. series.generatePoints();
  285. series.points.forEach(function (point) {
  286. var x1 = clamp(Math.round(xAxis.len -
  287. xAxis.translate(point.x - xPad, 0, 1, 0, 0)), -xAxis.len, 2 * xAxis.len),
  288. x2 = clamp(Math.round(xAxis.len -
  289. xAxis.translate(point.x, 0, 1, 0, 0)), -xAxis.len, 2 * xAxis.len),
  290. x3 = clamp(Math.round(xAxis.len -
  291. xAxis.translate(point.x + xPad, 0, 1, 0, 0)), -xAxis.len, 2 * xAxis.len),
  292. y1 = clamp(Math.round(yAxis.translate(point.y - yPad, 0, 1, 0, 0)), -yAxis.len, 2 * yAxis.len),
  293. y2 = clamp(Math.round(yAxis.translate(point.y, 0, 1, 0, 0)), -yAxis.len, 2 * yAxis.len),
  294. y3 = clamp(Math.round(yAxis.translate(point.y + yPad, 0, 1, 0, 0)), -yAxis.len, 2 * yAxis.len),
  295. pointPadding = pick(point.pointPadding,
  296. seriesPointPadding),
  297. // We calculate the point padding of the midpoints to
  298. // preserve the angles of the shape.
  299. midPointPadding = pointPadding *
  300. Math.abs(x2 - x1) / Math.abs(y3 - y2),
  301. xPointPadding = xAxis.reversed ?
  302. -midPointPadding : midPointPadding,
  303. yPointPadding = yAxis.reversed ?
  304. -pointPadding : pointPadding;
  305. // Shift y-values for every second grid column
  306. // We have to reverse the shift for reversed y-axes
  307. if (point.x % 2) {
  308. yShift = Math.abs(y3 - y1) / 2 * (yAxis.reversed ? -1 : 1);
  309. y1 += yShift;
  310. y2 += yShift;
  311. y3 += yShift;
  312. }
  313. // Set plotX and plotY for use in K-D-Tree and more
  314. point.plotX = point.clientX = x2;
  315. point.plotY = y2;
  316. // Apply point padding to translated coordinates
  317. x1 += xPointPadding;
  318. x3 -= xPointPadding;
  319. y1 -= yPointPadding;
  320. y3 += yPointPadding;
  321. // Store points for halo creation
  322. point.tileEdges = {
  323. x1: x1, x2: x2, x3: x3, y1: y1, y2: y2, y3: y3
  324. };
  325. // Set this point's shape parameters
  326. point.shapeType = 'path';
  327. point.shapeArgs = {
  328. d: [
  329. ['M', x2, y1],
  330. ['L', x3, y2],
  331. ['L', x2, y3],
  332. ['L', x1, y2],
  333. ['Z']
  334. ]
  335. };
  336. });
  337. series.translateColors();
  338. }
  339. },
  340. // Circle shape type.
  341. circle: {
  342. alignDataLabel: ScatterSeries.prototype.alignDataLabel,
  343. getSeriesPadding: function (series) {
  344. return tilePaddingFromTileSize(series, 2, 2);
  345. },
  346. haloPath: function (size) {
  347. return ScatterSeries.prototype.pointClass.prototype.haloPath
  348. .call(this, size + (size && this.radius));
  349. },
  350. translate: function () {
  351. var series = this,
  352. options = series.options,
  353. xAxis = series.xAxis,
  354. yAxis = series.yAxis,
  355. seriesPointPadding = options.pointPadding || 0,
  356. yRadius = (options.rowsize || 1) / 2,
  357. colsize = (options.colsize || 1),
  358. colsizePx,
  359. yRadiusPx,
  360. xRadiusPx,
  361. radius,
  362. forceNextRadiusCompute = false;
  363. series.generatePoints();
  364. series.points.forEach(function (point) {
  365. var x = clamp(Math.round(xAxis.len -
  366. xAxis.translate(point.x, 0, 1, 0, 0)), -xAxis.len, 2 * xAxis.len),
  367. y = clamp(Math.round(yAxis.translate(point.y, 0, 1, 0, 0)), -yAxis.len, 2 * yAxis.len),
  368. pointPadding = seriesPointPadding,
  369. hasPerPointPadding = false;
  370. // If there is point padding defined on a single point, add it
  371. if (typeof point.pointPadding !== 'undefined') {
  372. pointPadding = point.pointPadding;
  373. hasPerPointPadding = true;
  374. forceNextRadiusCompute = true;
  375. }
  376. // Find radius if not found already.
  377. // Use the smallest one (x vs y) to avoid overlap.
  378. // Note that the radius will be recomputed for each series.
  379. // Ideal (max) x radius is dependent on y radius:
  380. /*
  381. * (circle 2)
  382. * (circle 3)
  383. | yRadiusPx
  384. (circle 1) *-------|
  385. colsizePx
  386. The distance between circle 1 and 3 (and circle 2 and 3) is
  387. 2r, which is the hypotenuse of the triangle created by
  388. colsizePx and yRadiusPx. If the distance between circle 2
  389. and circle 1 is less than 2r, we use half of that distance
  390. instead (yRadiusPx).
  391. */
  392. if (!radius || forceNextRadiusCompute) {
  393. colsizePx = Math.abs(clamp(Math.floor(xAxis.len -
  394. xAxis.translate(point.x + colsize, 0, 1, 0, 0)), -xAxis.len, 2 * xAxis.len) - x);
  395. yRadiusPx = Math.abs(clamp(Math.floor(yAxis.translate(point.y + yRadius, 0, 1, 0, 0)), -yAxis.len, 2 * yAxis.len) - y);
  396. xRadiusPx = Math.floor(Math.sqrt((colsizePx * colsizePx + yRadiusPx * yRadiusPx)) / 2);
  397. radius = Math.min(colsizePx, xRadiusPx, yRadiusPx) - pointPadding;
  398. // If we have per point padding we need to always compute
  399. // the radius for this point and the next. If we used to
  400. // have per point padding but don't anymore, don't force
  401. // compute next radius.
  402. if (forceNextRadiusCompute && !hasPerPointPadding) {
  403. forceNextRadiusCompute = false;
  404. }
  405. }
  406. // Shift y-values for every second grid column.
  407. // Note that we always use the optimal y axis radius for this.
  408. // Also note: We have to reverse the shift for reversed y-axes.
  409. if (point.x % 2) {
  410. y += yRadiusPx * (yAxis.reversed ? -1 : 1);
  411. }
  412. // Set plotX and plotY for use in K-D-Tree and more
  413. point.plotX = point.clientX = x;
  414. point.plotY = y;
  415. // Save radius for halo
  416. point.radius = radius;
  417. // Set this point's shape parameters
  418. point.shapeType = 'circle';
  419. point.shapeArgs = {
  420. x: x,
  421. y: y,
  422. r: radius
  423. };
  424. });
  425. series.translateColors();
  426. }
  427. },
  428. // Square shape type.
  429. square: {
  430. alignDataLabel: HeatmapSeries.prototype.alignDataLabel,
  431. translate: HeatmapSeries.prototype.translate,
  432. getSeriesPadding: noop,
  433. haloPath: HeatmapSeries.prototype.pointClass.prototype.haloPath
  434. }
  435. };
  436. /* *
  437. *
  438. * Default Export
  439. *
  440. * */
  441. return TilemapShapes;
  442. });
  443. _registerModule(_modules, 'Series/Tilemap/TilemapComposition.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Utilities.js']], function (Axis, U) {
  444. /* *
  445. *
  446. * Tilemaps module
  447. *
  448. * (c) 2010-2021 Highsoft AS
  449. * Author: Øystein Moseng
  450. *
  451. * License: www.highcharts.com/license
  452. *
  453. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  454. *
  455. * */
  456. /* *
  457. *
  458. * Imports
  459. *
  460. * */
  461. var addEvent = U.addEvent;
  462. /* *
  463. *
  464. * Composition
  465. *
  466. * */
  467. /* eslint-disable no-invalid-this */
  468. // Extension to add pixel padding for series. Uses getSeriesPixelPadding on each
  469. // series and adds the largest padding required. If no series has this function
  470. // defined, we add nothing.
  471. addEvent(Axis, 'afterSetAxisTranslation', function () {
  472. if (this.recomputingForTilemap || this.coll === 'colorAxis') {
  473. return;
  474. }
  475. var axis = this,
  476. // Find which series' padding to use
  477. seriesPadding = axis.series
  478. .map(function (series) {
  479. return series.getSeriesPixelPadding &&
  480. series.getSeriesPixelPadding(axis);
  481. })
  482. .reduce(function (a, b) {
  483. return (a && a.padding) > (b && b.padding) ?
  484. a :
  485. b;
  486. }, void 0) ||
  487. {
  488. padding: 0,
  489. axisLengthFactor: 1
  490. }, lengthPadding = Math.round(seriesPadding.padding * seriesPadding.axisLengthFactor);
  491. // Don't waste time on this if we're not adding extra padding
  492. if (seriesPadding.padding) {
  493. // Recompute translation with new axis length now (minus padding)
  494. axis.len -= lengthPadding;
  495. axis.recomputingForTilemap = true;
  496. axis.setAxisTranslation();
  497. delete axis.recomputingForTilemap;
  498. axis.minPixelPadding += seriesPadding.padding;
  499. axis.len += lengthPadding;
  500. }
  501. });
  502. });
  503. _registerModule(_modules, 'Series/Tilemap/TilemapSeries.js', [_modules['Core/Globals.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Series/Tilemap/TilemapPoint.js'], _modules['Series/Tilemap/TilemapShapes.js'], _modules['Core/Utilities.js']], function (H, SeriesRegistry, TilemapPoint, TilemapShapes, U) {
  504. /* *
  505. *
  506. * Tilemaps module
  507. *
  508. * (c) 2010-2021 Highsoft AS
  509. * Author: Øystein Moseng
  510. *
  511. * License: www.highcharts.com/license
  512. *
  513. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  514. *
  515. * */
  516. var __extends = (this && this.__extends) || (function () {
  517. var extendStatics = function (d,
  518. b) {
  519. extendStatics = Object.setPrototypeOf ||
  520. ({ __proto__: [] } instanceof Array && function (d,
  521. b) { d.__proto__ = b; }) ||
  522. function (d,
  523. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  524. return extendStatics(d, b);
  525. };
  526. return function (d, b) {
  527. extendStatics(d, b);
  528. function __() { this.constructor = d; }
  529. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  530. };
  531. })();
  532. var noop = H.noop;
  533. var _a = SeriesRegistry.seriesTypes,
  534. ColumnSeries = _a.column,
  535. HeatmapSeries = _a.heatmap,
  536. ScatterSeries = _a.scatter;
  537. var extend = U.extend,
  538. merge = U.merge;
  539. /* *
  540. *
  541. * Class
  542. *
  543. * */
  544. /**
  545. * @private
  546. * @class
  547. * @name Highcharts.seriesTypes.tilemap
  548. *
  549. * @augments Highcharts.Series
  550. */
  551. var TilemapSeries = /** @class */ (function (_super) {
  552. __extends(TilemapSeries, _super);
  553. function TilemapSeries() {
  554. /* *
  555. *
  556. * Static Properties
  557. *
  558. * */
  559. var _this = _super !== null && _super.apply(this,
  560. arguments) || this;
  561. /* *
  562. *
  563. * Properties
  564. *
  565. * */
  566. _this.data = void 0;
  567. _this.options = void 0;
  568. _this.points = void 0;
  569. _this.tileShape = void 0;
  570. return _this;
  571. /* eslint-enable valid-jsdoc */
  572. }
  573. /* *
  574. *
  575. * Functions
  576. *
  577. * */
  578. /* eslint-disable valid-jsdoc */
  579. /**
  580. * Use the shape's defined data label alignment function.
  581. * @private
  582. */
  583. TilemapSeries.prototype.alignDataLabel = function () {
  584. return this.tileShape.alignDataLabel.apply(this, Array.prototype.slice.call(arguments));
  585. };
  586. TilemapSeries.prototype.drawPoints = function () {
  587. var _this = this;
  588. // In styled mode, use CSS, otherwise the fill used in the style
  589. // sheet will take precedence over the fill attribute.
  590. ColumnSeries.prototype.drawPoints.call(this);
  591. this.points.forEach(function (point) {
  592. point.graphic &&
  593. point.graphic[_this.chart.styledMode ? 'css' : 'animate'](_this.colorAttribs(point));
  594. });
  595. };
  596. /**
  597. * Get metrics for padding of axis for this series.
  598. * @private
  599. */
  600. TilemapSeries.prototype.getSeriesPixelPadding = function (axis) {
  601. var isX = axis.isXAxis,
  602. padding = this.tileShape.getSeriesPadding(this),
  603. coord1,
  604. coord2;
  605. // If the shape type does not require padding, return no-op padding
  606. if (!padding) {
  607. return {
  608. padding: 0,
  609. axisLengthFactor: 1
  610. };
  611. }
  612. // Use translate to compute how far outside the points we
  613. // draw, and use this difference as padding.
  614. coord1 = Math.round(axis.translate(isX ?
  615. padding.xPad * 2 :
  616. padding.yPad, 0, 1, 0, 1));
  617. coord2 = Math.round(axis.translate(isX ? padding.xPad : 0, 0, 1, 0, 1));
  618. return {
  619. padding: Math.abs(coord1 - coord2) || 0,
  620. // Offset the yAxis length to compensate for shift. Setting the
  621. // length factor to 2 would add the same margin to max as min.
  622. // Now we only add a slight bit of the min margin to max, as we
  623. // don't actually draw outside the max bounds. For the xAxis we
  624. // draw outside on both sides so we add the same margin to min
  625. // and max.
  626. axisLengthFactor: isX ? 2 : 1.1
  627. };
  628. };
  629. /**
  630. * Set tile shape object on series.
  631. * @private
  632. */
  633. TilemapSeries.prototype.setOptions = function () {
  634. // Call original function
  635. var ret = _super.prototype.setOptions.apply(this,
  636. Array.prototype.slice.call(arguments));
  637. this.tileShape = TilemapShapes[ret.tileShape];
  638. return ret;
  639. };
  640. /**
  641. * Use translate from tileShape.
  642. * @private
  643. */
  644. TilemapSeries.prototype.translate = function () {
  645. return this.tileShape.translate.apply(this, Array.prototype.slice.call(arguments));
  646. };
  647. /**
  648. * A tilemap series is a type of heatmap where the tile shapes are
  649. * configurable.
  650. *
  651. * @sample highcharts/demo/honeycomb-usa/
  652. * Honeycomb tilemap, USA
  653. * @sample maps/plotoptions/honeycomb-brazil/
  654. * Honeycomb tilemap, Brazil
  655. * @sample maps/plotoptions/honeycomb-china/
  656. * Honeycomb tilemap, China
  657. * @sample maps/plotoptions/honeycomb-europe/
  658. * Honeycomb tilemap, Europe
  659. * @sample maps/demo/circlemap-africa/
  660. * Circlemap tilemap, Africa
  661. * @sample maps/demo/diamondmap
  662. * Diamondmap tilemap
  663. *
  664. * @extends plotOptions.heatmap
  665. * @since 6.0.0
  666. * @excluding jitter, joinBy, shadow, allAreas, mapData, marker, data,
  667. * dataSorting, boostThreshold, boostBlending
  668. * @product highcharts highmaps
  669. * @requires modules/tilemap.js
  670. * @optionparent plotOptions.tilemap
  671. */
  672. TilemapSeries.defaultOptions = merge(HeatmapSeries.defaultOptions, {
  673. // Remove marker from tilemap default options, as it was before
  674. // heatmap refactoring.
  675. marker: null,
  676. states: {
  677. hover: {
  678. halo: {
  679. enabled: true,
  680. size: 2,
  681. opacity: 0.5,
  682. attributes: {
  683. zIndex: 3
  684. }
  685. }
  686. }
  687. },
  688. /**
  689. * The padding between points in the tilemap.
  690. *
  691. * @sample maps/plotoptions/tilemap-pointpadding
  692. * Point padding on tiles
  693. */
  694. pointPadding: 2,
  695. /**
  696. * The column size - how many X axis units each column in the tilemap
  697. * should span. Works as in [Heatmaps](#plotOptions.heatmap.colsize).
  698. *
  699. * @sample {highcharts} maps/demo/heatmap/
  700. * One day
  701. * @sample {highmaps} maps/demo/heatmap/
  702. * One day
  703. *
  704. * @type {number}
  705. * @default 1
  706. * @product highcharts highmaps
  707. * @apioption plotOptions.tilemap.colsize
  708. */
  709. /**
  710. * The row size - how many Y axis units each tilemap row should span.
  711. * Analogous to [colsize](#plotOptions.tilemap.colsize).
  712. *
  713. * @sample {highcharts} maps/demo/heatmap/
  714. * 1 by default
  715. * @sample {highmaps} maps/demo/heatmap/
  716. * 1 by default
  717. *
  718. * @type {number}
  719. * @default 1
  720. * @product highcharts highmaps
  721. * @apioption plotOptions.tilemap.rowsize
  722. */
  723. /**
  724. * The shape of the tiles in the tilemap. Possible values are `hexagon`,
  725. * `circle`, `diamond`, and `square`.
  726. *
  727. * @sample maps/demo/circlemap-africa
  728. * Circular tile shapes
  729. * @sample maps/demo/diamondmap
  730. * Diamond tile shapes
  731. *
  732. * @type {Highcharts.TilemapShapeValue}
  733. */
  734. tileShape: 'hexagon'
  735. });
  736. return TilemapSeries;
  737. }(HeatmapSeries));
  738. extend(TilemapSeries.prototype, {
  739. // Revert the noop on getSymbol.
  740. getSymbol: noop,
  741. // Use drawPoints, markerAttribs, pointAttribs methods from the old
  742. // heatmap implementation.
  743. // TODO: Consider standarizing heatmap and tilemap into more
  744. // consistent form.
  745. markerAttribs: ScatterSeries.prototype.markerAttribs,
  746. pointAttribs: ColumnSeries.prototype.pointAttribs,
  747. pointClass: TilemapPoint
  748. });
  749. SeriesRegistry.registerSeriesType('tilemap', TilemapSeries);
  750. /* *
  751. *
  752. * Default Export
  753. *
  754. * */
  755. /* *
  756. *
  757. * API Declarations
  758. *
  759. * */
  760. /**
  761. * @typedef {"circle"|"diamond"|"hexagon"|"square"} Highcharts.TilemapShapeValue
  762. */
  763. ''; // detach doclets above
  764. /* *
  765. *
  766. * API Options
  767. *
  768. * */
  769. /**
  770. * A `tilemap` series. If the [type](#series.tilemap.type) option is
  771. * not specified, it is inherited from [chart.type](#chart.type).
  772. *
  773. * @extends series,plotOptions.tilemap
  774. * @excluding allAreas, dataParser, dataURL, joinBy, mapData, marker,
  775. * pointRange, shadow, stack, dataSorting, boostThreshold,
  776. * boostBlending
  777. * @product highcharts highmaps
  778. * @requires modules/tilemap.js
  779. * @apioption series.tilemap
  780. */
  781. /**
  782. * An array of data points for the series. For the `tilemap` series
  783. * type, points can be given in the following ways:
  784. *
  785. * 1. An array of arrays with 3 or 2 values. In this case, the values correspond
  786. * to `x,y,value`. If the first value is a string, it is applied as the name
  787. * of the point, and the `x` value is inferred. The `x` value can also be
  788. * omitted, in which case the inner arrays should be of length 2\. Then the
  789. * `x` value is automatically calculated, either starting at 0 and
  790. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  791. * series options.
  792. * ```js
  793. * data: [
  794. * [0, 9, 7],
  795. * [1, 10, 4],
  796. * [2, 6, 3]
  797. * ]
  798. * ```
  799. *
  800. * 2. An array of objects with named values. The objects are point configuration
  801. * objects as seen below. If the total number of data points exceeds the
  802. * series' [turboThreshold](#series.tilemap.turboThreshold), this option is
  803. * not available.
  804. * ```js
  805. * data: [{
  806. * x: 1,
  807. * y: 3,
  808. * value: 10,
  809. * name: "Point2",
  810. * color: "#00FF00"
  811. * }, {
  812. * x: 1,
  813. * y: 7,
  814. * value: 10,
  815. * name: "Point1",
  816. * color: "#FF00FF"
  817. * }]
  818. * ```
  819. *
  820. * Note that for some [tileShapes](#plotOptions.tilemap.tileShape) the grid
  821. * coordinates are offset.
  822. *
  823. * @sample maps/series/tilemap-gridoffset
  824. * Offset grid coordinates
  825. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  826. * Arrays of numeric x and y
  827. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  828. * Arrays of datetime x and y
  829. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  830. * Arrays of point.name and y
  831. * @sample {highcharts} highcharts/series/data-array-of-objects/
  832. * Config objects
  833. *
  834. * @type {Array<Array<(number|string),number>|Array<(number|string),number,number>|*>}
  835. * @extends series.heatmap.data
  836. * @excluding marker
  837. * @product highcharts highmaps
  838. * @apioption series.tilemap.data
  839. */
  840. /**
  841. * The color of the point. In tilemaps the point color is rarely set
  842. * explicitly, as we use the color to denote the `value`. Options for
  843. * this are set in the [colorAxis](#colorAxis) configuration.
  844. *
  845. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  846. * @product highcharts highmaps
  847. * @apioption series.tilemap.data.color
  848. */
  849. /**
  850. * The x coordinate of the point.
  851. *
  852. * Note that for some [tileShapes](#plotOptions.tilemap.tileShape) the grid
  853. * coordinates are offset.
  854. *
  855. * @sample maps/series/tilemap-gridoffset
  856. * Offset grid coordinates
  857. *
  858. * @type {number}
  859. * @product highcharts highmaps
  860. * @apioption series.tilemap.data.x
  861. */
  862. /**
  863. * The y coordinate of the point.
  864. *
  865. * Note that for some [tileShapes](#plotOptions.tilemap.tileShape) the grid
  866. * coordinates are offset.
  867. *
  868. * @sample maps/series/tilemap-gridoffset
  869. * Offset grid coordinates
  870. *
  871. * @type {number}
  872. * @product highcharts highmaps
  873. * @apioption series.tilemap.data.y
  874. */
  875. ''; // adds doclets above to the transpiled file
  876. return TilemapSeries;
  877. });
  878. _registerModule(_modules, 'masters/modules/tilemap.src.js', [], function () {
  879. });
  880. }));