本文整理汇总了TypeScript中@cycle/dom.svg.rect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript svg.rect方法的具体用法?TypeScript svg.rect怎么用?TypeScript svg.rect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@cycle/dom.svg
的用法示例。
在下文中一共展示了svg.rect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: renderSourceOrSinkNode
function renderSourceOrSinkNode(node: StreamGraphNode, zaps: Array<Zap>) {
const index = zaps.map(zap => zap.id).indexOf(node.id);
const zap = index === -1 ? null : zaps[index];
const P = 5; // text padding
const hook = {
insert(vnode: VNode) {
const gElem = vnode.elm as Element;
const rectElem = gElem.childNodes[0] as Element;
const textElem = gElem.childNodes[1] as Element;
const tspanElem = textElem.childNodes[0] as Element;
tspanElem.setAttribute('x',
String(DIAGRAM_PADDING_H + node.x - textElem.clientWidth * 0.5 - P * 0.4),
);
tspanElem.setAttribute('y',
String(DIAGRAM_PADDING_V + node.y + textElem.clientHeight * 0.5 - P * 0.5),
);
rectElem.setAttribute('x',
String(DIAGRAM_PADDING_H + node.x - textElem.clientWidth * 0.5 - P),
);
rectElem.setAttribute('y',
String(DIAGRAM_PADDING_V + node.y - textElem.clientHeight * 0.5 - P),
);
rectElem.setAttribute('width', String(textElem.clientWidth + 2 * P));
rectElem.setAttribute('height', String(textElem.clientHeight + 2 * P));
},
};
return svg.g({ hook }, [
svg.rect({
class: {
[styles.sourceOrSinkNodeStyle]: !zap,
[styles.nodeZapNextStyle]: zap && zap.type === 'next',
[styles.nodeZapErrorStyle]: zap && zap.type === 'error',
[styles.nodeZapCompleteStyle]: zap && zap.type === 'complete',
},
attrs: {
x: node.x - node.width * 0.5 + DIAGRAM_PADDING_H,
y: node.y - node.height * 0.5 + DIAGRAM_PADDING_V,
rx: 9,
ry: 9,
width: node.width,
height: node.height,
},
}),
svg.text({ class: { [styles.sourceOrSinkNodeNameStyle]: true } }, [
svg.tspan(String(node.label)),
]),
renderNodeLabel(node, zap, styles.sourceOrSinkNodeLabelStyle),
]);
}
示例2: renderCommonNode
function renderCommonNode(node: StreamGraphNode, zaps: Array<Zap>): VNode {
const index = zaps.map(zap => zap.id).indexOf(node.id);
const zap = index === -1 ? null : zaps[index];
return svg.g([
svg.rect({
class: {
[styles.activeNodeStyle]: !zap,
[styles.nodeZapNextStyle]: zap && zap.type === 'next',
[styles.nodeZapErrorStyle]: zap && zap.type === 'error',
[styles.nodeZapCompleteStyle]: zap && zap.type === 'complete',
},
attrs: {
x: node.x - node.width * 0.5 + DIAGRAM_PADDING_H,
y: node.y - node.height * 0.5 + DIAGRAM_PADDING_V,
rx: 9,
ry: 9,
width: node.width,
height: node.height,
},
hook: {
update(oldVNode: VNode, newVNode: VNode) {
const rectElem = newVNode.elm as Element;
const inactiveAttr = 'data-inactive-state';
const inactiveAttrValue = rectElem.getAttribute(inactiveAttr);
if (zap && zap.type === 'complete') {
rectElem.setAttribute(inactiveAttr, 'complete');
} else if (zap && zap.type === 'error') {
rectElem.setAttribute(inactiveAttr, 'error');
} else if (zap && zap.type === 'next' && inactiveAttrValue) {
rectElem.removeAttribute(inactiveAttr);
rectElem.setAttribute('class', styles.nodeZapNextStyle);
} else if (inactiveAttrValue === 'complete') {
rectElem.setAttribute('class', styles.nodeInactiveCompleteStyle);
} else if (inactiveAttrValue === 'error') {
rectElem.setAttribute('class', styles.nodeInactiveErrorStyle);
}
},
},
}),
renderNodeLabel(node, zap, styles.commonNodeLabelStyle),
]);
}