Skip to content

Commit

Permalink
various small improvements
Browse files Browse the repository at this point in the history
i think after this the example is done and work should begin on synospecies proper
  • Loading branch information
nleanba committed Oct 30, 2024
1 parent d9c1d17 commit c1ff9ef
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 48 deletions.
13 changes: 8 additions & 5 deletions SynonymGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class SynonymGroup implements AsyncIterable<Name> {
*/
isFinished = false;
/** Used internally to watch for new names found */
private monitor = new EventTarget();
private monitor: EventTarget = new EventTarget();

/** Used internally to abort in-flight network requests when SynonymGroup is aborted */
private controller = new AbortController();
Expand Down Expand Up @@ -94,9 +94,12 @@ export class SynonymGroup implements AsyncIterable<Name> {
this.startWithSubTaxa = startWithSubTaxa;

if (taxonName.startsWith("http")) {
this.getName(taxonName, { searchTerm: true, subTaxon: false }).finally(
() => this.finish(),
);
this.getName(taxonName, { searchTerm: true, subTaxon: false })
.catch((e) => {
console.log("SynoGroup Failure: ", e);
this.controller.abort("SynoGroup Failed");
})
.finally(() => this.finish());
} else {
const name = [
...taxonName.split(" ").filter((n) => !!n),
Expand Down Expand Up @@ -602,7 +605,7 @@ LIMIT 500`;
cite,
};
} else if (this.expanded.has(t.tc.value)) {
console.log("Skipping known", t.tc.value);
// console.log("Skipping known", t.tc.value);
return;
} else {
authorizedTCNames.push({
Expand Down
20 changes: 8 additions & 12 deletions example/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ syno-name {
margin: 1rem 0;
}

.rank {
.rank,
.justification {
font-size: 0.8rem;
line-height: 1rem;
padding: 0 0.2rem;
Expand Down Expand Up @@ -61,14 +62,6 @@ syno-name {
}
}

.justification {
font-size: 0.8rem;
padding: 0.2rem;
margin: 0.2rem;
border-radius: 0.2rem;
background: #ededed;
}

h2,
h3,
ul {
Expand All @@ -87,13 +80,14 @@ syno-treatment,
}

.details {
display: grid;
/* display: grid; */
}

.hidden {
height: 0;
max-height: 0;
overflow: hidden;
transition: height 1s;
transition: all 200ms;
}

&.expanded {
Expand All @@ -105,7 +99,9 @@ syno-treatment,
margin: -0.2rem;

.hidden {
height: 100%;
height: auto;
max-height: 100px;
overflow: auto;
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@

<body>
<h1>SynoLib</h1>
<p>
Use url parameters to configure: (e.g. <a
href="?q=Sadayoshia&subtaxa=&show_col"
>/?q=Sadayoshia&subtaxa=&show_col</a>)
<ul>
<li>
<code>q=TAXON</code> for the search term (Latin name, CoL-URI,
taxon-name-URI or taxon-concept-URI)
</li>
<li>
<code>show_col=</code> to include many more CoL taxa
</li>
<li>
<code>subtaxa=</code> to include subtaxa of the search term
</li>
<li>
<code>server=URL</code> to configure the sparql endpoint
</li>
</ul>
<br />
Click on a treatment to show all cited taxa. Click on a taxon identifier
beneath a treatment to scroll to that name — if it is (already) in the
list.
</p>

<div id="root"></div>

<script type="module" src="index.js"></script>
Expand Down
91 changes: 60 additions & 31 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,13 @@ class SynoTreatment extends HTMLElement {
}
this.append(date);

const creators = document.createElement("span");
creators.innerText = "…";
this.append(": ", creators);

const title = document.createElement("i");
title.innerText = "…";
this.append(" ", title);
const spinner = document.createElement("progress");
this.append(": ", spinner);

const url = document.createElement("a");
url.classList.add("treatment", "uri");
url.href = trt.url;
url.target = "_blank";
url.innerText = trt.url.replace("http://treatment.plazi.org/id/", "");
url.innerHTML += icons.link;
this.append(" ", url);
Expand All @@ -92,6 +88,10 @@ class SynoTreatment extends HTMLElement {
this.append(names);

trt.details.then((details) => {
const creators = document.createElement("span");
const title = document.createElement("i");
spinner.replaceWith(creators, " ", title);

if (details.creators) creators.innerText = details.creators;
else {
creators.classList.add("missing");
Expand All @@ -115,9 +115,12 @@ class SynoTreatment extends HTMLElement {
names.append(line);

details.treats.def.forEach((n) => {
const url = document.createElement("code");
const url = document.createElement("a");
url.classList.add("taxon", "uri");
url.innerText = n.replace("http://taxon-concept.plazi.org/id/", "");
const short = n.replace("http://taxon-concept.plazi.org/id/", "");
url.innerText = short;
url.href = "#" + short;
url.title = "show name";
line.append(url);
});
}
Expand All @@ -132,15 +135,21 @@ class SynoTreatment extends HTMLElement {
names.append(line);

details.treats.aug.forEach((n) => {
const url = document.createElement("code");
const url = document.createElement("a");
url.classList.add("taxon", "uri");
url.innerText = n.replace("http://taxon-concept.plazi.org/id/", "");
const short = n.replace("http://taxon-concept.plazi.org/id/", "");
url.innerText = short;
url.href = "#" + short;
url.title = "show name";
line.append(url);
});
details.treats.treattn.forEach((n) => {
const url = document.createElement("code");
const url = document.createElement("a");
url.classList.add("taxon", "uri");
url.innerText = n.replace("http://taxon-name.plazi.org/id/", "");
const short = n.replace("http://taxon-name.plazi.org/id/", "");
url.innerText = short;
url.href = "#" + short;
url.title = "show name";
line.append(url);
});
}
Expand All @@ -155,9 +164,12 @@ class SynoTreatment extends HTMLElement {
names.append(line);

details.treats.dpr.forEach((n) => {
const url = document.createElement("code");
const url = document.createElement("a");
url.classList.add("taxon", "uri");
url.innerText = n.replace("http://taxon-concept.plazi.org/id/", "");
const short = n.replace("http://taxon-concept.plazi.org/id/", "");
url.innerText = short;
url.href = "#" + short;
url.title = "show name";
line.append(url);
});
}
Expand All @@ -170,15 +182,21 @@ class SynoTreatment extends HTMLElement {
names.append(line);

details.treats.citetc.forEach((n) => {
const url = document.createElement("code");
const url = document.createElement("a");
url.classList.add("taxon", "uri");
url.innerText = n.replace("http://taxon-concept.plazi.org/id/", "");
const short = n.replace("http://taxon-concept.plazi.org/id/", "");
url.innerText = short;
url.href = "#" + short;
url.title = "show name";
line.append(url);
});
details.treats.citetn.forEach((n) => {
const url = document.createElement("code");
const url = document.createElement("a");
url.classList.add("taxon", "uri");
url.innerText = n.replace("http://taxon-name.plazi.org/id/", "");
const short = n.replace("http://taxon-name.plazi.org/id/", "");
url.innerText = short;
url.href = "#" + short;
url.title = "show name";
line.append(url);
});
}
Expand All @@ -203,13 +221,17 @@ class SynoName extends HTMLElement {
title.append(" ", rank_badge);

if (name.taxonNameURI) {
const name_uri = document.createElement("code");
const name_uri = document.createElement("a");
name_uri.classList.add("taxon", "uri");
name_uri.innerText = name.taxonNameURI.replace(
const short = name.taxonNameURI.replace(
"http://taxon-name.plazi.org/id/",
"",
);
name_uri.title = name.taxonNameURI;
name_uri.innerText = short;
name_uri.id = short;
name_uri.href = name.taxonNameURI;
name_uri.target = "_blank";
name_uri.innerHTML += icons.link;
title.append(" ", name_uri);
}

Expand Down Expand Up @@ -255,26 +277,32 @@ class SynoName extends HTMLElement {
this.append(treatments);

if (authorizedName.taxonConceptURI) {
const name_uri = document.createElement("code");
const name_uri = document.createElement("a");
name_uri.classList.add("taxon", "uri");
name_uri.innerText = authorizedName.taxonConceptURI.replace(
const short = authorizedName.taxonConceptURI.replace(
"http://taxon-concept.plazi.org/id/",
"",
);
name_uri.title = authorizedName.taxonConceptURI;
authName.append(name_uri);
name_uri.innerText = short;
name_uri.id = short;
name_uri.href = authorizedName.taxonConceptURI;
name_uri.target = "_blank";
name_uri.innerHTML += icons.link;
authName.append(" ", name_uri);
}
if (authorizedName.colURI) {
const col_uri = document.createElement("code");
const col_uri = document.createElement("a");
col_uri.classList.add("col", "uri");
const id = authorizedName.colURI.replace(
"https://www.catalogueoflife.org/data/taxon/",
"",
);
col_uri.innerText = id;
col_uri.id = id;
col_uri.title = authorizedName.colURI;
authName.append(col_uri);
col_uri.href = authorizedName.colURI;
col_uri.target = "_blank";
col_uri.innerHTML += icons.link;
authName.append(" ", col_uri);

const li = document.createElement("div");
li.classList.add("treatmentline");
Expand Down Expand Up @@ -304,7 +332,7 @@ class SynoName extends HTMLElement {
);
col_uri.innerText = id;
col_uri.href = `#${id}`;
col_uri.title = authorizedName.acceptedColURI!;
col_uri.title = "show name";
line.append(col_uri);
}
}
Expand Down Expand Up @@ -361,7 +389,8 @@ async function justify(name: Name): Promise<string> {
const indicator = document.createElement("div");
root.insertAdjacentElement("beforebegin", indicator);
indicator.append(`Finding Synonyms for ${NAME} `);
indicator.append(document.createElement("progress"));
const progress = document.createElement("progress");
indicator.append(progress);

const timeStart = performance.now();

Expand Down

0 comments on commit c1ff9ef

Please sign in to comment.