-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using JS to customize spatial viz and tooltips
- Loading branch information
1 parent
0cb7c5e
commit be1a0f5
Showing
11 changed files
with
194 additions
and
45 deletions.
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,4 @@ | ||
.chart-tooltip { | ||
opacity: 0.75; | ||
font-size: 12px; | ||
} |
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
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,33 @@ | ||
import dompurify from 'dompurify'; | ||
import sandboxedEval from '../../../javascripts/modules/sandbox'; | ||
|
||
export function commonLayerProps(formData, slice) { | ||
const fd = formData; | ||
let onHover; | ||
if (fd.js_tooltip) { | ||
const jsTooltip = sandboxedEval(fd.js_tooltip); | ||
onHover = (o) => { | ||
if (o.picked) { | ||
slice.setTooltip({ | ||
content: dompurify.sanitize(jsTooltip(o)), | ||
x: o.x, | ||
y: o.y, | ||
}); | ||
} else { | ||
slice.setTooltip(null); | ||
} | ||
}; | ||
} | ||
let onClick; | ||
if (fd.js_onclick_href) { | ||
onClick = (o) => { | ||
const href = sandboxedEval(fd.js_onclick_href)(o); | ||
window.open(href); | ||
}; | ||
} | ||
return { | ||
onClick, | ||
onHover, | ||
pickable: Boolean(onHover), | ||
}; | ||
} |
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,19 +1,29 @@ | ||
import { PathLayer } from 'deck.gl'; | ||
|
||
export default function getLayer(formData, payload) { | ||
import * as common from './common'; | ||
import sandboxedEval from '../../../javascripts/modules/sandbox'; | ||
|
||
export default function getLayer(formData, payload, slice) { | ||
const fd = formData; | ||
const c = fd.color_picker; | ||
const fixedColor = [c.r, c.g, c.b, 255 * c.a]; | ||
const data = payload.data.paths.map(path => ({ | ||
path, | ||
let data = payload.data.features.map(feature => ({ | ||
...feature, | ||
path: feature.path, | ||
width: fd.line_width, | ||
color: fixedColor, | ||
})); | ||
|
||
if (fd.js_datapoint_mutator) { | ||
const jsFnMutator = sandboxedEval(fd.js_datapoint_mutator); | ||
data = data.map(jsFnMutator); | ||
} | ||
|
||
return new PathLayer({ | ||
id: `path-layer-${fd.slice_id}`, | ||
data, | ||
rounded: true, | ||
widthScale: 1, | ||
...common.commonLayerProps(fd, slice), | ||
}); | ||
} |
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.