Skip to content

Commit 57c73dc

Browse files
committed
Add parameters for enabling/disabling labels & legends on charts
1 parent 139a509 commit 57c73dc

File tree

1 file changed

+78
-27
lines changed

1 file changed

+78
-27
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,20 +4086,23 @@ def begin_presentation(
40864086

40874087
def create_pie_chart(
40884088
self, chart_name=None, title=None, subtitle=None,
4089-
data_name=None, unit=None, libs=True):
4089+
data_name=None, unit=None, libs=True, labels=True, legend=True):
40904090
""" Creates a JavaScript pie chart using "HighCharts".
40914091
@Params
40924092
chart_name - If creating multiple charts,
40934093
use this to select which one.
40944094
title - The title displayed for the chart.
40954095
subtitle - The subtitle displayed for the chart.
4096-
data_name - Set the series name. Useful for multi-series charts.
4096+
data_name - The series name. Useful for multi-series charts.
4097+
If no data_name, will default to using "Series 1".
40974098
unit - The description label given to the chart's y-axis values.
40984099
libs - The option to include Chart libraries (JS and CSS files).
40994100
Should be set to True (default) for the first time creating
41004101
a chart on a web page. If creating multiple charts on the
41014102
same web page, you won't need to re-import the libraries
41024103
when creating additional charts.
4104+
labels - If True, displays labels on the chart for data points.
4105+
legend - If True, displays the data point legend on the chart.
41034106
"""
41044107
if not chart_name:
41054108
chart_name = "default"
@@ -4108,24 +4111,28 @@ def create_pie_chart(
41084111
style = "pie"
41094112
self.__create_highchart(
41104113
chart_name=chart_name, title=title, subtitle=subtitle,
4111-
style=style, data_name=data_name, unit=unit, libs=libs)
4114+
style=style, data_name=data_name, unit=unit, libs=libs,
4115+
labels=labels, legend=legend)
41124116

41134117
def create_bar_chart(
41144118
self, chart_name=None, title=None, subtitle=None,
4115-
data_name=None, unit=None, libs=True):
4119+
data_name=None, unit=None, libs=True, labels=True, legend=True):
41164120
""" Creates a JavaScript bar chart using "HighCharts".
41174121
@Params
41184122
chart_name - If creating multiple charts,
41194123
use this to select which one.
41204124
title - The title displayed for the chart.
41214125
subtitle - The subtitle displayed for the chart.
4122-
data_name - Set the series name. Useful for multi-series charts.
4126+
data_name - The series name. Useful for multi-series charts.
4127+
If no data_name, will default to using "Series 1".
41234128
unit - The description label given to the chart's y-axis values.
41244129
libs - The option to include Chart libraries (JS and CSS files).
41254130
Should be set to True (default) for the first time creating
41264131
a chart on a web page. If creating multiple charts on the
41274132
same web page, you won't need to re-import the libraries
41284133
when creating additional charts.
4134+
labels - If True, displays labels on the chart for data points.
4135+
legend - If True, displays the data point legend on the chart.
41294136
"""
41304137
if not chart_name:
41314138
chart_name = "default"
@@ -4134,24 +4141,28 @@ def create_bar_chart(
41344141
style = "bar"
41354142
self.__create_highchart(
41364143
chart_name=chart_name, title=title, subtitle=subtitle,
4137-
style=style, data_name=data_name, unit=unit, libs=libs)
4144+
style=style, data_name=data_name, unit=unit, libs=libs,
4145+
labels=labels, legend=legend)
41384146

