2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software 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============================================
22 import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
23 import * as d3 from 'd3';
24 import { text } from 'd3';
27 selector: 'app-designer',
28 templateUrl: './designer.component.html',
29 styleUrls: ['./designer.component.scss']
31 export class DesignerComponent implements OnInit {
33 @ViewChild('svgArea') graphContainer: ElementRef;
43 this.dataForsimulation = {"nodes" :[],
48 d3.json("../../../../../assets/activation-blueprint.json")
51 this.buildD3DataNodes(data);
52 //this.buildD3DataLinks(data);
60 ngAfterContentInit() {
65 this.svg = d3.select('#svgArea')
66 .style('back-ground-color', 'white');
68 this.svgWidth = this.svg._groups[0][0].width.baseVal.value;
69 this.svgHeight = this.svg._groups[0][0].height.baseVal.value;
71 console.log('width', this.svgWidth);
78 let transformString = "translate(" + X + "," + Y + ")";
79 this.dataForsimulation.nodes.forEach((d, i)=> {
82 // xbyMath = Math.random() * ( this.svgWidth - 50 - 105 ) + ( 105/2 + 10 );
83 // ybyMath = Math.random() * ( this.svgWidth - 20 - 100 ) + ( 100/2 + 10 );
85 xbyMath = Math.floor(Math.random() * ((this.svgWidth-110) - 100 + 1)) + 100;
86 ybyMath = Math.floor(Math.random() * ((this.svgHeight-110) - 100 + 1)) + 100;
88 transformString = "translate(" + xbyMath + "," + ybyMath + ")";
91 let nodeTemprectId = gEleId+name
92 let requirement = gEleId+name+'requirement';
96 let firstg = d3.select('#g'+i)
97 .attr('transform', transformString);
107 .attr('fill', 'white')
108 .attr('stroke', 'black')
109 .attr('opacity', 0.6)
110 .on('mouseover', () => this.handleMouseOver());
115 firstg.append('rect')
121 .attr('fill', 'orange')
123 if(d.requirementsArray) {
124 d.requirementsArray.forEach(requirement =>{
125 firstg.append('rect')
126 .attr('id', d.name+requirement.name)
132 .attr('fill', 'blue')
133 requirement.x = xbyMath + 95;
134 requirement.y = ybyMath + 60;
138 if(d.capabilitiesArray) {
139 d.capabilitiesArray.forEach(capability =>{
140 firstg.append('rect')
141 .attr('id', d.name+capability.name)
147 .attr('fill', 'green');
148 capability.x = xbyMath + 95;
149 capability.y = ybyMath + 60;
154 firstg.append('text')
162 this.buildD3DataLinks();
165 buildD3DataNodes(data) {
167 d3data = data.topology_template.node_templates;
168 console.log('d3data:', d3data);
170 for (var property1 in d3data) {
171 d3data[property1].name = property1;
172 this.dataForsimulation.nodes.push(d3data[property1]);
173 finalData.push(d3data[property1]);
176 this.dataForsimulation.nodes.forEach(node => {
177 for( var nodeProperty in node) {
178 if(nodeProperty == 'requirements' || nodeProperty == 'capabilities') {
179 let arrayName = nodeProperty + 'Array';
180 node[arrayName] = [];
181 for(var reqProperty in node[nodeProperty]) {
182 node[nodeProperty][reqProperty].name = reqProperty;
183 node[arrayName].push(node[nodeProperty][reqProperty])
186 console.log('node array:', + node[arrayName]);
190 console.log( this.dataForsimulation);
196 this.dataForsimulation.nodes.forEach((node) => {
197 if(node.requirementsArray && node.requirementsArray.length > 0) {
198 node.requirementsArray.forEach(requirement => {
200 linkObject['sourceName'] = node.name + requirement.name;
201 linkObject['sourceid'] = node.name + requirement.name;
202 linkObject['sourceX'] = requirement.x;
203 linkObject['sourceY'] = requirement.y;
204 linkObject['targetNode'] = requirement.node;
205 linkObject['targetCapabilility'] = requirement.capability;
206 linkObject['ele'] = d3.select('#'+ linkObject['sourceid']);
207 this.dataForsimulation.links.push(linkObject);
212 this.capabilityTargets();
215 capabilityTargets() {
216 this.dataForsimulation.links.forEach(link=>{
217 this.dataForsimulation.nodes.forEach(node=>{
218 if(node.name == link.targetNode && node.capabilitiesArray) {
219 node.capabilitiesArray.forEach(capability=>{
220 if(capability.name == link.targetCapabilility) {
221 link['targetX'] = capability.x;
222 link['targetY'] = capability.y;
233 this.dataForsimulation.links.forEach(link=>{
234 this.svg.append('line')
235 .attr('x1', link.sourceX)
236 .attr('y1', link.sourceY)
237 .attr('x2', link.targetX)
238 .attr('y2', link.targetY)
239 .attr('stroke','gray')
240 .attr('stroke-width', 5);
245 console.log('mouse over');