Source

widgets/googleHeatMap.js

  1. import processStructure from '@devoinc/applications-data-library/structures/googleMap';
  2. import widgetFactory from '@devoinc/applications-builder/widgetFactory';
  3. import dependencies from '../data/dependencies';
  4. const GoogleHeatMapWidget = dependencies.require('widgets').GoogleHeatMapWidget;
  5. /**
  6. * This chart displays information on a world map using latitude and
  7. * longitude coordinates, representing data with different colors.
  8. * Information can be clustered on the map by an optional additional value.
  9. * @category Widgets
  10. * @module GoogleHeatmap
  11. * @see [base](module-base.html)
  12. * @see [collapser](module-collapser.html)
  13. * @see [dataSearch](module-dataSearch.html)
  14. * @see [download](module-download.html)
  15. * @see [info](module-info.html)
  16. * @see [lifeCycle](module-lifeCycle.html)
  17. * @see [listeners](module-listeners.html)
  18. * @see [loading](module-loading.html)
  19. * @see [menu](module-menu.html)
  20. * @see [screenshot](module-screenshot.html)
  21. * @see [zoom](module-zoom.html)
  22. * @tutorial widgets-google-heatmap
  23. */
  24. function mixin(self) {
  25. return {
  26. /**
  27. * Shows the MapType control in the map.
  28. * @param {boolean} bool - Enable or disable.
  29. * @see https://developers.google.com/maps/documentation/javascript/controls
  30. * @instance
  31. */
  32. setMapTypeControl: (bool) => (self.settings.mapTypeControl = bool),
  33. /**
  34. * Sets the Google maps type.
  35. * @param {string} type - Type of map.
  36. * @see https://developers.google.com/maps/documentation/javascript/maptypes#BasicMapTypes
  37. * @instance
  38. */
  39. setMapTypeId: (type) => (self.settings.mapTypeId = type),
  40. /**
  41. * Displays a small circular icon which allows you to rotate maps.
  42. * @param {boolean} bool - Enable or disable.
  43. * @see https://developers.google.com/maps/documentation/javascript/controls
  44. * @instance
  45. */
  46. setRotateControl: (bool) => (self.settings.rotateControl = bool),
  47. /**
  48. * Displays a map scale element.
  49. * @param {boolean} bool - Enable or disable.
  50. * @see https://developers.google.com/maps/documentation/javascript/controls
  51. * @instance
  52. */
  53. setScaleControl: (bool) => (self.settings.scaleControl = bool),
  54. /**
  55. * Displays a Pegman icon which can be dragged to the map to enable
  56. * Street View.
  57. * @param {boolean} bool - Enable or disable.
  58. * @see https://developers.google.com/maps/documentation/javascript/controls
  59. * @instance
  60. */
  61. setStreetViewControl: (bool) => (self.settings.streetViewControl = bool),
  62. /**
  63. * Displays a slider or "+/-" buttons to control the zoom level of
  64. * the map.
  65. * @param {boolean} bool - Enable or disable.
  66. * @see https://developers.google.com/maps/documentation/javascript/controls
  67. * @instance
  68. */
  69. setZoomControl: (bool) => (self.settings.zoomControl = bool),
  70. /**
  71. * Specifies whether heatmaps dissipate on zoom.
  72. * @param {boolean} dissipating - Enable or disable.
  73. * @see https://developers.google.com/maps/documentation/javascript/heatmaplayer#customize_a_heatmap_layer
  74. * @instance
  75. */
  76. setDissipating: (dissipating) => (self.settings.disipating = dissipating),
  77. /**
  78. * Set the color gradient of the heatmap.
  79. *
  80. * One of the following numbers:
  81. * - <i>0</i>: 'Default'.
  82. * - <i>1</i>: 'Artic'.
  83. * - <i>2</i>: 'Boreal'.
  84. * - <i>3</i> 'Bruise'.
  85. * - <i>4</i> 'Sunset'.
  86. * - <i>5</i> 'Antartic'.
  87. * - <i>6</i> 'Sky Burst'.
  88. * - <i>7</i> 'Rioja Lightning'.
  89. * - <i>8</i> 'Kamehameha'.
  90. * - <i>9</i> 'Alien'.
  91. * - <i>10</i> 'Rainbow'.
  92. * @param {number} gradient - Number of gradient.
  93. * @instance
  94. */
  95. setGradient: (gradient) => (self.settings.gradient = gradient),
  96. /**
  97. * Set the radius of influence for each data point.
  98. * @param {number} radius - Number in pixels.
  99. * @see https://developers.google.com/maps/documentation/javascript/heatmaplayer#customize_a_heatmap_layer
  100. * @instance
  101. */
  102. setRadius: (radius) => (self.settings.radius = radius),
  103. /**
  104. * Set the opacity of the heatmap.
  105. * @param {number} opacity - Number between 0 and 1.
  106. * @see https://developers.google.com/maps/documentation/javascript/heatmaplayer#customize_a_heatmap_layer
  107. * @instance
  108. */
  109. setOpacity: (opacity) => (self.settings.opacity = opacity),
  110. /**
  111. * Set custom styles.
  112. * @param {Object[]} styles - CSS styles properties.
  113. * @instance
  114. */
  115. setStyles: (styles) => (self.settings.styles = styles),
  116. /**
  117. * Set the default value for zoom.
  118. * @param {number} zoom - Zoom value.
  119. * @instance
  120. */
  121. setZoom: (zoom) => (self.settings.zoom = zoom),
  122. /**
  123. * Set the initial map center.
  124. * @param {Object} center
  125. * @param {number} center.lat - Latitude value.
  126. * @param {number} center.lng - Longitude value.
  127. * @instance
  128. */
  129. setCenter: (center) => (self.settings.center = center),
  130. /**
  131. * Set the operation to apply to the data.
  132. *
  133. * The following values are supported:
  134. * - <b>none</b>: No operation to apply.
  135. * - <b>log</b>: Logarithmic operation.
  136. * - <b>arc</b>: Arctangent operation.
  137. * @param {string} operation - Operation name.
  138. * @instance
  139. */
  140. setDataOperation: (operation) => (self.settings.dataOperation = operation),
  141. /**
  142. * Set the zooming on the map using a mouse scroll wheel.
  143. * @param {boolean} bool - Enable or disable.
  144. * @instance
  145. */
  146. setScrollwheel: (bool) => (self.settings.scrollWheel = bool),
  147. /**
  148. * Set the default options for map controls.
  149. * @param {Object} options - Show Google documentation.
  150. * @see https://developers.google.com/maps/documentation/javascript/controls
  151. * @instance
  152. */
  153. setMapTypeControlOptions: (options) =>
  154. (self.settings.mapTypeControlOptions = options),
  155. /**
  156. * Set the display options for the zoom control.
  157. * @param {Object} options - Show Google documentation.
  158. * @see https://developers.google.com/maps/documentation/javascript/reference/control#ZoomControlOptions
  159. * @instance
  160. */
  161. setZoomControlOptions: (options) =>
  162. (self.settings.zoomControlOptions = options),
  163. /**
  164. * Set the default options for the rendering of the Street View pegman
  165. * control on the map.
  166. * @param {Object} options - Show Google documentation.
  167. * @see https://developers.google.com/maps/documentation/javascript/reference/control#StreetViewControlOptions
  168. * @instance
  169. */
  170. setStreetViewControlOptions: (options) =>
  171. (self.settings.streetViewControlOptions = options),
  172. /**
  173. * Set the keys to show.
  174. * @param {Object[]} arr - Object with <i>lat</i> and <i>lon</i> values.
  175. * @instance
  176. */
  177. setKeys: (arr) => (self.settings.keys = arr),
  178. /**
  179. * Set the column nae with the value.
  180. * @param {string} value - Column name.
  181. * @instance
  182. */
  183. setValue: (value) => (self.settings.value = value),
  184. /**
  185. * Set partitioning key.
  186. * @param {string} partKey - Partitioning key
  187. * @instance
  188. */
  189. setPartKey: (partKey) => (self.settings.partKey = partKey),
  190. /**
  191. * Set initial gradient color.
  192. * @param {Object} gradient
  193. * @instance
  194. */
  195. setInitGradient: (gradient) => (self.settings.initGradient = gradient),
  196. // Life Cycle
  197. // ---------------------------------------------------------------------------
  198. /**
  199. * Render method
  200. * @ignore
  201. */
  202. render: (orig) => {
  203. if (!self.el) return; // If not have element not render
  204. let cfg = Object.assign(
  205. {},
  206. {
  207. scrollwheel: null,
  208. },
  209. self.settings
  210. );
  211. let data = processStructure(orig, cfg.keys, cfg.value, cfg.partKey);
  212. if (data) {
  213. self.widget = new GoogleHeatMapWidget(cfg);
  214. self.widget.setData(data);
  215. self.widget.display({ force: true, data: true });
  216. } else {
  217. this.debugError({
  218. msg: 'NO DATA',
  219. console: {
  220. method: 'error',
  221. msg: 'No data arrive to render function',
  222. },
  223. });
  224. }
  225. },
  226. };
  227. }
  228. export default widgetFactory(mixin);