imerss-bioinfo 1.0.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/README.md +156 -0
- package/build.js +196 -0
- package/docs/css/imerss-viz-all.css +1227 -0
- package/docs/css/imerss-viz-wp-overrides.css +70 -0
- package/docs/css/pepiowelh.css +76 -0
- package/docs/css/xetthecum-external.css +47 -0
- package/docs/css/xetthecum-shared.css +80 -0
- package/docs/css/xetthecum.css +526 -0
- package/docs/js/imerss-viz-all.js +58 -0
- package/docs/js/imerss-viz-all.js.map +1 -0
- package/docs/js/jquery.js +10881 -0
- package/index.html +81 -0
- package/index.js +7 -0
- package/indexWithJustMap.html +92 -0
- package/indexWithMap.html +79 -0
- package/indexWithMapHoweSound.html +91 -0
- package/indexWithMapPepiowelh.html +119 -0
- package/indexWithMapValdes.html +90 -0
- package/indexWithMapXetthecum.html +90 -0
- package/package.json +50 -0
- package/src/WoRMS/taxonAPI.js +13 -0
- package/src/arphify.js +662 -0
- package/src/assignNames.js +103 -0
- package/src/auxBuild/restoreJQuery.js +1 -0
- package/src/buildSource/Comprehensive Lists.html +42 -0
- package/src/buildSource/Data Paper Part I Visualisation.html +50 -0
- package/src/buildSource/Galiano Life List.html +43 -0
- package/src/buildSource/Metchosin/index.html +22 -0
- package/src/buildSource/Pe'pi'ow'elh.html +72 -0
- package/src/buildSource/Squamish Life List.html +48 -0
- package/src/buildSource/Valdes Island Biodiversity.html +64 -0
- package/src/buildSource/Xetthecum.html +40 -0
- package/src/buildSource/dataPaperSunburstAndMap.html +30 -0
- package/src/buildSource/index.html +224 -0
- package/src/client/css/imerss-viz-wp-overrides.css +70 -0
- package/src/client/css/imerss-viz.css +531 -0
- package/src/client/css/pepiowelh.css +76 -0
- package/src/client/css/xetthecum-external.css +47 -0
- package/src/client/css/xetthecum-shared.css +80 -0
- package/src/client/css/xetthecum.css +526 -0
- package/src/client/html/imerss-viz-map-only.html +75 -0
- package/src/client/html/imerss-viz-map-pepi.html +77 -0
- package/src/client/html/imerss-viz-map-xetthecum.html +90 -0
- package/src/client/html/imerss-viz-map.html +75 -0
- package/src/client/html/imerss-viz.html +58 -0
- package/src/client/html/importing Xetthecum patterns.txt +10 -0
- package/src/client/html/xetthecum-patterns.html +27 -0
- package/src/client/img/Animalia_2.svg +1 -0
- package/src/client/img/Animalia_Annelida.svg +655 -0
- package/src/client/img/Animalia_Chaetognatha.svg +72 -0
- package/src/client/img/Animalia_Cnidaria.svg +173 -0
- package/src/client/img/Animalia_Ctenophora.svg +298 -0
- package/src/client/img/Animalia_Nemertea.svg +54 -0
- package/src/client/img/Animalia_Phoronida.svg +271 -0
- package/src/client/img/Animalia_Platyhelminthes.svg +58 -0
- package/src/client/img/Animalia_Porifera.svg +220 -0
- package/src/client/img/Animalia_Sipuncula.svg +155 -0
- package/src/client/img/Arachnoidiscus_schmidtii_web_1-2-scaled.webp +0 -0
- package/src/client/img/Arrow-down.svg +11 -0
- package/src/client/img/Arrow-up.svg +6 -0
- package/src/client/img/Chromista.svg +1 -0
- package/src/client/img/Pepiowelh/BlackNoWe2-wb-bb.png +0 -0
- package/src/client/img/Pepiowelh/BlackNoWe2-wb.png +0 -0
- package/src/client/img/Pepiowelh/BlackNoWe2.png +0 -0
- package/src/client/img/Pepiowelh/Ecocultural Mapping Banner.svg +1 -0
- package/src/client/img/Plankton.jpg +0 -0
- package/src/client/img/Plantae.svg +1 -0
- package/src/client/img/Plantae_2.svg +1 -0
- package/src/client/img/Protista.svg +1 -0
- package/src/client/img/Valdes/Valdes Island Conservancy.jpg +0 -0
- package/src/client/img/Xetthecum/Agricultural.jpg +0 -0
- package/src/client/img/Xetthecum/Anthropogenic_banner.jpg +0 -0
- package/src/client/img/Xetthecum/Broad_Leaf.jpg +0 -0
- package/src/client/img/Xetthecum/Caves.jpg +0 -0
- package/src/client/img/Xetthecum/Coastal_Bluffs.jpg +0 -0
- package/src/client/img/Xetthecum/Conifer_Pole_Sapling.jpg +0 -0
- package/src/client/img/Xetthecum/Developed.jpg +0 -0
- package/src/client/img/Xetthecum/Dock.jpg +0 -0
- package/src/client/img/Xetthecum/Eelgrass.jpg +0 -0
- package/src/client/img/Xetthecum/Forests_banner.jpg +0 -0
- package/src/client/img/Xetthecum/Freshwater_banner.jpg +0 -0
- package/src/client/img/Xetthecum/Greig_Creek.jpg +0 -0
- package/src/client/img/Xetthecum/Intertidal.jpg +0 -0
- package/src/client/img/Xetthecum/Laughlin_Lake.jpg +0 -0
- package/src/client/img/Xetthecum/Marine_banner.jpg +0 -0
- package/src/client/img/Xetthecum/Mature_Conifer_Forest.jpg +0 -0
- package/src/client/img/Xetthecum/Porlier_Pass_Road.jpg +0 -0
- package/src/client/img/Xetthecum/Riparian.jpg +0 -0
- package/src/client/img/Xetthecum/Rural.jpg +0 -0
- package/src/client/img/Xetthecum/Subtidal.jpg +0 -0
- package/src/client/img/Xetthecum/Wetland.jpg +0 -0
- package/src/client/img/Xetthecum/Woodland.jpg +0 -0
- package/src/client/img/Xetthecum/Woodland_banner.jpg +0 -0
- package/src/client/img/Xetthecum/Xetthecum.jpg +0 -0
- package/src/client/img/Xetthecum/Young_Conifer_Forest.jpg +0 -0
- package/src/client/img/Xetthecum/Young_Mixed_Forest.jpg +0 -0
- package/src/client/img/Xetthecum/food.svg +38 -0
- package/src/client/img/Xetthecum/indicator.svg +52 -0
- package/src/client/img/Xetthecum/material.svg +186 -0
- package/src/client/img/Xetthecum/medicinal.svg +62 -0
- package/src/client/img/Xetthecum/missing-value.svg +3 -0
- package/src/client/img/Xetthecum/spiritual.svg +13 -0
- package/src/client/img/Xetthecum/trade.svg +74 -0
- package/src/client/img/audio.svg +5 -0
- package/src/client/img/external-link.svg +3 -0
- package/src/client/img/selected-eye.svg +4 -0
- package/src/client/img/selected-tick.svg +3 -0
- package/src/client/img/thumbs/BCLeps.jpg +0 -0
- package/src/client/img/thumbs/Checklist.jpg +0 -0
- package/src/client/img/thumbs/Data-Paper-Figma.jpg +0 -0
- package/src/client/img/thumbs/Galiano-Data-Paper.jpg +0 -0
- package/src/client/img/thumbs/Galiano.jpg +0 -0
- package/src/client/img/thumbs/Maxwell.jpg +0 -0
- package/src/client/img/thumbs/Squamish.jpg +0 -0
- package/src/client/img/thumbs/Valdes.jpg +0 -0
- package/src/client/img/thumbs/Xetthecum.jpg +0 -0
- package/src/client/img/up-arrow.svg +4 -0
- package/src/client/js/autocomplete.js +53 -0
- package/src/client/js/checklist.js +179 -0
- package/src/client/js/colour.js +139 -0
- package/src/client/js/datasetControls.js +212 -0
- package/src/client/js/imerss-viz.js +1397 -0
- package/src/client/js/leafletMap.js +357 -0
- package/src/client/js/leafletMapWithGrid.js +337 -0
- package/src/client/js/leafletMapWithRegions.js +381 -0
- package/src/client/js/renderSVG.js +108 -0
- package/src/client/js/tabs.js +53 -0
- package/src/client/js/xetthecum.js +106 -0
- package/src/client/json/emptyPhyloMap.json +1 -0
- package/src/client/json/kingdomPhyloMap.json +17 -0
- package/src/client/json/phyloMap.json +58 -0
- package/src/compare.js +97 -0
- package/src/compilecsv.js +47 -0
- package/src/dataProcessing/LZ4.js +27 -0
- package/src/dataProcessing/coordinatePatch.js +151 -0
- package/src/dataProcessing/readCSV.js +107 -0
- package/src/dataProcessing/readCSVwithMap.js +90 -0
- package/src/dataProcessing/readCSVwithoutMap.js +25 -0
- package/src/dataProcessing/readJSON.js +23 -0
- package/src/dataProcessing/sqlite.js +174 -0
- package/src/dataProcessing/summarise.js +122 -0
- package/src/dataProcessing/taxonScrape.js +14 -0
- package/src/dataProcessing/worker.js +31 -0
- package/src/dataProcessing/writeCSV.js +34 -0
- package/src/dataProcessing/writeJSON.js +15 -0
- package/src/dbtaxa.js +96 -0
- package/src/deAuthorise.js +48 -0
- package/src/deqgis.js +148 -0
- package/src/expressions/expr.js +65 -0
- package/src/expressions/jsep.js +925 -0
- package/src/filterFirst.js +51 -0
- package/src/geom/geoJSON.js +121 -0
- package/src/iNaturalist/examples/api.inaturalist.org-v1-taxa!q=Acmispon americanus americanus.json +200 -0
- package/src/iNaturalist/examples/api.inaturalist.org-v1-taxa!q=Flabellina japonica.json +61 -0
- package/src/iNaturalist/examples/www.inaturalist.org-taxa-877359.json +132 -0
- package/src/iNaturalist/iNatUrls.js +17 -0
- package/src/iNaturalist/obsAPI.js +150 -0
- package/src/iNaturalist/taxonAPI.js +460 -0
- package/src/inatObs.js +120 -0
- package/src/inattify.js +123 -0
- package/src/intersect.js +80 -0
- package/src/intersectFilter.js +48 -0
- package/src/landlocked.js +137 -0
- package/src/lib/jquery.binarytransport.js +51 -0
- package/src/lib/lz4-commentary.txt +9 -0
- package/src/lib/lz4.js +73 -0
- package/src/lib/point-in-polygon.js +36 -0
- package/src/lz4.js +40 -0
- package/src/marmalise.js +333 -0
- package/src/materialise.js +68 -0
- package/src/reintegrate.js +71 -0
- package/src/taxonomise.js +615 -0
- package/src/unscrewGBIF.js +44 -0
- package/src/utils/dataSource.js +173 -0
- package/src/utils/settleStructure.js +62 -0
- package/src/utils/utils.js +92 -0
- package/src/viz/plethify.js +39 -0
- package/src/wormify.js +154 -0
- package/src/xetthecum/xetthecumFilters.js +126 -0
- package/test/testDataSource.js +182 -0
- package/test/testiNatObsSource.js +38 -0
- package/test/testiNatSource.js +50 -0
|
@@ -0,0 +1,1397 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2017-2022 Antranig Basman
|
|
3
|
+
Licensed under the Educational Community License (ECL), Version 2.0 or the New
|
|
4
|
+
BSD license. You may not use this file except in compliance with one these
|
|
5
|
+
Licenses.
|
|
6
|
+
You may obtain a copy of the ECL 2.0 License and BSD License at
|
|
7
|
+
https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/* global lz4 */
|
|
11
|
+
|
|
12
|
+
"use strict";
|
|
13
|
+
// noinspection ES6ConvertVarToLetConst // otherwise this is a duplicate on minifying
|
|
14
|
+
var hortis = fluid.registerNamespace("hortis");
|
|
15
|
+
|
|
16
|
+
fluid.setLogging(true);
|
|
17
|
+
|
|
18
|
+
fluid.defaults("hortis.configHolder", {
|
|
19
|
+
gradeNames: "fluid.component"
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
fluid.defaults("hortis.sunburstLoader", {
|
|
23
|
+
gradeNames: ["fluid.viewComponent", "fluid.resourceLoader", "hortis.configHolder"],
|
|
24
|
+
sunburstPixels: 1002,
|
|
25
|
+
markupTemplate: "%resourceBase/html/imerss-viz.html",
|
|
26
|
+
phyloMap: "%resourceBase/json/phyloMap.json",
|
|
27
|
+
resourceBase: "src/client",
|
|
28
|
+
queryOnStartup: "",
|
|
29
|
+
selectOnStartup: "",
|
|
30
|
+
showObsListInTooltip: true,
|
|
31
|
+
gridResolution: undefined,
|
|
32
|
+
friendlyNames: undefined,
|
|
33
|
+
initialTab: "checklist",
|
|
34
|
+
distributeOptions: {
|
|
35
|
+
gridResolution: {
|
|
36
|
+
source: "{that}.options.gridResolution",
|
|
37
|
+
target: "{that hortis.quantiser}.options.model.longResolution"
|
|
38
|
+
},
|
|
39
|
+
friendlyNames: {
|
|
40
|
+
source: "{that}.options.friendlyNames",
|
|
41
|
+
target: "{that hortis.sunburst}.options.friendlyNames"
|
|
42
|
+
},
|
|
43
|
+
initialTab: {
|
|
44
|
+
source: "{that}.options.initialTab",
|
|
45
|
+
target: "{that hortis.imerssTabs}.options.model.selectedTab"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
resourceOptions: {
|
|
49
|
+
terms: {
|
|
50
|
+
resourceBase: "{that}.options.resourceBase"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
resources: {
|
|
54
|
+
viz: {
|
|
55
|
+
url: "{that}.options.vizFile",
|
|
56
|
+
dataType: "binary",
|
|
57
|
+
options: {
|
|
58
|
+
processData: false,
|
|
59
|
+
responseType: "arraybuffer"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
markup: {
|
|
63
|
+
url: "{that}.options.markupTemplate",
|
|
64
|
+
dataType: "text"
|
|
65
|
+
},
|
|
66
|
+
phyloMap: {
|
|
67
|
+
url: "{that}.options.phyloMap",
|
|
68
|
+
dataType: "json"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
invokers: {
|
|
72
|
+
resolveColourStrategy: "hortis.resolveColourStrategy({that}.options.colourCount)"
|
|
73
|
+
},
|
|
74
|
+
listeners: {
|
|
75
|
+
"onResourcesLoaded.renderMarkup": {
|
|
76
|
+
priority: "first",
|
|
77
|
+
listener: "hortis.sunburstLoader.renderMarkup",
|
|
78
|
+
args: ["{that}.container", "{that}.resources.markup.resourceText", "{that}.options.renderMarkup", {
|
|
79
|
+
sunburstPixels: "{that}.options.sunburstPixels"
|
|
80
|
+
}]
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
components: {
|
|
84
|
+
sunburst: {
|
|
85
|
+
type: "hortis.sunburst",
|
|
86
|
+
createOnEvent: "onResourcesLoaded",
|
|
87
|
+
options: {
|
|
88
|
+
container: "{sunburstLoader}.container",
|
|
89
|
+
gradeNames: "{sunburstLoader}.resolveColourStrategy",
|
|
90
|
+
colourCount: "{sunburstLoader}.options.colourCount",
|
|
91
|
+
culturalValues: "{sunburstLoader}.options.culturalValues",
|
|
92
|
+
suppressObsAuthors: "{sunburstLoader}.options.suppressObsAuthors",
|
|
93
|
+
queryOnStartup: "{sunburstLoader}.options.queryOnStartup",
|
|
94
|
+
selectOnStartup: "{sunburstLoader}.options.selectOnStartup",
|
|
95
|
+
members: {
|
|
96
|
+
viz: "@expand:hortis.decompressLZ4({sunburstLoader}.resources.viz.resourceText)",
|
|
97
|
+
tree: "{that}.viz.tree"
|
|
98
|
+
},
|
|
99
|
+
model: {
|
|
100
|
+
commonNames: "{sunburstLoader}.options.commonNames"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
hortis.resolveResources = function (resources, terms) {
|
|
108
|
+
const mapped = fluid.transform(resources, function (oneResource) {
|
|
109
|
+
return fluid.extend(true, {}, oneResource, {
|
|
110
|
+
url: fluid.stringTemplate(oneResource.url, terms)
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
return mapped;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
hortis.decompressLZ4 = function (arrayBuffer) {
|
|
117
|
+
const uint8in = new Uint8Array(arrayBuffer);
|
|
118
|
+
const uint8out = lz4.decompress(uint8in);
|
|
119
|
+
const text = new TextDecoder("utf-8").decode(uint8out);
|
|
120
|
+
return JSON.parse(text);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
hortis.combineSelectors = function () {
|
|
124
|
+
return fluid.makeArray(arguments).join(", ");
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
hortis.sunburstLoader.renderMarkup = function (container, template, renderMarkup, terms) {
|
|
128
|
+
if (renderMarkup) {
|
|
129
|
+
const rendered = fluid.stringTemplate(template, terms);
|
|
130
|
+
const fragment = document.createRange().createContextualFragment(rendered);
|
|
131
|
+
const root = fragment.firstElementChild;
|
|
132
|
+
while (root.firstChild) {
|
|
133
|
+
container[0].appendChild(root.firstChild);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
hortis.colouringGrades = {
|
|
139
|
+
undocumentedCount: "fluid.component",
|
|
140
|
+
observationCount: "hortis.sunburstWithObsColour"
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
hortis.resolveColourStrategy = function (countField) {
|
|
144
|
+
return hortis.colouringGrades[countField];
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
fluid.defaults("hortis.sunburstWithObsColour", {
|
|
148
|
+
gradeNames: "fluid.component",
|
|
149
|
+
invokers: {
|
|
150
|
+
fillColourForRow: "hortis.obsColourForRow({that}.options.parsedColours, {arguments}.0, {that}.flatTree.0)"
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
fluid.defaults("hortis.imerssTabs", {
|
|
155
|
+
gradeNames: "hortis.tabs",
|
|
156
|
+
tabIds: {
|
|
157
|
+
simpleChecklist: "fli-tab-simple-checklist",
|
|
158
|
+
checklist: "fli-tab-checklist",
|
|
159
|
+
sunburst: "fli-tab-sunburst"
|
|
160
|
+
},
|
|
161
|
+
model: {
|
|
162
|
+
// selectedTab: "checklist"
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Holds model state shared with checklist and index
|
|
167
|
+
fluid.defaults("hortis.layoutHolder", {
|
|
168
|
+
gradeNames: "fluid.modelComponent",
|
|
169
|
+
members: {
|
|
170
|
+
taxonHistory: []
|
|
171
|
+
},
|
|
172
|
+
model: {
|
|
173
|
+
rowFocus: {},
|
|
174
|
+
layoutId: null,
|
|
175
|
+
selectedId: null,
|
|
176
|
+
hoverId: null,
|
|
177
|
+
historyIndex: 0
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
fluid.defaults("hortis.withPanelLabel", {
|
|
182
|
+
gradeNames: "fluid.viewComponent",
|
|
183
|
+
selectors: {
|
|
184
|
+
panelLabel: ".fld-imerss-panel-label"
|
|
185
|
+
},
|
|
186
|
+
model: {
|
|
187
|
+
panelLabel: ""
|
|
188
|
+
},
|
|
189
|
+
modelRelay: {
|
|
190
|
+
panelLabel: {
|
|
191
|
+
source: "panelLabel",
|
|
192
|
+
target: "dom.panelLabel.text"
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Note that sunburst's container is the overall fl-imerss-container, all of its contents related to the
|
|
198
|
+
// sunburst itself really need to be demoted
|
|
199
|
+
fluid.defaults("hortis.sunburst", {
|
|
200
|
+
gradeNames: ["hortis.layoutHolder", "hortis.withPanelLabel", "fluid.viewComponent"],
|
|
201
|
+
selectors: {
|
|
202
|
+
panelLabel: "#fli-tab-sunburst .fld-imerss-panel-label", // irregularity due to faulty container level
|
|
203
|
+
svg: ".flc-imerss-svg",
|
|
204
|
+
back: ".fld-imerss-back",
|
|
205
|
+
tabs: ".fld-imerss-tabs",
|
|
206
|
+
taxonDisplay: ".fld-imerss-taxonDisplay",
|
|
207
|
+
autocomplete: ".fld-imerss-autocomplete",
|
|
208
|
+
checklist: ".fld-imerss-checklist-holder",
|
|
209
|
+
simpleChecklist: ".fld-imerss-simple-checklist-holder",
|
|
210
|
+
segment: ".fld-imerss-segment",
|
|
211
|
+
label: ".fld-imerss-label",
|
|
212
|
+
phyloPic: ".fld-imerss-phyloPic"
|
|
213
|
+
// No longer supportable under FLUID-6145: BUG
|
|
214
|
+
// mousable: "@expand:hortis.combineSelectors({that}.options.selectors.segment, {that}.options.selectors.label, {that}.options.selectors.phyloPic)"
|
|
215
|
+
},
|
|
216
|
+
styles: {
|
|
217
|
+
segment: "fld-imerss-segment",
|
|
218
|
+
label: "fld-imerss-label",
|
|
219
|
+
phyloPic: "fld-imerss-phyloPic",
|
|
220
|
+
layoutRoot: "fl-imerss-layoutRoot",
|
|
221
|
+
labelPath: "fld-imerss-labelPath",
|
|
222
|
+
clickable: "fl-imerss-clickable"
|
|
223
|
+
},
|
|
224
|
+
components: {
|
|
225
|
+
autocomplete: {
|
|
226
|
+
type: "hortis.autocomplete",
|
|
227
|
+
options: {
|
|
228
|
+
container: "{sunburst}.dom.autocomplete",
|
|
229
|
+
id: "fli-imerss-autocomplete",
|
|
230
|
+
listeners: {
|
|
231
|
+
onConfirm: "hortis.confirmAutocomplete({sunburst}, {arguments}.0)"
|
|
232
|
+
},
|
|
233
|
+
invokers: {
|
|
234
|
+
// query, callback
|
|
235
|
+
query: "hortis.queryAutocomplete({that}.lookupTaxon, {arguments}.0, {arguments}.1)",
|
|
236
|
+
lookupTaxon: "{sunburst}.lookupTaxon({arguments}.0, {that}.options.maxSuggestions)",
|
|
237
|
+
renderInputValue: "hortis.autocompleteInputForRow",
|
|
238
|
+
renderSuggestion: "hortis.autocompleteSuggestionForRow"
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
tabs: {
|
|
243
|
+
type: "hortis.imerssTabs",
|
|
244
|
+
options: {
|
|
245
|
+
container: "{sunburst}.dom.tabs",
|
|
246
|
+
modelRelay: {
|
|
247
|
+
sunburstVisible: {
|
|
248
|
+
target: "{sunburst}.model.visible",
|
|
249
|
+
func: tab => tab === "sunburst",
|
|
250
|
+
args: "{tabs}.model.selectedTab"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
checklist: {
|
|
256
|
+
type: "hortis.checklist",
|
|
257
|
+
options: {
|
|
258
|
+
container: "{sunburst}.dom.checklist"
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
simpleChecklist: {
|
|
262
|
+
type: "hortis.checklist",
|
|
263
|
+
options: {
|
|
264
|
+
container: "{sunburst}.dom.simpleChecklist",
|
|
265
|
+
filterRanks: ["phylum", "class", "order", "species"]
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
colours: {
|
|
270
|
+
lowColour: "#9ecae1",
|
|
271
|
+
highColour: "#e7969c",
|
|
272
|
+
unfocusedColour: "#ddd"
|
|
273
|
+
},
|
|
274
|
+
zoomDuration: 1250,
|
|
275
|
+
scaleConfig: {
|
|
276
|
+
// original settings 1 and 12
|
|
277
|
+
innerDepth: 1 / 22,
|
|
278
|
+
outerDepth: 13 / 22,
|
|
279
|
+
rootRadii: [3 / 22,
|
|
280
|
+
3 / 22,
|
|
281
|
+
3 / 22,
|
|
282
|
+
13 / 22],
|
|
283
|
+
maxNodes: 200
|
|
284
|
+
},
|
|
285
|
+
parsedColours: "@expand:hortis.parseColours({that}.options.colours)",
|
|
286
|
+
colourCount: "undocumentedCount",
|
|
287
|
+
culturalValues: true,
|
|
288
|
+
// Use public-friendly names such as "species" rather than "taxon"
|
|
289
|
+
friendlyNames: false,
|
|
290
|
+
suppressObsAuthors: false,
|
|
291
|
+
model: {
|
|
292
|
+
scale: {
|
|
293
|
+
left: 0,
|
|
294
|
+
right: 0,
|
|
295
|
+
radiusScale: []
|
|
296
|
+
},
|
|
297
|
+
// From layoutHolder base grade:
|
|
298
|
+
// layoutId: id of segment at layout root
|
|
299
|
+
// hoverId: id of segment being hovered, giving rise to tooltip
|
|
300
|
+
// selectedId: id of row for taxon display
|
|
301
|
+
// rowFocus: {} - rows "focused" as a result of, e.g. map
|
|
302
|
+
visible: false,
|
|
303
|
+
commonNames: true
|
|
304
|
+
},
|
|
305
|
+
modelRelay: {
|
|
306
|
+
isAtRoot: {
|
|
307
|
+
target: "isAtRoot",
|
|
308
|
+
func: "hortis.isAtRoot",
|
|
309
|
+
args: ["{that}", "{that}.model.layoutId"]
|
|
310
|
+
},
|
|
311
|
+
backEnabled: {
|
|
312
|
+
target: "dom.back.attr.aria-disabled",
|
|
313
|
+
func: index => index < 2,
|
|
314
|
+
args: "{that}.model.historyIndex"
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
markup: {
|
|
318
|
+
segmentHeader: "<g xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">",
|
|
319
|
+
segment: "<path id=\"%id\" d=\"%path\" visibility=\"%visibility\" class=\"%clazz\" vector-effect=\"non-scaling-stroke\" style=\"%style\"></path>",
|
|
320
|
+
// dominant-baseline fails on some old Chromium and AS machines
|
|
321
|
+
label: "<path id=\"%labelPathId\" d=\"%textPath\" visibility=\"%labelVisibility\" class=\"%labelPathClass\" vector-effect=\"non-scaling-stroke\"></path>"
|
|
322
|
+
+ "<text id=\"%labelId\" dy=\"0.25em\" class=\"%labelClass\" visibility=\"%labelVisibility\" style=\"%labelStyle\">"
|
|
323
|
+
+ "<textPath xlink:href=\"#%labelPathId\" startOffset=\"50%\" style=\"text-anchor: middle\">%label</textPath></text>",
|
|
324
|
+
phyloPic: "<image id=\"%phyloPicId\" class=\"%phyloPicClass fl-imerss-clickable\" xlink:href=\"%phyloPicUrl\" height=\"%diameter\" width=\"%diameter\" x=\"%phyloPicX\" y=\"%phyloPicY\" />",
|
|
325
|
+
segmentFooter: "</g>",
|
|
326
|
+
taxonDisplayHeader: "<div>",
|
|
327
|
+
taxonDisplayRow: "<div %rootAttrs><span class=\"fl-taxonDisplay-key\">%key</span><span class=\"fl-taxonDisplay-value %valueClazz\">%value</span></div>",
|
|
328
|
+
taxonDisplayFooter: "</div>"
|
|
329
|
+
},
|
|
330
|
+
events: {
|
|
331
|
+
changeLayoutId: null
|
|
332
|
+
},
|
|
333
|
+
invokers: {
|
|
334
|
+
render: "hortis.render({that})",
|
|
335
|
+
renderLight: "hortis.renderLight({that})",
|
|
336
|
+
renderSegment: "hortis.renderSegment({that}, {arguments}.0, {arguments}.1)",
|
|
337
|
+
angleScale: "hortis.angleScale({arguments}.0, {that}.model.scale)",
|
|
338
|
+
elementToRow: "hortis.elementToRow({that}, {arguments}.0)",
|
|
339
|
+
segmentClicked: "hortis.segmentClicked({that}, {arguments}.0)",
|
|
340
|
+
fillColourForRow: "hortis.undocColourForRow({that}.options.parsedColours, {arguments}.0)",
|
|
341
|
+
getMousable: "hortis.combineSelectors({that}.options.selectors.segment, {that}.options.selectors.label, {that}.options.selectors.phyloPic)",
|
|
342
|
+
lookupTaxon: "hortis.lookupTaxon({that}.flatTree, {arguments}.0, {arguments}.1)"
|
|
343
|
+
},
|
|
344
|
+
modelListeners: {
|
|
345
|
+
scale: {
|
|
346
|
+
excludeSource: "init",
|
|
347
|
+
func: "{that}.renderLight"
|
|
348
|
+
},
|
|
349
|
+
selectedId: [{
|
|
350
|
+
namespace: "updateTaxonDisplay",
|
|
351
|
+
excludeSource: "init",
|
|
352
|
+
funcName: "hortis.updateTaxonDisplay",
|
|
353
|
+
args: ["{that}", "{change}.value"]
|
|
354
|
+
}, {
|
|
355
|
+
namespace: "renderLight",
|
|
356
|
+
excludeSource: "init",
|
|
357
|
+
func: "{that}.renderLight"
|
|
358
|
+
}],
|
|
359
|
+
hoverId: {
|
|
360
|
+
excludeSource: "init",
|
|
361
|
+
funcName: "hortis.updateTooltip",
|
|
362
|
+
args: ["{that}", "{change}.value"]
|
|
363
|
+
},
|
|
364
|
+
rowFocus: {
|
|
365
|
+
funcName: "hortis.updateRowFocus",
|
|
366
|
+
args: ["{that}", "{change}.value", "{change}.transaction"]
|
|
367
|
+
},
|
|
368
|
+
backClick: {
|
|
369
|
+
path: "dom.back.click",
|
|
370
|
+
funcName: "hortis.backTaxon",
|
|
371
|
+
args: ["{that}"]
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
listeners: {
|
|
375
|
+
"onCreate.doLayout": {
|
|
376
|
+
func: "hortis.doLayout",
|
|
377
|
+
args: ["{that}.flatTree"]
|
|
378
|
+
},
|
|
379
|
+
"onCreate.computeInitialScale": {
|
|
380
|
+
funcName: "hortis.computeInitialScale",
|
|
381
|
+
args: ["{that}"],
|
|
382
|
+
priority: "after:doLayout"
|
|
383
|
+
},
|
|
384
|
+
"onCreate.boundNodes": {
|
|
385
|
+
funcName: "hortis.boundNodes",
|
|
386
|
+
args: ["{that}", "{that}.model.layoutId", true],
|
|
387
|
+
priority: "before:render"
|
|
388
|
+
},
|
|
389
|
+
"onCreate.applyPhyloMap": {
|
|
390
|
+
funcName: "hortis.applyPhyloMap",
|
|
391
|
+
args: ["{sunburstLoader}.resources.phyloMap.parsed", "{that}.flatTree", "{sunburstLoader}.options.resourceOptions.terms"],
|
|
392
|
+
priority: "before:computeInitialScale"
|
|
393
|
+
},
|
|
394
|
+
"onCreate.render": {
|
|
395
|
+
func: "{that}.render",
|
|
396
|
+
priority: "after:computeInitialScale"
|
|
397
|
+
},
|
|
398
|
+
"onCreate.bindSunburstMouse": {
|
|
399
|
+
funcName: "hortis.bindSunburstMouse",
|
|
400
|
+
args: ["{that}"]
|
|
401
|
+
},
|
|
402
|
+
"onCreate.bindRowExpander": {
|
|
403
|
+
funcName: "hortis.bindRowExpander",
|
|
404
|
+
args: ["{that}"]
|
|
405
|
+
},
|
|
406
|
+
// Naturally in "future Infusion" this would be a single chain event with beginZoom as the last listener
|
|
407
|
+
// layoutId, source
|
|
408
|
+
"changeLayoutId.updateModel": "hortis.changeLayoutId({that}, {arguments}.0, {arguments}.1)"
|
|
409
|
+
},
|
|
410
|
+
members: {
|
|
411
|
+
visMap: [], // array of visibility aligned with flatTree
|
|
412
|
+
tree: null,
|
|
413
|
+
flatTree: "@expand:hortis.flattenTree({that}.tree)",
|
|
414
|
+
maxDepth: "@expand:hortis.computeMaxDepth({that}.flatTree)",
|
|
415
|
+
index: "@expand:hortis.indexTree({that}.flatTree)" // map id to row
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
hortis.capitalize = function (string) {
|
|
421
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
hortis.autocompleteInputForRow = function (row) {
|
|
425
|
+
return row ? hortis.labelForRow(row) + (row.commonName ? " (" + row.commonName + ")" : "") : row;
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
hortis.autocompleteSuggestionForRow = function (row) {
|
|
429
|
+
return hortis.autocompleteInputForRow(row) + (row.childCount > 1 ? " (" + row.childCount + " species)" : "");
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
hortis.lookupTaxon = function (flatTree, query, maxSuggestions) {
|
|
433
|
+
maxSuggestions = maxSuggestions || 1;
|
|
434
|
+
const output = [];
|
|
435
|
+
query = query.toLowerCase();
|
|
436
|
+
for (let i = 0; i < flatTree.length; ++i) {
|
|
437
|
+
const row = flatTree[i];
|
|
438
|
+
const display = hortis.autocompleteInputForRow(row);
|
|
439
|
+
if (display.toLowerCase().indexOf(query) !== -1) {
|
|
440
|
+
output.push(row);
|
|
441
|
+
}
|
|
442
|
+
if (output.length >= maxSuggestions) {
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return maxSuggestions === 1 ? output[0] : output;
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
hortis.queryAutocomplete = function (lookupTaxon, query, callback) {
|
|
450
|
+
const output = lookupTaxon(query);
|
|
451
|
+
callback(output);
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
hortis.confirmAutocomplete = function (that, row) {
|
|
455
|
+
if (row) { // on blur it may send nothing
|
|
456
|
+
that.events.changeLayoutId.fire(row.id, "autocomplete");
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
hortis.rowToPhyloIndex = function (row) {
|
|
461
|
+
return row.rank + ":" + row.iNaturalistTaxonName;
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
hortis.colourChildren = function (row, parsed) {
|
|
465
|
+
row.lowColour = parsed.lowColour;
|
|
466
|
+
row.highColour = parsed.highColour;
|
|
467
|
+
row.children.forEach(function (child) {
|
|
468
|
+
hortis.colourChildren(child, parsed);
|
|
469
|
+
});
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
hortis.applyPhyloMap = function (phyloMap, rows, terms) {
|
|
473
|
+
const parsedMap = fluid.transform(phyloMap, function (onePhylo) {
|
|
474
|
+
const togo = {};
|
|
475
|
+
if (onePhylo.pic) {
|
|
476
|
+
togo.phyloPicUrl = fluid.stringTemplate(onePhylo.pic, terms);
|
|
477
|
+
}
|
|
478
|
+
if (onePhylo.taxonPic) {
|
|
479
|
+
togo.taxonPic = fluid.stringTemplate(onePhylo.taxonPic, terms);
|
|
480
|
+
}
|
|
481
|
+
togo.taxonPicDescription = onePhylo.taxonPicDescription;
|
|
482
|
+
if (onePhylo.colour) {
|
|
483
|
+
const parsedColour = fluid.colour.hexToArray(onePhylo.colour);
|
|
484
|
+
const hsl = fluid.colour.rgbToHsl(parsedColour);
|
|
485
|
+
togo.lowColour = fluid.colour.hslToRgb([hsl[0], hsl[1], hsl[2] * 0.2 + 0.8]);
|
|
486
|
+
togo.highColour = fluid.colour.hslToRgb([hsl[0], hsl[1], hsl[2] * 0.8 + 0.2]);
|
|
487
|
+
}
|
|
488
|
+
return togo;
|
|
489
|
+
});
|
|
490
|
+
rows.forEach(function (row) {
|
|
491
|
+
const phyloIndex = hortis.rowToPhyloIndex(row);
|
|
492
|
+
const parsed = parsedMap[phyloIndex];
|
|
493
|
+
if (parsed) {
|
|
494
|
+
row.phyloPicUrl = parsed.phyloPicUrl;
|
|
495
|
+
row.taxonPic = parsed.taxonPic;
|
|
496
|
+
row.taxonPicDescription = parsed.taxonPicDescription;
|
|
497
|
+
hortis.colourChildren(row, parsed);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
hortis.taxonDisplayLookup = {
|
|
503
|
+
iNaturalistTaxonName: "Taxon Name:",
|
|
504
|
+
observationCount: "Observation Count:",
|
|
505
|
+
iNaturalistObsLink: "Observation:",
|
|
506
|
+
taxonLink: "iNaturalist Taxon:",
|
|
507
|
+
commonName: "Common Name:",
|
|
508
|
+
wikipediaSummary: "Wikipedia Summary",
|
|
509
|
+
iNaturalistTaxonImage: "iNaturalist Taxon Image:",
|
|
510
|
+
phyloPic: "Taxon Icon:",
|
|
511
|
+
taxonPic: "Taxon Picture:",
|
|
512
|
+
taxonPicDescription: "Taxon Picture Description:"
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
hortis.friendlyDisplayLookup = {
|
|
516
|
+
...hortis.taxonDisplayLookup,
|
|
517
|
+
iNaturalistTaxonName: "Species:"
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
hortis.commonFields = ["commonName", "wikipediaSummary"];
|
|
521
|
+
|
|
522
|
+
hortis.dumpRow = function (key, value, markup, extraClazz, valueClazz, options) {
|
|
523
|
+
if (value) {
|
|
524
|
+
const toLook = options?.friendlyNames ? hortis.friendlyDisplayLookup : hortis.taxonDisplayLookup;
|
|
525
|
+
const keyName = key ? (toLook[key] || hortis.capitalize(key)) : "";
|
|
526
|
+
const clazz = "fl-taxonDisplay-row " + (extraClazz || "");
|
|
527
|
+
valueClazz = valueClazz || "";
|
|
528
|
+
return fluid.stringTemplate(markup.taxonDisplayRow, {
|
|
529
|
+
key: keyName,
|
|
530
|
+
value: value,
|
|
531
|
+
rootAttrs: "class=\"" + clazz + "\"",
|
|
532
|
+
valueClazz: valueClazz
|
|
533
|
+
});
|
|
534
|
+
} else {
|
|
535
|
+
return "";
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
hortis.renderDate = function (date) {
|
|
540
|
+
return new Date(date).toISOString().substring(0, 10);
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
hortis.expandButtonMarkup = "<span class=\"fl-taxonDisplay-expand fl-taxonDisplay-unexpanded\"></span>";
|
|
544
|
+
|
|
545
|
+
hortis.sourceTable = { // TODO: get this from marmalised.json but the names currently there are too long
|
|
546
|
+
iNat: "iNaturalist",
|
|
547
|
+
PMLS: "Pacific Marine Life Surveys",
|
|
548
|
+
RBCM: "Royal British Columbia Museum",
|
|
549
|
+
CMN: "Canadian Museum of Nature",
|
|
550
|
+
BCCSN: "British Columbia Cetacean Sightings Network",
|
|
551
|
+
"Gal-Salm": "Erickson",
|
|
552
|
+
CHU2010: "Chu and Leys (2010)",
|
|
553
|
+
CHU2012: "Chu and Leys (2012)",
|
|
554
|
+
Hunterston: "Hunterston Farms BioBlitz 2010"
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
/** Decode data collection from an observation id from a colon-separated prefix
|
|
558
|
+
* @param {String} obsId - The observation id to be decoded
|
|
559
|
+
* @return {String|Null} The observation's collection if the observation id was qualified with a prefix, else null
|
|
560
|
+
*/
|
|
561
|
+
hortis.sourceFromId = function (obsId) {
|
|
562
|
+
const colpos = obsId ? obsId.indexOf(":") : -1;
|
|
563
|
+
return colpos === -1 ? null : obsId.substring(0, colpos);
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
hortis.renderObsId = function (obsId) {
|
|
567
|
+
const dataset = hortis.datasetIdFromObs(obsId);
|
|
568
|
+
if (dataset === "iNat") {
|
|
569
|
+
const localId = hortis.localIdFromObs(obsId);
|
|
570
|
+
return fluid.stringTemplate("<a target=\"_blank\" href=\"https://www.inaturalist.org/observations/%obsId\">%obsId</a>", {
|
|
571
|
+
obsId: localId
|
|
572
|
+
});
|
|
573
|
+
} else {
|
|
574
|
+
return obsId;
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
// Render a set of fields derived from an "observation range" - group of fields prefixed by "first" and "last"
|
|
579
|
+
// including date/time/recordedBy/collection
|
|
580
|
+
hortis.renderObsBound = function (row, prefix, markup, options) {
|
|
581
|
+
const date = row[prefix + "Timestamp"];
|
|
582
|
+
if (date) {
|
|
583
|
+
const capPrefix = prefix === "since" ? "" : hortis.capitalize(prefix);
|
|
584
|
+
const recordedBy = row[prefix + "RecordedBy"];
|
|
585
|
+
const catalogueNumber = row[prefix + "CatalogueNumber"];
|
|
586
|
+
const value = hortis.renderDate(row[prefix + "Timestamp"]) + (recordedBy && !options.suppressObsAuthors ? " by " + recordedBy : "");
|
|
587
|
+
|
|
588
|
+
const row1 = hortis.dumpRow(capPrefix + (prefix === "since" ? " Observed:" : " Reported:"), value, markup);
|
|
589
|
+
|
|
590
|
+
const obsId = row[prefix + "ObservationId"];
|
|
591
|
+
|
|
592
|
+
const collection = row[prefix + "Collection"];
|
|
593
|
+
const obsIdCollection = hortis.sourceFromId(row[prefix + "ObservationId"]);
|
|
594
|
+
const renderedCollection = hortis.sourceTable[obsIdCollection || collection] || collection;
|
|
595
|
+
|
|
596
|
+
let source = renderedCollection + (catalogueNumber ? " (" + catalogueNumber + ")" : "");
|
|
597
|
+
if (obsId && obsIdCollection === "iNat") {
|
|
598
|
+
source += " observation " + hortis.renderObsId(obsId);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const row2 = hortis.dumpRow("Source:", source, markup);
|
|
602
|
+
|
|
603
|
+
return row1 + row2;
|
|
604
|
+
} else {
|
|
605
|
+
return "";
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
hortis.drivePlayer = "<iframe frameborder=\"0\" width=\"360\" height=\"55\" src=\"%url\"></iframe>";
|
|
610
|
+
|
|
611
|
+
hortis.driveToPreview = function (url) {
|
|
612
|
+
const lastSlash = url.lastIndexOf("/");
|
|
613
|
+
return url.substring(0, lastSlash) + "/preview";
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
hortis.hulqValues = ["food", "medicinal", "spiritual", "material", "trade", "indicator"];
|
|
617
|
+
|
|
618
|
+
hortis.hulqValueItem = "<div class=\"fl-imerss-cultural-value\"><div role=\"img\" class=\"fld-imerss-value-%img fl-imerss-cultural-value-img\"></div><div class=\"fld-imerss-cultural-value-text\">%label</div></div>";
|
|
619
|
+
|
|
620
|
+
hortis.hulqValueBlock = "<div class=\"fl-imerss-cultural-values\">%valueBlocks</div>";
|
|
621
|
+
|
|
622
|
+
hortis.dumpHulqName = function (row, markup) {
|
|
623
|
+
const player = row.audioLink ? fluid.stringTemplate(hortis.drivePlayer, {
|
|
624
|
+
url: hortis.driveToPreview(row.audioLink)
|
|
625
|
+
}) : "";
|
|
626
|
+
const nameRow = hortis.dumpRow("Hul'qumi'num name", row.hulqName + player, markup);
|
|
627
|
+
return nameRow;
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
hortis.dumpHulqValues = function (row, markup) {
|
|
631
|
+
const valueBlocks = hortis.hulqValues.map(function (value) {
|
|
632
|
+
return row[value + "Value"] === "1" ? value : "missing";
|
|
633
|
+
}).map(function (img, index) {
|
|
634
|
+
return fluid.stringTemplate(hortis.hulqValueItem, {
|
|
635
|
+
img: img,
|
|
636
|
+
label: hortis.hulqValues[index]
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
const valueBlock = fluid.stringTemplate(hortis.hulqValueBlock, {
|
|
640
|
+
valueBlocks: valueBlocks.join("\n")
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
const valueRow1 = hortis.dumpRow("Cultural values", " ", markup, "fl-taxonDisplay-empty-header");
|
|
644
|
+
const valueRow2 = hortis.dumpRow("", valueBlock, markup, "fl-taxonDisplay-empty-row");
|
|
645
|
+
return valueRow1 + valueRow2;
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
hortis.iNatExtern = "<a href=\"%iNatLink\" target=\"_blank\" class=\"fl-taxonDisplay-iNat-extern\">iNaturalist<span class=\"fl-external-link\"></span></a>";
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
hortis.imageTemplate =
|
|
653
|
+
"<div class=\"fl-taxonDisplay-image-holder\">" +
|
|
654
|
+
"<div class=\"fl-imerss-photo\" style=\"background-image: url(%imgUrl)\"/>" +
|
|
655
|
+
"%iNatExtern" +
|
|
656
|
+
"</div></div>";
|
|
657
|
+
|
|
658
|
+
hortis.idToTaxonLink = function (taxonId) {
|
|
659
|
+
return "https://www.inaturalist.org/taxa/" + taxonId;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
hortis.renderTaxonDisplay = function (row, markup, options) {
|
|
663
|
+
if (!row) {
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
666
|
+
let togo = markup.taxonDisplayHeader;
|
|
667
|
+
const dumpRow = function (keyName, value, extraClazz, options) {
|
|
668
|
+
if (keyName === "wikipediaSummary" && value) {
|
|
669
|
+
const row1 = hortis.dumpRow("Wikipedia Summary", hortis.expandButtonMarkup, markup, "fld-taxonDisplay-expandable-header fl-taxonDisplay-runon-header");
|
|
670
|
+
const row2 = hortis.dumpRow("", value, markup, "fld-taxonDisplay-expandable-remainder fl-taxonDisplay-runon-remainder", "fl-taxonDisplay-wikipediaSummary");
|
|
671
|
+
togo += row1 + row2;
|
|
672
|
+
} else {
|
|
673
|
+
togo += hortis.dumpRow(keyName, value, markup, extraClazz, undefined, options);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
const dumpImage = function (keyName, url, taxonId) {
|
|
677
|
+
const imageMarkup = fluid.stringTemplate(hortis.imageTemplate, {
|
|
678
|
+
imgUrl: url,
|
|
679
|
+
iNatExtern: taxonId ? fluid.stringTemplate(hortis.iNatExtern, {
|
|
680
|
+
iNatLink: hortis.idToTaxonLink(taxonId)
|
|
681
|
+
}) : ""
|
|
682
|
+
});
|
|
683
|
+
// TODO: key name is currently ignored - other types of images, e.g. phylopics, and obs images, can't be distinguished
|
|
684
|
+
togo += imageMarkup;
|
|
685
|
+
};
|
|
686
|
+
const dumpPhyloPic = function (keyName, url) {
|
|
687
|
+
togo += hortis.dumpRow(keyName, "<div><img alt=\"Taxon photo\" height=\"150\" width=\"150\" class=\"fl-imerss-photo\" src=\"" + url + "\"/></div>", markup);
|
|
688
|
+
};
|
|
689
|
+
if (row.rank) {
|
|
690
|
+
if (row.iNaturalistTaxonImage && !row.taxonPic) {
|
|
691
|
+
dumpImage("iNaturalistTaxonImage", row.iNaturalistTaxonImage, row.iNaturalistTaxonId);
|
|
692
|
+
} else if (row.taxonPic) {
|
|
693
|
+
dumpImage("taxonPic", row.taxonPic);
|
|
694
|
+
}
|
|
695
|
+
if (row.phyloPicUrl) {
|
|
696
|
+
dumpPhyloPic("phyloPic", row.phyloPicUrl);
|
|
697
|
+
}
|
|
698
|
+
dumpRow(row.rank, row.iNaturalistTaxonName, "fl-taxonDisplay-rank");
|
|
699
|
+
hortis.commonFields.forEach(function (field) {
|
|
700
|
+
dumpRow(field, row[field]);
|
|
701
|
+
});
|
|
702
|
+
dumpRow("taxonPicDescription", row.taxonPicDescription);
|
|
703
|
+
dumpRow("Species:", row.childCount);
|
|
704
|
+
dumpRow("observationCount", row.observationCount);
|
|
705
|
+
} else {
|
|
706
|
+
if (row.iNaturalistTaxonImage && !row.obsPhotoLink) {
|
|
707
|
+
dumpImage("iNaturalistTaxonImage", row.iNaturalistTaxonImage, row.iNaturalistTaxonId);
|
|
708
|
+
}
|
|
709
|
+
if (row.species) {
|
|
710
|
+
// Used to read:
|
|
711
|
+
// dumpRow("Species:", row.species + (row.authority ? (" " + row.authority) : ""), "fl-taxonDisplay-rank");
|
|
712
|
+
// "species" now just holdes raw species name. In the long term we should support our own normalised species name
|
|
713
|
+
// composed of taxon and infrataxon name but this is at least now complete and agrees with what is shown in the tooltip
|
|
714
|
+
dumpRow("iNaturalistTaxonName", row.iNaturalistTaxonName + (row.authority ? (" " + row.authority) : ""), "fl-taxonDisplay-rank", options);
|
|
715
|
+
}
|
|
716
|
+
if (row.hulqName) { // wot no polymorphism?
|
|
717
|
+
togo += hortis.dumpHulqName(row, markup);
|
|
718
|
+
}
|
|
719
|
+
dumpRow("commonName", row.commonName);
|
|
720
|
+
|
|
721
|
+
if (row.hulqName && options.culturalValues) { // wot no polymorphism?
|
|
722
|
+
togo += hortis.dumpHulqValues(row, markup);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
dumpRow("wikipediaSummary", row.wikipediaSummary);
|
|
726
|
+
let obsPanel = "";
|
|
727
|
+
|
|
728
|
+
obsPanel += hortis.renderObsBound(row, "first", markup, options);
|
|
729
|
+
obsPanel += hortis.renderObsBound(row, "last", markup, options);
|
|
730
|
+
obsPanel += hortis.renderObsBound(row, "since", markup, options);
|
|
731
|
+
|
|
732
|
+
if (row.iNaturalistObsLink) {
|
|
733
|
+
obsPanel += hortis.dumpRow("iNaturalistObsLink", "<a href=\"" + row.iNaturalistObsLink + "\">" + row.iNaturalistObsLink + "</a>", markup);
|
|
734
|
+
}
|
|
735
|
+
obsPanel += hortis.dumpRow("observationCount", row.observationCount, markup);
|
|
736
|
+
togo += hortis.dumpRow("Observation Data", hortis.expandButtonMarkup, markup, "fld-taxonDisplay-expandable-header");
|
|
737
|
+
togo += hortis.dumpRow("", obsPanel, markup, "fld-taxonDisplay-expandable-remainder fl-taxonDisplay-runon-remainder");
|
|
738
|
+
|
|
739
|
+
if (row.obsPhotoLink) {
|
|
740
|
+
// See this nonsense: https://stackoverflow.com/questions/5843035/does-before-not-work-on-img-elements
|
|
741
|
+
dumpImage("Observation photo", row.obsPhotoLink);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/** Axed per AS email 16/10/21
|
|
745
|
+
var iNatId = row.iNaturalistTaxonId;
|
|
746
|
+
if (iNatId) {
|
|
747
|
+
var taxonLink = "http://www.inaturalist.org/taxa/" + iNatId;
|
|
748
|
+
dumpRow("taxonLink", "<a href=\"" + taxonLink + "\">" + taxonLink + "</a>");
|
|
749
|
+
}*/
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
togo += markup.taxonDisplayFooter;
|
|
753
|
+
return togo;
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
hortis.bindRowExpander = function () {
|
|
757
|
+
$(document).on("click", ".fl-taxonDisplay-expand", function (e) {
|
|
758
|
+
const target = $(e.target);
|
|
759
|
+
target.toggleClass("fl-taxonDisplay-expanded");
|
|
760
|
+
target.toggleClass("fl-taxonDisplay-unexpanded");
|
|
761
|
+
const showing = target.hasClass("fl-taxonDisplay-expanded");
|
|
762
|
+
const header = target.closest(".fld-taxonDisplay-expandable-header");
|
|
763
|
+
header.toggleClass("fl-taxonDisplay-expanded", showing);
|
|
764
|
+
const siblings = header.parent().children();
|
|
765
|
+
const ownIndex = header.index();
|
|
766
|
+
const next = $(siblings[ownIndex + 1]);
|
|
767
|
+
if (next.hasClass("fld-taxonDisplay-expandable-remainder")) { // sanity check, we should not render ones without this
|
|
768
|
+
next[showing ? "show" : "hide"]();
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
};
|
|
772
|
+
|
|
773
|
+
hortis.updateTaxonDisplay = function (that, id) {
|
|
774
|
+
const content = id ? hortis.renderTaxonDisplay(that.index[id], that.options.markup, that.options) : null;
|
|
775
|
+
const taxonDisplay = that.locate("taxonDisplay");
|
|
776
|
+
if (content) {
|
|
777
|
+
taxonDisplay.empty();
|
|
778
|
+
taxonDisplay.html(content);
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
hortis.tooltipTemplate = "<div class=\"fl-imerss-tooltip\">" +
|
|
783
|
+
"<div class=\"fl-imerss-photo\" style=\"background-image: url(%imgUrl)\"></div>" +
|
|
784
|
+
"<div class=\"fl-text\"><b>%taxonRank:</b> %taxonNames</div>" +
|
|
785
|
+
"</div>";
|
|
786
|
+
|
|
787
|
+
hortis.renderTooltip = function (row) {
|
|
788
|
+
const terms = {
|
|
789
|
+
imgUrl: row.iNaturalistTaxonImage || ""
|
|
790
|
+
};
|
|
791
|
+
if (row.rank) {
|
|
792
|
+
terms.taxonRank = hortis.capitalize(row.rank);
|
|
793
|
+
} else {
|
|
794
|
+
terms.taxonRank = "Species";
|
|
795
|
+
}
|
|
796
|
+
const names = [row.iNaturalistTaxonName, row.commonName, row.hulqName].filter(name => name);
|
|
797
|
+
terms.taxonNames = names.join(" / ");
|
|
798
|
+
return fluid.stringTemplate(hortis.tooltipTemplate, terms);
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
// Lifted from Infusion Tooltip.js
|
|
803
|
+
hortis.isInDocument = function (node) {
|
|
804
|
+
const dokkument = fluid.getDocument(node),
|
|
805
|
+
container = node[0];
|
|
806
|
+
// jQuery UI framework will throw a fit if we have instantiated a widget on a DOM element and then
|
|
807
|
+
// removed it from the DOM. This apparently can't be detected via the jQuery UI API itself.
|
|
808
|
+
return $.contains(dokkument, container) || dokkument === container;
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
hortis.clearAllTooltips = function (that) {
|
|
812
|
+
hortis.clearTooltip(that);
|
|
813
|
+
$(".ui-tooltip").remove();
|
|
814
|
+
that.applier.change("hoverId", null);
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
hortis.clearTooltip = function (that) {
|
|
818
|
+
const tooltipTarget = that.tooltipTarget;
|
|
819
|
+
if (tooltipTarget) {
|
|
820
|
+
that.tooltipTarget = null;
|
|
821
|
+
if (hortis.isInDocument(tooltipTarget)) {
|
|
822
|
+
console.log("Cleared tooltip");
|
|
823
|
+
tooltipTarget.tooltip("destroy");
|
|
824
|
+
} else {
|
|
825
|
+
console.log("Tooltip target lost from document");
|
|
826
|
+
hortis.clearAllTooltips(that);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
hortis.updateTooltip = function (that, id) {
|
|
832
|
+
const content = id ? hortis.renderTooltip(that.index[id], that.options.markup) : null;
|
|
833
|
+
const target = $(that.mouseEvent.target);
|
|
834
|
+
|
|
835
|
+
hortis.clearTooltip(that);
|
|
836
|
+
|
|
837
|
+
if (content) {
|
|
838
|
+
console.log("Opening tooltip for node " + id);
|
|
839
|
+
target.tooltip({
|
|
840
|
+
items: target
|
|
841
|
+
});
|
|
842
|
+
target.tooltip("option", "content", content || "");
|
|
843
|
+
target.tooltip("option", "track", true);
|
|
844
|
+
target.tooltip("open", that.mouseEvent);
|
|
845
|
+
that.tooltipTarget = target;
|
|
846
|
+
} else {
|
|
847
|
+
that.mouseEvent = null;
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
hortis.isAtRoot = function (that, layoutId) {
|
|
852
|
+
return layoutId === that.flatTree[0].id;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
hortis.bindSunburstMouse = function (that) {
|
|
856
|
+
const svg = that.locate("svg");
|
|
857
|
+
// var mousable = that.options.selectors.mousable;
|
|
858
|
+
const mousable = that.getMousable();
|
|
859
|
+
svg.on("click", mousable, function () {
|
|
860
|
+
const id = hortis.elementToId(this);
|
|
861
|
+
let row = that.index[id];
|
|
862
|
+
if (!hortis.isAboveLayoutRoot(row, that) && that.index[id].phyloPicUrl) {
|
|
863
|
+
row = that.flatTree[0];
|
|
864
|
+
}
|
|
865
|
+
that.segmentClicked(row);
|
|
866
|
+
});
|
|
867
|
+
svg.on("mouseenter", mousable, function (e) {
|
|
868
|
+
const id = hortis.elementToId(this);
|
|
869
|
+
that.mouseEvent = e;
|
|
870
|
+
that.applier.change("hoverId", id);
|
|
871
|
+
});
|
|
872
|
+
svg.on("mouseleave", mousable, function () {
|
|
873
|
+
that.applier.change("hoverId", null);
|
|
874
|
+
});
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
hortis.parseColours = function (colours) {
|
|
878
|
+
return fluid.transform(colours, function (colour) {
|
|
879
|
+
return fluid.colour.hexToArray(colour);
|
|
880
|
+
});
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
hortis.angleScale = function (index, scale) {
|
|
885
|
+
const angle = 2 * Math.PI * (index - scale.left) / (scale.right - scale.left);
|
|
886
|
+
return fluid.transforms.limitRange(angle, {min: 0, max: 2 * Math.PI});
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
hortis.outRings = function (array, count, width) {
|
|
890
|
+
let lastRing = array[array.length - 1];
|
|
891
|
+
for (let i = 0; i < count; ++i) {
|
|
892
|
+
lastRing += width;
|
|
893
|
+
array.push(lastRing);
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
|
|
897
|
+
hortis.makeRadiusScale = function (innerRings, visRings, totalRings, scaleConfig, isAtRoot) {
|
|
898
|
+
console.log("makeRadiusScale with innerRings ", innerRings, " visRings ", visRings);
|
|
899
|
+
const togo = [0];
|
|
900
|
+
if (isAtRoot && scaleConfig.rootRadii) {
|
|
901
|
+
scaleConfig.rootRadii.forEach(function (radius) {
|
|
902
|
+
hortis.outRings(togo, 1, 1000 * radius);
|
|
903
|
+
});
|
|
904
|
+
hortis.outRings(togo, 1 + totalRings - togo.length, 0);
|
|
905
|
+
} else {
|
|
906
|
+
// Allocate as many outerRings as we can without making in between rings narrower than innerDepth
|
|
907
|
+
// Total amount available is 1 - innerRadius, in between thickness would be (1 - outerRings * options.outerDepth - innerRadius) / (totalRings - outerRings - innerRings);
|
|
908
|
+
const outerRings = Math.floor((1 - visRings * scaleConfig.innerDepth) / (scaleConfig.outerDepth - scaleConfig.innerDepth));
|
|
909
|
+
console.log("outerRings determined as ", outerRings);
|
|
910
|
+
const middleRings = visRings - outerRings - innerRings;
|
|
911
|
+
const middleDepth = (1 - outerRings * scaleConfig.outerDepth - innerRings * scaleConfig.innerDepth) / middleRings;
|
|
912
|
+
|
|
913
|
+
hortis.outRings(togo, innerRings, 1000 * scaleConfig.innerDepth);
|
|
914
|
+
hortis.outRings(togo, middleRings, 1000 * middleDepth);
|
|
915
|
+
hortis.outRings(togo, outerRings, 1000 * scaleConfig.outerDepth);
|
|
916
|
+
hortis.outRings(togo, totalRings - visRings, 0);
|
|
917
|
+
}
|
|
918
|
+
console.log("makeRadiusScale returning ", togo);
|
|
919
|
+
return togo;
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
hortis.boundNodes = function (that, layoutId, isInit) {
|
|
923
|
+
console.log("boundNodes beginning for node ", layoutId);
|
|
924
|
+
const layoutRoot = that.index[layoutId],
|
|
925
|
+
visMap = [];
|
|
926
|
+
for (let i = 0; i < that.flatTree.length; ++i) {
|
|
927
|
+
visMap[i] = 0;
|
|
928
|
+
}
|
|
929
|
+
for (let visUp = layoutRoot; visUp; visUp = visUp.parent) {
|
|
930
|
+
visMap[visUp.flatIndex] = 1;
|
|
931
|
+
}
|
|
932
|
+
let totalNodes = 1, parents = [layoutRoot], depth;
|
|
933
|
+
for (depth = layoutRoot.depth; depth < that.maxDepth; ++depth) {
|
|
934
|
+
let directChildren = 0;
|
|
935
|
+
parents.forEach(function (parent) {
|
|
936
|
+
directChildren += parent.children.length;
|
|
937
|
+
});
|
|
938
|
+
if (directChildren > 0 && totalNodes + directChildren < that.options.scaleConfig.maxNodes) {
|
|
939
|
+
const newParents = [];
|
|
940
|
+
parents.forEach(function (parent) {
|
|
941
|
+
parent.children.forEach(function (child) {
|
|
942
|
+
visMap[child.flatIndex] = 1;
|
|
943
|
+
});
|
|
944
|
+
newParents.push.apply(newParents, parent.children);
|
|
945
|
+
});
|
|
946
|
+
parents = newParents;
|
|
947
|
+
totalNodes += directChildren;
|
|
948
|
+
} else {
|
|
949
|
+
break;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
const isAtRoot = hortis.isAtRoot(that, layoutId);
|
|
953
|
+
const radiusScale = hortis.makeRadiusScale(layoutRoot.depth, depth + 1, that.maxDepth + 1, that.options.scaleConfig, isAtRoot);
|
|
954
|
+
const togo = {
|
|
955
|
+
visMap: visMap,
|
|
956
|
+
scale: {
|
|
957
|
+
left: layoutRoot.leftIndex,
|
|
958
|
+
right: layoutRoot.leftIndex + layoutRoot.childCount,
|
|
959
|
+
radiusScale: radiusScale
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
console.log("boundNodes returning ", togo);
|
|
963
|
+
if (isInit) {
|
|
964
|
+
that.visMap = visMap;
|
|
965
|
+
that.applier.change("scale", togo.scale);
|
|
966
|
+
}
|
|
967
|
+
return togo;
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
hortis.isClickable = function (row) {
|
|
971
|
+
return row.children.length > 0 || row.iNaturalistLink || row.iNaturalistTaxonId;
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
hortis.elementClass = function (row, isSelected, styles, baseStyle) {
|
|
975
|
+
return styles[baseStyle]
|
|
976
|
+
+ (hortis.isClickable(row) ? " " + styles.clickable : "")
|
|
977
|
+
+ (isSelected ? " " + styles.layoutRoot : "");
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
hortis.elementStyle = function (attrs, elementType) {
|
|
981
|
+
const opacity = attrs.opacity === undefined ? "" : " opacity: " + attrs.opacity + ";";
|
|
982
|
+
return elementType === "segment" ? "fill: " + attrs.fillColour + ";" + opacity : opacity;
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
hortis.phyloPicAttrMap = {
|
|
986
|
+
visibility: "visibility",
|
|
987
|
+
x: "phyloPicX",
|
|
988
|
+
y: "phyloPicY",
|
|
989
|
+
height: "diameter",
|
|
990
|
+
width: "diameter"
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
hortis.renderLight = function (that) {
|
|
994
|
+
that.flatTree.forEach(function (row, index) {
|
|
995
|
+
if (that.visMap[index] || that.oldVisMap && that.oldVisMap[index]) {
|
|
996
|
+
const attrs = hortis.attrsForRow(that, row);
|
|
997
|
+
attrs.fillColour = that.fillColourForRow(row);
|
|
998
|
+
const isSelected = row.id === that.model.selectedId;
|
|
999
|
+
const segment = fluid.byId("hortis-segment:" + row.id);
|
|
1000
|
+
if (segment) {
|
|
1001
|
+
segment.setAttribute("d", attrs.path);
|
|
1002
|
+
segment.setAttribute("visibility", attrs.visibility);
|
|
1003
|
+
segment.setAttribute("class", hortis.elementClass(row, isSelected, that.options.styles, "segment"));
|
|
1004
|
+
segment.setAttribute("style", hortis.elementStyle(attrs, "segment"));
|
|
1005
|
+
}
|
|
1006
|
+
const labelPath = fluid.byId("hortis-labelPath:" + row.id);
|
|
1007
|
+
if (labelPath) {
|
|
1008
|
+
labelPath.setAttribute("d", attrs.textPath);
|
|
1009
|
+
labelPath.setAttribute("visibility", attrs.labelVisibility);
|
|
1010
|
+
}
|
|
1011
|
+
const label = fluid.byId("hortis-label:" + row.id);
|
|
1012
|
+
if (label) {
|
|
1013
|
+
label.setAttribute("visibility", attrs.labelVisibility);
|
|
1014
|
+
label.setAttribute("class", hortis.elementClass(row, isSelected, that.options.styles, "label"));
|
|
1015
|
+
label.setAttribute("style", hortis.elementStyle(attrs, "label"));
|
|
1016
|
+
}
|
|
1017
|
+
const pic = fluid.byId("hortis-phyloPic:" + row.id);
|
|
1018
|
+
if (pic) {
|
|
1019
|
+
fluid.each(hortis.phyloPicAttrMap, function (source, target) {
|
|
1020
|
+
pic.setAttribute(target, attrs[source]);
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
};
|
|
1026
|
+
|
|
1027
|
+
hortis.renderSVGTemplate = function (template, terms) {
|
|
1028
|
+
return fluid.stringTemplate(template, terms);
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
hortis.interpolateModels = function (f, m1, m2) {
|
|
1033
|
+
return fluid.transform(m1, function (value, key) {
|
|
1034
|
+
if (typeof(value) === "number") {
|
|
1035
|
+
return (1 - f) * value + f * m2[key];
|
|
1036
|
+
} else if (fluid.isPlainObject(value)) {
|
|
1037
|
+
return hortis.interpolateModels(f, value, m2[key]);
|
|
1038
|
+
} else {
|
|
1039
|
+
return value;
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
hortis.undocColourForRow = function (parsedColours, row) {
|
|
1045
|
+
const undocFraction = 1 - row.undocumentedCount / row.childCount;
|
|
1046
|
+
const interp = fluid.colour.interpolate(undocFraction, row.highColour || parsedColours.highColour, row.lowColour || parsedColours.lowColour);
|
|
1047
|
+
return fluid.colour.arrayToString(interp);
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1050
|
+
hortis.obsColourForRow = function (parsedColours, row, rootRow) {
|
|
1051
|
+
const fraction = Math.pow(row.observationCount / rootRow.observationCount, 0.2);
|
|
1052
|
+
const interp = fluid.colour.interpolate(fraction, row.lowColour || parsedColours.lowColour, row.highColour || parsedColours.highColour);
|
|
1053
|
+
const focusProp = row.focusCount / row.childCount;
|
|
1054
|
+
const interp2 = fluid.colour.interpolate(focusProp, parsedColours.unfocusedColour, interp);
|
|
1055
|
+
return fluid.colour.arrayToString(interp2);
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1058
|
+
hortis.pathFromRoot = function (row) {
|
|
1059
|
+
const togo = [];
|
|
1060
|
+
while (row) {
|
|
1061
|
+
togo.unshift(row);
|
|
1062
|
+
row = row.parent;
|
|
1063
|
+
}
|
|
1064
|
+
return togo;
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1067
|
+
hortis.lcaRoot = function (parents) {
|
|
1068
|
+
let lcaRoot;
|
|
1069
|
+
for (let i = 0; ; ++i) {
|
|
1070
|
+
let commonValue = null;
|
|
1071
|
+
for (const key in parents) {
|
|
1072
|
+
const seg = parents[key][i];
|
|
1073
|
+
if (seg === undefined) {
|
|
1074
|
+
commonValue = null;
|
|
1075
|
+
break;
|
|
1076
|
+
} else if (commonValue === null) {
|
|
1077
|
+
commonValue = seg;
|
|
1078
|
+
} else if (commonValue !== seg) {
|
|
1079
|
+
commonValue = null;
|
|
1080
|
+
break;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
if (commonValue === null) {
|
|
1084
|
+
break;
|
|
1085
|
+
} else {
|
|
1086
|
+
lcaRoot = commonValue;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
return lcaRoot;
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1092
|
+
hortis.updateRowFocus = function (that, rowFocus, transaction) {
|
|
1093
|
+
const flatTree = that.flatTree;
|
|
1094
|
+
const focusAll = $.isEmptyObject(rowFocus);
|
|
1095
|
+
for (let i = flatTree.length - 1; i >= 0; --i) {
|
|
1096
|
+
const row = flatTree[i];
|
|
1097
|
+
let focusCount;
|
|
1098
|
+
if (focusAll || rowFocus[row.id]) {
|
|
1099
|
+
focusCount = row.childCount;
|
|
1100
|
+
} else {
|
|
1101
|
+
focusCount = row.children.reduce(function (sum, child) {
|
|
1102
|
+
return sum + child.focusCount;
|
|
1103
|
+
}, 0);
|
|
1104
|
+
}
|
|
1105
|
+
row.focusCount = focusCount;
|
|
1106
|
+
}
|
|
1107
|
+
let target;
|
|
1108
|
+
if (focusAll) {
|
|
1109
|
+
target = flatTree[0];
|
|
1110
|
+
} else {
|
|
1111
|
+
const parents = fluid.transform(rowFocus, function (troo, key) {
|
|
1112
|
+
return hortis.pathFromRoot(that.index[key]);
|
|
1113
|
+
});
|
|
1114
|
+
const lca = hortis.lcaRoot(parents);
|
|
1115
|
+
target = Object.keys(parents).length === 1 ? lca.parent : lca;
|
|
1116
|
+
}
|
|
1117
|
+
if (target.leftIndex !== undefined) { // Avoid trying to render before onCreate
|
|
1118
|
+
// We signal this to regions - need to avoid mutual action of resetting map and taxa, and we assume that
|
|
1119
|
+
// map is the only source of updateRowFocus
|
|
1120
|
+
// TODO: Used to read || !focusAll - try to recall why, perhaps wrt. Xetthecum
|
|
1121
|
+
if (!transaction.fullSources.map || !focusAll) {
|
|
1122
|
+
that.events.changeLayoutId.fire(target.id, "rowFocus");
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
hortis.elementToId = function (element) {
|
|
1128
|
+
const id = element.id;
|
|
1129
|
+
return id.substring(id.indexOf(":") + 1);
|
|
1130
|
+
};
|
|
1131
|
+
|
|
1132
|
+
hortis.elementToRow = function (that, element) {
|
|
1133
|
+
const id = hortis.elementToId(element);
|
|
1134
|
+
return that.index[id];
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
hortis.backTaxon = function (that) {
|
|
1138
|
+
if (that.model.historyIndex > 1) {
|
|
1139
|
+
that.applier.change("historyIndex", that.model.historyIndex - 1);
|
|
1140
|
+
that.events.changeLayoutId.fire(that.taxonHistory[that.model.historyIndex - 1], "history");
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
|
|
1144
|
+
hortis.changeLayoutId = function (that, layoutId, source) {
|
|
1145
|
+
console.log("changeLayoutId to layoutId ", layoutId);
|
|
1146
|
+
that.applier.change("selectedId", layoutId);
|
|
1147
|
+
if (source !== "history") {
|
|
1148
|
+
that.taxonHistory[that.model.historyIndex] = layoutId;
|
|
1149
|
+
that.applier.change("historyIndex", that.model.historyIndex + 1);
|
|
1150
|
+
}
|
|
1151
|
+
const row = that.index[layoutId];
|
|
1152
|
+
if (row.children.length === 0) {
|
|
1153
|
+
// Don't change layout parent if the taxon selected by direct manipulation
|
|
1154
|
+
layoutId = source === "autocomplete" ? row.parent.id : that.model.layoutId;
|
|
1155
|
+
}
|
|
1156
|
+
if (layoutId !== that.model.layoutId || source) {
|
|
1157
|
+
if (!that.model.layoutId) { // Can't render without some initial valid layout
|
|
1158
|
+
that.applier.change("layoutId", layoutId);
|
|
1159
|
+
} else {
|
|
1160
|
+
return hortis.beginZoom(that, layoutId);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
return fluid.promise().resolve();
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
// TODO: Consider whether we should always update layoutId at the start of the interaction in case there's any
|
|
1167
|
+
// collateral state that depends on this. Note that we defeat async interaction when sunburst is not visible
|
|
1168
|
+
hortis.beginZoom = function (that, rowId) {
|
|
1169
|
+
that.container.stop(true, true);
|
|
1170
|
+
hortis.clearAllTooltips(that);
|
|
1171
|
+
const initialScale = fluid.copy(that.model.scale);
|
|
1172
|
+
const newBound = hortis.boundNodes(that, rowId);
|
|
1173
|
+
newBound.scale.zoomProgress = 1;
|
|
1174
|
+
console.log("Begin zoom to rowId " + rowId);
|
|
1175
|
+
const togo = fluid.promise();
|
|
1176
|
+
that.oldVisMap = that.visMap;
|
|
1177
|
+
that.visMap = newBound.visMap;
|
|
1178
|
+
that.render();
|
|
1179
|
+
that.container.animate({"zoomProgress": 1}, {
|
|
1180
|
+
easing: "swing",
|
|
1181
|
+
duration: that.model.visible ? that.options.zoomDuration : 0,
|
|
1182
|
+
step: function (zoomProgress) {
|
|
1183
|
+
const interpScale = hortis.interpolateModels(zoomProgress, initialScale, newBound.scale);
|
|
1184
|
+
that.applier.change("scale", interpScale);
|
|
1185
|
+
},
|
|
1186
|
+
complete: function () {
|
|
1187
|
+
console.log("Zoom complete");
|
|
1188
|
+
delete that.oldVisMap;
|
|
1189
|
+
that.container[0].zoomProgress = 0;
|
|
1190
|
+
that.applier.change("layoutId", rowId);
|
|
1191
|
+
that.applier.change("scale.zoomProgress", 0); // TODO: suppress render here
|
|
1192
|
+
that.render();
|
|
1193
|
+
togo.resolve();
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
return togo;
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
hortis.segmentClicked = function (that, row) {
|
|
1200
|
+
that.events.changeLayoutId.fire(row.id);
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
hortis.nameOverrides = {
|
|
1204
|
+
"Chromista": "Chromists"
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
hortis.labelForRow = function (row, commonNames) {
|
|
1208
|
+
let name = commonNames && row.commonName ? row.commonName : row.iNaturalistTaxonName;
|
|
1209
|
+
if (row.hulqName) {
|
|
1210
|
+
name += " - " + row.hulqName;
|
|
1211
|
+
}
|
|
1212
|
+
name = hortis.nameOverrides[row.iNaturalistTaxonName] || name;
|
|
1213
|
+
return hortis.capitalize(name);
|
|
1214
|
+
// return row.rank ? (row.rank === "Life" ? "Life" : row.rank + ": " + name) : name;
|
|
1215
|
+
};
|
|
1216
|
+
|
|
1217
|
+
// Returns true if the supplied row is either at the layout root or above it. Alternatively - can we get to the
|
|
1218
|
+
// global root from the layout root without hitting this row - if so it is not "shadowing" us (and hence its phylopic
|
|
1219
|
+
// should not go to the centre)
|
|
1220
|
+
hortis.isAboveLayoutRoot = function (row, that) {
|
|
1221
|
+
const layoutId = that.model.layoutId;
|
|
1222
|
+
let layoutRow = that.index[layoutId];
|
|
1223
|
+
while (layoutRow) {
|
|
1224
|
+
if (layoutRow.id === row.id) {
|
|
1225
|
+
return false;
|
|
1226
|
+
}
|
|
1227
|
+
layoutRow = layoutRow.parent;
|
|
1228
|
+
}
|
|
1229
|
+
return true;
|
|
1230
|
+
};
|
|
1231
|
+
|
|
1232
|
+
// This guide is a great one for "bestiary of reuse failures": https://www.visualcinnamon.com/2015/09/placing-text-on-arcs.html
|
|
1233
|
+
// What the chaining method reduces one to who is unable to allocate any intermediate variables
|
|
1234
|
+
|
|
1235
|
+
hortis.attrsForRow = function (that, row) {
|
|
1236
|
+
let leftAngle = that.angleScale(row.leftIndex),
|
|
1237
|
+
rightAngle = that.angleScale(row.leftIndex + row.childCount),
|
|
1238
|
+
midAngle = (leftAngle + rightAngle) / 2,
|
|
1239
|
+
innerRadius = that.model.scale.radiusScale[row.depth],
|
|
1240
|
+
outerRadius = that.model.scale.radiusScale[row.depth + 1];
|
|
1241
|
+
const isAboveLayoutRoot = hortis.isAboveLayoutRoot(row, that);
|
|
1242
|
+
const isComplete = fluid.model.isSameValue(leftAngle, 0) && fluid.model.isSameValue(rightAngle, 2 * Math.PI);
|
|
1243
|
+
const isCircle = fluid.model.isSameValue(innerRadius, 0) && isComplete;
|
|
1244
|
+
const isVisible = !fluid.model.isSameValue(leftAngle, rightAngle) && !fluid.model.isSameValue(innerRadius, outerRadius);
|
|
1245
|
+
const isOuterSegment = fluid.model.isSameValue(outerRadius - innerRadius, that.options.scaleConfig.outerDepth * 1000);
|
|
1246
|
+
const label = hortis.labelForRow(row, that.model.commonNames);
|
|
1247
|
+
const outerLength = outerRadius * (rightAngle - leftAngle);
|
|
1248
|
+
// Note that only purpose of midRadius is to position phylopic
|
|
1249
|
+
const midRadius = (isCircle || !isAboveLayoutRoot) ? 0 : (innerRadius + outerRadius) / 2;
|
|
1250
|
+
const radius = outerRadius - midRadius;
|
|
1251
|
+
if (fluid.model.isSameValue(leftAngle, Math.PI)) {
|
|
1252
|
+
// Eliminate Chrome crash bug exhibited in https://amb26.github.io/svg-failure/ but apparently only on Windows 7!
|
|
1253
|
+
// Note that 1e-5 will be too small!
|
|
1254
|
+
leftAngle += 1e-4;
|
|
1255
|
+
}
|
|
1256
|
+
const labelVisibility = isOuterSegment ? outerLength > 45 : outerLength > label.length * 22; // TODO: make a guess of this factor from font size (e.g. 2/3 of it)
|
|
1257
|
+
const togo = {
|
|
1258
|
+
visibility: isVisible ? "visible" : "hidden",
|
|
1259
|
+
labelVisibility: isVisible && labelVisibility ? "visible" : "hidden",
|
|
1260
|
+
label: hortis.encodeHTML(label),
|
|
1261
|
+
phyloPicX: Math.cos(midAngle) * midRadius - radius,
|
|
1262
|
+
phyloPicY: -Math.sin(midAngle) * midRadius - radius,
|
|
1263
|
+
phyloPicUrl: row.phyloPicUrl,
|
|
1264
|
+
diameter: 2 * radius
|
|
1265
|
+
};
|
|
1266
|
+
if (isComplete) {
|
|
1267
|
+
togo.textPath = hortis.circularTextPath(outerRadius);
|
|
1268
|
+
if (isCircle) {
|
|
1269
|
+
togo.path = hortis.circularPath(outerRadius);
|
|
1270
|
+
} else {
|
|
1271
|
+
togo.path = hortis.annularPath(innerRadius, outerRadius);
|
|
1272
|
+
}
|
|
1273
|
+
} else {
|
|
1274
|
+
togo.textPath = isOuterSegment ? hortis.linearTextPath(leftAngle, rightAngle, innerRadius, outerRadius) : hortis.segmentTextPath(leftAngle, rightAngle, outerRadius);
|
|
1275
|
+
togo.path = hortis.segmentPath(leftAngle, rightAngle, innerRadius, outerRadius);
|
|
1276
|
+
}
|
|
1277
|
+
if (that.oldVisMap) {
|
|
1278
|
+
const index = row.flatIndex;
|
|
1279
|
+
if (!that.oldVisMap[index] && that.visMap[index]) {
|
|
1280
|
+
togo.opacity = that.model.scale.zoomProgress;
|
|
1281
|
+
} else if (that.oldVisMap[index] && !that.visMap[index]) {
|
|
1282
|
+
togo.opacity = 1 - that.model.scale.zoomProgress;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return togo;
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
hortis.renderSegment = function (that, row) {
|
|
1289
|
+
const isSelected = row.id === that.model.selectedId;
|
|
1290
|
+
const terms = $.extend({
|
|
1291
|
+
id: "hortis-segment:" + row.id,
|
|
1292
|
+
labelPathId: "hortis-labelPath:" + row.id,
|
|
1293
|
+
labelId: "hortis-label:" + row.id,
|
|
1294
|
+
phyloPicId: "hortis-phyloPic:" + row.id,
|
|
1295
|
+
clazz: hortis.elementClass(row, isSelected, that.options.styles, "segment"),
|
|
1296
|
+
labelPathClass: that.options.styles.labelPath,
|
|
1297
|
+
phyloPicClass: that.options.styles.phyloPic,
|
|
1298
|
+
labelClass: hortis.elementClass(row, isSelected, that.options.styles, "label"),
|
|
1299
|
+
fillColour: that.fillColourForRow(row)
|
|
1300
|
+
}, hortis.attrsForRow(that, row));
|
|
1301
|
+
terms.style = hortis.elementStyle(terms, "segment");
|
|
1302
|
+
terms.labelStyle = hortis.elementStyle(terms, "label");
|
|
1303
|
+
const togo = [{
|
|
1304
|
+
position: 0,
|
|
1305
|
+
markup: hortis.renderSVGTemplate(that.options.markup.segment, terms)
|
|
1306
|
+
}, {
|
|
1307
|
+
position: 2,
|
|
1308
|
+
markup: hortis.renderSVGTemplate(that.options.markup.label, terms)
|
|
1309
|
+
}];
|
|
1310
|
+
if (terms.phyloPicUrl) {
|
|
1311
|
+
togo.push({
|
|
1312
|
+
position: 1,
|
|
1313
|
+
markup: hortis.renderSVGTemplate(that.options.markup.phyloPic, terms)
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
return togo;
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
hortis.elementComparator = function (element1, element2) {
|
|
1320
|
+
return element1.position - element2.position;
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
hortis.render = function (that) {
|
|
1324
|
+
let markup = that.options.markup.segmentHeader;
|
|
1325
|
+
let elements = [];
|
|
1326
|
+
for (let i = 0; i < that.flatTree.length; ++i) {
|
|
1327
|
+
if (that.visMap[i] || that.oldVisMap && that.oldVisMap[i]) {
|
|
1328
|
+
elements = elements.concat(that.renderSegment(that.flatTree[i]));
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
elements.sort(hortis.elementComparator);
|
|
1332
|
+
markup += fluid.getMembers(elements, "markup").join("");
|
|
1333
|
+
markup += that.options.markup.segmentFooter;
|
|
1334
|
+
const container = that.locate("svg");
|
|
1335
|
+
container.empty();
|
|
1336
|
+
hortis.renderSVGElement(markup, container);
|
|
1337
|
+
};
|
|
1338
|
+
|
|
1339
|
+
|
|
1340
|
+
hortis.depthComparator = function (rowa, rowb) {
|
|
1341
|
+
return rowa.depth - rowb.depth;
|
|
1342
|
+
};
|
|
1343
|
+
|
|
1344
|
+
hortis.flattenTree = function (tree) {
|
|
1345
|
+
const flat = [];
|
|
1346
|
+
flat.push(tree);
|
|
1347
|
+
hortis.flattenTreeRecurse(tree, flat);
|
|
1348
|
+
flat.sort(hortis.depthComparator);
|
|
1349
|
+
flat.forEach(function (row, flatIndex) {
|
|
1350
|
+
row.flatIndex = flatIndex;
|
|
1351
|
+
});
|
|
1352
|
+
return flat;
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
hortis.indexTree = function (flatTree) {
|
|
1356
|
+
const index = {};
|
|
1357
|
+
flatTree.forEach(function (row) {
|
|
1358
|
+
index[row.id] = row;
|
|
1359
|
+
});
|
|
1360
|
+
return index;
|
|
1361
|
+
};
|
|
1362
|
+
|
|
1363
|
+
hortis.flattenTreeRecurse = function (tree, toAppend) {
|
|
1364
|
+
tree.children.forEach(function (child) {
|
|
1365
|
+
child.parent = tree;
|
|
1366
|
+
toAppend.push(child);
|
|
1367
|
+
hortis.flattenTreeRecurse(child, toAppend);
|
|
1368
|
+
});
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
hortis.doLayout = function (flatTree) {
|
|
1372
|
+
fluid.each(flatTree, function (node) {
|
|
1373
|
+
if (node.depth === 0) {
|
|
1374
|
+
node.leftIndex = 0;
|
|
1375
|
+
}
|
|
1376
|
+
let thisLeft = node.leftIndex;
|
|
1377
|
+
node.children.forEach(function (child) {
|
|
1378
|
+
child.leftIndex = thisLeft;
|
|
1379
|
+
thisLeft += child.childCount;
|
|
1380
|
+
});
|
|
1381
|
+
});
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1384
|
+
hortis.computeMaxDepth = function (flatTree) {
|
|
1385
|
+
return flatTree[flatTree.length - 1].depth;
|
|
1386
|
+
};
|
|
1387
|
+
|
|
1388
|
+
hortis.doInitialQuery = function (that) {
|
|
1389
|
+
// These used to be different but are now the same since we no longer select taxon on hover. Should be able to axe "selectOnStartup" as disused
|
|
1390
|
+
const toSelect = that.options.queryOnStartup || that.options.selectOnStartup;
|
|
1391
|
+
return toSelect ? that.lookupTaxon(toSelect) : that.flatTree[0];
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
hortis.computeInitialScale = function (that) {
|
|
1395
|
+
const root = hortis.doInitialQuery(that);
|
|
1396
|
+
that.events.changeLayoutId.fire(root.id);
|
|
1397
|
+
};
|