Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions src/ui/widgets/EmbeddedDisplay/opiParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,16 @@ function opiPatchPaths(
}
}
}

// symbols: list of string file paths
if (widgetDescription["symbols"] && parentDir) {
widgetDescription["symbols"] = widgetDescription["symbols"].map(
(symbol: string) => {
if (symbol.startsWith("http")) return symbol;
return normalisePath(symbol, parentDir);
}
);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general comment: Throughout this function we are mutating the object widgetDescription. Typescript prefers immutable objects. If I were to write this function opiPatchPaths from scratch I would have it return a new instance of WidgetDescription. Which I think would make its operation more transparent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @GregJHarris, I agree it will make it more transparent. I hadn't properly noticed it was just mutating the existing widgetDescription.


function opiPatchActions(widgetDescription: WidgetDescription): void {
Expand Down
12 changes: 9 additions & 3 deletions src/ui/widgets/Image/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const ImageProps = {
onClick: FuncPropOpt,
overflow: BoolPropOpt,
backgroundColor: ColorPropOpt,
transparent: BoolPropOpt
transparent: BoolPropOpt,
preserveRatio: BoolPropOpt
};

export const ImageComponent = (
Expand All @@ -37,7 +38,8 @@ export const ImageComponent = (
rotation = 0,
flipHorizontal,
flipVertical,
stretchToFit = false
stretchToFit = false,
preserveRatio = false
} = props;

const onClick = (event: React.MouseEvent<HTMLDivElement>): void => {
Expand Down Expand Up @@ -67,6 +69,10 @@ export const ImageComponent = (
imageFileName = imageFileName + new Date().getTime();
}

// In Phoebus, the aspect ratio of svgs is always maintained even when
// stretchToFit is true. Also accept preserveRatio property passed from
// Symbol widget
const ratio = imageFileName.includes(".svg") ? true : preserveRatio;
return (
<div style={style} onClick={onClick}>
<img
Expand All @@ -77,7 +83,7 @@ export const ImageComponent = (
transform: `rotate(${rotation}deg) scaleX(${
flipHorizontal ? -1 : 1
}) scaleY(${flipVertical ? -1 : 1})`,
objectFit: stretchToFit ? "fill" : "none",
objectFit: ratio ? "contain" : stretchToFit ? "fill" : "contain",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth simplifying this to something like:
objectFit: ratio || !stretchToFit ? "contain" : "fill",

objectPosition: "top left"
}}
/>
Expand Down
12 changes: 6 additions & 6 deletions src/ui/widgets/Symbol/__snapshots__/symbol.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`<Symbol /> from .bob file > matches snapshot (using fallback symbol) 1`
>
<img
src="https://cs-web-symbol.diamond.ac.uk/catalogue/default_symbol.png"
style="display: block; transform: rotate(0deg) scaleX(1) scaleY(1); object-fit: none; object-position: top left;"
style="display: block; transform: rotate(0deg) scaleX(1) scaleY(1); object-fit: contain; object-position: top left;"
/>
</div>
</DocumentFragment>
Expand All @@ -20,7 +20,7 @@ exports[`<Symbol /> from .bob file > matches snapshot (with index) 1`] = `
>
<img
src="img 3.svg"
style="display: block; transform: rotate(0deg) scaleX(1) scaleY(1); object-fit: none; object-position: top left;"
style="display: block; transform: rotate(0deg) scaleX(1) scaleY(1); object-fit: contain; object-position: top left;"
/>
</div>
</DocumentFragment>
Expand All @@ -33,7 +33,7 @@ exports[`<Symbol /> from .bob file > matches snapshot (with rotation) 1`] = `
>
<img
src="img 1.gif"
style="display: block; transform: rotate(45deg) scaleX(1) scaleY(1); object-fit: none; object-position: top left;"
style="display: block; transform: rotate(45deg) scaleX(1) scaleY(1); object-fit: contain; object-position: top left;"
/>
</div>
</DocumentFragment>
Expand All @@ -46,7 +46,7 @@ exports[`<Symbol /> from .bob file > matches snapshot (without index) 1`] = `
>
<img
src="img 1.gif"
style="display: block; transform: rotate(0deg) scaleX(1) scaleY(1); object-fit: none; object-position: top left;"
style="display: block; transform: rotate(0deg) scaleX(1) scaleY(1); object-fit: contain; object-position: top left;"
/>
</div>
</DocumentFragment>
Expand All @@ -59,7 +59,7 @@ exports[`<Symbol /> from .opi file > matches snapshot (with rotation) 1`] = `
>
<img
src="img 1.gif"
style="display: block; transform: rotate(45deg) scaleX(1) scaleY(1); object-fit: none; object-position: top left;"
style="display: block; transform: rotate(45deg) scaleX(1) scaleY(1); object-fit: contain; object-position: top left;"
/>
</div>
</DocumentFragment>
Expand All @@ -72,7 +72,7 @@ exports[`<Symbol /> from .opi file > matches snapshot 1`] = `
>
<img
src="img 1.gif"
style="display: block; transform: rotate(0deg) scaleX(1) scaleY(1); object-fit: none; object-position: top left;"
style="display: block; transform: rotate(0deg) scaleX(1) scaleY(1); object-fit: contain; object-position: top left;"
/>
</div>
<div
Expand Down
6 changes: 4 additions & 2 deletions src/ui/widgets/Symbol/symbol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const SymbolProps = {
arrayIndex: FloatPropOpt,
enabled: BoolPropOpt,
fallbackSymbol: StringPropOpt,
transparent: BoolPropOpt
transparent: BoolPropOpt,
preserveRatio: BoolPropOpt
};

export type SymbolComponentProps = InferWidgetProps<typeof SymbolProps> &
Expand All @@ -76,6 +77,7 @@ export const SymbolComponent = (props: SymbolComponentProps): JSX.Element => {
backgroundColor = "white",
showBooleanLabel = false,
enabled = true,
preserveRatio = true,
pvData
} = props;
const { value } = getPvValueAndName(pvData);
Expand Down Expand Up @@ -158,7 +160,7 @@ export const SymbolComponent = (props: SymbolComponentProps): JSX.Element => {
transparent
imageFile={imageFile}
onClick={onClick}
stretchToFit={false}
stretchToFit={preserveRatio ? false : true}
overflow={true}
/>
{isBob ? (
Expand Down
Loading