fixed more styling issues
This commit is contained in:
1 parent
c36050380d
commit
0c8c113e28
3 files changed
+79
-55
No files matched your search
@@ -136,7 +136,7 @@ export const DAGBoard: FC<Props & { zoomLevel: number }> = props => {
|
||||
const [[x0, y0], [x1, y1]] = it.returnValue as BBox;
|
||||
return <SVGBoard
|
||||
graphHeight={y1 - y0}
|
||||
minGraphWidth={x1 - x0}
|
||||
minGraphWidth={Math.max(x1 - x0, props.settings.nodeWidth * 15)}
|
||||
nodeHeight={props.settings.nodeHeight}
|
||||
nodeWidth={props.settings.nodeWidth}
|
||||
zoomLevel={props.zoomLevel}
|
||||
|
||||
@@ -10,7 +10,7 @@ export default {
|
||||
component: SequenceNodes,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
args: {
|
||||
zoomLevel: 0.5,
|
||||
zoomLevel: 1,
|
||||
startPoint: [0.5, 0.5],
|
||||
dims: {
|
||||
nodeHeight: NODE_HEIGHT,
|
||||
@@ -244,3 +244,9 @@ DeepNested.args = {
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
export const SubsequentIssue = Template.bind({})
|
||||
SubsequentIssue.args = {
|
||||
...SubsequentIssue.args,
|
||||
sequence: [{ "$smType": "condition", "condition": "and", "condition_data": { "conditions": [{ "$smType": "condition", "condition": "numeric_state", "condition_data": { "entity_id": "sensor.temperature_kitchen", "below": "15" } }, { "$smType": "condition", "condition": "template", "condition_data": { "value_template": "states(switch.kitchen_light) == \"on\"" } }] } }, { "$smType": "action", "action": "service", "action_data": { "alias": "Start Music In Kitchen", "service": "media_player.play_media", "target": { "entity_id": "media_player.kitchen_dot" }, "data": { "media_content_id": "Good Morning", "media_content_type": "SPOTIFY" } } }, { "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [{ "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [] } }] } }, { "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [] } }, { "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [] } }]
|
||||
}
|
||||
@@ -2,12 +2,35 @@ import { DAGElement } from "components/DAGSvgs/DAGBoard";
|
||||
import { AutomationSequenceNode } from "types/automations";
|
||||
import { Point } from "types/graphs";
|
||||
import { makeUpdater, Updater } from './updater';
|
||||
import { ChooseAction } from '../../types/automations/actions';
|
||||
|
||||
const offsetPoint = (
|
||||
[x, y]: Point,
|
||||
[ox, oy]: Point = [0, 0]
|
||||
): Point => [x + ox, y + oy];
|
||||
;
|
||||
|
||||
const makeOffsetMaintainer = (startPoint: Point) => {
|
||||
let offset: Point = [0, 0];
|
||||
let i = 0;
|
||||
return {
|
||||
setI(newI: number) {
|
||||
i = newI;
|
||||
},
|
||||
resetY() {
|
||||
offset[1] = 0;
|
||||
},
|
||||
update(p: Point, innerStartLoc: Point) {
|
||||
offset[0] = Math.max(offset[0], p[0] - i - 0.5 - startPoint[0])
|
||||
offset[1] = Math.max(offset[1], p[1] - innerStartLoc[1] + 1)
|
||||
},
|
||||
get x() {
|
||||
return offset[0]
|
||||
},
|
||||
get y() {
|
||||
return offset[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function* inner(
|
||||
nodeLoc: Point,
|
||||
@@ -34,28 +57,45 @@ function* inner(
|
||||
}
|
||||
}
|
||||
|
||||
const makeOffsetMaintainer = (startPoint: Point) => {
|
||||
let offset: Point = [0, 0];
|
||||
let i = 0;
|
||||
return {
|
||||
setI(newI: number) {
|
||||
i = newI;
|
||||
},
|
||||
resetY() {
|
||||
offset[1] = 0;
|
||||
},
|
||||
update(p: Point, innerStartLoc: Point) {
|
||||
offset[0] = Math.max(offset[0], p[0] - i - 0.5 - startPoint[0])
|
||||
offset[1] = Math.max(offset[1], p[1] - innerStartLoc[1] + 1)
|
||||
},
|
||||
get x() {
|
||||
return offset[0]
|
||||
},
|
||||
get y() {
|
||||
return offset[1]
|
||||
function* dealWithChoose(
|
||||
node: ChooseAction,
|
||||
nodeLoc: Point,
|
||||
makeUpdater: (j: number | null) => Updater,
|
||||
offset: ReturnType<typeof makeOffsetMaintainer>,
|
||||
keyPrefix: string,
|
||||
) {
|
||||
offset.resetY()
|
||||
for (let j = 0; j < node.action_data.choose.length; j++) {
|
||||
const innerStartLoc = offsetPoint(nodeLoc, [1, j + 1 + offset.y]);
|
||||
for (let elm of inner(
|
||||
nodeLoc,
|
||||
innerStartLoc ,
|
||||
makeUpdater(j),
|
||||
`${keyPrefix}.${j}`,
|
||||
node.action_data.choose[j].sequence
|
||||
)) {
|
||||
yield elm
|
||||
if (elm.type === 'node') {
|
||||
offset.update(elm.loc, innerStartLoc)
|
||||
}
|
||||
}
|
||||
}
|
||||
const innerStartLoc = offsetPoint(nodeLoc, [1, node.action_data.choose.length + 1 + offset.y]);
|
||||
for (let elm of inner(
|
||||
nodeLoc,
|
||||
innerStartLoc,
|
||||
makeUpdater(null),
|
||||
`${keyPrefix}-d`,
|
||||
node.action_data.default,
|
||||
)) {
|
||||
yield elm
|
||||
if (elm.type === 'node') {
|
||||
offset.update(elm.loc, innerStartLoc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function* computeNodesEdgesPos(
|
||||
startPoint: Point,
|
||||
sequence: AutomationSequenceNode[],
|
||||
@@ -64,7 +104,7 @@ export function* computeNodesEdgesPos(
|
||||
): Generator<DAGElement> {
|
||||
const rootUpdater = makeUpdater(sequence, onChange);
|
||||
const offset = makeOffsetMaintainer(startPoint)
|
||||
|
||||
let lastNodeLoc: Point | null = null;
|
||||
for (let i = 0; i < sequence.length; i++) {
|
||||
offset.setI(i)
|
||||
const node = sequence[i];
|
||||
@@ -77,48 +117,26 @@ export function* computeNodesEdgesPos(
|
||||
onRemove: () => rootUpdater.removeNode(i),
|
||||
onAdd: i === sequence.length - 1 ? rootUpdater.addNode : undefined,
|
||||
}
|
||||
if (i > 0) {
|
||||
if (lastNodeLoc) {
|
||||
yield {
|
||||
type: 'edge',
|
||||
key: `${keyPrefix}(${i-1}->${i})`,
|
||||
p1: offsetPoint(startPoint, [i - 1, 0]),
|
||||
p2: offsetPoint(nodeLoc, [0, 0]),
|
||||
p1: lastNodeLoc,
|
||||
p2: nodeLoc,
|
||||
direction: '1->2',
|
||||
}
|
||||
}
|
||||
lastNodeLoc = [...nodeLoc];
|
||||
if (
|
||||
(node.$smType === 'action') && (node.action === 'choose')
|
||||
) {
|
||||
offset.resetY()
|
||||
|
||||
for (let j = 0; j < node.action_data.choose.length; j++) {
|
||||
const innerStartLoc = offsetPoint(nodeLoc, [1, j + 1 + offset.y]);
|
||||
for (let elm of inner(
|
||||
nodeLoc,
|
||||
innerStartLoc ,
|
||||
rootUpdater.makeChildUpdaterForChooseAction(i, j),
|
||||
`${keyPrefix}.${i}.${j}`,
|
||||
node.action_data.choose[j].sequence
|
||||
)) {
|
||||
yield elm
|
||||
if (elm.type === 'node') {
|
||||
offset.update(elm.loc, innerStartLoc)
|
||||
}
|
||||
}
|
||||
}
|
||||
const innerStartLoc = offsetPoint(nodeLoc, [1, node.action_data.choose.length + 1 + offset.y]);
|
||||
for (let elm of inner(
|
||||
yield* dealWithChoose(
|
||||
node,
|
||||
nodeLoc,
|
||||
innerStartLoc,
|
||||
rootUpdater.makeChildUpdaterForChooseAction(i, null),
|
||||
`${keyPrefix}${i}-d`,
|
||||
node.action_data.default,
|
||||
)) {
|
||||
yield elm
|
||||
if (elm.type === 'node') {
|
||||
offset.update(elm.loc, innerStartLoc)
|
||||
}
|
||||
}
|
||||
j => rootUpdater.makeChildUpdaterForChooseAction(i, j),
|
||||
offset,
|
||||
`${keyPrefix}.${i}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user