# -*- coding: utf-8 -*- # $Id: wuihlpgraphgooglechart.py $ """ Test Manager Web-UI - Graph Helpers - Implemented using Google Charts. """ __copyright__ = \ """ Copyright (C) 2012-2023 Oracle and/or its affiliates. This file is part of VirtualBox base platform packages, as available from https://www.virtualbox.org. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, in version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . The contents of this file may alternatively be used under the terms of the Common Development and Distribution License Version 1.0 (CDDL), a copy of it is provided in the "COPYING.CDDL" file included in the VirtualBox distribution, in which case the provisions of the CDDL are applicable instead of those of the GPL. You may elect to license modified versions of this file under the terms and conditions of either the GPL or the CDDL or both. SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 """ __version__ = "$Revision: 155244 $" # Validation Kit imports. from common import utils, webutils; from testmanager.webui.wuihlpgraphbase import WuiHlpGraphBase; #******************************************************************************* #* Global Variables * #******************************************************************************* g_cGraphs = 0; class WuiHlpGraphGoogleChartsBase(WuiHlpGraphBase): """ Base class for the Google Charts graphs. """ pass; # pylint: disable=unnecessary-pass class WuiHlpBarGraph(WuiHlpGraphGoogleChartsBase): """ Bar graph. """ def __init__(self, sId, oData, oDisp = None): WuiHlpGraphGoogleChartsBase.__init__(self, sId, oData, oDisp); self.fpMax = None; self.fpMin = 0.0; self.fYInverted = False; def setRangeMax(self, fpMax): """ Sets the max range.""" self.fpMax = float(fpMax); return None; def invertYDirection(self): """ Inverts the direction of the Y-axis direction. """ self.fYInverted = True; return None; def renderGraph(self): aoTable = self._oData.aoTable # type: WuiHlpGraphDataTable # Seems material (google.charts.Bar) cannot change the direction on the Y-axis, # so we cannot get bars growing downwards from the top like we want for the # reports. The classic charts OTOH cannot put X-axis labels on the top, but # we just drop them all together instead, saving a little space. fUseMaterial = False; # Unique on load function. global g_cGraphs; iGraph = g_cGraphs; g_cGraphs += 1; sHtml = '
\n' % ( self._sId, ); sHtml += '\n' \ '\n' \ '
\n'; return sHtml; class WuiHlpLineGraph(WuiHlpGraphGoogleChartsBase): """ Line graph. """ ## @todo implement error bars. kfNoErrorBarsSupport = True; def __init__(self, sId, oData, oDisp = None, fErrorBarY = False): # oData must be a WuiHlpGraphDataTableEx like object. WuiHlpGraphGoogleChartsBase.__init__(self, sId, oData, oDisp); self._cMaxErrorBars = 12; self._fErrorBarY = fErrorBarY; def setErrorBarY(self, fEnable): """ Enables or Disables error bars, making this work like a line graph. """ self._fErrorBarY = fEnable; return True; def renderGraph(self): # pylint: disable=too-many-locals fSlideFilter = True; # Tooltips? cTooltips = 0; for oSeries in self._oData.aoSeries: cTooltips += oSeries.asHtmlTooltips is not None; # Unique on load function. global g_cGraphs; iGraph = g_cGraphs; g_cGraphs += 1; sHtml = '
\n' % ( self._sId, ); if fSlideFilter: sHtml += '
\n' \ % ( self._sId, self._sId, ); sHtml += '\n' \ '\n' \ '
\n'; return sHtml; class WuiHlpLineGraphErrorbarY(WuiHlpLineGraph): """ Line graph with an errorbar for the Y axis. """ def __init__(self, sId, oData, oDisp = None): WuiHlpLineGraph.__init__(self, sId, oData, fErrorBarY = True);