-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhf.html
More file actions
316 lines (316 loc) · 14.8 KB
/
hf.html
File metadata and controls
316 lines (316 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<!DOCTYPE html>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<style>
html{
height: 100%;
}
body {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: 5px;
}
</style>
<div id="body"></div>
<style>
.node {cursor: pointer;}
.node text {font: 10px sans-serif;font-weight: bold;}
.link {fill: none;stroke: #ccc;stroke-width: 1.5px;}
</style>
<script>
width = 960,height = 800;
var root =
{"id":1,"gparent":-1,"tag":"top","type":10,"cfr":0.00545047581264801,"pbf":-1,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"HF Vaporizer","name2":"Rupture","children":[{"id":2,"gparent":1,"tag":"G_2","type":12,"cfr":0.00544947581264801,"pbf":-1,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Overpressure","name2":"Unrelieved","children":[{"id":4,"gparent":2,"tag":"G_4","type":10,"cfr":-1,"pbf":0.02724737906324,"crt":-1,"moe":0,"condition":1,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Pressure Relief System","name2":"in Failed State","children":[{"id":6,"gparent":4,"tag":"G_6","type":10,"cfr":0.2,"pbf":0.00829296833573068,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Pressure Relief","name2":"Isolated","children":[{"id":7,"gparent":6,"tag":"","type":2,"cfr":0.1,"pbf":0.0041551166651157,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":0,"p2":0.0833333333333333,"collapse":0,"name":"Valve 20","name2":"Left Closed","children":[{"id":8,"gparent":7,"tag":"","type":2,"cfr":0.1,"pbf":0.0041551166651157,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":0,"p2":0.0833333333333333,"collapse":0,"name":"Valve 21","name2":"Left Closed"}]}]},{"id":9,"gparent":4,"tag":"G_9","type":10,"cfr":0.10000001803596,"pbf":0.00926309057262087,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Rupture Disk Fails","name2":"to Open at Design Pt.","children":[{"id":10,"gparent":9,"tag":"G_10","type":10,"cfr":-1,"pbf":0.002997001,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Installation/Mfr","name2":"Errors","children":[{"id":11,"gparent":10,"tag":"E_11","type":4,"cfr":-1,"pbf":0.001,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Rupture Disk","name2":"Installed Upside Down","children":[{"id":12,"gparent":11,"tag":"E_12","type":4,"cfr":-1,"pbf":0.001,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Wrong Rupture Disk","name2":"Installed","children":[{"id":13,"gparent":12,"tag":"E_13","type":4,"cfr":-1,"pbf":0.001,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Rupture Disk","name2":"Manuf. Error"}]}]}]},{"id":14,"gparent":9,"tag":"G_14","type":10,"cfr":0.10000001803596,"pbf":0.0062849255006312,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Pressure Between Disk","name2":"and Relief Valve","children":[{"id":15,"gparent":14,"tag":"G_15","type":12,"cfr":0.00483741803595952,"pbf":0.00234006132546264,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Pressure NOT","name2":"Detectable by PI","children":[{"id":16,"gparent":15,"tag":"","type":2,"cfr":-1,"pbf":0.0483741803595952,"crt":-1,"moe":0,"condition":1,"cond_code":0,"etype":0,"p1":0,"p2":1,"collapse":0,"name":"Pressure Gage","name2":"Failed Low Position"},{"id":17,"gparent":15,"tag":"","type":2,"cfr":0.1,"pbf":0.0483741803595952,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":0,"p2":1,"collapse":0,"name":"Rupture Disk Leak","name2":"Undetected"}]},{"id":18,"gparent":14,"tag":"G_18","type":12,"cfr":0.0951626,"pbf":0.00395411705155739,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Pressure","name2":"Detectable by PI","children":[{"id":19,"gparent":18,"tag":"E_19","type":4,"cfr":-1,"pbf":0.951626,"crt":-1,"moe":0,"condition":1,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Pressure Gage","name2":"Detects Pressure"},{"id":20,"gparent":18,"tag":"","type":2,"cfr":0.1,"pbf":0.0041551166651157,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":0,"p2":0.0833333333333333,"collapse":0,"name":"Rupture Disk Leak","name2":"Detectable"}]}]}]},{"id":21,"gparent":4,"tag":"G_21","type":10,"cfr":0.00666666666666667,"pbf":0.00994191580805981,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Pressure Relief Fails","name2":" to Open at Design Pt","children":[{"id":22,"gparent":21,"tag":"","type":2,"cfr":0.00333333333333333,"pbf":0.00498337491681067,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":0,"p2":3,"collapse":0,"name":"Pressure Relief","name2":"set too high"},{"id":23,"gparent":21,"tag":"","type":2,"cfr":0.00333333333333333,"pbf":0.00498337491681067,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":0,"p2":3,"collapse":0,"name":"Pressure Relief Unable","name2":"to Open at Design Pt"}]}]},{"id":5,"gparent":2,"tag":"G_5","type":10,"cfr":0.2,"pbf":-1,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Overpressure","name2":"Occurs","children":[{"id":24,"gparent":5,"tag":"E_24","type":3,"cfr":0.1,"pbf":-1,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"High Pressure","name2":"Feed to Vaporizer"},{"id":25,"gparent":5,"tag":"E_25","type":3,"cfr":0.1,"pbf":-1,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Vaporizer Heating","name2":"Runaway"}]}]},{"id":3,"gparent":1,"tag":"E_3","type":3,"cfr":1e-06,"pbf":-1,"crt":-1,"moe":0,"condition":0,"cond_code":0,"etype":0,"p1":-1,"p2":-1,"collapse":0,"name":"Vaporizer Rupture","name2":"Due to Stress/Fatigue"}]};
var llim=1e-25;
var duration = 200,rectW = 124,rectH = 90,TrectH = 24;
var width_initial = $(window).width()/2-60;
var tree = d3.layout.tree()
.nodeSize([rectW*1.15, rectH*1.2])
.separation(function(a, b) { return (a.parent == b.parent ? 1 : 1.2); });
// the widget must select el, not "#body" as in html
var svg = d3.select("#body").append("svg").attr("width", "100%").attr("height", "100%")
.call(zm = d3.behavior.zoom().scaleExtent([0.05,5]).on("zoom", redraw)).append("g")
.attr("transform", "translate(" + width_initial + "," + 50 + ")");
zm.translate([width_initial, 20]);
root.x0 = 0;
root.y0 = height / 2;
var duration_backup = duration;
duration = 0;
//function collapse(d) {
//if (d.children) {
//d._children = d.children;
//d._children.forEach(collapse);
//d.children = null;}}
update(root);
autocollapse(root);
duration = duration_backup;
d3.select("#body").style("height", "100%");
function update(source) {
var nodes = tree.nodes(root)
links = tree.links(nodes);
var node = svg.selectAll("g.node")
.data(nodes, function (d) {
return d.id || (d.id = ++i);});
var nodeEnter = node.enter().append("g")
.attr("class", "node")
.attr("transform", function (d) {
return "translate(" + source.x0 + "," + source.y0 + ")";})
.on("click", click);
nodeEnter.append("rect")
.attr("width", rectW)
.attr("height", TrectH)
.attr("stroke", function (d) {
return d._children ? "blue" : "black";})
.attr("stroke-width", 1)
.style("fill", function (d) {
return d._children ? "lightcyan" : "#fff";});
nodeEnter.append("text")
.attr("x", rectW/2)
.attr("y", 10)
.attr("text-anchor", "middle")
.text(function (d) {
return d.name;});
nodeEnter.append("text")
.attr("x", rectW/2)
.attr("y", 17)
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.text(function (d) {
return d.name2;});
nodeEnter.append("text")
.attr("x", rectW / 2 -144)
.attr("y", TrectH +14)
.attr("text-anchor", "middle")
.attr("fill", "navy")
.text(function (d) {
return (d.tag=="top" && d.p2>0) ? "Mission Time" : "" ;});
nodeEnter.append("text")
.attr("x", rectW / 2 -144)
.attr("y", TrectH +26)
.attr("text-anchor", "middle")
.attr("fill", "navy")
.text(function (d) {
return (d.tag=="top" && d.p2>0) ? d.p2 : "" ;});
var orGate="m 75,65 c -1.4, -10, .6, -22 -15, -30 -15.6, 8, -13.4, 20, -15, 30, 0, 0 3, -8 15, -8 10, 0 15, 8 15, 8 z";
var andGate="m 45,50 0,15 30,0 0,-15 a15,15 .2 0,0 -15,-15 a15,15 .2 0,0 -15,15";
var priorityGate="m 45,50 0,15 30,0 0,-15 a15,15 .2 0,0 -15,-15 a15,15 .2 0,0 -15,15 m 0,10 30,0";
var inhibitGate="m 60,35 -15,6.340 0,17.3205 15,6.340 15,-6.340 0,-17.3205 z";
var alarmGate="m 75,65 c -1.4, -10, .6, -22 -15, -30 -15.6, 8, -13.4, 20, -15, 30, 0, 0 3, -8 15, -8 10, 0 15, 8 15, 8 z m -30,0 v5 c0, 0 3, -8 15, -8 10, 0 15, 8 15, 8 v-5";
var voteGate="m 75,65 c -1.4,-10,.6,-22-15,-30 -15.6,8,-13.4,20,-15,30 m 0,0 0,10 30,0 0,-10 m-28,-7.5 27,0";
var house="m 45,50 0,15 30,0 0,-15 -15,-15 -15,15";
var undeveloped="m 60,35 m 0,0 l 24,15 l -24,15 l -24,-15 z";
var component="m 75, 50 a15,15 .2 0,0 -15,-15 a15,15 .2 0,0 -15,15 a15,15 .2 0,0 15,15 a15,15 .2 0,0 15,-15";
nodeEnter.append("path")
.attr("d",
function(d) {switch (d.type) {
case 10 : return(orGate);
break;
case 11 : return(andGate);
break;
case 12 : return(inhibitGate);
break;
case 13 : return(alarmGate);
break;
case 14 : return(priorityGate);
break;
case 15 : return(voteGate);
break;
case 16 : return(voteGate);
break;
case 9 : return(house);
break;
case 6 : return(undeveloped);
break;
case 3 : return(undeveloped);
break;
default : return(component);
}})
.attr({stroke:"black",
"stroke-width":1,
"stroke-linejoin":"round",
fill: "#fff"});
nodeEnter.append("text")
.attr("x", rectW / 2-2)
.attr("y", TrectH + 25)
.attr("text-anchor", "middle")
.attr("fill", function(d){return d.moe==0 ? "red": "magenta";})
//.attr("font", "12px")
//.attr("stroke", "white")
//.attr("stroke-width", ".5px")
.text(function (d) {
return d.moe>0 ? d.moe : d.id ;});
nodeEnter.append("text")
.attr("x", rectW / 2-2)
.attr("y", TrectH + 45)
.attr("text-anchor", "middle")
.attr("fill", "blue")
.text(function (d) {
return d.type>14 && d.p2>0 ? parseInt(d.p1)+" :"+parseInt(d.p2) : d.type==16 ? parseInt(d.p1)+" :" : "" ;});
nodeEnter.append("text")
.attr("x", rectW / 2 -56)
.attr("y", TrectH -26)
.attr("text-anchor", "middle")
.attr("fill", "magenta")
.text(function (d) {
return d.moe > 0 ? "R" : d.moe<0 ? "S" : "" ;});
nodeEnter.append("text")
.attr("x", rectW / 2 -31)
.attr("y", TrectH -26)
.attr("text-anchor", "right")
.attr("fill", "navy")
.text(function (d) {
return d.condition > 0 ? "Cond" : "" ;});
nodeEnter.append("text")
.attr("x", rectW / 2 +3)
.attr("y", TrectH -26)
.attr("text-anchor", "left")
.attr("fill", function(d){return d.moe==0 ? "red": "magenta";})
.text(function (d) {
return d.tag;});
nodeEnter.append("text")
.attr("x", rectW/2+19)
.attr("y", TrectH + 12)
.attr("text-anchor", "left")
.attr("fill", "green")
//.text(function (d) { return d.cfr>0&&d.condition==0 ? "Fail Rate":"";});
.text(function (d) { return d.cfr>0 ? "Fail Rate":"";});
nodeEnter.append("text")
.attr("x", rectW/2+19)
.attr("y", TrectH + 24)
.attr("text-anchor", "left")
.attr("fill", "green")
//.text(function (d) {return d.cfr>0&&d.condition==0 ? (d.cfr).toExponential(4):"";});
.text(function (d) {return d.cfr>0 ? (d.cfr).toExponential(4):"";});
nodeEnter.append("text")
.attr("x", rectW/2+19)
.attr("y", TrectH + 36)
.attr("text-anchor", "left")
.attr("fill", "navy")
.text(function (d) { return d.pbf>llim ? "Prob":"";});
nodeEnter.append("text")
.attr("x", rectW/2+19)
.attr("y", TrectH + 48)
.attr("text-anchor", "left")
.attr("fill", "navy")
.text(function (d) {return d.pbf>llim ? (d.pbf).toExponential(4):"" ;});
nodeEnter.append("text")
.attr("x", -4)
.attr("y", TrectH + 12)
.attr("text-anchor", "left")
.attr("fill", function(d){return d.condition==1 ? "dimgray": d.etype>0 ? "dimgray" : "lightgray" ;})
.text(function (d) { return d.crt>0 ? "Repair Time": d.etype==1 ? "Exponential": d.etype==2 ? "Weibull":"";});
nodeEnter.append("text")
.attr("x", -4)
.attr("y", TrectH + 24)
.attr("text-anchor", "left")
.attr("fill", function(d){return d.condition==1 ? "dimgray": d.etype>0 ? "dimgray" : "lightgray" ;})
.text(function (d) {return d.crt>0 ? (d.crt).toExponential(4): d.etype==2 ? "B="+parseFloat(d.p1.toFixed(2)) : (d.etype==1 && d.p2>0) ? "exposure" :"" ;});
nodeEnter.append("text")
.attr("x", -4)
.attr("y", TrectH + 36)
.attr("text-anchor", "left")
// must have an else for fill condition
.attr("fill", function(d){return d.etype>0 ? "dimgray" : "white" ;})
.text(function (d) {return d.etype==2 ? "TS="+d.p2 : (d.etype==1 && d.p2>0) ? d.p2 :"" ;});
nodeEnter.append("text")
.attr("x", -4)
.attr("y", TrectH + 48)
.attr("text-anchor", "left")
.attr("fill", "black")
.text(function (d) { return d.type==13 ? "Phf="+parseFloat(d.p1.toFixed(2)) :"";});
nodeEnter.append("text")
.attr("x", function(d) { return d.type==2 ? rectW/2 : rectW/2+10;})
.attr("y", TrectH + 60)
.attr("text-anchor", function(d) { return d.type==2 ? "middle" : "left";})
.attr("fill", "maroon")
.text(function (d) {
return d.type==2 ? "T="+parseFloat(d.p2.toFixed(4)) +" Po=" +parseFloat(d.p1.toFixed(5))
:"";});
var nodeUpdate = node.transition()
.duration(duration)
.attr("transform", function (d) {
return "translate(" + d.x + "," + d.y + ")";});
nodeUpdate.select("rect")
.attr("width", rectW)
.attr("height", TrectH)
.attr("stroke", function (d) {
return d._children ? "blue" : "black";})
.attr("stroke-width", 1)
.style("fill", function (d) {
return d._children ? "lightcyan" : "#fff";});
nodeUpdate.select("text")
.style("fill-opacity", 1);
var nodeExit = node.exit().transition()
.duration(duration)
.attr("transform", function (d) {
return "translate(" + source.x + "," + source.y + ")";})
.remove();
nodeExit.select("rect")
.attr("width", rectW)
.attr("height", TrectH)
.attr("stroke", "black")
.attr("stroke-width", 1);
nodeExit.select("text");
var link = svg.selectAll("path.link")
.data(links, function (d) {
return d.target.id;});
link.enter().insert("path", "g")
.attr("class", "link")
.attr("x", rectW / 2)
.attr("y", rectH / 2)
.attr("d", function (d) {
var o = {
x: source.x0,
y: source.y0};
return elbow({
source: o,
target: o});});
link.transition()
.duration(duration)
.attr("d", elbow);
link.exit().transition()
.duration(duration)
.attr("d", function (d) {
var o = {
x: source.x,
y: source.y};
return elbow({
source: o,
target: o});})
.remove();
nodes.forEach(function (d) {
d.x0 = d.x;
d.y0 = d.y;});}
function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;}
update(d);}
function autocollapse(d) {
svg.selectAll("g.node").each(function(d) {
if (d.collapse==1) {
click(d);
}
})
}
function redraw() {
svg.attr("transform",
"translate(" + d3.event.translate + ")"
+ " scale(" + d3.event.scale + ")");}
function elbow(d) {
var sourceY = d.source.y+TrectH,
sourceX = d.source.x+rectW/2-2,
targetY = d.target.y+TrectH+20,
targetX = d.target.x+rectW/2-2;
return "M" + sourceX + "," + sourceY
+ "V" + (sourceY+targetY)/2
+ "H" + targetX
+ "V" + targetY;}
</script>