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