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] return [all,des,ans]
def add_user_options(self): def add_user_options(self):
self.arrowstyle_optionmenu = GtkOptionMenu()
self.arrowhead_optionmenu = GtkOptionMenu()
menu = GtkMenu() menu = GtkMenu()
menuitem = GtkMenuItem(_("Descendants <- Ancestors")) menuitem = GtkMenuItem(_("Descendants <- Ancestors"))
menuitem.set_data('i', '[arrowhead=none, arrowtail=normal]') menuitem.set_data('t', ('none', 'normal'))
menuitem.show() menuitem.show()
menu.append(menuitem) menu.append(menuitem)
menuitem = GtkMenuItem(_("Descendants -> Ancestors")) menuitem = GtkMenuItem(_("Descendants -> Ancestors"))
menuitem.set_data('i', '[arrowhead=normal, arrowtail=none]') menuitem.set_data('t', ('normal', 'none'))
menuitem.show() menuitem.show()
menu.append(menuitem) menu.append(menuitem)
menuitem = GtkMenuItem(_("Descendants <-> Ancestors")) 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() menuitem.show()
menu.append(menuitem) menu.append(menuitem)
menu.set_active(0) menu.set_active(0)
self.arrowhead_optionmenu.set_menu(menu)
self.add_frame_option(_("GraphViz Options"), _("Arrowhead Options"), self.arrowstyle_optionmenu.set_menu(menu)
self.arrowhead_optionmenu,
self.add_frame_option(_("GraphViz Options"),
_("Arrowhead Options"),
self.arrowstyle_optionmenu,
_("Choose the direction that the arrows point.")) _("Choose the direction that the arrows point."))
msg = _("Include Birth and Death Dates") msg = _("Include Birth and Death Dates")
self.includedates_checkbutton = GtkCheckButton(msg) self.includedates_cb = GtkCheckButton(msg)
self.includedates_checkbutton.set_active(1) self.includedates_cb.set_active(1)
self.add_frame_option(_("GraphViz Options"), '', self.add_frame_option(_("GraphViz Options"), '',
self.includedates_checkbutton, self.includedates_cb,
_("Include the years that the individual " _("Include the years that the individual "
"was born and/or died in the graph node " "was born and/or died in the graph node "
"labels.")) "labels."))
self.includeurl_checkbutton = GtkCheckButton(_("Include URLs")) self.includeurl_cb = GtkCheckButton(_("Include URLs"))
self.includeurl_checkbutton.set_active(1) self.includeurl_cb.set_active(1)
self.add_frame_option(_("GraphViz Options"), '', self.add_frame_option(_("GraphViz Options"), '',
self.includeurl_checkbutton, self.includeurl_cb,
_("Include a URL in each graph node so " _("Include a URL in each graph node so "
"that PDF and imagemap files can be " "that PDF and imagemap files can be "
"generated that contain active links " "generated that contain active links "
"to the files generated by the 'Generate " "to the files generated by the 'Generate "
"Web Site' report.")) "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, tb_margin_adj = GtkAdjustment(value=0.5, lower=0.25,
upper=100.0, step_incr=0.25) upper=100.0, step_incr=0.25)
lr_margin_adj = GtkAdjustment(value=0.5, lower=0.25, lr_margin_adj = GtkAdjustment(value=0.5, lower=0.25,
@ -151,6 +177,28 @@ class GraphVizDialog(ReportDialog):
_("Left & Right Margins"), _("Left & Right Margins"),
self.lr_margin_sb) 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 # Functions related to selecting/changing the current file format
@ -187,12 +235,16 @@ class GraphVizDialog(ReportDialog):
pass pass
def parse_other_frames(self): def parse_other_frames(self):
menu = self.arrowhead_optionmenu.get_menu() menu = self.arrowstyle_optionmenu.get_menu()
self.arrowhead_option = menu.get_active().get_data('i') self.arrowheadstyle, self.arrowtailstyle = menu.get_active().get_data('t')
self.includedates = self.includedates_checkbutton.get_active() self.includedates = self.includedates_cb.get_active()
self.includeurl = self.includeurl_checkbutton.get_active() self.includeurl = self.includeurl_cb.get_active()
self.tb_margin = self.tb_margin_sb.get_value_as_float() self.tb_margin = self.tb_margin_sb.get_value_as_float()
self.lr_margin = self.lr_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()) ind_list = self.filter.apply(self.db.getPersonMap().values())
file.write("digraph g {\n") write_dot(file, ind_list, self.orien, width, height,
file.write("bgcolor=white;\n") self.tb_margin, self.lr_margin, self.hpages,
file.write("rankdir=LR;\n") self.vpages, self.includedates, self.includeurl,
file.write("center=1;\n") self.colorize, self.adoptionsdashed, self.arrowheadstyle, self.arrowtailstyle)
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()
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -245,27 +278,67 @@ def report(database,person):
# #
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def dump_person(person_list,file,arrowhead_option): def write_dot(file, ind_list, orien, width, height, tb_margin,
for person in person_list: lr_margin, hpages, vpages, includedates, includeurl,
pid = string.replace(person.getId(),'-','_') colorize, adoptionsdashed, arrowheadstyle, arrowtailstyle):
family = person.getMainParents() file.write("digraph g {\n")
if family == None: file.write("bgcolor=white;\n")
continue file.write("rankdir=LR;\n")
father = family.getFather() file.write("center=1;\n")
if father and father in person_list: file.write("margin=0.5;\n")
fid = string.replace(father.getId(),'-','_') file.write("ratio=fill;\n")
file.write('p%s -> p%s %s;\n' % (pid, fid, arrowhead_option)) file.write("size=\"%3.1f,%3.1f\";\n" % ((width * hpages) - (lr_margin * 2) - ((hpages - 1) * 1.0),
mother = family.getMother() (height * vpages) - (tb_margin * 2) - ((vpages - 1) * 1.0)))
if mother and mother in person_list: file.write("page=\"%3.1f,%3.1f\";\n" % (width,height))
mid = string.replace(mother.getId(),'-','_')
file.write('p%s -> p%s %s;\n' % (pid, mid, arrowhead_option)) 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: for person in person_list:
label = person.getPrimaryName().getName() label = person.getPrimaryName().getName()
id = string.replace(person.getId(),'-','_') id = string.replace(person.getId(),'-','_')
@ -282,6 +355,14 @@ def dump_index(person_list,file,includedates,includeurl):
file.write('p%s [shape=box, ' % id) file.write('p%s [shape=box, ' % id)
if includeurl: if includeurl:
file.write('URL="%s.html", ' % id) 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) file.write('fontname="Arial", label="%s"];\n' % label)
#------------------------------------------------------------------------ #------------------------------------------------------------------------