41394147
def create_column_chart(
41404148
self, chart_name=None, title=None, subtitle=None,
4141-
data_name=None, unit=None, libs=True):
4149+
data_name=None, unit=None, libs=True, labels=True, legend=True):
41424150
""" Creates a JavaScript column chart using "HighCharts".
41434151
@Params
41444152
chart_name - If creating multiple charts,
41454153
use this to select which one.
41464154
title - The title displayed for the chart.
41474155
subtitle - The subtitle displayed for the chart.
4148-
data_name - Set the series name. Useful for multi-series charts.
4156+
data_name - The series name. Useful for multi-series charts.
4157+
If no data_name, will default to using "Series 1".
41494158
unit - The description label given to the chart's y-axis values.
41504159
libs - The option to include Chart libraries (JS and CSS files).
41514160
Should be set to True (default) for the first time creating
41524161
a chart on a web page. If creating multiple charts on the
41534162
same web page, you won't need to re-import the libraries
41544163
when creating additional charts.
4164+
labels - If True, displays labels on the chart for data points.
4165+
legend - If True, displays the data point legend on the chart.
41554166
"""
41564167
if not chart_name:
41574168
chart_name = "default"
@@ -4160,25 +4171,30 @@ def create_column_chart(
41604171
style = "column"
41614172
self.__create_highchart(
41624173
chart_name=chart_name, title=title, subtitle=subtitle,
4163-
style=style, data_name=data_name, unit=unit, libs=libs)
4174+
style=style, data_name=data_name, unit=unit, libs=libs,
4175+
labels=labels, legend=legend)
41644176

41654177
def create_line_chart(
41664178
self, chart_name=None, title=None, subtitle=None,
4167-
data_name=None, unit=None, zero=False, libs=True):
4179+
data_name=None, unit=None, zero=False, libs=True,
4180+
labels=True, legend=True):
41684181
""" Creates a JavaScript line chart using "HighCharts".
41694182
@Params
41704183
chart_name - If creating multiple charts,
41714184
use this to select which one.
41724185
title - The title displayed for the chart.
41734186
subtitle - The subtitle displayed for the chart.
4174-
data_name - Set the series name. Useful for multi-series charts.
4187+
data_name - The series name. Useful for multi-series charts.
4188+
If no data_name, will default to using "Series 1".
41754189
unit - The description label given to the chart's y-axis values.
41764190
zero - If True, the y-axis always starts at 0. (Default: False).
41774191
libs - The option to include Chart libraries (JS and CSS files).
41784192
Should be set to True (default) for the first time creating
41794193
a chart on a web page. If creating multiple charts on the
41804194
same web page, you won't need to re-import the libraries
41814195
when creating additional charts.
4196+
labels - If True, displays labels on the chart for data points.
4197+
legend - If True, displays the data point legend on the chart.
41824198
"""
41834199
if not chart_name:
41844200
chart_name = "default"
@@ -4187,25 +4203,30 @@ def create_line_chart(
41874203
style = "line"
41884204
self.__create_highchart(
41894205
chart_name=chart_name, title=title, subtitle=subtitle,
4190-
style=style, data_name=data_name, unit=unit, zero=zero, libs=libs)
4206+
style=style, data_name=data_name, unit=unit, zero=zero, libs=libs,
4207+
labels=labels, legend=legend)
41914208

41924209
def create_area_chart(
41934210
self, chart_name=None, title=None, subtitle=None,
4194-
data_name=None, unit=None, zero=False, libs=True):
4211+
data_name=None, unit=None, zero=False, libs=True,
4212+
labels=True, legend=True):
41954213
""" Creates a JavaScript area chart using "HighCharts".
41964214
@Params
41974215
chart_name - If creating multiple charts,
41984216
use this to select which one.
41994217
title - The title displayed for the chart.
42004218
subtitle - The subtitle displayed for the chart.
4201-
data_name - Set the series name. Useful for multi-series charts.
4219+
data_name - The series name. Useful for multi-series charts.
4220+
If no data_name, will default to using "Series 1".
42024221
unit - The description label given to the chart's y-axis values.
42034222
zero - If True, the y-axis always starts at 0. (Default: False).
42044223
libs - The option to include Chart libraries (JS and CSS files).
42054224
Should be set to True (default) for the first time creating
42064225
a chart on a web page. If creating multiple charts on the
42074226
same web page, you won't need to re-import the libraries
42084227
when creating additional charts.
4228+
labels - If True, displays labels on the chart for data points.
4229+
legend - If True, displays the data point legend on the chart.
42094230
"""
42104231
if not chart_name:
42114232
chart_name = "default"
@@ -4214,11 +4235,13 @@ def create_area_chart(
42144235
style = "area"
42154236
self.__create_highchart(
42164237
chart_name=chart_name, title=title, subtitle=subtitle,
4217-
style=style, data_name=data_name, unit=unit, zero=zero, libs=libs)
4238+
style=style, data_name=data_name, unit=unit, zero=zero, libs=libs,
4239+
labels=labels, legend=legend)
42184240

