import * as d3 from 'd3'; import * as uuid from 'uuid'; import GraphView from '../../graph-view'; import NodeView, { INode } from '../../node-view'; import { ISlot } from '../../slot-view'; import OutputCircleGroup from './output-circle-group'; import { NODE_STATUS, EVENTS, NODE_STATUS_COLOR, NODE_TYPE } from '../constants'; import { DATA_NODE_UI, OPERATOR_NODE_UI } from '../stream-job-style-constant'; import { toTransform, createTextWrap, d3Selection } from '../../util'; import statusIcons from '../static/icon/status'; import commonIcons from '../static/icon/common'; import '../static/operator-node-view.less'; import DagSlotView from '../slot/slot-view'; import Tooltip from '../../widget/tooltip'; const bodyWidth = DATA_NODE_UI.WIDTH; const bodyHeight = DATA_NODE_UI.HEIGHT; const wrap = createTextWrap(90); export default class StreamJobNodeView extends NodeView { private $avatar: d3Selection; private $status: d3Selection; private $progress: d3Selection; private $gradient: d3Selection; private outputCircleGroup: OutputCircleGroup; private status: NODE_STATUS; public inputSlots: DagSlotView[]; public outputSlots: DagSlotView[]; protected render(nodeConfig: INode) { const status = nodeConfig.status || NODE_STATUS.UNCONFIGURE; const title = this.getTitleFromConfig(nodeConfig); this.status = status; this.renderBody(); this.renderTitle(title); this.renderAvatar(); this.renderStatus(nodeConfig.status || NODE_STATUS.UNCONFIGURE); this.renderInputSlots(nodeConfig.inputSlots); this.renderOutputSlots(nodeConfig.outputSlots); this.initEvents(); } private renderBody() { this.$body = this.$el.append('rect'); this.$body .attr('x', 0) .attr('y', 0) .attr('width', bodyWidth) .attr('height', bodyHeight) .attr('rx', 2) .attr('ry', 2) // .style('fill', '#fff') .classed('x-node-body', true); } private renderTitle(title: string) { this.$title = this.$el.append('text'); this.$title .attr('text-anchor', 'left') .attr('x', 38) .attr('y', bodyHeight / 2 + 4) .text(title).each(wrap) .classed('x-node-title', true); } private renderAvatar() { this.$avatar = this.$el.append('image'); this.$avatar .attr('xlink:href', commonIcons.streamJobImg) .attr('width', OPERATOR_NODE_UI.AVATAR_SIZE) .attr('height', OPERATOR_NODE_UI.AVATAR_SIZE) .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', statusSize) .attr('height', statusSize) .attr('x', bodyWidth - statusSize - 8) .attr('y', (bodyHeight - statusSize) / 2) .classed('x-node-status', true); } private getTitleFromConfig(nodeConfig: INode) { return nodeConfig.alias || nodeConfig.title || nodeConfig.name; } private runable() { const status = [ NODE_STATUS.UNCONFIGURE, NODE_STATUS.RUNNING, NODE_STATUS.AWAITING, NODE_STATUS.RESUMING, NODE_STATUS.SUCCEEDED, ]; return !status.includes(this.status); } protected initEvents() { super.initEvents(); } protected detachEvents() { this.$el.on('mouseenter', null) .on('mouseleave', null); this.$status .on('mouseover', null) .on('mouseout', null); super.detachEvents(); } // /** // * @param {NODE_STATUS} [status=NODE_STATUS.UNCONFIGURE] // * @memberof OperatorNodeView // */ public updateStatus(status = NODE_STATUS.UNCONFIGURE) { if (this.status === status) return; this.status = status; this.$status.attr('xlink:href', statusIcons[status.toLowerCase()]); // this.$statusBg.style('fill', NODE_STATUS_COLOR[status]); if (status !== NODE_STATUS.RUNNING) { this.$progress.text(null).classed('x-visible', false); this.$gradient.attr('width', 0); } } public destroy() { super.destroy(); } }