Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/struktolab/src/common/svg-renderer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { KEYWORDS_DE } from "./pseudocode-parser.js";

const SVG_NS = "http://www.w3.org/2000/svg";

const COLORS = {
Expand Down Expand Up @@ -52,6 +54,7 @@ const COLORS = {
};

let COLOR_MODE = "color";
let KEYWORDS = KEYWORDS_DE;

function getColor(nodeType) {
return COLORS[COLOR_MODE](nodeType);
Expand Down Expand Up @@ -457,11 +460,11 @@ function renderNode(node, x, y, width, fontSize, availH) {
// True/False labels below slopes
const smallFS = fontSize * 0.8;
elements.push(
textEl("Wahr", x + PADDING_X, slopeBottom, labelRowH, smallFS, null),
textEl(KEYWORDS.true, x + PADDING_X, slopeBottom, labelRowH, smallFS, null),
);
elements.push(
textEl(
"Falsch",
KEYWORDS.false,
x + width - PADDING_X,
slopeBottom,
labelRowH,
Expand Down Expand Up @@ -926,6 +929,7 @@ function renderNode(node, x, y, width, fontSize, availH) {
* @param {number} [options.width=600] - SVG coordinate width (used for layout calculations)
* @param {number} [options.fontSize=14] - Font size in px
* @param {string} [options.colorMode] - "color" (default) or "bw" for black-and-white colors
* @param {Object} [options.keywords=KEYWORDS_DE] - Keyword map for the true/false labels
* @returns {SVGSVGElement}
*/
export function renderStructogramSVG(tree, options = {}) {
Expand All @@ -934,6 +938,7 @@ export function renderStructogramSVG(tree, options = {}) {
if (options.colorMode && COLORS[options.colorMode]) {
COLOR_MODE = options.colorMode;
}
KEYWORDS = options.keywords || KEYWORDS_DE;

const totalHeight = measureHeight(tree, fontSize, width);
const h = totalHeight || 40;
Expand Down
4 changes: 2 additions & 2 deletions packages/struktolab/src/editor/struktolab-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ class StruktolabEditor extends HTMLElement {
// moment a move starts used to grow the diagram and slide the node out
// from under the pointer, which is the one thing a drag must not do.
setInsertNodeHeight(0);
const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode });
const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode, keywords: this._getKeywords() });

svg.setAttribute("role", "group");
svg.setAttribute("aria-label", this._t("structogram"));
Expand Down Expand Up @@ -2713,7 +2713,7 @@ class StruktolabEditor extends HTMLElement {

// Render a clean SVG (no insert-node space, no overlays)
setInsertNodeHeight(0);
const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode });
const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode, keywords: this._getKeywords() });
setInsertNodeHeight(0);

const serializer = new XMLSerializer();
Expand Down
2 changes: 1 addition & 1 deletion packages/struktolab/src/renderer/struktolab-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class StruktolabRenderer extends HTMLElement {
this._container.removeChild(this._container.firstChild);
}

const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode });
const svg = renderStructogramSVG(this._tree, { width, fontSize, colorMode, keywords: this._getKeywords() });
this._container.appendChild(svg);
}
}
Expand Down
Loading