@abi-software/map-utilities 1.2.0 → 1.2.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/map-utilities.js +3917 -3852
- package/dist/map-utilities.umd.cjs +55 -54
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/ConnectivityGraph/ConnectivityGraph.vue +48 -6
- package/src/components/ConnectivityGraph/graph.js +83 -4
- package/src/components/utilities.js +9 -0
package/package.json
CHANGED
|
@@ -106,7 +106,8 @@
|
|
|
106
106
|
</div>
|
|
107
107
|
</div>
|
|
108
108
|
|
|
109
|
-
<div class="connectivity-graph-error" v-if="errorMessage">
|
|
109
|
+
<div class="connectivity-graph-error" v-if="errorMessage || errorConnectivities">
|
|
110
|
+
<strong v-if="errorConnectivities">{{ errorConnectivities }}</strong>
|
|
110
111
|
{{ errorMessage }}
|
|
111
112
|
</div>
|
|
112
113
|
|
|
@@ -115,6 +116,7 @@
|
|
|
115
116
|
|
|
116
117
|
<script>
|
|
117
118
|
import { ConnectivityGraph } from './graph';
|
|
119
|
+
import { capitalise } from '../utilities';
|
|
118
120
|
|
|
119
121
|
const MIN_SCHEMA_VERSION = 1.3;
|
|
120
122
|
const CACHE_LIFETIME = 24 * 60 * 60 * 1000; // One day
|
|
@@ -125,6 +127,7 @@ const ZOOM_IN_LABEL = 'Zoom in';
|
|
|
125
127
|
const ZOOM_OUT_LABEL = 'Zoom out';
|
|
126
128
|
const ZOOM_INCREMENT = 0.25;
|
|
127
129
|
const APP_PRIMARY_COLOR = '#8300bf';
|
|
130
|
+
const ERROR_TIMEOUT = 3000; // 3 seconds
|
|
128
131
|
|
|
129
132
|
export default {
|
|
130
133
|
name: 'ConnectivityGraph',
|
|
@@ -140,6 +143,10 @@ export default {
|
|
|
140
143
|
type: String,
|
|
141
144
|
default: '',
|
|
142
145
|
},
|
|
146
|
+
selectedConnectivityData: {
|
|
147
|
+
type: Array,
|
|
148
|
+
default: [],
|
|
149
|
+
},
|
|
143
150
|
},
|
|
144
151
|
data: function () {
|
|
145
152
|
return {
|
|
@@ -158,6 +165,7 @@ export default {
|
|
|
158
165
|
iconColor: APP_PRIMARY_COLOR,
|
|
159
166
|
zoomEnabled: false,
|
|
160
167
|
errorMessage: '',
|
|
168
|
+
errorConnectivities: '',
|
|
161
169
|
};
|
|
162
170
|
},
|
|
163
171
|
mounted() {
|
|
@@ -245,13 +253,17 @@ export default {
|
|
|
245
253
|
|
|
246
254
|
this.connectivityGraph.showConnectivity(graphCanvas);
|
|
247
255
|
|
|
256
|
+
// saved state from list view
|
|
257
|
+
if (this.selectedConnectivityData.length) {
|
|
258
|
+
this.connectivityGraph.selectConnectivity(this.selectedConnectivityData);
|
|
259
|
+
}
|
|
260
|
+
|
|
248
261
|
this.connectivityGraph.on('tap-node', (event) => {
|
|
249
|
-
const
|
|
250
|
-
const labels = label ? label.split(`\n`) : [];
|
|
262
|
+
const data = event.detail;
|
|
251
263
|
/**
|
|
252
264
|
* This event is triggered after a node on the connectivity graph is clicked.
|
|
253
265
|
*/
|
|
254
|
-
this.$emit('tap-node',
|
|
266
|
+
this.$emit('tap-node', data);
|
|
255
267
|
});
|
|
256
268
|
},
|
|
257
269
|
query: async function (sql, params) {
|
|
@@ -414,12 +426,41 @@ export default {
|
|
|
414
426
|
this.zoomLockLabel = this.zoomEnabled ? ZOOM_UNLOCK_LABEL : ZOOM_LOCK_LABEL;
|
|
415
427
|
this.connectivityGraph.enableZoom(!this.zoomEnabled);
|
|
416
428
|
},
|
|
417
|
-
|
|
429
|
+
getErrorConnectivities: function (errorData) {
|
|
430
|
+
const errorDataToEmit = [...new Set(errorData)];
|
|
431
|
+
let errorConnectivities = '';
|
|
432
|
+
|
|
433
|
+
errorDataToEmit.forEach((connectivity, i) => {
|
|
434
|
+
const { label } = connectivity;
|
|
435
|
+
errorConnectivities += (i === 0) ? capitalise(label) : label;
|
|
436
|
+
|
|
437
|
+
if (errorDataToEmit.length > 1) {
|
|
438
|
+
if ((i + 2) === errorDataToEmit.length) {
|
|
439
|
+
errorConnectivities += ' and ';
|
|
440
|
+
} else if ((i + 1) < errorDataToEmit.length) {
|
|
441
|
+
errorConnectivities += ', ';
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
return errorConnectivities;
|
|
447
|
+
},
|
|
448
|
+
/**
|
|
449
|
+
* Function to show error message.
|
|
450
|
+
* `errorInfo` includes `errorData` array (optional) for error connectivities
|
|
451
|
+
* and `errorMessage` for error message.
|
|
452
|
+
* @arg `errorInfo`
|
|
453
|
+
*/
|
|
454
|
+
showErrorMessage: function (errorInfo) {
|
|
455
|
+
const { errorData, errorMessage } = errorInfo;
|
|
456
|
+
this.errorConnectivities = this.getErrorConnectivities(errorData);
|
|
418
457
|
this.errorMessage = errorMessage;
|
|
458
|
+
|
|
419
459
|
// Show error for 3 seconds
|
|
420
460
|
setTimeout(() => {
|
|
461
|
+
this.errorConnectivities = '';
|
|
421
462
|
this.errorMessage = '';
|
|
422
|
-
},
|
|
463
|
+
}, ERROR_TIMEOUT);
|
|
423
464
|
},
|
|
424
465
|
},
|
|
425
466
|
};
|
|
@@ -584,6 +625,7 @@ export default {
|
|
|
584
625
|
background: #f3ecf6 !important;
|
|
585
626
|
border: 1px solid $app-primary-color;
|
|
586
627
|
border-radius: var(--el-border-radius-base);
|
|
628
|
+
box-shadow: 1px 1px 6px 1px rgba($app-primary-color, 0.15);
|
|
587
629
|
position: relative;
|
|
588
630
|
top: 0;
|
|
589
631
|
left: 0;
|
|
@@ -84,6 +84,25 @@ export class ConnectivityGraph extends EventTarget
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
selectConnectivity(selectedConnectivityData)
|
|
88
|
+
{
|
|
89
|
+
if (this.cyg?.cy) {
|
|
90
|
+
let eleId = ''
|
|
91
|
+
this.cyg.cy.elements().forEach((ele) => {
|
|
92
|
+
const label = ele.data('label')
|
|
93
|
+
const connectivityData = getConnectivityData(label)
|
|
94
|
+
|
|
95
|
+
if (areArraysIdentical(selectedConnectivityData, connectivityData)) {
|
|
96
|
+
eleId = ele.id()
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
if (eleId) {
|
|
101
|
+
this.cyg.cy.$id(eleId).select()
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
87
106
|
clearConnectivity()
|
|
88
107
|
//=================
|
|
89
108
|
{
|
|
@@ -183,6 +202,8 @@ export class ConnectivityGraph extends EventTarget
|
|
|
183
202
|
|
|
184
203
|
//==============================================================================
|
|
185
204
|
|
|
205
|
+
const APP_PRIMARY_COLOR = '#8300bf'
|
|
206
|
+
const BG_COLOR = '#f3ecf6'
|
|
186
207
|
const GRAPH_STYLE = [
|
|
187
208
|
{
|
|
188
209
|
'selector': 'node',
|
|
@@ -235,6 +256,21 @@ const GRAPH_STYLE = [
|
|
|
235
256
|
'target-arrow-shape': 'triangle',
|
|
236
257
|
'curve-style': 'bezier'
|
|
237
258
|
}
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
'selector': 'node:active',
|
|
262
|
+
'style': {
|
|
263
|
+
'border-color': APP_PRIMARY_COLOR,
|
|
264
|
+
'border-width': 2
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
'selector': 'node:selected',
|
|
269
|
+
'style': {
|
|
270
|
+
'border-color': APP_PRIMARY_COLOR,
|
|
271
|
+
'background-color': BG_COLOR,
|
|
272
|
+
'background-opacity': 0.75,
|
|
273
|
+
}
|
|
238
274
|
}
|
|
239
275
|
]
|
|
240
276
|
|
|
@@ -242,7 +278,7 @@ function trimLabel(label) {
|
|
|
242
278
|
const labels = label.split('\n')
|
|
243
279
|
const half = labels.length/2
|
|
244
280
|
const trimLabels = labels.slice(half)
|
|
245
|
-
return trimLabels.join('\n')
|
|
281
|
+
return capitalizeLabels(trimLabels.join('\n'))
|
|
246
282
|
}
|
|
247
283
|
|
|
248
284
|
function capitalizeLabels(input) {
|
|
@@ -254,6 +290,40 @@ function capitalizeLabels(input) {
|
|
|
254
290
|
}).join('\n')
|
|
255
291
|
}
|
|
256
292
|
|
|
293
|
+
function getConnectivityData(label) {
|
|
294
|
+
const labels = label ? label.split(`\n`) : []
|
|
295
|
+
const connectivityData = []
|
|
296
|
+
|
|
297
|
+
for (let i = 0; i < labels.length / 2; i++) {
|
|
298
|
+
connectivityData.push({
|
|
299
|
+
id: labels[i],
|
|
300
|
+
label: labels[i + labels.length / 2]
|
|
301
|
+
})
|
|
302
|
+
}
|
|
303
|
+
return connectivityData
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function areArraysIdentical(arr1, arr2) {
|
|
307
|
+
arr1.sort((a, b) => {
|
|
308
|
+
if (a.id < b.id) return -1
|
|
309
|
+
if (a.id > b.id) return 1
|
|
310
|
+
return 0
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
arr2.sort((a, b) => {
|
|
314
|
+
if (a.id < b.id) return -1
|
|
315
|
+
if (a.id > b.id) return 1
|
|
316
|
+
return 0
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
320
|
+
if (JSON.stringify(arr1[i]) !== JSON.stringify(arr2[i])) {
|
|
321
|
+
return false
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return true
|
|
326
|
+
}
|
|
257
327
|
//==============================================================================
|
|
258
328
|
|
|
259
329
|
class CytoscapeGraph extends EventTarget
|
|
@@ -308,12 +378,18 @@ class CytoscapeGraph extends EventTarget
|
|
|
308
378
|
//==============
|
|
309
379
|
{
|
|
310
380
|
const node = event.target
|
|
311
|
-
const
|
|
381
|
+
const data = node.data()
|
|
382
|
+
const { label } = data
|
|
383
|
+
const connectivityData = getConnectivityData(label)
|
|
384
|
+
const labels = connectivityData.map((data) => (
|
|
385
|
+
data.label + ' (' + data.id + ')'
|
|
386
|
+
))
|
|
312
387
|
|
|
313
|
-
this.tooltip.innerText =
|
|
388
|
+
this.tooltip.innerText = capitalizeLabels(labels.join('\n'))
|
|
314
389
|
this.tooltip.style.left = `${event.renderedPosition.x}px`
|
|
315
390
|
this.tooltip.style.top = `${event.renderedPosition.y}px`
|
|
316
391
|
this.tooltip.style.maxWidth = '240px'
|
|
392
|
+
this.tooltip.style.zIndex = 2
|
|
317
393
|
this.tooltip.hidden = false
|
|
318
394
|
|
|
319
395
|
this.checkRightBoundary(event.renderedPosition.x)
|
|
@@ -339,8 +415,11 @@ class CytoscapeGraph extends EventTarget
|
|
|
339
415
|
{
|
|
340
416
|
const node = event.target
|
|
341
417
|
const data = node.data()
|
|
418
|
+
const { label } = data
|
|
419
|
+
const connectivityData = getConnectivityData(label)
|
|
420
|
+
|
|
342
421
|
const tapEvent = new CustomEvent('tap-node', {
|
|
343
|
-
detail:
|
|
422
|
+
detail: connectivityData
|
|
344
423
|
})
|
|
345
424
|
this.dispatchEvent(tapEvent);
|
|
346
425
|
}
|