|
|
|
@ -5,27 +5,25 @@ var BuoyAnalysisChart = { |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
bars: { |
|
|
|
|
padding: 26, |
|
|
|
|
padding: 15, |
|
|
|
|
spacing: 2, |
|
|
|
|
width: 23, |
|
|
|
|
height: 23, |
|
|
|
|
width: 210, |
|
|
|
|
|
|
|
|
|
showMonths: true, |
|
|
|
|
showYears: true, |
|
|
|
|
|
|
|
|
|
property: 'WTMP', |
|
|
|
|
property: 'wt', |
|
|
|
|
tickValues: null, |
|
|
|
|
|
|
|
|
|
imperialLabel: null, |
|
|
|
|
metricLabel: null, |
|
|
|
|
|
|
|
|
|
bottomHexValue: null, |
|
|
|
|
topHexValue: null |
|
|
|
|
leftHexValue: null, |
|
|
|
|
rightHexValue: null |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
axis: { |
|
|
|
|
h: 200, |
|
|
|
|
min: 100, |
|
|
|
|
max: 0, |
|
|
|
|
scale: null, |
|
|
|
|
scaleInverted: null, |
|
|
|
|
imperial: null, |
|
|
|
@ -35,23 +33,24 @@ var BuoyAnalysisChart = { |
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
barYearX: function(d, i) { |
|
|
|
|
return i * BuoyAnalysisChart.bars.width + i * BuoyAnalysisChart.bars.spacing + BuoyAnalysisChart.bars.padding; |
|
|
|
|
barYearY: function(d, i) { |
|
|
|
|
return i * BuoyAnalysisChart.bars.height + i * BuoyAnalysisChart.bars.spacing + BuoyAnalysisChart.bars.padding; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
barMonthX: function(d, i) { |
|
|
|
|
barMonthY: function(d, i) { |
|
|
|
|
var year = Math.floor(i / 12); |
|
|
|
|
return year * BuoyAnalysisChart.bars.width + BuoyAnalysisChart.bars.padding + year * BuoyAnalysisChart.bars.spacing + (i % 12) * 2; |
|
|
|
|
return year * BuoyAnalysisChart.bars.height + BuoyAnalysisChart.bars.padding + year * BuoyAnalysisChart.bars.spacing + (i % 12) * 2; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
appendGradient: function() { |
|
|
|
|
var chart = d3.select('#chart'); |
|
|
|
|
var chart = d3.select('#chart svg'); |
|
|
|
|
var id = 'gradient-year'; |
|
|
|
|
|
|
|
|
|
chart.selectAll('#' + id).remove(); |
|
|
|
@ -59,16 +58,15 @@ var BuoyAnalysisChart = { |
|
|
|
|
var gradient = chart.append("svg:defs") |
|
|
|
|
.append("svg:linearGradient") |
|
|
|
|
.attr("id", id) |
|
|
|
|
.attr('gradientTransform', 'rotate(90)') |
|
|
|
|
|
|
|
|
|
gradient.append("svg:stop") |
|
|
|
|
.attr("offset", "0%") |
|
|
|
|
.attr("stop-color", BuoyAnalysisChart.bars.bottomHexValue) |
|
|
|
|
.attr("stop-color", BuoyAnalysisChart.bars.leftHexValue) |
|
|
|
|
.attr("stop-opacity", 1); |
|
|
|
|
|
|
|
|
|
gradient.append("svg:stop") |
|
|
|
|
.attr("offset", "100%") |
|
|
|
|
.attr("stop-color", BuoyAnalysisChart.bars.topHexValue) |
|
|
|
|
.attr("stop-color", BuoyAnalysisChart.bars.rightHexValue) |
|
|
|
|
.attr("stop-opacity", 1); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
@ -84,46 +82,43 @@ var BuoyAnalysisChart = { |
|
|
|
|
.text(function(d) { |
|
|
|
|
return d.year.toString().slice(-2); |
|
|
|
|
}) |
|
|
|
|
.attr('x', BuoyAnalysisChart.barYearX) |
|
|
|
|
.attr('y', 180) |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
appendAxes: function() { |
|
|
|
|
var chart = d3.select('#chart'); |
|
|
|
|
var chart = d3.select('#chart svg'); |
|
|
|
|
|
|
|
|
|
chart.selectAll('.axis').remove(); |
|
|
|
|
chart.selectAll('.label-axis-y').remove(); |
|
|
|
|
chart.selectAll('.label-axis-x').remove(); |
|
|
|
|
|
|
|
|
|
chart.append("g") |
|
|
|
|
.classed('axis', true) |
|
|
|
|
.classed('axis-imperial', true) |
|
|
|
|
.attr('transform', 'translate(30, 0)') |
|
|
|
|
.attr('transform', 'translate(0, 19)') |
|
|
|
|
.attr('fill', '#000') |
|
|
|
|
.call(BuoyAnalysisChart.axis.imperial); |
|
|
|
|
|
|
|
|
|
chart.append("g") |
|
|
|
|
.classed('axis', true) |
|
|
|
|
.classed('axis-metric', true) |
|
|
|
|
.attr('transform', 'translate(871, 0)') |
|
|
|
|
.attr('transform', 'translate(0, 860)') |
|
|
|
|
.call(BuoyAnalysisChart.axis.metric); |
|
|
|
|
|
|
|
|
|
chart.append('text') |
|
|
|
|
.classed('label-axis-y', true) |
|
|
|
|
.classed('label-axis-x', true) |
|
|
|
|
.attr('text-anchor', 'middle') |
|
|
|
|
.text(BuoyAnalysisChart.bars.imperialLabel) |
|
|
|
|
.attr('x', 12) |
|
|
|
|
.attr('y', 15) |
|
|
|
|
.attr('x', 200) |
|
|
|
|
.attr('y', 10) |
|
|
|
|
|
|
|
|
|
chart.append('text') |
|
|
|
|
.classed('label-axis-y', true) |
|
|
|
|
.classed('label-axis-x', true) |
|
|
|
|
.attr('text-anchor', 'middle') |
|
|
|
|
.text(BuoyAnalysisChart.bars.metricLabel) |
|
|
|
|
.attr('x', 885) |
|
|
|
|
.attr('y', 15) |
|
|
|
|
.attr('x', 200) |
|
|
|
|
.attr('y', 876) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -131,55 +126,54 @@ var BuoyAnalysisChart = { |
|
|
|
|
*/ |
|
|
|
|
updateAxes: function() { |
|
|
|
|
switch(BuoyAnalysisChart.bars.property) { |
|
|
|
|
case 'ATMP': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [8, 12, 16, 20, 24]; |
|
|
|
|
case 'at': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [8, 12, 16, 20]; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = 'F'; |
|
|
|
|
BuoyAnalysisChart.bars.metricLabel = 'C'; |
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = '°F'; |
|
|
|
|
BuoyAnalysisChart.bars.metricLabel = '°C'; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.topHexValue = '#a7dde6'; |
|
|
|
|
BuoyAnalysisChart.bars.bottomHexValue = '#f75c5c'; |
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#a7dde6'; |
|
|
|
|
BuoyAnalysisChart.bars.rightHexValue = '#f75c5c'; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'WTMP': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [10, 13, 15.5, 18.5, 21]; |
|
|
|
|
case 'wt': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [8, 12, 16, 20]; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = 'F'; |
|
|
|
|
BuoyAnalysisChart.bars.metricLabel = 'C'; |
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = '°F'; |
|
|
|
|
BuoyAnalysisChart.bars.metricLabel = '°C'; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.topHexValue = '#a7dde6'; |
|
|
|
|
BuoyAnalysisChart.bars.bottomHexValue = '#f75c5c'; |
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#a7dde6'; |
|
|
|
|
BuoyAnalysisChart.bars.rightHexValue = '#f75c5c'; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'WVHT': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [0, 1, 2, 3, 4]; |
|
|
|
|
case 'wh': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [1, 2, 3, 4]; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = 'FT'; |
|
|
|
|
BuoyAnalysisChart.bars.metricLabel = 'M'; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.topHexValue = '#c3fd98'; |
|
|
|
|
BuoyAnalysisChart.bars.bottomHexValue = '#f00'; |
|
|
|
|
// BuoyAnalysisChart.bars.bottomHexValue = '#ff0';
|
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#c3fd98'; |
|
|
|
|
BuoyAnalysisChart.bars.rightHexValue = '#f00'; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'WPER': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [5, 7, 9, 11, 13, 15]; |
|
|
|
|
case 'wp': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [5, 7, 9, 11, 13]; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = 'SEC'; |
|
|
|
|
BuoyAnalysisChart.bars.metricLabel = 'SEC'; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.topHexValue = '#9c90ca'; |
|
|
|
|
BuoyAnalysisChart.bars.bottomHexValue = '#a8747e'; |
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#9c90ca'; |
|
|
|
|
BuoyAnalysisChart.bars.rightHexValue = '#a8747e'; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'WSPD': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [3, 6, 9, 12]; |
|
|
|
|
case 'ws': |
|
|
|
|
BuoyAnalysisChart.bars.tickValues = [3.05, 6.1, 9.15]; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = 'FT/S'; |
|
|
|
|
BuoyAnalysisChart.bars.metricLabel = 'M/S'; |
|
|
|
|
|
|
|
|
|
BuoyAnalysisChart.bars.topHexValue = '#f3cab8'; |
|
|
|
|
BuoyAnalysisChart.bars.bottomHexValue = '#e6dea5'; |
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#f3cab8'; |
|
|
|
|
BuoyAnalysisChart.bars.rightHexValue = '#e6dea5'; |
|
|
|
|
break; |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
@ -192,7 +186,11 @@ var BuoyAnalysisChart = { |
|
|
|
|
|
|
|
|
|
var months = BuoyAnalysisData.calculateMonthlyAverages(BuoyAnalysisMap.reticle.stations); |
|
|
|
|
|
|
|
|
|
var chart = d3.select('#chart'); |
|
|
|
|
var chart = d3.select('#chart svg'); |
|
|
|
|
|
|
|
|
|
var len = BuoyAnalysisData.years.end - BuoyAnalysisData.years.start; |
|
|
|
|
var h = (BuoyAnalysisChart.bars.height + BuoyAnalysisChart.bars.spacing) * len + BuoyAnalysisChart.bars.padding; |
|
|
|
|
// alert(BuoyAnalysisData.bars.height + ' ' + BuoyAnalysisChart.bars.spacing)
|
|
|
|
|
|
|
|
|
|
BuoyAnalysisData.setAxisProperties(); |
|
|
|
|
BuoyAnalysisChart.appendAxes(); |
|
|
|
@ -202,29 +200,49 @@ var BuoyAnalysisChart = { |
|
|
|
|
chart.selectAll('.bar-year').remove(); |
|
|
|
|
chart.selectAll('.mask-year').remove(); |
|
|
|
|
chart.selectAll('.bar-month').remove(); |
|
|
|
|
chart.selectAll('.tick-line').remove(); |
|
|
|
|
|
|
|
|
|
chart.append('line') |
|
|
|
|
.classed('tick-line', true) |
|
|
|
|
.attr('x1', BuoyAnalysisChart.axis.scale(BuoyAnalysisChart.bars.tickValues[0])) |
|
|
|
|
.attr('x2', BuoyAnalysisChart.axis.scale(BuoyAnalysisChart.bars.tickValues[0])) |
|
|
|
|
.attr('y1', 15) |
|
|
|
|
.attr('y2', h) |
|
|
|
|
|
|
|
|
|
chart.append('line') |
|
|
|
|
.classed('tick-line', true) |
|
|
|
|
.attr('x1', BuoyAnalysisChart.axis.scale(BuoyAnalysisChart.bars.tickValues[BuoyAnalysisChart.bars.tickValues.length - 1])) |
|
|
|
|
.attr('x2', BuoyAnalysisChart.axis.scale(BuoyAnalysisChart.bars.tickValues[BuoyAnalysisChart.bars.tickValues.length - 1])) |
|
|
|
|
.attr('y1', 15) |
|
|
|
|
.attr('y2', h) |
|
|
|
|
|
|
|
|
|
if (BuoyAnalysisChart.bars.showYears === true) { |
|
|
|
|
chart.selectAll('.bar-year').data(years).enter() |
|
|
|
|
.append('rect') |
|
|
|
|
.classed('bar-year', true) |
|
|
|
|
.attr('fill', 'url("#gradient-year")') |
|
|
|
|
.attr('width', 23) |
|
|
|
|
.attr('height', BuoyAnalysisChart.axis.h) |
|
|
|
|
.attr('x', BuoyAnalysisChart.barYearX) |
|
|
|
|
.attr('y', 0) |
|
|
|
|
|
|
|
|
|
chart.selectAll('.mask-year').data(years).enter() |
|
|
|
|
.append('rect') |
|
|
|
|
.classed('.mask-year', true) |
|
|
|
|
.attr('fill', '#fff') |
|
|
|
|
.attr('width', 25) |
|
|
|
|
.attr('height', function(d) { |
|
|
|
|
return Math.max(0, BuoyAnalysisChart.axis.scale(d.average)); |
|
|
|
|
.attr('height', 23) |
|
|
|
|
// .attr('width', BuoyAnalysisChart.bars.width)
|
|
|
|
|
.attr('width', function(d) { |
|
|
|
|
return BuoyAnalysisChart.axis.scale(d.average); |
|
|
|
|
}) |
|
|
|
|
.attr('x', function(d, i) { |
|
|
|
|
return BuoyAnalysisChart.barYearX(d, i) - 1; |
|
|
|
|
}) |
|
|
|
|
.attr('y', 0) |
|
|
|
|
.attr('x', 0) |
|
|
|
|
.attr('y', BuoyAnalysisChart.barYearY) |
|
|
|
|
|
|
|
|
|
// chart.selectAll('.mask-year').data(years).enter()
|
|
|
|
|
// .append('rect')
|
|
|
|
|
// .classed('.mask-year', true)
|
|
|
|
|
// .attr('fill', '#fff')
|
|
|
|
|
// .attr('height', 23)
|
|
|
|
|
// .attr('width', function(d) {
|
|
|
|
|
// return Math.max(0, BuoyAnalysisChart.bars.width - BuoyAnalysisChart.axis.scale(d.average));
|
|
|
|
|
// })
|
|
|
|
|
// .attr('x', function(d) {
|
|
|
|
|
// return BuoyAnalysisChart.axis.scale(d.average);
|
|
|
|
|
// })
|
|
|
|
|
// .attr('y', function(d, i) {
|
|
|
|
|
// return BuoyAnalysisChart.barYearY(d, i);
|
|
|
|
|
// })
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (BuoyAnalysisChart.bars.showMonths === true) { |
|
|
|
@ -232,14 +250,18 @@ var BuoyAnalysisChart = { |
|
|
|
|
.append('rect') |
|
|
|
|
.classed('bar-month', true) |
|
|
|
|
.attr('fill', 'rgba(0, 0, 0, 0.2)') |
|
|
|
|
.attr('width', 1) |
|
|
|
|
.attr('height', function(d) { |
|
|
|
|
return Math.max(0, BuoyAnalysisChart.axis.scaleInverted(d.average)); |
|
|
|
|
}) |
|
|
|
|
.attr('x', BuoyAnalysisChart.barMonthX) |
|
|
|
|
.attr('y', function(d) { |
|
|
|
|
return BuoyAnalysisChart.axis.h - BuoyAnalysisChart.axis.scaleInverted(d.average); |
|
|
|
|
.attr('height', 1) |
|
|
|
|
.attr('width', function(d) { |
|
|
|
|
var w = BuoyAnalysisChart.axis.scale(d.average); |
|
|
|
|
|
|
|
|
|
if (w <= 20) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return w; |
|
|
|
|
}) |
|
|
|
|
.attr('x', 0) |
|
|
|
|
.attr('y', BuoyAnalysisChart.barMonthY) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|