Automated coloring calculation - interval, percentile
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
Motivation
Calculating the right values for color steps is hard and error-prone. Why not using mapbox gl to take over this task?
Design
Current approach
map.addLayer({
'id': 'data_layer',
'source': 'data',
'type': 'fill',
'paint': {
'fill-color': {
property: 'my_field',
type: 'interval',
stops: [
[0.002, '#dedcf1'],
[0.015, '#bfbce5'],
[0.0276, '#9c98d7'],
[0.0394, '#6760c1'],
[0.05, '#1f12a0']],
default: "#ffffff"
}
}
});
New approach
map.addLayer({
'id': 'data_layer',
'source': 'data',
'type': 'fill',
'paint': {
'fill-color': {
property: 'my_field',
type: 'interval', //'interval' or 'percentile'
colors: ['#dedcf1', '#bfbce5', '#9c98d7', '#6760c1', '#1f12a0'],
default: "#ffffff"
}
}
});
Instead of pairing each color with a value, in this approach Mapbox will calculate it by itself. By setting the type to interval, Mapbox will look at all values, the numbers of colors and calculating the steps by itself.
Types
Not only interval should be a possible option for type, I would recommend the following:
- Interval
- Percentile
Pros and Cons
I cant talk about the complexity to implement it. One contra: Performance. Imagine we will use automated coloring for fill-color and line-color. The colors should in this case only be calculated once. Therefore it should possible to store the result of the calculation in a variable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start by tracing the map.addLayer handling for fill-color expressions, then determine how interval and percentile values would be calculated from the available feature data. Done means supporting the proposed colors and type options while allowing one calculation to be reused by fill-color and line-color.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- computer-graphics, frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100