import * as d3 from 'd3'; import GraphView from '../../graph-view'; import NodeView, { INode } from '../../node-view'; import { ISlot } from '../../slot-view'; import { NODE_STATUS, DATA_NODE_UI, NODE_TYPE, OPERATOR_NODE_UI } from '../constants'; import { toTransform, createMutilineTextWrap, createSVGElement, d3Selection } from '../../util'; import '../static/data-node-view.less'; const multilineTextWrap = createMutilineTextWrap(DATA_NODE_UI.TITLE_MAX_WIDTH); export default class StartNodeView extends NodeView { private $label: d3Selection; private $status: d3Selection; protected render (nodeConfig: INode) { this.renderBody(nodeConfig); this.renderTitle(nodeConfig.title || nodeConfig.name); // this.renderLabel(label); // this.renderStatus();s // this.reLayout(); if (nodeConfig.type === NODE_TYPE.START || nodeConfig.type === 'REQUEST') { this.renderOutputSlots(nodeConfig.outputSlots); } else { this.renderInputSlots(nodeConfig.inputSlots); } } private renderBody (nodeConfig: INode) { this.$body = this.$el.append('rect'); this.$body .attr('x', 0) .attr('y', 0) .attr('width', 120) .attr('height', 40) .attr('rx', 10) .attr('ry', 10) .style('fill', 'rgba(53, 142, 223, 0.1)') .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', 'middle') .attr('x', 60) .attr('y', 24) .text(title) .classed('x-node-start-title', true) .attr('fontSize', '14px'); } private renderStatus() { this.$status = this.$el.append('rect'); this.$status .attr('x', DATA_NODE_UI.WIDTH + 5) .attr('y', 1) .attr('width', DATA_NODE_UI.WIDTH / 5) .attr('height', 12 + DATA_NODE_UI.TITLE_VERTICAL_GAP * 2) .attr('rx', 0) .attr('ry', 0) .style('fill', 'rgba(53, 142, 223, 0.3)') .classed('x-node-status', true); } private renderLabel (label: string) { const LABEL_SIZE = DATA_NODE_UI.LABEL_SIZE; this.$label = this.$el .append('g') .classed('x-node-label', true); this.$label.append('rect') .attr('width', LABEL_SIZE) .attr('height',LABEL_SIZE) .attr('rx', LABEL_SIZE / 2) .attr('ry', LABEL_SIZE); this.$label.append('text') .attr('text-anchor', 'middle') .attr('x', LABEL_SIZE / 2) .attr('y', (LABEL_SIZE - 10) / 2) .attr('dy', LABEL_SIZE / 2) .attr('fill', '#fff') .text(label.slice(0, 1)) .classed('x-node-label', true); } private getLabelFromConfig (nodeConfig: INode) { let label = ''; switch (nodeConfig.type) { case NODE_TYPE.TABLE: label = '数据'; break; case NODE_TYPE.INSTANCE: label = '样本'; break; case NODE_TYPE.MODEL: label = '模型'; break; case NODE_TYPE.GRAPH: label = '图表'; break; default: break; } return label; } private reLayout () { this.$title.each(multilineTextWrap); const WIDTH = DATA_NODE_UI.WIDTH; const LABEL_SIZE = DATA_NODE_UI.LABEL_SIZE; const sTitle = this.$title.node() as SVGTextElement; const bbox = sTitle.getBBox(); const bodyWidth = WIDTH + DATA_NODE_UI.TITLE_SIDE_GAP; const labelTransform = toTransform({ translate: [(bodyWidth - LABEL_SIZE) / 2, -1 * LABEL_SIZE / 2], }); this.$title.attr('x', 80).selectAll('tspan').each(function () { d3.select(this).attr('x', 80); }); // this.$label.attr('transform', labelTransform); this.$body .attr('width', bodyWidth) .attr('height', 44); } public destroy() { this.$label = null; super.destroy(); } }