@diagrammo/dgmo 0.7.2 → 0.7.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/dist/index.js CHANGED
@@ -13169,6 +13169,9 @@ function renderInitiativeStatus(container, parsed, layout, palette, isDark, opti
13169
13169
  const pillH = LEGEND_HEIGHT - (isActive ? LEGEND_CAPSULE_PAD * 2 : 0);
13170
13170
  const groupW = isActive ? lg.width : pillW;
13171
13171
  const gEl = legendRow.append("g").attr("transform", `translate(${cursorX}, 0)`).attr("class", "is-legend-group").attr("data-legend-group", lg.key).style("cursor", "pointer");
13172
+ if (!isActive) {
13173
+ gEl.attr("data-export-ignore", "true");
13174
+ }
13172
13175
  if (isActive) {
13173
13176
  gEl.append("rect").attr("width", groupW).attr("height", LEGEND_HEIGHT).attr("rx", LEGEND_HEIGHT / 2).attr("fill", groupBg);
13174
13177
  }
@@ -13181,17 +13184,32 @@ function renderInitiativeStatus(container, parsed, layout, palette, isDark, opti
13181
13184
  gEl.append("text").attr("x", pillXOff + pillW / 2).attr("y", LEGEND_HEIGHT / 2 + LEGEND_PILL_FONT_SIZE / 2 - 2).attr("font-size", LEGEND_PILL_FONT_SIZE).attr("font-weight", "500").attr("fill", isActive ? palette.text : palette.textMuted).attr("text-anchor", "middle").attr("font-family", FONT_FAMILY).text(lg.name);
13182
13185
  if (isActive) {
13183
13186
  const hiddenSet = !lg.isStatus ? hiddenTagValues?.get(lg.key) : void 0;
13184
- let entryX = pillXOff + pillW + 4;
13187
+ const entryStartX = pillXOff + pillW + 4;
13188
+ const entryData = [];
13189
+ let estimatedX = entryStartX;
13185
13190
  for (const entry of lg.entries) {
13186
13191
  const isHidden = hiddenSet?.has(entry.value) ?? false;
13187
- const entryG = gEl.append("g").attr("data-legend-entry", entry.value).style("cursor", !lg.isStatus ? "pointer" : "default");
13192
+ const estimatedTextW = entry.label.length * LEGEND_ENTRY_FONT_W;
13193
+ const entryG = gEl.append("g").attr("data-legend-entry", entry.value).attr("transform", `translate(${estimatedX}, 0)`).style("cursor", "pointer");
13194
+ const entryW = LEGEND_DOT_R * 2 + LEGEND_ENTRY_DOT_GAP + estimatedTextW + LEGEND_ENTRY_TRAIL;
13195
+ entryG.append("rect").attr("x", -2).attr("y", 0).attr("width", entryW + 4).attr("height", LEGEND_HEIGHT).attr("fill", "transparent");
13188
13196
  if (isHidden) {
13189
- entryG.append("circle").attr("cx", entryX + LEGEND_DOT_R).attr("cy", LEGEND_HEIGHT / 2).attr("r", LEGEND_DOT_R).attr("fill", "none").attr("stroke", entry.color).attr("stroke-width", 1.2).attr("opacity", 0.5);
13197
+ entryG.append("circle").attr("cx", LEGEND_DOT_R).attr("cy", LEGEND_HEIGHT / 2).attr("r", LEGEND_DOT_R).attr("fill", "none").attr("stroke", entry.color).attr("stroke-width", 1.2).attr("opacity", 0.5);
13190
13198
  } else {
13191
- entryG.append("circle").attr("cx", entryX + LEGEND_DOT_R).attr("cy", LEGEND_HEIGHT / 2).attr("r", LEGEND_DOT_R).attr("fill", entry.color);
13199
+ entryG.append("circle").attr("cx", LEGEND_DOT_R).attr("cy", LEGEND_HEIGHT / 2).attr("r", LEGEND_DOT_R).attr("fill", entry.color);
13192
13200
  }
13193
- entryG.append("text").attr("x", entryX + LEGEND_DOT_R * 2 + LEGEND_ENTRY_DOT_GAP).attr("y", LEGEND_HEIGHT / 2 + LEGEND_ENTRY_FONT_SIZE / 2 - 1).attr("font-size", LEGEND_ENTRY_FONT_SIZE).attr("fill", palette.textMuted).attr("font-family", FONT_FAMILY).attr("opacity", isHidden ? 0.4 : 1).attr("text-decoration", isHidden ? "line-through" : "none").text(entry.label);
13194
- entryX += LEGEND_DOT_R * 2 + LEGEND_ENTRY_DOT_GAP + entry.label.length * LEGEND_ENTRY_FONT_W + LEGEND_ENTRY_TRAIL;
13201
+ const textEl = entryG.append("text").attr("x", LEGEND_DOT_R * 2 + LEGEND_ENTRY_DOT_GAP).attr("y", LEGEND_HEIGHT / 2 + LEGEND_ENTRY_FONT_SIZE / 2 - 1).attr("font-size", LEGEND_ENTRY_FONT_SIZE).attr("fill", palette.textMuted).attr("font-family", FONT_FAMILY).attr("opacity", isHidden ? 0.4 : 1).attr("text-decoration", isHidden ? "line-through" : "none").text(entry.label);
13202
+ entryData.push({ g: entryG, textEl: textEl.node(), estimatedW: estimatedTextW });
13203
+ estimatedX += LEGEND_DOT_R * 2 + LEGEND_ENTRY_DOT_GAP + estimatedTextW + LEGEND_ENTRY_TRAIL;
13204
+ }
13205
+ let reflowX = entryStartX;
13206
+ for (const ed of entryData) {
13207
+ const measuredW = ed.textEl.getComputedTextLength?.() ?? 0;
13208
+ const textW = measuredW > 0 ? measuredW : ed.estimatedW;
13209
+ ed.g.attr("transform", `translate(${reflowX}, 0)`);
13210
+ const actualEntryW = LEGEND_DOT_R * 2 + LEGEND_ENTRY_DOT_GAP + textW + LEGEND_ENTRY_TRAIL;
13211
+ ed.g.select("rect").attr("width", actualEntryW + 4);
13212
+ reflowX += actualEntryW;
13195
13213
  }
13196
13214
  }
13197
13215
  cursorX += groupW + LEGEND_GROUP_GAP;
@@ -25437,6 +25455,7 @@ function finalizeSvgExport(container, theme, palette, options) {
25437
25455
  }
25438
25456
  svgEl.setAttribute("xmlns", "http://www.w3.org/2000/svg");
25439
25457
  svgEl.style.fontFamily = FONT_FAMILY;
25458
+ svgEl.querySelectorAll("[data-export-ignore]").forEach((el) => el.remove());
25440
25459
  const svgHtml = svgEl.outerHTML;
25441
25460
  document.body.removeChild(container);
25442
25461
  if (options?.branding !== false) {