2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 import React from 'react';
23 import IconFactory from './IconFactory.js';
24 import NodeVisualElementConstants from './NodeVisualElementConstants.js';
26 class NodeVisualElementFactory {
29 this.visualElementMeta = {};
31 this.setVisualElementMeta = this.setVisualElementMeta.bind(this);
32 this.buildVisualElement = this.buildVisualElement.bind(this);
33 this.createSvgCircle = this.createSvgCircle.bind(this);
34 this.createSvgLine = this.createSvgLine.bind(this);
35 this.createTextElement = this.createTextElement.bind(this);
36 this.createImageElement = this.createImageElement.bind(this);
37 this.createObjectElement = this.createObjectElement.bind(this);
38 this.createButtonElement = this.createButtonElement.bind(this);
39 this.applySvgAttributes = this.applySvgAttributes.bind(this);
40 this.applyTransform = this.applyTransform.bind(this);
43 setVisualElementMeta(metaObject) {
44 this.visualElementMeta = metaObject;
47 buildVisualElement(nodeProps, elementType, elementProps, index) {
48 let elementKey = nodeProps.id + index.toString();
49 switch (elementType) {
50 case NodeVisualElementConstants.SVG_CIRCLE:
51 return this.createSvgCircle(elementProps, elementKey);
53 case NodeVisualElementConstants.SVG_LINE:
54 return this.createSvgLine(elementProps, elementKey);
56 case NodeVisualElementConstants.TEXT:
57 return this.createTextElement(nodeProps, elementProps, elementKey);
59 case NodeVisualElementConstants.IMAGE:
60 return this.createImageElement(elementProps, elementKey);
62 case NodeVisualElementConstants.OBJECT:
63 return this.createObjectElement(elementProps, elementKey);
65 case NodeVisualElementConstants.BUTTON:
66 return this.createButtonElement(elementProps, elementKey);
68 case NodeVisualElementConstants.ICON:
69 return this.createButtonElement(elementProps, elementKey, nodeProps);
74 createSvgCircle(circleProps, elementKey) {
76 finalProps[NodeVisualElementConstants.CSS_CLASS] = circleProps.class;
78 finalProps = this.applyTransform(finalProps, circleProps.shapeAttributes);
79 finalProps = this.applySvgAttributes(finalProps, circleProps.svgAttributes);
86 return React.createElement(NodeVisualElementConstants.SVG_CIRCLE,
90 createSvgLine(lineProps, elementKey) {
92 /* Keep this commented code. Will be used again when
93 proper link construction is added
95 finalProps[NodeVisualElementConstants.CSS_CLASS] = lineProps.class;
96 finalProps = this.applySvgAttributes(finalProps, lineProps.svgAttributes);
97 finalProps = this.applyTransform(finalProps, lineProps.shapeAttributes);
105 return React.createElement(NodeVisualElementConstants.SVG_LINE, finalProps);
108 createTextElement(nodeProps, textProps, elementKey) {
110 finalProps[NodeVisualElementConstants.CSS_CLASS] = textProps.class;
112 finalProps = this.applySvgAttributes(finalProps, textProps.svgAttributes);
113 finalProps = this.applyTransform(finalProps, textProps.shapeAttributes);
120 return React.createElement(NodeVisualElementConstants.TEXT, finalProps,
121 nodeProps[textProps.displayKey]);
124 createImageElement(imageProps, elementKey) {
126 finalProps[NodeVisualElementConstants.CSS_CLASS] = imageProps.class;
128 finalProps = this.applyTransform(finalProps, imageProps.shapeAttributes);
129 finalProps = this.applySvgAttributes(finalProps, imageProps.svgAttributes);
136 return React.createElement(NodeVisualElementConstants.IMAGE, finalProps);
139 createObjectElement(objectProps, elementKey) {
141 finalProps[NodeVisualElementConstants.CSS_CLASS] = objectProps.class;
143 finalProps = this.applyTransform(finalProps, objectProps.shapeAttributes);
144 finalProps = this.applySvgAttributes(finalProps, objectProps.svgAttributes);
151 return React.createElement(NodeVisualElementConstants.OBJECT, finalProps);
154 createButtonElement(buttonProps, elementKey, nodeMeta) {
155 return IconFactory.createIcon(buttonProps.name, buttonProps, elementKey,
159 applySvgAttributes(elementProps, svgAttributes) {
169 applyTransform(elementProps, shapeAttributes) {
170 if (shapeAttributes) {
171 if (shapeAttributes.offset) {
174 transform: `translate(
175 ${shapeAttributes.offset.x},
176 ${shapeAttributes.offset.y})`
184 export default NodeVisualElementFactory;