-
Notifications
You must be signed in to change notification settings - Fork 26
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
Change eval methods for multiple feature #1376
Merged
elenatorro
merged 11 commits into
develop
from
feature/1348-change-eval-methods-for-multiple-features
Jul 12, 2019
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
02c9bcf
First PoC to improve getLegendData with several operators
elenatorro 2fe523d
Merge branch 'develop' into 1348-change-eval-methods-for-multiple-fea…
elenatorro 3c3f84b
PoC bivariate legends
elenatorro 78cc532
Fix eval
elenatorro f775bc8
Update example
elenatorro ed5d065
Move binary expressions to independent files
elenatorro cfecb3c
Fix Mul and add tests
elenatorro 5194c29
Fix and add missing specs
elenatorro abddc6a
Add legend dimensions
elenatorro 3ee589b
Add to CHANGELOG
elenatorro 8c91928
Merge branch 'develop' into feature/1348-change-eval-methods-for-mult…
elenatorro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<script src="../../dist/carto-vl.js"></script> | ||
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.js"></script> | ||
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.css" rel="stylesheet" /> | ||
<link rel="stylesheet" type="text/css" href="../../examples/style.css"> | ||
<style> | ||
ul.legend { | ||
display: grid; | ||
list-style: none; | ||
grid-template-columns: 1fr 1fr 1fr; | ||
grid-template-rows: 1fr 1fr 1fr; | ||
grid-gap: 1px; | ||
width: 100%; | ||
height: 100%; | ||
background: white; | ||
box-sizing: border-box; | ||
margin: 12px 0 0; | ||
padding: 0; | ||
} | ||
|
||
ul.legend > li { | ||
height: 70px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="map"></div> | ||
<aside class="toolbox"> | ||
<div class="box"> | ||
<header> | ||
<h1>Bivariate Legends</h1> | ||
</header> | ||
<section> | ||
<div id="legend" class="bivariate-legend"> | ||
<ul id="legend-content" class="legend"></ul> | ||
</div> | ||
<div id="controls"> | ||
<ul id="content"></ul> | ||
</div> | ||
</section> | ||
<footer class="js-footer"></footer> | ||
</div> | ||
</aside> | ||
<div id="loader"> | ||
<div class="CDB-LoaderIcon CDB-LoaderIcon--big"> | ||
<svg class="CDB-LoaderIcon-spinner" viewBox="0 0 50 50"> | ||
<circle class="CDB-LoaderIcon-path" cx="25" cy="25" r="20" fill="none"></circle> | ||
</svg> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
const map = new mapboxgl.Map({ | ||
container: 'map', | ||
style: carto.basemaps.positron, | ||
center: [-96.72033740507385, 32.84383032617839], | ||
zoom: 10.2 | ||
}); | ||
|
||
carto.setDefaultAuth({ | ||
username: 'cartovl', | ||
apiKey: 'default_public' | ||
}); | ||
|
||
const source = new carto.source.Dataset('dallas_mkt'); | ||
|
||
const viz = new carto.Viz(` | ||
strokeColor: rgba(255,255,255,0.2) | ||
@pop: $pop_sqkm | ||
@percent: $percent_25_29 | ||
color: ramp(globalQuantiles($pop_sqkm, 3), [#e8e8e8, #dfb0d6, #be64ac]) * | ||
ramp(globalQuantiles($percent_25_29, 3), [#e8e8e8, #ace4e4, #5ac8c8]) | ||
`); | ||
|
||
const layer = new carto.Layer('layer', source, viz); | ||
layer.addTo(map); | ||
|
||
layer.on('loaded', () => { | ||
hideLoader(); | ||
|
||
const legends = layer.viz.color.getLegendData(); | ||
let content = ''; | ||
|
||
legends.data.forEach((legend) => { | ||
const colorHex = rgbToHex(legend.value); | ||
content += | ||
`<li style="background-color:${colorHex};"></li>` | ||
}); | ||
|
||
document.getElementById('legend-content').innerHTML = content; | ||
}); | ||
|
||
function hideLoader() { | ||
document.getElementById('loader').style.opacity = '0'; | ||
} | ||
|
||
function rgbToHex(color) { | ||
return "#" + ((1 << 24) + (color.r << 16) + (color.g << 8) + color.b).toString(16).slice(1); | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import { And, Or, Equals, NotEquals, LessThan, LessThanOrEqualTo, GreaterThan, GreaterThanOrEqualTo } from '../renderer/viz/expressions/binary'; | ||
import GreaterThan from '../renderer/viz/expressions/binary/GreaterThan'; | ||
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. Why this small refactor here? Was it maybe based on some tooling? 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. Oh, I see it now... you deleted the binary.js, much better |
||
import GreaterThanOrEqualTo from '../renderer/viz/expressions/binary/GreaterThanOrEqualTo'; | ||
import LessThan from '../renderer/viz/expressions/binary/LessThan'; | ||
import LessThanOrEqualTo from '../renderer/viz/expressions/binary/LessThanOrEqualTo'; | ||
import And from '../renderer/viz/expressions/binary/And'; | ||
import Or from '../renderer/viz/expressions/binary/Or'; | ||
import Equals from '../renderer/viz/expressions/binary/Equals'; | ||
import NotEquals from '../renderer/viz/expressions/binary/NotEquals'; | ||
import { In, Nin } from '../renderer/viz/expressions/belongs'; | ||
import Between from '../renderer/viz/expressions/between'; | ||
import Property from '../renderer/viz/expressions/basic/property'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@elenatorro I think we can now remove this
rgbToHex
thing, and just usargba
as infeature-and-legend-opacity.html
exampleThere 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.
I would probably move this 'debug' example to public ones, what do you think? Or maybe we should do a small blog post?
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.
Totally! I'd like to have this in a separate task (since this one is a bit big), and it'd be great to have more than one example (but not too much, I mean, like two or three). At leas this one and another one that combines with and color properties.
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.
Fair enough. We can keep the rgbToHex if it is just a debug example.