|
| 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 choroplethAttrs = require('../choropleth/attributes'); |
| 12 | +var colorScaleAttrs = require('../../components/colorscale/attributes'); |
| 13 | +var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes'); |
| 14 | + |
| 15 | +var extendFlat = require('../../lib/extend').extendFlat; |
| 16 | + |
| 17 | +module.exports = extendFlat({ |
| 18 | + locations: { |
| 19 | + valType: 'data_array', |
| 20 | + editType: 'calc', |
| 21 | + description: [ |
| 22 | + 'Sets which features found in *geojson* to plot using', |
| 23 | + 'their feature `id` field.' |
| 24 | + ].join(' ') |
| 25 | + }, |
| 26 | + |
| 27 | + // TODO |
| 28 | + // Maybe start with only one value (that we could name e.g. 'geojson-id'), |
| 29 | + // but eventually: |
| 30 | + // - we could also support for our own dist/topojson/* |
| 31 | + // - some people might want `geojson-properties-name` to map data arrays to |
| 32 | + // GeoJSON features |
| 33 | + // locationmode: choroplethAttrs.locationmode, |
| 34 | + |
| 35 | + z: { |
| 36 | + valType: 'data_array', |
| 37 | + editType: 'calc', |
| 38 | + description: 'Sets the color values.' |
| 39 | + }, |
| 40 | + |
| 41 | + // TODO maybe we could also set a "key" to dig out values out of the |
| 42 | + // GeoJSON feature `properties` fields? |
| 43 | + |
| 44 | + geojson: { |
| 45 | + valType: 'any', |
| 46 | + role: 'info', |
| 47 | + editType: 'calc', |
| 48 | + description: [ |
| 49 | + 'Sets the GeoJSON data associated with this trace.', |
| 50 | + 'Can be set as a valid GeoJSON object or as URL string', |
| 51 | + 'Note that we only accept GeoJSON of type *FeatureCollection* and *Feature*', |
| 52 | + 'with geometries of type *Polygon* and *MultiPolygon*.' |
| 53 | + ].join(' ') |
| 54 | + }, |
| 55 | + |
| 56 | + // TODO agree on name |
| 57 | + // 'below' is used currently for layout.mapbox.layers, it's not very |
| 58 | + // plotly-esque though |
| 59 | + // https://docs.mapbox.com/mapbox-gl-js/example/geojson-layer-in-stack/ |
| 60 | + below: { |
| 61 | + valType: 'string', |
| 62 | + dflt: '', |
| 63 | + role: 'info', |
| 64 | + description: [ |
| 65 | + 'Determines if the choropleth polygons will be inserted', |
| 66 | + 'before the layer with the specified ID.', |
| 67 | + 'If omitted or set to \'\',', |
| 68 | + 'the layer will be inserted above every existing layer.' |
| 69 | + ].join(' ') |
| 70 | + }, |
| 71 | + |
| 72 | + text: choroplethAttrs.text, |
| 73 | + hovertext: choroplethAttrs.hovertext, |
| 74 | + |
| 75 | + marker: { |
| 76 | + line: { |
| 77 | + color: extendFlat({}, choroplethAttrs.marker.line.color, {editType: 'plot'}), |
| 78 | + width: extendFlat({}, choroplethAttrs.marker.line.width, {editType: 'plot'}), |
| 79 | + editType: 'calc' |
| 80 | + }, |
| 81 | + // TODO maybe having a dflt less than 1 would be better? |
| 82 | + opacity: extendFlat({}, choroplethAttrs.marker.opacity, {editType: 'plot'}), |
| 83 | + editType: 'calc' |
| 84 | + }, |
| 85 | + |
| 86 | + selected: { |
| 87 | + marker: { |
| 88 | + opacity: extendFlat({}, choroplethAttrs.selected.marker.opacity, {editType: 'plot'}), |
| 89 | + editType: 'plot' |
| 90 | + }, |
| 91 | + editType: 'plot' |
| 92 | + }, |
| 93 | + unselected: { |
| 94 | + marker: { |
| 95 | + opacity: extendFlat({}, choroplethAttrs.unselected.marker.opacity, {editType: 'plot'}), |
| 96 | + editType: 'plot' |
| 97 | + }, |
| 98 | + editType: 'plot' |
| 99 | + }, |
| 100 | + |
| 101 | + hoverinfo: choroplethAttrs.hoverinfo, |
| 102 | + hovertemplate: hovertemplateAttrs({}, {keys: ['properties']}) |
| 103 | +}, |
| 104 | + |
| 105 | + colorScaleAttrs('', { |
| 106 | + cLetter: 'z', |
| 107 | + editTypeOverride: 'calc' |
| 108 | + }) |
| 109 | +); |
0 commit comments