* src/plugins/AncestorChart2.py: first pass at multipage output
svn: r2643
This commit is contained in:
parent
c3e3bfe2bc
commit
b79704d371
@ -85,6 +85,7 @@ class GenChart :
|
|||||||
self.array[i] = [0]*generations
|
self.array[i] = [0]*generations
|
||||||
|
|
||||||
self.max_x = 0
|
self.max_x = 0
|
||||||
|
self.ad = (self.size,generations)
|
||||||
|
|
||||||
def set(self,index,value):
|
def set(self,index,value):
|
||||||
x = log2(index)
|
x = log2(index)
|
||||||
@ -111,8 +112,11 @@ class GenChart :
|
|||||||
return (x,y)
|
return (x,y)
|
||||||
|
|
||||||
def get(self,index):
|
def get(self,index):
|
||||||
(x,y) = self.index_to_xy(index)
|
try:
|
||||||
return self.array[y][x]
|
(x,y) = self.index_to_xy(index)
|
||||||
|
return self.array[y][x]
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_xy(self,x,y):
|
def get_xy(self,x,y):
|
||||||
return self.array[y][x]
|
return self.array[y][x]
|
||||||
@ -139,6 +143,7 @@ class GenChart :
|
|||||||
old_y += 1
|
old_y += 1
|
||||||
self.array = new_array
|
self.array = new_array
|
||||||
self.map = new_map
|
self.map = new_map
|
||||||
|
self.ad = (new_y,self.ad[1])
|
||||||
|
|
||||||
def display(self):
|
def display(self):
|
||||||
index = 0
|
index = 0
|
||||||
@ -159,7 +164,7 @@ class GenChart :
|
|||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
class AncestorChart:
|
class AncestorChart:
|
||||||
|
|
||||||
def __init__(self,database,person,max,display,doc,output,scale,compress,
|
def __init__(self,database,person,max,display,doc,output,scale,
|
||||||
title,newpage=0):
|
title,newpage=0):
|
||||||
self.doc = doc
|
self.doc = doc
|
||||||
self.title = title.strip()
|
self.title = title.strip()
|
||||||
@ -175,7 +180,6 @@ class AncestorChart:
|
|||||||
self.display = display
|
self.display = display
|
||||||
self.newpage = newpage
|
self.newpage = newpage
|
||||||
self.force_fit = scale
|
self.force_fit = scale
|
||||||
self.compress_chart = compress
|
|
||||||
if output:
|
if output:
|
||||||
self.doc.open(output)
|
self.doc.open(output)
|
||||||
self.standalone = output
|
self.standalone = output
|
||||||
@ -227,21 +231,21 @@ class AncestorChart:
|
|||||||
generation = 1
|
generation = 1
|
||||||
done = 0
|
done = 0
|
||||||
page = 1
|
page = 1
|
||||||
|
(maxy,maxx) = self.genchart.dimensions()
|
||||||
|
maxh = int(self.uh/self.box_height)
|
||||||
|
|
||||||
if self.force_fit:
|
if self.force_fit:
|
||||||
self.print_page(1,1,1)
|
self.print_page(0,maxx,0,maxy)
|
||||||
else:
|
else:
|
||||||
while not done:
|
starty = 0
|
||||||
done = 1
|
while starty < maxy-1:
|
||||||
start = 2**(generation-1)
|
startx = 0
|
||||||
for index in range(start, (start*2)):
|
while startx < maxx-1:
|
||||||
values = []
|
stopx = min(maxx,startx+self.generations_per_page)
|
||||||
self.get_numbers(index,1,values)
|
stopy = min(maxy,starty+maxh)
|
||||||
if len(values) > 1 or generation == 1:
|
self.print_page(startx,stopx,starty,stopy)
|
||||||
done = 0
|
startx += self.generations_per_page
|
||||||
self.print_page(index, generation, page)
|
starty += maxh-1
|
||||||
page = page + 1
|
|
||||||
generation = generation + self.generations_per_page
|
|
||||||
|
|
||||||
if self.standalone:
|
if self.standalone:
|
||||||
self.doc.close()
|
self.doc.close()
|
||||||
|
|
||||||
@ -252,15 +256,14 @@ class AncestorChart:
|
|||||||
the elements on a page.
|
the elements on a page.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.compress_chart:
|
self.genchart.compress()
|
||||||
self.genchart.compress()
|
|
||||||
|
|
||||||
self.box_pad_pts = 10
|
self.box_pad_pts = 10
|
||||||
if self.title:
|
if self.title and self.force_fit:
|
||||||
self.offset = pt2cm(1.25* self.tfont.get_size())
|
self.offset = pt2cm(1.25* self.tfont.get_size())
|
||||||
else:
|
else:
|
||||||
self.offset = 0
|
self.offset = 0
|
||||||
uh = self.doc.get_usable_height() - self.offset
|
self.uh = self.doc.get_usable_height() - self.offset
|
||||||
uw = self.doc.get_usable_width()-pt2cm(self.box_pad_pts)
|
uw = self.doc.get_usable_width()-pt2cm(self.box_pad_pts)
|
||||||
|
|
||||||
calc_width = pt2cm(self.box_width + self.box_pad_pts) + 0.2
|
calc_width = pt2cm(self.box_width + self.box_pad_pts) + 0.2
|
||||||
@ -273,20 +276,20 @@ class AncestorChart:
|
|||||||
(maxy,maxx) = self.genchart.dimensions()
|
(maxy,maxx) = self.genchart.dimensions()
|
||||||
|
|
||||||
bw = calc_width/(uw/maxx)
|
bw = calc_width/(uw/maxx)
|
||||||
bh = self.box_height/(uh/maxy)
|
bh = self.box_height/(self.uh/maxy)
|
||||||
|
|
||||||
self.scale = max(bw,bh)
|
self.scale = max(bw,bh)
|
||||||
self.box_width = self.box_width/self.scale
|
self.box_width = self.box_width/self.scale
|
||||||
self.box_height = self.box_height/self.scale
|
self.box_height = self.box_height/self.scale
|
||||||
self.box_pad_pts = self.box_pad_pts/self.scale
|
self.box_pad_pts = self.box_pad_pts/self.scale
|
||||||
|
|
||||||
maxh = int(uh/self.box_height)
|
maxh = int(self.uh/self.box_height)
|
||||||
maxw = int(uw/calc_width)
|
maxw = int(uw/calc_width)
|
||||||
|
|
||||||
if log2(maxh) < maxw:
|
if log2(maxh) < maxw:
|
||||||
self.generations_per_page = int(log2(maxh))
|
self.generations_per_page = int(log2(maxh))
|
||||||
else:
|
else:
|
||||||
self.generations_per_page = maxw + 1
|
self.generations_per_page = maxw
|
||||||
acty = 2**self.generations_per_page
|
acty = 2**self.generations_per_page
|
||||||
|
|
||||||
# build array of x indices
|
# build array of x indices
|
||||||
@ -294,7 +297,11 @@ class AncestorChart:
|
|||||||
xstart = 0
|
xstart = 0
|
||||||
ystart = self.offset-self.box_height/2.0
|
ystart = self.offset-self.box_height/2.0
|
||||||
self.delta = pt2cm(self.box_pad_pts) + self.box_width + 0.2
|
self.delta = pt2cm(self.box_pad_pts) + self.box_width + 0.2
|
||||||
|
if not self.force_fit:
|
||||||
|
calc_width = self.box_width + 0.2 + pt2cm(self.box_pad_pts)
|
||||||
|
remain = self.doc.get_usable_width() - ((self.generations_per_page)*calc_width)
|
||||||
|
self.delta += remain/(self.generations_per_page)
|
||||||
|
|
||||||
self.font.set_size(self.font.get_size()/self.scale)
|
self.font.set_size(self.font.get_size()/self.scale)
|
||||||
|
|
||||||
g = BaseDoc.GraphicsStyle()
|
g = BaseDoc.GraphicsStyle()
|
||||||
@ -326,31 +333,38 @@ class AncestorChart:
|
|||||||
self.get_numbers(start*2,index+1,vals)
|
self.get_numbers(start*2,index+1,vals)
|
||||||
self.get_numbers((start*2)+1,index+1,vals)
|
self.get_numbers((start*2)+1,index+1,vals)
|
||||||
|
|
||||||
def print_page(self,start,generation, page):
|
def print_page(self,startx,stopx,starty,stopy):
|
||||||
|
|
||||||
(maxy,maxx) = self.genchart.dimensions()
|
|
||||||
self.doc.start_page()
|
self.doc.start_page()
|
||||||
if self.title:
|
if self.title and self.force_fit:
|
||||||
self.doc.center_text('title',self.title,self.doc.get_usable_width()/2,0)
|
self.doc.center_text('title',self.title,self.doc.get_usable_width()/2,0)
|
||||||
for y in range(0,maxy):
|
phys_y = 0
|
||||||
for x in range(0,maxx):
|
for y in range(starty,stopy):
|
||||||
|
phys_x = 0
|
||||||
|
for x in range(startx,stopx):
|
||||||
value = self.genchart.get_xy(x,y)
|
value = self.genchart.get_xy(x,y)
|
||||||
if value:
|
if value:
|
||||||
(person,index) = value
|
(person,index) = value
|
||||||
text = string.join(self.text[index],"\n")
|
text = string.join(self.text[index],"\n")
|
||||||
self.doc.draw_box("box",text,x*self.delta,y*self.box_height+self.offset)
|
self.doc.draw_box("box",text,phys_x*self.delta,phys_y*self.box_height+self.offset)
|
||||||
if index > 1:
|
if self.genchart.get(index*2):
|
||||||
parent = int(index>>1)
|
(px,py) = self.genchart.index_to_xy(index*2)
|
||||||
(px,py) = self.genchart.index_to_xy(parent)
|
x2 = min(self.doc.get_usable_width(),(px-startx)*self.delta)
|
||||||
x1 = px*self.delta+(0.5 * self.delta)
|
x1 = (x-startx)*self.delta+(0.5 * self.box_width)
|
||||||
x2 = x*self.delta
|
y2 = self.box_height * (py-starty) + 0.5*self.box_height + self.offset
|
||||||
y2 = self.box_height * y + 0.5*self.box_height + self.offset
|
y1 = self.box_height * (y-starty) + self.offset
|
||||||
if py > y:
|
|
||||||
y1 = self.box_height * py + self.offset
|
|
||||||
else:
|
|
||||||
y1 = self.box_height * (py+1) + self.offset
|
|
||||||
self.doc.draw_line("line",x1,y1,x1,y2)
|
self.doc.draw_line("line",x1,y1,x1,y2)
|
||||||
self.doc.draw_line("line",x1,y2,x2,y2)
|
self.doc.draw_line("line",x1,y2,x2,y2)
|
||||||
|
if self.genchart.get(index*2+1):
|
||||||
|
(px,py) = self.genchart.index_to_xy(index*2+1)
|
||||||
|
x2 = min(self.doc.get_usable_width(),(px-startx)*self.delta)
|
||||||
|
x1 = (x-startx)*self.delta+(0.5 * self.box_width)
|
||||||
|
y2 = self.box_height * (py-starty) + 0.5*self.box_height + self.offset
|
||||||
|
y1 = self.box_height * (y-starty+1) + self.offset
|
||||||
|
self.doc.draw_line("line",x1,y1,x1,y2)
|
||||||
|
self.doc.draw_line("line",x1,y2,x2,y2)
|
||||||
|
phys_x +=1
|
||||||
|
phys_y += 1
|
||||||
|
|
||||||
self.doc.end_page()
|
self.doc.end_page()
|
||||||
|
|
||||||
@ -395,10 +409,6 @@ class AncestorChartDialog(Report.DrawReportDialog):
|
|||||||
self.title.set_text(self.get_header(self.person.getPrimaryName().getName()))
|
self.title.set_text(self.get_header(self.person.getPrimaryName().getName()))
|
||||||
self.title.show()
|
self.title.show()
|
||||||
self.add_option(_('Title'),self.title)
|
self.add_option(_('Title'),self.title)
|
||||||
self.compress = gtk.CheckButton(_('Compress graph'))
|
|
||||||
self.compress.set_active(1)
|
|
||||||
self.compress.show()
|
|
||||||
self.add_option('',self.compress)
|
|
||||||
self.scale = gtk.CheckButton(_('Scale to fit on a single page'))
|
self.scale = gtk.CheckButton(_('Scale to fit on a single page'))
|
||||||
self.scale.set_active(1)
|
self.scale.set_active(1)
|
||||||
self.scale.show()
|
self.scale.show()
|
||||||
@ -443,7 +453,6 @@ class AncestorChartDialog(Report.DrawReportDialog):
|
|||||||
self.max_gen, self.report_text,
|
self.max_gen, self.report_text,
|
||||||
self.doc,self.target_path,
|
self.doc,self.target_path,
|
||||||
self.scale.get_active(),
|
self.scale.get_active(),
|
||||||
self.compress.get_active(),
|
|
||||||
self.title.get_text()
|
self.title.get_text()
|
||||||
)
|
)
|
||||||
MyReport.write_report()
|
MyReport.write_report()
|
||||||
|
Loading…
Reference in New Issue
Block a user