42194241
def __create_highchart(
42204242
self, chart_name=None, title=None, subtitle=None,
4221-
style=None, data_name=None, unit=None, zero=False, libs=True):
4243+
style=None, data_name=None, unit=None, zero=False, libs=True,
4244+
labels=True, legend=True):
42224245
""" Creates a JavaScript chart using the "HighCharts" library. """
42234246
if not chart_name:
42244247
chart_name = "default"
@@ -4232,6 +4255,14 @@ def __create_highchart(
42324255
data_name = "Series 1"
42334256
if not unit:
42344257
unit = "Values"
4258+
if labels:
4259+
labels = "true"
4260+
else:
4261+
labels = "false"
4262+
if legend:
4263+
legend = "true"
4264+
else:
4265+
legend = "false"
42354266
title = title.replace("'", "\\'")
42364267
subtitle = subtitle.replace("'", "\\'")
42374268
unit = unit.replace("'", "\\'")
@@ -4355,25 +4386,45 @@ def __create_highchart(
43554386
padding: '6px',
43564387
fontSize: '14px'
43574388
},
4389+
backgroundColor: {
4390+
linearGradient: {
4391+
x1: 0,
4392+
y1: 0,
4393+
x2: 0,
4394+
y2: 1
4395+
},
4396+
stops: [
4397+
[0, 'rgba(255, 255, 255, 0.78)'],
4398+
[0.5, 'rgba(235, 235, 235, 0.76)'],
4399+
[1, 'rgba(244, 252, 255, 0.74)']
4400+
]
4401+
},
4402+
hideDelay: 40,
43584403
pointFormat: '%s'
43594404
},
43604405
""" % point_format)
43614406
chart_init_3 = (
4362-
r"""
4407+
"""
43634408
accessibility: {
43644409
point: {
4365-
valueSuffix: '%'
4410+
valueSuffix: '%%'
43664411
}
43674412
},
43684413
plotOptions: {
4414+
series: {
4415+
states: {
4416+
inactive: {
4417+
opacity: 0.85
4418+
}
4419+
}
4420+
},
43694421
pie: {
4370-
size: "95%",
4422+
size: "95%%",
43714423
allowPointSelect: true,
43724424
animation: false,
43734425
cursor: 'pointer',
43744426
dataLabels: {
4375-
// enabled: false,
4376-
// format: '{point.name}: {point.y:.0f}',
4427+
enabled: %s,
43774428
formatter: function() {
43784429
if (this.y > 0) {
43794430
return this.point.name + ': ' + this.point.y
@@ -4385,10 +4436,10 @@ def __create_highchart(
43854436
enabled: true
43864437
}
43874438
},
4388-
showInLegend: true
4439+
showInLegend: %s
43894440
}
43904441
},
4391-
""")
4442+
""" % (labels, legend))
43924443
if style != "pie":
43934444
chart_init_3 = (
43944445
"""
@@ -4406,11 +4457,11 @@ def __create_highchart(
44064457
},
44074458
plotOptions: {
44084459
series: {
4409-
showInLegend: true,
4410-
animation: false,
44114460
dataLabels: {
4412-
enabled: true
4461+
enabled: %s
44134462
},
4463+
showInLegend: %s,
4464+
animation: false,
44144465
shadow: false,
44154466
lineWidth: 3,
44164467
fillOpacity: 0.5,
@@ -4419,7 +4470,7 @@ def __create_highchart(
44194470
}
44204471
}
44214472
},
4422-
""")
4473+
""" % (labels, legend))
44234474
chart_init = chart_init_1 + chart_init_2 + chart_init_3
44244475
color_by_point = "true"
44254476
if style != "pie":

0 commit comments

Comments
 (0)