@abi-software/map-utilities 1.1.3-beta.0 → 1.2.0-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/map-utilities",
3
- "version": "1.1.3-beta.0",
3
+ "version": "1.2.0-beta.0",
4
4
  "files": [
5
5
  "dist/*",
6
6
  "src/*",
@@ -31,7 +31,6 @@
31
31
  "dependencies": {
32
32
  "@abi-software/svg-sprite": "^1.0.1",
33
33
  "@element-plus/icons-vue": "^2.3.1",
34
- "cytoscape": "^3.30.2",
35
34
  "element-plus": "2.8.4",
36
35
  "mitt": "^3.0.1",
37
36
  "vue": "^3.4.21"
package/src/App.vue CHANGED
@@ -26,6 +26,7 @@ const hoverVisibilities = [
26
26
  { value: false, refs: "toolbarPopover", ref: "polygonPopover" },
27
27
  { value: false, refs: "toolbarPopover", ref: "connectionPopover" },
28
28
  ];
29
+ const filterText = ref("")
29
30
  const isFlatmap = ref(true);
30
31
  const appRef = ref(null);
31
32
  const newlyDrawnEntry = ref({});
@@ -467,6 +468,11 @@ function changeHover(value) {
467
468
  @annotation="commitAnnotationEvent"
468
469
  @onActionClick="onActionClick"
469
470
  />
471
+ <el-input
472
+ v-model="filterText"
473
+ style="width: 240px"
474
+ placeholder="Filter keyword"
475
+ />
470
476
  <TreeControls
471
477
  v-show="mapType === 'flatmap'"
472
478
  mapType="flatmap"
@@ -478,6 +484,7 @@ function changeHover(value) {
478
484
  @checkChanged="checkChanged"
479
485
  @changeActive="changeActive"
480
486
  @changeHover="changeHover"
487
+ :filterText="filterText"
481
488
  />
482
489
  <TreeControls
483
490
  v-show="mapType === 'scaffold'"
@@ -490,6 +497,7 @@ function changeHover(value) {
490
497
  :showColourPicker="true"
491
498
  @setColour="setColour"
492
499
  @checkChanged="checkChanged"
500
+ :filterText="filterText"
493
501
  />
494
502
  </div>
495
503
  </template>
@@ -11,7 +11,7 @@
11
11
  <div :class="['tree-tooltip', tooltipAtBottom ? 'bottom' : '']" >
12
12
  <el-popover
13
13
  ref="tooltip"
14
- :visible="tooltipVisible"
14
+ :visible="tooltipVisible && tooltipLabel !== ''"
15
15
  placement="top"
16
16
  :show-arrow="false"
17
17
  :teleported="false"
@@ -38,6 +38,7 @@
38
38
  :default-expanded-keys="expandedKeys"
39
39
  @check="checkChanged"
40
40
  :indent="8"
41
+ :filter-node-method="filterNode"
41
42
  :class="[mapType === 'flatmap' ? 'hide_grandchildren_checkbox': '']"
42
43
  >
43
44
  <template #default="{ node, data }">
@@ -94,6 +95,10 @@
94
95
  export default {
95
96
  name: "TreeControls",
96
97
  props: {
98
+ filterText: {
99
+ type: String,
100
+ default: "",
101
+ },
97
102
  /**
98
103
  * The type of map that the TreeControls is used. Either "flatmap" or "scaffold".
99
104
  */
@@ -178,8 +183,17 @@ export default {
178
183
  else this.myPopperClass = "hide-scaffold-colour-popup";
179
184
  },
180
185
  },
186
+ filterText: {
187
+ handler: function (value) {
188
+ if (this.$refs.regionTree) this.$refs.regionTree.filter(value);
189
+ },
190
+ },
181
191
  },
182
192
  methods: {
193
+ filterNode: function(value, data) {
194
+ if (!value) return true;
195
+ return data.label ? data.label.toLowerCase().includes(value) : false;
196
+ },
183
197
  setColour: function (nodeData, value) {
184
198
  this.$emit("setColour", nodeData, value);
185
199
  },
@@ -250,6 +264,9 @@ export default {
250
264
  unmounted: function () {
251
265
  this.sortedPrimitiveGroups = undefined;
252
266
  },
267
+ mounted: function() {
268
+ if (this.$refs.regionTree) this.$refs.regionTree.filter(this.filterText);
269
+ }
253
270
  };
254
271
  </script>
255
272
 
@@ -3,13 +3,5 @@ import HelpModeDialog from "./HelpModeDialog/HelpModeDialog.vue";
3
3
  import Tooltip from "./Tooltip/Tooltip.vue";
4
4
  import TreeControls from "./TreeControls/TreeControls.vue";
5
5
  import CopyToClipboard from "./CopyToClipboard/CopyToClipboard.vue";
6
- import ConnectivityGraph from "./ConnectivityGraph/ConnectivityGraph.vue";
7
6
 
8
- export {
9
- DrawToolbar,
10
- HelpModeDialog,
11
- Tooltip,
12
- TreeControls,
13
- CopyToClipboard,
14
- ConnectivityGraph,
15
- };
7
+ export { DrawToolbar, HelpModeDialog, Tooltip, TreeControls, CopyToClipboard };
@@ -9,7 +9,6 @@ declare module 'vue' {
9
9
  export interface GlobalComponents {
10
10
  AnnotationPopup: typeof import('./components/Tooltip/AnnotationPopup.vue')['default']
11
11
  ConnectionDialog: typeof import('./components/DrawToolbar/ConnectionDialog.vue')['default']
12
- ConnectivityGraph: typeof import('./components/ConnectivityGraph/ConnectivityGraph.vue')['default']
13
12
  CopyToClipboard: typeof import('./components/CopyToClipboard/CopyToClipboard.vue')['default']
14
13
  DrawToolbar: typeof import('./components/DrawToolbar/DrawToolbar.vue')['default']
15
14
  ElButton: typeof import('element-plus/es')['ElButton']
@@ -1,231 +0,0 @@
1
- <template>
2
- <div class="connectivity-graph">
3
- <div ref="graphCanvas" class="graph-canvas"></div>
4
- <div class="node-key">
5
- <div class="key-head">Node type:</div>
6
- <div>
7
- <div><span>Node:</span><span class="key-box" style="background: #80F0F0"/></div>
8
- <div><span>Axon:</span><span class="key-box" style="background: green"/></div>
9
- <div><span>Dendrite:</span><span class="key-box" style="background: red"/></div>
10
- <div><span>Both:</span><span class="key-box" style="background: gray"/></div>
11
- </div>
12
- </div>
13
- </div>
14
- </template>
15
-
16
- <script>
17
- import { ConnectivityGraph } from './graph';
18
-
19
- const MIN_SCHEMA_VERSION = 1.3;
20
-
21
- export default {
22
- name: 'ConnectivityGraph',
23
- props: {
24
- /**
25
- * Entity to load its connectivity graph.
26
- */
27
- entry: {
28
- type: String,
29
- default: '',
30
- },
31
- mapServer: {
32
- type: String,
33
- default: '',
34
- },
35
- },
36
- data: function () {
37
- return {
38
- cy: null,
39
- connectivityGraph: null,
40
- knowledgeByPath: new Map(),
41
- labelledTerms: new Set(),
42
- labelCache: new Map(),
43
- };
44
- },
45
- mounted() {
46
- this.run().then((res) => {
47
- this.showGraph(this.entry);
48
- });
49
- },
50
- methods: {
51
- run: async function () {
52
- const schemaVersion = await this.getSchemaVersion();
53
- if (schemaVersion < MIN_SCHEMA_VERSION) {
54
- console.warn('No Server!');
55
- return;
56
- }
57
- this.showSpinner();
58
- const selectedSource = await this.setSourceList();
59
- await this.setPathList(selectedSource)
60
- this.hideSpinner();
61
- },
62
- showGraph: async function (neuronPath) {
63
- const graphCanvas = this.$refs.graphCanvas;
64
- this.showSpinner();
65
- this.connectivityGraph = new ConnectivityGraph(this.labelCache, graphCanvas);
66
- await this.connectivityGraph.addConnectivity(this.knowledgeByPath.get(neuronPath));
67
- this.hideSpinner();
68
- this.connectivityGraph.showConnectivity(graphCanvas);
69
- this.currentPath = neuronPath
70
- },
71
- query: async function (sql, params) {
72
- const url = `${this.mapServer}knowledge/query/`;
73
- const query = { sql, params }
74
- try {
75
- const response = await fetch(url, {
76
- method: 'POST',
77
- headers: {
78
- "Accept": "application/json; charset=utf-8",
79
- "Cache-Control": "no-store",
80
- "Content-Type": "application/json"
81
- },
82
- body: JSON.stringify(query)
83
- });
84
- if (!response.ok) {
85
- throw new Error(`Cannot access ${url}`);
86
- }
87
- return await response.json();
88
- } catch {
89
- return {
90
- values: []
91
- };
92
- }
93
- },
94
- setSourceList: async function () {
95
- const data = await this.getJsonData(`${this.mapServer}knowledge/sources`);
96
- const sources = data ? (data.sources || []) : [];
97
-
98
- // Order with most recent first...
99
- let firstSource = '';
100
- const sourceList = [];
101
- for (const source of sources) {
102
- if (source) {
103
- sourceList.push(source);
104
- if (firstSource === '') {
105
- firstSource = source;
106
- }
107
- }
108
- }
109
- // this.#sourceSelector.innerHTML = sourceList.join('')
110
- return firstSource;
111
- },
112
- setPathList: async function (source) {
113
- const data = await this.query(
114
- `select entity, knowledge from knowledge
115
- where entity like 'ilxtr:%' and source=?
116
- order by entity`,
117
- [source]);
118
- const pathList = [];
119
- this.knowledgeByPath.clear();
120
- this.labelledTerms = new Set();
121
- for (const [key, jsonKnowledge] of data.values) {
122
- const knowledge = JSON.parse(jsonKnowledge);
123
- if ('connectivity' in knowledge) {
124
- const label = knowledge.label || key;
125
- const shortLabel = (label === key.slice(6).replace('-prime', "'").replaceAll('-', ' '))
126
- ? ''
127
- : (label.length < 50) ? label : `${label.slice(0, 50)}...`;
128
- pathList.push(key);
129
- this.knowledgeByPath.set(key, knowledge);
130
- this.cacheLabels(knowledge);
131
- }
132
- }
133
- await this.getCachedTermLabels();
134
- return '';
135
- },
136
- getSchemaVersion: async function () {
137
- const data = await this.getJsonData(`${this.mapServer}knowledge/schema-version`);
138
- return data ? (+data.version || 0) : 0;
139
- },
140
- getJsonData: async function (url) {
141
- try {
142
- const response = await fetch(url, {
143
- method: 'GET',
144
- headers: {
145
- "Accept": "application/json; charset=utf-8",
146
- "Cache-Control": "no-store",
147
- "Content-Type": "application/json"
148
- }
149
- });
150
- if (!response.ok) {
151
- console.error(`Cannot access ${url}`);
152
- }
153
- return await response.json();
154
- } catch {
155
- return null;
156
- }
157
- },
158
- getCachedTermLabels: async function () {
159
- if (this.labelledTerms.size) {
160
- const termLabels = await this.query(`
161
- select entity, label from labels
162
- where entity in (?${', ?'.repeat(this.labelledTerms.size-1)})`,
163
- [...this.labelledTerms.values()]
164
- );
165
- for (const termLabel of termLabels.values) {
166
- this.labelCache.set(termLabel[0], termLabel[1]);
167
- }
168
- }
169
- },
170
- cacheNodeLabels: function (node) {
171
- for (const term of [node[0], ...node[1]]) {
172
- this.labelledTerms.add(term);
173
- }
174
- },
175
- cacheLabels: async function (knowledge) {
176
- for (const edge of knowledge.connectivity) {
177
- this.cacheNodeLabels(edge[0]);
178
- this.cacheNodeLabels(edge[1]);
179
- }
180
- },
181
- showSpinner: function () {
182
- // show loading spinner
183
- },
184
- hideSpinner: function () {
185
- // hide loading spinner
186
- },
187
- },
188
- };
189
- </script>
190
-
191
- <style lang="scss" scoped>
192
- .connectivity-graph,
193
- .graph-canvas {
194
- width: 100%;
195
- height: 600px;
196
- background-color: white;
197
- position: relative;
198
- }
199
-
200
- .connectivity-graph {
201
- box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.06);
202
- border: solid 1px #e4e7ed;
203
- }
204
-
205
- .node-key {
206
- position: absolute;
207
- top: 1rem;
208
- right: 1rem;
209
- border: 1px solid $app-primary-color;
210
- padding: 4px;
211
- background-color: rgba(240, 240, 240, 0.8);
212
-
213
- div div {
214
- width: 90px;
215
- }
216
- }
217
-
218
- .key-head {
219
- text-align: center;
220
- font-weight: bold;
221
- border-bottom: 1px solid gray;
222
- padding-bottom: 4px;
223
- margin-bottom: 4px;
224
- }
225
-
226
- .key-box {
227
- float: right;
228
- width: 12px;
229
- height: 12px;
230
- }
231
- </style>
@@ -1,246 +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
- cy = 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.cy = new CytoscapeGraph(this, graphCanvas)
73
- }
74
-
75
- clearConnectivity()
76
- //=================
77
- {
78
- if (this.cy) {
79
- this.cy.remove()
80
- this.cy = null
81
- }
82
- }
83
-
84
- get elements()
85
- //============
86
- {
87
- return [
88
- ...this.nodes.map(n => { return {data: n}}),
89
- ...this.edges.map(e => { return {data: e}})
90
- ]
91
- }
92
-
93
- get roots()
94
- //===================
95
- {
96
- return this.dendrites
97
- }
98
-
99
- async graphNode(node)
100
- //=======================================================
101
- {
102
- const id = JSON.stringify(node)
103
- const label = [node[0], ...node[1]]
104
- const humanLabels = []
105
- for (const term of label) {
106
- const humanLabel = this.labelCache.has(term) ? this.labelCache.get(term) : ''
107
- humanLabels.push(humanLabel)
108
- }
109
- label.push(...humanLabels)
110
-
111
- const result = {
112
- id,
113
- label: label.join('\n')
114
- }
115
- if (this.axons.includes(id)) {
116
- if (this.dendrites.includes(id)) {
117
- result['both-a-d'] = true
118
- } else {
119
- result['axon'] = true
120
- }
121
- } else if (this.dendrites.includes(id)) {
122
- result['dendrite'] = true
123
-
124
- }
125
- return result
126
- }
127
- }
128
-
129
- //==============================================================================
130
-
131
- const GRAPH_STYLE = [
132
- {
133
- 'selector': 'node',
134
- 'style': {
135
- 'label': 'data(label)',
136
- 'background-color': '#80F0F0',
137
- 'text-valign': 'center',
138
- 'text-wrap': 'wrap',
139
- 'text-max-width': '80px',
140
- 'font-size': '6px'
141
- }
142
- },
143
- {
144
- 'selector': 'node[axon]',
145
- 'style': {
146
- 'background-color': 'green'
147
- }
148
- },
149
- {
150
- 'selector': 'node[dendrite]',
151
- 'style': {
152
- 'background-color': 'red'
153
- }
154
- },
155
- {
156
- 'selector': 'node[both-a-d]',
157
- 'style': {
158
- 'background-color': 'gray'
159
- }
160
- },
161
- {
162
- 'selector': 'edge',
163
- 'style': {
164
- 'width': 2,
165
- 'line-color': '#9dbaea',
166
- 'target-arrow-color': '#9dbaea',
167
- 'target-arrow-shape': 'triangle',
168
- 'curve-style': 'bezier'
169
- }
170
- }
171
- ]
172
-
173
- //==============================================================================
174
-
175
- class CytoscapeGraph
176
- {
177
- cy
178
- tooltip
179
-
180
- constructor(connectivityGraph, graphCanvas)
181
- {
182
- // const graphCanvas = document.getElementById('graph-canvas')
183
- this.cy = cytoscape({
184
- container: graphCanvas,
185
- elements: connectivityGraph.elements,
186
- layout: {
187
- name: 'breadthfirst',
188
- circle: false,
189
- roots: connectivityGraph.roots
190
- },
191
- directed: true,
192
- style: GRAPH_STYLE
193
- }).on('mouseover', 'node', this.overNode.bind(this))
194
- .on('mouseout', 'node', this.exitNode.bind(this))
195
- .on('position', 'node', this.moveNode.bind(this))
196
-
197
- this.tooltip = document.createElement('div')
198
- this.tooltip.id = 'tooltip'
199
- this.tooltip.hidden = true
200
- this.graphCanvas?.lastChild?.appendChild(this.tooltip)
201
- }
202
-
203
- remove()
204
- //======
205
- {
206
- if (this.cy) {
207
- this.cy.destroy()
208
- }
209
- }
210
-
211
- checkRightBoundary(leftPos)
212
- //==================================
213
- {
214
- if ((leftPos + this.tooltip.offsetWidth) >= this.tooltip.parentElement?.offsetWidth) {
215
- this.tooltip.style.left = `${leftPos - this.tooltip.offsetWidth}px`
216
- }
217
- }
218
-
219
- overNode(event)
220
- //==============
221
- {
222
- const node = event.target
223
- this.tooltip.innerText = node.data().label
224
- this.tooltip.style.left = `${event.renderedPosition.x}px`
225
- this.tooltip.style.top = `${event.renderedPosition.y}px`
226
- this.tooltip.hidden = false
227
- this.checkRightBoundary(event.renderedPosition.x)
228
- }
229
-
230
- moveNode(event)
231
- //==============
232
- {
233
- const node = event.target
234
- this.tooltip.style.left = `${node.renderedPosition().x}px`
235
- this.tooltip.style.top = `${node.renderedPosition().y}px`
236
- this.checkRightBoundary(node.renderedPosition().x)
237
- }
238
-
239
- exitNode(event)
240
- //==============
241
- {
242
- this.tooltip.hidden = true
243
- }
244
- }
245
-
246
- //==============================================================================