MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / add_data_point

Method add_data_point

seleniumbase/fixtures/base_case.py:13196–13245  ·  view source on GitHub ↗

Add a data point to a SeleniumBase-generated chart. @Params label - The label name for the data point. value - The numeric value of the data point. color - The HTML color of the data point. Can be an RGB color. Eg: "#55ACDC". Can also b

(self, label, value, color=None, chart_name=None)

Source from the content-addressed store, hash-verified

13194 self._chart_first_series[chart_name] = False
13195
13196 def add_data_point(self, label, value, color=None, chart_name=None):
13197 """Add a data point to a SeleniumBase-generated chart.
13198 @Params
13199 label - The label name for the data point.
13200 value - The numeric value of the data point.
13201 color - The HTML color of the data point.
13202 Can be an RGB color. Eg: "#55ACDC".
13203 Can also be a named color. Eg: "Teal".
13204 chart_name - If creating multiple charts,
13205 use this to select which one."""
13206 if not chart_name:
13207 chart_name = "default"
13208 if chart_name not in self._chart_data:
13209 # Create a chart if it doesn't already exist
13210 self.create_pie_chart(chart_name=chart_name)
13211 if not value:
13212 value = 0
13213 if not isinstance(value, (int, float)):
13214 raise Exception('Expecting a numeric value for "value"!')
13215 if not color:
13216 color = ""
13217 else:
13218 color = color.replace("'", "\\'")
13219 label = label.replace("'", "\\'")
13220 if color:
13221 data_point = """
13222 {
13223 name: '%s',
13224 y: %s,
13225 color: '%s'
13226 },
13227 """ % (
13228 label,
13229 value,
13230 color,
13231 )
13232 else:
13233 data_point = """
13234 {
13235 name: '%s',
13236 y: %s,
13237 },
13238 """ % (
13239 label,
13240 value,
13241 )
13242 data_point = textwrap.dedent(data_point)
13243 self._chart_data[chart_name].append(data_point)
13244 if self._chart_first_series[chart_name]:
13245 self._chart_label[chart_name].append(label)
13246
13247 def save_chart(self, chart_name=None, filename=None, folder=None):
13248 """Saves a SeleniumBase-generated chart to a file for later use.

Calls 1

create_pie_chartMethod · 0.95

Tested by 9

test_multi_seriesMethod · 0.64
test_pie_chartsMethod · 0.64
test_display_chartMethod · 0.64
test_save_chartMethod · 0.64
test_line_chartMethod · 0.64
test_chart_makerMethod · 0.64
test_area_chartMethod · 0.64