Files
TRIMSP/myplots.js
T

112 lines
2.6 KiB
JavaScript

function Plot_xy(plotdiv,x,y,labels){
// Plot (x,y) scatter with x/ylabels
// place generated plot in div named plotdiv
//var plotDiv = document.getElementById(plotdiv);
let xlable = '';
let ylable = '';
let legend = '';
// labels are arranged as xlable, ylabel, legend
if (labels[0]) xlabel=labels[0];
if (labels[1]) ylabel=labels[1];
if (labels[2]) legend=labels[2];
let traces = [{
x: x,
y: y,
mode: 'lines+markers',
line: {shape: 'spline'},
name: legend
}];
let layout = {
autosize: true,
xaxis: {title: xlabel},
yaxis: {title: ylabel}
}
Plotly.plot(plotdiv, traces, layout);
// Resize
if (plotdiv == "plotRge") resizePl(1);
if (plotdiv == "plotFrac") resizePl(2);
};
function Plot_xyerr(plotdiv,x, y,dy,xlabel,ylabel){
// Plot (x,y) scatter with x/ylabels
// place generated plot in div named plotdiv
// and y error bars in dy
var traces = [{
x: x,
y: y,
mode: 'lines+markers',
error_y: {
type: 'data',
array : dy,
visible: true
},
}];
var layout = {
xaxis: {title: xlabel},
yaxis: {title: ylabel}
}
Plotly.plot(plotdiv, traces, layout);
};
function Plot_xyerrpm(plotdiv,x, y,dyp,dym,xlabel,ylabel){
// Plot (x,y) scatter with x/ylabels
// place generated plot in div named plotdiv
// and aymmetric y error bars in dyp and dym
var plotDiv = document.getElementById("plot");
var traces = [{
x: x,
y: y,
mode: 'lines+markers',
error_y: {
type: 'data',
symmetric: false,
array : dyp,
arrayminus: dym,
visible: true
},
}];
var layout = {
xaxis: {title: xlabel},
yaxis: {title: ylabel}
}
Plotly.plot(plotdiv,traces,layout);
};
function sizePlot(){
var plotDiv=this.document.getElementById("newPlot");
let newx=this.innerWidth-25;
let newy=this.innerHeight-25;
var update ={
width: newx,
height: newy
};
Plotly.relayout(plotDiv,update);
}
function resizePl(flag){
var plotDiv1=document.getElementById("plotRge");
var plotDiv2=document.getElementById("plotFrac");
const canRelayout = (plotDiv) => plotDiv && plotDiv.data && plotDiv.layout;
let plotDivs = [];
if (flag == null || flag == 1) plotDivs.push(plotDiv1);
if (flag == null || flag == 2) plotDivs.push(plotDiv2);
for (const plotDiv of plotDivs) {
if (!canRelayout(plotDiv) || !plotDiv.parentElement) continue;
let width = Math.max(280, plotDiv.parentElement.clientWidth - 8);
let height = Math.max(300, plotDiv.parentElement.clientHeight - 8);
Plotly.relayout(plotDiv, {width: width, height: height});
}
}