You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
275 lines
8.9 KiB
275 lines
8.9 KiB
'use strict';
|
|
|
|
var BuoyAnalysisChart = {
|
|
/**
|
|
*
|
|
*/
|
|
bars: {
|
|
padding: 15,
|
|
spacing: 2,
|
|
height: 23,
|
|
width: 210,
|
|
|
|
showMonths: true,
|
|
showYears: true,
|
|
|
|
property: 'wt',
|
|
tickValues: null,
|
|
|
|
imperialLabel: null,
|
|
metricLabel: null,
|
|
|
|
leftHexValue: null,
|
|
rightHexValue: null
|
|
},
|
|
|
|
axis: {
|
|
scale: null,
|
|
scaleInverted: null,
|
|
imperial: null,
|
|
metric: null
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
barYearY: function(d, i) {
|
|
return i * BuoyAnalysisChart.bars.height + i * BuoyAnalysisChart.bars.spacing + BuoyAnalysisChart.bars.padding;
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
barMonthY: function(d, i) {
|
|
var year = Math.floor(i / 12);
|
|
return year * BuoyAnalysisChart.bars.height + BuoyAnalysisChart.bars.padding + year * BuoyAnalysisChart.bars.spacing + (i % 12) * 2;
|
|
},
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
// appendGradient: function() {
|
|
// var chart = d3.select('#chart svg');
|
|
// var id = 'gradient-year';
|
|
|
|
// chart.selectAll('#' + id).remove();
|
|
|
|
// var gradient = chart.append("svg:defs")
|
|
// .append("svg:linearGradient")
|
|
// .attr("id", id)
|
|
|
|
// gradient.append("svg:stop")
|
|
// .attr("offset", "0%")
|
|
// .attr("stop-color", BuoyAnalysisChart.bars.leftHexValue)
|
|
// .attr("stop-opacity", 1);
|
|
|
|
// gradient.append("svg:stop")
|
|
// .attr("offset", "100%")
|
|
// .attr("stop-color", BuoyAnalysisChart.bars.rightHexValue)
|
|
// .attr("stop-opacity", 1);
|
|
// },
|
|
|
|
/**
|
|
*
|
|
*/
|
|
appendYearLabels: function() {
|
|
var years = BuoyAnalysisData.calculateYearlyAverages(BuoyAnalysisMap.reticle.stations);
|
|
|
|
d3.select('#year-labels').selectAll('div').data(years).enter()
|
|
.append('div')
|
|
.classed('label', true)
|
|
.text(function(d) {
|
|
return d.year.toString().slice(-2);
|
|
})
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
appendAxes: function() {
|
|
var chart = d3.select('#chart svg');
|
|
|
|
chart.selectAll('.axis').remove();
|
|
chart.selectAll('.label-axis-x').remove();
|
|
|
|
chart.append("g")
|
|
.classed('axis', true)
|
|
.classed('axis-imperial', true)
|
|
.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(0, 860)')
|
|
.call(BuoyAnalysisChart.axis.metric);
|
|
|
|
chart.append('text')
|
|
.classed('label-axis-x', true)
|
|
.attr('text-anchor', 'middle')
|
|
.text(BuoyAnalysisChart.bars.imperialLabel)
|
|
.attr('x', 200)
|
|
.attr('y', 10)
|
|
|
|
chart.append('text')
|
|
.classed('label-axis-x', true)
|
|
.attr('text-anchor', 'middle')
|
|
.text(BuoyAnalysisChart.bars.metricLabel)
|
|
.attr('x', 200)
|
|
.attr('y', 876)
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
updateAxes: function() {
|
|
switch(BuoyAnalysisChart.bars.property) {
|
|
case 'at':
|
|
BuoyAnalysisChart.bars.tickValues = [8, 12, 16, 20];
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = '°F';
|
|
BuoyAnalysisChart.bars.metricLabel = '°C';
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#a7dde6';
|
|
BuoyAnalysisChart.bars.rightHexValue = '#f75c5c';
|
|
break;
|
|
|
|
case 'wt':
|
|
BuoyAnalysisChart.bars.tickValues = [8, 12, 16, 20];
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = '°F';
|
|
BuoyAnalysisChart.bars.metricLabel = '°C';
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#e8e8e8';
|
|
BuoyAnalysisChart.bars.rightHexValue = '#e8e8e8';
|
|
break;
|
|
|
|
case 'wh':
|
|
BuoyAnalysisChart.bars.tickValues = [1, 2, 3, 4];
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = 'FT';
|
|
BuoyAnalysisChart.bars.metricLabel = 'M';
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#c3fd98';
|
|
BuoyAnalysisChart.bars.rightHexValue = '#f00';
|
|
break;
|
|
|
|
case 'wp':
|
|
BuoyAnalysisChart.bars.tickValues = [5, 7, 9, 11, 13];
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = 'SEC';
|
|
BuoyAnalysisChart.bars.metricLabel = 'SEC';
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#9c90ca';
|
|
BuoyAnalysisChart.bars.rightHexValue = '#a8747e';
|
|
break;
|
|
|
|
case 'ws':
|
|
BuoyAnalysisChart.bars.tickValues = [3.05, 6.1, 9.15];
|
|
|
|
BuoyAnalysisChart.bars.imperialLabel = 'FT/S';
|
|
BuoyAnalysisChart.bars.metricLabel = 'M/S';
|
|
|
|
BuoyAnalysisChart.bars.leftHexValue = '#f3cab8';
|
|
BuoyAnalysisChart.bars.rightHexValue = '#e6dea5';
|
|
break;
|
|
};
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
draw: function() {
|
|
var years = BuoyAnalysisData.calculateYearlyAverages(BuoyAnalysisMap.reticle.stations);
|
|
|
|
var months = BuoyAnalysisData.calculateMonthlyAverages(BuoyAnalysisMap.reticle.stations);
|
|
|
|
var chart = d3.select('#chart svg');
|
|
|
|
var len = BuoyAnalysisData.years.end - BuoyAnalysisData.years.start + 1;
|
|
var h = (BuoyAnalysisChart.bars.height + BuoyAnalysisChart.bars.spacing) * len + BuoyAnalysisChart.bars.padding;
|
|
// alert(BuoyAnalysisData.bars.height + ' ' + BuoyAnalysisChart.bars.spacing)
|
|
|
|
BuoyAnalysisData.setAxisProperties();
|
|
BuoyAnalysisChart.appendAxes();
|
|
// BuoyAnalysisChart.appendGradient();
|
|
BuoyAnalysisChart.appendYearLabels();
|
|
|
|
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', 1)
|
|
.attr('x2', 1)
|
|
.attr('y1', 15)
|
|
.attr('y2', h)
|
|
|
|
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('fill', '#f0f0ff')
|
|
.attr('height', 23)
|
|
// .attr('width', BuoyAnalysisChart.bars.width)
|
|
.attr('width', function(d) {
|
|
return BuoyAnalysisChart.axis.scale(d.average);
|
|
})
|
|
.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) {
|
|
chart.selectAll('.bar-month').data(months).enter()
|
|
.append('rect')
|
|
.classed('bar-month', true)
|
|
.attr('fill', 'rgba(0, 0, 0, 0.2)')
|
|
.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)
|
|
}
|
|
}
|
|
};
|
|
|