Bug 2950. Made subgraph optional for Relationship Graph as discussed in bug report. Moved the option to GraphvizReportDialog and refactored FamilyLines to use it.

svn: r12596
This commit is contained in:
Gary Burton 2009-05-30 12:12:58 +00:00
parent ed13f340d5
commit cc38a53add
3 changed files with 81 additions and 60 deletions

View File

@ -3,6 +3,7 @@
#
# Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2007-2009 Stephane Charette
# Copyright (C) 2009 Gary Burton
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -52,7 +53,8 @@ import Config
from ReportBase import CATEGORY_GRAPHVIZ
from _ReportDialog import ReportDialog
from _PaperMenu import PaperFrame
from gen.plug.menu import NumberOption, TextOption, EnumeratedListOption
from gen.plug.menu import NumberOption, TextOption, EnumeratedListOption, \
BooleanOption
#-------------------------------------------------------------------------------
#
@ -171,6 +173,7 @@ class GVDocBase(BaseDoc, GVDoc):
self.ranksep = menu.get_option_by_name('ranksep').get_value()
self.ratio = menu.get_option_by_name('ratio').get_value()
self.vpages = menu.get_option_by_name('v_pages').get_value()
self.usesubgraphs = menu.get_option_by_name('usesubgraphs').get_value()
paper_size = paper_style.get_size()
@ -1019,6 +1022,13 @@ class GraphvizReportDialog(ReportDialog):
"between columns."))
self.options.add_menu_option(category, "ranksep", ranksep)
use_subgraphs = BooleanOption(_('Use subgraphs'), True)
use_subgraphs.set_help(_("Subgraphs can help GraphViz position "
"spouses together, but with non-trivial "
"graphs will result in longer lines and "
"larger graphs."))
self.options.add_menu_option(category, "usesubgraphs", use_subgraphs)
################################
category = _("Note")
################################

View File

@ -218,13 +218,6 @@ class FamilyLinesOptions(MenuReportOptions):
'between women and men.'))
menu.add_option(category, "useroundedcorners", use_roundedcorners)
use_subgraphs = BooleanOption(_('Use subgraphs'), False)
use_subgraphs.set_help(_("Subgraphs can help GraphViz position "
"certain linked nodes closer together, "
"but with non-trivial graphs will result "
"in longer lines and larger graphs."))
menu.add_option(category, "usesubgraphs", use_subgraphs)
self.include_dates = BooleanOption(_('Include dates'), True)
self.include_dates.set_help(_('Whether to include dates for people ' \
'and families.'))

View File

@ -125,6 +125,7 @@ class RelGraphReport(Report):
self.show_families = menu.get_option_by_name('showfamily').get_value()
self.just_years = menu.get_option_by_name('justyears').get_value()
self.use_place = menu.get_option_by_name('use_place').get_value()
self.use_subgraphs = menu.get_option_by_name('usesubgraphs').get_value()
self.colorize = menu.get_option_by_name('color').get_value()
color_males = menu.get_option_by_name('colormales').get_value()
@ -243,14 +244,28 @@ class RelGraphReport(Report):
if self.show_families:
family_list = person.get_family_handle_list()
for fam_handle in family_list:
fam = self.database.get_family_from_handle(fam_handle)
fam_id = fam.get_gramps_id()
family = self.database.get_family_from_handle(fam_handle)
fam_id = family.get_gramps_id()
if fam_handle not in families_done:
families_done[fam_handle] = 1
self.__add_family(fam_handle)
# If subgraphs are not chosen then each parent is linked
# separately to the family. This gives Graphviz greater
# control over the layout of the whole graph but
# may leave spouses not positioned together.
if not self.use_subgraphs:
self.doc.add_link(fam_id, p_id, "",
self.arrowheadstyle,
self.arrowtailstyle)
def __add_family(self, fam_handle):
"""Add a node for a family and optionally link the spouses to it"""
fam = self.database.get_family_from_handle(fam_handle)
fam_id = fam.get_gramps_id()
label = ""
for event_ref in fam.get_event_ref_list():
event = self.database.get_event_from_handle(
event_ref.ref)
event = self.database.get_event_from_handle(event_ref.ref)
if event.type == gen.lib.EventType.MARRIAGE:
label = self.get_event_string(event)
break
@ -264,26 +279,29 @@ class RelGraphReport(Report):
elif self.colorize == 'filled':
fill = self.colors['family']
style = "filled"
self.doc.add_node(fam_id, label, "ellipse",
color, style, fill)
self.doc.add_node(fam_id, label, "ellipse", color, style, fill)
# If subgraphs are used then we add both spouses here and Graphviz
# will attempt to position both spouses closely together.
# TODO: A person who is a parent in more than one family may only be
# positioned next to one of their spouses. The code currently
# does not take into account multiple spouses.
if self.use_subgraphs:
self.doc.start_subgraph(fam_id)
f_handle = fam.get_father_handle()
m_handle = fam.get_mother_handle()
self.doc.start_subgraph(fam_id)
if f_handle:
father = \
self.database.get_person_from_handle(f_handle)
father = self.database.get_person_from_handle(f_handle)
self.doc.add_link(fam_id,
father.get_gramps_id(), "",
self.arrowheadstyle,
self.arrowtailstyle )
self.arrowtailstyle)
if m_handle:
mother = \
self.database.get_person_from_handle(m_handle)
mother = self.database.get_person_from_handle(m_handle)
self.doc.add_link(fam_id,
mother.get_gramps_id(), "",
self.arrowheadstyle,
self.arrowtailstyle )
self.arrowtailstyle)
self.doc.end_subgraph()
def get_gender_style(self, person):