Skip to content

Commit 20a3545

Browse files
#107 added parse config to data.view .config save
in order to create more readable data.view json configs for loading and display
1 parent 16e94ad commit 20a3545

2 files changed

Lines changed: 56 additions & 7 deletions

File tree

data/json/cars.config

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
11
{
22
"config": {
3-
"aggregates": "{\"Name\":\"count\",\"Origin\":\"count\",\"Year\":\"count\",\"Acceleration\":\"sum\",\"Cylinders\":\"sum\",\"Displacement\":\"sum\",\"Horsepower\":\"sum\",\"Miles_per_Gallon\":\"sum\",\"Weight_in_lbs\":\"sum\"}",
4-
"column-pivots": "[]",
5-
"columns": "[\"Acceleration\",\"Cylinders\",\"Displacement\",\"Horsepower\",\"Miles_per_Gallon\",\"Name\",\"Origin\",\"Weight_in_lbs\",\"Year\"]",
6-
"filters": "[]",
7-
"row-pivots": "[]",
3+
"aggregates": {
4+
"Acceleration": "sum",
5+
"Cylinders": "sum",
6+
"Displacement": "sum",
7+
"Horsepower": "sum",
8+
"Miles_per_Gallon": "sum",
9+
"Name": "count",
10+
"Origin": "count",
11+
"Weight_in_lbs": "sum",
12+
"Year": "count"
13+
},
14+
"column-pivots": [],
15+
"columns": [
16+
"Acceleration",
17+
"Cylinders",
18+
"Displacement",
19+
"Horsepower",
20+
"Miles_per_Gallon",
21+
"Name",
22+
"Origin",
23+
"Weight_in_lbs",
24+
"Year"
25+
],
26+
"filters": [],
27+
"plugin": "hypergrid",
28+
"row-pivots": [],
829
"settings": "true",
9-
"sort": "[[\"Horsepower\",\"desc\"]]",
30+
"sort": [
31+
[
32+
"Horsepower",
33+
"desc"
34+
]
35+
],
1036
"view": "hypergrid"
1137
},
1238
"dataFileName": "cars.json",

templates/data.view.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@
565565
const data = {
566566
dataFileName: dataFileName,
567567
dataTable: dataTable,
568-
config: viewConfig
568+
config: parseConfig(viewConfig)
569569
};
570570
if (dataUrl.startsWith('http')) {
571571
// append remote data url
@@ -597,6 +597,29 @@
597597
}
598598
} // end of saveData()
599599

600+
/**
601+
* Parses data view config by converting config string properties
602+
* to arrays and objects for the data viewer web component attributes.
603+
* @param viewConfig View config object to parse.
604+
*/
605+
function parseConfig(viewConfig) {
606+
// set new view config plugin attribute
607+
viewConfig['plugin'] = viewConfig['view'];
608+
// create clean view config instance
609+
const config = {};
610+
Object.keys(viewConfig).forEach(key => {
611+
config[key] = viewConfig[key];
612+
if (typeof viewConfig[key] === 'string') {
613+
const attribute = String(viewConfig[key]);
614+
if (attribute.startsWith('{') || attribute.startsWith('[')) {
615+
// parse config object or array
616+
config[key] = JSON.parse(attribute);
617+
}
618+
}
619+
});
620+
return config;
621+
}
622+
600623
/**
601624
* Posts binary Arrow data for saving.
602625
* @param arrayBuffer Arrow data ArrayBuffer to save.

0 commit comments

Comments
 (0)