Fixes visualizations when using Enso's builtin JSON parser (https://github.com/enso-org/ide/pull/912)

Original commit: 788892be52
This commit is contained in:
Maciej Mikołajek 2020-11-05 11:18:06 +01:00 committed by GitHub
parent 3354d69381
commit 073f22a67c
3 changed files with 25 additions and 6 deletions

View File

@ -62,12 +62,21 @@ class MapViewVisualization extends Visualization {
mapElem.setAttributeNS(null,"style","width:" + width + "px;height: " + height + "px;");
this.dom.appendChild(mapElem);
const parsedData = eval('('+data+')' );
let parsedData = data;
if (typeof data === "string") {
parsedData = JSON.parse(data);
}
let defaultMapStyle = 'mapbox://styles/mapbox/light-v9';
if (document.getElementById("root").classList.contains("dark")){
defaultMapStyle = 'mapbox://styles/mapbox/dark-v9';
}
const deckgl = new deck.DeckGL({
container: 'map',
mapboxApiAccessToken: 'pk.eyJ1IjoiZW5zby1vcmciLCJhIjoiY2tmNnh5MXh2MGlyOTJ5cWdubnFxbXo4ZSJ9.3KdAcCiiXJcSM18nwk09-Q',
mapStyle: parsedData.mapStyle || 'mapbox://styles/mapbox/light-v9',
mapStyle: parsedData.mapStyle || defaultMapStyle,
initialViewState: {
longitude: parsedData.longitude || 0.0,
latitude: parsedData.latitude || 0.0,

View File

@ -90,7 +90,10 @@ class ScatterPlot extends Visualization {
const divElem = this.createDivElem(width,height);
this.dom.appendChild(divElem);
let parsedData = JSON.parse(data);
let parsedData = data;
if (typeof data === "string") {
parsedData = JSON.parse(data);
}
let axis = parsedData.axis || {x:{scale:linear_scale},y:{scale:linear_scale}};
let focus = parsedData.focus;
let points = parsedData.points || {labels:"invisible"};

View File

@ -233,10 +233,17 @@ class TableViewVisualization extends Visualization {
tabElem.setAttributeNS(null,"style" ,tblViewStyle);
this.dom.appendChild(tabElem);
let parsedData = JSON.parse(data);
let table = genTable(parsedData.data || parsedData, 0, parsedData.header);
tabElem.innerHTML = style_light + table;
let parsedData = data;
if (typeof data === "string") {
parsedData = JSON.parse(data);
}
let style = style_light
if (document.getElementById("root").classList.contains("dark")){
style = style_dark + table;
}
let table = genTable(parsedData.data || parsedData, 0, parsedData.header);
tabElem.innerHTML = style + table;
}
setSize(size) {