CZ_OpenSpice/static/spice/show_result.js

113 lines
2.6 KiB
JavaScript
Raw Normal View History

2021-03-18 12:54:06 +00:00
/* bokeh.js
使用该文件前请现在html加载相关js文件*/
2021-03-20 07:45:00 +00:00
// 仿真结果数据
var SimResult ;
var Flag_Refresh = false ;
2021-03-18 12:54:06 +00:00
2021-03-20 07:45:00 +00:00
var color_store = ["blue","brown","cyan","green","orange","pink","purple","red","whitesmoke","yellow"];
2021-03-18 12:54:06 +00:00
// create a data source to hold data
2021-03-20 07:45:00 +00:00
var the_source = new Bokeh.ColumnDataSource({
data: { x: [], y: [], color: [] }
2021-03-18 12:54:06 +00:00
});
2021-03-20 07:45:00 +00:00
2021-03-18 12:54:06 +00:00
// make a plot with some tools
var plot = Bokeh.Plotting.figure({
title:'Example of Random data',
tools: "pan,wheel_zoom,box_zoom,reset,save",
height: 300,
2021-03-20 07:45:00 +00:00
width: 400,
background_fill_color: "#F2F2F7"
2021-03-18 12:54:06 +00:00
});
2021-03-20 07:45:00 +00:00
function plotPoint() {
if(Flag_Refresh == true){
the_source.data.x = [];
the_source.data.y = [];
the_source.data.color = [];
console.log("Flag_Refresh = true !");
var the_nodes_name = SimResult["nodes_name"];
var the_x = SimResult["time"];
for(var i=0; i < the_nodes_name.length; i++){
var the_y = SimResult["nodes"][the_nodes_name[i]] ;
the_source.data.x.push(the_x);
the_source.data.y.push(the_y);
the_source.data.color.push(color_store[i%color_store.length]);
}
the_source.change.emit();
}
}
function requestSimInfo(){
var data = new Object();
var sim_result ;
data["sim_type"] = 'transient';
$.ajax({
type: 'POST',
url: "/getsiminfo",
data: data,
async:false, // 必须关闭异步!!!
dataType:'json',
success: function (siminfo) {
console.log("load sim result successfully !!");
sim_result = siminfo;
},
error: function(){
alert('failed');
}
});
return sim_result ;
}
function Callback_PlotPoint() {
plotPoint();
}
function Callback_Refresh(){
SimResult = requestSimInfo();
Flag_Refresh = true;
}
2021-03-18 12:54:06 +00:00
// add a line with data from the source
2021-03-20 07:45:00 +00:00
plot.multi_line({field:"x"},{field:"y"},{
source: the_source,
color: {field:"color"},
2021-03-18 12:54:06 +00:00
line_width: 2
});
2021-03-20 07:45:00 +00:00
2021-03-18 12:54:06 +00:00
// show the plot, appending it to the end of the current section
Bokeh.Plotting.show(plot,'#bokeh_01');
2021-03-20 07:45:00 +00:00
var RefreshButton = document.createElement("Button");
RefreshButton.appendChild(document.createTextNode("Refresh"));
document.currentScript.parentElement.appendChild(RefreshButton);
RefreshButton.addEventListener("click", Callback_Refresh);
2021-03-18 12:54:06 +00:00
var addDataButton = document.createElement("Button");
2021-03-20 07:45:00 +00:00
addDataButton.appendChild(document.createTextNode("Plot"));
2021-03-18 12:54:06 +00:00
document.currentScript.parentElement.appendChild(addDataButton);
2021-03-20 07:45:00 +00:00
addDataButton.addEventListener("click", Callback_PlotPoint);