TilemapSeries.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /* *
  2. *
  3. * Tilemaps module
  4. *
  5. * (c) 2010-2021 Highsoft AS
  6. * Author: Øystein Moseng
  7. *
  8. * License: www.highcharts.com/license
  9. *
  10. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  11. *
  12. * */
  13. 'use strict';
  14. var __extends = (this && this.__extends) || (function () {
  15. var extendStatics = function (d, b) {
  16. extendStatics = Object.setPrototypeOf ||
  17. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  18. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  19. return extendStatics(d, b);
  20. };
  21. return function (d, b) {
  22. extendStatics(d, b);
  23. function __() { this.constructor = d; }
  24. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  25. };
  26. })();
  27. import H from '../../Core/Globals.js';
  28. var noop = H.noop;
  29. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  30. var _a = SeriesRegistry.seriesTypes, ColumnSeries = _a.column, HeatmapSeries = _a.heatmap, ScatterSeries = _a.scatter;
  31. import TilemapPoint from './TilemapPoint.js';
  32. import TilemapShapes from './TilemapShapes.js';
  33. import U from '../../Core/Utilities.js';
  34. var extend = U.extend, merge = U.merge;
  35. import './TilemapComposition.js';
  36. /* *
  37. *
  38. * Class
  39. *
  40. * */
  41. /**
  42. * @private
  43. * @class
  44. * @name Highcharts.seriesTypes.tilemap
  45. *
  46. * @augments Highcharts.Series
  47. */
  48. var TilemapSeries = /** @class */ (function (_super) {
  49. __extends(TilemapSeries, _super);
  50. function TilemapSeries() {
  51. /* *
  52. *
  53. * Static Properties
  54. *
  55. * */
  56. var _this = _super !== null && _super.apply(this, arguments) || this;
  57. /* *
  58. *
  59. * Properties
  60. *
  61. * */
  62. _this.data = void 0;
  63. _this.options = void 0;
  64. _this.points = void 0;
  65. _this.tileShape = void 0;
  66. return _this;
  67. /* eslint-enable valid-jsdoc */
  68. }
  69. /* *
  70. *
  71. * Functions
  72. *
  73. * */
  74. /* eslint-disable valid-jsdoc */
  75. /**
  76. * Use the shape's defined data label alignment function.
  77. * @private
  78. */
  79. TilemapSeries.prototype.alignDataLabel = function () {
  80. return this.tileShape.alignDataLabel.apply(this, Array.prototype.slice.call(arguments));
  81. };
  82. TilemapSeries.prototype.drawPoints = function () {
  83. var _this = this;
  84. // In styled mode, use CSS, otherwise the fill used in the style
  85. // sheet will take precedence over the fill attribute.
  86. ColumnSeries.prototype.drawPoints.call(this);
  87. this.points.forEach(function (point) {
  88. point.graphic &&
  89. point.graphic[_this.chart.styledMode ? 'css' : 'animate'](_this.colorAttribs(point));
  90. });
  91. };
  92. /**
  93. * Get metrics for padding of axis for this series.
  94. * @private
  95. */
  96. TilemapSeries.prototype.getSeriesPixelPadding = function (axis) {
  97. var isX = axis.isXAxis, padding = this.tileShape.getSeriesPadding(this), coord1, coord2;
  98. // If the shape type does not require padding, return no-op padding
  99. if (!padding) {
  100. return {
  101. padding: 0,
  102. axisLengthFactor: 1
  103. };
  104. }
  105. // Use translate to compute how far outside the points we
  106. // draw, and use this difference as padding.
  107. coord1 = Math.round(axis.translate(isX ?
  108. padding.xPad * 2 :
  109. padding.yPad, 0, 1, 0, 1));
  110. coord2 = Math.round(axis.translate(isX ? padding.xPad : 0, 0, 1, 0, 1));
  111. return {
  112. padding: Math.abs(coord1 - coord2) || 0,
  113. // Offset the yAxis length to compensate for shift. Setting the
  114. // length factor to 2 would add the same margin to max as min.
  115. // Now we only add a slight bit of the min margin to max, as we
  116. // don't actually draw outside the max bounds. For the xAxis we
  117. // draw outside on both sides so we add the same margin to min
  118. // and max.
  119. axisLengthFactor: isX ? 2 : 1.1
  120. };
  121. };
  122. /**
  123. * Set tile shape object on series.
  124. * @private
  125. */
  126. TilemapSeries.prototype.setOptions = function () {
  127. // Call original function
  128. var ret = _super.prototype.setOptions.apply(this, Array.prototype.slice.call(arguments));
  129. this.tileShape = TilemapShapes[ret.tileShape];
  130. return ret;
  131. };
  132. /**
  133. * Use translate from tileShape.
  134. * @private
  135. */
  136. TilemapSeries.prototype.translate = function () {
  137. return this.tileShape.translate.apply(this, Array.prototype.slice.call(arguments));
  138. };
  139. /**
  140. * A tilemap series is a type of heatmap where the tile shapes are
  141. * configurable.
  142. *
  143. * @sample highcharts/demo/honeycomb-usa/
  144. * Honeycomb tilemap, USA
  145. * @sample maps/plotoptions/honeycomb-brazil/
  146. * Honeycomb tilemap, Brazil
  147. * @sample maps/plotoptions/honeycomb-china/
  148. * Honeycomb tilemap, China
  149. * @sample maps/plotoptions/honeycomb-europe/
  150. * Honeycomb tilemap, Europe
  151. * @sample maps/demo/circlemap-africa/
  152. * Circlemap tilemap, Africa
  153. * @sample maps/demo/diamondmap
  154. * Diamondmap tilemap
  155. *
  156. * @extends plotOptions.heatmap
  157. * @since 6.0.0
  158. * @excluding jitter, joinBy, shadow, allAreas, mapData, marker, data,
  159. * dataSorting, boostThreshold, boostBlending
  160. * @product highcharts highmaps
  161. * @requires modules/tilemap.js
  162. * @optionparent plotOptions.tilemap
  163. */
  164. TilemapSeries.defaultOptions = merge(HeatmapSeries.defaultOptions, {
  165. // Remove marker from tilemap default options, as it was before
  166. // heatmap refactoring.
  167. marker: null,
  168. states: {
  169. hover: {
  170. halo: {
  171. enabled: true,
  172. size: 2,
  173. opacity: 0.5,
  174. attributes: {
  175. zIndex: 3
  176. }
  177. }
  178. }
  179. },
  180. /**
  181. * The padding between points in the tilemap.
  182. *
  183. * @sample maps/plotoptions/tilemap-pointpadding
  184. * Point padding on tiles
  185. */
  186. pointPadding: 2,
  187. /**
  188. * The column size - how many X axis units each column in the tilemap
  189. * should span. Works as in [Heatmaps](#plotOptions.heatmap.colsize).
  190. *
  191. * @sample {highcharts} maps/demo/heatmap/
  192. * One day
  193. * @sample {highmaps} maps/demo/heatmap/
  194. * One day
  195. *
  196. * @type {number}
  197. * @default 1
  198. * @product highcharts highmaps
  199. * @apioption plotOptions.tilemap.colsize
  200. */
  201. /**
  202. * The row size - how many Y axis units each tilemap row should span.
  203. * Analogous to [colsize](#plotOptions.tilemap.colsize).
  204. *
  205. * @sample {highcharts} maps/demo/heatmap/
  206. * 1 by default
  207. * @sample {highmaps} maps/demo/heatmap/
  208. * 1 by default
  209. *
  210. * @type {number}
  211. * @default 1
  212. * @product highcharts highmaps
  213. * @apioption plotOptions.tilemap.rowsize
  214. */
  215. /**
  216. * The shape of the tiles in the tilemap. Possible values are `hexagon`,
  217. * `circle`, `diamond`, and `square`.
  218. *
  219. * @sample maps/demo/circlemap-africa
  220. * Circular tile shapes
  221. * @sample maps/demo/diamondmap
  222. * Diamond tile shapes
  223. *
  224. * @type {Highcharts.TilemapShapeValue}
  225. */
  226. tileShape: 'hexagon'
  227. });
  228. return TilemapSeries;
  229. }(HeatmapSeries));
  230. extend(TilemapSeries.prototype, {
  231. // Revert the noop on getSymbol.
  232. getSymbol: noop,
  233. // Use drawPoints, markerAttribs, pointAttribs methods from the old
  234. // heatmap implementation.
  235. // TODO: Consider standarizing heatmap and tilemap into more
  236. // consistent form.
  237. markerAttribs: ScatterSeries.prototype.markerAttribs,
  238. pointAttribs: ColumnSeries.prototype.pointAttribs,
  239. pointClass: TilemapPoint
  240. });
  241. SeriesRegistry.registerSeriesType('tilemap', TilemapSeries);
  242. /* *
  243. *
  244. * Default Export
  245. *
  246. * */
  247. export default TilemapSeries;
  248. /* *
  249. *
  250. * API Declarations
  251. *
  252. * */
  253. /**
  254. * @typedef {"circle"|"diamond"|"hexagon"|"square"} Highcharts.TilemapShapeValue
  255. */
  256. ''; // detach doclets above
  257. /* *
  258. *
  259. * API Options
  260. *
  261. * */
  262. /**
  263. * A `tilemap` series. If the [type](#series.tilemap.type) option is
  264. * not specified, it is inherited from [chart.type](#chart.type).
  265. *
  266. * @extends series,plotOptions.tilemap
  267. * @excluding allAreas, dataParser, dataURL, joinBy, mapData, marker,
  268. * pointRange, shadow, stack, dataSorting, boostThreshold,
  269. * boostBlending
  270. * @product highcharts highmaps
  271. * @requires modules/tilemap.js
  272. * @apioption series.tilemap
  273. */
  274. /**
  275. * An array of data points for the series. For the `tilemap` series
  276. * type, points can be given in the following ways:
  277. *
  278. * 1. An array of arrays with 3 or 2 values. In this case, the values correspond
  279. * to `x,y,value`. If the first value is a string, it is applied as the name
  280. * of the point, and the `x` value is inferred. The `x` value can also be
  281. * omitted, in which case the inner arrays should be of length 2\. Then the
  282. * `x` value is automatically calculated, either starting at 0 and
  283. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  284. * series options.
  285. * ```js
  286. * data: [
  287. * [0, 9, 7],
  288. * [1, 10, 4],
  289. * [2, 6, 3]
  290. * ]
  291. * ```
  292. *
  293. * 2. An array of objects with named values. The objects are point configuration
  294. * objects as seen below. If the total number of data points exceeds the
  295. * series' [turboThreshold](#series.tilemap.turboThreshold), this option is
  296. * not available.
  297. * ```js
  298. * data: [{
  299. * x: 1,
  300. * y: 3,
  301. * value: 10,
  302. * name: "Point2",
  303. * color: "#00FF00"
  304. * }, {
  305. * x: 1,
  306. * y: 7,
  307. * value: 10,
  308. * name: "Point1",
  309. * color: "#FF00FF"
  310. * }]
  311. * ```
  312. *
  313. * Note that for some [tileShapes](#plotOptions.tilemap.tileShape) the grid
  314. * coordinates are offset.
  315. *
  316. * @sample maps/series/tilemap-gridoffset
  317. * Offset grid coordinates
  318. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  319. * Arrays of numeric x and y
  320. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  321. * Arrays of datetime x and y
  322. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  323. * Arrays of point.name and y
  324. * @sample {highcharts} highcharts/series/data-array-of-objects/
  325. * Config objects
  326. *
  327. * @type {Array<Array<(number|string),number>|Array<(number|string),number,number>|*>}
  328. * @extends series.heatmap.data
  329. * @excluding marker
  330. * @product highcharts highmaps
  331. * @apioption series.tilemap.data
  332. */
  333. /**
  334. * The color of the point. In tilemaps the point color is rarely set
  335. * explicitly, as we use the color to denote the `value`. Options for
  336. * this are set in the [colorAxis](#colorAxis) configuration.
  337. *
  338. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  339. * @product highcharts highmaps
  340. * @apioption series.tilemap.data.color
  341. */
  342. /**
  343. * The x coordinate of the point.
  344. *
  345. * Note that for some [tileShapes](#plotOptions.tilemap.tileShape) the grid
  346. * coordinates are offset.
  347. *
  348. * @sample maps/series/tilemap-gridoffset
  349. * Offset grid coordinates
  350. *
  351. * @type {number}
  352. * @product highcharts highmaps
  353. * @apioption series.tilemap.data.x
  354. */
  355. /**
  356. * The y coordinate of the point.
  357. *
  358. * Note that for some [tileShapes](#plotOptions.tilemap.tileShape) the grid
  359. * coordinates are offset.
  360. *
  361. * @sample maps/series/tilemap-gridoffset
  362. * Offset grid coordinates
  363. *
  364. * @type {number}
  365. * @product highcharts highmaps
  366. * @apioption series.tilemap.data.y
  367. */
  368. ''; // adds doclets above to the transpiled file