1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: wuihlpgraphsimple.py 69111 2017-10-17 14:26:02Z vboxsync $
|
---|
3 |
|
---|
4 | """
|
---|
5 | Test Manager Web-UI - Graph Helpers - Simple/Stub Implementation.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2012-2017 Oracle Corporation
|
---|
11 |
|
---|
12 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | available from http://www.virtualbox.org. This file is free software;
|
---|
14 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | General Public License (GPL) as published by the Free Software
|
---|
16 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 |
|
---|
20 | The contents of this file may alternatively be used under the terms
|
---|
21 | of the Common Development and Distribution License Version 1.0
|
---|
22 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
23 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
24 | CDDL are applicable instead of those of the GPL.
|
---|
25 |
|
---|
26 | You may elect to license modified versions of this file under the
|
---|
27 | terms and conditions of either the GPL or the CDDL or both.
|
---|
28 | """
|
---|
29 | __version__ = "$Revision: 69111 $"
|
---|
30 |
|
---|
31 | # Validation Kit imports.
|
---|
32 | from common.webutils import escapeAttr, escapeElem;
|
---|
33 | from testmanager.webui.wuihlpgraphbase import WuiHlpGraphBase;
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 | class WuiHlpBarGraph(WuiHlpGraphBase):
|
---|
38 | """
|
---|
39 | Bar graph.
|
---|
40 | """
|
---|
41 |
|
---|
42 | def __init__(self, sId, oData, oDisp = None):
|
---|
43 | WuiHlpGraphBase.__init__(self, sId, oData, oDisp);
|
---|
44 | self.cxMaxBar = 480;
|
---|
45 | self.fpMax = None;
|
---|
46 | self.fpMin = 0.0;
|
---|
47 |
|
---|
48 | def setRangeMax(self, fpMax):
|
---|
49 | """ Sets the max range."""
|
---|
50 | self.fpMax = float(fpMax);
|
---|
51 | return None;
|
---|
52 |
|
---|
53 | def renderGraph(self):
|
---|
54 | aoTable = self._oData.aoTable;
|
---|
55 | sReport = '<div class="tmbargraph">\n';
|
---|
56 |
|
---|
57 | # Figure the range.
|
---|
58 | fpMin = self.fpMin;
|
---|
59 | fpMax = self.fpMax;
|
---|
60 | if self.fpMax is None:
|
---|
61 | fpMax = float(aoTable[1].aoValues[0]);
|
---|
62 | for i in range(1, len(aoTable)):
|
---|
63 | for oValue in aoTable[i].aoValues:
|
---|
64 | fpValue = float(oValue);
|
---|
65 | if fpValue < fpMin:
|
---|
66 | fpMin = fpValue;
|
---|
67 | if fpValue > fpMax:
|
---|
68 | fpMax = fpValue;
|
---|
69 | assert fpMin >= 0;
|
---|
70 |
|
---|
71 | # Format the data.
|
---|
72 | sReport += '<table class="tmbargraphl1" border="1" id="%s">\n' % (escapeAttr(self._sId),);
|
---|
73 | for i in range(1, len(aoTable)):
|
---|
74 | oRow = aoTable[i];
|
---|
75 | sReport += ' <tr>\n' \
|
---|
76 | ' <td>%s</td>\n' \
|
---|
77 | ' <td height="100%%" width="%spx">\n' \
|
---|
78 | ' <table class="tmbargraphl2" height="100%%" width="100%%" ' \
|
---|
79 | 'border="0" cellspacing="0" cellpadding="0">\n' \
|
---|
80 | % (escapeElem(oRow.sName), escapeAttr(str(self.cxMaxBar + 2)));
|
---|
81 | for j in range(len(oRow.aoValues)):
|
---|
82 | oValue = oRow.aoValues[j];
|
---|
83 | cPct = int(float(oValue) * 100 / fpMax);
|
---|
84 | cxBar = int(float(oValue) * self.cxMaxBar / fpMax);
|
---|
85 | sValue = escapeElem(oRow.asValues[j]);
|
---|
86 | sColor = self.kasColors[j % len(self.kasColors)];
|
---|
87 | sInvColor = 'white';
|
---|
88 | if sColor[0] == '#' and len(sColor) == 7:
|
---|
89 | sInvColor = '#%06x' % (~int(sColor[1:],16) & 0xffffff,);
|
---|
90 |
|
---|
91 | sReport += ' <tr><td>\n' \
|
---|
92 | ' <table class="tmbargraphl3" height="100%%" border="0" cellspacing="0" cellpadding="0">\n' \
|
---|
93 | ' <tr>\n';
|
---|
94 | if cPct >= 99:
|
---|
95 | sReport += ' <td width="%spx" nowrap bgcolor="%s" align="right" style="color:%s;">' \
|
---|
96 | '%s </td>\n' \
|
---|
97 | % (cxBar, sColor, sInvColor, sValue);
|
---|
98 | elif cPct < 1:
|
---|
99 | sReport += ' <td width="%spx" nowrap style="color:%s;">%s</td>\n' \
|
---|
100 | % (self.cxMaxBar - cxBar, sColor, sValue);
|
---|
101 | elif cPct >= 50:
|
---|
102 | sReport += ' <td width="%spx" nowrap bgcolor="%s" align="right" style="color:%s;">' \
|
---|
103 | '%s </td>\n' \
|
---|
104 | ' <td width="%spx" nowrap><div> </div></td>\n' \
|
---|
105 | % (cxBar, sColor, sInvColor, sValue, self.cxMaxBar - cxBar);
|
---|
106 | else:
|
---|
107 | sReport += ' <td width="%spx" nowrap bgcolor="%s"></td>\n' \
|
---|
108 | ' <td width="%spx" nowrap> %s</td>\n' \
|
---|
109 | % (cxBar, sColor, self.cxMaxBar - cxBar, sValue);
|
---|
110 | sReport += ' </tr>\n' \
|
---|
111 | ' </table>\n' \
|
---|
112 | ' </td></tr>\n'
|
---|
113 | sReport += ' </table>\n' \
|
---|
114 | ' </td>\n' \
|
---|
115 | ' </tr>\n';
|
---|
116 | if i + 1 < len(aoTable) and len(oRow.aoValues) > 1:
|
---|
117 | sReport += ' <tr></tr>\n'
|
---|
118 |
|
---|
119 | sReport += '</table>\n';
|
---|
120 |
|
---|
121 | sReport += '<div class="tmgraphlegend">\n' \
|
---|
122 | ' <p>Legend:\n';
|
---|
123 | for j in range(len(aoTable[0].asValues)):
|
---|
124 | sColor = self.kasColors[j % len(self.kasColors)];
|
---|
125 | sReport += ' <font color="%s">■ %s</font>\n' \
|
---|
126 | % (sColor, escapeElem(aoTable[0].asValues[j]));
|
---|
127 | sReport += ' </p>\n' \
|
---|
128 | '</div>\n';
|
---|
129 |
|
---|
130 | sReport += '</div>\n';
|
---|
131 | return sReport;
|
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 | class WuiHlpLineGraph(WuiHlpGraphBase):
|
---|
137 | """
|
---|
138 | Line graph.
|
---|
139 | """
|
---|
140 |
|
---|
141 | def __init__(self, sId, oData, oDisp):
|
---|
142 | WuiHlpGraphBase.__init__(self, sId, oData, oDisp);
|
---|
143 |
|
---|
144 |
|
---|
145 | class WuiHlpLineGraphErrorbarY(WuiHlpLineGraph):
|
---|
146 | """
|
---|
147 | Line graph with an errorbar for the Y axis.
|
---|
148 | """
|
---|
149 |
|
---|
150 | pass;
|
---|
151 |
|
---|