|
57 | 57 | <option value=".csv">csv</option> |
58 | 58 | </select> |
59 | 59 | </div> |
60 | | - <div>🈸 <a id="title" title="load data view config" href="#" onclick="loadConfig()"></a></div> |
| 60 | + <div>🈸 <a id="title" title="Load data view config" href="#" onclick="loadConfig()"></a></div> |
61 | 61 | </div> |
62 | 62 | <perspective-viewer id="data-viewer" view="grid"></perspective-viewer> |
63 | 63 | <script type="text/javascript"> |
64 | 64 | // data preview vars |
65 | | - let vscode, title, fileTypeSelector, dataUri, viewer, viewConfig = {}, viewData = []; |
| 65 | + let vscode, title, fileTypeSelector, dataUri, viewer, toggleConfig = true, viewConfig = {}, viewData = []; |
66 | 66 |
|
67 | 67 | // check web assembly support. uncomment this for dev debug: |
68 | 68 | // console.log(`data.preview:supportsWebAssembly(): ${supportsWebAssembly()}`); |
|
117 | 117 | try { |
118 | 118 | // set preview state for restore on vscode reload |
119 | 119 | dataUri = data.uri; |
120 | | - viewConfig = data.config; |
121 | | - vscode.setState({uri: dataUri, config: viewConfig}); |
122 | 120 | title.innerText = data.fileName; |
| 121 | + // check view config |
| 122 | + if (JSON.stringify(viewConfig) != JSON.stringify(data.config)) { |
| 123 | + viewConfig = data.config; |
| 124 | + vscode.setState({uri: dataUri, config: viewConfig}); |
| 125 | + // update view config |
| 126 | + viewer.restore(viewConfig); |
| 127 | + // reset view data for new view load |
| 128 | + viewData = []; |
| 129 | + } |
123 | 130 |
|
124 | 131 | // load file data |
125 | 132 | const tableData = getData(data.fileName, data.data, data.schema); |
126 | | - // update view config |
127 | | - viewer.restore(viewConfig); |
128 | 133 | if (Array.isArray(viewData) && viewData.length === 0) { |
129 | 134 | // initialize perspective viewer |
130 | 135 | console.log(`data.view:refresh(): initializing view data for: ${data.fileName}`); |
|
136 | 141 | else { |
137 | 142 | viewer.load(tableData); |
138 | 143 | } |
139 | | - viewer.toggleConfig(); |
| 144 | + if (toggleConfig) { |
| 145 | + // show viewer toggles on the 1st run |
| 146 | + viewer.toggleConfig(); |
| 147 | + toggleConfig = false; |
| 148 | + } |
140 | 149 | } else { // update viewer data without toggles reset |
141 | 150 | console.log(`data.view:refresh(): updating view data for: ${data.fileName}`); |
142 | 151 | viewer.clear(); |
|
209 | 218 | switch (dataFileType) { |
210 | 219 | case '.config': |
211 | 220 | const data = { |
212 | | - fileName: dataUri.substr(dataUri.lastIndexOf('/') + 1), |
| 221 | + dataFileName: dataUri.substr(dataUri.lastIndexOf('/') + 1), |
213 | 222 | config: viewConfig |
214 | 223 | }; |
215 | 224 | postData(dataFileType, data); |
|
0 commit comments