Charts coloured by gender, the self box unsmudged (#116)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
hum3 2026-11-03 16:00:45 +00:00
commit ae4865a028
15 changed files with 248 additions and 14 deletions

View file

@ -55,6 +55,7 @@ life-weaver dir jm1fj00 # 3/0j/m1/fj/00
|---|---|
| `name`, `short` | Full name; the short form links use |
| `summary` | One line under the name |
| `gender` | `female`, `male` or `other`; left out when unknown. Charts colour by it |
| `portrait` | A file under `files/`, the picture at the head of the page |
| `born`, `died`, `buried` | `date` (ISO prefix: `1894`, `1894-10`, `1894-10-14`) and `place` |
| `parents` | IDs. Children and siblings are derived from these |
@ -95,6 +96,7 @@ are to items the same person holds; another's is shown as a bare id.
| Record | The YAML file holding what we know of a person |
| Register | A directory of records with the ties between them checked |
| Family | A person's parents, spouses, siblings and children, derived from the register |
| Gender | What the record says, `gender`: `female`, `male` or `other`, left out when unknown; the chart's pink, blue and yellow (story 016) |
| Influence | Someone who shaped a person's upbringing without being a parent in the register's sense, with a role and a weight (`influences`, story 014) |
| Chart | A drawing of the kin around one person, the subject, from the register: rows by generation and the edges between them (`internal/chart`), drawn by `genealogy` to a directory with a `review.html` to judge by eye |
| Hourglass chart | Ancestors above the subject, descendants below, the subject's row with siblings in birth order and spouses beside them: a drop-line chart, each couple joined by a bar and their children hung from it; influences as dashed curves as wide as their weight |

1
changes/116.added.md Normal file
View file

@ -0,0 +1 @@
Charts colour each box by the record's new `gender` (`female`, `male`, `other`: pink, blue, yellow; the panel colour when unknown), and the self box's name is no longer smudged by its copper stroke (#116)

43
charts/0-hourglass.svg Normal file
View file

@ -0,0 +1,43 @@
<svg xmlns="http://www.w3.org/2000/svg" width="718.4" height="208" viewBox="0 0 718.4 208" font-family="system-ui, sans-serif" font-size="13">
<style>
:root {
--paper: #fefdfb;
--ink: #0f1953;
--muted: #546380;
--rule: #c8d9ef;
--panel: #ebf3fc;
--link: #2151bb;
--copper: #b4662f;
color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
:root {
--paper: #070d25;
--ink: #d8e6f9;
--muted: #909fb8;
--rule: #2e3a55;
--panel: #101834;
--link: #99c0f8;
--copper: #eea471;
}
}
.box { fill: var(--panel); stroke: var(--rule); }
.self { stroke: var(--copper); stroke-width: 2; }
.spouse { stroke-dasharray: 5 3; }
.influence { stroke: var(--muted); stroke-dasharray: 2 3; }
.tie { fill: none; stroke: var(--muted); stroke-width: 1.2; }
.influenced { fill: none; stroke: var(--link); stroke-dasharray: 6 4; }
.label { fill: var(--ink); } .years, .role { fill: var(--muted); font-size: 11px; }
</style>
<line class="tie" x1="347.2" y1="46" x2="371.2" y2="46"/>
<path class="tie" d="M98.8 140 V104 H359.2 V46"/>
<path class="tie" d="M272.4 140 V104 H359.2 V46"/>
<path class="tie" d="M446 140 V104 H359.2 V46"/>
<path class="tie" d="M619.5999999999999 140 V104 H359.2 V46"/>
<g class="kin"><rect class="box kin" x="197.6" y="24" width="149.6" height="44" rx="4"/><text class="label" x="272.4" y="42" text-anchor="middle">Malcolm Drummond</text><text class="years" x="272.4" y="58" text-anchor="middle">1856–1924</text></g>
<g class="kin"><rect class="box kin" x="371.2" y="24" width="149.6" height="44" rx="4"/><text class="label" x="446" y="42" text-anchor="middle">Geraldine Drummond</text><text class="years" x="446" y="58" text-anchor="middle">–1956</text></g>
<g class="sibling"><rect class="box sibling" x="24" y="140" width="149.6" height="44" rx="4"/><text class="label" x="98.8" y="158" text-anchor="middle">Jean Drummond</text><text class="years" x="98.8" y="174" text-anchor="middle">1891–1974</text></g>
<g class="self"><rect class="box self" x="197.6" y="140" width="149.6" height="44" rx="4"/><text class="label" x="272.4" y="158" text-anchor="middle">Victoria Drummond</text><text class="years" x="272.4" y="174" text-anchor="middle">1894–1978</text></g>
<g class="sibling"><rect class="box sibling" x="371.2" y="140" width="149.6" height="44" rx="4"/><text class="label" x="446" y="158" text-anchor="middle">Frances Drummond</text><text class="years" x="446" y="174" text-anchor="middle">1897–1974</text></g>
<g class="sibling"><rect class="box sibling" x="544.8" y="140" width="149.6" height="44" rx="4"/><text class="label" x="619.5999999999999" y="158" text-anchor="middle">John Drummond</text><text class="years" x="619.5999999999999" y="174" text-anchor="middle">1900–1982</text></g>
</svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

43
charts/3-hourglass.svg Normal file
View file

@ -0,0 +1,43 @@
<svg xmlns="http://www.w3.org/2000/svg" width="718.4" height="208" viewBox="0 0 718.4 208" font-family="system-ui, sans-serif" font-size="13">
<style>
:root {
--paper: #fefdfb;
--ink: #0f1953;
--muted: #546380;
--rule: #c8d9ef;
--panel: #ebf3fc;
--link: #2151bb;
--copper: #b4662f;
color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
:root {
--paper: #070d25;
--ink: #d8e6f9;
--muted: #909fb8;
--rule: #2e3a55;
--panel: #101834;
--link: #99c0f8;
--copper: #eea471;
}
}
.box { fill: var(--panel); stroke: var(--rule); }
.self { stroke: var(--copper); stroke-width: 2; }
.spouse { stroke-dasharray: 5 3; }
.influence { stroke: var(--muted); stroke-dasharray: 2 3; }
.tie { fill: none; stroke: var(--muted); stroke-width: 1.2; }
.influenced { fill: none; stroke: var(--link); stroke-dasharray: 6 4; }
.label { fill: var(--ink); } .years, .role { fill: var(--muted); font-size: 11px; }
</style>
<line class="tie" x1="347.2" y1="46" x2="371.2" y2="46"/>
<path class="tie" d="M98.8 140 V104 H359.2 V46"/>
<path class="tie" d="M272.4 140 V104 H359.2 V46"/>
<path class="tie" d="M446 140 V104 H359.2 V46"/>
<path class="tie" d="M619.5999999999999 140 V104 H359.2 V46"/>
<g class="kin"><rect class="box kin" x="197.6" y="24" width="149.6" height="44" rx="4"/><text class="label" x="272.4" y="42" text-anchor="middle">Malcolm Drummond</text><text class="years" x="272.4" y="58" text-anchor="middle">1856–1924</text></g>
<g class="kin"><rect class="box kin" x="371.2" y="24" width="149.6" height="44" rx="4"/><text class="label" x="446" y="42" text-anchor="middle">Geraldine Drummond</text><text class="years" x="446" y="58" text-anchor="middle">–1956</text></g>
<g class="self"><rect class="box self" x="24" y="140" width="149.6" height="44" rx="4"/><text class="label" x="98.8" y="158" text-anchor="middle">Jean Drummond</text><text class="years" x="98.8" y="174" text-anchor="middle">1891–1974</text></g>
<g class="sibling"><rect class="box sibling" x="197.6" y="140" width="149.6" height="44" rx="4"/><text class="label" x="272.4" y="158" text-anchor="middle">Victoria Drummond</text><text class="years" x="272.4" y="174" text-anchor="middle">1894–1978</text></g>
<g class="sibling"><rect class="box sibling" x="371.2" y="140" width="149.6" height="44" rx="4"/><text class="label" x="446" y="158" text-anchor="middle">Frances Drummond</text><text class="years" x="446" y="174" text-anchor="middle">1897–1974</text></g>
<g class="sibling"><rect class="box sibling" x="544.8" y="140" width="149.6" height="44" rx="4"/><text class="label" x="619.5999999999999" y="158" text-anchor="middle">John Drummond</text><text class="years" x="619.5999999999999" y="174" text-anchor="middle">1900–1982</text></g>
</svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

21
charts/review.html Normal file
View file

@ -0,0 +1,21 @@
<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Charts to review</title>
<style>
body { font-family: system-ui, sans-serif; margin: 2rem; color-scheme: light dark; }
h2 { font-weight: normal; margin: 2rem 0 .5rem; }
h2 small { color: #777; }
figure { margin: 0; overflow-x: auto; }
</style>
</head>
<body>
<h1>Charts to review</h1>
<h2>Victoria Alexandrina Drummond <small>1894–1978</small></h2>
<figure><img src="0-hourglass.svg" alt="The hourglass chart of Victoria Alexandrina Drummond"></figure>
<h2>Jean Drummond <small>1891–1974</small></h2>
<figure><img src="3-hourglass.svg" alt="The hourglass chart of Jean Drummond"></figure>
</body>
</html>

View file

@ -0,0 +1,59 @@
# 016 — Charts coloured by gender, the self box unsmudged (#116)
**Status:** built
**Roadmap:** none — story 014's chart, seen on the review page
## Why
On the review page the subject's name is smudged: the copper stroke
meant for the self box is on the group around it, so the text takes it
too and comes out bold and clashing. And every box is the same colour,
so a reader cannot see at a glance who is who; charts colour by gender,
and the record has nowhere to say it.
## Vocabulary
| Term | Meaning |
|---|---|
| Gender | What the record says, `gender`: `female`, `male` or `other`; left out when unknown |
## What changes
- `person.Person` gains `gender`, optional, one of `female`, `male`,
`other`; anything else is refused at load, so a chart can colour by
it. README's field table and vocabulary.
- `chart.Box` carries Gender; `chart.SVG` tints the box pink, blue or
yellow by it in both schemes, the panel colour for unknown. The role
class (self, spouse, influence) goes on the rect alone, so the text is
drawn as every other box's text.
## Acceptance
| Record | Load |
|---|---|
| no `gender` | accepted; the box is the panel colour |
| `gender: female` / `male` / `other` | accepted; pink / blue / yellow |
| `gender: f` | refused: `… gender "f": want female, male or other` |
| Box | Drawn |
|---|---|
| any | the name and years in the ink, no stroke, whatever the role |
| self | the rect's stroke copper, 2 px |
## Out of scope
- Gender on the person page or the facts list.
- Any other field of identity.
## Decisions
- An enumeration, not free text: the chart colours by it, and a colour
needs a known value. `other` is the third value rather than a longer
list the chart could not colour anyway.
## Done when
- [x] tests express the acceptance tables and pass
- [x] README: `gender` field, vocabulary
- [x] changelog entry
- [ ] issue closed with a link to the release

View file

@ -28,13 +28,15 @@ type Row struct {
}
// Box is one person on the chart. X is the box's left edge in box widths,
// 0 the leftmost on the chart; a row's boxes are at least 1 apart.
// 0 the leftmost on the chart; a row's boxes are at least 1 apart. Gender
// is the record's, "" when unknown.
type Box struct {
ID pid.ID
Label string
Years string
Role Role
X float64
ID pid.ID
Label string
Years string
Gender string
Role Role
X float64
}
// Role is how a box stands to the subject.
@ -170,7 +172,7 @@ func (b *builder) place(p *person.Person, gen int, x float64, role Role) {
if b.boxes == nil {
b.boxes = map[pid.ID]Box{}
}
box := Box{ID: p.ID, Label: p.Label(), Years: p.Years(), Role: role, X: x}
box := Box{ID: p.ID, Label: p.Label(), Years: p.Years(), Gender: p.Gender, Role: role, X: x}
b.rows[gen] = append(b.rows[gen], box)
b.placed[p.ID] = true
b.boxes[p.ID] = box

View file

@ -196,6 +196,27 @@ func leftmost(c Chart) float64 {
return left
}
// Boxes carry the record's gender, and the drawing tints them by it; the
// role class is on the rect alone, so no text inherits a stroke.
func TestSVGColoursByGenderAndStrokesOnlyTheRect(t *testing.T) {
reg := load(t)
ch := hourglass(t, reg, 0, 2, 2)
for id, want := range map[pid.ID]string{0: "female", 1: "male", 9: "", 4: "other"} {
if got := box(ch, id).Gender; got != want {
t.Errorf("Gender of %s = %q, want %q", id, got, want)
}
}
svg := string(SVG(ch))
for _, want := range []string{`<rect class="box self female"`, `<rect class="box kin male"`, `<rect class="box influence"`, `<rect class="box kin other"`, ".female {", ".male {", ".other {"} {
if !strings.Contains(svg, want) {
t.Errorf("SVG() lacks %q", want)
}
}
if strings.Contains(svg, "<g class=") {
t.Errorf("SVG() puts a role class on a group, which its text would inherit")
}
}
func TestSVG(t *testing.T) {
reg := load(t)
svg := string(SVG(hourglass(t, reg, 0, 2, 2)))

View file

@ -5,6 +5,7 @@ import (
"fmt"
"html"
"math"
"strings"
"git.bytestone.uk/hum3/life-weaver/internal/brand"
"git.bytestone.uk/hum3/life-weaver/pid"
@ -20,8 +21,8 @@ const (
fontSize = 13
)
// SVG draws the chart: the self box in copper, spouses dashed, influences
// dotted, couples joined by a bar, children hung from it by a rail, and
// SVG draws the chart: boxes tinted by gender, the self box in copper,
// spouses dashed, influences dotted, couples joined by a bar, children hung from it by a rail, and
// each influence a dashed curve as wide as its weight with the role on
// it. The brand's palette is in the file, so it follows the scheme.
func SVG(c Chart) []byte {
@ -55,9 +56,12 @@ func SVG(c Chart) []byte {
fmt.Fprintf(&w, `<svg xmlns="http://www.w3.org/2000/svg" width="%g" height="%g" viewBox="0 0 %g %g" font-family="system-ui, sans-serif" font-size="%d">`+"\n", width, height, width, height, fontSize)
w.WriteString("<style>\n" + brand.CSS() +
".box { fill: var(--panel); stroke: var(--rule); }\n" +
".self { stroke: var(--copper); stroke-width: 2; }\n" +
".spouse { stroke-dasharray: 5 3; }\n" +
".influence { stroke: var(--muted); stroke-dasharray: 2 3; }\n" +
".box.self { stroke: var(--copper); stroke-width: 2; }\n" +
".box.spouse { stroke-dasharray: 5 3; }\n" +
".box.influence { stroke: var(--muted); stroke-dasharray: 2 3; }\n" +
// the tints by gender: pink, blue, yellow, pale on paper and deep on night
".female { fill: #fce4ee; } .male { fill: #cfe0fa; } .other { fill: #fbf2cf; }\n" +
"@media (prefers-color-scheme: dark) { .female { fill: #4a2239; } .male { fill: #1a2f5c; } .other { fill: #4a3d12; } }\n" +
".tie { fill: none; stroke: var(--muted); stroke-width: 1.2; }\n" +
".influenced { fill: none; stroke: var(--link); stroke-dasharray: 6 4; }\n" +
".label { fill: var(--ink); } .years, .role { fill: var(--muted); font-size: 11px; }\n" +
@ -133,8 +137,8 @@ func SVG(c Chart) []byte {
for _, r := range c.Rows {
for _, b := range r.Boxes {
p := at[b.ID]
fmt.Fprintf(&w, `<g class="%s"><rect class="box %s" x="%g" y="%g" width="%g" height="%d" rx="4"/>`,
b.Role, b.Role, p.x, p.y, boxW, boxH)
fmt.Fprintf(&w, `<g><rect class="%s" x="%g" y="%g" width="%g" height="%d" rx="4"/>`,
strings.TrimSpace(fmt.Sprintf("box %s %s", b.Role, b.Gender)), p.x, p.y, boxW, boxH)
fmt.Fprintf(&w, `<text class="label" x="%g" y="%g" text-anchor="middle">%s</text>`, p.x+boxW/2, p.y+18, html.EscapeString(b.Label))
if b.Years != "" {
fmt.Fprintf(&w, `<text class="years" x="%g" y="%g" text-anchor="middle">%s</text>`, p.x+boxW/2, p.y+34, html.EscapeString(b.Years))

View file

@ -1,4 +1,5 @@
name: Victoria Example
gender: female
short: Victoria
born:
date: 1894-10-14

View file

@ -1,4 +1,5 @@
name: Malcolm Example
gender: male
short: Malcolm
born:
date: 1856

View file

@ -1,4 +1,5 @@
name: Walter Example
gender: other
short: Walter
born:
date: 1830

View file

@ -20,6 +20,13 @@ type Marriage struct {
Place string `yaml:"place,omitempty" json:"place,omitempty"`
}
// The words gender may be (story 016); "" is unknown.
const (
Female = "female"
Male = "male"
Other = "other"
)
// Influence is someone who shaped a person's upbringing without being a
// parent in the register's sense: a nanny, a grandparent who took them
// in, a guardian, a godparent. Role is the record's own words; Weight,
@ -68,6 +75,7 @@ type Person struct {
Name string `yaml:"name" json:"name"`
Short string `yaml:"short,omitempty" json:"short,omitempty"`
Summary string `yaml:"summary,omitempty" json:"summary,omitempty"`
Gender string `yaml:"gender,omitempty" json:"gender,omitempty"` // Female, Male or Other; "" when unknown
Portrait string `yaml:"portrait,omitempty" json:"portrait,omitempty"` // a file under files/, shown at the head of the page
Born Event `yaml:"born,omitempty" json:"born,omitzero"`
Died Event `yaml:"died,omitempty" json:"died,omitzero"`

View file

@ -308,3 +308,25 @@ func TestInfluences(t *testing.T) {
t.Errorf("NewRegister() error = %v, want one mentioning influence 7", err)
}
}
// Gender is one of three words or left out (story 016): a chart colours by it.
func TestGender(t *testing.T) {
for _, g := range []string{"", "female", "male", "other"} {
yaml := "name: A\n"
if g != "" {
yaml += "gender: " + g + "\n"
}
reg, err := Load(writeRegister(t, map[string]string{"0/00/person.yaml": yaml}))
if err != nil {
t.Errorf("gender %q: Load() error = %v", g, err)
continue
}
if p, _ := reg.Get(0); p.Gender != g {
t.Errorf("Gender = %q, want %q", p.Gender, g)
}
}
_, err := Load(writeRegister(t, map[string]string{"0/00/person.yaml": "name: A\ngender: f\n"}))
if err == nil || !strings.Contains(err.Error(), `gender "f"`) {
t.Errorf("Load() error = %v, want one refusing gender \"f\"", err)
}
}

View file

@ -148,6 +148,11 @@ func (p *Person) validate() error {
return fmt.Errorf("marriage: %w", err)
}
}
switch p.Gender {
case "", Female, Male, Other:
default:
return fmt.Errorf("gender %q: want %s, %s or %s", p.Gender, Female, Male, Other)
}
return nil
}