mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-10 07:05:35 +00:00
Linting fixes
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
angular.module('app').directive('areaChart', ['$window', function ($window) {
|
||||
|
||||
|
||||
angular.module('app').directive('areaChart', ['$window', function($window) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope:{
|
||||
scope: {
|
||||
config: '=',
|
||||
series: '='
|
||||
},
|
||||
@@ -11,64 +9,64 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
||||
var series = scope.series,
|
||||
config = scope.config,
|
||||
labels = config.labels,
|
||||
margin = {top: 15, right: 15, bottom: 35, left: 60},
|
||||
margin = { top: 15, right: 15, bottom: 35, left: 60 },
|
||||
fmt = d3.format('.3r'),
|
||||
fmtLong = d3.format('.2f'),
|
||||
func = series.func,
|
||||
drag = d3.behavior.drag(),
|
||||
dragging = false,
|
||||
// Define Axes
|
||||
xAxis = d3.svg.axis().outerTickSize(0).orient("bottom").tickFormat(d3.format('.2r')),
|
||||
yAxis = d3.svg.axis().ticks(6).outerTickSize(0).orient("left").tickFormat(fmt),
|
||||
xAxis = d3.svg.axis().outerTickSize(0).orient('bottom').tickFormat(d3.format('.2r')),
|
||||
yAxis = d3.svg.axis().ticks(6).outerTickSize(0).orient('left').tickFormat(fmt),
|
||||
x = d3.scale.linear(),
|
||||
y = d3.scale.linear();
|
||||
|
||||
// Create chart
|
||||
var svg = d3.select(element[0]).append("svg");
|
||||
var vis = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||
var svg = d3.select(element[0]).append('svg');
|
||||
var vis = svg.append('g').attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
||||
|
||||
// Define Area
|
||||
var area = d3.svg.area();
|
||||
|
||||
var gradient = vis.append("defs")
|
||||
.append("linearGradient")
|
||||
.attr("id", "gradient")
|
||||
.attr("x1", "0%").attr("y1", "0%")
|
||||
.attr("x2", "100%").attr("y2", "100%")
|
||||
.attr("spreadMethod", "pad");
|
||||
gradient.append("stop")
|
||||
.attr("offset", "0%")
|
||||
.attr("stop-color", "#ff8c0d")
|
||||
.attr("stop-opacity", 1);
|
||||
gradient.append("stop")
|
||||
.attr("offset", "100%")
|
||||
.attr("stop-color", "#ff3b00")
|
||||
.attr("stop-opacity", 1);
|
||||
var gradient = vis.append('defs')
|
||||
.append('linearGradient')
|
||||
.attr('id', 'gradient')
|
||||
.attr('x1', '0%').attr('y1', '0%')
|
||||
.attr('x2', '100%').attr('y2', '100%')
|
||||
.attr('spreadMethod', 'pad');
|
||||
gradient.append('stop')
|
||||
.attr('offset', '0%')
|
||||
.attr('stop-color', '#ff8c0d')
|
||||
.attr('stop-opacity', 1);
|
||||
gradient.append('stop')
|
||||
.attr('offset', '100%')
|
||||
.attr('stop-color', '#ff3b00')
|
||||
.attr('stop-opacity', 1);
|
||||
|
||||
// Create Y Axis SVG Elements
|
||||
var yTxt = vis.append("g").attr("class", "y axis")
|
||||
.append("text")
|
||||
.attr("transform", "rotate(-90)")
|
||||
.attr("y", -50)
|
||||
.attr("dy", ".1em")
|
||||
.style("text-anchor", "middle")
|
||||
var yTxt = vis.append('g').attr('class', 'y axis')
|
||||
.append('text')
|
||||
.attr('transform', 'rotate(-90)')
|
||||
.attr('y', -50)
|
||||
.attr('dy', '.1em')
|
||||
.style('text-anchor', 'middle')
|
||||
.text(labels.yAxis.title + ' (' + labels.yAxis.unit + ')');
|
||||
// Create X Axis SVG Elements
|
||||
var xLbl = vis.append("g").attr("class", "x axis");
|
||||
var xTxt = xLbl.append("text")
|
||||
.attr("y", 30)
|
||||
.attr("dy", ".1em")
|
||||
.style("text-anchor", "middle")
|
||||
var xLbl = vis.append('g').attr('class', 'x axis');
|
||||
var xTxt = xLbl.append('text')
|
||||
.attr('y', 30)
|
||||
.attr('dy', '.1em')
|
||||
.style('text-anchor', 'middle')
|
||||
.text(labels.xAxis.title + ' (' + labels.xAxis.unit + ')');
|
||||
|
||||
// Create and Add tooltip
|
||||
var tip = vis.append("g").style("display", "none");
|
||||
tip.append("rect").attr("width","4em").attr("height", "2em").attr("x", "0.5em").attr("y","-1em").attr("class","tip");
|
||||
tip.append("circle")
|
||||
.attr("class", "marker")
|
||||
.attr("r", 4);
|
||||
tip.append("text").attr("class", 'label x').attr("y", "-0.25em");
|
||||
tip.append("text").attr("class", 'label y').attr("y", '0.85em');
|
||||
var tip = vis.append('g').style('display', 'none');
|
||||
tip.append('rect').attr('width', '4em').attr('height', '2em').attr('x', '0.5em').attr('y', '-1em').attr('class', 'tip');
|
||||
tip.append('circle')
|
||||
.attr('class', 'marker')
|
||||
.attr('r', 4);
|
||||
tip.append('text').attr('class', 'label x').attr('y', '-0.25em');
|
||||
tip.append('text').attr('class', 'label y').attr('y', '0.85em');
|
||||
|
||||
/**
|
||||
* Watch for changes in the series data (mass changes, etc)
|
||||
@@ -87,35 +85,35 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
||||
var yVal = func(series.xMin);
|
||||
data.push([ series.xMin, yVal ]);
|
||||
data.push([ series.xMin, yVal ]);
|
||||
area.x(function(d,i) { return i * w; }).y0(h).y1(function(d) { return y(d[1]); });
|
||||
area.x(function(d, i) { return i * w; }).y0(h).y1(function(d) { return y(d[1]); });
|
||||
} else {
|
||||
for (var d = series.xMin; d <= series.xMax; d += 1) {
|
||||
data.push([ d, func(d) ]);
|
||||
for (var val = series.xMin; val <= series.xMax; val += 1) {
|
||||
data.push([ val, func(val) ]);
|
||||
}
|
||||
area.x(function(d) { return x(d[0]); }).y0(h).y1(function(d) { return y(d[1]); });
|
||||
}
|
||||
|
||||
// Update Chart Size
|
||||
svg.attr("width", width).attr("height", height);
|
||||
svg.attr('width', width).attr('height', height);
|
||||
// Update domain and scale for axes;
|
||||
x.range([0, w]).domain([series.xMin, series.xMax]).clamp(true);
|
||||
xAxis.scale(x);
|
||||
xLbl.attr("transform", "translate(0," + h + ")");
|
||||
xTxt.attr("x", w/2);
|
||||
xLbl.attr('transform', 'translate(0,' + h + ')');
|
||||
xTxt.attr('x', w / 2);
|
||||
y.range([h, 0]).domain([series.yMin, series.yMax]);
|
||||
yAxis.scale(y);
|
||||
yTxt.attr("x", -h/2);
|
||||
vis.selectAll(".y.axis").call(yAxis);
|
||||
vis.selectAll(".x.axis").call(xAxis);
|
||||
yTxt.attr('x', -h / 2);
|
||||
vis.selectAll('.y.axis').call(yAxis);
|
||||
vis.selectAll('.x.axis').call(xAxis);
|
||||
|
||||
// Remove existing elements
|
||||
vis.selectAll('path.area').remove();
|
||||
|
||||
vis.insert("path",':first-child') // Area/Path to appear behind everything else
|
||||
vis.insert('path', ':first-child') // Area/Path to appear behind everything else
|
||||
.datum(data)
|
||||
.attr("class", "area")
|
||||
.attr('class', 'area')
|
||||
.attr('fill', 'url(#gradient)')
|
||||
.attr("d", area)
|
||||
.attr('d', area)
|
||||
.on('mouseover', showTip)
|
||||
.on('mouseout', hideTip)
|
||||
.on('mousemove', moveTip)
|
||||
@@ -127,7 +125,7 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
||||
moveTip.call(this);
|
||||
showTip();
|
||||
})
|
||||
.on("dragend", function() {
|
||||
.on('dragend', function() {
|
||||
dragging = false;
|
||||
hideTip();
|
||||
})
|
||||
@@ -135,20 +133,20 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
||||
}
|
||||
|
||||
function showTip() {
|
||||
tip.style("display", null);
|
||||
tip.style('display', null);
|
||||
}
|
||||
|
||||
function hideTip() {
|
||||
if (!dragging) {
|
||||
tip.style("display", "none");
|
||||
tip.style('display', 'none');
|
||||
}
|
||||
}
|
||||
|
||||
function moveTip() {
|
||||
var xPos = d3.mouse(this)[0], x0 = x.invert(xPos), y0 = func(x0), flip = (x0 / x.domain()[1] > 0.75);
|
||||
tip.attr("transform", "translate(" + x(x0) + "," + y(y0) + ")");
|
||||
tip.selectAll('rect').attr("x", flip? '-4.5em' : "0.5em").style("text-anchor", flip? 'end' : 'start');
|
||||
tip.selectAll('text.label').attr("x", flip? "-1em" : "1em").style("text-anchor", flip? 'end' : 'start');
|
||||
tip.attr('transform', 'translate(' + x(x0) + ',' + y(y0) + ')');
|
||||
tip.selectAll('rect').attr('x', flip ? '-4.5em' : '0.5em').style('text-anchor', flip ? 'end' : 'start');
|
||||
tip.selectAll('text.label').attr('x', flip ? '-1em' : '1em').style('text-anchor', flip ? 'end' : 'start');
|
||||
tip.select('text.label.x').text(fmtLong(x0) + ' ' + labels.xAxis.unit);
|
||||
tip.select('text.label.y').text(fmtLong(y0) + ' ' + labels.yAxis.unit);
|
||||
}
|
||||
@@ -159,4 +157,4 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
||||
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
angular.module('app').directive('barChart', ['$window', function ($window) {
|
||||
angular.module('app').directive('barChart', ['$window', function($window) {
|
||||
|
||||
function bName (build) {
|
||||
function bName(build) {
|
||||
return build.buildName + '\n' + build.name;
|
||||
}
|
||||
|
||||
var insertLinebreaks = function (d) {
|
||||
function insertLinebreaks(d) {
|
||||
var el = d3.select(this);
|
||||
var words = d.split('\n');
|
||||
el.text('').attr('y', -6);
|
||||
@@ -14,11 +14,11 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
||||
tspan.attr('x', -9).attr('dy', 12);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope:{
|
||||
scope: {
|
||||
data: '=',
|
||||
facet: '='
|
||||
},
|
||||
@@ -28,7 +28,7 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
||||
fmt = scope.facet.fmt,
|
||||
properties = scope.facet.props,
|
||||
unit = scope.facet.unit,
|
||||
margin = {top: 10, right: 20, bottom: 35, left: 150},
|
||||
margin = { top: 10, right: 20, bottom: 35, left: 150 },
|
||||
y0 = d3.scale.ordinal(),
|
||||
y1 = d3.scale.ordinal(),
|
||||
x = d3.scale.linear(),
|
||||
@@ -43,7 +43,7 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
||||
var tip = d3.tip()
|
||||
.attr('class', 'd3-tip')
|
||||
.html(function(property, propertyIndex) {
|
||||
return (labels? (labels[propertyIndex] + ': ') : '') + fmt(property.value) + ' ' + unit;
|
||||
return (labels ? (labels[propertyIndex] + ': ') : '') + fmt(property.value) + ' ' + unit;
|
||||
});
|
||||
|
||||
vis.call(tip);
|
||||
@@ -52,13 +52,13 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
||||
vis.append('g').attr('class', 'y axis');
|
||||
vis.selectAll('g.y.axis g text').each(insertLinebreaks);
|
||||
// Create X Axis SVG Elements
|
||||
var xAxisLbl = vis.append('g')
|
||||
var xAxisLbl = vis.append('g')
|
||||
.attr('class', 'x axis')
|
||||
.append('text')
|
||||
.attr('y', 30)
|
||||
.attr('dy', '.1em')
|
||||
.style('text-anchor', 'middle')
|
||||
.text(scope.facet.title + (unit? (' (' + unit + ')') : ''));
|
||||
.text(scope.facet.title + (unit ? (' (' + unit + ')') : ''));
|
||||
|
||||
|
||||
/**
|
||||
@@ -84,11 +84,11 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
||||
|
||||
// Update X & Y Axis
|
||||
x.range([0, w]).domain([0, maxVal]);
|
||||
y0.domain(data.map(bName)).rangeRoundBands([0, h],0.3);
|
||||
y0.domain(data.map(bName)).rangeRoundBands([0, h], 0.3);
|
||||
y1.domain(properties).rangeRoundBands([0, y0.rangeBand()]);
|
||||
vis.selectAll('.y.axis').call(yAxis);
|
||||
vis.selectAll('.x.axis').attr('transform', 'translate(0,' + h + ')').call(xAxis);
|
||||
xAxisLbl.attr('x', w/2);
|
||||
xAxisLbl.attr('x', w / 2);
|
||||
// Update Y-Axis labels
|
||||
vis.selectAll('g.y.axis g text').each(insertLinebreaks);
|
||||
|
||||
@@ -102,13 +102,13 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
||||
.data(function(build) {
|
||||
var o = [];
|
||||
for (var i = 0; i < properties.length; i++) {
|
||||
o.push({name: properties[i], value:build[properties[i]]});
|
||||
o.push({ name: properties[i], value: build[properties[i]] });
|
||||
}
|
||||
return o;
|
||||
})
|
||||
.enter().append('rect')
|
||||
.attr('height', y1.rangeBand())
|
||||
.attr('x',0)
|
||||
.attr('x', 0)
|
||||
.attr('y', function(d) {return y1(d.name); })
|
||||
.attr('width', function(d) { return x(d.value); })
|
||||
.on('mouseover', tip.show)
|
||||
@@ -124,4 +124,4 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
||||
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module('app').directive('comparisonTable', ['$state', function ($state) {
|
||||
angular.module('app').directive('comparisonTable', ['$state', function($state) {
|
||||
|
||||
function tblHeader(facets) {
|
||||
var r1 = ['<tr class="main"><th rowspan="2" class="prop" prop="name">Ship</th><th rowspan="2" class="prop" prop="buildName">Build</th>'];
|
||||
@@ -8,17 +8,17 @@ angular.module('app').directive('comparisonTable', ['$state', function ($state)
|
||||
var f = facets[i];
|
||||
var p = f.props;
|
||||
var pl = p.length;
|
||||
r1.push('<th rowspan="', f.props.length == 1 ? 2 : 1,'" colspan="',pl,'"');
|
||||
r1.push('<th rowspan="', f.props.length == 1 ? 2 : 1, '" colspan="', pl, '"');
|
||||
|
||||
if (pl == 1) {
|
||||
r1.push(' prop="',p[0],'" class="prop"');
|
||||
r1.push(' prop="', p[0], '" class="prop"');
|
||||
} else {
|
||||
for (var j = 0; j < pl; j++) {
|
||||
r2.push('<th prop="', p[j], '" class="prop ', j === 0? 'lft' : '', ' ">' , f.lbls[j], '</th>');
|
||||
r2.push('<th prop="', p[j], '" class="prop ', j === 0 ? 'lft' : '', '">', f.lbls[j], '</th>');
|
||||
}
|
||||
}
|
||||
|
||||
r1.push('>', f.title ,'</th>');
|
||||
r1.push('>', f.title, '</th>');
|
||||
}
|
||||
}
|
||||
r1.push('</tr><tr>');
|
||||
@@ -30,16 +30,16 @@ angular.module('app').directive('comparisonTable', ['$state', function ($state)
|
||||
function tblBody(facets, builds) {
|
||||
var body = [];
|
||||
|
||||
if(builds.length === 0) {
|
||||
if (builds.length === 0) {
|
||||
return '<td colspan="100" class="cen">No builds added to comparison!</td';
|
||||
}
|
||||
|
||||
for (var i = 0, l = builds.length; i < l; i++) {
|
||||
var b = builds[i];
|
||||
body.push('<tr class="tr">');
|
||||
var href = $state.href('outfit',{shipId: b.id, code: b.code, bn: b.buildName});
|
||||
body.push('<td class="tl"><a href="', href,'">', b.name,'</a></td>');
|
||||
body.push('<td class="tl"><a href="', href,'">', b.buildName,'</a></td>');
|
||||
var href = $state.href('outfit', { shipId: b.id, code: b.code, bn: b.buildName });
|
||||
body.push('<td class="tl"><a href="', href, '">', b.name, '</a></td>');
|
||||
body.push('<td class="tl"><a href="', href, '">', b.buildName, '</a></td>');
|
||||
|
||||
for (var j = 0, fl = facets.length; j < fl; j++) {
|
||||
if (facets[j].active) {
|
||||
@@ -59,13 +59,13 @@ angular.module('app').directive('comparisonTable', ['$state', function ($state)
|
||||
return {
|
||||
restrict: 'A',
|
||||
|
||||
link: function (scope, element) {
|
||||
link: function(scope, element) {
|
||||
var header = angular.element('<thead></thead>');
|
||||
var body = angular.element('<tbody></tbody>');
|
||||
element.append(header);
|
||||
element.append(body);
|
||||
|
||||
var updateAll = function (){
|
||||
var updateAll = function() {
|
||||
header.html(tblHeader(scope.facets));
|
||||
body.html(tblBody(scope.facets, scope.builds));
|
||||
};
|
||||
@@ -77,4 +77,4 @@ angular.module('app').directive('comparisonTable', ['$state', function ($state)
|
||||
});
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module('app').directive('componentSelect', function () {
|
||||
angular.module('app').directive('componentSelect', function() {
|
||||
|
||||
// Generting the HTML in this manner is MUCH faster than using an angular template.
|
||||
|
||||
@@ -8,42 +8,42 @@ angular.module('app').directive('componentSelect', function () {
|
||||
var o = opts[i];
|
||||
var id = o.id || (o.class + o.rating); // Common components' ID is their class and rating
|
||||
|
||||
if(i > 0 && opts.length > 3 && o.class != prevClass && (!o.grp || o.rating != prevRating || o.mode)) {
|
||||
if (i > 0 && opts.length > 3 && o.class != prevClass && (!o.grp || o.rating != prevRating || o.mode)) {
|
||||
list.push('<br/>');
|
||||
}
|
||||
|
||||
list.push('<li class="', o.name? 'lc' : 'c');
|
||||
list.push('<li class="', o.name ? 'lc' : 'c');
|
||||
|
||||
if (cid == id) {
|
||||
list.push(' active');
|
||||
}
|
||||
|
||||
list.push((o.maxmass && mass > o.maxmass)? ' disabled"' : '" cpid="', id, '">');
|
||||
list.push((o.maxmass && mass > o.maxmass) ? ' disabled"' : '" cpid="', id, '">');
|
||||
|
||||
if(o.mode) {
|
||||
list.push('<svg cpid="', id, '" class="icon lg"><use xlink:href="#mount-', o.mode , '"></use></svg> ');
|
||||
if (o.mode) {
|
||||
list.push('<svg cpid="', id, '" class="icon lg"><use xlink:href="#mount-', o.mode, '"></use></svg> ');
|
||||
}
|
||||
|
||||
list.push(o.class, o.rating);
|
||||
|
||||
if(o.missile) {
|
||||
if (o.missile) {
|
||||
list.push('/' + o.missile);
|
||||
}
|
||||
|
||||
|
||||
if(o.name) {
|
||||
if (o.name) {
|
||||
list.push(' ' + o.name);
|
||||
}
|
||||
|
||||
list.push('</li>');
|
||||
prevClass = o.class;
|
||||
prevRating= o.rating;
|
||||
prevRating = o.rating;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope:{
|
||||
scope: {
|
||||
opts: '=', // Component Options object
|
||||
groups: '=', // Groups of Component Options
|
||||
mass: '=', // Current ship unladen mass
|
||||
@@ -57,13 +57,13 @@ angular.module('app').directive('componentSelect', function () {
|
||||
var groups = scope.groups;
|
||||
var mass = scope.mass || 0;
|
||||
|
||||
if(groups) {
|
||||
if (groups) {
|
||||
// At present time slots with grouped options (Hardpoints and Internal) can be empty
|
||||
list.push('<div class="empty-c" cpid="empty">EMPTY</div>');
|
||||
for (var g in groups) {
|
||||
var grp = groups[g];
|
||||
var grpCode = grp[Object.keys(grp)[0]].grp; // Nasty operation to get the grp property of the first/any single component
|
||||
list.push('<div id="', grpCode ,'" class="select-group">', g, '</div><ul>');
|
||||
list.push('<div id="', grpCode, '" class="select-group">', g, '</div><ul>');
|
||||
appendGroup(list, grp, cid, mass);
|
||||
list.push('</ul>');
|
||||
}
|
||||
@@ -77,9 +77,9 @@ angular.module('app').directive('componentSelect', function () {
|
||||
// If groups are present and a component is already selectd
|
||||
if (groups && component && component.grp) {
|
||||
var groupElement = angular.element(document.getElementById(component.grp));
|
||||
var parentElem = element[0].parentElement;
|
||||
var parentElem = element[0].parentElement;
|
||||
parentElem.scrollTop = groupElement[0].offsetTop; // Scroll to currently selected group
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Persist', 'ShipsDB', function (_, $rootScope, Persist, ships) {
|
||||
angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Persist', 'ShipsDB', function(_, $rootScope, Persist, ships) {
|
||||
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: 'views/_header.html',
|
||||
scope: true,
|
||||
link: function (scope) {
|
||||
link: function(scope) {
|
||||
scope.openedMenu = null;
|
||||
scope.ships = ships;
|
||||
scope.allBuilds = Persist.builds;
|
||||
@@ -15,22 +15,22 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
||||
// Insurance options and management here for now.
|
||||
$rootScope.insurance = {
|
||||
opts: [
|
||||
{ name:'Standard', pct: 0.05 },
|
||||
{ name:'Alpha', pct: 0.025 },
|
||||
{ name:'Beta', pct: 0.035 }
|
||||
{ name: 'Standard', pct: 0.05 },
|
||||
{ name: 'Alpha', pct: 0.025 },
|
||||
{ name: 'Beta', pct: 0.035 }
|
||||
]
|
||||
};
|
||||
|
||||
var insIndex = _.findIndex($rootScope.insurance.opts, 'name', Persist.getInsurance());
|
||||
$rootScope.insurance.current = $rootScope.insurance.opts[insIndex != -1? insIndex : 0];
|
||||
$rootScope.insurance.current = $rootScope.insurance.opts[insIndex != -1 ? insIndex : 0];
|
||||
|
||||
// Close menus if a navigation change event occurs
|
||||
$rootScope.$on('$stateChangeStart',function(){
|
||||
$rootScope.$on('$stateChangeStart', function() {
|
||||
scope.openedMenu = null;
|
||||
});
|
||||
|
||||
// Listen to close event to close opened menus or modals
|
||||
$rootScope.$on('close', function () {
|
||||
$rootScope.$on('close', function() {
|
||||
scope.openedMenu = null;
|
||||
$rootScope.showAbout = false;
|
||||
});
|
||||
@@ -38,13 +38,13 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
||||
/**
|
||||
* Save selected insurance option
|
||||
*/
|
||||
scope.updateInsurance = function(){
|
||||
scope.updateInsurance = function() {
|
||||
Persist.setInsurance($rootScope.insurance.current.name);
|
||||
};
|
||||
|
||||
scope.openMenu = function (e, menu) {
|
||||
scope.openMenu = function(e, menu) {
|
||||
e.stopPropagation();
|
||||
if(menu == scope.openedMenu) {
|
||||
if (menu == scope.openedMenu) {
|
||||
scope.openedMenu = null;
|
||||
return;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
||||
$rootScope.showAbout = true;
|
||||
};
|
||||
|
||||
$rootScope.hideAbout = function (){
|
||||
$rootScope.hideAbout = function() {
|
||||
$rootScope.showAbout = false;
|
||||
};
|
||||
|
||||
@@ -72,4 +72,4 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
||||
});
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
angular.module('app').directive('powerBands', ['$window', function ($window) {
|
||||
angular.module('app').directive('powerBands', ['$window', function($window) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope:{
|
||||
scope: {
|
||||
bands: '=',
|
||||
available: '='
|
||||
},
|
||||
link: function(scope, element) {
|
||||
var margin = {top: 20, right: 130, bottom: 20, left: 40},
|
||||
var margin = { top: 20, right: 130, bottom: 20, left: 40 },
|
||||
barHeight = 20,
|
||||
innerHeight = (barHeight * 2) + 3,
|
||||
height = innerHeight + margin.top + margin.bottom + 1,
|
||||
@@ -25,11 +25,11 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
||||
// Create Y Axis SVG Elements
|
||||
vis.append('g').attr('class', 'watt axis');
|
||||
vis.append('g').attr('class', 'pct axis');
|
||||
vis.append("text").attr('x', -35).attr('y', 16).attr('class','primary').text('RET');
|
||||
vis.append("text").attr('x', -35).attr('y', barHeight + 18).attr('class','primary').text('DEP');
|
||||
vis.append('text').attr('x', -35).attr('y', 16).attr('class', 'primary').text('RET');
|
||||
vis.append('text').attr('x', -35).attr('y', barHeight + 18).attr('class', 'primary').text('DEP');
|
||||
|
||||
var retLbl = vis.append("text").attr('y', 16);
|
||||
var depLbl = vis.append("text").attr('y', barHeight + 18);
|
||||
var retLbl = vis.append('text').attr('y', 16);
|
||||
var depLbl = vis.append('text').attr('y', barHeight + 18);
|
||||
|
||||
// Watch for changes to data and events
|
||||
scope.$watchCollection('available', render);
|
||||
@@ -61,40 +61,41 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
||||
|
||||
retLbl
|
||||
.attr('x', w + 5 )
|
||||
.attr('class',maxBand.retractedSum > available? 'warning': 'primary')
|
||||
.text(wattFmt(Math.max(0,maxBand.retractedSum)) + ' (' + pctFmt(Math.max(0,maxBand.retractedSum / available)) + ')');
|
||||
.attr('class', maxBand.retractedSum > available ? 'warning' : 'primary')
|
||||
.text(wattFmt(Math.max(0, maxBand.retractedSum)) + ' (' + pctFmt(Math.max(0, maxBand.retractedSum / available)) + ')');
|
||||
|
||||
depLbl
|
||||
.attr('x', w + 5 )
|
||||
.attr('class',maxBand.deployedSum > available? 'warning': 'primary')
|
||||
.text(wattFmt(Math.max(0,maxBand.deployedSum)) + ' (' + pctFmt(Math.max(0,maxBand.deployedSum / available)) + ')');
|
||||
.attr('class', maxBand.deployedSum > available ? 'warning' : 'primary')
|
||||
.text(wattFmt(Math.max(0, maxBand.deployedSum)) + ' (' + pctFmt(Math.max(0, maxBand.deployedSum / available)) + ')');
|
||||
|
||||
retracted.selectAll("rect").data(bands).enter().append("rect")
|
||||
.attr("height", barHeight)
|
||||
.attr("width", function(d) { return Math.max(wattScale(d.retracted) - 1, 0); })
|
||||
.attr("x", function(d) { return wattScale(d.retractedSum) - wattScale(d.retracted); })
|
||||
retracted.selectAll('rect').data(bands).enter().append('rect')
|
||||
.attr('height', barHeight)
|
||||
.attr('width', function(d) { return Math.max(wattScale(d.retracted) - 1, 0); })
|
||||
.attr('x', function(d) { return wattScale(d.retractedSum) - wattScale(d.retracted); })
|
||||
.attr('y', 1)
|
||||
.attr('class',function(d){ return (d.retractedSum > available)? 'warning' :'primary'; });
|
||||
.attr('class', function(d) { return (d.retractedSum > available) ? 'warning' : 'primary'; });
|
||||
|
||||
retracted.selectAll("text").data(bands).enter().append("text")
|
||||
retracted.selectAll('text').data(bands).enter().append('text')
|
||||
.attr('x', function(d) { return wattScale(d.retractedSum) - (wattScale(d.retracted) / 2); })
|
||||
.attr('y', 15)
|
||||
.style('text-anchor', 'middle')
|
||||
.attr('class','primary-bg')
|
||||
.text(function(d,i) { return bandText(d.retracted, i); });
|
||||
.attr('class', 'primary-bg')
|
||||
.text(function(d, i) { return bandText(d.retracted, i); });
|
||||
|
||||
deployed.selectAll("rect").data(bands).enter().append("rect")
|
||||
.attr("height", barHeight)
|
||||
.attr("width", function(d) { return Math.max(wattScale(d.deployed + d.retracted) - 1, 0); })
|
||||
.attr("x", function(d) { return wattScale(d.deployedSum) - wattScale(d.retracted) - wattScale(d.deployed); })
|
||||
deployed.selectAll('rect').data(bands).enter().append('rect')
|
||||
.attr('height', barHeight)
|
||||
.attr('width', function(d) { return Math.max(wattScale(d.deployed + d.retracted) - 1, 0); })
|
||||
.attr('x', function(d) { return wattScale(d.deployedSum) - wattScale(d.retracted) - wattScale(d.deployed); })
|
||||
.attr('y', barHeight + 2)
|
||||
.attr('class',function(d){ return (d.deployedSum > available)? 'warning' :'primary'; });
|
||||
.attr('class', function(d) { return (d.deployedSum > available) ? 'warning' : 'primary'; });
|
||||
|
||||
deployed.selectAll("text").data(bands).enter().append("text")
|
||||
deployed.selectAll('text').data(bands).enter().append('text')
|
||||
.attr('x', function(d) { return wattScale(d.deployedSum) - ((wattScale(d.retracted) + wattScale(d.deployed)) / 2); })
|
||||
.attr('y', barHeight + 17)
|
||||
.style('text-anchor', 'middle')
|
||||
.attr('class','primary-bg')
|
||||
.text(function(d,i) { return bandText(d.deployed + d.retracted, i); });
|
||||
.attr('class', 'primary-bg')
|
||||
.text(function(d, i) { return bandText(d.deployed + d.retracted, i); });
|
||||
|
||||
}
|
||||
|
||||
@@ -110,4 +111,4 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
||||
});
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
angular.module('app').directive('slider', ['$window', function ($window) {
|
||||
angular.module('app').directive('slider', ['$window', function($window) {
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope:{
|
||||
scope: {
|
||||
max: '=',
|
||||
unit: '=',
|
||||
change: '&onChange'
|
||||
},
|
||||
link: function(scope, element) {
|
||||
var margin = {top: -10, right: 140, bottom: 0, left: 50},
|
||||
var margin = { top: -10, right: 140, bottom: 0, left: 50 },
|
||||
height = 40, // Height is fixed
|
||||
h = height - margin.top - margin.bottom,
|
||||
fmt = d3.format('.2f'),
|
||||
pct = d3.format('.1%'),
|
||||
unit = scope.unit,
|
||||
val = scope.max,
|
||||
svg = d3.select(element[0]).append("svg"),
|
||||
vis = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"),
|
||||
xAxis = vis.append("g").attr("class", "x slider-axis").attr("transform", "translate(0," + h / 2 + ")"),
|
||||
svg = d3.select(element[0]).append('svg'),
|
||||
vis = svg.append('g').attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'),
|
||||
xAxis = vis.append('g').attr('class', 'x slider-axis').attr('transform', 'translate(0,' + h / 2 + ')'),
|
||||
x = d3.scale.linear(),
|
||||
slider = vis.append("g").attr("class", "slider"),
|
||||
filled = slider.append('path').attr('class', 'filled').attr("transform", "translate(0," + h/2 + ")"),
|
||||
brush = d3.svg.brush().x(x).extent([scope.max, scope.max]).on("brush", brushed),
|
||||
handle = slider.append("circle").attr("class", "handle").attr("r", '0.6em'),
|
||||
lbl = slider.append("g").append("text").attr("y", h/2);
|
||||
slider = vis.append('g').attr('class', 'slider'),
|
||||
filled = slider.append('path').attr('class', 'filled').attr('transform', 'translate(0,' + h / 2 + ')'),
|
||||
brush = d3.svg.brush().x(x).extent([scope.max, scope.max]).on('brush', brushed),
|
||||
handle = slider.append('circle').attr('class', 'handle').attr('r', '0.6em'),
|
||||
lbl = slider.append('g').append('text').attr('y', h / 2);
|
||||
|
||||
slider.call(brush);
|
||||
slider.select(".background").attr("height", h);
|
||||
handle.attr("transform", "translate(0," + h / 2 + ")");
|
||||
slider.select('.background').attr('height', h);
|
||||
handle.attr('transform', 'translate(0,' + h / 2 + ')');
|
||||
|
||||
/**
|
||||
* Watch for changes in the max, window size
|
||||
@@ -42,21 +42,21 @@ angular.module('app').directive('slider', ['$window', function ($window) {
|
||||
function render() {
|
||||
var width = element[0].offsetWidth, w = width - margin.left - margin.right;
|
||||
|
||||
svg.attr("width", width).attr("height", height);
|
||||
svg.attr('width', width).attr('height', height);
|
||||
x.domain([0, scope.max]).range([0, w]).clamp(true);
|
||||
handle.attr("cx", x(val));
|
||||
handle.attr('cx', x(val));
|
||||
xAxis
|
||||
.call(d3.svg.axis()
|
||||
.scale(x)
|
||||
.orient("bottom")
|
||||
.orient('bottom')
|
||||
.tickFormat(function(d) { return d + unit; })
|
||||
.tickValues([0, scope.max / 4, scope.max / 2, (3 * scope.max) / 4, scope.max])
|
||||
.tickSize(0)
|
||||
.tickPadding(12))
|
||||
.select(".domain");
|
||||
.select('.domain');
|
||||
lbl.attr('x', w + 20);
|
||||
slider.call(brush.extent([val, val])).call(brush.event);
|
||||
slider.selectAll(".extent,.resize").remove();
|
||||
slider.selectAll('.extent,.resize').remove();
|
||||
}
|
||||
|
||||
function brushed() {
|
||||
@@ -65,10 +65,10 @@ angular.module('app').directive('slider', ['$window', function ($window) {
|
||||
val = x.invert(d3.mouse(this)[0]);
|
||||
brush.extent([val, val]);
|
||||
}
|
||||
lbl.text(fmt(val) + ' ' + unit + ' ' + pct(val / scope.max));
|
||||
scope.change({val: val});
|
||||
handle.attr("cx", x(val));
|
||||
filled.attr("d", "M0,0V0H" + x(val) + "V0");
|
||||
lbl.text(fmt(val) + ' ' + unit + ' ' + pct(val / scope.max));
|
||||
scope.change({ val: val });
|
||||
handle.attr('cx', x(val));
|
||||
filled.attr('d', 'M0,0V0H' + x(val) + 'V0');
|
||||
}
|
||||
|
||||
scope.$on('$destroy', function() {
|
||||
@@ -77,4 +77,4 @@ angular.module('app').directive('slider', ['$window', function ($window) {
|
||||
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
angular.module('app').directive('slotHardpoint', ['$rootScope', function ($r) {
|
||||
angular.module('app').directive('slotHardpoint', ['$rootScope', function($r) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope:{
|
||||
scope: {
|
||||
hp: '=',
|
||||
size: '=',
|
||||
lbl: '=',
|
||||
lbl: '='
|
||||
},
|
||||
templateUrl: 'views/_slot-hardpoint.html',
|
||||
link: function (scope) {
|
||||
link: function(scope) {
|
||||
scope.$r = $r;
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
angular.module('app').directive('slotInternal', ['$rootScope', function ($r) {
|
||||
angular.module('app').directive('slotInternal', ['$rootScope', function($r) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope:{
|
||||
scope: {
|
||||
c: '=slot',
|
||||
lbl: '=',
|
||||
fuel: '='
|
||||
@@ -11,4 +11,4 @@ angular.module('app').directive('slotInternal', ['$rootScope', function ($r) {
|
||||
scope.$r = $r;
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
|
||||
Reference in New Issue
Block a user