Skip to content

Commit 5ea5b1e

Browse files
committed
make grayscale and opacity configurable
1 parent cd9bf3d commit 5ea5b1e

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ image:
187187
bottom: -170
188188
```
189189

190+
By default, images are shown at half opacity and grayscale. This is usually a good idea to make the labels and pins more legible when printing. For documentation, you might want to show the image in full color and opacity. You can do this by setting the `opacity` and `grayscale` properties.
191+
192+
```yaml
193+
image:
194+
front:
195+
src: "esp32-c3-super-mini.front.png"
196+
grayscale: false
197+
opacity: 1
198+
```
199+
190200
### offsets
191201

192202
By default, the pin rows will sit on the edges of the defined board size. Sometimes you might want to define your board's size larger than the actual pin area. You can use the offsets setting to move a pin row further in.

src/Builder.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ export class Builder {
2626
left: 0,
2727
right: 0,
2828
bottom: 0,
29+
opacity: 0.5,
30+
grayscale: true,
2931
},
3032
back: {
3133
src: '',
3234
top: 0,
3335
left: 0,
3436
right: 0,
3537
bottom: 0,
36-
}
38+
opacity: 0.5,
39+
grayscale: true,
40+
},
3741
},
3842

3943
// types
@@ -143,20 +147,27 @@ export class Builder {
143147
const legendBBox = legend.getBoundingBox();
144148
const titleBBox = title.getBoundingBox();
145149

146-
// Position legend to the right/left of the pin layout with padding
150+
// Position legend to the bottom aligned to the right/left of the pin layout with padding
151+
let rootBBox = root.getBoundingBox();
147152
if(this.isFlipped) {
148153
// FIXME
149154
// it's hacky:
150155
// rect returns the visual bounding box that includes the stroke width
151156
// for alignment we need to adjust for the stroke width, thus the +10
152157
// see Rect.getBoundingBox()
153-
legend.setTranslate(pinLayoutBBox.x - legendBBox.width + 10 - (PADDING * 3), pinLayoutBBox.y);
158+
legend.setTranslate(
159+
pinLayoutBBox.x - legendBBox.width + 10 - (PADDING * 3),
160+
rootBBox.y + rootBBox.height - legendBBox.height
161+
);
154162
} else {
155-
legend.setTranslate(pinLayoutBBox.x + pinLayoutBBox.width + (PADDING * 3), pinLayoutBBox.y);
163+
legend.setTranslate(
164+
pinLayoutBBox.x + pinLayoutBBox.width + (PADDING * 3),
165+
rootBBox.y + rootBBox.height - legendBBox.height
166+
);
156167
}
157168

158-
// Position title above the pin layout, left aligned
159-
const rootBBox = root.getBoundingBox();
169+
// Position title at the top, left aligned
170+
rootBBox = root.getBoundingBox();
160171
title.setTranslate(rootBBox.x, rootBBox.y - PADDING - titleBBox.height);
161172

162173
// Update SVG bounds to include everything

src/components/Pcb.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export class Pcb extends Group {
6060
left = 0,
6161
right = 0,
6262
bottom = 0,
63-
opacity = 0.5, // Default opacity if not specified
64-
preserveAspectRatio = 'xMidYMid slice' // Default aspect ratio
63+
opacity = 0.5,
64+
grayscale = true
6565
} = imageConfig;
6666

6767
// Adjust dimensions based on top, left, right, bottom offsets
@@ -70,11 +70,15 @@ export class Pcb extends Group {
7070
const imgWidth = basePcbWidth - left - right;
7171
const imgHeight = basePcbHeight - top - bottom;
7272

73-
return new Image(imgX, imgY, imgWidth, imgHeight, src, {
73+
const options = {
7474
preserveAspectRatio: 'none',
7575
'opacity': opacity,
76-
filter: 'url(#grayscale)',
77-
});
76+
}
77+
if(grayscale) {
78+
options['filter'] = 'url(#grayscale)';
79+
}
80+
81+
return new Image(imgX, imgY, imgWidth, imgHeight, src, options);
7882
}
7983

8084
/**

0 commit comments

Comments
 (0)