Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Duberstein committed Dec 11, 2019
1 parent 7c7281d commit 134f927
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 26 deletions.
1 change: 1 addition & 0 deletions bindings/python/pydeck/tests/bindings/test_deck.py
Expand Up @@ -50,6 +50,7 @@ def create_multi_layer_test_object():
"TextLayer",
id='textlayer',
data=[{"position": [-122.45, 37.8], "text": "Hello World"}],
get_position='position',
get_text_anchor="end",
)
geojson_layer = Layer(
Expand Down
1 change: 0 additions & 1 deletion bindings/python/pydeck/tests/fixtures/minimal.json
Expand Up @@ -19,7 +19,6 @@
],
"elevationScale": 50,
"extruded": true,
"getPosition": "[lng, lat]",
"id": "heatmap",
"lightSettings": {
"ambientRatio": 0.4,
Expand Down
6 changes: 1 addition & 5 deletions bindings/python/pydeck/tests/fixtures/multilayers.json
@@ -1,11 +1,7 @@
{
"initialViewState": {
"bearing": 0,
"latitude": -122.45,
"longitude": 37.8,
"maxZoom": 20,
"minZoom": 0,
"pitch": 0,
"zoom": 12
},
"layers": [
Expand Down Expand Up @@ -40,7 +36,7 @@
"text": "Hello World"
}
],
"getPosition": "[lng, lat]",
"getPosition": "position",
"getTextAnchor": "end",
"id": "textlayer"
},
Expand Down
19 changes: 5 additions & 14 deletions modules/json/src/json-converter.js
Expand Up @@ -11,12 +11,11 @@
import assert from './utils/assert';
import JSONConfiguration from './json-configuration';
import {instantiateClass} from './helpers/instantiate-class';

import {FUNCTION_IDENTIFIER, CONSTANT_IDENTIFIER} from './syntactic-sugar';
import parseJSON from './helpers/parse-json';

const isObject = value => value && typeof value === 'object';
const FUNCTION_IDENTIFIER = '@@=';
const ENUM_IDENTIFIER = '@@#';
const CONSTANT_IDENTIFIER = '@@!';

export default class JSONConverter {
constructor(props) {
Expand Down Expand Up @@ -104,7 +103,8 @@ function convertJSONRecursively(json, key, configuration) {
// Returns true if an object has a `type` field
function isClassInstance(json, configuration) {
const {typeKey} = configuration;
return isObject(json) && Boolean(json[typeKey]);
const isClass = isObject(json) && Boolean(json[typeKey]);
return isClass;
}

function convertClassInstance(json, configuration) {
Expand Down Expand Up @@ -140,16 +140,7 @@ function convertString(string, key, configuration) {
// Here the JSON value is supposed to be treated as a function
if (string.startsWith(FUNCTION_IDENTIFIER) && configuration.convertFunction) {
string = string.replace(FUNCTION_IDENTIFIER, '');
return configuration.convertFunction(string, key, configuration);
}
if (string.startsWith(CONSTANT_IDENTIFIER)) {
string = string.replace(CONSTANT_IDENTIFIER, '');
return configuration.constants[string];
}
if (string.startsWith(ENUM_IDENTIFIER)) {
string = string.replace(ENUM_IDENTIFIER, '');
const [enumVarName, enumValName] = string.split('.');
return configuration.enumerations[enumVarName][enumValName];
return configuration.convertFunction(string, configuration);
}
if (string.startsWith(CONSTANT_IDENTIFIER)) {
string = string.replace(CONSTANT_IDENTIFIER, '');
Expand Down
9 changes: 7 additions & 2 deletions test/modules/json/data/deck-props.json
Expand Up @@ -4,13 +4,18 @@
"latitude": 37.8,
"zoom": 12
},
"controller": "@@!MapController",
"controller": "@@#MapController",
"mapStyle": {},
"views": [
{
"@@type": "MapView",
"height": "50%",
"controller": true
},
{
"@@type": "FirstPersonView",
"y": "50%",
"height": "50%"
}
],
"layers": [
Expand Down Expand Up @@ -46,7 +51,7 @@
0,
3000
],
"getText": "Hello World",
"getText": "@@=Hello World",
"billboard": false
}
]
Expand Down
8 changes: 4 additions & 4 deletions test/render/jupyter-widget.js
Expand Up @@ -54,8 +54,8 @@ const TEST_CASES = [
rgb: [123, 159, 53]
}
],
getColor: 'rgb',
getPosition: 'position',
getColor: '@@=rgb',
getPosition: '@@=position',
getRadius: 100
},
{
Expand All @@ -72,8 +72,8 @@ const TEST_CASES = [
],
fontSize: 144,
getColor: [0, 0, 255],
getPosition: 'position',
getTextAnchor: '"start"',
getPosition: '@@=position',
getTextAnchor: 'start',
fontFamily: 'Times, Times New Roman, Georgia, serif'
}
]
Expand Down

0 comments on commit 134f927

Please sign in to comment.