@ -8,19 +8,16 @@ var BuoyAnalysisChart = {
padding : 15 ,
spacing : 2 ,
height : 23 ,
width : 210 ,
width : 190 ,
color : '#f00' ,
showMonths : true ,
showYears : true ,
property : 'wt' ,
tickValues : null ,
imperialLabel : null ,
metricLabel : null ,
leftHexValue : null ,
rightHexValue : null
} ,
axis : {
@ -45,33 +42,8 @@ var BuoyAnalysisChart = {
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);
// },
/ * *
*
* DOM init .
* /
appendYearLabels : function ( ) {
var years = BuoyAnalysisData . calculateYearlyAverages ( BuoyAnalysisMap . reticle . stations ) ;
@ -89,7 +61,7 @@ var BuoyAnalysisChart = {
} ,
/ * *
*
* DOM init .
* /
appendAxes : function ( ) {
var chart = d3 . select ( '#chart svg' ) ;
@ -114,22 +86,44 @@ var BuoyAnalysisChart = {
. classed ( 'label-axis-x' , true )
. attr ( 'text-anchor' , 'middle' )
. text ( BuoyAnalysisChart . bars . imperialLabel )
. attr ( 'x' , 20 0)
. attr ( 'x' , 18 0)
. attr ( 'y' , 10 )
chart . append ( 'text' )
. classed ( 'label-axis-x' , true )
. attr ( 'text-anchor' , 'middle' )
. text ( BuoyAnalysisChart . bars . metricLabel )
. attr ( 'x' , 20 0)
. attr ( 'x' , 18 0)
. attr ( 'y' , 876 )
} ,
/ * *
*
* Updates the color of the bars to an average of current station colors .
* /
updateColor : function ( ) {
var r , g , b , station , tmp ;
r = g = b = 0 ;
function avg ( val ) {
return Math . round ( val / BuoyAnalysisMap . reticle . stations . length ) ;
}
BuoyAnalysisMap . reticle . stations . forEach ( function ( s ) {
station = BuoyAnalysisData . stationJson [ s ] ;
tmp = BuoyAnalysisMap . stationColorScale ( station . lat ) . substr ( 1 ) . match ( /.{1,2}/g ) ;
r += parseInt ( tmp [ 0 ] , 16 ) ;
g += parseInt ( tmp [ 1 ] , 16 ) ;
b += parseInt ( tmp [ 2 ] , 16 ) ;
} ) ;
BuoyAnalysisChart . bars . color = 'rgba(' + avg ( r ) + ',' + avg ( g ) + ',' + avg ( b ) + ', 0.1)' ;
} ,
/ * *
* Handles unit and scale changes .
* /
updateAxes : function ( ) {
switch ( BuoyAnalysisChart . bars . property ) {
switch ( BuoyAnalysisData . property ) {
case 'at' :
BuoyAnalysisChart . bars . tickValues = [ 8 , 12 , 16 , 20 ] ;
@ -194,11 +188,9 @@ var BuoyAnalysisChart = {
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 ( ) ;
@ -231,30 +223,13 @@ var BuoyAnalysisChart = {
chart . selectAll ( '.bar-year' ) . data ( years ) . enter ( )
. append ( 'rect' )
. classed ( 'bar-year' , true )
// .attr('fill', 'url("#gradient-year")')
. attr ( 'fill' , '#f0f0ff' )
. attr ( 'fill' , BuoyAnalysisChart . bars . color )
. 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 ) {