1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: wuihlpgraph.py 79087 2019-06-11 11:58:28Z vboxsync $
|
---|
3 |
|
---|
4 | """
|
---|
5 | Test Manager Web-UI - Graph Helpers.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2012-2019 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: 79087 $"
|
---|
30 |
|
---|
31 |
|
---|
32 | class WuiHlpGraphDataTable(object): # pylint: disable=too-few-public-methods
|
---|
33 | """
|
---|
34 | Data table container.
|
---|
35 | """
|
---|
36 |
|
---|
37 | class Row(object): # pylint: disable=too-few-public-methods
|
---|
38 | """A row."""
|
---|
39 | def __init__(self, sGroup, aoValues, asValues = None):
|
---|
40 | self.sName = sGroup;
|
---|
41 | self.aoValues = aoValues;
|
---|
42 | if asValues is None:
|
---|
43 | self.asValues = [str(oVal) for oVal in aoValues];
|
---|
44 | else:
|
---|
45 | assert len(asValues) == len(aoValues);
|
---|
46 | self.asValues = asValues;
|
---|
47 |
|
---|
48 | def __init__(self, sGroupLable, asMemberLabels):
|
---|
49 | self.aoTable = [ WuiHlpGraphDataTable.Row(sGroupLable, asMemberLabels), ];
|
---|
50 |
|
---|
51 | def addRow(self, sGroup, aoValues, asValues = None):
|
---|
52 | """Adds a row to the data table."""
|
---|
53 | self.aoTable.append(WuiHlpGraphDataTable.Row(sGroup, aoValues, asValues));
|
---|
54 | return True;
|
---|
55 |
|
---|
56 | def getGroupCount(self):
|
---|
57 | """Gets the number of data groups (rows)."""
|
---|
58 | return len(self.aoTable) - 1;
|
---|
59 |
|
---|
60 |
|
---|
61 | class WuiHlpGraphDataTableEx(object): # pylint: disable=too-few-public-methods
|
---|
62 | """
|
---|
63 | Data container for an table/graph with optional error bars on the Y values.
|
---|
64 | """
|
---|
65 |
|
---|
66 | class DataSeries(object): # pylint: disable=too-few-public-methods
|
---|
67 | """
|
---|
68 | A data series.
|
---|
69 |
|
---|
70 | The aoXValues, aoYValues and aoYErrorBars are parallel arrays, making a
|
---|
71 | series of (X,Y,Y-err-above-delta,Y-err-below-delta) points.
|
---|
72 |
|
---|
73 | The error bars are optional.
|
---|
74 | """
|
---|
75 | def __init__(self, sName, aoXValues, aoYValues, asHtmlTooltips = None, aoYErrorBarBelow = None, aoYErrorBarAbove = None):
|
---|
76 | self.sName = sName;
|
---|
77 | self.aoXValues = aoXValues;
|
---|
78 | self.aoYValues = aoYValues;
|
---|
79 | self.asHtmlTooltips = asHtmlTooltips;
|
---|
80 | self.aoYErrorBarBelow = aoYErrorBarBelow;
|
---|
81 | self.aoYErrorBarAbove = aoYErrorBarAbove;
|
---|
82 |
|
---|
83 | def __init__(self, sXUnit, sYUnit):
|
---|
84 | self.sXUnit = sXUnit;
|
---|
85 | self.sYUnit = sYUnit;
|
---|
86 | self.aoSeries = [];
|
---|
87 |
|
---|
88 | def addDataSeries(self, sName, aoXValues, aoYValues, asHtmlTooltips = None, aoYErrorBarBelow = None, aoYErrorBarAbove = None):
|
---|
89 | """Adds an data series to the table."""
|
---|
90 | self.aoSeries.append(WuiHlpGraphDataTableEx.DataSeries(sName, aoXValues, aoYValues, asHtmlTooltips,
|
---|
91 | aoYErrorBarBelow, aoYErrorBarAbove));
|
---|
92 | return True;
|
---|
93 |
|
---|
94 | def getDataSeriesCount(self):
|
---|
95 | """Gets the number of data series."""
|
---|
96 | return len(self.aoSeries);
|
---|
97 |
|
---|
98 |
|
---|
99 | #
|
---|
100 | # Dynamically choose implementation.
|
---|
101 | #
|
---|
102 | if True: # pylint: disable=using-constant-test
|
---|
103 | from testmanager.webui import wuihlpgraphgooglechart as GraphImplementation;
|
---|
104 | else:
|
---|
105 | try:
|
---|
106 | import matplotlib; # pylint: disable=unused-import,import-error,import-error,wrong-import-order
|
---|
107 | from testmanager.webui import wuihlpgraphmatplotlib as GraphImplementation; # pylint: disable=ungrouped-imports
|
---|
108 | except:
|
---|
109 | from testmanager.webui import wuihlpgraphsimple as GraphImplementation;
|
---|
110 |
|
---|
111 | # pylint: disable=invalid-name
|
---|
112 | WuiHlpBarGraph = GraphImplementation.WuiHlpBarGraph;
|
---|
113 | WuiHlpLineGraph = GraphImplementation.WuiHlpLineGraph;
|
---|
114 | WuiHlpLineGraphErrorbarY = GraphImplementation.WuiHlpLineGraphErrorbarY;
|
---|
115 |
|
---|