proper zoom level
This commit is contained in:
1 parent
b1c5bce584
commit
93fe26e787
6 files changed
+45
-12
No files matched your search
@@ -13,6 +13,7 @@ import { AutomationTrigger } from 'types/automations/triggers';
|
||||
import { Modal } from "components/Modal";
|
||||
import { NodeEditor } from "components/NodeEditor";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
|
||||
interface TriggerEditorModalState {
|
||||
trigger: AutomationTrigger;
|
||||
@@ -29,6 +30,7 @@ export const AutomationEditor: FC<Props> = ({
|
||||
onUpdate,
|
||||
}) => {
|
||||
// state
|
||||
const [zoomLevel, setZoomLevel] = useState(40);
|
||||
const { ratioWbh } = useWindowSize();
|
||||
const [closeInfo, setCloseInfo] = useState(false);
|
||||
const [modalState, setModalState] = useState<null | TriggerEditorModalState>(null);
|
||||
@@ -49,6 +51,13 @@ export const AutomationEditor: FC<Props> = ({
|
||||
|
||||
// render
|
||||
return <div className={classes.root}>
|
||||
<InputNumber
|
||||
label="Zoom"
|
||||
min={1} max={100} step={1}
|
||||
className={classes.zoom}
|
||||
value={zoomLevel}
|
||||
onChange={z => setZoomLevel(z ?? 40)}
|
||||
/>
|
||||
<Modal open={!!modalState}>
|
||||
{!!modalState && <NodeEditor
|
||||
node={modalState.trigger}
|
||||
@@ -73,7 +82,7 @@ export const AutomationEditor: FC<Props> = ({
|
||||
</AutoInfoBox>
|
||||
|
||||
<SequenceNodes
|
||||
zoomLevel={1.5}
|
||||
zoomLevel={zoomLevel * 200 / 100 + 50}
|
||||
startPoint={[2, 0.5]}
|
||||
dims={dims}
|
||||
sequence={automation.sequence}
|
||||
|
||||
@@ -5,7 +5,7 @@ export const useEditorStyles = createAppUseStyles<{
|
||||
closeInfo: boolean;
|
||||
horizontalMode: boolean;
|
||||
}>(theme => ({
|
||||
root: ({horizontalMode}) => ({
|
||||
root: ({ horizontalMode }) => ({
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
color: theme.primaryAccent,
|
||||
@@ -18,7 +18,14 @@ export const useEditorStyles = createAppUseStyles<{
|
||||
borderColor: theme.secondaryAccent,
|
||||
width: '100%',
|
||||
},
|
||||
infoIcon: ({horizontalMode}) => ({
|
||||
infoIcon: ({ horizontalMode }) => ({
|
||||
bottom: horizontalMode ? '90%' : 10
|
||||
})
|
||||
}),
|
||||
zoom: {
|
||||
position: 'absolute !important',
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
width: "100%",
|
||||
// maxWidth: "10em",
|
||||
}
|
||||
}))
|
||||
@@ -16,25 +16,26 @@ export const SVGBoard: FC<{
|
||||
minGraphWidth = 300,
|
||||
nodeHeight = NODE_HEIGHT,
|
||||
nodeWidth = NODE_WIDTH,
|
||||
zoomLevel = 1,
|
||||
zoomLevel = 100,
|
||||
}) => {
|
||||
|
||||
// state
|
||||
const { ratioWbh } = useWindowSize();
|
||||
// alias
|
||||
const paddedZoomLevel = zoomLevel / 100;
|
||||
const graphWidth = Math.max(
|
||||
Math.round(graphHeight * ratioWbh),
|
||||
minGraphWidth
|
||||
);
|
||||
const { classes, theme } = useBoardStyles({
|
||||
boardHeight: Math.max(nodeHeight, graphHeight) * zoomLevel,
|
||||
boardWidth: Math.max(4 * nodeWidth, graphWidth) * zoomLevel,
|
||||
boardHeight: Math.max(nodeHeight, graphHeight) * paddedZoomLevel,
|
||||
boardWidth: Math.max(4 * nodeWidth, graphWidth) * paddedZoomLevel,
|
||||
});
|
||||
// render
|
||||
return <div className={classes.dag} >
|
||||
<svg
|
||||
className={classes.svg}
|
||||
viewBox={[0, 0, graphWidth, graphHeight].join(" ")}
|
||||
viewBox={[0, 0, graphWidth / paddedZoomLevel, graphHeight / paddedZoomLevel].join(" ")}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<defs>
|
||||
|
||||
@@ -10,7 +10,7 @@ export default {
|
||||
component: DAGBoard,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
args: {
|
||||
zoomLevel: 1,
|
||||
zoomLevel: 100,
|
||||
settings: {
|
||||
nodeHeight: NODE_HEIGHT,
|
||||
nodeWidth: NODE_WIDTH,
|
||||
|
||||
@@ -6,22 +6,38 @@ export interface Props {
|
||||
label: string;
|
||||
value: number | undefined;
|
||||
onChange: (v: number | undefined) => void;
|
||||
className?: string;
|
||||
min?: number,
|
||||
max?: number,
|
||||
step?: number,
|
||||
}
|
||||
export default function InputNumber({
|
||||
label,
|
||||
value = undefined,
|
||||
onChange,
|
||||
className = "",
|
||||
min, max, step,
|
||||
}: Props) {
|
||||
const { classes } = useInputNumberStyles({});
|
||||
return <InputWrapper label={label} labelSize={value !== undefined ? 'small' : 'normal'}>
|
||||
return <InputWrapper className={className} label={label} labelSize={value !== undefined ? 'small' : 'normal'}>
|
||||
<input
|
||||
className={classes.input}
|
||||
type="number"
|
||||
value={value ?? ""}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(Number(e.target.value))
|
||||
let v = Number(e.target.value);
|
||||
if (max) {
|
||||
v = Math.min(v, max)
|
||||
}
|
||||
if (min) {
|
||||
v = Math.max(v, min)
|
||||
}
|
||||
onChange(v)
|
||||
}}
|
||||
step={step}
|
||||
min={min}
|
||||
max={max}
|
||||
/>
|
||||
{value && <button className={classes.deleteIcon} onClick={() => onChange(undefined)}>X</button>}
|
||||
</InputWrapper>
|
||||
|
||||
@@ -11,7 +11,7 @@ export default {
|
||||
component: SequenceNodes,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
args: {
|
||||
zoomLevel: 1.5,
|
||||
zoomLevel: 100,
|
||||
startPoint: [0.5, 0.5],
|
||||
dims: {
|
||||
nodeHeight: NODE_HEIGHT,
|
||||
|
||||
Reference in new issue
Block a user