-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Miscellaneous mapbox tweaks #681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9c72548
4a8563b
32973fc
17f3378
053058a
c1cd50c
a899283
34d5275
cf27e55
1620e61
51fa1ea
60e4285
0d082e4
0fdf70c
cb854fe
752c419
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
var Lib = require('../../lib'); | ||
|
||
|
||
/** | ||
* Convert plotly.js 'textposition' to mapbox-gl 'anchor' and 'offset' | ||
* (with the help of the icon size). | ||
* | ||
* @param {string} textpostion : plotly.js textposition value | ||
* @param {number} iconSize : plotly.js icon size (e.g. marker.size for traces) | ||
* | ||
* @return {object} | ||
* - anchor | ||
* - offset | ||
*/ | ||
module.exports = function convertTextOpts(textposition, iconSize) { | ||
var parts = textposition.split(' '), | ||
vPos = parts[0], | ||
hPos = parts[1]; | ||
|
||
// ballpack values | ||
var factor = Array.isArray(iconSize) ? Lib.mean(iconSize) : iconSize, | ||
xInc = 0.5 + (factor / 100), | ||
yInc = 1.5 + (factor / 100); | ||
|
||
var anchorVals = ['', ''], | ||
offset = [0, 0]; | ||
|
||
switch(vPos) { | ||
case 'top': | ||
anchorVals[0] = 'top'; | ||
offset[1] = -yInc; | ||
break; | ||
case 'bottom': | ||
anchorVals[0] = 'bottom'; | ||
offset[1] = yInc; | ||
break; | ||
} | ||
|
||
switch(hPos) { | ||
case 'left': | ||
anchorVals[1] = 'right'; | ||
offset[0] = -xInc; | ||
break; | ||
case 'right': | ||
anchorVals[1] = 'left'; | ||
offset[0] = xInc; | ||
break; | ||
} | ||
|
||
// Mapbox text-anchor must be one of: | ||
// center, left, right, top, bottom, | ||
// top-left, top-right, bottom-left, bottom-right | ||
|
||
var anchor; | ||
if(anchorVals[0] && anchorVals[1]) anchor = anchorVals.join('-'); | ||
else if(anchorVals[0]) anchor = anchorVals[0]; | ||
else if(anchorVals[1]) anchor = anchorVals[1]; | ||
else anchor = 'center'; | ||
|
||
return { anchor: anchor, offset: offset }; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,10 @@ | |
|
||
'use strict'; | ||
|
||
var scatterMapboxAttrs = require('../../traces/scattermapbox/attributes'); | ||
var Lib = require('../../lib'); | ||
var defaultLine = require('../../components/color').defaultLine; | ||
var extendFlat = require('../../lib').extendFlat; | ||
|
||
var lineAttrs = scatterMapboxAttrs.line; | ||
var fontAttrs = require('../font_attributes'); | ||
var textposition = require('../../traces/scatter/attributes').textposition; | ||
|
||
|
||
module.exports = { | ||
|
@@ -129,15 +128,18 @@ module.exports = { | |
|
||
type: { | ||
valType: 'enumerated', | ||
values: ['line', 'fill'], | ||
dflt: 'line', | ||
values: ['circle', 'line', 'fill', 'symbol'], | ||
dflt: 'circle', | ||
role: 'info', | ||
description: [ | ||
'Sets the layer type.', | ||
'Support for *raster*, *background* types is coming soon.' | ||
'Support for *raster*, *background* types is coming soon.', | ||
'Note that *line* and *fill* are not compatible with Point', | ||
'GeoJSON geometries.' | ||
].join(' ') | ||
}, | ||
|
||
// attributes shared between all types | ||
below: { | ||
valType: 'string', | ||
dflt: '', | ||
|
@@ -149,23 +151,101 @@ module.exports = { | |
'the layer will be inserted above every existing layer.' | ||
].join(' ') | ||
}, | ||
|
||
line: { | ||
color: extendFlat({}, lineAttrs.color, { | ||
dflt: defaultLine | ||
}), | ||
width: lineAttrs.width | ||
color: { | ||
valType: 'color', | ||
dflt: defaultLine, | ||
role: 'style', | ||
description: [ | ||
'Sets the primary layer color.', | ||
'If `type` is *circle*, color corresponds to the circle color', | ||
'If `type` is *line*, color corresponds to the line color', | ||
'If `type` is *fill*, color corresponds to the fill color', | ||
'If `type` is *symbol*, color corresponds to the icon color' | ||
].join(' ') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleaner, right? |
||
}, | ||
|
||
fillcolor: scatterMapboxAttrs.fillcolor, | ||
|
||
opacity: { | ||
valType: 'number', | ||
min: 0, | ||
max: 1, | ||
dflt: 1, | ||
role: 'info', | ||
description: 'Sets the opacity of the layer.' | ||
}, | ||
|
||
// type-specific style attributes | ||
circle: { | ||
radius: { | ||
valType: 'number', | ||
dflt: 15, | ||
role: 'style', | ||
description: [ | ||
'Sets the circle radius.', | ||
'Has an effect only when `type` is set to *circle*.' | ||
].join(' ') | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}, | ||
|
||
line: { | ||
width: { | ||
valType: 'number', | ||
dflt: 2, | ||
role: 'style', | ||
description: [ | ||
'Sets the line radius.', | ||
'Has an effect only when `type` is set to *line*.' | ||
].join(' ') | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing opacity here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. layers of different type don't need different There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yeah, isee now |
||
}, | ||
|
||
fill: { | ||
outlinecolor: { | ||
valType: 'color', | ||
dflt: defaultLine, | ||
role: 'style', | ||
description: [ | ||
'Sets the fill outline color.', | ||
'Has an effect only when `type` is set to *fill*.' | ||
].join(' ') | ||
} | ||
}, | ||
|
||
symbol: { | ||
icon: { | ||
valType: 'string', | ||
dflt: 'marker', | ||
role: 'style', | ||
description: [ | ||
'Sets the symbol icon image.', | ||
'Full list: https://www.mapbox.com/maki-icons/' | ||
].join(' ') | ||
}, | ||
iconsize: { | ||
valType: 'number', | ||
dflt: 10, | ||
role: 'style', | ||
description: [ | ||
'Sets the symbol icon size.', | ||
'Has an effect only when `type` is set to *symbol*.' | ||
].join(' ') | ||
}, | ||
text: { | ||
valType: 'string', | ||
dflt: '', | ||
role: 'info', | ||
description: [ | ||
'Sets the symbol text.' | ||
].join(' ') | ||
}, | ||
textfont: Lib.extendDeep({}, fontAttrs, { | ||
description: [ | ||
'Sets the icon text font.', | ||
'Has an effect only when `type` is set to *symbol*.' | ||
].join(' '), | ||
family: { | ||
dflt: 'Open Sans Regular, Arial Unicode MS Regular' | ||
} | ||
}), | ||
textposition: Lib.extendFlat({}, textposition, { arrayOk: false }) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
presumably
, *symbol*
too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I could add it now if you want.