-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathenvTable.js
More file actions
executable file
·142 lines (130 loc) · 4.49 KB
/
envTable.js
File metadata and controls
executable file
·142 lines (130 loc) · 4.49 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
/*******************************************************************************
* Copyright 2017 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
// Table for displaying environment parameters
// Width of environment div
var envDivCanvasWidth = $('#envDiv').width() - 8;
var tableRowHeight = 30;
var tableRowWidth = 170;
// Define the environment chart space
var envSVG = d3.select('#envDiv')
.append('svg')
.attr('width', envDivCanvasWidth)
.attr('height', canvasHeight)
.attr('class', 'envData');
var envTitleBox = envSVG.append('rect')
.attr('width', envDivCanvasWidth)
.attr('height', 30)
.attr('class', 'titlebox');
envSVG.append('text')
.attr('x', 7)
.attr('y', 15)
.attr('dominant-baseline', 'central')
.style('font-size', '18px')
.text(localizedStrings.envTitle);
var paragraph = envSVG.append('g')
.attr('class', 'envGroup')
.attr('transform',
'translate(' + 20 + ',' + (margin.top + 10) + ')');
var envTableIsFullScreen = false;
// Add the maximise button
var envResize = envSVG.append('image')
.attr('x', envDivCanvasWidth - 30)
.attr('y', 4)
.attr('width', 24)
.attr('height', 24)
.attr('xlink:href', 'graphmetrics/images/maximize_24_grey.png')
.attr('class', 'maximize')
.on('click', function(){
envTableIsFullScreen = !envTableIsFullScreen;
d3.selectAll('.hideable').classed('invisible', envTableIsFullScreen);
d3.select('#envDiv')
.classed('fullscreen', envTableIsFullScreen)
.classed('invisible', false); // remove invisible from this chart
if (envTableIsFullScreen) {
d3.select('.envData .maximize')
.attr('xlink:href', 'graphmetrics/images/minimize_24_grey.png');
// Redraw this chart only
resizeEnvTable();
} else {
d3.select('.envData .maximize')
.attr('xlink:href', 'graphmetrics/images/maximize_24_grey.png');
canvasHeight = 250;
// Redraw all
resize();
}
})
.on('mouseover', function() {
if (envTableIsFullScreen) {
d3.select('.envData .maximize')
.attr('xlink:href', 'graphmetrics/images/minimize_24.png');
} else {
d3.select('.envData .maximize')
.attr('xlink:href', 'graphmetrics/images/maximize_24.png');
}
})
.on('mouseout', function() {
if (envTableIsFullScreen) {
d3.select('.envData .maximize')
.attr('xlink:href', 'graphmetrics/images/minimize_24_grey.png');
} else {
d3.select('.envData .maximize')
.attr('xlink:href', 'graphmetrics/images/maximize_24_grey.png');
}
});
function populateEnvTable(envRequestData) {
var envData = JSON.parse(envRequestData);
if (envData == null) return;
function tabulate(data) {
// create a row for each object in the data
var rows = paragraph.selectAll('text')
.data(data)
.enter()
.append('text')
.style('font-size', '14px')
.attr('transform', function(d, i) {
return 'translate(0,' + (i * tableRowHeight) + ')';
});
// create a cell in each row for each column
rows.selectAll('tspan')
.data(function(row) {
return ['Parameter', 'Value'].map(function(column) {
return {column: column, value: row[column]};
});
})
.enter()
.append('tspan')
.attr('x', function(d, i) {
return i * tableRowWidth; // indent second element for each row
})
.text(function(d) { return d.value; });
}
// render the table(s)
tabulate(envData); // 2 column table
}
function resizeEnvTable() {
envDivCanvasWidth = $('#envDiv').width() - 8; // -8 for margins and borders
if (envTableIsFullScreen) {
canvasHeight = $('#envDiv').height() - 100;
}
envResize
.attr('x', envDivCanvasWidth - 30)
.attr('y', 4);
envSVG
.attr('width', envDivCanvasWidth)
.attr('height', canvasHeight);
envTitleBox
.attr('width', envDivCanvasWidth);
}