@abi-software/map-utilities 1.1.3-beta.4 → 1.2.0-beta.1
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 +6890 -23425
- package/dist/map-utilities.umd.cjs +41 -61
- package/dist/style.css +1 -1
- package/package.json +1 -2
- package/src/App.vue +0 -34
- package/src/components/TreeControls/TreeControls.vue +38 -1
- package/src/components/index.js +1 -9
- package/src/components.d.ts +0 -4
- package/src/components/ConnectivityGraph/ConnectivityGraph.vue +0 -451
- package/src/components/ConnectivityGraph/graph.js +0 -264
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
/*==============================================================================
|
|
2
|
-
|
|
3
|
-
A viewer for neuron connectivity graphs.
|
|
4
|
-
|
|
5
|
-
Copyright (c) 2019 - 2024 David Brooks
|
|
6
|
-
|
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
you may not use this file except in compliance with the License.
|
|
9
|
-
You may obtain a copy of the License at
|
|
10
|
-
|
|
11
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
|
|
13
|
-
Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
See the License for the specific language governing permissions and
|
|
17
|
-
limitations under the License.
|
|
18
|
-
|
|
19
|
-
==============================================================================*/
|
|
20
|
-
|
|
21
|
-
import cytoscape from 'cytoscape'
|
|
22
|
-
|
|
23
|
-
//==============================================================================
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//==============================================================================
|
|
27
|
-
|
|
28
|
-
export class ConnectivityGraph
|
|
29
|
-
{
|
|
30
|
-
cyg = null
|
|
31
|
-
nodes = []
|
|
32
|
-
edges = []
|
|
33
|
-
axons = []
|
|
34
|
-
dendrites = []
|
|
35
|
-
labelCache = new Map()
|
|
36
|
-
graphCanvas = null
|
|
37
|
-
|
|
38
|
-
constructor(labelCache, graphCanvas)
|
|
39
|
-
{
|
|
40
|
-
this.labelCache = labelCache;
|
|
41
|
-
this.graphCanvas = graphCanvas;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async addConnectivity(knowledge)
|
|
45
|
-
//=====================================================
|
|
46
|
-
{
|
|
47
|
-
this.axons = knowledge.axons.map(node => JSON.stringify(node))
|
|
48
|
-
this.dendrites = knowledge.dendrites.map(node => JSON.stringify(node))
|
|
49
|
-
if (knowledge.connectivity.length) {
|
|
50
|
-
for (const edge of knowledge.connectivity) {
|
|
51
|
-
const e0 = await this.graphNode(edge[0])
|
|
52
|
-
const e1 = await this.graphNode(edge[1])
|
|
53
|
-
this.nodes.push(e0)
|
|
54
|
-
this.nodes.push(e1)
|
|
55
|
-
this.edges.push({
|
|
56
|
-
id: `${e0.id}_${e1.id}`,
|
|
57
|
-
source: e0.id,
|
|
58
|
-
target: e1.id
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
this.nodes.push({
|
|
63
|
-
id: 'MISSING',
|
|
64
|
-
label: 'NO PATHS'
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
showConnectivity(graphCanvas)
|
|
70
|
-
//================
|
|
71
|
-
{
|
|
72
|
-
this.cyg = new CytoscapeGraph(this, graphCanvas)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
clearConnectivity()
|
|
76
|
-
//=================
|
|
77
|
-
{
|
|
78
|
-
if (this.cyg?.cy) {
|
|
79
|
-
this.cyg.cy.remove()
|
|
80
|
-
this.cyg.cy = null
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
reset()
|
|
85
|
-
//=================
|
|
86
|
-
{
|
|
87
|
-
if (this.cyg?.cy) {
|
|
88
|
-
this.cyg.cy.reset()
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
enableZoom(option)
|
|
93
|
-
//=================
|
|
94
|
-
{
|
|
95
|
-
if (this.cyg?.cy) {
|
|
96
|
-
this.cyg.cy.userZoomingEnabled(option)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
get elements()
|
|
101
|
-
//============
|
|
102
|
-
{
|
|
103
|
-
return [
|
|
104
|
-
...this.nodes.map(n => { return {data: n}}),
|
|
105
|
-
...this.edges.map(e => { return {data: e}})
|
|
106
|
-
]
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
get roots()
|
|
110
|
-
//===================
|
|
111
|
-
{
|
|
112
|
-
return this.dendrites
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async graphNode(node)
|
|
116
|
-
//=======================================================
|
|
117
|
-
{
|
|
118
|
-
const id = JSON.stringify(node)
|
|
119
|
-
const label = [node[0], ...node[1]]
|
|
120
|
-
const humanLabels = []
|
|
121
|
-
for (const term of label) {
|
|
122
|
-
const humanLabel = this.labelCache.has(term) ? this.labelCache.get(term) : ''
|
|
123
|
-
humanLabels.push(humanLabel)
|
|
124
|
-
}
|
|
125
|
-
label.push(...humanLabels)
|
|
126
|
-
|
|
127
|
-
const result = {
|
|
128
|
-
id,
|
|
129
|
-
label: label.join('\n')
|
|
130
|
-
}
|
|
131
|
-
if (this.axons.includes(id)) {
|
|
132
|
-
if (this.dendrites.includes(id)) {
|
|
133
|
-
result['both-a-d'] = true
|
|
134
|
-
} else {
|
|
135
|
-
result['axon'] = true
|
|
136
|
-
}
|
|
137
|
-
} else if (this.dendrites.includes(id)) {
|
|
138
|
-
result['dendrite'] = true
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
return result
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
//==============================================================================
|
|
146
|
-
|
|
147
|
-
const GRAPH_STYLE = [
|
|
148
|
-
{
|
|
149
|
-
'selector': 'node',
|
|
150
|
-
'style': {
|
|
151
|
-
'label': 'data(label)',
|
|
152
|
-
'background-color': '#80F0F0',
|
|
153
|
-
'text-valign': 'center',
|
|
154
|
-
'text-wrap': 'wrap',
|
|
155
|
-
'text-max-width': '80px',
|
|
156
|
-
'font-size': '6px'
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
'selector': 'node[axon]',
|
|
161
|
-
'style': {
|
|
162
|
-
'background-color': 'green'
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
'selector': 'node[dendrite]',
|
|
167
|
-
'style': {
|
|
168
|
-
'background-color': 'red'
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
'selector': 'node[both-a-d]',
|
|
173
|
-
'style': {
|
|
174
|
-
'background-color': 'gray'
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
'selector': 'edge',
|
|
179
|
-
'style': {
|
|
180
|
-
'width': 2,
|
|
181
|
-
'line-color': '#9dbaea',
|
|
182
|
-
'target-arrow-color': '#9dbaea',
|
|
183
|
-
'target-arrow-shape': 'triangle',
|
|
184
|
-
'curve-style': 'bezier'
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
]
|
|
188
|
-
|
|
189
|
-
//==============================================================================
|
|
190
|
-
|
|
191
|
-
class CytoscapeGraph
|
|
192
|
-
{
|
|
193
|
-
cy
|
|
194
|
-
tooltip
|
|
195
|
-
|
|
196
|
-
constructor(connectivityGraph, graphCanvas)
|
|
197
|
-
{
|
|
198
|
-
this.cy = cytoscape({
|
|
199
|
-
container: graphCanvas,
|
|
200
|
-
elements: connectivityGraph.elements,
|
|
201
|
-
layout: {
|
|
202
|
-
name: 'breadthfirst',
|
|
203
|
-
circle: false,
|
|
204
|
-
roots: connectivityGraph.roots
|
|
205
|
-
},
|
|
206
|
-
directed: true,
|
|
207
|
-
style: GRAPH_STYLE,
|
|
208
|
-
minZoom: 0.5,
|
|
209
|
-
maxZoom: 10,
|
|
210
|
-
wheelSensitivity: 0.4,
|
|
211
|
-
}).on('mouseover', 'node', this.overNode.bind(this))
|
|
212
|
-
.on('mouseout', 'node', this.exitNode.bind(this))
|
|
213
|
-
.on('position', 'node', this.moveNode.bind(this))
|
|
214
|
-
|
|
215
|
-
this.tooltip = document.createElement('div')
|
|
216
|
-
this.tooltip.className = 'cy-graph-tooltip'
|
|
217
|
-
this.tooltip.hidden = true
|
|
218
|
-
graphCanvas?.lastChild?.appendChild(this.tooltip)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
remove()
|
|
222
|
-
//======
|
|
223
|
-
{
|
|
224
|
-
if (this.cy) {
|
|
225
|
-
this.cy.destroy()
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
checkRightBoundary(leftPos)
|
|
230
|
-
//==================================
|
|
231
|
-
{
|
|
232
|
-
if ((leftPos + this.tooltip.offsetWidth) >= this.tooltip.parentElement?.offsetWidth) {
|
|
233
|
-
this.tooltip.style.left = `${leftPos - this.tooltip.offsetWidth}px`
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
overNode(event)
|
|
238
|
-
//==============
|
|
239
|
-
{
|
|
240
|
-
const node = event.target
|
|
241
|
-
this.tooltip.innerText = node.data().label
|
|
242
|
-
this.tooltip.style.left = `${event.renderedPosition.x}px`
|
|
243
|
-
this.tooltip.style.top = `${event.renderedPosition.y}px`
|
|
244
|
-
this.tooltip.hidden = false
|
|
245
|
-
this.checkRightBoundary(event.renderedPosition.x)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
moveNode(event)
|
|
249
|
-
//==============
|
|
250
|
-
{
|
|
251
|
-
const node = event.target
|
|
252
|
-
this.tooltip.style.left = `${node.renderedPosition().x}px`
|
|
253
|
-
this.tooltip.style.top = `${node.renderedPosition().y}px`
|
|
254
|
-
this.checkRightBoundary(node.renderedPosition().x)
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
exitNode(event)
|
|
258
|
-
//==============
|
|
259
|
-
{
|
|
260
|
-
this.tooltip.hidden = true
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
//==============================================================================
|