@fengwk/kchart 0.0.0-stage → 0.1.1
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/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/NOTICE.md +11 -0
- package/README.md +68 -2
- package/README.zh-CN.md +69 -0
- package/dist/LICENSE +21 -0
- package/dist/NOTICE.md +11 -0
- package/dist/assets/ICONS-LICENSE.txt +53 -0
- package/dist/assets/maps/LICENSE.md +75 -0
- package/dist/assets/maps/METADATA.md +9 -0
- package/dist/assets/maps/REGIONS.md +28 -0
- package/dist/assets/maps/us-states.geojson +1 -0
- package/dist/assets/maps/world.geojson +1 -0
- package/dist/esm/_virtual/_kchart-families.js +48 -0
- package/dist/esm/_virtual/_rolldown/runtime.js +12 -0
- package/dist/esm/assets/icons.js +11 -0
- package/dist/esm/assets/maps/us-states.js +3 -0
- package/dist/esm/assets/maps/world.js +3 -0
- package/dist/esm/assets/themes/claude.js +69 -0
- package/dist/esm/assets/themes/cloudmusic.js +62 -0
- package/dist/esm/assets/themes/kanagawa.js +67 -0
- package/dist/esm/assets/themes/obsidian.js +67 -0
- package/dist/esm/assets/themes/paper.js +61 -0
- package/dist/esm/assets/themes/terminal.js +60 -0
- package/dist/esm/assets/themes/tokyo.js +62 -0
- package/dist/esm/chart/basic.js +1313 -0
- package/dist/esm/chart/catalog.js +476 -0
- package/dist/esm/chart/composition.js +844 -0
- package/dist/esm/chart/context.js +189 -0
- package/dist/esm/chart/distribution.js +442 -0
- package/dist/esm/chart/fields.js +67 -0
- package/dist/esm/chart/maps.js +563 -0
- package/dist/esm/chart/mindmap.js +629 -0
- package/dist/esm/chart/multivariate.js +1229 -0
- package/dist/esm/chart/registry.js +108 -0
- package/dist/esm/chart/relations.js +949 -0
- package/dist/esm/chart/spec.js +1415 -0
- package/dist/esm/chart/stat-compare.js +302 -0
- package/dist/esm/chart/stat-trend.js +181 -0
- package/dist/esm/chart/statistics.js +1007 -0
- package/dist/esm/chart/unit-variants.js +645 -0
- package/dist/esm/chart/variants.js +552 -0
- package/dist/esm/core/color.js +197 -0
- package/dist/esm/core/context.js +256 -0
- package/dist/esm/core/diagnostics.js +23 -0
- package/dist/esm/core/format.js +167 -0
- package/dist/esm/core/geometry.js +130 -0
- package/dist/esm/core/icon-data.js +5 -0
- package/dist/esm/core/icons.js +173 -0
- package/dist/esm/core/scale.js +112 -0
- package/dist/esm/core/scene.js +234 -0
- package/dist/esm/core/svg.js +89 -0
- package/dist/esm/core/text.js +184 -0
- package/dist/esm/core/theme.js +318 -0
- package/dist/esm/diagram/agentflow.js +596 -0
- package/dist/esm/diagram/architecture.js +729 -0
- package/dist/esm/diagram/block.js +988 -0
- package/dist/esm/diagram/blocks.js +687 -0
- package/dist/esm/diagram/c4.js +1002 -0
- package/dist/esm/diagram/class.js +1158 -0
- package/dist/esm/diagram/cynefin.js +749 -0
- package/dist/esm/diagram/emphasis.js +7 -0
- package/dist/esm/diagram/er.js +657 -0
- package/dist/esm/diagram/eventmodeling.js +948 -0
- package/dist/esm/diagram/gantt-date.js +323 -0
- package/dist/esm/diagram/gantt.js +661 -0
- package/dist/esm/diagram/gitgraph.js +472 -0
- package/dist/esm/diagram/graph-layout.js +4046 -0
- package/dist/esm/diagram/graph-parse.js +1366 -0
- package/dist/esm/diagram/graph-route.js +490 -0
- package/dist/esm/diagram/graph.js +553 -0
- package/dist/esm/diagram/ishikawa.js +496 -0
- package/dist/esm/diagram/journey.js +512 -0
- package/dist/esm/diagram/kanban.js +280 -0
- package/dist/esm/diagram/label.js +56 -0
- package/dist/esm/diagram/layers.js +385 -0
- package/dist/esm/diagram/map-label.js +44 -0
- package/dist/esm/diagram/mindmap.js +277 -0
- package/dist/esm/diagram/numeric-composition.js +78 -0
- package/dist/esm/diagram/numeric-model.js +86 -0
- package/dist/esm/diagram/numeric-parse.js +205 -0
- package/dist/esm/diagram/numeric-radar.js +355 -0
- package/dist/esm/diagram/numeric-sankey.js +201 -0
- package/dist/esm/diagram/numeric-xy.js +422 -0
- package/dist/esm/diagram/packet.js +175 -0
- package/dist/esm/diagram/presentation.js +252 -0
- package/dist/esm/diagram/quadrant.js +297 -0
- package/dist/esm/diagram/railroad-parse.js +465 -0
- package/dist/esm/diagram/railroad.js +294 -0
- package/dist/esm/diagram/registry.js +296 -0
- package/dist/esm/diagram/relations.js +966 -0
- package/dist/esm/diagram/requirement.js +341 -0
- package/dist/esm/diagram/sequence.js +1228 -0
- package/dist/esm/diagram/shapes.js +366 -0
- package/dist/esm/diagram/source.js +538 -0
- package/dist/esm/diagram/support.js +153 -0
- package/dist/esm/diagram/swimlane-mermaid.js +140 -0
- package/dist/esm/diagram/swimlane.js +1186 -0
- package/dist/esm/diagram/time.js +748 -0
- package/dist/esm/diagram/timeline.js +376 -0
- package/dist/esm/diagram/tree-family-icon.js +22 -0
- package/dist/esm/diagram/treeview.js +293 -0
- package/dist/esm/diagram/usecase.js +852 -0
- package/dist/esm/diagram/venn.js +1038 -0
- package/dist/esm/diagram/wardley.js +838 -0
- package/dist/esm/index.d.ts +133 -0
- package/dist/esm/index.js +92 -0
- package/dist/esm/interaction.js +561 -0
- package/dist/esm/mermaid.d.ts +28 -0
- package/dist/esm/mermaid.js +70 -0
- package/dist/esm/node.d.ts +68 -0
- package/dist/esm/node.js +373 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/page-api.js +65 -0
- package/dist/esm/runtime.js +352 -0
- package/dist/esm/src/families.js +209 -0
- package/dist/page-api.js +1 -0
- package/dist/units/chart/basic.js +1 -0
- package/dist/units/chart/catalog.js +1 -0
- package/dist/units/chart/composition.js +1 -0
- package/dist/units/chart/context.js +1 -0
- package/dist/units/chart/distribution.js +1 -0
- package/dist/units/chart/fields.js +1 -0
- package/dist/units/chart/maps.js +1 -0
- package/dist/units/chart/mindmap.js +1 -0
- package/dist/units/chart/multivariate.js +1 -0
- package/dist/units/chart/registry.js +1 -0
- package/dist/units/chart/relations.js +1 -0
- package/dist/units/chart/spec.js +3 -0
- package/dist/units/chart/stat-compare.js +1 -0
- package/dist/units/chart/stat-trend.js +1 -0
- package/dist/units/chart/statistics.js +1 -0
- package/dist/units/chart/unit-variants.js +1 -0
- package/dist/units/chart/variants.js +1 -0
- package/dist/units/core/color.js +1 -0
- package/dist/units/core/context.js +1 -0
- package/dist/units/core/diagnostics.js +1 -0
- package/dist/units/core/format.js +1 -0
- package/dist/units/core/geometry.js +1 -0
- package/dist/units/core/icon-data.js +1 -0
- package/dist/units/core/icons.js +1 -0
- package/dist/units/core/scale.js +1 -0
- package/dist/units/core/scene.js +1 -0
- package/dist/units/core/svg.js +1 -0
- package/dist/units/core/text.js +2 -0
- package/dist/units/core/theme.js +1 -0
- package/dist/units/diagram/agentflow.js +12 -0
- package/dist/units/diagram/architecture.js +4 -0
- package/dist/units/diagram/block.js +2 -0
- package/dist/units/diagram/blocks.js +2 -0
- package/dist/units/diagram/c4.js +6 -0
- package/dist/units/diagram/class.js +5 -0
- package/dist/units/diagram/cynefin.js +4 -0
- package/dist/units/diagram/emphasis.js +1 -0
- package/dist/units/diagram/er.js +9 -0
- package/dist/units/diagram/eventmodeling.js +5 -0
- package/dist/units/diagram/gantt-date.js +1 -0
- package/dist/units/diagram/gantt.js +3 -0
- package/dist/units/diagram/gitgraph.js +2 -0
- package/dist/units/diagram/graph-layout.js +4 -0
- package/dist/units/diagram/graph-parse.js +9 -0
- package/dist/units/diagram/graph-route.js +1 -0
- package/dist/units/diagram/graph.js +1 -0
- package/dist/units/diagram/ishikawa.js +2 -0
- package/dist/units/diagram/journey.js +5 -0
- package/dist/units/diagram/kanban.js +2 -0
- package/dist/units/diagram/label.js +4 -0
- package/dist/units/diagram/layers.js +1 -0
- package/dist/units/diagram/map-label.js +1 -0
- package/dist/units/diagram/mindmap.js +2 -0
- package/dist/units/diagram/numeric-composition.js +1 -0
- package/dist/units/diagram/numeric-model.js +1 -0
- package/dist/units/diagram/numeric-parse.js +2 -0
- package/dist/units/diagram/numeric-radar.js +3 -0
- package/dist/units/diagram/numeric-sankey.js +2 -0
- package/dist/units/diagram/numeric-xy.js +2 -0
- package/dist/units/diagram/packet.js +2 -0
- package/dist/units/diagram/presentation.js +2 -0
- package/dist/units/diagram/quadrant.js +2 -0
- package/dist/units/diagram/railroad-parse.js +4 -0
- package/dist/units/diagram/railroad.js +1 -0
- package/dist/units/diagram/registry.js +2 -0
- package/dist/units/diagram/relations.js +3 -0
- package/dist/units/diagram/requirement.js +3 -0
- package/dist/units/diagram/sequence.js +2 -0
- package/dist/units/diagram/shapes.js +60 -0
- package/dist/units/diagram/source.js +20 -0
- package/dist/units/diagram/support.js +3 -0
- package/dist/units/diagram/swimlane-mermaid.js +3 -0
- package/dist/units/diagram/swimlane.js +2 -0
- package/dist/units/diagram/time.js +3 -0
- package/dist/units/diagram/timeline.js +2 -0
- package/dist/units/diagram/tree-family-icon.js +1 -0
- package/dist/units/diagram/treeview.js +2 -0
- package/dist/units/diagram/usecase.js +3 -0
- package/dist/units/diagram/venn.js +2 -0
- package/dist/units/diagram/wardley.js +4 -0
- package/dist/units/interaction.js +1 -0
- package/dist/units/runtime.js +1 -0
- package/dist/units.json +712 -0
- package/package.json +30 -4
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { resolveIconRef } from "../core/icons.js";
|
|
3
|
+
import { normalizeLabel } from "./label.js";
|
|
4
|
+
import { presentation } from "./presentation.js";
|
|
5
|
+
import { FONT, blocking, error, isEn, maxWidthOf, warning, wrapText } from "./support.js";
|
|
6
|
+
import { DAY, add, axisTokens, compileAxis, compileDate, dateTokens, durationPattern, excludedBy, intervalPattern, shiftEnd, ticks, weekdays } from "./gantt-date.js";
|
|
7
|
+
// src/diagram/gantt.js
|
|
8
|
+
var gantt_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
9
|
+
var flags = {
|
|
10
|
+
done: ["已完成", "done"],
|
|
11
|
+
active: ["进行中", "in progress"],
|
|
12
|
+
crit: ["关键", "critical"],
|
|
13
|
+
milestone: ["里程碑", "milestone"],
|
|
14
|
+
vert: ["竖线", "vertical marker"]
|
|
15
|
+
};
|
|
16
|
+
var dependency = /^(after|until)\s+(.+)$/i;
|
|
17
|
+
var iconPack = /(?<![\w:/.-])(?:fa[bsrlk]?|logos|mdi|tabler|simple-icons):[a-z\d-]+/gi;
|
|
18
|
+
var separator = /:::[\w-]+|::icon\([^)]+\)|(?<![\w:/.-])(?:fa[bsrlk]?|logos|mdi|tabler|simple-icons):[a-z\d-]+|(:)/gi;
|
|
19
|
+
var iconSlot = (icon) => icon ? 20 : 0;
|
|
20
|
+
var iso = compileDate("YYYY-MM-DD");
|
|
21
|
+
var timeLimit = 864e13;
|
|
22
|
+
var valid = (stamp) => Number.isFinite(stamp) && Math.abs(stamp) <= timeLimit;
|
|
23
|
+
function parse(body, info) {
|
|
24
|
+
const { lang, firstLine = 2 } = info, errors = [], items = [], sections = [{
|
|
25
|
+
name: "",
|
|
26
|
+
items: []
|
|
27
|
+
}];
|
|
28
|
+
const config = info.config?.gantt || {}, configLines = info.configLines || {};
|
|
29
|
+
const look = presentation({ lang }), assets = /* @__PURE__ */ new Set();
|
|
30
|
+
const asset = (diagnostic) => {
|
|
31
|
+
if (!assets.has(diagnostic.message)) {
|
|
32
|
+
assets.add(diagnostic.message);
|
|
33
|
+
errors.push(diagnostic);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const label = (raw, line) => {
|
|
37
|
+
let icon = null;
|
|
38
|
+
const resolve = (ref) => {
|
|
39
|
+
const resolved = resolveIconRef(ref);
|
|
40
|
+
if (!resolved) asset(warning("IGNORED_ASSET", lang, line, `未知图标 ${ref}`, `Unknown icon ${ref}`));
|
|
41
|
+
icon ??= resolved;
|
|
42
|
+
return "";
|
|
43
|
+
};
|
|
44
|
+
const source = String(raw ?? "").replace(/::icon\(([^)]+)\)/gi, (_, ref) => resolve(ref.trim())).replace(iconPack, (ref) => /^fa[bsrlk]?:/i.test(ref) ? ref : resolve(ref));
|
|
45
|
+
const result = normalizeLabel(source, {
|
|
46
|
+
lang,
|
|
47
|
+
line
|
|
48
|
+
});
|
|
49
|
+
result.diagnostics.forEach(asset);
|
|
50
|
+
return {
|
|
51
|
+
name: result.text,
|
|
52
|
+
icon: result.icon || icon
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
let title = {
|
|
56
|
+
raw: info.title,
|
|
57
|
+
line: info.configLines?.title ?? info.headerLine ?? firstLine
|
|
58
|
+
};
|
|
59
|
+
const model = {
|
|
60
|
+
type: "gantt",
|
|
61
|
+
title: "",
|
|
62
|
+
items,
|
|
63
|
+
sections,
|
|
64
|
+
firstLine,
|
|
65
|
+
compact: config.displayMode === "compact"
|
|
66
|
+
};
|
|
67
|
+
const directives = /* @__PURE__ */ new Map(), excludes = /* @__PURE__ */ new Set(), includes = /* @__PURE__ */ new Set();
|
|
68
|
+
const issue = (line, zh, en, fixZh = "修正甘特图语句", fixEn = "Correct the Gantt statement") => errors.push(error(lang, line, zh, en, fixZh, fixEn));
|
|
69
|
+
const notice = (line, zh, en) => errors.push(warning("DIAGRAM_HINT", lang, line, zh, en));
|
|
70
|
+
if (info.params || Object.keys(info.options || {}).length) issue(info.headerLine, "gantt 标题行不接受选项", "The gantt header takes no options");
|
|
71
|
+
if (body.length > 2e5) {
|
|
72
|
+
issue(firstLine, "甘特图源码超过 200000 字符,请拆分", "Gantt source exceeds 200,000 characters; split the diagram");
|
|
73
|
+
return {
|
|
74
|
+
model,
|
|
75
|
+
errors
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
let autoId = 0;
|
|
79
|
+
for (const [i, raw] of body.split("\n").entries()) {
|
|
80
|
+
const line = firstLine + i;
|
|
81
|
+
const text = raw.trim();
|
|
82
|
+
if (!text || text.startsWith("%%")) continue;
|
|
83
|
+
const both = /^click\s+(\S+)\s+(?:(href\s+"(?:\\.|[^"\\])*")\s+(call\s+[\w.$]+\s*\(.*\))|(call\s+[\w.$]+\s*\(.*\))\s+(href\s+"(?:\\.|[^"\\])*"))\s*;?$/i.exec(text);
|
|
84
|
+
if (both) {
|
|
85
|
+
for (const command of both.slice(2).filter(Boolean)) look.accept(`click ${both[1]} ${command.replace(/^\w+/, (word) => word.toLowerCase())}`, line);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (look.accept(text.replace(/^(click\s+\S+\s+)(HREF|CALL)(?=\s)/i, (_, prefix, command) => prefix + command.toLowerCase()), line)) continue;
|
|
89
|
+
const statement = /^(dateFormat|axisFormat|tickInterval|weekday|weekend|todayMarker|includes|excludes|title|section)(?:\s+(.*)|$)/i.exec(text);
|
|
90
|
+
if (statement) {
|
|
91
|
+
const key = statement[1].toLowerCase(), value = statement[2] || "";
|
|
92
|
+
if (key === "title") title = {
|
|
93
|
+
raw: value,
|
|
94
|
+
line
|
|
95
|
+
};
|
|
96
|
+
else if (key === "section") sections.push({
|
|
97
|
+
...label(value, line),
|
|
98
|
+
items: []
|
|
99
|
+
});
|
|
100
|
+
else if (key === "includes" || key === "excludes") for (const token of value.toLowerCase().split(/[ ,\t]+/).filter(Boolean)) (key === "includes" ? includes : excludes).add(token);
|
|
101
|
+
else directives.set(key, {
|
|
102
|
+
line,
|
|
103
|
+
value
|
|
104
|
+
});
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (/^(topAxis|inclusiveEndDates)$/i.test(text)) {
|
|
108
|
+
directives.set(text.toLowerCase(), {
|
|
109
|
+
line,
|
|
110
|
+
value: true
|
|
111
|
+
});
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const colon = [...text.matchAll(separator)].find((match) => match[1])?.index;
|
|
115
|
+
if (colon == null) {
|
|
116
|
+
issue(line, `无法识别甘特图语句:${text.slice(0, 50)}`, `Unrecognized Gantt statement: ${text.slice(0, 50)}`);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const names = [];
|
|
120
|
+
const stripClasses = (text) => text.replace(/:::([\w-]+)/g, (_, name) => {
|
|
121
|
+
names.push(name);
|
|
122
|
+
return "";
|
|
123
|
+
});
|
|
124
|
+
const caption = label(stripClasses(text.slice(0, colon)).trim(), line);
|
|
125
|
+
const fields = text.slice(colon + 1).replace(/((?:\s*:::[\w-]+)+)\s*$/, stripClasses).trim().split(",").map((x) => x.trim()), tags = [];
|
|
126
|
+
while (Object.hasOwn(flags, fields[0]?.toLowerCase())) tags.push(fields.shift().toLowerCase());
|
|
127
|
+
if (fields.length > 3 || fields.some((x) => !x) || !fields.length) {
|
|
128
|
+
issue(line, "任务需要结束值,可在前面加起点和 ID", "Expected end, start/end, or ID/start/end");
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const id = fields.length === 3 ? fields.shift() : `task${++autoId}`;
|
|
132
|
+
if (names.length) look.addClasses(id, names, line);
|
|
133
|
+
const record = {
|
|
134
|
+
id,
|
|
135
|
+
...caption,
|
|
136
|
+
startField: fields.length === 2 ? fields[0] : null,
|
|
137
|
+
endField: fields.at(-1),
|
|
138
|
+
flags: tags,
|
|
139
|
+
line
|
|
140
|
+
};
|
|
141
|
+
sections.at(-1).items.push(record);
|
|
142
|
+
items.push(record);
|
|
143
|
+
}
|
|
144
|
+
const heading = label(title.raw, title.line);
|
|
145
|
+
model.title = info.title = heading.name;
|
|
146
|
+
model.titleIcon = heading.icon;
|
|
147
|
+
errors.push(...look.diagnostics());
|
|
148
|
+
for (const task of items) {
|
|
149
|
+
task.status = look.statusOf(task.id);
|
|
150
|
+
task.link = look.linkOf(task.id);
|
|
151
|
+
}
|
|
152
|
+
if (items.length > 2e3) issue(firstLine, `甘特图有 ${items.length} 个任务,超过 2000,请拆分`, `Gantt has ${items.length} tasks (limit 2,000); split the diagram`);
|
|
153
|
+
const option = (key, fallback) => directives.get(key.toLowerCase()) ?? {
|
|
154
|
+
value: config[key] ?? fallback,
|
|
155
|
+
line: configLines[`gantt.${key.toLowerCase()}`] ?? firstLine
|
|
156
|
+
};
|
|
157
|
+
const dateSpec = option("dateFormat", "YYYY-MM-DD"), axisSpec = option("axisFormat", dateSpec.value === "D" ? "%d" : "%Y-%m-%d");
|
|
158
|
+
let date, axis;
|
|
159
|
+
try {
|
|
160
|
+
date = compileDate(String(dateSpec.value));
|
|
161
|
+
} catch (e) {
|
|
162
|
+
issue(dateSpec.line, `不支持的 dateFormat 标记:${e.message}`, `Unsupported dateFormat token: ${e.message}`, `支持:${dateTokens.join(" ")}`, `Supported: ${dateTokens.join(" ")}`);
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
axis = compileAxis(String(axisSpec.value));
|
|
166
|
+
} catch (e) {
|
|
167
|
+
issue(axisSpec.line, `不支持的 axisFormat 标记:${e.message}`, `Unsupported axisFormat token: ${e.message}`, `支持:${axisTokens.map((t) => "%" + t).join(" ")}`, `Supported: ${axisTokens.map((t) => "%" + t).join(" ")}`);
|
|
168
|
+
}
|
|
169
|
+
const weekdaySpec = option("weekday", "sunday"), weekStart = weekdays.findIndex((day) => day.toLowerCase() === String(weekdaySpec.value).toLowerCase());
|
|
170
|
+
if (weekStart < 0) issue(weekdaySpec.line, "weekday 需要英文星期名", "weekday requires an English weekday name");
|
|
171
|
+
const weekendSpec = option("weekend", "saturday"), weekend = ["friday", "saturday"].indexOf(String(weekendSpec.value).toLowerCase()) + 5;
|
|
172
|
+
if (weekend < 5) issue(weekendSpec.line, "weekend 必须是 friday 或 saturday", "weekend must be friday or saturday");
|
|
173
|
+
const intervalSpec = option("tickInterval", ""), interval = intervalPattern.exec(intervalSpec.value);
|
|
174
|
+
if (intervalSpec.value && (!interval || !Number.isSafeInteger(+interval[1]))) notice(intervalSpec.line, "无效的 tickInterval,使用自动刻度", "Invalid tickInterval; using automatic ticks");
|
|
175
|
+
const fixed = config.todayDate != null ? iso.parse(String(config.todayDate)) : NaN;
|
|
176
|
+
if (config.todayDate != null && !valid(fixed)) issue(configLines["gantt.todaydate"] ?? firstLine, "todayDate 必须是 YYYY-MM-DD 日期", "todayDate must be a YYYY-MM-DD date");
|
|
177
|
+
const marker = option("todayMarker", "");
|
|
178
|
+
const off = String(marker.value).toLowerCase() === "off";
|
|
179
|
+
if (!off && marker.value) errors.push(warning("IGNORED_STYLE", lang, marker.line, "Today 标记使用主题样式", "Today marker uses the theme style"));
|
|
180
|
+
const today = off ? NaN : fixed;
|
|
181
|
+
Object.assign(model, {
|
|
182
|
+
axis,
|
|
183
|
+
interval: interval && Number.isSafeInteger(+interval[1]) ? interval : null,
|
|
184
|
+
intervalLine: intervalSpec.line,
|
|
185
|
+
weekStart,
|
|
186
|
+
monthLabels: axisSpec.value === "%Y-%m",
|
|
187
|
+
topAxis: option("topAxis", false).value,
|
|
188
|
+
today
|
|
189
|
+
});
|
|
190
|
+
if (errors.some(blocking)) return {
|
|
191
|
+
model,
|
|
192
|
+
errors
|
|
193
|
+
};
|
|
194
|
+
model.excluded = excludes.size ? excludedBy({
|
|
195
|
+
includes,
|
|
196
|
+
excludes,
|
|
197
|
+
weekend
|
|
198
|
+
}, date.format) : null;
|
|
199
|
+
const ids = /* @__PURE__ */ new Map(), unresolved = /* @__PURE__ */ new Set(), ignoredEnds = /* @__PURE__ */ new Set();
|
|
200
|
+
for (const task of items) {
|
|
201
|
+
if (ids.has(task.id)) issue(task.line, `重复的任务 ID:${task.id}`, `Duplicate task ID: ${task.id}`);
|
|
202
|
+
ids.set(task.id, task);
|
|
203
|
+
}
|
|
204
|
+
const prior = new Map(items.map((task, i) => [task, items[i - 1]]));
|
|
205
|
+
const visiting = /* @__PURE__ */ new Set(), done = /* @__PURE__ */ new Set(), failed = /* @__PURE__ */ new Set();
|
|
206
|
+
const parseDay = (value, task) => {
|
|
207
|
+
const stamp = date.parse(value);
|
|
208
|
+
if (!valid(stamp)) issue(task.line, `日期「${value}」不符合 ${dateSpec.value}`, `Date “${value}” does not match ${dateSpec.value}`);
|
|
209
|
+
return stamp;
|
|
210
|
+
};
|
|
211
|
+
const baseline = valid(fixed) ? fixed : 0;
|
|
212
|
+
const inclusive = option("inclusiveEndDates", false).value;
|
|
213
|
+
function resolve(task) {
|
|
214
|
+
if (done.has(task)) return !failed.has(task);
|
|
215
|
+
if (visiting.has(task)) {
|
|
216
|
+
const path = [...visiting].slice([...visiting].indexOf(task)).map((x) => x.id).concat(task.id).join(" → ");
|
|
217
|
+
issue(task.line, `任务依赖循环:${path}`, `Task dependency cycle: ${path}`);
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
visiting.add(task);
|
|
221
|
+
const relative = (match, useEnd) => {
|
|
222
|
+
const values = [], unknown = [];
|
|
223
|
+
for (const id of match[2].trim().split(/\s+/)) {
|
|
224
|
+
const dep = ids.get(id);
|
|
225
|
+
if (!dep) {
|
|
226
|
+
if (!unresolved.has(id)) unknown.push(id);
|
|
227
|
+
unresolved.add(id);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (!resolve(dep)) return NaN;
|
|
231
|
+
values.push(useEnd ? dep.endTime : dep.startTime);
|
|
232
|
+
}
|
|
233
|
+
if (unknown.length) notice(task.line, `找不到任务:${unknown.join(", ")};使用可解析的任务或固定基准日`, `Unknown task IDs: ${unknown.join(", ")}; using resolved tasks or the fixed baseline`);
|
|
234
|
+
return values.length ? useEnd ? Math.max(...values) : Math.min(...values) : baseline;
|
|
235
|
+
};
|
|
236
|
+
const startDependency = /^after\s/i.test(task.startField || "") && dependency.exec(task.startField);
|
|
237
|
+
const previous = prior.get(task);
|
|
238
|
+
task.startTime = startDependency ? relative(startDependency, true) : task.startField ? parseDay(task.startField, task) : previous ? resolve(previous) ? previous.endTime : NaN : baseline;
|
|
239
|
+
const endDependency = /^until\s/i.test(task.endField) && dependency.exec(task.endField);
|
|
240
|
+
const duration = durationPattern.exec(task.endField);
|
|
241
|
+
if (valid(task.startTime)) {
|
|
242
|
+
let end = endDependency ? relative(endDependency, false) : duration ? add(task.startTime, +duration[1], duration[2]) : date.parse(task.endField);
|
|
243
|
+
if (!duration && !endDependency) {
|
|
244
|
+
if (valid(end)) {
|
|
245
|
+
if (inclusive) end += DAY;
|
|
246
|
+
} else {
|
|
247
|
+
if (!ignoredEnds.has(task.endField)) notice(task.line, `无法解析结束值「${task.endField}」,任务按零时长绘制`, `Unrecognized end value “${task.endField}”; drawing a zero-duration task`);
|
|
248
|
+
ignoredEnds.add(task.endField);
|
|
249
|
+
end = task.startTime;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (duration && model.excluded && valid(end)) end = shiftEnd(task.startTime, end, model.excluded);
|
|
253
|
+
if (end < task.startTime || !valid(end) && (duration || Number.isFinite(end))) issue(task.line, "任务结束日期无效或早于起点", "Task end is invalid or before its start");
|
|
254
|
+
else if (valid(end)) {
|
|
255
|
+
task.endTime = end;
|
|
256
|
+
task.start = iso.format(task.startTime);
|
|
257
|
+
task.end = iso.format(end);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
visiting.delete(task);
|
|
261
|
+
done.add(task);
|
|
262
|
+
if (!valid(task.endTime)) failed.add(task);
|
|
263
|
+
return !failed.has(task);
|
|
264
|
+
}
|
|
265
|
+
if (!errors.some(blocking)) items.forEach(resolve);
|
|
266
|
+
return {
|
|
267
|
+
model,
|
|
268
|
+
errors
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function compactRows(items, { bounds, caption, markerXs, left, width }) {
|
|
272
|
+
const rows = [], gap = 7;
|
|
273
|
+
for (const item of items) {
|
|
274
|
+
const [start, end] = bounds(item), label = caption(item);
|
|
275
|
+
const { w } = label;
|
|
276
|
+
const candidates = [];
|
|
277
|
+
if (!item.flags.includes("milestone") && label.names.length === 1 && end - start >= w + 14) {
|
|
278
|
+
let lo = start + gap;
|
|
279
|
+
const middle = (start + end - w) / 2;
|
|
280
|
+
for (const edge of [...markerXs.filter((x) => x > start && x < end), end]) {
|
|
281
|
+
if (edge - gap - lo >= w) candidates.push({
|
|
282
|
+
x: Math.max(lo, Math.min(middle, edge - gap - w)),
|
|
283
|
+
inside: true
|
|
284
|
+
});
|
|
285
|
+
lo = edge + gap;
|
|
286
|
+
}
|
|
287
|
+
candidates.sort((a, b) => Math.abs(a.x - middle) - Math.abs(b.x - middle));
|
|
288
|
+
}
|
|
289
|
+
candidates.push({ x: end + gap }, { x: start - gap - w });
|
|
290
|
+
const free = candidates.filter(({ x }) => x >= left && x + w <= width - 14 && markerXs.every((marker) => marker <= x - gap || marker >= x + w + gap));
|
|
291
|
+
const available = (row, candidate) => row.every((other) => (item.endTime <= other.item.startTime || item.startTime >= other.item.endTime) && (Math.max(end, candidate.x + w) + gap <= other.lo || Math.min(start, candidate.x) >= other.hi + gap));
|
|
292
|
+
let lane, position;
|
|
293
|
+
for (const row of rows) {
|
|
294
|
+
const place = free.find((candidate) => available(row, candidate));
|
|
295
|
+
if (place) {
|
|
296
|
+
lane = row;
|
|
297
|
+
position = place;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (!lane) {
|
|
302
|
+
lane = [];
|
|
303
|
+
rows.push(lane);
|
|
304
|
+
position = free[0] || candidates.at(-2);
|
|
305
|
+
}
|
|
306
|
+
lane.push({
|
|
307
|
+
item,
|
|
308
|
+
label,
|
|
309
|
+
...position,
|
|
310
|
+
lo: Math.min(start, position.x),
|
|
311
|
+
hi: Math.max(end, position.x + w)
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return rows;
|
|
315
|
+
}
|
|
316
|
+
function layout(model, { width, ctx, measure, renderOptions }) {
|
|
317
|
+
const { design: d, lang } = ctx, { items, sections, today } = model;
|
|
318
|
+
const errors = [], children = [], title = model.title, naked = !renderOptions?.frame && title;
|
|
319
|
+
const body = FONT.body, small = FONT.label, bold = {
|
|
320
|
+
...body,
|
|
321
|
+
weight: 600
|
|
322
|
+
};
|
|
323
|
+
const texts = (value) => value.split("\n");
|
|
324
|
+
const states = (item) => item.flags.map((flag) => flags[flag][isEn(lang) ? 1 : 0]).join(" · ");
|
|
325
|
+
const labelW = Math.max(model.compact ? 32 : 120, ...model.compact ? [] : items.flatMap((item) => [maxWidthOf(texts(item.name), body, measure) + iconSlot(item.icon), measure(states(item), small)]), ...sections.map((s) => maxWidthOf(texts(s.name), bold, measure) + iconSlot(s.icon)));
|
|
326
|
+
const addShape = (tag, attrs, meta, link) => {
|
|
327
|
+
const mark = {
|
|
328
|
+
...ctx.el(tag, attrs),
|
|
329
|
+
...meta ? { meta } : {}
|
|
330
|
+
};
|
|
331
|
+
children.push(link ? ctx.link(link.href, [mark], link) : mark);
|
|
332
|
+
};
|
|
333
|
+
const drawIcon = (icon, x, y, color = d.fg1) => {
|
|
334
|
+
if (!icon) return;
|
|
335
|
+
const [vx, vy, iw, ih] = icon.viewBox.split(/\s+/).map(Number), scale = 14 / Math.max(iw, ih), stroke = icon.set === "tabler";
|
|
336
|
+
children.push(ctx.el("g", {
|
|
337
|
+
transform: `translate(${x - vx * scale} ${y - ih * scale / 2 - vy * scale}) scale(${scale})`,
|
|
338
|
+
fill: stroke ? "none" : color,
|
|
339
|
+
stroke: stroke ? color : "none",
|
|
340
|
+
"stroke-width": 1.6,
|
|
341
|
+
"stroke-linecap": "round",
|
|
342
|
+
"stroke-linejoin": "round"
|
|
343
|
+
}, icon.elements.map(({ tag, attrs }) => ctx.shape(tag, attrs))));
|
|
344
|
+
};
|
|
345
|
+
const text = (value, x, y, font = body, fill = d.fg1, anchor = "start", meta) => children.push(ctx.text(x, y, value, {
|
|
346
|
+
...font,
|
|
347
|
+
fill,
|
|
348
|
+
anchor,
|
|
349
|
+
"dominant-baseline": "central",
|
|
350
|
+
meta
|
|
351
|
+
}));
|
|
352
|
+
const line = (x, y1, y2, stroke, dash) => addShape("line", {
|
|
353
|
+
x1: x,
|
|
354
|
+
x2: x,
|
|
355
|
+
y1,
|
|
356
|
+
y2,
|
|
357
|
+
stroke,
|
|
358
|
+
...dash ? {
|
|
359
|
+
"stroke-width": 2,
|
|
360
|
+
"stroke-dasharray": "4 4"
|
|
361
|
+
} : {}
|
|
362
|
+
});
|
|
363
|
+
const left = labelW + 52, min = items.length ? Math.min(...items.map((item) => item.startTime)) : 0;
|
|
364
|
+
const end = items.length ? Math.max(...items.map((item) => item.endTime)) : min;
|
|
365
|
+
const max = Math.max(end, min + 1);
|
|
366
|
+
const interval = model.interval ?? (model.monthLabels && end - min >= 26784e5 && end - min <= 23328e6 ? intervalPattern.exec("1month") : null);
|
|
367
|
+
const tickResult = items.length ? ticks(min, end, model.weekStart, interval) : { values: [] };
|
|
368
|
+
if (tickResult.dropped) errors.push(warning("DIAGRAM_HINT", lang, model.intervalLine, "刻度超过 10000 个,改用自动刻度", "More than 10,000 ticks; using automatic ticks"));
|
|
369
|
+
const tickList = [];
|
|
370
|
+
const seen = /* @__PURE__ */ new Set(), intervalStep = Math.max(1, Math.ceil(tickResult.values.length / 10));
|
|
371
|
+
tickResult.values.forEach((stamp, i) => {
|
|
372
|
+
if (i % intervalStep) return;
|
|
373
|
+
const label = model.axis(stamp);
|
|
374
|
+
if (!seen.has(label)) {
|
|
375
|
+
seen.add(label);
|
|
376
|
+
tickList.push({
|
|
377
|
+
stamp,
|
|
378
|
+
label,
|
|
379
|
+
w: measure(label, small)
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
let plot = Math.max(228, width - left - 60);
|
|
384
|
+
const ratio = (stamp) => (stamp - min) / (max - min);
|
|
385
|
+
for (let i = 1; i < tickList.length; i++) {
|
|
386
|
+
const a = tickList[i - 1], b = tickList[i];
|
|
387
|
+
plot = Math.max(plot, Math.min(1800, ((a.w + b.w) / 2 + 16) / (ratio(b.stamp) - ratio(a.stamp))));
|
|
388
|
+
}
|
|
389
|
+
const x = (stamp) => left + ratio(stamp) * plot;
|
|
390
|
+
const range = (w, stamp) => ({
|
|
391
|
+
x: x(stamp),
|
|
392
|
+
left: x(stamp) - w / 2,
|
|
393
|
+
right: x(stamp) + w / 2
|
|
394
|
+
});
|
|
395
|
+
const right = Math.max(30, ...tickList.map((t) => t.w / 2 + 14));
|
|
396
|
+
let w = Math.max(width, Math.ceil(left + plot + right));
|
|
397
|
+
const markers = items.filter((item) => item.flags.includes("vert"));
|
|
398
|
+
const showToday = valid(today) && items.length && today >= min && today <= end;
|
|
399
|
+
const markerStamp = (marker) => marker.today ? today : marker.startTime + (marker.endTime - marker.startTime) / 2;
|
|
400
|
+
const markerXs = [...markers.map((marker) => x(markerStamp(marker))), ...showToday ? [x(today)] : []].sort((a, b) => a - b);
|
|
401
|
+
const markBounds = (item) => item.flags.includes("milestone") ? [x(markerStamp(item)) - 9, x(markerStamp(item)) + 9] : [x(item.startTime), Math.max(x(item.startTime) + 4, x(item.endTime))];
|
|
402
|
+
const compact = /* @__PURE__ */ new Map();
|
|
403
|
+
if (model.compact) for (const section of sections) {
|
|
404
|
+
const rows = compactRows(section.items.filter((item) => !item.flags.includes("vert")), {
|
|
405
|
+
bounds: markBounds,
|
|
406
|
+
markerXs,
|
|
407
|
+
left: left - 10,
|
|
408
|
+
width: w,
|
|
409
|
+
caption: (item) => {
|
|
410
|
+
const names = texts(item.name), state = states(item);
|
|
411
|
+
return {
|
|
412
|
+
names,
|
|
413
|
+
state,
|
|
414
|
+
w: Math.max(maxWidthOf(names, body, measure) + iconSlot(item.icon), measure(state, small))
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
compact.set(section, rows);
|
|
419
|
+
for (const row of rows) for (const entry of row) w = Math.max(w, Math.ceil(entry.hi + 14));
|
|
420
|
+
}
|
|
421
|
+
const titleLines = naked ? wrapText(title, w - 48 - iconSlot(model.titleIcon), FONT.title, measure) : [];
|
|
422
|
+
if (titleLines.length) drawIcon(model.titleIcon, 24, 24);
|
|
423
|
+
titleLines.forEach((value, i) => text(value, 24 + iconSlot(model.titleIcon), 24 + i * 20, FONT.title));
|
|
424
|
+
let y = titleLines.length ? 24 + titleLines.length * 20 : 24;
|
|
425
|
+
if (model.topAxis) y += 22;
|
|
426
|
+
const markerY = y, markerInfo = [];
|
|
427
|
+
for (const marker of [...markers, ...showToday ? [{
|
|
428
|
+
startTime: today,
|
|
429
|
+
name: isEn(lang) ? "Today" : "今天",
|
|
430
|
+
today: true
|
|
431
|
+
}] : []]) {
|
|
432
|
+
const stamp = markerStamp(marker);
|
|
433
|
+
const name = marker.name.replace(/\s*\n\s*/g, " ");
|
|
434
|
+
const caption = marker.today ? name : [name, model.axis(stamp)].filter(Boolean).join(" · ");
|
|
435
|
+
const content = wrapText(caption, w - 28 - iconSlot(marker.icon), small, measure);
|
|
436
|
+
const tw = maxWidthOf(content, small, measure) + iconSlot(marker.icon), pitch = 17;
|
|
437
|
+
const center = Math.max(14 + tw / 2, Math.min(w - 14 - tw / 2, x(stamp)));
|
|
438
|
+
markerInfo.push({
|
|
439
|
+
marker,
|
|
440
|
+
stamp,
|
|
441
|
+
y,
|
|
442
|
+
center,
|
|
443
|
+
content
|
|
444
|
+
});
|
|
445
|
+
y += content.length * pitch + 8;
|
|
446
|
+
}
|
|
447
|
+
const top = y;
|
|
448
|
+
const bands = [], bars = [];
|
|
449
|
+
for (const section of sections) {
|
|
450
|
+
if (!section.name && !section.icon && !section.items.length) continue;
|
|
451
|
+
const top = y, names = section.name || section.icon ? texts(section.name) : [];
|
|
452
|
+
if (names.length) y += 14 + 18 * names.length;
|
|
453
|
+
if (model.compact) for (const row of compact.get(section)) {
|
|
454
|
+
const rowH = Math.max(48, ...row.map(({ label, inside }) => inside && label.state ? 58 : (label.names.length + Number(Boolean(label.state))) * 18 + 20));
|
|
455
|
+
for (const entry of row) {
|
|
456
|
+
const middle = y + rowH / 2;
|
|
457
|
+
const lines = entry.label.names.length + Number(Boolean(entry.label.state));
|
|
458
|
+
bars.push({
|
|
459
|
+
task: entry.item,
|
|
460
|
+
barY: middle,
|
|
461
|
+
caption: entry,
|
|
462
|
+
labelY: middle - (entry.inside ? 0 : (lines - 1) * 9)
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
y += rowH;
|
|
466
|
+
}
|
|
467
|
+
else for (const task of section.items.filter((item) => !item.flags.includes("vert"))) {
|
|
468
|
+
const lines = texts(task.name).length + Number(Boolean(states(task)));
|
|
469
|
+
const rowH = Math.max(48, lines * 18 + 20), labelY = y + rowH / 2 - (lines - 1) * 9;
|
|
470
|
+
bars.push({
|
|
471
|
+
task,
|
|
472
|
+
barY: labelY,
|
|
473
|
+
labelY
|
|
474
|
+
});
|
|
475
|
+
y += rowH;
|
|
476
|
+
}
|
|
477
|
+
if (names.length) bands.push({
|
|
478
|
+
names,
|
|
479
|
+
icon: section.icon,
|
|
480
|
+
top,
|
|
481
|
+
bottom: y
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
const bottom = Math.max(y, top + 72), height = bottom + 46;
|
|
485
|
+
bands.forEach(({ top, bottom }, i) => addShape("rect", {
|
|
486
|
+
x: 8,
|
|
487
|
+
y: top,
|
|
488
|
+
width: w - 16,
|
|
489
|
+
height: bottom - top,
|
|
490
|
+
rx: 4,
|
|
491
|
+
fill: ctx.tint(d.bg, ctx.color(`tone${1 + i % 6}`), .07)
|
|
492
|
+
}, {
|
|
493
|
+
kind: "frame",
|
|
494
|
+
id: `section:${i}`
|
|
495
|
+
}));
|
|
496
|
+
if (model.excluded && end - min <= 158112e6) {
|
|
497
|
+
let blocked;
|
|
498
|
+
for (let stamp = Math.floor(min / DAY) * DAY; stamp <= end + DAY; stamp += DAY) {
|
|
499
|
+
if (stamp < end && model.excluded(stamp)) {
|
|
500
|
+
blocked ??= Math.max(min, stamp);
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (blocked != null) {
|
|
504
|
+
const finish = Math.min(end, stamp);
|
|
505
|
+
addShape("rect", {
|
|
506
|
+
x: x(blocked),
|
|
507
|
+
y: top,
|
|
508
|
+
width: x(finish) - x(blocked),
|
|
509
|
+
height: bottom - top,
|
|
510
|
+
fill: ctx.tint(d.bg, d.fg4, .08)
|
|
511
|
+
});
|
|
512
|
+
blocked = void 0;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
} else if (model.excluded) errors.push(warning("DIAGRAM_HINT", lang, model.firstLine, "超过五年,不绘制排除日背景", "Excluded-day shading omitted for ranges over five years"));
|
|
516
|
+
let last = -Infinity;
|
|
517
|
+
for (const tick of tickList) {
|
|
518
|
+
const pos = range(tick.w, tick.stamp);
|
|
519
|
+
if (pos.left < last + 12) continue;
|
|
520
|
+
line(pos.x, top, bottom, ctx.color("grid"));
|
|
521
|
+
text(tick.label, pos.x, bottom + 20, small, d.fg2, "middle");
|
|
522
|
+
if (model.topAxis) text(tick.label, pos.x, markerY - 14, small, d.fg2, "middle");
|
|
523
|
+
last = pos.right;
|
|
524
|
+
}
|
|
525
|
+
for (const { marker, stamp, y, center, content } of markerInfo) {
|
|
526
|
+
const color = marker.status ? d[marker.status] : marker.today ? d.warn : ctx.color("accent");
|
|
527
|
+
drawIcon(marker.icon, center - (measure(content[0] || "", small) + iconSlot(marker.icon)) / 2, y + 8, color);
|
|
528
|
+
const parts = content.map((value, i) => ctx.text(center + iconSlot(marker.icon) / 2, y + 8 + i * 17, value, {
|
|
529
|
+
...small,
|
|
530
|
+
fill: d.fg1,
|
|
531
|
+
anchor: "middle",
|
|
532
|
+
"dominant-baseline": "central"
|
|
533
|
+
}));
|
|
534
|
+
if (marker.link) children.push(ctx.link(marker.link.href, parts, marker.link));
|
|
535
|
+
else children.push(...parts);
|
|
536
|
+
const markerX = x(stamp);
|
|
537
|
+
if (!model.compact) line(markerX, top, bottom, color, true);
|
|
538
|
+
else {
|
|
539
|
+
const gaps = bars.filter(({ caption }) => markerX > caption.x - 3 && markerX < caption.x + caption.label.w + 3);
|
|
540
|
+
let from = top;
|
|
541
|
+
const segment = (to) => {
|
|
542
|
+
if (to > from) addShape("line", {
|
|
543
|
+
x1: markerX,
|
|
544
|
+
x2: markerX,
|
|
545
|
+
y1: from,
|
|
546
|
+
y2: to,
|
|
547
|
+
stroke: color,
|
|
548
|
+
"stroke-width": 2,
|
|
549
|
+
"stroke-dasharray": "4 4"
|
|
550
|
+
}, {
|
|
551
|
+
kind: "leader",
|
|
552
|
+
id: marker.id || "today"
|
|
553
|
+
});
|
|
554
|
+
};
|
|
555
|
+
for (const { caption, labelY } of gaps) {
|
|
556
|
+
segment(labelY - 10);
|
|
557
|
+
from = labelY + (caption.label.names.length - 1 + Number(Boolean(caption.label.state))) * 18 + 10;
|
|
558
|
+
}
|
|
559
|
+
segment(bottom);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
bands.forEach(({ names, icon, top }) => {
|
|
563
|
+
drawIcon(icon, 12, top + 15);
|
|
564
|
+
names.forEach((value, i) => text(value, 12 + iconSlot(icon), top + 15 + i * 18, bold, d.fg2));
|
|
565
|
+
});
|
|
566
|
+
for (const { task, barY, labelY, caption } of bars) {
|
|
567
|
+
const { names, state } = caption?.label ?? {
|
|
568
|
+
names: texts(task.name),
|
|
569
|
+
state: states(task)
|
|
570
|
+
};
|
|
571
|
+
const labelX = caption?.x ?? 12;
|
|
572
|
+
if (!caption) {
|
|
573
|
+
drawIcon(task.icon, labelX, labelY);
|
|
574
|
+
names.forEach((name, i) => text(name, labelX + iconSlot(task.icon), labelY + i * 18));
|
|
575
|
+
if (state) text(state, labelX, labelY + names.length * 18, small, d.fg2);
|
|
576
|
+
}
|
|
577
|
+
const x1 = x(task.startTime), x2 = x(task.endTime), meta = {
|
|
578
|
+
kind: "node",
|
|
579
|
+
id: task.id,
|
|
580
|
+
...task.status ? { status: task.status } : {}
|
|
581
|
+
};
|
|
582
|
+
const critical = task.flags.includes("crit"), done = task.flags.includes("done"), active = task.flags.includes("active");
|
|
583
|
+
const tone = task.status ? d[task.status] : critical ? d.accent : done ? d.ok : active ? d.info : ctx.color("tone1");
|
|
584
|
+
const stroke = ctx.tint(d.bg, tone, critical || task.status ? .82 : .62);
|
|
585
|
+
const fill = ctx.tint(d.bg, tone, done ? .3 : critical ? .24 : .17);
|
|
586
|
+
if (task.flags.includes("milestone")) {
|
|
587
|
+
const mid = (x1 + x2) / 2;
|
|
588
|
+
addShape("polygon", {
|
|
589
|
+
points: `${mid},${barY - 9} ${mid + 9},${barY} ${mid},${barY + 9} ${mid - 9},${barY}`,
|
|
590
|
+
fill,
|
|
591
|
+
stroke
|
|
592
|
+
}, meta, task.link);
|
|
593
|
+
} else {
|
|
594
|
+
const barW = Math.max(4, x2 - x1);
|
|
595
|
+
addShape("rect", {
|
|
596
|
+
x: x1,
|
|
597
|
+
y: barY - 11,
|
|
598
|
+
width: barW,
|
|
599
|
+
height: 22,
|
|
600
|
+
fill,
|
|
601
|
+
stroke,
|
|
602
|
+
rx: 4
|
|
603
|
+
}, meta, task.link);
|
|
604
|
+
if (active && barW > 8) addShape("rect", {
|
|
605
|
+
x: x1 + 2,
|
|
606
|
+
y: barY - 9,
|
|
607
|
+
width: (barW - 4) * .55,
|
|
608
|
+
height: 18,
|
|
609
|
+
fill: ctx.tint(d.bg, tone, .38),
|
|
610
|
+
rx: 3,
|
|
611
|
+
"pointer-events": "none"
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
if (caption) {
|
|
615
|
+
drawIcon(task.icon, labelX, labelY);
|
|
616
|
+
const labelMeta = {
|
|
617
|
+
kind: caption.inside ? "node-label" : "edge-label",
|
|
618
|
+
node: task.id
|
|
619
|
+
};
|
|
620
|
+
names.forEach((name, i) => text(name, labelX + iconSlot(task.icon), labelY + i * 18, body, d.fg1, "start", labelMeta));
|
|
621
|
+
if (state) text(state, labelX, labelY + names.length * 18, small, d.fg2, "start", {
|
|
622
|
+
kind: "edge-label",
|
|
623
|
+
node: task.id
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (items.length === 0) text(isEn(lang) ? "No scheduled tasks" : "暂无排期任务", w / 2, top + 36, body, d.fg2, "middle");
|
|
628
|
+
if (w > 2 * width || items.length > 60) errors.push(warning("LARGE_DIAGRAM", lang, model.firstLine, "甘特图较大,可滚动查看", "Large Gantt chart; scroll to view", "可拆成多张图", "Consider splitting the chart"));
|
|
629
|
+
const scene = {
|
|
630
|
+
width: w,
|
|
631
|
+
height,
|
|
632
|
+
title,
|
|
633
|
+
children,
|
|
634
|
+
...renderOptions?.frame ? { heading: title || void 0 } : {}
|
|
635
|
+
};
|
|
636
|
+
return {
|
|
637
|
+
width: w,
|
|
638
|
+
height,
|
|
639
|
+
scene,
|
|
640
|
+
errors
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
var implementations = { gantt: {
|
|
644
|
+
parse,
|
|
645
|
+
layout,
|
|
646
|
+
acceptsPresentation: true,
|
|
647
|
+
trailingComments: false,
|
|
648
|
+
honoredConfig: [
|
|
649
|
+
"gantt.dateFormat",
|
|
650
|
+
"gantt.axisFormat",
|
|
651
|
+
"gantt.tickInterval",
|
|
652
|
+
"gantt.weekday",
|
|
653
|
+
"gantt.weekend",
|
|
654
|
+
"gantt.topAxis",
|
|
655
|
+
"gantt.inclusiveEndDates",
|
|
656
|
+
"gantt.displayMode",
|
|
657
|
+
"gantt.todayDate",
|
|
658
|
+
"gantt.todayMarker"
|
|
659
|
+
]
|
|
660
|
+
} };
|
|
661
|
+
export { gantt_exports, implementations };
|