cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTest Manager Web-UI - Graph Helpers.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__copyright__ = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2012-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__version__ = "$Revision$"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass WuiHlpGraphDataTable(object): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Data table container.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync class Row(object): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """A row."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, sGroup, aoValues, asValues = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sName = sGroup;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoValues = aoValues;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if asValues is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.asValues = [str(oVal) for oVal in aoValues];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync assert len(asValues) == len(aoValues);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.asValues = asValues;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, sGroupLable, asMemberLabels):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoTable = [ WuiHlpGraphDataTable.Row(sGroupLable, asMemberLabels), ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addRow(self, sGroup, aoValues, asValues = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Adds a row to the data table."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoTable.append(WuiHlpGraphDataTable.Row(sGroup, aoValues, asValues));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getGroupCount(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Gets the number of data groups (rows)."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return len(self.aoTable) - 1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass WuiHlpGraphDataTableEx(object): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Data container for an table/graph with optional error bars on the Y values.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync class DataSeries(object): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync A data series.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The aoXValues, aoYValues and aoYErrorBars are parallel arrays, making a
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync series of (X,Y,Y-err-above-delta,Y-err-below-delta) points.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The error bars are optional.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, sName, aoXValues, aoYValues, asHtmlTooltips = None, aoYErrorBarBelow = None, aoYErrorBarAbove = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sName = sName;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoXValues = aoXValues;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoYValues = aoYValues;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.asHtmlTooltips = asHtmlTooltips;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoYErrorBarBelow = aoYErrorBarBelow;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoYErrorBarAbove = aoYErrorBarAbove;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, sXUnit, sYUnit):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sXUnit = sXUnit;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sYUnit = sYUnit;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoSeries = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addDataSeries(self, sName, aoXValues, aoYValues, asHtmlTooltips = None, aoYErrorBarBelow = None, aoYErrorBarAbove = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Adds an data series to the table."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoSeries.append(WuiHlpGraphDataTableEx.DataSeries(sName, aoXValues, aoYValues, asHtmlTooltips,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoYErrorBarBelow, aoYErrorBarAbove));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getDataSeriesCount(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Gets the number of data series."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return len(self.aoSeries);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync#
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Dynamically choose implementation.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync#
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncif True:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync from testmanager.webui import wuihlpgraphgooglechart as GraphImplementation;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncelse:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync import matplotlib; # pylint: disable=W0611,F0401
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync from testmanager.webui import wuihlpgraphmatplotlib as GraphImplementation;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync from testmanager.webui import wuihlpgraphsimple as GraphImplementation;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# pylint: disable=C0103
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncWuiHlpBarGraph = GraphImplementation.WuiHlpBarGraph;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncWuiHlpLineGraph = GraphImplementation.WuiHlpLineGraph;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncWuiHlpLineGraphErrorbarY = GraphImplementation.WuiHlpLineGraphErrorbarY;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync