def AddLine(self, points, label=None, color=None, pattern=LineStyle.SOLID, width=LineStyle.THIN, markers=None): """Add a new line to the chart. This is a convenience method which constructs the DataSeries and appends it for you. It returns the new series. points: List of equally-spaced y-values for the line label: Name of the line (used for the legend) color: Hex string, like 'ff0000' for red pattern: Tuple for (length of segment, length of gap). i.e. LineStyle.DASHED width: Width of the line (i.e. LineStyle.THIN) markers: List of Marker objects to attach to this line (see DataSeries for more info) """ if color is not None and isinstance(color[0], common.Marker): warnings.warn( 'Your code may be broken! ' 'You passed a list of Markers instead of a color. The ' 'old argument order (markers before color) is deprecated.', DeprecationWarning, stacklevel=2) style = LineStyle(width, pattern[0], pattern[1], color=color) series = common.DataSeries(points, label=label, style=style, markers=markers) self.data.append(series) return series
def testDataSeriesStyles(self): # Deprecated approach warnings.filterwarnings('error') self.assertRaises(DeprecationWarning, common.DataSeries, [1, 2, 3], color='0000FF') warnings.filterwarnings('ignore') d = common.DataSeries([1, 2, 3], color='0000FF') self.assertEqual('0000FF', d.color) d.color = 'F00' self.assertEqual('F00', d.color)
def testDataSeriesArgumentOrder(self): # Deprecated approach warnings.filterwarnings('error') self.assertRaises(DeprecationWarning, common.DataSeries, [1, 2, 3], '0000FF', 'style') # New order style = common._BasicStyle('0000FF') d = common.DataSeries([1, 2, 3], 'label', style) self.assertEqual('label', d.label) self.assertEqual(style, d.style)
def testLineStyleByValueGivesWarning(self): """Using LineStyle.foo as a value should throw a deprecation warning""" warnings.filterwarnings('error') self.assertRaises(DeprecationWarning, common.DataSeries, [], style=line_chart.LineStyle.solid) series = common.DataSeries([]) def _TestAssignment(): series.style = line_chart.LineStyle.solid self.assertRaises(DeprecationWarning, _TestAssignment) warnings.filterwarnings('ignore') series.style = line_chart.LineStyle.solid warnings.resetwarnings() self.assertEqual(1, series.style.width) self.assertEqual(1, series.style.on) self.assertEqual(0, series.style.off)
def AddBars(self, points, label=None, color=None): """Add a series of bars to the chart. points: List of y-values for the bars in this series label: Name of the series (used in the legend) color: Hex string, like '00ff00' for green This is a convenience method which constructs & appends the DataSeries for you. """ if label is not None and util._IsColor(label): warnings.warn( 'Your code may be broken! ' 'Label is a hex triplet. Maybe it is a color? The ' 'old argument order (color before label) is deprecated.', DeprecationWarning, stacklevel=2) style = BarsStyle(color) series = common.DataSeries(points, label=label, style=style) self.data.append(series) return series
def AddData(self, points, color=None, label=None): style = common._BasicStyle(color) series = common.DataSeries(points, style=style, label=label) self.data.append(series) return series