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