Compare commits

...

3 Commits

Author SHA1 Message Date
Bram Kragten
8d39901c88 Update hat-graph-node.ts 2021-04-06 18:42:38 +02:00
Bram Kragten
9f4650b012 Update hat-graph-node.ts 2021-04-06 18:39:05 +02:00
Bram Kragten
1fe8b36d6e Add spacer for default of choose 2021-04-06 18:22:52 +02:00
2 changed files with 30 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
import { css, customElement, LitElement, property, svg } from "lit-element"; import { css, customElement, LitElement, property, svg } from "lit-element";
import { ifDefined } from "lit-html/directives/if-defined";
import { NODE_SIZE, SPACING } from "./hat-graph"; import { NODE_SIZE, SPACING } from "./hat-graph";
@@ -10,6 +11,8 @@ export class HatGraphNode extends LitElement {
@property({ reflect: true, type: Boolean }) graphstart?: boolean; @property({ reflect: true, type: Boolean }) graphstart?: boolean;
@property({ reflect: true, type: Boolean }) spacer?: boolean;
@property({ reflect: true, type: Boolean }) nofocus?: boolean; @property({ reflect: true, type: Boolean }) nofocus?: boolean;
@property({ reflect: true, type: Number }) badge?: number; @property({ reflect: true, type: Number }) badge?: number;
@@ -22,7 +25,7 @@ export class HatGraphNode extends LitElement {
updated() { updated() {
const svgEl = this.shadowRoot?.querySelector("svg"); const svgEl = this.shadowRoot?.querySelector("svg");
if (!svgEl) { if (!svgEl || this.spacer) {
return; return;
} }
const bbox = svgEl.getBBox(); const bbox = svgEl.getBBox();
@@ -42,6 +45,15 @@ export class HatGraphNode extends LitElement {
render() { render() {
return svg` return svg`
<svg <svg
width=${ifDefined(this.spacer ? `${SPACING}px` : undefined)}
height=${ifDefined(
this.spacer ? `${SPACING + NODE_SIZE + 1}px` : undefined
)}
viewBox=${ifDefined(
this.spacer
? `-${SPACING / 2} 0 10 ${SPACING + NODE_SIZE + 1}`
: undefined
)}
> >
${ ${
this.graphstart this.graphstart
@@ -50,7 +62,9 @@ export class HatGraphNode extends LitElement {
<path <path
class="connector" class="connector"
d=" d="
M 0 ${-SPACING - NODE_SIZE / 2} M 0 ${
this.spacer ? SPACING + NODE_SIZE + 1 : -SPACING - NODE_SIZE / 2
}
L 0 0 L 0 0
" "
line-caps="round" line-caps="round"
@@ -58,11 +72,15 @@ export class HatGraphNode extends LitElement {
` `
} }
<g class="node"> <g class="node">
<circle ${
!this.spacer
? svg`<circle
cx="0" cx="0"
cy="0" cy="0"
r="${NODE_SIZE / 2}" r="${NODE_SIZE / 2}"
/> />`
: ""
}
${ ${
this.badge this.badge
? svg` ? svg`

View File

@@ -192,6 +192,14 @@ class HatScriptGraph extends LitElement {
`; `;
})} })}
<hat-graph> <hat-graph>
<hat-graph-node
nofocus
spacer
class=${classMap({
track:
trace !== undefined && trace[0].result?.choice === "default",
})}
></hat-graph-node>
${ensureArray(config.default)?.map((action, i) => ${ensureArray(config.default)?.map((action, i) =>
this.render_node(action, `${path}/default/${i}`) this.render_node(action, `${path}/default/${i}`)
)} )}