-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsankey2.html
190 lines (186 loc) · 6.52 KB
/
sankey2.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/pms.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/plotly-2.24.1.min.js"></script>
<script src="js/fast-stats.js"></script>
<script src="js/sfunc.js"></script>
<script src="js/sprintf.js"></script>
<script src="js/readers.js"></script>
<script src="js/d3.v7.min.js"></script>
<title>Template Title</title>
</head>
<body>
<table>
<tr>
<td>Titel</td><td><input type="text" id="title" value="Massenströme Jessen" /></td></td>
</tr>
<tr>
<td>Daten</td>
<td>
<textarea id="tdata">
Molkelinie;UF;80.0
RO;UF; 10.0
UF;HK-3; 2.5
UF;RO; 87.5
RO;MVR;29.5
RO;Polisher;48.5
MVR;PE-50;11.8
MVR;Brüden;17.7
PE-50;HK-1;11.8
HK-1;PE-70;8.4
HK-1;Brüden;3.4
</textarea>
</td>
</tr>
<tr>
<td><button onclick="makeDiag()">Make</button></td>
<td><button onclick="makeImg('myDiv', 'jpg-export')">Copy</button></td>
</tr>
<tr>
<td>Width</td><td><input type="number" id="cWidth" value="600" onchange="cHWChange()" /></td>
</tr>
<tr>
<td>Height</td><td><input type="number" id="cHeight" value="300" onchange="cHWChange()" /></td>
</tr>
<tr>
<button onclick="makeDiag()">Make</button>
</tr>
</table>
<p>
<div id='myDiv' class="resizable" onresize="doResize(this)"></div>
<br>
</p>
<img id="jpg-export"></img>
</body>
<script>
function loadJSON(filename, callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
// Replace 'my_data' with the path to your file
xobj.open('GET', filename, false);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as
// .open will NOT return a value but simply
// returns undefined in asynchronous mode
callback(xobj.responseText);
}
};
xobj.send(null);
}
/**
Helper functions to simplify entry of flow data.
First variable is the list that holds the principal data,
src and dst are the names of the two nodes, and amount is the
value flowing from src to dst.
*/
function enter_pair(list, src, dst, amount){
list.push({src: src, dst: dst, amount: amount});
}
/**
* Re-arange data from list above into nodes and link, so
* that it can be munched by plotly.
*/
function gobble(list, nodes, link){
list.forEach(function(entry){
if(-1== nodes.indexOf(entry.src)){
nodes.push(entry.src);
}
if(-1== nodes.indexOf(entry.dst)){
nodes.push(entry.dst);
}
let si = nodes.indexOf(entry.src);
let di = nodes.indexOf(entry.dst);
link.source.push(si);
link.target.push(di);
link.value.push(entry.amount);
});
}
function makeDiag(){
let values = [];
let link = { source: [], target: [], value: [] };
let label = [];
let nodes = [];
let title = document.getElementById('title').value;
let tdata = document.getElementById('tdata').value.split('\n');
console.log(title);
//console.log(tdata);
tdata.forEach(function(line){
// Check for '#'
let wLine = line.split('#')[0];
// Separator: Semikolon, Tab, oder Pipe
let cells = wLine.split(RegExp('[;|/\t]'));
//console.log('Entries: '+cells[0]+', '+cells[1]+', '+cells[2]);
if(cells.length == 3){
enter_pair(values, cells[0], cells[1], Number(cells[2]));
}
});
gobble(values, nodes, link);
var layout = {"title": title}
Plotly.newPlot('myDiv',
[{
type: "sankey",
arrangement: 'freeform',
domain: {
x: [0,1],
y: [0,1]
},
valueformat: ".1f",
valuesuffix: "t/h",
node:{
label: nodes,
pad:10, // 10 Pixels
},
link: link,
}],
layout,
{editable: true, responsive: true},
);
}
function cHWChange(){
let W = document.getElementById('cWidth').value;
let H = document.getElementById('cHeight').value;
document.getElementById('myDiv').setAttribute("style","Width:"+ W +'px;Height:'+ H+'px');
}
/*
let values = [];
let link = { source: [], target: [], value: [] };
let label = [];
let nodes = [];
enter_pair(values, 'Molkelinie', 'UF', 80.0);
enter_pair(values, 'RO', 'UF', 10.0);
enter_pair(values, 'UF', 'HK-3', 2.5);
enter_pair(values, 'UF', 'RO', 87.5);
enter_pair(values, 'RO', 'MVR', 29.5);
enter_pair(values, 'RO', 'Polisher', 48.5);
enter_pair(values, 'MVR', 'PE-50', 11.8);
enter_pair(values, 'MVR', 'Brüden', 17.7);
enter_pair(values, 'PE-50', 'HK-1', 11.8);
enter_pair(values, 'HK-1', 'PE-70', 8.4);
enter_pair(values, 'HK-1', 'Brüden', 3.4);
gobble(values, nodes, link);
var layout = {"title": "Massenströme TP-Jessen"}
Plotly.newPlot('myDiv',
[{
type: "sankey",
arrangement: 'freeform',
domain: {
x: [0,1],
y: [0,1]
},
valueformat: ".1f",
valuesuffix: "t/h",
node:{
label: nodes,
pad:10, // 10 Pixels
},
link: link,
}],
layout);
*/
</script>
</html>