Skip to content

Commit 0a437a6

Browse files
committed
use circle for densitymapbox legend with radial gradient
1 parent ce35947 commit 0a437a6

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

src/components/legend/style.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,17 @@ module.exports = function style(s, gd) {
499499
break;
500500
case 'choropleth' :
501501
case 'choroplethmapbox' :
502-
case 'densitymapbox' :
503502
ptsData = [
504503
['M-6,-6V6H6V-6Z']
505504
];
506505
useGradient = true;
507506
break;
507+
case 'densitymapbox' :
508+
ptsData = [
509+
['M-6,0 a6,6 0 1,0 12,0 a 6,6 0 1,0 -12,0']
510+
];
511+
useGradient = 'radial';
512+
break;
508513
case 'cone' :
509514
ptsData = [
510515
['M-6,2 A2,2 0 0,0 -6,6 V6L6,4Z'],
@@ -573,7 +578,7 @@ module.exports = function style(s, gd) {
573578
if(s.size()) {
574579
var gradientID = 'legendfill-' + trace.uid;
575580
Drawing.gradient(s, gd, gradientID,
576-
getGradientDirection(reversescale),
581+
getGradientDirection(reversescale, useGradient === 'radial'),
577582
colorscale, 'fill');
578583
}
579584
};
@@ -602,6 +607,7 @@ module.exports = function style(s, gd) {
602607
}
603608
};
604609

605-
function getGradientDirection(reversescale) {
606-
return reversescale ? 'horizontal' : 'horizontalreversed';
610+
function getGradientDirection(reversescale, isRadial) {
611+
var str = isRadial ? 'radial' : 'horizontal';
612+
return str + (reversescale ? '' : 'reversed');
607613
}
Loading
358 Bytes
Loading
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"data": [{
3+
"showlegend": true,
4+
"showscale": false,
5+
"type": "densitymapbox",
6+
"name": "w/ reversescale:true",
7+
"lon": [10, 20, 30],
8+
"lat": [15, 25, 35],
9+
"z": [1, 3, 2],
10+
"zmid": 0,
11+
"reversescale": true,
12+
"radius": 50,
13+
"below": "",
14+
"colorbar": {
15+
"y": 1,
16+
"yanchor": "top",
17+
"len": 0.45
18+
}
19+
}, {
20+
"showlegend": true,
21+
"showscale": false,
22+
"type": "densitymapbox",
23+
"name": "w/0 z data",
24+
"lon": [-10, -20, -30],
25+
"lat": [15, 25, 35],
26+
"zmin": 0,
27+
"zauto": false,
28+
"radius": [50, 100, 10],
29+
"colorbar": {
30+
"y": 0,
31+
"yanchor": "bottom",
32+
"len": 0.45
33+
}
34+
}],
35+
"layout": {
36+
"mapbox": {
37+
"style": "light",
38+
"center": {"lat": 20}
39+
},
40+
"width": 600,
41+
"height": 400
42+
}
43+
}

0 commit comments

Comments
 (0)