Skip to content

Add cluster features to scattermapbox trace #5147

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

Closed
wants to merge 672 commits into from
Closed
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
672 commits
Select commit Hold shift + click to select a range
01115cd
Update src/plots/layout_attributes.js
archmoj Nov 2, 2020
8e64281
888: changed transformPlot fn, added dragzoom test
alexhartstone Nov 3, 2020
fb67c82
revise new attribute names and val types
archmoj Nov 3, 2020
aad34f1
Merge pull request #5232 from thierryVergult/treemapDrilldown
archmoj Nov 3, 2020
03ea08d
handle rootcolor and adopt tests
archmoj Nov 3, 2020
b5caa8f
Merge pull request #5245 from plotly/rootcolor-tests
archmoj Nov 3, 2020
f1c0e31
add early return for empty arrays to test category case and a bit of …
archmoj Nov 4, 2020
1977f12
Fix based on review comments
s417-lama Nov 4, 2020
837761c
maintain detecting dates using strict mode
archmoj Nov 4, 2020
ff0b32e
Merge pull request #5212 from s417-lama/legend_itemwidth
archmoj Nov 4, 2020
b73d395
pass convertNumeric to linearOK and category
archmoj Nov 4, 2020
0224fa0
store type of
archmoj Nov 4, 2020
d218bab
add early return for dates - remove unnecessary early return in linea…
archmoj Nov 4, 2020
b800a65
add early returns - array of arrays is not relevant to date, category…
archmoj Nov 4, 2020
f6d8c39
flat input array before passing to autoType functions
archmoj Nov 4, 2020
560405c
revert description change
archmoj Nov 4, 2020
4697f9c
flat 2d arrays before passing to autotypes
archmoj Nov 4, 2020
dbc5232
888: select test
alexhartstone Nov 4, 2020
07b934b
888: more flexible transform testing
alexhartstone Nov 4, 2020
96d7511
Merge pull request #5237 from plotly/fix4459-labels-disappear
archmoj Nov 4, 2020
688438c
handle typed arrays inside a 2d array - plus a bit of optimization
archmoj Nov 4, 2020
e02deaf
add tests for autotype - case of 2d arrays
archmoj Nov 4, 2020
4b5bfcc
correct keys in description
archmoj Nov 4, 2020
08aa300
drop unused option in ternary
archmoj Nov 4, 2020
1198e56
add noMultiCategory option for polar
archmoj Nov 4, 2020
99a2015
apply layout.calnedar and layout.autotypenumbers in box defaults
archmoj Nov 4, 2020
6fdf559
fixup box plot test to have a layout object
archmoj Nov 4, 2020
4e09ad3
Merge pull request #5240 from plotly/disable-convertnumeric-in-autotype
archmoj Nov 4, 2020
d75c018
888: polar hover test
alexhartstone Nov 5, 2020
24530b2
Fix broken link
ChaosEx Nov 5, 2020
c638fd6
Merge pull request #5253 from TeeVenDick/master
archmoj Nov 5, 2020
89666f8
centralize functions for adding 2d translate, uniform scale and simpl…
archmoj Nov 5, 2020
15c4fa0
remove unused condition check
archmoj Nov 5, 2020
c09fe29
Merge pull request #5254 from plotly/lib-transform-funcs
archmoj Nov 5, 2020
807de62
Fix typo in Czech locale file
helb Nov 6, 2020
e62219a
Merge pull request #5255 from helb/cs-locale-typo
archmoj Nov 6, 2020
d31244a
888: fix polar dragzoom
alexhartstone Nov 9, 2020
894a2eb
Support opacity
Nov 9, 2020
fcb9800
Fix role
Nov 9, 2020
5cd1157
Fix mock
Nov 9, 2020
1715133
Fix edittype
Nov 9, 2020
6b234f1
Reuse maxzoom from mapbox plot
Nov 9, 2020
9b38fa2
Fix syntax error
Nov 9, 2020
13ce0f0
update flaky list
archmoj Nov 9, 2020
11df3f6
more mock validation
archmoj Nov 9, 2020
a232c90
Merge pull request #5257 from plotly/fixup-image-tests
archmoj Nov 9, 2020
52d6e67
bump some dev deps
archmoj Nov 9, 2020
98dfdb8
Merge pull request #5258 from plotly/bump-dev-deps-Nov09-20
archmoj Nov 9, 2020
94f685f
888: fixed cartesian pan
alexhartstone Nov 10, 2020
435945b
888: use scale factors in polar too for performance
alexhartstone Nov 10, 2020
0d1db3f
Refactor to extract lookupBelow and findFollowingMapboxLayerId functions
jonmmease Nov 12, 2020
0f5e491
fix issue 5267 - pick correct categories and values pluse a bit of op…
archmoj Nov 12, 2020
82fbdcd
Reorder layer in updateImage to match what updateLayer would do
jonmmease Nov 12, 2020
e240ce6
Handle layer.source as arrays in equality check
jonmmease Nov 12, 2020
b95a0a5
add test to lock issue 5267
archmoj Nov 12, 2020
a51b91f
Merge pull request #5268 from plotly/fix5267-cartesian-category-values
archmoj Nov 12, 2020
4054735
Extend the updateImage mapbox test to check layer order
jonmmease Nov 12, 2020
a382098
Merge pull request #5269 from plotly/mapbox_layer_order
archmoj Nov 13, 2020
4da7e58
declare calcBreaksLength once
archmoj Nov 9, 2020
3ea0bb7
refactor inside and outside ticks
archmoj Nov 9, 2020
c7a23b4
fix issue 5262
archmoj Nov 12, 2020
a9d9140
rename axes.makeTransFn to makeTransTickFn
archmoj Nov 5, 2020
ee2d648
rename transFn function in cartesian axes
archmoj Nov 5, 2020
fa07cc5
create makeTransTickLabelFn and handle period case inside it
archmoj Nov 5, 2020
9e63c04
implement ticklabelposition for cartesian axes
archmoj Nov 13, 2020
7a6fd0f
add image tests
archmoj Nov 13, 2020
c5ff836
- Fix array support for opacity
Nov 15, 2020
1f42ee2
Remove scatter cluster mapbox
Nov 15, 2020
4b083e1
Fix syntax error
Nov 15, 2020
f3c03cd
888: assign scales at makePlotFramework
alexhartstone Nov 16, 2020
23b4d3c
888: fix polar plot rotation
alexhartstone Nov 16, 2020
84ede31
888: fix alignHTMLWith
archmoj Nov 16, 2020
4b1bf62
888: various syntax fixes
archmoj Nov 16, 2020
d3b548f
888: adjust scatter mapbox hover when css transition is present
archmoj Nov 16, 2020
4e1fd5f
drop unused argument
archmoj Nov 16, 2020
76afc6c
a bit of optimization in choropleth/hover - avoid creating the same a…
archmoj Nov 16, 2020
0117b41
888: fixup scattermapbox both select and hover
archmoj Nov 16, 2020
4980e24
return correct latitude and longitude from mapbox p2c
archmoj Nov 16, 2020
88b24f6
offsetX and offsetY are now implemented in FireFox - remove from blac…
archmoj Nov 17, 2020
42aabe1
rework matching & scaleanchor so they work together
alexcjohnson Nov 12, 2020
b2eed52
888: added polar drag and select tests
alexhartstone Nov 17, 2020
8cc496c
fixup polar test
archmoj Nov 17, 2020
1dee019
expand and fix tests
archmoj Nov 17, 2020
02b6f79
removed hacky clientX and clientY from scattermaobox events
archmoj Nov 17, 2020
805d97b
add scattermapbox tests when css transform is present
archmoj Nov 17, 2020
127f171
expand choropleth hover tests to cover css transform
archmoj Nov 17, 2020
12a57c9
expand choroplethmapbox hover tests to cover css transform
archmoj Nov 17, 2020
34845ec
expand select tests for various traces to cover css transform
archmoj Nov 18, 2020
29e772d
expand ternary hover and drag zoom tests to cover css transform
archmoj Nov 18, 2020
28a9178
remove dirty matrix validation - take care of matrix3d form instead
archmoj Nov 18, 2020
a2f34c9
adjust hover positions on parcats category bands in respect to css tr…
archmoj Nov 18, 2020
9fe42b6
adjust hover positions on sankey nodes in respect to css transforms
archmoj Nov 18, 2020
d76a304
compounding aspect ratios edge case test, and minor scale/match inter…
alexcjohnson Nov 18, 2020
5681a34
bypass test
archmoj Nov 18, 2020
e94ef47
bapass on more flaky test to pass on the CI
archmoj Nov 18, 2020
9cc0a15
integrate fullLayout inverseTransform and m shorthand
archmoj Nov 18, 2020
95a81fc
refactor polar fix
archmoj Nov 18, 2020
4afc441
Merge pull request #5193 from Displayr/888-style-transforms
archmoj Nov 18, 2020
c262d4b
store and use ticklabel bounding boxes to increase pad for inside labels
archmoj Nov 18, 2020
74f594d
autorange call to account extra pad for inside tick labels
archmoj Nov 18, 2020
5ca95d3
save initial ranges after insideticklabel is done
archmoj Nov 19, 2020
8a34a95
better fit based on tick angle - increase pad only when text does not…
archmoj Nov 19, 2020
13acf8a
baseline images altered by improved matching axes autorange
alexcjohnson Nov 19, 2020
22e9519
ensure plotinfo in axes redraw
archmoj Nov 19, 2020
95751cb
reset autorange flag for inside tick labels during GUI edits
archmoj Nov 19, 2020
ab37122
fixup interactions
archmoj Nov 19, 2020
52b5051
address issue 5289 - set false locale
archmoj Nov 19, 2020
0a21710
address issue 5289 - use if block instead of loop
archmoj Nov 19, 2020
aa6f442
Merge pull request #5293 from plotly/fix5289-gcc
archmoj Nov 19, 2020
ba58472
bump events to v3 in glslify
archmoj Nov 19, 2020
b1632b7
In staticPlot, do not draw zero length bars
antoinerg Nov 19, 2020
6a0ecd2
Merge pull request #5294 from plotly/remove-zero-length-bar-static-plot
antoinerg Nov 20, 2020
d9f4641
remove autorange duplication for matching axes
alexcjohnson Nov 20, 2020
b707c0f
fix tests & some edge cases uncovered by them
alexcjohnson Nov 20, 2020
bb70db7
fix a few baselines for updated matching autorange
alexcjohnson Nov 20, 2020
0f5c33c
update splom tests
alexcjohnson Nov 21, 2020
6d291c9
Merge branch 'master' into match-scale-aj
alexcjohnson Nov 21, 2020
1de111d
matches + scale interaction tests
alexcjohnson Nov 21, 2020
f78b46e
fix matches + rangebreaks, with a mock
alexcjohnson Nov 21, 2020
aaf33d3
remove TODO about rangebreaks - done :)
alexcjohnson Nov 21, 2020
f7baf5d
Merge pull request #5287 from plotly/match-scale-aj
alexcjohnson Nov 21, 2020
432e448
Merge remote-tracking branch 'origin/master' into ticklabelposition
archmoj Nov 21, 2020
e840f8f
update attribute description
archmoj Nov 23, 2020
2361958
revise ticklabelposition supply defaults
archmoj Nov 23, 2020
91ea2f6
validate new scaleanchor matches mocks
archmoj Nov 23, 2020
47c5773
hide out of range inside text labels during redraws
archmoj Nov 23, 2020
591b321
adjust padding for inside tick labels
archmoj Nov 23, 2020
bd379f8
improve overlap detection for aligned tick labels
archmoj Nov 23, 2020
05893b3
use lib function to convert from deg to rad
archmoj Nov 24, 2020
b5f09fb
revisit ticklabelposition logic
archmoj Nov 24, 2020
6e80dc9
fix issue 5301
archmoj Nov 24, 2020
21b59e4
fixups u and v
archmoj Nov 24, 2020
e01dc32
correct linewidth effect
archmoj Nov 24, 2020
b46327c
fixup tickangle for inside tick labels
archmoj Nov 25, 2020
aa57518
handle multi-line dates on x-axis
archmoj Nov 25, 2020
fe912ae
5291: recalculation of transforms on hover
alexhartstone Nov 25, 2020
70e708a
adjust pad for inside labels and make more room for end labels to appear
archmoj Nov 25, 2020
fa0f3b2
validate new mocks
archmoj Nov 25, 2020
26eb86a
reinstall glslify so that events bump to v3
archmoj Nov 25, 2020
c87cda6
add jsamine tests for ticklabelposition defaults
archmoj Nov 25, 2020
c59fcd9
clear function to hide inside tick labels and ensure subplot
archmoj Nov 25, 2020
d2c656d
simplify reading axis end positions to hide inside tick labels
archmoj Nov 25, 2020
d7423af
ensure ax._rl in hide function
archmoj Nov 25, 2020
cfd8e36
5291: make transform update func in fullLayout
alexhartstone Nov 26, 2020
2217f7c
5291: add transform recalc to prep funcs for various plots
alexhartstone Nov 26, 2020
60addca
compute linear range if not defined
archmoj Nov 26, 2020
a83d5af
add ticklabelposition option to colorbar
archmoj Nov 26, 2020
01efcf5
add inside and outside ticklabelposition options to mocks
archmoj Nov 26, 2020
5244a09
use fresh linear range in the hide function
archmoj Nov 26, 2020
a7518ec
add image test for issue 5301 - and before fixing another bug on the …
archmoj Nov 26, 2020
8efa7bd
adjust vertical ticklabels on x axes
archmoj Nov 26, 2020
2ff6cfb
revisit positioning of inside tick labels after bug fix
archmoj Nov 26, 2020
2108c8d
test another angle on the mock
archmoj Nov 26, 2020
a1d021b
adjustment for vertical tick labels inside
archmoj Nov 26, 2020
6f575a3
adjustment for vertical labels on the x axis and update baselines
archmoj Nov 26, 2020
0403aa7
5291: simplify recalculate fn name
alexhartstone Nov 26, 2020
3b9071f
5291: fixed syntax
alexhartstone Nov 27, 2020
8796f1b
5291: changed tests to do dynamic transforms
alexhartstone Nov 27, 2020
648c3c9
5291: fix syntax errors
alexhartstone Nov 27, 2020
0cf2a7f
add mock for reversed image that uses source
almarklein Nov 27, 2020
fb8d995
Reverse images as needed with css
almarklein Nov 27, 2020
fbaf868
fixup jasmine tests
archmoj Nov 27, 2020
3a5ca3a
ensure gd
archmoj Nov 27, 2020
189243f
formatting
almarklein Nov 27, 2020
0b2397a
fixup calcInverseTransform function and rename domRectsAreEqual
archmoj Nov 27, 2020
fe5ee9b
use shorter inverse keys for css transforms in gd._fullLayout
archmoj Nov 27, 2020
b97895f
remove unnecessary call at the end of makePlotFramework and call reca…
archmoj Nov 27, 2020
cdd836c
Merge pull request #5302 from Displayr/5291-dynamic-transforms
archmoj Nov 27, 2020
24c7699
remove jasmine tests that are no longer valid
almarklein Nov 29, 2020
0f0ca1f
Add jasmine test to validate that hover tool shows correct color rega…
almarklein Nov 29, 2020
2470532
Use strTranslate for cleaner code
almarklein Nov 29, 2020
7895727
Bit of suggested code refactoring
almarklein Nov 30, 2020
4d98780
fix test
almarklein Nov 30, 2020
a19b05b
remove mock
almarklein Nov 30, 2020
8ebfa71
improve test code
almarklein Nov 30, 2020
db00dea
also put autorange tests in
almarklein Nov 30, 2020
d4eadbd
correct style
archmoj Nov 30, 2020
e351d9b
simplify transform
almarklein Nov 30, 2020
632532f
fix transform, use linear ranges, fix tests, add mock
archmoj Nov 30, 2020
6d87753
Merge pull request #5307 from almarklein/reverse-y
archmoj Nov 30, 2020
5700db2
Merge pull request #5297 from plotly/bump-events-in-glslify
archmoj Nov 30, 2020
0e52adb
remove duplicate pad functions
archmoj Dec 1, 2020
999f877
revert guiEdit and fixup autorange interactions for inside tick labels
archmoj Dec 1, 2020
7b22175
revise axId scope
archmoj Dec 2, 2020
445eee4
fixup autorange on interactions
archmoj Dec 2, 2020
5f252f5
consider some offset from top of the bounding box when hiding a horiz…
archmoj Dec 2, 2020
90c3097
adjust position on bar_multiline_labels mock
archmoj Dec 2, 2020
40c09b7
add comment about U and V
archmoj Dec 2, 2020
08f3f04
Merge pull request #5275 from plotly/ticklabelposition
archmoj Dec 2, 2020
7527d55
update changelog for v1.58.0
archmoj Dec 2, 2020
4492a37
1.58.0
archmoj Dec 2, 2020
8c7a526
Fix contributer's name in CHANGELOG
s417-lama Dec 3, 2020
fa781ed
Merge pull request #5313 from s417-lama/changelog_typo
archmoj Dec 3, 2020
4a5a92c
Add scatterclustermapbox trace
Sep 14, 2020
7b1d507
Fix syntax error
Sep 14, 2020
54be4ae
Fix roles
Sep 14, 2020
7f1e699
Fix syntax
Sep 14, 2020
18eca7d
Format mock
Sep 14, 2020
fbc5666
Fix attributes
Sep 14, 2020
ee836ff
rename new mock, generate baseline and append new trace mock to the list
archmoj Sep 14, 2020
677f7c8
Share option functionality in scattermapbox and scatterclustermapbox
Sep 14, 2020
f07cae9
Fix linting
Sep 14, 2020
705468b
Add id to geojson and fix lines
Sep 14, 2020
e786754
Fix hover bug.
Sep 14, 2020
d00475a
Add clustering options to scattermapbox
Sep 14, 2020
0a345e3
Remove mock
Sep 14, 2020
0cbb4b5
Add hover functionality
Sep 14, 2020
75c1c39
Fix lint
Sep 14, 2020
43c219c
Remove legacy tests
Sep 14, 2020
0bc0328
Fix to old version
Sep 14, 2020
752060a
Fix legend selection/unselection
Sep 15, 2020
6e83a1c
Add test sample
Sep 15, 2020
5016156
Fix linting
Sep 15, 2020
43bb8f0
Add test
Sep 15, 2020
85b727f
Rewrite plot function
Sep 22, 2020
b16a694
Fix linting
Sep 22, 2020
4939d3b
Fix whitespace
Sep 24, 2020
0e61ce1
Fix whitespacae
Sep 24, 2020
1faa5b7
Fix linting
Sep 24, 2020
c5d67b6
Fix whitespace
Sep 24, 2020
95aedef
Add custom colors and sizes
Sep 24, 2020
eb799bc
lowercase attribute
Sep 24, 2020
4a37e2c
Fix default
Sep 24, 2020
97b8472
Update src/traces/scattermapbox/plot.js
elben10 Sep 24, 2020
f889df1
Add enabled to api
Sep 24, 2020
ed639f4
Fix addSource prototype
Sep 24, 2020
c902830
use indexOf instead of includes
Sep 24, 2020
0fe6ba2
Fix naming
Sep 24, 2020
de1dc20
Import core lib + update mock
Sep 28, 2020
c2f1ed4
Update src/traces/scattermapbox/convert.js
elben10 Sep 28, 2020
26e7791
Fix linting + remove comments
Sep 28, 2020
2ae0f1b
Fix typo
Sep 29, 2020
d23c597
Make code more readable + reuse marker attributes
Sep 29, 2020
9fc6f3c
Fix baseline
Sep 29, 2020
69d1589
Fix color and sizes
Sep 29, 2020
b03a18b
Fix typo
Sep 29, 2020
22abfa8
Change attributes to singular name + Refactor code
Oct 1, 2020
da9e6ec
Support opacity
Nov 9, 2020
68eea5c
Fix role
Nov 9, 2020
c6cfa77
Fix mock
Nov 9, 2020
ba7e38f
Fix edittype
Nov 9, 2020
ae93bf5
Reuse maxzoom from mapbox plot
Nov 9, 2020
3b1f0da
Fix syntax error
Nov 9, 2020
9d82a40
- Fix array support for opacity
Nov 15, 2020
6faf7b3
Remove scatter cluster mapbox
Nov 15, 2020
aeb2d7c
Fix syntax error
Nov 15, 2020
4c9eaeb
- Add tests
Dec 6, 2020
6a3ce4f
Merge branch 'master' of github.com:elben10/plotly.js
Dec 6, 2020
e1236a2
Remove radius attribute coercion
Dec 6, 2020
f536972
Fix linting errors
Dec 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/traces/scattermapbox/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,61 @@ module.exports = overrideAll({
lon: scatterGeoAttrs.lon,
lat: scatterGeoAttrs.lat,

cluster: {
enabled: {
valType: 'boolean',
role: 'info',
dflt: false,
editType: 'plot',
description: 'Determines whether clustering is enabled or disabled.'
},
maxzoom: {
valType: 'number',
role: 'info',
min: 0,
max: 22,
dflt: 14,
description: 'Sets the maximum zoom level for the cluster.',
},
radius: {
role: 'info',
valType: 'number',
dflt: 50,
description: 'Radius of each cluster when clustering points.',
},
steps: {
role: 'info',
valType: 'number',
arrayOk: true,
dflt: -1,
min: -1,
description: [
'Sets the steps for each cluster.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about what this attribute does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cluster can be coloured in different colors and take different sizes dependent on how many observations that are contained in a cluster. The steps determines when the cluster will change size or/and color

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice any changes when trying to tweak this parameter.
@elben10 wondering if you could provide an illustration?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cluster can be coloured in different colors and take different sizes dependent on how many observations that are contained in a cluster. The steps determines when the cluster will change size or/and color

Thanks @elben10 please provide part of this info in the attribute description.

].join(' ')
},
color: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we could drop color and size here and reuse trace.marker.color and trace.marker.size.

Copy link
Contributor Author

@elben10 elben10 Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can drop color and size. Shouldn't one be able to have different color and sized point and clusters. If we use the color from trace.marker.color it will no be possible to have a cluster with say 3 different colors, and the points being pained with another color.

Like this example

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of having color and size both be arrays, we might want to have a single attribute that accepts an array of color/size tuples like steps: [ {color: "red", size: 10} ] or something?

Copy link
Contributor Author

@elben10 elben10 Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need either color/size to be a singular value or an array. If color/size is an array, steps should also be defined as an array that has length one less than color/size. steps defines at which levels the cluster changes color/size dependent on how many observations the cluster contains.

One way to achieve that would be

steps: [ {color: "red", size: 10, "step": null}, {color: "blue", size: 20, "step": 20} ]

In this case, the cluster will be coloured red and sized 10 as long as there are less than 20 observations in the cluster else the cluster will be coloured blue and sized 20.

role: 'info',
valType: 'color',
dflt: '#51bbd6',
arrayOk: true,
editType: 'style',
anim: true,
description: [
'Sets the color for each cluster.'
].join(' ')
},
size: {
role: 'info',
valType: 'number',
arrayOk: true,
dflt: 20,
min: 0,
description: [
'Sets the size for each cluster.'
].join(' ')
},
},

// locations
// locationmode

Expand Down
75 changes: 65 additions & 10 deletions src/traces/scattermapbox/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,39 @@ module.exports = function convert(gd, calcTrace) {
var hasLines = subTypes.hasLines(trace);
var hasMarkers = subTypes.hasMarkers(trace);
var hasText = subTypes.hasText(trace);
var hasCircles = (hasMarkers && trace.marker.symbol === 'circle');
var hasSymbols = (hasMarkers && trace.marker.symbol !== 'circle');
var hasCircles = hasMarkers && trace.marker.symbol === 'circle';
var hasSymbols = hasMarkers && trace.marker.symbol !== 'circle';
var hasCluster = trace.cluster.enabled;

var fill = initContainer();
var line = initContainer();
var circle = initContainer();
var symbol = initContainer();
var fill = initContainer('fill');
var line = initContainer('line');
var circle = initContainer('circle');
var symbol = initContainer('symbol');

var opts = {
fill: fill,
line: line,
circle: circle,
symbol: symbol
symbol: symbol,
cluster: {
type: 'circle',
filter: ['has', 'point_count'],
layout: {visibility: 'visible'},
paint: {
'circle-color': createClusterColors(trace.cluster.color, trace.cluster.steps),
'circle-radius': createClusterSizes(trace.cluster.size, trace.cluster.steps)
},
},
clusterCount: {
type: 'symbol',
filter: ['has', 'point_count'],
paint: {},
layout: {
'text-field': '{point_count_abbreviated}',
'text-font': ['Open Sans Regular', 'Arial Unicode MS Regular'],
'text-size': 12
}
}
};

// early return if not visible or placeholder
Expand Down Expand Up @@ -90,6 +110,10 @@ module.exports = function convert(gd, calcTrace) {
});
}

