PageSourceSearch

https://www.okqubit.net/bench/controller.js

js okqubit.net collected 2026-10-02 18:42:56 UTC 4,011 bytes, 115 lines download raw bytes

1(function(){
2	'use strict';
3	function Controller(view,model){
4		this.view=view;
5		this.model=model;
6		this.updatetimer=null;
7		this.mode=0;
8		this.view.addAxisOptionsChangeListener(this.postDelayedRedraw.bind(this));
9		this.view.addPointClickListener(this.pointClicked.bind(this));
10		this.view.setModeChangeListener(this.modeChangeRequested.bind(this));
11	}
12	Controller.prototype.init=function(){
13		this.view.log('loading...');
14		this.model.loadMaster(this.masterLoaded.bind(this));
15	};
16	Controller.prototype.masterLoaded=function(err){
17		if(err===0){
18			var n=this.model.nMachines();
19			this.view.log('master loaded: '+n+' machines');
20			this.model.populateMachines();
21			this.layoutXYwidgets();
22			this.loadParameters();
23			this.view.hideDebug();
24			this.redrawPlot();
25			this.view.addFigureResizeListener(this.postDelayedRedraw.bind(this));
26		}else{
27			this.view.log('master load failed with err='+err);
28		}
29	};
30	Controller.prototype.layoutXYwidgets=function(){
31		this.view.populateArchPanel(this.model.arch_list,this.postDelayedRedraw.bind(this));
32		var ncols=this.model.numericColumnNames();
33		this.view.populateXpanel(ncols,this.postDelayedRedraw.bind(this));
34		this.view.populateYpanel(ncols,this.postDelayedRedraw.bind(this));
35	};
36	Controller.prototype.postDelayedRedraw=function(){
37		this.cancelPendingDelayedRedraw();
38		this.updatetimer=setTimeout(function(){
39			this.redrawPlot();
40			this.updatetimer=null;
41		}.bind(this),1000);
42	};
43	Controller.prototype.cancelPendingDelayedRedraw=function(){
44		if(this.updatetimer){
45			clearTimeout(this.updatetimer);
46		}
47	};
48	Controller.prototype.redrawPlot=function(){
49		var appstate;
50		if(this.mode===0){//scatter mode
51			appstate=this.redrawScatter();
52		}else if(this.mode===1){//bar mode
53			appstate=this.redrawBar();
54		}
55		if(!appstate){return;}
56		var logstr=JSON.stringify(appstate);
57		this.view.log('start updating with '+logstr);
58		this.view.setParams(appstate);
59	};
60	Controller.prototype.redrawScatter=function(){
61		var a=this.view.selectionArch();
62		var x=this.view.selectionX();
63		var xo=this.view.axisXopts();
64		var y=this.view.selectionY();
65		var yo=this.view.axisYopts();
66		var plot_param=this.model.plotParam(a,x,y,xo,yo);
67		this.view.plot(plot_param,x,y,xo,yo);
68		var appstate={'m':this.mode,'a':a,'x':x,'y':y,'xo':xo,'yo':yo};
69		return appstate;
70	};
71	Controller.prototype.redrawBar=function(){
72		var y=this.view.selectionY();
73		var yo=this.view.axisYopts();
74		var m=this.view.selectionMachines();
75		var plot_param=this.model.plotParamForBar(y,yo,m);
76		this.view.plotBar(plot_param,y,yo);
77		let appstate={'m':this.mode,'y':y,'yo':yo,'s':m};
78		return appstate;
79	};
80	Controller.prototype.loadParameters=function(fakeparams){
81		let params=fakeparams||this.view.getParams();
82		this.view.log('got parameter '+JSON.stringify(params));
83		if(params.m===1){ //bar mode
84			this.changeMode(1);
85			this.view.selectMachines(params.s||this.model.por_params.bar_s);
86			this.view.selectY(params.y||this.model.por_params.bar_y);
87			this.view.setAxisYopts(params.yo||this.model.por_params.bar_yo);
88		}else{//scatter mode
89			this.changeMode(0);
90			this.view.selectArch(params.a||this.model.arch_list);
91			this.view.selectX(params.x||this.model.por_params.x);
92			this.view.selectY(params.y||this.model.por_params.y);
93			this.view.setAxisXopts(params.xo||this.model.por_params.xo);
94			this.view.setAxisYopts(params.yo||this.model.por_params.yo);
95		}
96	};
97	Controller.prototype.pointClicked=function(m_id){
98		this.view.showDetails(this.model.machines[m_id]);
99	};
100	Controller.prototype.modeChangeRequested=function(toMode){
101		this.loadParameters({'m':Number(toMode)});
102		this.redrawPlot();
103	};
104	Controller.prototype.changeMode=function(toMode){
105		this.view.setupSceneForMode(toMode);
106		if(toMode==1){ // bar
107			let idxlist=this.model.idxList('Year');
108			if(!this.view.machinesListPopulated){
109				this.view.populateMachinesList(this.model.machines,idxlist,this.postDelayedRedraw.bind(this));
110			}
111		}
112		this.mode=Number(toMode);
113	};
114	window.app.Controller=Controller;
115})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.