diff --git a/changelog.md b/changelog.md index feab47f..2788079 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## [1.7.0] - 2024-12-14 + +- Add `data-compartment` attribute to SVG output for identifying the compartment index when building interactivity. + ## [1.6.3] - 2024-12-01 - Fix bug when running `nomnoml-cli` with input files in the same directory. diff --git a/dist/nomnoml.js b/dist/nomnoml.js index e25c808..a35a916 100644 --- a/dist/nomnoml.js +++ b/dist/nomnoml.js @@ -1144,6 +1144,7 @@ const style = config.styles[node.type] || styles.class; g.save(); g.setData('name', node.id); + g.setData('compartment', undefined); g.save(); g.fillStyle(style.fill || config.fill[level] || last(config.fill)); g.strokeStyle(style.stroke || config.stroke); @@ -1157,12 +1158,15 @@ g.path(divider.map((e) => add(e, { x, y }))).stroke(); } g.restore(); + let partIndex = 0; for (let part of node.parts) { const textStyle = part === node.parts[0] ? style.title : style.body; g.save(); + g.setData('compartment', String(partIndex)); g.translate(x + part.x, y + part.y); g.setFont(config.font, config.fontSize, textStyle.bold ? 'bold' : 'normal', textStyle.italic ? 'italic' : 'normal'); renderCompartment(part, style.stroke, textStyle, level + 1); + partIndex++; g.restore(); } g.restore(); @@ -1440,7 +1444,7 @@ return this.parent; } serialize() { - const data = getDefined(this.group(), (e) => e.data) ?? {}; + const data = getAncestorData(this.group()) ?? {}; const attrs = toAttrString({ ...this.attr, ...data }); const content = this.children.map((o) => o.serialize()).join('\n'); if (this.text && this.children.length === 0) @@ -1453,6 +1457,11 @@ `; } } + function getAncestorData(group) { + if (!group) + return syntheticRoot.data; + return { ...getAncestorData(group.parent), ...group.data }; + } function getDefined(group, getter) { if (!group) return getter(syntheticRoot); @@ -1744,7 +1753,7 @@ return processImports(loadFile(rootFileName), loadFile, maxImportDepth); } - const version = '1.6.3'; + const version = '1.7.0'; exports.ImportDepthError = ImportDepthError; exports.ParseError = ParseError; diff --git a/package-lock.json b/package-lock.json index a4a735a..40a5224 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nomnoml", - "version": "1.6.3", + "version": "1.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "nomnoml", - "version": "1.6.3", + "version": "1.7.0", "license": "MIT", "dependencies": { "graphre": "^0.1.3" diff --git a/package.json b/package.json index e6b217c..64bf19d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nomnoml", - "version": "1.6.3", + "version": "1.7.0", "description": "The sassy UML renderer that generates diagrams from text", "homepage": "http://www.nomnoml.com", "author": "Daniel Kallin ", diff --git a/src/index.ts b/src/index.ts index c50b82c..27be35b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ export { processAsyncImports, ImportDepthError, } from './nomnoml' -export const version = '1.6.3' +export const version = '1.7.0' export * as skanaar from './util' export { parse, ParseError } from './parser'