circuit-to-svg 0.0.247 → 0.0.249

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
@@ -2490,7 +2490,7 @@ function createSvgObjectsFromPcbPanel(pcbPanel, ctx) {
2490
2490
  attributes: {
2491
2491
  class: "pcb-panel",
2492
2492
  d: path,
2493
- fill: shouldRenderSolderMask ? colorMap2.soldermask.top : "none",
2493
+ fill: "none",
2494
2494
  stroke: colorMap2.boardOutline,
2495
2495
  "stroke-width": (0.1 * Math.abs(transform.a)).toString(),
2496
2496
  "data-type": "pcb_panel",
@@ -3287,7 +3287,7 @@ function getSoftwareUsedString(circuitJson) {
3287
3287
  var package_default = {
3288
3288
  name: "circuit-to-svg",
3289
3289
  type: "module",
3290
- version: "0.0.246",
3290
+ version: "0.0.248",
3291
3291
  description: "Convert Circuit JSON to SVG",
3292
3292
  main: "dist/index.js",
3293
3293
  files: [
@@ -9989,39 +9989,81 @@ function createAxes({
9989
9989
  );
9990
9990
  return svgElement("g", { class: "axes" }, children);
9991
9991
  }
9992
+ var MAX_LEGEND_LINE_LENGTH = 5;
9993
+ var LEGEND_LINE_HEIGHT = 16;
9994
+ var LEGEND_MIN_SPACING = 24;
9992
9995
  function createLegend(graphs, width) {
9993
- const children = graphs.map((entry, index) => {
9994
- const y = MARGIN.top + index * 24;
9996
+ let currentY = MARGIN.top;
9997
+ const children = graphs.map((entry) => {
9995
9998
  const x = width - MARGIN.right + 20;
9999
+ const lines = wrapLegendText(entry.label);
10000
+ const legendItem = createLegendItem(entry, x, currentY, lines);
10001
+ const itemHeight = lines.length * LEGEND_LINE_HEIGHT;
10002
+ currentY += Math.max(itemHeight, LEGEND_MIN_SPACING);
10003
+ return legendItem;
10004
+ });
10005
+ return svgElement("g", { class: "legend" }, children);
10006
+ }
10007
+ function wrapLegendText(label) {
10008
+ const parts = label.split("_");
10009
+ if (parts.length <= 1) {
10010
+ return [label];
10011
+ }
10012
+ const lines = [];
10013
+ let currentLine = parts[0] ?? "";
10014
+ for (let i = 1; i < parts.length; i++) {
10015
+ const part = parts[i] ?? "";
10016
+ const testLine = currentLine + "_" + part;
10017
+ if (testLine.length > MAX_LEGEND_LINE_LENGTH) {
10018
+ lines.push(currentLine);
10019
+ currentLine = part;
10020
+ } else {
10021
+ currentLine = testLine;
10022
+ }
10023
+ }
10024
+ if (currentLine) {
10025
+ lines.push(currentLine);
10026
+ }
10027
+ return lines;
10028
+ }
10029
+ function createLegendItem(entry, x, y, lines) {
10030
+ const textChildren = lines.map((line, index) => {
9996
10031
  return svgElement(
9997
- "g",
10032
+ "tspan",
9998
10033
  {
9999
- class: "legend-item",
10000
- transform: `translate(${formatNumber(x)} ${formatNumber(y)})`
10034
+ x: "32",
10035
+ dy: index === 0 ? "0" : String(LEGEND_LINE_HEIGHT)
10001
10036
  },
10002
- [
10003
- svgElement("line", {
10004
- class: "legend-line",
10005
- x1: "0",
10006
- y1: "0",
10007
- x2: "24",
10008
- y2: "0",
10009
- stroke: entry.color
10010
- }),
10011
- svgElement(
10012
- "text",
10013
- {
10014
- class: "legend-label",
10015
- x: "32",
10016
- y: "0",
10017
- "dominant-baseline": "middle"
10018
- },
10019
- [textNode(entry.label)]
10020
- )
10021
- ]
10037
+ [textNode(line)]
10022
10038
  );
10023
10039
  });
10024
- return svgElement("g", { class: "legend" }, children);
10040
+ return svgElement(
10041
+ "g",
10042
+ {
10043
+ class: "legend-item",
10044
+ transform: `translate(${formatNumber(x)} ${formatNumber(y)})`
10045
+ },
10046
+ [
10047
+ svgElement("line", {
10048
+ class: "legend-line",
10049
+ x1: "0",
10050
+ y1: "0",
10051
+ x2: "24",
10052
+ y2: "0",
10053
+ stroke: entry.color
10054
+ }),
10055
+ svgElement(
10056
+ "text",
10057
+ {
10058
+ class: "legend-label",
10059
+ x: "32",
10060
+ y: "0",
10061
+ "dominant-baseline": "middle"
10062
+ },
10063
+ textChildren
10064
+ )
10065
+ ]
10066
+ );
10025
10067
  }
10026
10068
  function createDataGroup(graphs, clipPathId, scaleX, scaleY) {
10027
10069
  const LINE_REPEAT_COUNT = 3;