|
| 1 | +/** |
| 2 | +* Copyright 2012-2019, Plotly, Inc. |
| 3 | +* All rights reserved. |
| 4 | +* |
| 5 | +* This source code is licensed under the MIT license found in the |
| 6 | +* LICENSE file in the root directory of this source tree. |
| 7 | +*/ |
| 8 | + |
| 9 | +'use strict'; |
| 10 | + |
| 11 | +var colorScaleAttrs = require('../../components/colorscale/attributes'); |
| 12 | +var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes'); |
| 13 | +var plotAttrs = require('../../plots/attributes'); |
| 14 | +var scatterMapboxAttrs = require('../scattermapbox/attributes'); |
| 15 | + |
| 16 | +var extendFlat = require('../../lib/extend').extendFlat; |
| 17 | + |
| 18 | +/* |
| 19 | + * - https://docs.mapbox.com/help/tutorials/make-a-heatmap-with-mapbox-gl-js/ |
| 20 | + * - https://docs.mapbox.com/mapbox-gl-js/example/heatmap-layer/ |
| 21 | + * - https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers-heatmap |
| 22 | + * - https://blog.mapbox.com/introducing-heatmaps-in-mapbox-gl-js-71355ada9e6c |
| 23 | + * |
| 24 | + * Gotchas: |
| 25 | + * - https://github.com/mapbox/mapbox-gl-js/issues/6463 |
| 26 | + * - https://github.com/mapbox/mapbox-gl-js/issues/6112 |
| 27 | + */ |
| 28 | + |
| 29 | +/* |
| 30 | + * |
| 31 | + * In mathematical terms, Mapbox GL heatmaps are a bivariate (2D) kernel density |
| 32 | + * estimation with a Gaussian kernel. It means that each data point has an area |
| 33 | + * of “influence” around it (called a kernel) where the numerical value of |
| 34 | + * influence (which we call density) decreases as you go further from the point. |
| 35 | + * If we sum density values of all points in every pixel of the screen, we get a |
| 36 | + * combined density value which we then map to a heatmap color. |
| 37 | + * |
| 38 | + */ |
| 39 | + |
| 40 | +module.exports = extendFlat({ |
| 41 | + lon: scatterMapboxAttrs.lon, |
| 42 | + lat: scatterMapboxAttrs.lat, |
| 43 | + |
| 44 | + z: { |
| 45 | + valType: 'data_array', |
| 46 | + editType: 'calc', |
| 47 | + description: [ |
| 48 | + 'Sets the points\' weight.', |
| 49 | + 'For example, a value of 10 would be equivalent to having 10 points of weight 1', |
| 50 | + 'in the same spot' |
| 51 | + ].join(' ') |
| 52 | + }, |
| 53 | + |
| 54 | + radius: { |
| 55 | + valType: 'number', |
| 56 | + role: 'info', |
| 57 | + editType: 'plot', |
| 58 | + arrayOk: true, |
| 59 | + min: 1, |
| 60 | + dflt: 30, |
| 61 | + description: [ |
| 62 | + 'Sets the radius of influence of one `lon` / `lat` point in pixels.', |
| 63 | + 'Increasing the value makes the densitymapbox trace smoother, but less detailed.' |
| 64 | + ].join(' ') |
| 65 | + }, |
| 66 | + |
| 67 | + below: { |
| 68 | + valType: 'string', |
| 69 | + role: 'info', |
| 70 | + editType: 'plot', |
| 71 | + description: [ |
| 72 | + 'Determines if the densitymapbox trace will be inserted', |
| 73 | + 'before the layer with the specified ID.', |
| 74 | + 'By default, densitymapbox traces are placed below the first', |
| 75 | + 'layer of type symbol', |
| 76 | + 'If set to \'\',', |
| 77 | + 'the layer will be inserted above every existing layer.' |
| 78 | + ].join(' ') |
| 79 | + }, |
| 80 | + |
| 81 | + text: scatterMapboxAttrs.text, |
| 82 | + hovertext: scatterMapboxAttrs.hovertext, |
| 83 | + |
| 84 | + hoverinfo: extendFlat({}, plotAttrs.hoverinfo, { |
| 85 | + flags: ['lon', 'lat', 'z', 'text', 'name'] |
| 86 | + }), |
| 87 | + hovertemplate: hovertemplateAttrs() |
| 88 | +}, |
| 89 | + colorScaleAttrs('', { |
| 90 | + cLetter: 'z', |
| 91 | + editTypeOverride: 'calc' |
| 92 | + }) |
| 93 | +); |
0 commit comments