Map.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* *
  2. *
  3. * (c) 2010-2021 Torstein Honsi
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8. *
  9. * */
  10. 'use strict';
  11. import Chart from '../Core/Chart/Chart.js';
  12. import H from '../Core/Globals.js';
  13. import SVGRenderer from '../Core/Renderer/SVG/SVGRenderer.js';
  14. import U from '../Core/Utilities.js';
  15. var getOptions = U.getOptions, merge = U.merge, pick = U.pick;
  16. import './MapSymbols.js';
  17. /* eslint-disable valid-jsdoc */
  18. var Map;
  19. (function (Map) {
  20. /* *
  21. *
  22. * Constants
  23. *
  24. * */
  25. /**
  26. * Contains all loaded map data for Highmaps.
  27. *
  28. * @requires modules/map
  29. *
  30. * @name Highcharts.maps
  31. * @type {Record<string,*>}
  32. */
  33. Map.maps = {};
  34. /* *
  35. *
  36. * Functions
  37. *
  38. * */
  39. /**
  40. * The factory function for creating new map charts. Creates a new {@link
  41. * Highcharts.Chart|Chart} object with different default options than the
  42. * basic Chart.
  43. *
  44. * @requires modules/map
  45. *
  46. * @function Highcharts.mapChart
  47. *
  48. * @param {string|Highcharts.HTMLDOMElement} [renderTo]
  49. * The DOM element to render to, or its id.
  50. *
  51. * @param {Highcharts.Options} options
  52. * The chart options structure as described in the
  53. * [options reference](https://api.highcharts.com/highstock).
  54. *
  55. * @param {Highcharts.ChartCallbackFunction} [callback]
  56. * A function to execute when the chart object is finished loading and
  57. * rendering. In most cases the chart is built in one thread, but in
  58. * Internet Explorer version 8 or less the chart is sometimes initialized
  59. * before the document is ready, and in these cases the chart object will
  60. * not be finished synchronously. As a consequence, code that relies on the
  61. * newly built Chart object should always run in the callback. Defining a
  62. * [chart.events.load](https://api.highcharts.com/highstock/chart.events.load)
  63. * handler is equivalent.
  64. *
  65. * @return {Highcharts.Chart}
  66. * The chart object.
  67. */
  68. function mapChart(a, b, c) {
  69. var hasRenderToArg = typeof a === 'string' || a.nodeName, options = arguments[hasRenderToArg ? 1 : 0], userOptions = options, hiddenAxis = {
  70. endOnTick: false,
  71. visible: false,
  72. minPadding: 0,
  73. maxPadding: 0,
  74. startOnTick: false
  75. }, seriesOptions, defaultCreditsOptions = getOptions().credits;
  76. /* For visual testing
  77. hiddenAxis.gridLineWidth = 1;
  78. hiddenAxis.gridZIndex = 10;
  79. hiddenAxis.tickPositions = undefined;
  80. // */
  81. // Don't merge the data
  82. seriesOptions = options.series;
  83. options.series = null;
  84. options = merge({
  85. chart: {
  86. panning: {
  87. enabled: true,
  88. type: 'xy'
  89. },
  90. type: 'map'
  91. },
  92. credits: {
  93. mapText: pick(defaultCreditsOptions.mapText, ' \u00a9 <a href="{geojson.copyrightUrl}">' +
  94. '{geojson.copyrightShort}</a>'),
  95. mapTextFull: pick(defaultCreditsOptions.mapTextFull, '{geojson.copyright}')
  96. },
  97. tooltip: {
  98. followTouchMove: false
  99. },
  100. xAxis: hiddenAxis,
  101. yAxis: merge(hiddenAxis, { reversed: true })
  102. }, options, // user's options
  103. {
  104. chart: {
  105. inverted: false,
  106. alignTicks: false
  107. }
  108. });
  109. options.series = userOptions.series = seriesOptions;
  110. return hasRenderToArg ?
  111. new Chart(a, options, c) :
  112. new Chart(options, b);
  113. }
  114. Map.mapChart = mapChart;
  115. /**
  116. * Utility for reading SVG paths directly.
  117. *
  118. * @requires modules/map
  119. *
  120. * @function Highcharts.splitPath
  121. *
  122. * @param {string|Array<string|number>} path
  123. *
  124. * @return {Highcharts.SVGPathArray}
  125. */
  126. function splitPath(path) {
  127. var arr;
  128. if (typeof path === 'string') {
  129. path = path
  130. // Move letters apart
  131. .replace(/([A-Za-z])/g, ' $1 ')
  132. // Trim
  133. .replace(/^\s*/, '').replace(/\s*$/, '');
  134. // Split on spaces and commas. The semicolon is bogus, designed to
  135. // circumvent string replacement in the pre-v7 assembler that built
  136. // specific styled mode files.
  137. var split = path.split(/[ ,;]+/);
  138. arr = split.map(function (item) {
  139. if (!/[A-za-z]/.test(item)) {
  140. return parseFloat(item);
  141. }
  142. return item;
  143. });
  144. }
  145. else {
  146. arr = path;
  147. }
  148. return SVGRenderer.prototype.pathToSegments(arr);
  149. }
  150. Map.splitPath = splitPath;
  151. })(Map || (Map = {}));
  152. /* *
  153. *
  154. * Compatibility
  155. *
  156. * */
  157. H.Map = Map.mapChart; // @todo remove fake class for jQuery
  158. H.mapChart = Map.mapChart;
  159. H.maps = Map.maps;
  160. /* *
  161. *
  162. * Default Export
  163. *
  164. * */
  165. export default Map;