Skip to content

Commit

Permalink
👹 Feed the hobgoblins (delint).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 1, 2024
1 parent 0cbb4f6 commit a9265eb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 68 deletions.
18 changes: 8 additions & 10 deletions svg/charts/pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,14 @@ def draw_data(self):
x_end = radius + (math.sin(radians) * radius)
y_end = radius - (math.cos(radians) * radius)
percent_greater_fifty = int(percent >= 50)
path = ' '.join(
(
"M%(radius)s,%(radius)s",
"L%(x_start)s,%(y_start)s",
"A%(radius)s,%(radius)s",
"0,",
"%(percent_greater_fifty)s,1,",
"%(x_end)s %(y_end)s Z",
)
)
path = ' '.join((
"M%(radius)s,%(radius)s",
"L%(x_start)s,%(y_start)s",
"A%(radius)s,%(radius)s",
"0,",
"%(percent_greater_fifty)s,1,",
"%(x_end)s %(y_end)s Z",
))
path = path % vars()

wedge = etree.SubElement(
Expand Down
7 changes: 4 additions & 3 deletions svg/charts/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ def field_height(self):
def draw_data(self):
self.load_transform_parameters()
for line, data in zip(itertools.count(1), self.data):
x_start, y_start = self.transform_output_coordinates(
(data['data'][0][self.x_data_index], data['data'][0][self.y_data_index])
)
x_start, y_start = self.transform_output_coordinates((
data['data'][0][self.x_data_index],
data['data'][0][self.y_data_index],
))
data_points = data['data']
graph_points = self.get_graph_points(data_points)
lpath = self.get_lpath(graph_points)
Expand Down
60 changes: 26 additions & 34 deletions tests/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,27 @@


def sample_Plot():
g = Plot(
{
'min_x_value': 0,
'min_y_value': 0,
'area_fill': True,
'stagger_x_labels': True,
'stagger_y_labels': True,
'show_x_guidelines': True,
}
)
g = Plot({
'min_x_value': 0,
'min_y_value': 0,
'area_fill': True,
'stagger_x_labels': True,
'stagger_y_labels': True,
'show_x_guidelines': True,
})
g.add_data({'data': [[1, 25], [2, 30], [3, 45]], 'title': 'series 1'})
g.add_data({'data': [[1, 30], [2, 31], [3, 40]], 'title': 'series 2'})
g.add_data({'data': [[0.5, 35], [1, 20], [3, 10.5]], 'title': 'series 3'})
return g


def sample_PlotTextLabels():
g = Plot(
{
'draw_lines_between_points': False,
'min_x_value': 0,
'min_y_value': 0,
'show_x_guidelines': True,
}
)
g = Plot({
'draw_lines_between_points': False,
'min_x_value': 0,
'min_y_value': 0,
'show_x_guidelines': True,
})
# Processed Apple production 2015
# Any object with a .text attribute will do;
# we like namedtuple().
Expand All @@ -47,16 +43,14 @@ def sample_PlotTextLabels():

Datum = namedtuple("Datum", "x y text")

g.add_data(
{
'data': [
Datum(8.24, 80.85, 'ES'),
Datum(0.17, 6.73, 'IE'),
Datum(0, 0, 'IS'),
],
'title': 'Processed Apple',
}
)
g.add_data({
'data': [
Datum(8.24, 80.85, 'ES'),
Datum(0.17, 6.73, 'IE'),
Datum(0, 0, 'IS'),
],
'title': 'Processed Apple',
})
return g


Expand All @@ -68,12 +62,10 @@ def sample_TimeSeries():
g.x_label_format = '%d-%b %H:%M'
# g.max_y_value = 200

g.add_data(
{
'data': ['2005-12-21T00:00:00', 20, '2005-12-22T00:00:00', 21],
'title': 'series 1',
}
)
g.add_data({
'data': ['2005-12-21T00:00:00', 20, '2005-12-22T00:00:00', 21],
'title': 'series 1',
})

return g

Expand Down
28 changes: 13 additions & 15 deletions tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,19 @@ def test_rounding(self):
"""
Labels should be rounded to 4 digits of precision.
"""
g = Plot(
{
'show_data_values': False,
'show_data_points': False,
'min_x_value': 0,
'max_x_value': 0.5,
'min_y_value': 0,
'max_y_value': 1,
'scale_y_divisions': 0.1,
'scale_x_divisions': 0.1,
'area_fill': False,
'show_x_guidelines': True,
'show_y_guidelines': True,
}
)
g = Plot({
'show_data_values': False,
'show_data_points': False,
'min_x_value': 0,
'max_x_value': 0.5,
'min_y_value': 0,
'max_y_value': 1,
'scale_y_divisions': 0.1,
'scale_x_divisions': 0.1,
'area_fill': False,
'show_x_guidelines': True,
'show_y_guidelines': True,
})

g.add_data({'data': self.read_data('source.csv'), 'title': 'title'})
res = g.burn()
Expand Down
10 changes: 4 additions & 6 deletions tests/test_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ def test_field_width():
g.stagger_x_labels = True
g.x_label_format = '%d-%b %H:%M'

g.add_data(
{
'data': [('2005-12-21T00:00:00', 20), ('2005-12-22T00:00:00', 21)],
'title': 'series 1',
}
)
g.add_data({
'data': [('2005-12-21T00:00:00', 20), ('2005-12-22T00:00:00', 21)],
'title': 'series 1',
})
g.burn()
assert g.field_width() > 1

0 comments on commit a9265eb

Please sign in to comment.