wuihlpgraphmatplotlib.py revision cf22150eaeeb72431bf1cf65c309a431454fb22b
af062818b47340eef15700d2f0211576ba3506eevboxsync# -*- coding: utf-8 -*-
af062818b47340eef15700d2f0211576ba3506eevboxsyncTest Manager Web-UI - Graph Helpers - Implemented using matplotlib.
af062818b47340eef15700d2f0211576ba3506eevboxsyncCopyright (C) 2012-2014 Oracle Corporation
af062818b47340eef15700d2f0211576ba3506eevboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
af062818b47340eef15700d2f0211576ba3506eevboxsyncavailable from http://www.virtualbox.org. This file is free software;
af062818b47340eef15700d2f0211576ba3506eevboxsyncyou can redistribute it and/or modify it under the terms of the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsyncGeneral Public License (GPL) as published by the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
af062818b47340eef15700d2f0211576ba3506eevboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
af062818b47340eef15700d2f0211576ba3506eevboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsyncThe contents of this file may alternatively be used under the terms
4b9d6701570cb98fd36e209314239d104ec584d3vboxsyncof the Common Development and Distribution License Version 1.0
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsyncVirtualBox OSE distribution, in which case the provisions of the
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsyncCDDL are applicable instead of those of the GPL.
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsyncYou may elect to license modified versions of this file under the
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsyncterms and conditions of either the GPL or the CDDL or both.
af062818b47340eef15700d2f0211576ba3506eevboxsync# Standard Python Import and extensions installed on the system.
af062818b47340eef15700d2f0211576ba3506eevboxsyncfrom numpy import arange as numpy_arange; # pylint: disable=E0611
af062818b47340eef15700d2f0211576ba3506eevboxsync# Validation Kit imports.
af062818b47340eef15700d2f0211576ba3506eevboxsyncfrom testmanager.webui.wuihlpgraphbase import WuiHlpGraphBase;
af062818b47340eef15700d2f0211576ba3506eevboxsync """ Base class for the matplotlib graphs. """
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync """ Enables xkcd style graphs for implementations that supports it. """
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync Wrapper around matplotlib.pyplot.figure that feeds the figure the
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync basic graph configuration.
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync if self._fXkcdStyle and matplotlib.__version__ > '1.2.9':
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync matplotlib.rcParams.update({'font.size': self._cPtFont});
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync oFigure = matplotlib.pyplot.figure(figsize = (float(self._cxGraph) / self._cDpiGraph,
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync def _produceSvg(self, oFigure, fTightLayout = True):
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync """ Creates an SVG string from the given figure. """
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync if self._oDisp and self._oDisp.isBrowserGecko('20100101'):
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync # This browser will stretch images to fit if no size or width is given.
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync sSubstitute = r'\1 \3 reserveAspectRatio="xMidYMin meet"';
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync # Chrome and IE likes to have the sizes as well as the viewBox.
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync sSubstitute = r'\1 \3 reserveAspectRatio="xMidYMin meet" \2 \4';
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync return re.sub(r'(<svg) (height="\d+pt") (version="\d+.\d+" viewBox="\d+ \d+ \d+ \d+") (width="\d+pt")',
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync WuiHlpGraphMatplotlibBase.__init__(self, sId, oData, oDisp);
af062818b47340eef15700d2f0211576ba3506eevboxsync """ Sets the max range."""
5112e32d7072e280613921c982a6672f2c859cf3vboxsync return None;
5112e32d7072e280613921c982a6672f2c859cf3vboxsync # Extract/structure the required data.
5112e32d7072e280613921c982a6672f2c859cf3vboxsync oXRange = numpy_arange(self._oData.getGroupCount());
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync self.cxBarWidth = 1.0 / (len(aoTable[0].asValues) + 1.1);
af062818b47340eef15700d2f0211576ba3506eevboxsync # Render the PNG.
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync aoBars.append(oSubPlot.bar(oXRange + self.cxBarWidth * i,
af062818b47340eef15700d2f0211576ba3506eevboxsync #oSubPlot.set_title('Title')
af062818b47340eef15700d2f0211576ba3506eevboxsync #oSubPlot.set_xlabel('X-axis')
af062818b47340eef15700d2f0211576ba3506eevboxsync #oSubPlot.set_xticks(oXRange + self.cxBarWidth);
af062818b47340eef15700d2f0211576ba3506eevboxsync oLegend = oSubPlot.legend(aoTable[0].asValues, loc = 'best', fancybox = True);
af062818b47340eef15700d2f0211576ba3506eevboxsync #oSubPlot.set_ylabel('Y-axis')
af062818b47340eef15700d2f0211576ba3506eevboxsync oSubPlot.set_yticks(numpy_arange(fpMin, fpMax + (fpMax - fpMin) / 10 * 0, fpMax / 10));
af062818b47340eef15700d2f0211576ba3506eevboxsync oSubPlot.text(oRect.get_x() + oRect.get_width() / 2.0,
af062818b47340eef15700d2f0211576ba3506eevboxsync ha = 'center', va = 'bottom', rotation = 'vertical', alpha = 0.6, fontsize = 'small');
af062818b47340eef15700d2f0211576ba3506eevboxsync oSubPlot.text(oRect.get_x() + oRect.get_width() / 2.0,
af062818b47340eef15700d2f0211576ba3506eevboxsync ha = 'center', va = 'top', rotation = 'vertical', alpha = 0.6, fontsize = 'small');
af062818b47340eef15700d2f0211576ba3506eevboxsync Line graph.
af062818b47340eef15700d2f0211576ba3506eevboxsync def __init__(self, sId, oData, oDisp = None, fErrorBarY = False):
af062818b47340eef15700d2f0211576ba3506eevboxsync # oData must be a WuiHlpGraphDataTableEx like object.
af062818b47340eef15700d2f0211576ba3506eevboxsync WuiHlpGraphMatplotlibBase.__init__(self, sId, oData, oDisp);
af062818b47340eef15700d2f0211576ba3506eevboxsync """ Enables or Disables error bars, making this work like a line graph. """
af062818b47340eef15700d2f0211576ba3506eevboxsync oSubPlot.errorbar(oSeries.aoXValues, oSeries.aoYValues, color = sColor);
af062818b47340eef15700d2f0211576ba3506eevboxsync oSubPlot.errorbar(oSeries.aoXValues, oSeries.aoYValues, color = sColor);
af062818b47340eef15700d2f0211576ba3506eevboxsync oSubPlot.errorbar(oSeries.aoXValues, oSeries.aoYValues,
af062818b47340eef15700d2f0211576ba3506eevboxsync yerr = [oSeries.aoYErrorBarBelow, oSeries.aoYErrorBarAbove],
af062818b47340eef15700d2f0211576ba3506eevboxsync errorevery = len(oSeries.aoXValues) / self._cMaxErrorBars,
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync oSubPlot.errorbar(oSeries.aoXValues, oSeries.aoYValues,
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync yerr = [oSeries.aoYErrorBarBelow, oSeries.aoYErrorBarAbove],
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync oLegend = oSubPlot.legend([oSeries.sName for oSeries in aoSeries], loc = 'best', fancybox = True);
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync # oSubPlot.axis('off');
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync #oSubPlot.grid(True, 'major', axis = 'none');
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync #oSubPlot.grid(True, 'both', axis = 'none');
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync matplotlib.pyplot.setp(oSubPlot, xticks = [], yticks = []);
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync Line graph with an errorbar for the Y axis.
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync WuiHlpLineGraph.__init__(self, sId, oData, fErrorBarY = True);
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsyncclass WuiHlpMiniSuccessRateGraph(WuiHlpGraphMatplotlibBase):
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync Mini rate graph.
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync oData must be a WuiHlpGraphDataTableEx like object, but only aoSeries,
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync aoSeries[].aoXValues, and aoSeries[].aoYValues will be used. The
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync values are expected to be a percentage, i.e. values between 0 and 100.
ee6bcfc59fe3b0230aad85e2ef63d0402b7719b2vboxsync WuiHlpGraphMatplotlibBase.__init__(self, sId, oData, oDisp);
af062818b47340eef15700d2f0211576ba3506eevboxsync #self.setWidth(512);
af062818b47340eef15700d2f0211576ba3506eevboxsync #self.setHeight(128);
af062818b47340eef15700d2f0211576ba3506eevboxsync from mpl_toolkits.axes_grid.axislines import SubplotZero;
af062818b47340eef15700d2f0211576ba3506eevboxsync # Disable all the normal axis.
af062818b47340eef15700d2f0211576ba3506eevboxsync # Use the zero axis instead.
af062818b47340eef15700d2f0211576ba3506eevboxsync oAxis.plot(oSeries.aoXValues, oSeries.aoYValues, '.-', color = sColor, linewidth = 3);
af062818b47340eef15700d2f0211576ba3506eevboxsync oAxis.fill_between(oSeries.aoXValues, oSeries.aoYValues, facecolor = sColor, alpha = 0.5)
af062818b47340eef15700d2f0211576ba3506eevboxsync #oAxis.set_yticklabels([]);