if(hasCircles && hasCluster) {
circle.filter = ['!', ['has', 'point_count']];
}

if(hasSymbols || hasText) {
symbol.geojson = makeSymbolGeoJSON(calcTrace, gd);

Expand Down Expand Up @@ -150,10 +174,12 @@ module.exports = function convert(gd, calcTrace) {
return opts;
};

function initContainer() {
function initContainer(type) {
return {
type: type,
geojson: geoJsonUtils.makeBlank(),
layout: { visibility: 'none' },
filter: null,
paint: {}
};
}
Expand Down Expand Up @@ -208,7 +234,8 @@ function makeCircleOpts(calcTrace) {

features.push({
type: 'Feature',
geometry: {type: 'Point', coordinates: lonlat},
id: i + 1,
geometry: { type: 'Point', coordinates: lonlat },
properties: props
});
}
Expand Down Expand Up @@ -266,7 +293,6 @@ function makeSymbolGeoJSON(calcTrace, gd) {
getFillFunc(trace.text) :
blankFillFunc;


var features = [];

for(var i = 0; i < calcTrace.length; i++) {
Expand Down Expand Up @@ -331,3 +357,32 @@ function blankFillFunc() { return ''; }
function isBADNUM(lonlat) {
return lonlat[0] === BADNUM;
}

function createClusterColors(colors, steps) {
var idx, newColors;
if(Lib.isArrayOrTypedArray(colors)) {
newColors = ['step', ['get', 'point_count'], colors[0]];
for(idx = 1; idx < colors.length; idx++) {
newColors.push(steps[idx - 1], colors[idx]);
}
} else {
newColors = colors;
}
return newColors;
}

function createClusterSizes(sizes, steps) {
var idx, newSizes;
if(
Lib.isArrayOrTypedArray(sizes) &&
Lib.isArrayOrTypedArray(steps)
) {
newSizes = ['step', ['get', 'point_count'], sizes[0]];
for(idx = 1; idx < sizes.length; idx++) {
newSizes.push(steps[idx - 1], sizes[idx]);
}
} else {
newSizes = sizes;
}
return newSizes;
}
9 changes: 9 additions & 0 deletions src/traces/scattermapbox/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
return;
}

var clusterEnabled = coerce('cluster.enabled');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcjohnson should we use Lib.coerce2 for this attribute?

if(clusterEnabled) {
coerce('cluster.maxzoom');
coerce('cluster.radius');
coerce('cluster.steps');
coerce('cluster.size');
coerce('cluster.color');
}

coerce('text');
coerce('texttemplate');
coerce('hovertext');
Expand Down
9 changes: 9 additions & 0 deletions src/traces/scattermapbox/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ var Lib = require('../../lib');
var getTraceColor = require('../scatter/get_trace_color');
var fillText = Lib.fillText;
var BADNUM = require('../../constants/numerical').BADNUM;
var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix;

module.exports = function hoverPoints(pointData, xval, yval) {
var cd = pointData.cd;
var trace = cd[0].trace;
var xa = pointData.xa;
var ya = pointData.ya;
var subplot = pointData.subplot;
var clusteredPointsIds = [];
var layer = LAYER_PREFIX + trace.uid + '-circle';

if(trace.cluster.enabled) {
var elems = subplot.map.queryRenderedFeatures(null, {layers: [layer]});
clusteredPointsIds = elems.map(function(elem) {return elem.id;});
}

// compute winding number about [-180, 180] globe
var winding = (xval >= 0) ?
Expand All @@ -34,6 +42,7 @@ module.exports = function hoverPoints(pointData, xval, yval) {
function distFn(d) {
var lonlat = d.lonlat;
if(lonlat[0] === BADNUM) return Infinity;
if(trace.cluster.enabled && clusteredPointsIds.indexOf(d.i + 1) === -1) return Infinity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hover does not appear!
But if you revert the changes if hover.js it displays the original data points; which I think is desirable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hover functionality should at the moment work when the individual points is unpacked from the cluster.

I think it is desirable to enable the hover functionality is being enabled when the individual points is unpacked from its cluster


var lon = Lib.modHalf(lonlat[0], 360);
var lat = lonlat[1];
Expand Down
Loading