@abi-software/flatmapvuer 1.13.4 → 1.13.5-demo.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/flatmapvuer",
3
- "version": "1.13.4",
3
+ "version": "1.13.5-demo.0",
4
4
  "license": "Apache-2.0",
5
5
  "files": [
6
6
  "dist/*",
@@ -634,6 +634,7 @@ import { capitalise, normaliseAlertToStringArray } from './utilities.js'
634
634
  import yellowstar from '../icons/yellowstar'
635
635
  import ResizeSensor from 'css-element-queries/src/ResizeSensor'
636
636
  import flatmap from '../services/flatmapLoader.js'
637
+ import { attachSomaLocationMarkerMethods } from '../services/somaLocationMarkers.js'
637
638
  import { AnnotationService } from '@abi-software/sparc-annotation'
638
639
  import { mapState } from 'pinia'
639
640
  import { useMainStore } from '@/store/index'
@@ -2837,7 +2838,7 @@ export default {
2837
2838
  }
2838
2839
  )
2839
2840
  promise1.then((returnedObject) => {
2840
- this.mapImp = returnedObject
2841
+ this.mapImp = attachSomaLocationMarkerMethods(returnedObject)
2841
2842
  this.serverURL = this.mapImp.makeServerUrl('').slice(0, -1)
2842
2843
  let mapVersion = this.mapImp.details.version
2843
2844
  this.setFlightPathInfo(mapVersion)
@@ -0,0 +1,125 @@
1
+ const SOMA_MARKER_COLOUR = '#1b7f6b'
2
+ const SOMA_MARKER_SECONDARY_COLOUR = '#f4f1de'
3
+ const SOMA_MARKER_TEXT_COLOUR = '#12312b'
4
+ const SOMA_MARKER_MAX_COUNT_LABEL = '99+'
5
+
6
+ const normalizeSomaLocations = function (somaLocations) {
7
+ return (Array.isArray(somaLocations) ? somaLocations : [])
8
+ .map((item) => ({
9
+ label: String(item?.label || '').trim(),
10
+ curie: String(item?.curie || '').trim(),
11
+ count: Number(item?.count || 0),
12
+ }))
13
+ .filter((item) => item.curie && item.count > 0)
14
+ }
15
+
16
+ const formatCount = function (count) {
17
+ if (count > 99) return SOMA_MARKER_MAX_COUNT_LABEL
18
+ return String(count)
19
+ }
20
+
21
+ const createSomaLocationMarkerElement = function (somaLocation) {
22
+ const wrapper = document.createElement('div')
23
+ wrapper.className = 'flatmapvuer-soma-location-marker'
24
+ wrapper.title = somaLocation.label || somaLocation.curie
25
+ wrapper.style.width = '34px'
26
+ wrapper.style.height = '48px'
27
+ wrapper.style.display = 'flex'
28
+ wrapper.style.alignItems = 'center'
29
+ wrapper.style.justifyContent = 'center'
30
+ wrapper.style.transform = 'translate(-50%, -100%)'
31
+
32
+ const countLabel = formatCount(somaLocation.count)
33
+ wrapper.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1 -1 27 42" width="34" height="48" aria-hidden="true">
34
+ <ellipse style="fill: rgb(0, 0, 0); fill-opacity: 0.18;" cx="12" cy="36" rx="8" ry="4"/>
35
+ <path d="M12.25.25a12.254 12.254 0 0 0-12 12.494
36
+ c0 6.444 6.488 12.109 11.059 22.564.549 1.256 1.333 1.256 1.882 0
37
+ C17.762 24.853 24.25 19.186 24.25 12.744A12.254 12.254 0 0 0 12.25.25Z"
38
+ style="fill:${SOMA_MARKER_COLOUR};stroke:${SOMA_MARKER_SECONDARY_COLOUR};stroke-width:1.1"/>
39
+ <circle cx="12.5" cy="12.5" r="8" fill="${SOMA_MARKER_SECONDARY_COLOUR}"/>
40
+ <text x="12.5" y="16.1" text-anchor="middle" style="font-size:7.5px;font-weight:700;fill:${SOMA_MARKER_TEXT_COLOUR};font-family:Arial, sans-serif">${countLabel}</text>
41
+ </svg>`
42
+
43
+ return wrapper
44
+ }
45
+
46
+ const resolveMarkerPlacement = function (mapImp, curie) {
47
+ const featureIds = Array.isArray(mapImp?.modelFeatureIds?.(curie)) ? mapImp.modelFeatureIds(curie) : []
48
+ const placements = []
49
+ const seenFeatureUris = new Set()
50
+
51
+ for (const featureId of featureIds) {
52
+ const annotation = mapImp.annotation(featureId)
53
+ const featureUri = String(annotation?.uri || '').trim()
54
+ if (featureUri && !seenFeatureUris.has(featureUri)) {
55
+ seenFeatureUris.add(featureUri)
56
+ placements.push({
57
+ type: 'feature-uri',
58
+ value: featureUri,
59
+ })
60
+ }
61
+ }
62
+
63
+ // Fall back to model placement only when no feature URI can be resolved.
64
+ if (!placements.length && featureIds.length) {
65
+ placements.push({
66
+ type: 'model',
67
+ value: curie,
68
+ })
69
+ }
70
+
71
+ return placements
72
+ }
73
+
74
+ export const attachSomaLocationMarkerMethods = function (mapImp) {
75
+ if (!mapImp || mapImp.addSomaLocationMarkers) {
76
+ return mapImp
77
+ }
78
+
79
+ let markerIds = []
80
+
81
+ mapImp.clearSomaLocationMarkers = function () {
82
+ markerIds.forEach((markerId) => {
83
+ mapImp.removeMarker(markerId)
84
+ })
85
+ markerIds = []
86
+ }
87
+
88
+ mapImp.addSomaLocationMarkers = function (somaLocations) {
89
+ const normalizedSomaLocations = normalizeSomaLocations(somaLocations)
90
+ const placedSomaLocations = []
91
+
92
+ mapImp.clearSomaLocationMarkers()
93
+
94
+ normalizedSomaLocations.forEach((somaLocation) => {
95
+ const placements = resolveMarkerPlacement(mapImp, somaLocation.curie)
96
+ if (!placements.length) return
97
+
98
+ let somaLocationPlaced = false
99
+ placements.forEach((placement) => {
100
+ const markerElement = createSomaLocationMarkerElement(somaLocation)
101
+ let addedMarkerIds = []
102
+
103
+ if (placement.type === 'feature-uri') {
104
+ addedMarkerIds = mapImp.addMarkerByFeatureUri(placement.value, { element: markerElement })
105
+ } else if (placement.type === 'model') {
106
+ const markerId = mapImp.addMarker(placement.value, { element: markerElement })
107
+ addedMarkerIds = markerId > -1 ? [markerId] : []
108
+ }
109
+
110
+ if (!addedMarkerIds.length) return
111
+
112
+ markerIds.push(...addedMarkerIds)
113
+ somaLocationPlaced = true
114
+ })
115
+
116
+ if (somaLocationPlaced) {
117
+ placedSomaLocations.push(somaLocation)
118
+ }
119
+ })
120
+
121
+ return placedSomaLocations
122
+ }
123
+
124
+ return mapImp
125
+ }