Skip to content

Commit de2641e

Browse files
committed
Refactored instances of dagitty to models4pt in gui/dagitty.js file and dependencies
1 parent fb463d9 commit de2641e

File tree

19 files changed

+111
-143
lines changed

19 files changed

+111
-143
lines changed

gui/dags.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@
5757
dag_model_text_data : null
5858
};
5959

60-
var DAGittyControl;
60+
var Models4PTControl;
6161

6262
function initialize(){
6363

6464

65-
DAGitty.setup({autofocus:true});
66-
DAGittyControl = DAGitty.controllers[0];
65+
Models4PT.setup({autofocus:true});
66+
Models4PTControl = Models4PT.controllers[0];
6767

6868
GUI.menus = ["model","examples","howto","layout","help"]
6969
_.each(GUI.menus,function(t){
7070
document.getElementById("menu_"+t+"_title").addEventListener( 'click',
7171
function(){menuToggle(t)} );
7272
});
7373

74-
DAGittyControl.observe( 'graphchange',
74+
Models4PTControl.observe( 'graphchange',
7575
function(g){
7676
Model.dag = g;
7777
document.getElementById("adj_matrix").value = g.toString();
@@ -86,13 +86,13 @@
8686
}
8787
);
8888

89-
DAGittyControl.observe( 'graphlayoutchange',
89+
Models4PTControl.observe( 'graphlayoutchange',
9090
function(g){
9191
document.getElementById("adj_matrix").value = g.toString();
9292
}
9393
);
9494

95-
DAGittyControl.observe( 'vertex_marked',
95+
Models4PTControl.observe( 'vertex_marked',
9696
function( v ){
9797
if( v ){
9898
displayShow( 'variable' )
@@ -120,13 +120,13 @@
120120
// load user-supplied model
121121
loadOnline( "dagitty.net/m"+getid );
122122
} else {
123-
DAGittyControl.graphChanged();
123+
Models4PTControl.graphChanged();
124124
}
125125

126126
document.onkeydown = function(e){
127127
if( e.keyCode == 27 ){
128-
DAGittyControl.getView().getImplementation().stopMousemove()
129-
DAGittyControl.getView().closeDialog()
128+
Models4PTControl.getView().getImplementation().stopMousemove()
129+
Models4PTControl.getView().closeDialog()
130130
}
131131
}
132132
}
@@ -211,7 +211,7 @@
211211
<li style="float:none; overflow: hidden; border-right: none;"> &nbsp;</li>
212212
</ul>
213213

214-
<div id="canvas" class="dagitty" data-mutable="true">
214+
<div id="canvas" class="models4pt" data-mutable="true">
215215
A [selected,pos="-2.200,-1.520"]
216216
B [pos="1.400,-1.460"]
217217
D [outcome,pos="1.400,1.621"]
@@ -257,8 +257,8 @@ <h3 onclick="displayToggle('variable')"><img src="images/arrow-down.png" alt=""
257257
<input type="hidden" id="variable_id" value="">
258258

259259
<p>
260-
<button type="button" onclick="DAGittyControl.deleteVertex(document.getElementById('variable_id').value)">delete</button>
261-
<button type="button" onclick="DAGittyControl.getView().renameVertexDialog(document.getElementById('variable_id').value)">rename</button>
260+
<button type="button" onclick="Models4PTControl.deleteVertex(document.getElementById('variable_id').value)">delete</button>
261+
<button type="button" onclick="Models4PTControl.getView().renameVertexDialog(document.getElementById('variable_id').value)">rename</button>
262262
</p>
263263

264264
</form>

gui/js/dagitty.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8649,7 +8649,7 @@ var Models4PTController = Class.extend({
86498649
}
86508650
})
86518651

8652-
var DAGitty = {
8652+
var Models4PT = {
86538653
makeController : function( el, op ){
86548654
for( var k of Object.keys( el.dataset ) ){
86558655
if( !op.hasOwnProperty( k ) ){
@@ -8684,7 +8684,8 @@ var DAGitty = {
86848684
var tags = op.tags || ["div", "pre"]
86858685
for( var j = 0 ; j < tags.length ; j ++ ){
86868686
var divs = document.getElementsByTagName( tags[j] )
8687-
var re = new RegExp("\\bdagitty\\b")
8687+
// var re = new RegExp("\\bdagitty\\b")
8688+
var re = new RegExp("\\bmodels4pt\\b")
86888689
for( var i = 0 ; i < divs.length ; i ++ ){
86898690
el = divs.item(i)
86908691
if( re.test(el.className) ){
@@ -8702,8 +8703,8 @@ var DAGitty = {
87028703
return this.controllers_by_id[id]
87038704
},
87048705
resize : function(){
8705-
for( var i = 0 ; i < DAGitty.controllers.length ; i ++ ){
8706-
DAGitty.controllers[i].getView().resize()
8706+
for( var i = 0 ; i < Models4PT.controllers.length ; i ++ ){
8707+
Models4PT.controllers[i].getView().resize()
87078708
}
87088709
},
87098710
Math : {
@@ -8796,7 +8797,7 @@ var DAGitty = {
87968797
}
87978798

87988799

8799-
/* globals DAGitty,Class,_ */
8800+
/* globals Models4PT,Class,_ */
88008801
/* exported GraphGUI_SVG */
88018802

88028803
var svgns = "http://www.w3.org/2000/svg"
@@ -8829,10 +8830,10 @@ var GraphGUI_SVG = Class.extend({
88298830
return this.style
88308831
},
88318832
setStyle : function( stylename ){
8832-
if( DAGitty.stylesheets[stylename] ){
8833-
this.style = DAGitty.stylesheets[stylename]
8833+
if( Models4PT.stylesheets[stylename] ){
8834+
this.style = Models4PT.stylesheets[stylename]
88348835
} else {
8835-
this.style = DAGitty.stylesheets["default"]
8836+
this.style = Models4PT.stylesheets["default"]
88368837
}
88378838
},
88388839
clear : function(){
@@ -8931,10 +8932,10 @@ var GraphGUI_SVG = Class.extend({
89318932
this.unsetLastHoveredElement, this ) )
89328933
},
89338934
anchorEdgeShape : function( el ){
8934-
var anchorback = DAGitty.Math.svgEdgeAnchor( el, 0, el.directed )
8935+
var anchorback = Models4PT.Math.svgEdgeAnchor( el, 0, el.directed )
89358936
el.x1 = anchorback[0]; el.y1 = anchorback[1]
89368937

8937-
var anchorfront = DAGitty.Math.svgEdgeAnchor( el, 1., el.directed )
8938+
var anchorfront = Models4PT.Math.svgEdgeAnchor( el, 1., el.directed )
89388939
el.x2 = anchorfront[0]; el.y2 = anchorfront[1]
89398940

89408941
if( el.cx ){

gui/js/main.js

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var GUI = {
2626
highlight_puredirect : false,
2727
allow_intermediate_adjustment : true,
2828
activate_path_style : function( s, b ){
29-
var sty = DAGitty.stylesheets.default.style
29+
var sty = Models4PT.stylesheets.default.style
3030
if( b ) {
3131
if(sty[s+"path_inactive"] ){
3232
sty[s+"path"] = sty[s+"path_inactive"];
@@ -38,10 +38,10 @@ var GUI = {
3838
delete sty[s+"path"];
3939
displayHide("legend_"+s);
4040
}
41-
DAGittyControl && DAGittyControl.redraw();
41+
Models4PTControl && Models4PTControl.redraw();
4242
},
4343
activate_node_style : function( s, b ){
44-
var sty = DAGitty.stylesheets.default.style
44+
var sty = Models4PT.stylesheets.default.style
4545
if( b ) {
4646
if(sty[s+"node_inactive"] ){
4747
sty[s+"node"] = sty[s+"node_inactive"];
@@ -67,15 +67,15 @@ var GUI = {
6767
this.activate_node_style( n, b );
6868
},this);
6969
b ? displayShow("legend_ancestors") : displayHide("legend_ancestors");
70-
DAGittyControl && DAGittyControl.redraw();
70+
Models4PTControl && Models4PTControl.redraw();
7171
},
7272
set_view_mode : function( vm ){
7373
let vmel = document.getElementById( "dagview_"+vm )
7474
vmel.checked ||= true
75-
DAGittyControl && DAGittyControl.setViewMode( vm );
75+
Models4PTControl && Models4PTControl.setViewMode( vm );
7676
},
7777
set_bias_mode : function( bm ){
78-
DAGittyControl && DAGittyControl.setBiasMode( bm );
78+
Models4PTControl && Models4PTControl.setBiasMode( bm );
7979
},
8080
refresh_variable_status : function(){
8181
var vid = document.getElementById("variable_id").value
@@ -89,14 +89,14 @@ var GUI = {
8989
set_variable_status : function( n, stat ){
9090
var vid = document.getElementById("variable_id").value
9191
if( stat ){
92-
DAGittyControl && DAGittyControl.setVertexProperty( vid, n )
92+
Models4PTControl && Models4PTControl.setVertexProperty( vid, n )
9393
} else {
94-
DAGittyControl && DAGittyControl.unsetVertexProperty( vid, n )
94+
Models4PTControl && Models4PTControl.unsetVertexProperty( vid, n )
9595
}
9696
},
9797
set_style : function( s ){
98-
DAGitty.stylesheets.default = DAGitty.stylesheets[s]
99-
var sty = DAGitty.stylesheets.default.style
98+
Models4PT.stylesheets.default = Models4PT.stylesheets[s]
99+
var sty = Models4PT.stylesheets.default.style
100100
document.getElementById("highlight_ancestral").checked = typeof(sty["confoundernode_inactive"]) === "undefined";
101101
document.getElementById("highlight_ancestral").checked ? displayShow("legend_ancestors") : displayHide("legend_ancestors");
102102

@@ -111,7 +111,7 @@ var GUI = {
111111
"outcome","rnode","adjustednode"],function(n){
112112
document.getElementById("li"+n).src="images/legend/"+s+"/"+n+".png"
113113
},this);
114-
DAGittyControl.setStyle( s )
114+
Models4PTControl.setStyle( s )
115115
}
116116
};
117117

@@ -183,7 +183,7 @@ function nl2br (str, is_xhtml) {
183183
}
184184

185185
function msg( t ){
186-
DAGittyControl.getView().openAlertDialog( t );
186+
Models4PTControl.getView().openAlertDialog( t );
187187
}
188188

189189
function how( t ){
@@ -608,7 +608,7 @@ function displayImplicationInfo( full ){
608608
}
609609

610610
function exportTikzCode(){
611-
DAGittyControl.getView().openHTMLDialog(
611+
Models4PTControl.getView().openHTMLDialog(
612612
"<textarea style=\"width:80%\" rows=\"10\">"+
613613
"% This code uses the tikz package\n"+
614614
"\\begin{tikzpicture}\n"+
@@ -653,7 +653,7 @@ function loadDAGFromTextData(){
653653
var layouter = new GraphLayouter.Spring( Model.dag );
654654
layouter.layout();
655655
}
656-
DAGittyControl.setGraph( Model.dag );
656+
Models4PTControl.setGraph( Model.dag );
657657
displayHide("model_refresh");
658658
document.getElementById("adj_matrix").style.backgroundColor="#fff";
659659
}
@@ -662,7 +662,7 @@ function generateSpringLayout(){
662662
var layouter = new GraphLayouter.Spring( Model.dag );
663663
_.each(Model.dag.edges,function(e){delete e["layout_pos_x"];delete e["layout_pos_y"]})
664664
layouter.layout();
665-
DAGittyControl.setGraph( Model.dag ); // trigges to refresh the rendering
665+
Models4PTControl.setGraph( Model.dag ); // trigges to refresh the rendering
666666
};
667667

668668
function loadExample( nr ){
@@ -684,7 +684,7 @@ function newModel2(ename){
684684
if( ename === null ){ return false; }
685685
ename = (""+ename).trim()
686686
if( ename == "" ){ return false; }
687-
DAGittyControl.getView().openPromptDialog(
687+
Models4PTControl.getView().openPromptDialog(
688688
"Please enter name of outcome variable","",function(s){
689689
newModel3(ename,s) } )
690690
return true;
@@ -695,7 +695,7 @@ function newModel3(ename,oname){
695695
if( oname == "" || ename == oname ){ return false; }
696696
document.getElementById("adj_matrix").value = ename+" E @0,0\n"+oname+" O @1,1\n\n"+ename+" "+oname
697697
loadDAGFromTextData()
698-
DAGittyControl.getView().closeDialog()
698+
Models4PTControl.getView().closeDialog()
699699
}
700700

701701
function supportsSVG() {
@@ -799,9 +799,9 @@ function hostName(){
799799
function networkFailMsg(){
800800
msg(
801801
"A network error occurred when trying to perform this function. "+
802-
"If you are using a downloaded DAGitty version, this is likely "+
802+
"If you are using a downloaded Models4PT version, this is likely "+
803803
"due to Browser security settings. Try again using the online "+
804-
"version of DAGitty." )
804+
"version of Models4PT." )
805805
}
806806

807807
function getModelIdFromURL( url ){
@@ -820,31 +820,7 @@ function saveOnlineForm(){
820820
}
821821
}
822822

823-
/*
824-
The original loadOnline function fetched a model from dagitty.net using an API call.
825-
This version has been commented out as we are transitioning to using localStorage
826-
for saving and loading models. When we implement a backend in the future, we may revisit
827-
or adapt this function to integrate with our own backend.
828-
829-
async function loadOnline( url ){
830-
var graphid = getModelIdFromURL( url )
831-
try{
832-
const response = await fetch( "https://dagitty.net/db/id/"+graphid )
833-
if( response.ok ){
834-
const modelsyntax = await response.json()
835-
DAGittyControl.getView().closeDialog()
836-
document.getElementById("adj_matrix").value = modelsyntax.g
837-
Model.uniqid = modelsyntax.g.id
838-
loadDAGFromTextData()
839-
} else {
840-
networkFailMsg(); return
841-
}
842-
} catch( err ){
843-
networkFailMsg();
844-
console.log( err );
845-
return
846-
}
847-
} */
823+
848824

849825
// New localStorage-based version
850826
async function loadOnline(url) {
@@ -861,7 +837,7 @@ async function loadOnline(url) {
861837
const modelsyntax = JSON.parse(modelData);
862838

863839
// Update the UI and render the DAG
864-
DAGittyControl.getView().closeDialog();
840+
Models4PTControl.getView().closeDialog();
865841
document.getElementById("adj_matrix").value = modelsyntax.g;
866842
Model.uniqid = graphid; // Optional: track the graph ID
867843
loadDAGFromTextData(); // Render the graph
@@ -874,7 +850,7 @@ async function loadOnline(url) {
874850
// Updated loadOnlineForm function for localStorage:
875851
// This version prompts the user for a Graph ID instead of a URL and loads the model from localStorage.
876852
function loadOnlineForm() {
877-
DAGittyControl.getView().openPromptDialog(
853+
Models4PTControl.getView().openPromptDialog(
878854
"Enter the Graph ID",
879855
"exampleGraph123", // Example placeholder
880856
function (graphID) {
@@ -888,16 +864,7 @@ function loadOnlineForm() {
888864
}
889865

890866

891-
/*
892-
The original loadOnlineForm function opened a prompt dialog for the user to enter a URL.
893-
This functionality relied on models stored remotely on dagitty.net.
894-
As we transition to localStorage, this version has been replaced with one that prompts for a Graph ID instead of a URL.
895867

896-
Original code:
897-
function loadOnlineForm(){
898-
DAGittyControl.getView().openPromptDialog(
899-
"Enter the URL","dagitty.net/mOWOV4V",loadOnline)
900-
} */
901868

902869
// ----------------------------
903870
// Save and Load Functionality

gui/js/styles/learn.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ var Decoration = {
2626
{ 'class' : "arrowback", 'd': "M-1.5,0L5,5M-1.5,0L5,-5" }
2727
]
2828
}
29-
DAGitty.stylesheets.semlikePlain = { style : Base, decoration : Decoration };
30-
DAGitty.stylesheets.default = DAGitty.stylesheets.semlikePlain
29+
Models4PT.stylesheets.semlikePlain = { style : Base, decoration : Decoration };
30+
Models4PT.stylesheets.default = Models4PT.stylesheets.semlikePlain
3131
})();

gui/js/styles/original.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function(){
2-
DAGitty.stylesheets.original = {
2+
Models4PT.stylesheets.original = {
33
style : {
44
node : {
55
'd' : 'M 0 0 m 20, 0 a 20,15 0 1,1 -40,0 a 20,15 0 1,1 40,0',
@@ -31,5 +31,5 @@ DAGitty.stylesheets.original = {
3131
]
3232
}
3333
};
34-
DAGitty.stylesheets.default = DAGitty.stylesheets.original
34+
Models4PT.stylesheets.default = Models4PT.stylesheets.original
3535
})();

gui/js/styles/semlike.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var Decoration = {
4040
]
4141
}
4242

43-
DAGitty.stylesheets.semlike = { style : Base, decoration : Decoration };
44-
DAGitty.stylesheets.default = DAGitty.stylesheets.semlike
43+
Models4PT.stylesheets.semlike = { style : Base, decoration : Decoration };
44+
Models4PT.stylesheets.default = Models4PT.stylesheets.semlike
4545

4646
})();

gui/publish.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ <h1>Publish your causal diagram</h1>
162162
<br/>
163163

164164

165-
<label for="modelsavefrm_code">DAGitty code</label><br/>
165+
<label for="modelsavefrm_code">Models4PT code</label><br/>
166166
<textarea class="form-control" name="code" readonly required
167167
value="" id="modelsavefrm_code"></textarea>
168168
<br/>

0 commit comments

Comments
 (0)