-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overlay plot for comparing cyclic voltammetry #178
Draft
linuxrider
wants to merge
18
commits into
echemdb:main
Choose a base branch
from
linuxrider:d3js-plot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8fd1c5e
first test d3js overlay plot
linuxrider 5d67136
add csv copy hook for development
linuxrider 5fdf7e3
first partial working overlay plot
linuxrider 8cf944a
add hook to copy data for local tests
linuxrider 1d00fda
add dependency for local testing
linuxrider 6ac1119
display more meaningful label
linuxrider 17212b2
properly use promise, styling, and cleanup
linuxrider ecc2ee0
fix lints
linuxrider 621c1c4
black hints
linuxrider 2d71867
styling plot
linuxrider 4a03bb3
Merge branch 'main' into d3js-plot
linuxrider 53b36d5
change default behavior of copy data hook
linuxrider f83e70a
remove unnecessary environment file
linuxrider e3ba74e
add caching
linuxrider 9f379fd
beautify js
linuxrider e87b483
add quickfilter
linuxrider 138a1bc
move compare js to serparate file
linuxrider 5fa9f66
use minimized d3js
linuxrider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ dependencies: | |
- pymdown-extensions>=9.2,<10 | ||
- python-frontmatter | ||
- tabulate | ||
- mkdocs-simple-hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
var cache = {}; | ||
var traces = []; | ||
|
||
var layout = { | ||
|
||
xaxis: { | ||
title: { | ||
text: '<i>E</i> [V]', | ||
font: { | ||
family: 'Courier New, monospace', | ||
size: 18, | ||
} | ||
}, | ||
showline: true, | ||
zeroline: false, | ||
ticks: "outside", | ||
mirror: true, | ||
side: "bottom" | ||
}, | ||
|
||
yaxis: { | ||
title: { | ||
text: '<i>j</i> [A m⁻²]', | ||
font: { | ||
family: 'Courier New, monospace', | ||
size: 18, | ||
} | ||
}, | ||
showline: true, | ||
zeroline: true, | ||
ticks: "outside", | ||
mirror: true, | ||
side: "left" | ||
}, | ||
legend: { | ||
yanchor: "top", | ||
y: -0.3, | ||
xanchor: "left", | ||
x: 0.01 | ||
} | ||
}; | ||
|
||
Plotly.newPlot('vis', traces, layout); | ||
|
||
async function updatePlot(names) { | ||
Promise.all( | ||
names.map(name => { | ||
const source = name.split("_") | ||
.slice(0, -2) | ||
.join("_"); | ||
if (name in cache) { | ||
return cache[name]; | ||
} else { | ||
return d3.csv(["/data/generated/svgdigitizer/", source, "/", name, ".csv"].join(""), convertNumbers) | ||
.then(processData) | ||
.then(function (result) { | ||
return { | ||
x: result[0], | ||
y: result[1], | ||
name: name, | ||
type: 'scatter' | ||
} | ||
}) | ||
.then(function (result) { | ||
cache[name] = result; | ||
return result; | ||
}); | ||
} | ||
}) | ||
) | ||
.then(function (traces) { | ||
Plotly.newPlot('vis', traces, layout); | ||
}); | ||
}; | ||
|
||
function convertNumbers(row) { | ||
var r = {}; | ||
for (var k in row) { | ||
r[k] = +row[k]; | ||
if (isNaN(r[k])) { | ||
r[k] = row[k]; | ||
} | ||
} | ||
return r; | ||
} | ||
|
||
function processData(allRows) { | ||
var x = []; | ||
var y = []; | ||
for (var i = 0; i < allRows.length; i++) { | ||
row = allRows[i]; | ||
x.push(row['E']); | ||
y.push(row['j']); | ||
} | ||
|
||
return [x, y] | ||
}; | ||
|
||
// selection mechanism | ||
var selected_cyclic_voltammograms = []; | ||
// callback on selections for all checkboxes | ||
// not ideal since for every selection iterate over all checkboxes | ||
d3.selectAll(".checkbox") | ||
.on("change", function (d, i) { | ||
selected_cyclic_voltammograms = [...d3.selectAll("input[class='checkbox']:checked") | ||
._groups[0] | ||
].map(checkbox => { | ||
return checkbox.name | ||
}); | ||
updatePlot(selected_cyclic_voltammograms); | ||
}); | ||
|
||
function quickFilter() { | ||
var input, filter, table, tr, i, f, trContent, results; | ||
input = document.getElementById("filterInput"); | ||
filter = input.value.toUpperCase().split(" "); | ||
table = document.getElementsByClassName("md-typeset__table")[0]; | ||
tr = table.getElementsByTagName("tr"); | ||
for (i = 1; i < tr.length; i++) { | ||
|
||
trContent = tr[i].textContent.replace(/[\s]+/g, ' '); | ||
|
||
if (trContent) { | ||
results = [] | ||
for (f of filter) { | ||
if (trContent.toUpperCase().indexOf(f) > -1) { | ||
results.push(true); | ||
} else { | ||
results.push(false); | ||
} | ||
} | ||
|
||
if (results.every( (val, r, arr) => val === true )) { | ||
tr[i].style.display = ""; | ||
} else { | ||
tr[i].style.display = "none"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
| Selected | | Substrate | Electrolyte {: .echemdb-expand-column } | Year {: .echemdb-hide-mobile } | Reference {: .echemdb-hide-mobile } | | ||
| -------- | ----- | --------- | ----------- | ---- | --------- | | ||
{% for entry in database %} | ||
| <input class="checkbox" type="checkbox" name="{{ entry.identifier }}" unchecked> {{entry.identifier}} | [ | b64encode }}){: .echemdb-cv-thumbnail }](/cv/entries/{{ entry.identifier }}) {: .echemdb-middle-cell } | {{ entry.system.electrodes.working_electrode.material }}({{ entry.system.electrodes.working_electrode.crystallographic_orientation }}) {: .echemdb-middle-cell } | {{ entry.system.electrolyte | render("components/electrolyte.md") }} {: .echemdb-middle-cell } | {{ database.bibliography.entries[entry.source.citation_key].fields['year'] }} {: .echemdb-hide-mobile .echemdb-middle-cell } | [ {{ entry.bibliography.persons['author'][0].last_names[0] | unicode }} ***et. al.*** Fig. {{ entry.source.figure }} ({{ entry.source.curve }})]({{ entry.source.url }}) {: .echemdb-hide-mobile .echemdb-middle-cell } | | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Cyclic Voltammograms | ||
{{ intro }} | ||
<div id="vis"></div> | ||
Click a graph to add it to the comparison. | ||
|
||
|
||
|
||
<input type="text" id="filterInput" onkeyup="quickFilter()" placeholder="Filter list ..." title="Type in a name"> | ||
|
||
{{ render("components/cv_compare_table.md", entries_path=entries_path, database=database) }} | ||
|
||
<script src="https://cdn.plot.ly/plotly-2.12.1.min.js"></script> | ||
<script src="https://d3js.org/d3.v7.min.js"></script> | ||
<script src="/javascripts/compare.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""Hooks for local usage.""" | ||
import os | ||
import shutil | ||
|
||
|
||
def copy_data(config): | ||
"""Copy the data to the website folder.""" | ||
site_dir = config["site_dir"] | ||
shutil.copytree("data", os.path.join(site_dir, "data")) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.