Changeset 82645 in vbox for trunk/src/VBox
- Timestamp:
- Dec 23, 2019 2:41:05 PM (5 years ago)
- Location:
- trunk/src/VBox/ValidationKit/testmanager/webui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testmanager/webui/wuihlpgraph.py
r79087 r82645 48 48 def __init__(self, sGroupLable, asMemberLabels): 49 49 self.aoTable = [ WuiHlpGraphDataTable.Row(sGroupLable, asMemberLabels), ]; 50 self.fHasStringValues = False; 50 51 51 52 def addRow(self, sGroup, aoValues, asValues = None): 52 53 """Adds a row to the data table.""" 54 if asValues: 55 self.fHasStringValues = True; 53 56 self.aoTable.append(WuiHlpGraphDataTable.Row(sGroup, aoValues, asValues)); 54 57 return True; -
trunk/src/VBox/ValidationKit/testmanager/webui/wuihlpgraphgooglechart.py
r79092 r82645 30 30 31 31 # Validation Kit imports. 32 from common import webutils;32 from common import utils, webutils; 33 33 from testmanager.webui.wuihlpgraphbase import WuiHlpGraphBase; 34 from testmanager.webui import wuihlpgraphsimple;35 34 36 35 … … 45 44 46 45 47 ## @todo bar graphs later. 48 WuiHlpBarGraph = wuihlpgraphsimple.WuiHlpBarGraph; 46 class WuiHlpBarGraph(WuiHlpGraphGoogleChartsBase): 47 """ 48 Bar graph. 49 """ 50 51 def __init__(self, sId, oData, oDisp = None): 52 WuiHlpGraphGoogleChartsBase.__init__(self, sId, oData, oDisp); 53 self.fpMax = None; 54 self.fpMin = 0.0; 55 56 def setRangeMax(self, fpMax): 57 """ Sets the max range.""" 58 self.fpMax = float(fpMax); 59 return None; 60 61 def renderGraph(self): 62 aoTable = self._oData.aoTable; # type: WuiHlpGraphDataTable 63 64 # Unique on load function. 65 global g_cGraphs; 66 iGraph = g_cGraphs; 67 g_cGraphs += 1; 68 69 sHtml = '<div id="%s">\n' % ( self._sId, ); 70 sHtml += '<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>\n' \ 71 '<script type="text/javascript">\n' \ 72 'google.charts.load("current", { packages: ["corechart", "bar"] });\n' \ 73 'google.setOnLoadCallback(tmDrawBarGraph%u);\n' \ 74 'function tmDrawBarGraph%u()\n' \ 75 '{\n' \ 76 ' var oGraph;\n' \ 77 ' var dGraphOptions = \n' \ 78 ' {\n' \ 79 ' "title": "%s",\n' \ 80 ' "hAxis": {\n' \ 81 ' "title": "%s",\n' \ 82 ' },\n' \ 83 ' };\n' \ 84 % ( iGraph, 85 iGraph, 86 webutils.escapeAttrJavaScriptStringDQ(self._sTitle) if self._sTitle is not None else '', 87 webutils.escapeAttrJavaScriptStringDQ(aoTable[0].sName) if aoTable and aoTable[0].sName else '', 88 ); 89 90 # The data. 91 if self._oData.fHasStringValues and len(aoTable) > 1: 92 sHtml += ' var oData = new google.visualization.DataTable();\n'; 93 # Column definitions. 94 sHtml += ' oData.addColumn("string", "%s");\n' \ 95 % (webutils.escapeAttrJavaScriptStringDQ(aoTable[0].sName) if aoTable[0].sName else '',); 96 for iValue, oValue in enumerate(aoTable[0].aoValues): 97 oSampleValue = aoTable[1].aoValues[iValue]; 98 if utils.isString(oSampleValue): 99 sHtml += ' oData.addColumn("string", "%s");\n' % (webutils.escapeAttrJavaScriptStringDQ(oValue),); 100 else: 101 sHtml += ' oData.addColumn("number", "%s");\n' % (webutils.escapeAttrJavaScriptStringDQ(oValue),); 102 sHtml += ' oData.addColumn({type: "string", role: "annotation"});\n'; 103 # The data rows. 104 sHtml += ' oData.addRows([\n'; 105 for oRow in aoTable[1:]: 106 sRow = ' [ "%s"' % (webutils.escapeAttrJavaScriptStringDQ(oRow.sName),); 107 for iValue, oValue in enumerate(oRow.aoValues): 108 if not utils.isString(oValue): 109 sRow += ', %s' % (oValue,); 110 else: 111 sRow += ', "%s"' % (webutils.escapeAttrJavaScriptStringDQ(oValue),); 112 if oRow.asValues[iValue]: 113 sRow += ', "%s"' % (webutils.escapeAttrJavaScriptStringDQ(oRow.asValues[iValue]),); 114 else: 115 sRow += ', null'; 116 sHtml += sRow + '],\n'; 117 sHtml += ' ]);\n'; 118 else: 119 sHtml += ' var oData = google.visualization.arrayToDataTable([\n'; 120 for oRow in aoTable: 121 sRow = ' [ "%s"' % (webutils.escapeAttrJavaScriptStringDQ(oRow.sName),); 122 for oValue in oRow.aoValues: 123 if utils.isString(oValue): 124 sRow += ', "%s"' % (webutils.escapeAttrJavaScriptStringDQ(oValue),); 125 else: 126 sRow += ', %s' % (oValue,); 127 sHtml += sRow + '],\n'; 128 sHtml += ' ]);\n'; 129 130 # Create and draw. 131 sHtml += ' oGraph = new google.visualization.ColumnChart(document.getElementById("%s"));\n' \ 132 ' oGraph.draw(oData, dGraphOptions);\n' \ 133 % ( self._sId, ); 134 135 # clean and return. 136 sHtml += ' oData = null;\n' \ 137 ' return true;\n' \ 138 '};\n'; 139 140 sHtml += '</script>\n' \ 141 '</div>\n'; 142 return sHtml; 49 143 50 144
Note:
See TracChangeset
for help on using the changeset viewer.