Skip to content

Commit

Permalink
Replace KAOS goal model in risk model with Chernoff face (static for …
Browse files Browse the repository at this point in the history
…now)
  • Loading branch information
Shamal Faily committed Jan 23, 2017
1 parent 8660134 commit 12f1a35
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cairis/misc/EnvironmentModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def buildNode(self,dimName,objtName):
elif (dimName == 'component'):
self.theGraph.add_node(pydot.Node(objtName,shape='component',fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'requirement'):
self.theGraph.add_node(pydot.Node(objtName,shape='parallelogram',fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl))
self.theGraph.add_node(pydot.Node(objtName,shape='circle',fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'goal'):
self.theGraph.add_node(pydot.Node(objtName,shape='parallelogram',fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'obstacle'):
Expand Down
30 changes: 30 additions & 0 deletions cairis/web/dist/js/cairis/Cairis.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,35 @@ function getResponsibilityview(environment,role){
});
}

function replaceRequirementNodes(data) {

d3.select(data).selectAll('a').each(function(d) {
if ((d3.select(this).attr('xlink:href').indexOf('/api/requirements/shortcode') >= 0) && (d3.select(this).attr('xlink:title') != null)) {
// var txtY = d3.select(this).select('text').attr('y');
// d3.select(this).select('text').attr('y',txtY + 13);
var cxi = d3.select(this).select('ellipse').attr('cx');
var cyi = d3.select(this).select('ellipse').attr('cy');
var ri = d3.select(this).select('ellipse').attr('rx');
var reqLabel = d3.select(this).attr('xlink:title');
d3.select(this).select('ellipse').remove();
var svg = d3.select(this).attr("id","face" + reqLabel);
var c = d3.chernoff()
.xloc(function(d) { return d.cx; })
.yloc(function(d) { return d.cy; })
.frad(function(d) { return d.r; })
.mouth(function(d) { return d.m; })
.eyew(function(d) { return d.ew; })
.eyeh(function(d) { return d.eh; })
.brow(function(d) { return d.b; });
var dat = [{cx: cxi, cy: cyi, r: ri, m: 2, ew: 0.5, eh: 1.5, b: -2, face: svg}];

svg.selectAll("g.chernoff").data(dat).enter()
.append("svg:g")
.attr("class", "chernoff")
.call(c);
}
});
}

function getRiskview(environment,dimName,objtName,modelLayout){
window.assetEnvironment = environment;
Expand All @@ -529,6 +558,7 @@ function getRiskview(environment,dimName,objtName,modelLayout){
crossDomain: true,
url: serverIP + "/api/risks/model/environment/" + environment.replace(" ","%20"),
success: function(data){
replaceRequirementNodes(data);
fillSvgViewer(data);
},
error: function(xhr, textStatus, errorThrown) {
Expand Down
189 changes: 189 additions & 0 deletions cairis/web/dist/js/cairis/chernoff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/* Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
Authors: Shamal Faily
Based on Lars Kotthoff's 'Chernoff faces for D3' Block: http://bl.ocks.org/larskotthoff/2011590
*/

function sign(num) {
if(num > 0) {
return 1;
} else if(num < 0) {
return -1;
} else {
return 0;
}
}

function scale(v,f) {
return parseFloat((f/60) * v);
}

function d3_chernoff() {
var facef = 0, // 0 - 1
mouthf = 0, // -1 - 1
eyehf = 0.5, // 0 - 1
eyewf = 0.5, // 0 - 1
browf = 0, // -1 - 1
xf = 0,
yf = 0,
frf = 0,

line = d3.svg.line()
.interpolate("cardinal-closed")
.x(function(d) { return d.x; })
.y(function(d) { return d.y; }),
bline = d3.svg.line()
.interpolate("basis-closed")
.x(function(d) { return d.x; })
.y(function(d) { return d.y; });

function chernoff(a) {
if(a instanceof Array) {
a.each(__chernoff);
} else {
d3.select(this).each(__chernoff);
}
}

function __chernoff(d) {
var ele = d3.select(this),
xCoord = parseFloat(typeof(xf) === "function" ? xf(d) : xf),
yCoord = parseFloat(typeof(yf) === "function" ? yf(d) : yf),
fRad = parseFloat(typeof(frf) === "function" ? frf(d) : frf),
mouthvar = parseFloat(typeof(mouthf) === "function" ? mouthf(d) : mouthf) * 7,
nosehvar = 5,
nosewvar = 5,
eyehvar = parseFloat(typeof(eyehf) === "function" ? eyehf(d) : eyehf) * 10,
eyewvar = parseFloat(typeof(eyewf) === "function" ? eyewf(d) : eyewf) * 10,
browvar = parseFloat(typeof(browf) === "function" ? browf(d) : browf) * 3;

var face = d.face;
ele.selectAll("path.face").data([face]).enter()
.append("svg:ellipse")
.attr("class", "face")
.attr("fill","none")
.attr("stroke","black")
.attr("cx", xCoord)
.attr("cy", yCoord)
.attr("rx", fRad)
.attr("ry", fRad);

var mouth = [{x: parseFloat(xCoord), y: parseFloat(yCoord + scale(15 + mouthvar,fRad))}, //y+15
{x: parseFloat(xCoord + scale(40,fRad)), y: parseFloat(yCoord + scale(20 - mouthvar,fRad))}, //x+40,y+20
{x: parseFloat(xCoord), y: parseFloat(yCoord + scale(25 + mouthvar,fRad))}, //y+25
{x: parseFloat(xCoord - scale(40,fRad)), y: parseFloat(yCoord + scale(15 - mouthvar,fRad))}]; //x-40,y+15
ele.selectAll("path.mouth").data([mouth]).enter()
.append("svg:path")
.attr("class", "mouth")
.attr("fill","none")
.attr("stroke","black")
.attr("d", line);

var nose = [{x: parseFloat(xCoord + scale(nosewvar,fRad)), y: parseFloat(yCoord - scale(10 - nosehvar,fRad))},
{x: parseFloat(xCoord), y: parseFloat(yCoord - scale(10 + nosehvar,fRad))},
{x: parseFloat(xCoord - scale(nosewvar,fRad)), y: parseFloat(yCoord - scale(10 - nosehvar,fRad))}];
ele.selectAll("path.nose").data([nose]).enter()
.append("svg:path")
.attr("class", "nose")
.attr("fill","none")
.attr("stroke","black")
.attr("d", line);

var leye = [{x: parseFloat(xCoord - scale(15,fRad)), y: parseFloat(yCoord - scale(25 - eyehvar,fRad))}, {x: parseFloat(xCoord - scale(15 + eyewvar,fRad)), y: parseFloat(yCoord - scale(25,fRad))},
{x: parseFloat(xCoord - scale(15,fRad)), y: parseFloat(yCoord - scale(25 + eyehvar,fRad))}, {x: parseFloat(xCoord - scale(15 - eyewvar,fRad)), y: parseFloat(yCoord - scale(25,fRad))}];
var reye = [{x: parseFloat(xCoord + scale(15,fRad)), y: parseFloat(yCoord - scale(25 - eyehvar,fRad))}, {x: parseFloat(xCoord + scale(15 + eyewvar,fRad)), y: parseFloat(yCoord - scale(25,fRad))},
{x: parseFloat(xCoord + scale(15,fRad)), y: parseFloat(yCoord - scale(25 + eyehvar,fRad))}, {x: parseFloat(xCoord + scale(15 - eyewvar,fRad)), y: parseFloat(yCoord - scale(25,fRad))}];
ele.selectAll("path.leye").data([leye]).enter()
.append("svg:path")
.attr("class", "leye")
.attr("fill","none")
.attr("stroke","black")
.attr("d", bline);
ele.selectAll("path.reye").data([reye]).enter()
.append("svg:path")
.attr("class", "reye")
.attr("fill","none")
.attr("stroke","black")
.attr("d", bline);

ele.append("svg:path")
.attr("class", "lbrow")
.attr("fill","none")
.attr("stroke","black")
.attr("d", "M" + (parseFloat(xCoord - scale(15 - eyewvar/1.7 - sign(browvar),fRad))) + "," +
(parseFloat(yCoord - scale(60 - eyehvar + browvar,fRad))) + " " +
(parseFloat(xCoord - scale(15 + eyewvar/1.7 - sign(browvar),fRad))) + "," +
(parseFloat(yCoord - scale(60 - eyehvar - browvar,fRad))));
ele.append("svg:path")
.attr("class", "rbrow")
.attr("fill","none")
.attr("stroke","black")
.attr("d", "M" + (parseFloat(xCoord + scale(15 - eyewvar/1.7+ sign(browvar),fRad))) + "," +
(parseFloat(yCoord - scale(60 - eyehvar + browvar,fRad))) + " " +
(parseFloat(xCoord + scale(15 + eyewvar/1.7 + sign(browvar),fRad))) + "," +
(parseFloat(yCoord - scale(60 - eyehvar - browvar,fRad))));
}

chernoff.xloc = function(x) {
if(!arguments.length) return xf;
xf = x;
return chernoff;
};

chernoff.yloc = function(x) {
if(!arguments.length) return yf;
yf = x;
return chernoff;
};

chernoff.frad = function(x) {
if(!arguments.length) return frf;
frf = x;
return chernoff;
};

chernoff.mouth = function(x) {
if(!arguments.length) return mouthf;
mouthf = x;
return chernoff;
};

chernoff.eyeh = function(x) {
if(!arguments.length) return eyehf;
eyehf = x;
return chernoff;
};

chernoff.eyew = function(x) {
if(!arguments.length) return eyewf;
eyewf = x;
return chernoff;
};

chernoff.brow = function(x) {
if(!arguments.length) return browf;
browf = x;
return chernoff;
};

return chernoff;
}

d3.chernoff = function() {
return d3_chernoff(Object);
};
3 changes: 1 addition & 2 deletions cairis/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<script src="plugins/d3/nv.d3.min.js"></script>



<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
Expand Down Expand Up @@ -816,7 +815,7 @@ <h4 class="modal-title">Add Interface</h4>
<script>
LazyLoad.js(["dist/js/cairis/Cairis-UI.js","dist/js/cairis/buttonclicks.js", "dist/js/cairis/Cairis.js", "dist/js/cairis/readFile.js",
"dist/js/cairis/threats.js", "dist/js/cairis/attackers.js", "dist/js/cairis/personas.js", "dist/js/cairis/assets.js", "dist/js/cairis/templateassets.js","dist/js/cairis/templaterequirements.js","dist/js/cairis/templategoals.js","dist/js/cairis/goals.js", "dist/js/cairis/projectSettings.js", "dist/js/cairis/tasks.js", "dist/js/cairis/domainproperties.js", "dist/js/cairis/obstacles.js", "dist/js/cairis/countermeasures.js", "dist/js/cairis/usecases.js","dist/js/cairis/vulnerabilities.js","dist/js/cairis/architecturalpatterns.js","dist/js/cairis/requirements.js",
"dist/js/cairis/risks.js", "dist/js/cairis/fileImport.js", "dist/js/cairis/fileExport.js", "dist/js/cairis/responses.js","dist/js/cairis/dependencies.js","dist/js/cairis/genDoc.js","dist/js/cairis/findobjt.js","dist/js/cairis/externaldocuments.js","dist/js/cairis/documentreferences.js","dist/js/cairis/personacharacteristics.js","dist/js/cairis/homeSettings.js","dist/js/cairis/roles.js","dist/js/cairis/environments.js","dist/js/cairis/valuetypes.js","dist/js/cairis/locations.js","dist/js/cairis/traceability.js",
"dist/js/cairis/risks.js", "dist/js/cairis/fileImport.js", "dist/js/cairis/fileExport.js", "dist/js/cairis/responses.js","dist/js/cairis/dependencies.js","dist/js/cairis/genDoc.js","dist/js/cairis/findobjt.js","dist/js/cairis/externaldocuments.js","dist/js/cairis/documentreferences.js","dist/js/cairis/personacharacteristics.js","dist/js/cairis/homeSettings.js","dist/js/cairis/roles.js","dist/js/cairis/environments.js","dist/js/cairis/valuetypes.js","dist/js/cairis/locations.js","dist/js/cairis/traceability.js","dist/js/cairis/chernoff.js",
"dist/js/cairis/SVGhandler.js","dist/js/objects/jsonDefaultObjects.js"], function () {

console.log("All Cairis JS loaded");
Expand Down

0 comments on commit 12f1a35

Please sign in to comment.