Skip to content

Commit

Permalink
chore: Cleaned.
Browse files Browse the repository at this point in the history
  • Loading branch information
mzechmeister committed Aug 21, 2021
1 parent 49ddaa6 commit 7e93bdf
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions csv_plotter.htm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
opacity: 0.4;
}

#colnames > .coli {
#colpool > .coli {
margin: 3px;
}

Expand Down Expand Up @@ -202,7 +202,7 @@
</div>
</div>

<div id="colnames">
<div id="colpool">
</div>


Expand Down Expand Up @@ -350,27 +350,27 @@
return div
}

function init_box(colnames){
function init_box(colpool){
// list option
colx = document.getElementById('colx_list');
coly = document.getElementById('coly_list');
colt = document.getElementById('colt_list');
for (list of [colx, coly, colt]){
list.innerHTML = '' // remove all currents options
for (colname of colnames) {
for (colname of colpool) {
let option = document.createElement('option');
option.value = colname;
// option.id = colname; // for dict-like access and to check is id in present
list.appendChild(option);
}
}

c1 = document.getElementById('colnames');
c1 = document.getElementById('colpool');
//c1.addEventListener('mouseover', (_ => {add_drag("trace edit")}) );
//c1.addEventListener('mouseleave', (_ => {remove_drag("trace edit")}) );
c1.innerHTML = '' // remove all currents options
// put all columns into dragable divs
for (let [k, colname] of colnames.entries()) {
for (let [k, colname] of colpool.entries()) {
let div = colBox(k+1, colname);
c1.appendChild(div);
}
Expand Down Expand Up @@ -473,14 +473,7 @@
if (cs) trace1.marker.size = data[cs]

traces = [trace1];
/*
expr1 = document.getElementById("funcf").value
if (expr1!="") {
expr = new Function("x", "return "+expr1);
x1 = x.filter(x => !isNaN(x))
x1 = linspace(Math.min(...x1), Math.max(...x1), 200)
y1 = x1.map(expr)
*/

trace2 = {
type: "line",
x: [],
Expand All @@ -492,7 +485,7 @@
layout = {
autosize: true,
// height: 394,
// width: 1121,
// width: 1121,
hovermode: 'closest',
title: "csv plotter",
xaxis: {
Expand All @@ -505,7 +498,7 @@
},
margin: {l: 50, r: 10, b: 40, t: 30}
};
// Plotly.plot('plotly-div', {
// Plotly.plot('plotly-div', {
Plotly.newPlot('plotly-div', {
data: traces,
layout: layout,
Expand All @@ -519,12 +512,10 @@
zoompan()


var myPlot = document.getElementById('plotly-div')
graph = document.getElementsByClassName("js-plotly-plot")[0];

graph.on('plotly_click', function(data){
var pts = '';
console.log(data)
for(var i=0; i < data.points.length; i++){
pts = 'x = '+data.points[i].x +', y = '+
data.points[i].y + ', ' + data.points[i].text;
Expand All @@ -534,7 +525,7 @@

graph.on('plotly_relayout', function(event){
// recompute the function for new ranges after zoom (resize?)
draw_func()
draw_func()
});

}
Expand Down Expand Up @@ -562,14 +553,15 @@

dsv(url, function(){
// after reading data:
init_box(arguments[0]._colnames)
colpool = arguments[0]._colnames
init_box(colpool)

plot_data(...arguments, ...[..."xytsco"].map(x => url_kwargs['col'+x]))

// render column names in plot fields
lookup = {}
// lookup has both column names and column number
for ([i,k] of colnames.entries()) {lookup [i+1] = lookup[k] = i+1}
for ([i,k] of colpool.entries()) {lookup [i+1] = lookup[k] = i+1}
for (arg in url_kwargs) {
t = document.getElementById(arg)
t.innerText = ''
Expand Down

0 comments on commit 7e93bdf

Please sign in to comment.