import * as d3 from 'd3'; import GraphView from '../../graph-view'; import NodeView, { INode } from '../../node-view'; import { ISlot } from '../../slot-view'; import { NODE_STATUS, NODE_TYPE } from '../constants'; import { DATA_NODE_UI, OPERATOR_NODE_UI } from '../stream-job-style-constant'; import { toTransform, createTextWrap, createSVGElement, d3Selection } from '../../util'; import statusIcons from '../static/icon/status'; import commonIcons from '../static/icon/common'; const bodyWidth = DATA_NODE_UI.WIDTH; const bodyHeight = DATA_NODE_UI.HEIGHT; const wrap = createTextWrap(140); export default class DataNodeView extends NodeView { private $avatar: d3Selection; private $status: d3Selection; protected render(nodeConfig: INode) { this.renderBody(); this.renderTitle(nodeConfig.title || nodeConfig.name); this.renderAvatar(); // this.renderStatus(nodeConfig.status || NODE_STATUS.UNCONFIGURE); this.reLayout(); this.renderInputSlots(nodeConfig.inputSlots); } private renderBody() { this.$body = this.$el.append('rect'); this.$body .attr('x', 0) .attr('y', 0) .attr('width', bodyWidth) .attr('height', bodyHeight) .attr('rx', 20) .attr('ry', 20) .classed('x-node-body', true); } private renderTitle(title: string) { if (!title) throw new Error(`nodeConfig missing either name or title field`); this.$title = this.$el.append('text'); this.$title .attr('text-anchor', 'start') .attr('x', 38) .attr('y', bodyHeight / 2 + 4) .text(title) .classed('x-node-title', true); } private renderAvatar() { this.$avatar = this.$el.append('image'); this.$avatar .attr('xlink:href', commonIcons.streamJobTableImg) .attr('width', OPERATOR_NODE_UI.AVATAR_SIZE - 2) .attr('height', OPERATOR_NODE_UI.AVATAR_SIZE - 2) .attr('x', OPERATOR_NODE_UI.ICON_SIDE_GAP) .attr('y', 12) .classed('x-node-avatar', true); } private renderStatus(status: NODE_STATUS) { const statusSize = OPERATOR_NODE_UI.STATUS_SIZE; this.$status = this.$el.append('image'); this.$status .attr('xlink:href', statusIcons[status.toLowerCase()]) .attr('width', 14) .attr('height', 14) .attr('x', bodyWidth - statusSize - 8) .attr('y', (bodyHeight - statusSize) / 2) .classed('x-node-status', true); } private reLayout() { this.$title.each(wrap); } public destroy() { super.destroy(); } }