Skip to content

Commit

Permalink
Fixed background bug
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina7479 committed Jul 14, 2014
1 parent ee0e934 commit 99dea25
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
8 changes: 3 additions & 5 deletions bin/barcharttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ def BarChartTest():
# Get document object
document = writer.get_document()

cursor = PDFCursor(100, 300)
cursor = PDFCursor(100, 50)
data = [("Sunday", 11.5), ("Monday", 13.9), ("Tuesday", 15.1), ("Wednesday", 15.2), ("Thursday", 16.3),
("Friday", 18.0), ("Saturday", 12.1)]

document.add_simple_bar_chart(data, cursor, 400, 300, "Blog Re-tweets By Day of the Week", axis_titles=("day", "percent chance of re-tweet"), y_axis_limits=(11, 19), y_axis_frequency=1, legend="right")

document.add_simple_bar_chart(data, cursor, 400, 300, "Blog Re-tweets By Day of the Week", axis_titles=("day", "percent chance of re-tweet"), y_axis_limits=(11, 19), y_axis_frequency=1)


document.add_page()
cursor = PDFCursor(100, 300)
cursor = PDFCursor(100, 400)
document.add_simple_bar_chart(data, cursor, 400, 300, "Blog Re-tweets By Day of the Week", axis_titles=("day", "percent chance of re-tweet"), y_axis_limits=(11, 19), y_axis_frequency=1)


Expand Down
7 changes: 3 additions & 4 deletions bin/piecharttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ def PieChartTest():

# Get document object
document = writer.get_document()
cursor = PDFCursor(100, 300)
cursor = PDFCursor(100, 50)
data = [("English", 565004126), ("Chinese", 509965013), ("Spanish", 164968742),
("Arabic", 65365400), ("French", 59779525), ("Russian", 59700000),
("Japanese", 99182000), ("Portuguese", 82586600), ("German", 75422674),
("Korean", 39440000)]

document.add_pie_chart(data, cursor, 400, 300, title="Languages Spoken on the Internet", legend="right")
document.add_pie_chart(data, cursor, 400, 300, title="Languages Spoken on the Internet")

document.add_page()
cursor = PDFCursor(100, 300)
cursor = PDFCursor(100, 400)
document.add_pie_chart(data, cursor, 400, 300, title="Languages Spoken on the Internet", labels=True)

# Close Document
Expand Down
17 changes: 17 additions & 0 deletions pypdflite/pdfdocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,32 +482,49 @@ def draw_arc(self, center_cursor, radius, starting_angle, arc_angle, inverted=Fa
def add_line_graph(self, data, cursor, width, height, title=None, x_axis_limits=None, y_axis_limits=None, frequency=None, axis_titles=None, axis_labels=None, axis_font_size=None, line_colors=None,
background_style='S', border_size=1, background_border_color=None, background_fill_color=None, padding=0.1, legend=None):

save_draw_color = self.draw_color
save_fill_color = self.fill_color
save_font_size = self.get_font_size()
if axis_font_size is None:
self.set_font_size(8)
else:
self.set_font_size(axis_font_size)

graph = PDFLineGraph(self.session, self.page, cursor, data, width, height, title, x_axis_limits, y_axis_limits, frequency, axis_titles, axis_labels, line_colors, background_style, border_size, background_border_color, background_fill_color, padding, legend)

self.set_font_size(save_font_size)
self.set_draw_color(save_draw_color)
self.set_fill_color(save_fill_color)

def add_simple_bar_chart(self, data, cursor, width, height, title=None, axis_titles=None, axis_font_size=None, y_axis_limits=None, y_axis_frequency=None, bar_style="B", bar_padding=.1, bar_border_colors=None, bar_fill_colors=None,
background_style="S", border_size=1, background_border_color=None, background_fill_color=None, padding=0.1, legend=None):

save_draw_color = self.draw_color
save_fill_color = self.fill_color
save_font_size = self.get_font_size()

if axis_font_size is None:
self.set_font_size(8)
else:
self.set_font_size(axis_font_size)

graph = PDFBarChart(self.session, self.page, data, cursor, width, height, title, axis_titles, y_axis_limits, y_axis_frequency, bar_style, bar_padding, bar_border_colors, bar_fill_colors,
background_style, border_size, background_border_color, background_fill_color, padding, legend)

self.set_font_size(save_font_size)
self.set_draw_color(save_draw_color)
self.set_fill_color(save_fill_color)

def add_pie_chart(self, data, cursor, width, height, title=None, data_type="raw", fill_colors=None, labels=False, background_style='S', border_size=1, background_border_color=None, background_fill_color=None, padding=0.1, legend=None):
""" Data type may be "raw" or "percent" """
save_draw_color = self.draw_color
save_fill_color = self.fill_color

chart = PDFPieChart(self.session, self.page, data, cursor, width, height, title, data_type, fill_colors, labels, background_style, border_size, background_border_color, background_fill_color, padding, legend)

self.set_draw_color(save_draw_color)
self.set_fill_color(save_fill_color)

def add_table(self, rows, columns, cursor=None):
if cursor is None:
cursor = self.page.cursor
Expand Down
7 changes: 4 additions & 3 deletions pypdflite/pdfobjects/pdfgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ def _set_accessories(self, title, legend, padding, width, height):
self.padding = (self.padding[0] * 0.7, self.padding[1])
else:
self.legend = None
print self.padding

def _draw_background(self, width, height, style, size, border_color, fill_color):
cursor_end = PDFCursor(self.origin.x + width, self.origin.y - height)
if border_color is None:
border_color = self.base_color
cursor_end = PDFCursor(self.origin.x + width, self.origin.y + height)
rectangle = PDFRectangle(self.session, self.page, self.origin, cursor_end, border_color, fill_color, style, "solid", size)
rectangle._draw()

Expand All @@ -58,7 +59,7 @@ def _draw_title(self):
save_font = self.font
self.session.parent.document.set_font(save_font.family, "b", save_font.font_size * 1.2)
title_cursor = PDFCursor(self.origin.x + (self.width - self.session.parent.document.font._string_width(self.title))/ 2.0, self.origin.y - self.height - (self.padding[1] * 0.4))
title = PDFText(self.session, self.page, self.title, cursor=title_cursor)
title = PDFText(self.session, self.page, self.title, cursor=title_cursor, color=self.base_color)
self.session.parent.document.set_font(font=save_font)

def _get_limits_from_data(self, data):
Expand Down

0 comments on commit 99dea25

Please sign in to comment.