mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-17 11:14:12 +01:00
refactor(types): fix kanbanRenderer types
Add the appropriate type checks to ensure that we're only ever calling:
- `insertCluster()` with `ClusterNode`
- `insertNode()` with a `NonClusterNode`
Fixes: 7401cb8f6a
This commit is contained in:
@@ -7,6 +7,7 @@ import type { KanbanDB } from './kanbanTypes.js';
|
|||||||
import defaultConfig from '../../defaultConfig.js';
|
import defaultConfig from '../../defaultConfig.js';
|
||||||
import { insertCluster } from '../../rendering-util/rendering-elements/clusters.js';
|
import { insertCluster } from '../../rendering-util/rendering-elements/clusters.js';
|
||||||
import { insertNode, positionNode } from '../../rendering-util/rendering-elements/nodes.js';
|
import { insertNode, positionNode } from '../../rendering-util/rendering-elements/nodes.js';
|
||||||
|
import type { ClusterNode } from '../../rendering-util/types.js';
|
||||||
|
|
||||||
export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
||||||
log.debug('Rendering kanban diagram\n' + text);
|
log.debug('Rendering kanban diagram\n' + text);
|
||||||
@@ -26,7 +27,10 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
|||||||
sectionsElem.attr('class', 'sections');
|
sectionsElem.attr('class', 'sections');
|
||||||
const nodesElem = svg.append('g');
|
const nodesElem = svg.append('g');
|
||||||
nodesElem.attr('class', 'items');
|
nodesElem.attr('class', 'items');
|
||||||
const sections = data4Layout.nodes.filter((node) => node.isGroup);
|
const sections = data4Layout.nodes.filter(
|
||||||
|
// TODO: TypeScript 5.5 will infer this predicate automatically
|
||||||
|
(node): node is typeof node & ClusterNode => node.isGroup
|
||||||
|
);
|
||||||
let cnt = 0;
|
let cnt = 0;
|
||||||
// TODO set padding
|
// TODO set padding
|
||||||
const padding = 10;
|
const padding = 10;
|
||||||
@@ -60,6 +64,11 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
|||||||
let y = top;
|
let y = top;
|
||||||
const sectionItems = data4Layout.nodes.filter((node) => node.parentId === section.id);
|
const sectionItems = data4Layout.nodes.filter((node) => node.parentId === section.id);
|
||||||
for (const item of sectionItems) {
|
for (const item of sectionItems) {
|
||||||
|
if (item.isGroup) {
|
||||||
|
// Kanban diagrams should not have groups within groups
|
||||||
|
// this should never happen
|
||||||
|
throw new Error('Groups within groups are not allowed in Kanban diagrams');
|
||||||
|
}
|
||||||
item.x = section.x;
|
item.x = section.x;
|
||||||
item.width = WIDTH - 1.5 * padding;
|
item.width = WIDTH - 1.5 * padding;
|
||||||
const nodeEl = await insertNode(nodesElem, item, { config: conf });
|
const nodeEl = await insertNode(nodesElem, item, { config: conf });
|
||||||
|
|||||||
Reference in New Issue
Block a user