Με λίγα λόγια
Δύο σελίδες ενός οδηγού δήμου: ποιος ευθύνεται για τι, ως διάγραμμα από πλαίσια ενωμένα με γραμμές, και πού βρίσκεται κάθε υπηρεσία, ως σειρές εικόνων. Οι σελίδες φτιάχνονται από λίγα επαναχρησιμοποιήσιμα μπλοκ· το Markdown λέει πόσα.
Τι θα στοιχειοθετήσετε
Ένα δισέλιδο από τον οδηγό υπηρεσιών της Valdeloma, μιας επινοημένης πόλης 8.400 κατοίκων. Η αριστερή σελίδα είναι το οργανόγραμμα του δήμου: ο δήμαρχος και το δημοτικό συμβούλιο σε ένα κόκκινο πλαίσιο, τέσσερα τμήματα σε πράσινο, και οι υπηρεσίες κάθε τμήματος σε ανοιχτόχρωμα πλαίσια από κάτω του, ενωμένες με πράσινες γραμμές με μια κουκκίδα ή ένα βέλος στις άκρες τους. Η δεξιά σελίδα δείχνει πού βρίσκονται οι υπηρεσίες: δύο πεδία με τρεις υδατογραφίες το καθένα, με το όνομα, τη διεύθυνση και το ωράριο κάτω από κάθε εικόνα, και ένα πλαίσιο για το γραφείο εξυπηρέτησης δημοτών. Τίποτα δεν σχεδιάζεται με το χέρι. Το πρότυπο κρατά τρεις μονάδες (ένα τμήμα, ένα πεδίο φωτογραφιών και μια ανακοίνωση), και κάθε σελίδα στοιβάζει όσες από αυτές έχει το Markdown της· οι γραμμές ακολουθούν τα πλαίσια όπου κι αν τα βάλει το κείμενο.
Αυτή η συνταγή απαντά
- Πώς φτιάχνω οργανόγραμμα και πλέγμα φωτογραφιών από επαναχρησιμοποιήσιμες μονάδες, με τις γραμμές να τις σχεδιάζει το πρότυπο;
Η σύντομη απάντηση
// The page template draws the head of the chart and a group that takes the page's modules;
// the module draws one area: its box, a grid of its services and the lines between them.
const area = {
id: 'area', role: 'module',
frames: [
{ name: 'concejalia', style: 'area', width: mm(84), placement: at('container', 'top-left') },
{ name: 'servicio', style: 'servicio' }, // repeated: one per :::frame{slot="servicio"}
],
groups: [{ name: 'servicios', kind: 'grid', columns: 3, columnGap: mm(4), rowGap: mm(4),
repeat: { frames: ['servicio'] }, // rowAlign 'stretch': a row's boxes are one height
placement: { ...at('#concejalia', 'below', 0, 7), size: { width: 'fill', height: 'fill' } } }],
decoration: { elements: [
// From the area down to each of its services: a tree with a bar over the row.
line({ id: 'rama', routing: 'tree', from: { to: '#concejalia', side: 'bottom' },
to: { to: '#servicio[*]', side: 'top' }, endCap: 'dot', capSize: mm(1.8) }),
// From the mayor's box, a frame of the page, to this area: the spine and its branch.
line({ id: 'tronco', routing: 'elbow', width: pt(1.8),
from: { to: '#alcaldia', side: 'bottom', at: 0.06 }, to: { to: '#concejalia', side: 'left' },
endCap: 'arrow', capSize: mm(2.6) }),
] },
};
const chart = {
id: 'organigrama',
frames: [
{ name: 'titulo', takes: 'h1', width: mm(W), placement: at('container', 'top-left') },
{ name: 'entradilla', flow: true, width: mm(W) },
{ name: 'alcaldia', style: 'alcaldia', width: mm(96) },
],
groups: [{ name: 'cabeza', kind: 'stack', gap: mm(6),
frames: ['titulo', 'entradilla', 'alcaldia'] },
{ name: 'areas', modules: true, gap: mm(6), placement: { ...at('#alcaldia', 'below', SPINE, 9),
size: { width: mm(W - SPINE), height: 'fill' } } }],
};
Υλικά
- Λειτουργίες
- Μονάδες στοιβαγμένες σε μια σελίδαΣυνδέσεις ανάμεσα σε πλαίσια κειμένουΠλέγματα που επαναλαμβάνουν ένα σύνολο πλαισίωνΣτοιχειοθετημένες σελίδεςΠλαίσια κειμένου που μεγαλώνουν σε ομάδαΔιακόσμηση αγκυρωμένη σε πλαίσια κειμένουΠλαίσια σημειώσεωνΣυμμετρικά περιθώριαΤρέχουσες κεφαλίδες και αριθμοί σελίδαςΕικόνες και πίνακες ως πόροιΣημασιολογική χρωματική παλέταΣελίδες σε καμβάΕξαγωγή PDF
- Χρησιμοποιεί επίσης
- Αριθμημένες καρτέλες πλαισίωνΕικόνες ακριβώς εδώΓραμματοσειρές ενσωματωμένες στο PDFΠροσαρμοσμένοι τύποι πόρων
- Γραμματοσειρές
- Public Sans, Source Serif 4 (SIL OFL 1.1)
- Αρχεία
biblioteca-900.jpgcentro-mayores-900.jpgmercado-900.jpgmusica-900.jpgpiscina-900.jpgpolideportivo-900.jpg- The reading room of a town library, in watercolour. (Generated With Diffusion Models, πρωτότυπο)
- Children with violins and a piano at a music school, in watercolour. (Generated With Diffusion Models, πρωτότυπο)
- Older people playing cards and painting at a day centre, in watercolour. (Generated With Diffusion Models, πρωτότυπο)
- A covered pool under a timber roof, in watercolour. (Generated With Diffusion Models, πρωτότυπο)
- Children playing basketball in a sports hall, in watercolour. (Generated With Diffusion Models, πρωτότυπο)
- A Saturday market under the arcades of a town square, in watercolour. (Generated With Diffusion Models, πρωτότυπο)
Προετοιμασία
#1 · Μία μονάδα ανά τμήμα
// The page template draws the head of the chart and a group that takes the page's modules;
// the module draws one area: its box, a grid of its services and the lines between them.
const area = {
id: 'area', role: 'module',
frames: [
{ name: 'concejalia', style: 'area', width: mm(84), placement: at('container', 'top-left') },
{ name: 'servicio', style: 'servicio' }, // repeated: one per :::frame{slot="servicio"}
],
groups: [{ name: 'servicios', kind: 'grid', columns: 3, columnGap: mm(4), rowGap: mm(4),
repeat: { frames: ['servicio'] }, // rowAlign 'stretch': a row's boxes are one height
placement: { ...at('#concejalia', 'below', 0, 7), size: { width: 'fill', height: 'fill' } } }],
decoration: { elements: [
// From the area down to each of its services: a tree with a bar over the row.
line({ id: 'rama', routing: 'tree', from: { to: '#concejalia', side: 'bottom' },
to: { to: '#servicio[*]', side: 'top' }, endCap: 'dot', capSize: mm(1.8) }),
// From the mayor's box, a frame of the page, to this area: the spine and its branch.
line({ id: 'tronco', routing: 'elbow', width: pt(1.8),
from: { to: '#alcaldia', side: 'bottom', at: 0.06 }, to: { to: '#concejalia', side: 'left' },
endCap: 'arrow', capSize: mm(2.6) }),
] },
};
const chart = {
id: 'organigrama',
frames: [
{ name: 'titulo', takes: 'h1', width: mm(W), placement: at('container', 'top-left') },
{ name: 'entradilla', flow: true, width: mm(W) },
{ name: 'alcaldia', style: 'alcaldia', width: mm(96) },
],
groups: [{ name: 'cabeza', kind: 'stack', gap: mm(6),
frames: ['titulo', 'entradilla', 'alcaldia'] },
{ name: 'areas', modules: true, gap: mm(6), placement: { ...at('#alcaldia', 'below', SPINE, 9),
size: { width: mm(W - SPINE), height: 'fill' } } }],
};
Ένα πρότυπο με role: 'module' είναι μια μονάδα: λίγα πλαίσια κειμένου, ομάδες και διάκοσμος, φτιαγμένα για να ξαναχρησιμοποιούνται. Η σελίδα του οργανογράμματος έχει μια ομάδα με modules: true, και κάθε :::module{template="area"} του Markdown της βάζει ένα ακόμη τμήμα κάτω από το προηγούμενο, με απόσταση 6 mm. Τα πλαίσια κειμένου της μονάδας παίρνουν το όνομα του στιγμιοτύπου, area[1].concejalia, area[2].concejalia…, οπότε οι δύο γραμμές σύνδεσής της γράφονται μία φορά: το rama, ένα tree από τη βάση του τμήματος προς κάθε υπηρεσία του πλέγματός του (#servicio[*]), και το tronco, ένα elbow από ένα σημείο κοντά στην αριστερή πλευρά του πλαισίου του δημάρχου (at: 0.06) ως την αριστερή πλευρά του τμήματος. Το #alcaldia είναι πλαίσιο κειμένου της σελίδας, όχι της μονάδας: η μονάδα κρατά την άκρη, και η σελιδοποίηση τη βρίσκει στη σελίδα, οπότε οι τέσσερις γωνιακές γραμμές μοιράζονται το πρώτο τους τμήμα και διαβάζονται ως μία κεντρική γραμμή με ένα βέλος προς κάθε τμήμα. Οι υπηρεσίες είναι ένα πλέγμα τριών στηλών που επαναλαμβάνει ένα πλαίσιο κειμένου servicio, οπότε ένα τμήμα με δύο υπηρεσίες σχεδιάζει δύο πλαίσια και το δέντρο έχει δύο κλάδους.
#2 · Πεδία με κάρτες φωτογραφιών
const gallery = {
id: 'galeria', role: 'module',
frames: [
{ name: 'cabecera', takes: 'h2', placement: at('container', 'top-left', 4, 4) },
{ name: 'foto', style: 'marco' }, // the photo of a card
{ name: 'pie', style: 'ficha', placement: at('#foto', 'below', 0, 2.5) }, // and its words
],
groups: [{ name: 'fotos', kind: 'grid', columns: 3, columnGap: mm(5), rowGap: mm(6),
rowAlign: 'start', repeat: { frames: ['foto', 'pie'] },
placement: { ...at('#cabecera', 'below', 0, 3), size: { width: mm(W - 8), height: 'fill' } } }],
// The module's own ground: a tint as large as the module, whatever its rows.
decoration: { elements: [{ kind: 'box', id: 'suelo',
placement: { ...at('container', 'top-left'), size: { width: 'fill', height: 'fill' } },
style: { backgroundColor: col('tint'), borderRadius: mm(3) } }] },
};
// A notice box as a module of its own: one frame whose tab grows out of the box (joined).
const notice = { id: 'aviso', role: 'module', frames: [{ name: 'texto', style: 'aviso',
placement: at('container', 'top-left', 0, 7) }] };
const places = {
id: 'centros',
frames: [
{ name: 'titulo', takes: 'h1', width: mm(W), placement: at('container', 'top-left') },
{ name: 'entradilla', flow: true, width: mm(W) },
{ name: 'colofon', style: 'colofon', optional: true, width: mm(W),
placement: at('container', 'bottom-left', 0, 8) },
],
groups: [{ name: 'cabeza', kind: 'stack', gap: mm(5), frames: ['titulo', 'entradilla'] },
{ name: 'galerias', modules: true, gap: mm(7), placement: { ...at('#entradilla', 'below', 0, 7),
size: { width: mm(W), height: 'fill' } } }],
};
Και ένα πεδίο είναι μονάδα: ένα πλαίσιο κειμένου επικεφαλίδας που παίρνει την επικεφαλίδα ## της μονάδας, και ένα πλέγμα που επαναλαμβάνει ένα σύνολο δύο πλαισίων κειμένου, τη φωτογραφία και τις λέξεις κάτω από αυτήν. Κάθε :::frame{slot="foto"} είναι μία κάρτα, και το :::frame{slot="pie"} μέσα του πηγαίνει στις λέξεις αυτής της κάρτας. Το χρωματισμένο φόντο είναι διάκοσμος της μονάδας, ένα πλαίσιο τόσο μεγάλο όσο η μονάδα, οπότε μεγαλώνει με τις σειρές και με τη μεγαλύτερη λεζάντα. Το γραφείο εξυπηρέτησης δημοτών είναι μια τρίτη μονάδα, ένα πλαίσιο του οποίου η καρτέλα είναι joined: η καρτέλα και το πλαίσιο είναι ένα περίγραμμα με ένα γέμισμα.
#3 · Εικόνες στο μέγεθος που τυπώνονται
const ART = {
biblioteca: t({ es: 'La sala de lectura de la biblioteca, con estanterías de madera y vecinos '
+ 'de todas las edades leyendo en mesas largas.',
en: 'The library reading room, with wooden shelves and neighbours of every age reading at '
+ 'long tables.' }),
musica: t({ es: 'Un aula de la escuela de música: niños con violines, una profesora y una niña '
+ 'al piano.',
en: 'A room of the music school: children with violins, a teacher and a girl at the piano.' }),
'centro-mayores': t({ es: 'El centro de día: mayores jugando a las cartas y pintando junto a '
+ 'una puerta al jardín.',
en: 'The day centre: older people playing cards and painting beside a door to the garden.' }),
piscina: t({ es: 'La piscina cubierta bajo un techo de madera, con nadadores en las calles y un '
+ 'socorrista.',
en: 'The covered pool under a timber roof, with swimmers in the lanes and a lifeguard.' }),
polideportivo: t({ es: 'La pista del polideportivo, con niños jugando al baloncesto y gradas a '
+ 'un lado.',
en: 'The sports hall court, with children playing basketball and stands along one side.' }),
mercado: t({ es: 'El mercado de los sábados en los soportales de la plaza, con el ayuntamiento '
+ 'al fondo.',
en: 'The Saturday market under the arcades of the square, with the town hall behind.' }),
};
const resources = await Promise.all(Object.entries(ART).map(async ([id, altText]) => {
const fileId = `${id}-900.jpg`;
await loadImage(fileId, asset(fileId));
return { id, typeId: 'foto', kind: 'bitmap', caption: '', altText, createdAt: 0, updatedAt: 0,
bitmap: { fileId, format: 'jpeg', width: 900, height: 600, resolution: 400 } };
}));
Οι έξι υδατογραφίες είναι 900 × 600 px δηλωμένες στα 400 ppi, πλάτους 57 mm, περίπου όσο μια στήλη του πλέγματος, οπότε το πλέγμα δεν τις μεγεθύνει ποτέ. Το εναλλακτικό τους κείμενο βρίσκεται εδώ στο script, επειδή οι εικόνες είναι ίδιες και στις δύο εκδόσεις· μια λεζάντα που θα άλλαζε με τη γλώσσα θα ήταν μια γραμμή ::caption στο Markdown.
#4 · Ένα πράσινο για τις γραμμές και τα πλαίσια
const palette = {
ink: '#1f2b2a', // text
green: '#1d6b57', // the lines of the chart, the areas' boxes, the headings
mayor: '#a8452e', // the box at the head of the chart
tint: '#e6f1ec', // the services' boxes and the galleries' ground
rule: '#b9cbc3', // the hairline round a service
muted: '#5c6b67', // running heads and the colophon
paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
{ id: 'main-color', name: 'green (defaults)', value: { hex: palette.green, model: 'hex' } },
];
Οι γραμμές σύνδεσης, τα πλαίσια των τμημάτων και οι επικεφαλίδες των πεδίων χρησιμοποιούν το green, μια εγγραφή της παλέτας, οπότε μια πόλη με άλλο χρώμα αλλάζει ένα hex. Το πλαίσιο του δημάρχου παίρνει το μόνο θερμό χρώμα του δισέλιδου, το σημείο όπου κοιτάζει πρώτα ο αναγνώστης.
Η πλήρης συνταγή
// ═══ Postext Cookbook · Nº 162 · An org chart and a photo grid built from modules ═══
// https://postext.dev/en/cookbook/org-chart-from-modules
// Code: MIT · Text: original (CC BY 4.0) · Pictures: generated with diffusion models
// Fonts: Public Sans, Source Serif 4 (SIL OFL 1.1) · Needs postext ≥ 1.65.0
import {
buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document ('es' | 'en')
const RECIPE = 'org-chart-from-modules';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: an ink, the town's green for the lines and the areas, a warm mayor's box
const palette = {
ink: '#1f2b2a', // text
green: '#1d6b57', // the lines of the chart, the areas' boxes, the headings
mayor: '#a8452e', // the box at the head of the chart
tint: '#e6f1ec', // the services' boxes and the galleries' ground
rule: '#b9cbc3', // the hairline round a service
muted: '#5c6b67', // running heads and the colophon
paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
{ id: 'main-color', name: 'green (defaults)', value: { hex: palette.green, model: 'hex' } },
];
// #endregion
const SANS = 'Public Sans', SERIF = 'Source Serif 4';
const PAGE = { w: 210, h: 297, top: 22, bottom: 22, inner: 18, outer: 15 }; // mm, mirrored
const W = PAGE.w - PAGE.inner - PAGE.outer; // the type area's width: 177 mm
const SPINE = 12; // mm: the room on the left of the areas where the chart's spine runs down
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const line = (more) => ({ kind: 'connector', color: col('green'), width: pt(1.2), radius: mm(2.5),
...more });
// #region answer: a module per area of the town hall, stacked by the page's modules group
// The page template draws the head of the chart and a group that takes the page's modules;
// the module draws one area: its box, a grid of its services and the lines between them.
const area = {
id: 'area', role: 'module',
frames: [
{ name: 'concejalia', style: 'area', width: mm(84), placement: at('container', 'top-left') },
{ name: 'servicio', style: 'servicio' }, // repeated: one per :::frame{slot="servicio"}
],
groups: [{ name: 'servicios', kind: 'grid', columns: 3, columnGap: mm(4), rowGap: mm(4),
Το συντεθειμένο script.js εκτελείται ως έχει: επικολλήστε το στο module script οποιασδήποτε σελίδας ή ανοίξτε τη συνταγή στο CodePen. Φάκελος της συνταγής στο GitHub ↗ (ανοίγει σε νέα καρτέλα)
Παραλλαγές
#Υπηρεσίες σε δύο στήλες
Με columns: 2, οι υπηρεσίες κάθε τμήματος μπαίνουν δύο σε κάθε σειρά· το δέντρο σχεδιάζει την οριζόντια γραμμή του μόνο πάνω από την πρώτη σειρά, οπότε κρατήστε το για τμήματα με δύο ή τέσσερις υπηρεσίες.
- groups: [{ name: 'servicios', kind: 'grid', columns: 3, columnGap: mm(4), rowGap: mm(4),
+ groups: [{ name: 'servicios', kind: 'grid', columns: 2, columnGap: mm(4), rowGap: mm(4),#Στρογγυλέψτε τις γωνίες της κεντρικής γραμμής
Το radius στρογγυλεύει τις καμπές μιας γωνιακής γραμμής και ενός δέντρου: η βοηθητική συνάρτηση line() δίνει σε κάθε γραμμή σύνδεσης 2,5 mm· με radius: mm(0) το διάγραμμα γίνεται με ορθές γωνίες.
Συνήθη λάθη
- Ένα στοιχείο πλέγματος είναι δικός του φράχτης: οι λέξεις μιας κάρτας φωτογραφίας ανήκουν σε αυτήν μόνο όταν το
:::frame{slot="pie"}τους είναι γραμμένο μέσα στο:::frame{slot="foto"}της κάρτας. - Μια γραμμή σύνδεσης μιας μονάδας που ονομάζει πλαίσιο κειμένου της σελίδας σχεδιάζεται μόνο σε σελίδες που έχουν αυτό το πλαίσιο· σε άλλη σελίδα παραλείπεται, και το αρχείο καταγραφής της αναδιάταξης γράφει
connectorDropped. - Μια ενωμένη καρτέλα κάθεται στην άκρη του πλαισίου και παίρνει το γέμισμά του: δώστε στις λέξεις της ένα σκούρο
color, αφού μια λευκή ετικέτα πάνω σε ανοιχτόχρωμο πλαίσιο δεν διαβάζεται.
Ευχαριστίες
- Συνταγή
- Ignacio Ferro
- Κείμενο
- A guide to the council services of Valdeloma, an invented town, written for this recipe in Spanish and English · Postext Cookbook · CC BY 4.0
- Εικόνες
- The reading room of a town library, in watercolour. · Generated With Diffusion Models · πρωτότυπο
- Children with violins and a piano at a music school, in watercolour. · Generated With Diffusion Models · πρωτότυπο
- Older people playing cards and painting at a day centre, in watercolour. · Generated With Diffusion Models · πρωτότυπο
- A covered pool under a timber roof, in watercolour. · Generated With Diffusion Models · πρωτότυπο
- Children playing basketball in a sports hall, in watercolour. · Generated With Diffusion Models · πρωτότυπο
- A Saturday market under the arcades of a town square, in watercolour. · Generated With Diffusion Models · πρωτότυπο
- Γραμματοσειρές
- Public Sans (SIL OFL 1.1) · Source Serif 4 (SIL OFL 1.1)
- Κώδικας
- MIT, όπως το Postext
Επεξεργασία αυτού του κειμένου ↗ (ανοίγει σε νέα καρτέλα)Φάκελος της συνταγής στο GitHub ↗ (ανοίγει σε νέα καρτέλα)


