Skip to content

Commit a4f12e9

Browse files
committed
api loading logic change
1 parent d052a08 commit a4f12e9

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

components/controls/VueLoadControl.vue

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,54 @@
77
type="string"
88
:readonly="readonly"
99
:placeholder="placeholder"
10-
:value="value"
11-
@input="change($event)"
10+
@input="update($event)"
1211
@dblclick.stop=""
1312
@pointerdown.stop=""
1413
@pointermove.stop=""/>
1514
</div>
1615
</div>
1716
</template>
1817
<script>
18+
import { csvParse, text } from 'd3';
19+
1920
export default {
2021
props: ['placeholder', 'readonly', 'emitter', 'ikey', 'node', 'getData', 'putData'],
2122
data() {
2223
return {
23-
value: '',
2424
loading: false
2525
}
2626
},
2727
methods: {
28-
change(e){
29-
this.value = e.target.value;
30-
this.update();
31-
},
32-
update() {
33-
this.loading = true;
34-
this.putData(this.ikey, this.value);
35-
this.emitter.nodeId = this.node.id;
36-
this.emitter.trigger('process');
28+
update(e) {
29+
let url = e.target.value;
30+
if(!(url.endsWith('.csv') || url.endsWith('.json') || url.endsWith('.geojson'))) return;
31+
32+
this.loading = true;
33+
34+
url = url.startsWith('https') ? url : 'https://' + url;
35+
text(url).then(async result=>{
36+
const data = url.endsWith('.csv') ? await csvParse(result) : JSON.parse(result);
37+
38+
node.data.name = url.split('/').pop();
39+
node.data.data = data;
40+
41+
this.emitter.nodeId = this.node.id;
42+
this.emitter.trigger('process');
43+
}).catch(e=>{
44+
this.loading = false;
45+
});
46+
47+
// const result = await text(url);
48+
// const data = url.endsWith('.csv') ? await csvParse(result) : JSON.parse(result);
49+
50+
// node.data.name = url.split('/').pop();
51+
// node.data.data = data;
52+
53+
// console.log(node.data.name, node.data.data);
54+
55+
// this.emitter.nodeId = this.node.id;
56+
// this.emitter.trigger('process');
3757
}
38-
},
39-
mounted() {
40-
this.value = this.getData(this.ikey);
4158
}
4259
}
4360
</script>

language/components.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class ColorComponent extends Rete.Component {
9191
data: inputs.values[0].map(d=> isNaN(d) ? colors[d] : color(d) ),
9292
value: null
9393
}
94-
console.log(outputs.colors.data);
9594
}
9695
}
9796
class ParseComponent extends Rete.Component {
@@ -158,16 +157,6 @@ class DatasetComponent extends Rete.Component {
158157
data: node.data.data
159158
};
160159
}
161-
if(node.data.url){
162-
let url = node.data.url;
163-
if(!(url.endsWith('.csv') || url.endsWith('.json') || url.endsWith('.geojson'))) return;
164-
url = url.startsWith('https') ? url : 'https://' + url;
165-
const result = await d3.text(url);
166-
const data = url.endsWith('.csv') ? await d3.csvParse(result) : JSON.parse(result);
167-
const name = url.split('/').pop();
168-
169-
data = { name, data };
170-
}
171160
if(data){
172161
if(data.data.type == 'FeatureCollection'){
173162
(d3.nest()
@@ -686,7 +675,6 @@ class ScatterComponent extends Rete.Component {
686675
.addInput(new Rete.Input('size','Size', dataSocket));
687676
}
688677
worker(node, inputs, outputs){
689-
console.log(inputs.colors)
690678
if( inputs.x.length && inputs.y.length ){
691679
node.data.DATA = inputs.x[0].map((x, i)=> ({
692680
x: inputs.x[0][i],
@@ -695,7 +683,6 @@ class ScatterComponent extends Rete.Component {
695683
...(inputs.size.length ? {size: +inputs.size[0][i]} : {}),
696684
}));
697685
}
698-
699686
this.editor.nodes.find(n=>n.id===node.id).update();
700687
}
701688
}

0 commit comments

Comments
 (0)