@zyro-sec/merman 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/script/layout-audit.ts +98 -98
- package/src/core/canvas.ts +228 -228
- package/src/core/color/style.ts +56 -56
- package/src/core/drawing.ts +301 -301
- package/src/core/geometry.ts +347 -347
- package/src/core/mermaid.ts +38 -38
- package/src/core/render-grid.ts +51 -51
- package/src/core/spatial.ts +243 -243
- package/src/core/text-lines.ts +32 -32
- package/src/core/text.ts +44 -44
- package/src/detect.ts +17 -17
- package/src/diagnostics.ts +16 -16
- package/src/flowchart/drawing.ts +340 -340
- package/src/flowchart/labels.ts +144 -144
- package/src/flowchart/layout.ts +1427 -1427
- package/src/flowchart/options.ts +12 -12
- package/src/flowchart/parser.ts +467 -467
- package/src/flowchart/render.ts +10 -10
- package/src/flowchart/routing.ts +1542 -1542
- package/src/flowchart/style.ts +79 -79
- package/src/flowchart/types.ts +65 -65
- package/src/gantt/diagram.ts +8 -8
- package/src/gantt/drawing.ts +191 -191
- package/src/gantt/parser.ts +161 -161
- package/src/gantt/render-grid.ts +17 -17
- package/src/gantt/style.ts +36 -36
- package/src/gantt/types.ts +44 -44
- package/src/gitgraph/diagram.ts +8 -8
- package/src/gitgraph/drawing.ts +234 -234
- package/src/gitgraph/parser.ts +219 -219
- package/src/gitgraph/render-grid.ts +17 -17
- package/src/gitgraph/style.ts +37 -37
- package/src/gitgraph/types.ts +36 -36
- package/src/markdown.ts +336 -336
- package/src/palette.ts +75 -75
- package/src/plugin.ts +15 -15
- package/src/sequence/diagram.ts +8 -8
- package/src/sequence/drawing.ts +287 -287
- package/src/sequence/options.ts +8 -8
- package/src/sequence/parser.ts +282 -282
- package/src/sequence/placement.ts +684 -684
- package/src/sequence/render-grid.ts +22 -22
- package/src/sequence/style.ts +81 -81
- package/src/sequence/types.ts +74 -74
- package/src/state/diagram.ts +8 -8
- package/src/state/drawing.ts +360 -360
- package/src/state/endpoint.ts +15 -15
- package/src/state/layout.ts +1134 -1134
- package/src/state/note.ts +59 -59
- package/src/state/options.ts +11 -11
- package/src/state/parser.ts +224 -224
- package/src/state/render-grid.ts +22 -22
- package/src/state/routing.ts +1522 -1522
- package/src/state/search.ts +103 -103
- package/src/state/style.ts +52 -52
- package/src/state/types.ts +63 -63
- package/src/state/visible-model.ts +77 -77
- package/src/test/diagram.ts +32 -32
- package/src/test/layout-audit/fixtures.ts +538 -538
- package/src/test/layout-audit/harness.ts +522 -522
- package/src/timeline/diagram.ts +8 -8
- package/src/timeline/drawing.ts +109 -109
- package/src/timeline/parser.ts +119 -119
- package/src/timeline/render-grid.ts +17 -17
- package/src/timeline/style.ts +36 -36
- package/src/timeline/types.ts +31 -31
- package/tsconfig.json +10 -10
- package/src/core/canvas.test.ts +0 -203
- package/src/core/color/style.test.ts +0 -24
- package/src/core/drawing.test.ts +0 -116
- package/src/core/geometry.test.ts +0 -112
- package/src/core/spatial.test.ts +0 -87
- package/src/core/text.test.ts +0 -33
- package/src/flowchart/flowchart.test.ts +0 -2800
- package/src/flowchart/labels.test.ts +0 -127
- package/src/flowchart/routing.test.ts +0 -368
- package/src/gantt/diagram.test.ts +0 -124
- package/src/gitgraph/diagram.test.ts +0 -183
- package/src/layout-audit.test.ts +0 -92
- package/src/palette.test.ts +0 -103
- package/src/sequence/diagram.test.ts +0 -757
- package/src/sequence/placement.test.ts +0 -219
- package/src/state/diagram.test.ts +0 -1386
- package/src/state/layout.test.ts +0 -314
- package/src/state/routing.test.ts +0 -693
- package/src/state/style.test.ts +0 -113
- package/src/state/visible-model.test.ts +0 -84
- package/src/test/diagnostics.test.ts +0 -129
- package/src/test/markdown.test.ts +0 -474
- package/src/timeline/diagram.test.ts +0 -188
package/src/gantt/drawing.ts
CHANGED
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
import { DiagramCanvas } from "../core/canvas.js"
|
|
2
|
-
import { diagramTextWidth } from "../core/text.js"
|
|
3
|
-
import type { GanttGrid } from "./render-grid.js"
|
|
4
|
-
import type {
|
|
5
|
-
GanttDiagram,
|
|
6
|
-
GanttDiagramRenderOptions,
|
|
7
|
-
GanttLabelLayout,
|
|
8
|
-
GanttLineStyle,
|
|
9
|
-
GanttRenderStyle,
|
|
10
|
-
GanttTask,
|
|
11
|
-
} from "./types.js"
|
|
12
|
-
|
|
13
|
-
const LABEL_GAP = 2
|
|
14
|
-
const MIN_CHART_WIDTH = 24
|
|
15
|
-
const MAX_CHART_WIDTH = 64
|
|
16
|
-
|
|
17
|
-
export function drawGanttDiagramGrid(diagram: GanttDiagram, options: GanttDiagramRenderOptions = {}): GanttGrid {
|
|
18
|
-
if (diagram.entries.length === 0) return new DiagramCanvas(0, 0)
|
|
19
|
-
const labels = diagram.entries.map((_, index) => entryLabel(diagram, index, options.labels ?? "left"))
|
|
20
|
-
const labelWidth = Math.max(...labels.map(diagramTextWidth))
|
|
21
|
-
const entryRows: number[] = []
|
|
22
|
-
let bodyHeight = 0
|
|
23
|
-
diagram.entries.forEach((entry, index) => {
|
|
24
|
-
if ((options.sections ?? "spaced") === "spaced" && entry.type === "section" && index > 0) bodyHeight += 1
|
|
25
|
-
entryRows.push(bodyHeight)
|
|
26
|
-
bodyHeight += 1
|
|
27
|
-
})
|
|
28
|
-
if (diagram.tasks.length === 0) {
|
|
29
|
-
const grid: GanttGrid = new DiagramCanvas(labelWidth, bodyHeight)
|
|
30
|
-
diagram.entries.forEach((entry, index) => {
|
|
31
|
-
if (entry.type === "section") grid.setText(0, entryRows[index]!, entry.section.label, "section")
|
|
32
|
-
})
|
|
33
|
-
return grid
|
|
34
|
-
}
|
|
35
|
-
const available = (options.layoutMaxWidth ?? 120) - labelWidth - LABEL_GAP
|
|
36
|
-
const chartWidth = Math.max(MIN_CHART_WIDTH, Math.min(MAX_CHART_WIDTH, available))
|
|
37
|
-
const starts = diagram.tasks.map((task) => task.start)
|
|
38
|
-
const ends = diagram.tasks.map((task) => task.end)
|
|
39
|
-
const minimum = Math.min(...starts)
|
|
40
|
-
const maximum = Math.max(...ends)
|
|
41
|
-
const span = Math.max(1, maximum - minimum)
|
|
42
|
-
const titleHeight = diagram.title ? 2 : 0
|
|
43
|
-
const axisHeight = 2
|
|
44
|
-
const grid: GanttGrid = new DiagramCanvas(labelWidth + LABEL_GAP + chartWidth, titleHeight + axisHeight + bodyHeight)
|
|
45
|
-
const chartX = labelWidth + LABEL_GAP
|
|
46
|
-
|
|
47
|
-
if (diagram.title)
|
|
48
|
-
grid.setText(
|
|
49
|
-
Math.max(0, chartX + Math.floor((chartWidth - diagramTextWidth(diagram.title)) / 2)),
|
|
50
|
-
0,
|
|
51
|
-
diagram.title,
|
|
52
|
-
"title",
|
|
53
|
-
)
|
|
54
|
-
drawAxis(grid, chartX, titleHeight, chartWidth, minimum, span, diagram.axisFormat)
|
|
55
|
-
|
|
56
|
-
diagram.entries.forEach((entry, index) => {
|
|
57
|
-
const y = titleHeight + axisHeight + entryRows[index]!
|
|
58
|
-
if (entry.type === "section") {
|
|
59
|
-
grid.setText(0, y, labels[index]!, "section")
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
const label = labels[index]!
|
|
63
|
-
const labelX = options.labels === "right" ? labelWidth - diagramTextWidth(label) : 0
|
|
64
|
-
grid.setText(labelX, y, label, entry.task.state)
|
|
65
|
-
drawTask(grid, entry.task, chartX, y, chartWidth, minimum, span, options)
|
|
66
|
-
})
|
|
67
|
-
return grid
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function drawAxis(
|
|
71
|
-
grid: GanttGrid,
|
|
72
|
-
x: number,
|
|
73
|
-
y: number,
|
|
74
|
-
width: number,
|
|
75
|
-
minimum: number,
|
|
76
|
-
span: number,
|
|
77
|
-
format: string,
|
|
78
|
-
): void {
|
|
79
|
-
for (let offset = 0; offset < width; offset++) grid.setCell(x + offset, y + 1, "─", "axis")
|
|
80
|
-
const step = tickStep(span)
|
|
81
|
-
const ticks: number[] = []
|
|
82
|
-
for (let value = Math.ceil(minimum / step) * step; value <= minimum + span; value += step) ticks.push(value)
|
|
83
|
-
if (ticks.length === 0) ticks.push(minimum, minimum + span)
|
|
84
|
-
for (const value of ticks) {
|
|
85
|
-
const offset = Math.round(((value - minimum) / span) * (width - 1))
|
|
86
|
-
const label = formatTime(value, format)
|
|
87
|
-
const labelX = Math.max(
|
|
88
|
-
x,
|
|
89
|
-
Math.min(x + width - diagramTextWidth(label), x + offset - Math.floor(diagramTextWidth(label) / 2)),
|
|
90
|
-
)
|
|
91
|
-
grid.setText(labelX, y, label, "axis")
|
|
92
|
-
grid.setCell(x + offset, y + 1, "┬", "axis")
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function tickStep(span: number): number {
|
|
97
|
-
const steps = [
|
|
98
|
-
1_000, 5_000, 10_000, 30_000, 60_000, 300_000, 900_000, 3_600_000, 21_600_000, 43_200_000, 86_400_000, 172_800_000,
|
|
99
|
-
604_800_000, 2_592_000_000, 31_536_000_000,
|
|
100
|
-
]
|
|
101
|
-
return steps.find((step) => step >= span / 4) ?? steps.at(-1)!
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function drawTask(
|
|
105
|
-
grid: GanttGrid,
|
|
106
|
-
task: GanttTask,
|
|
107
|
-
x: number,
|
|
108
|
-
y: number,
|
|
109
|
-
width: number,
|
|
110
|
-
minimum: number,
|
|
111
|
-
span: number,
|
|
112
|
-
options: GanttDiagramRenderOptions,
|
|
113
|
-
): void {
|
|
114
|
-
const style: GanttRenderStyle = options.style ?? "track"
|
|
115
|
-
const line = lineGlyph(options.line ?? "thin")
|
|
116
|
-
const start = Math.round(((task.start - minimum) / span) * (width - 1))
|
|
117
|
-
const end = Math.round(((task.end - minimum) / span) * (width - 1))
|
|
118
|
-
if (task.state === "milestone" || start === end) {
|
|
119
|
-
grid.setCell(x + start, y, "◆", task.state)
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
if (style === "track") {
|
|
123
|
-
for (let offset = 0; offset < width; offset++) {
|
|
124
|
-
grid.setCell(x + offset, y, (options.track ?? "line") === "line" ? line : "·", trackCellStyle(options))
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
const glyph = style === "block" ? "█" : line
|
|
128
|
-
for (let offset = start; offset <= end; offset++) grid.setCell(x + offset, y, glyph, task.state)
|
|
129
|
-
if (style === "block") return
|
|
130
|
-
if (style === "capsule" || style === "track") {
|
|
131
|
-
if (style === "track") {
|
|
132
|
-
if (options.endpoints === "points") {
|
|
133
|
-
grid.setCell(x + start, y, "●", trackCellStyle(options))
|
|
134
|
-
grid.setCell(x + end, y, "●", trackCellStyle(options))
|
|
135
|
-
}
|
|
136
|
-
return
|
|
137
|
-
}
|
|
138
|
-
const caps = capGlyphs(options.line ?? "thin")
|
|
139
|
-
grid.setCell(x + start, y, caps.start, task.state)
|
|
140
|
-
grid.setCell(x + end, y, caps.end, task.state)
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
if (style === "points") {
|
|
144
|
-
grid.setCell(x + start, y, "●", task.state)
|
|
145
|
-
grid.setCell(x + end, y, "●", task.state)
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
grid.setCell(x + start, y, "┣", task.state)
|
|
149
|
-
grid.setCell(x + end, y, "┫", task.state)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function entryLabel(diagram: GanttDiagram, index: number, layout: GanttLabelLayout): string {
|
|
153
|
-
const entry = diagram.entries[index]!
|
|
154
|
-
if (entry.type === "section" || layout !== "tree") {
|
|
155
|
-
return entry.type === "section" ? entry.section.label : entry.task.label
|
|
156
|
-
}
|
|
157
|
-
const last = diagram.entries[index + 1]?.type !== "task"
|
|
158
|
-
return ` ${last ? "└" : "├"}─ ${entry.task.label}`
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function lineGlyph(line: GanttLineStyle): string {
|
|
162
|
-
if (line === "thin") return "─"
|
|
163
|
-
if (line === "double") return "═"
|
|
164
|
-
if (line === "dashed") return "╌"
|
|
165
|
-
return "━"
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function capGlyphs(line: GanttLineStyle): { start: string; end: string } {
|
|
169
|
-
if (line === "thin" || line === "dashed") return { start: "╶", end: "╴" }
|
|
170
|
-
if (line === "double") return { start: "╞", end: "╡" }
|
|
171
|
-
return { start: "╺", end: "╸" }
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function trackCellStyle(options: GanttDiagramRenderOptions): "trackMedium" | "trackDim" | "trackFaint" {
|
|
175
|
-
if (options.trackTone === "medium") return "trackMedium"
|
|
176
|
-
if (options.trackTone === "dim") return "trackDim"
|
|
177
|
-
return "trackFaint"
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function formatTime(value: number, format: string): string {
|
|
181
|
-
const date = new Date(value)
|
|
182
|
-
const parts: Record<string, string> = {
|
|
183
|
-
"%Y": String(date.getUTCFullYear()),
|
|
184
|
-
"%m": String(date.getUTCMonth() + 1).padStart(2, "0"),
|
|
185
|
-
"%d": String(date.getUTCDate()).padStart(2, "0"),
|
|
186
|
-
"%H": String(date.getUTCHours()).padStart(2, "0"),
|
|
187
|
-
"%M": String(date.getUTCMinutes()).padStart(2, "0"),
|
|
188
|
-
"%S": String(date.getUTCSeconds()).padStart(2, "0"),
|
|
189
|
-
}
|
|
190
|
-
return Object.entries(parts).reduce((result, [token, replacement]) => result.replaceAll(token, replacement), format)
|
|
191
|
-
}
|
|
1
|
+
import { DiagramCanvas } from "../core/canvas.js"
|
|
2
|
+
import { diagramTextWidth } from "../core/text.js"
|
|
3
|
+
import type { GanttGrid } from "./render-grid.js"
|
|
4
|
+
import type {
|
|
5
|
+
GanttDiagram,
|
|
6
|
+
GanttDiagramRenderOptions,
|
|
7
|
+
GanttLabelLayout,
|
|
8
|
+
GanttLineStyle,
|
|
9
|
+
GanttRenderStyle,
|
|
10
|
+
GanttTask,
|
|
11
|
+
} from "./types.js"
|
|
12
|
+
|
|
13
|
+
const LABEL_GAP = 2
|
|
14
|
+
const MIN_CHART_WIDTH = 24
|
|
15
|
+
const MAX_CHART_WIDTH = 64
|
|
16
|
+
|
|
17
|
+
export function drawGanttDiagramGrid(diagram: GanttDiagram, options: GanttDiagramRenderOptions = {}): GanttGrid {
|
|
18
|
+
if (diagram.entries.length === 0) return new DiagramCanvas(0, 0)
|
|
19
|
+
const labels = diagram.entries.map((_, index) => entryLabel(diagram, index, options.labels ?? "left"))
|
|
20
|
+
const labelWidth = Math.max(...labels.map(diagramTextWidth))
|
|
21
|
+
const entryRows: number[] = []
|
|
22
|
+
let bodyHeight = 0
|
|
23
|
+
diagram.entries.forEach((entry, index) => {
|
|
24
|
+
if ((options.sections ?? "spaced") === "spaced" && entry.type === "section" && index > 0) bodyHeight += 1
|
|
25
|
+
entryRows.push(bodyHeight)
|
|
26
|
+
bodyHeight += 1
|
|
27
|
+
})
|
|
28
|
+
if (diagram.tasks.length === 0) {
|
|
29
|
+
const grid: GanttGrid = new DiagramCanvas(labelWidth, bodyHeight)
|
|
30
|
+
diagram.entries.forEach((entry, index) => {
|
|
31
|
+
if (entry.type === "section") grid.setText(0, entryRows[index]!, entry.section.label, "section")
|
|
32
|
+
})
|
|
33
|
+
return grid
|
|
34
|
+
}
|
|
35
|
+
const available = (options.layoutMaxWidth ?? 120) - labelWidth - LABEL_GAP
|
|
36
|
+
const chartWidth = Math.max(MIN_CHART_WIDTH, Math.min(MAX_CHART_WIDTH, available))
|
|
37
|
+
const starts = diagram.tasks.map((task) => task.start)
|
|
38
|
+
const ends = diagram.tasks.map((task) => task.end)
|
|
39
|
+
const minimum = Math.min(...starts)
|
|
40
|
+
const maximum = Math.max(...ends)
|
|
41
|
+
const span = Math.max(1, maximum - minimum)
|
|
42
|
+
const titleHeight = diagram.title ? 2 : 0
|
|
43
|
+
const axisHeight = 2
|
|
44
|
+
const grid: GanttGrid = new DiagramCanvas(labelWidth + LABEL_GAP + chartWidth, titleHeight + axisHeight + bodyHeight)
|
|
45
|
+
const chartX = labelWidth + LABEL_GAP
|
|
46
|
+
|
|
47
|
+
if (diagram.title)
|
|
48
|
+
grid.setText(
|
|
49
|
+
Math.max(0, chartX + Math.floor((chartWidth - diagramTextWidth(diagram.title)) / 2)),
|
|
50
|
+
0,
|
|
51
|
+
diagram.title,
|
|
52
|
+
"title",
|
|
53
|
+
)
|
|
54
|
+
drawAxis(grid, chartX, titleHeight, chartWidth, minimum, span, diagram.axisFormat)
|
|
55
|
+
|
|
56
|
+
diagram.entries.forEach((entry, index) => {
|
|
57
|
+
const y = titleHeight + axisHeight + entryRows[index]!
|
|
58
|
+
if (entry.type === "section") {
|
|
59
|
+
grid.setText(0, y, labels[index]!, "section")
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
const label = labels[index]!
|
|
63
|
+
const labelX = options.labels === "right" ? labelWidth - diagramTextWidth(label) : 0
|
|
64
|
+
grid.setText(labelX, y, label, entry.task.state)
|
|
65
|
+
drawTask(grid, entry.task, chartX, y, chartWidth, minimum, span, options)
|
|
66
|
+
})
|
|
67
|
+
return grid
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function drawAxis(
|
|
71
|
+
grid: GanttGrid,
|
|
72
|
+
x: number,
|
|
73
|
+
y: number,
|
|
74
|
+
width: number,
|
|
75
|
+
minimum: number,
|
|
76
|
+
span: number,
|
|
77
|
+
format: string,
|
|
78
|
+
): void {
|
|
79
|
+
for (let offset = 0; offset < width; offset++) grid.setCell(x + offset, y + 1, "─", "axis")
|
|
80
|
+
const step = tickStep(span)
|
|
81
|
+
const ticks: number[] = []
|
|
82
|
+
for (let value = Math.ceil(minimum / step) * step; value <= minimum + span; value += step) ticks.push(value)
|
|
83
|
+
if (ticks.length === 0) ticks.push(minimum, minimum + span)
|
|
84
|
+
for (const value of ticks) {
|
|
85
|
+
const offset = Math.round(((value - minimum) / span) * (width - 1))
|
|
86
|
+
const label = formatTime(value, format)
|
|
87
|
+
const labelX = Math.max(
|
|
88
|
+
x,
|
|
89
|
+
Math.min(x + width - diagramTextWidth(label), x + offset - Math.floor(diagramTextWidth(label) / 2)),
|
|
90
|
+
)
|
|
91
|
+
grid.setText(labelX, y, label, "axis")
|
|
92
|
+
grid.setCell(x + offset, y + 1, "┬", "axis")
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function tickStep(span: number): number {
|
|
97
|
+
const steps = [
|
|
98
|
+
1_000, 5_000, 10_000, 30_000, 60_000, 300_000, 900_000, 3_600_000, 21_600_000, 43_200_000, 86_400_000, 172_800_000,
|
|
99
|
+
604_800_000, 2_592_000_000, 31_536_000_000,
|
|
100
|
+
]
|
|
101
|
+
return steps.find((step) => step >= span / 4) ?? steps.at(-1)!
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function drawTask(
|
|
105
|
+
grid: GanttGrid,
|
|
106
|
+
task: GanttTask,
|
|
107
|
+
x: number,
|
|
108
|
+
y: number,
|
|
109
|
+
width: number,
|
|
110
|
+
minimum: number,
|
|
111
|
+
span: number,
|
|
112
|
+
options: GanttDiagramRenderOptions,
|
|
113
|
+
): void {
|
|
114
|
+
const style: GanttRenderStyle = options.style ?? "track"
|
|
115
|
+
const line = lineGlyph(options.line ?? "thin")
|
|
116
|
+
const start = Math.round(((task.start - minimum) / span) * (width - 1))
|
|
117
|
+
const end = Math.round(((task.end - minimum) / span) * (width - 1))
|
|
118
|
+
if (task.state === "milestone" || start === end) {
|
|
119
|
+
grid.setCell(x + start, y, "◆", task.state)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
if (style === "track") {
|
|
123
|
+
for (let offset = 0; offset < width; offset++) {
|
|
124
|
+
grid.setCell(x + offset, y, (options.track ?? "line") === "line" ? line : "·", trackCellStyle(options))
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const glyph = style === "block" ? "█" : line
|
|
128
|
+
for (let offset = start; offset <= end; offset++) grid.setCell(x + offset, y, glyph, task.state)
|
|
129
|
+
if (style === "block") return
|
|
130
|
+
if (style === "capsule" || style === "track") {
|
|
131
|
+
if (style === "track") {
|
|
132
|
+
if (options.endpoints === "points") {
|
|
133
|
+
grid.setCell(x + start, y, "●", trackCellStyle(options))
|
|
134
|
+
grid.setCell(x + end, y, "●", trackCellStyle(options))
|
|
135
|
+
}
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
const caps = capGlyphs(options.line ?? "thin")
|
|
139
|
+
grid.setCell(x + start, y, caps.start, task.state)
|
|
140
|
+
grid.setCell(x + end, y, caps.end, task.state)
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
if (style === "points") {
|
|
144
|
+
grid.setCell(x + start, y, "●", task.state)
|
|
145
|
+
grid.setCell(x + end, y, "●", task.state)
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
grid.setCell(x + start, y, "┣", task.state)
|
|
149
|
+
grid.setCell(x + end, y, "┫", task.state)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function entryLabel(diagram: GanttDiagram, index: number, layout: GanttLabelLayout): string {
|
|
153
|
+
const entry = diagram.entries[index]!
|
|
154
|
+
if (entry.type === "section" || layout !== "tree") {
|
|
155
|
+
return entry.type === "section" ? entry.section.label : entry.task.label
|
|
156
|
+
}
|
|
157
|
+
const last = diagram.entries[index + 1]?.type !== "task"
|
|
158
|
+
return ` ${last ? "└" : "├"}─ ${entry.task.label}`
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function lineGlyph(line: GanttLineStyle): string {
|
|
162
|
+
if (line === "thin") return "─"
|
|
163
|
+
if (line === "double") return "═"
|
|
164
|
+
if (line === "dashed") return "╌"
|
|
165
|
+
return "━"
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function capGlyphs(line: GanttLineStyle): { start: string; end: string } {
|
|
169
|
+
if (line === "thin" || line === "dashed") return { start: "╶", end: "╴" }
|
|
170
|
+
if (line === "double") return { start: "╞", end: "╡" }
|
|
171
|
+
return { start: "╺", end: "╸" }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function trackCellStyle(options: GanttDiagramRenderOptions): "trackMedium" | "trackDim" | "trackFaint" {
|
|
175
|
+
if (options.trackTone === "medium") return "trackMedium"
|
|
176
|
+
if (options.trackTone === "dim") return "trackDim"
|
|
177
|
+
return "trackFaint"
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function formatTime(value: number, format: string): string {
|
|
181
|
+
const date = new Date(value)
|
|
182
|
+
const parts: Record<string, string> = {
|
|
183
|
+
"%Y": String(date.getUTCFullYear()),
|
|
184
|
+
"%m": String(date.getUTCMonth() + 1).padStart(2, "0"),
|
|
185
|
+
"%d": String(date.getUTCDate()).padStart(2, "0"),
|
|
186
|
+
"%H": String(date.getUTCHours()).padStart(2, "0"),
|
|
187
|
+
"%M": String(date.getUTCMinutes()).padStart(2, "0"),
|
|
188
|
+
"%S": String(date.getUTCSeconds()).padStart(2, "0"),
|
|
189
|
+
}
|
|
190
|
+
return Object.entries(parts).reduce((result, [token, replacement]) => result.replaceAll(token, replacement), format)
|
|
191
|
+
}
|