Patches from Jeff Ollie for colorization and dashed lines

svn: r905
This commit is contained in:
Don Allingham 2002-04-09 15:51:59 +00:00
parent 531bea65d9
commit 20a3b7e00b

View File

@ -93,49 +93,75 @@ class GraphVizDialog(ReportDialog):
return [all,des,ans]
def add_user_options(self):
self.arrowhead_optionmenu = GtkOptionMenu()
self.arrowstyle_optionmenu = GtkOptionMenu()
menu = GtkMenu()
menuitem = GtkMenuItem(_("Descendants <- Ancestors"))
menuitem.set_data('i', '[arrowhead=none, arrowtail=normal]')
menuitem.set_data('t', ('none', 'normal'))
menuitem.show()
menu.append(menuitem)
menuitem = GtkMenuItem(_("Descendants -> Ancestors"))
menuitem.set_data('i', '[arrowhead=normal, arrowtail=none]')
menuitem.set_data('t', ('normal', 'none'))
menuitem.show()
menu.append(menuitem)
menuitem = GtkMenuItem(_("Descendants <-> Ancestors"))
menuitem.set_data('i', '[arrowhead=normal, arrowtail=normal]')
menuitem.set_data('t', ('normal', 'normal'))
menuitem.show()
menu.append(menuitem)
menuitem = GtkMenuItem(_("Descendants - Ancestors"))
menuitem.set_data('t', ('none', 'none'))
menuitem.show()
menu.append(menuitem)
menu.set_active(0)
self.arrowhead_optionmenu.set_menu(menu)
self.add_frame_option(_("GraphViz Options"), _("Arrowhead Options"),
self.arrowhead_optionmenu,
self.arrowstyle_optionmenu.set_menu(menu)
self.add_frame_option(_("GraphViz Options"),
_("Arrowhead Options"),
self.arrowstyle_optionmenu,
_("Choose the direction that the arrows point."))
msg = _("Include Birth and Death Dates")
self.includedates_checkbutton = GtkCheckButton(msg)
self.includedates_checkbutton.set_active(1)
self.includedates_cb = GtkCheckButton(msg)
self.includedates_cb.set_active(1)
self.add_frame_option(_("GraphViz Options"), '',
self.includedates_checkbutton,
self.includedates_cb,
_("Include the years that the individual "
"was born and/or died in the graph node "
"labels."))
self.includeurl_checkbutton = GtkCheckButton(_("Include URLs"))
self.includeurl_checkbutton.set_active(1)
self.includeurl_cb = GtkCheckButton(_("Include URLs"))
self.includeurl_cb.set_active(1)
self.add_frame_option(_("GraphViz Options"), '',
self.includeurl_checkbutton,
self.includeurl_cb,
_("Include a URL in each graph node so "
"that PDF and imagemap files can be "
"generated that contain active links "
"to the files generated by the 'Generate "
"Web Site' report."))
self.colorize_cb = GtkCheckButton(_("Colorize Graph"))
self.colorize_cb.set_active(1)
self.add_frame_option(_("GraphViz Options"),
'',
self.colorize_cb,
_("Males will be outlined in blue, females "
"will be outlined in pink. If the sex of "
"an individual is unknown it will be "
"outlined in black."))
self.adoptionsdashed_cb = GtkCheckButton(_("Indicate non-birth relationships with dashed lines"))
self.adoptionsdashed_cb.set_active(1)
self.add_frame_option(_("GraphViz Options"),
'',
self.adoptionsdashed_cb,
_("Non-birth relationships will show up "
"as dashed lines in the graph."))
tb_margin_adj = GtkAdjustment(value=0.5, lower=0.25,
upper=100.0, step_incr=0.25)
lr_margin_adj = GtkAdjustment(value=0.5, lower=0.25,
@ -151,6 +177,28 @@ class GraphVizDialog(ReportDialog):
_("Left & Right Margins"),
self.lr_margin_sb)
hpages_adj = GtkAdjustment(value=1, lower=1, upper=25, step_incr=1)
vpages_adj = GtkAdjustment(value=1, lower=1, upper=25, step_incr=1)
self.hpages_sb = GtkSpinButton(adj=hpages_adj, digits=0)
self.vpages_sb = GtkSpinButton(adj=vpages_adj, digits=0)
self.add_frame_option(_("GraphViz Options"),
_("Number of Horizontal Pages"),
self.hpages_sb,
_("GraphViz can create very large graphs by "
"spreading the graph across a rectangular "
"array of pages. This controls the number "
"pages in the array horizontally."))
self.add_frame_option(_("GraphViz Options"),
_("Number of Vertical Pages"),
self.vpages_sb,
_("GraphViz can create very large graphs "
"by spreading the graph across a "
"rectangular array of pages. This "
"controls the number pages in the array "
"vertically."))
#------------------------------------------------------------------------
#
# Functions related to selecting/changing the current file format
@ -187,12 +235,16 @@ class GraphVizDialog(ReportDialog):
pass
def parse_other_frames(self):
menu = self.arrowhead_optionmenu.get_menu()
self.arrowhead_option = menu.get_active().get_data('i')
self.includedates = self.includedates_checkbutton.get_active()
self.includeurl = self.includeurl_checkbutton.get_active()
menu = self.arrowstyle_optionmenu.get_menu()
self.arrowheadstyle, self.arrowtailstyle = menu.get_active().get_data('t')
self.includedates = self.includedates_cb.get_active()
self.includeurl = self.includeurl_cb.get_active()
self.tb_margin = self.tb_margin_sb.get_value_as_float()
self.lr_margin = self.lr_margin_sb.get_value_as_float()
self.colorize = self.colorize_cb.get_active()
self.adoptionsdashed = self.adoptionsdashed_cb.get_active()
self.hpages = self.hpages_sb.get_value_as_int()
self.vpages = self.vpages_sb.get_value_as_int()
#------------------------------------------------------------------------
#
@ -208,29 +260,10 @@ class GraphVizDialog(ReportDialog):
ind_list = self.filter.apply(self.db.getPersonMap().values())
file.write("digraph g {\n")
file.write("bgcolor=white;\n")
file.write("rankdir=LR;\n")
file.write("center=1;\n")
if self.pagecount == _scaled:
file.write("ratio=compress;\n")
file.write('size="%3.1f' % (width-(self.lr_margin*2)))
file.write(',%3.1f";\n' % (height-(self.tb_margin*2)))
else:
file.write("ratio=auto;\n")
file.write("page=\"%3.1f,%3.1f\";\n" % (width,height))
if self.orien == PAPER_LANDSCAPE:
file.write("rotate=90;\n")
if len(ind_list) > 1:
dump_index(ind_list,file,self.includedates,self.includeurl)
dump_person(ind_list,file,self.arrowhead_option)
file.write("}\n")
file.close()
write_dot(file, ind_list, self.orien, width, height,
self.tb_margin, self.lr_margin, self.hpages,
self.vpages, self.includedates, self.includeurl,
self.colorize, self.adoptionsdashed, self.arrowheadstyle, self.arrowtailstyle)
#------------------------------------------------------------------------
#
@ -245,27 +278,67 @@ def report(database,person):
#
#
#------------------------------------------------------------------------
def dump_person(person_list,file,arrowhead_option):
for person in person_list:
pid = string.replace(person.getId(),'-','_')
family = person.getMainParents()
if family == None:
continue
father = family.getFather()
if father and father in person_list:
fid = string.replace(father.getId(),'-','_')
file.write('p%s -> p%s %s;\n' % (pid, fid, arrowhead_option))
mother = family.getMother()
if mother and mother in person_list:
mid = string.replace(mother.getId(),'-','_')
file.write('p%s -> p%s %s;\n' % (pid, mid, arrowhead_option))
def write_dot(file, ind_list, orien, width, height, tb_margin,
lr_margin, hpages, vpages, includedates, includeurl,
colorize, adoptionsdashed, arrowheadstyle, arrowtailstyle):
file.write("digraph g {\n")
file.write("bgcolor=white;\n")
file.write("rankdir=LR;\n")
file.write("center=1;\n")
file.write("margin=0.5;\n")
file.write("ratio=fill;\n")
file.write("size=\"%3.1f,%3.1f\";\n" % ((width * hpages) - (lr_margin * 2) - ((hpages - 1) * 1.0),
(height * vpages) - (tb_margin * 2) - ((vpages - 1) * 1.0)))
file.write("page=\"%3.1f,%3.1f\";\n" % (width,height))
if orien == PAPER_LANDSCAPE:
file.write("rotate=90;\n")
if len(ind_list) > 1:
dump_index(ind_list,file,includedates,includeurl,colorize)
dump_person(ind_list,file,adoptionsdashed,arrowheadstyle,arrowtailstyle)
file.write("}\n")
file.close()
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
def dump_index(person_list,file,includedates,includeurl):
def dump_person(person_list,file,adoptionsdashed,arrowheadstyle,arrowtailstyle):
for person in person_list:
pid = string.replace(person.getId(),'-','_')
family, mrel, frel = person.getMainParentsRel()
if family == None:
continue
father = family.getFather()
if father and father in person_list:
fid = string.replace(father.getId(),'-','_')
file.write('p%s -> p%s [' % (pid, fid))
file.write('arrowhead=%s, arrowtail=%s, ' % (arrowheadstyle, arrowtailstyle))
if adoptionsdashed and frel != _("Birth"):
file.write('style=dashed')
else:
file.write('style=solid')
file.write('];\n')
mother = family.getMother()
if mother and mother in person_list:
mid = string.replace(mother.getId(),'-','_')
file.write('p%s -> p%s [' % (pid, fid))
file.write('arrowhead=%s, arrowtail=%s, ' % (arrowheadstyle, arrowtailstyle))
if adoptionsdashed and mrel != _("Birth"):
file.write('style=dashed')
else:
file.write('style=solid')
file.write('];\n')
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
def dump_index(person_list,file,includedates,includeurl,colorize):
for person in person_list:
label = person.getPrimaryName().getName()
id = string.replace(person.getId(),'-','_')
@ -282,6 +355,14 @@ def dump_index(person_list,file,includedates,includeurl):
file.write('p%s [shape=box, ' % id)
if includeurl:
file.write('URL="%s.html", ' % id)
if colorize:
gender = person.getGender()
if gender == person.male:
file.write('color=dodgerblue4, ')
elif gender == person.female:
file.write('color=deeppink, ')
else:
file.write('color=black, ')
file.write('fontname="Arial", label="%s"];\n' % label)
#------------------------------------------------------------------------