@@ -515,6 +515,27 @@ nv.nearestValueIndex = function (values, searchVal, threshold) {
515515 }
516516 } ) ;
517517
518+ //EDIT
519+ //add info about a post to tooltip when hover over a post icon
520+ if ( d . postMarkerTooltip ) {
521+ var tfootEnter = tbodyEnter . selectAll ( "tfoot" )
522+ . data ( [ d ] )
523+ . enter ( )
524+ . append ( "tfoot" ) ;
525+
526+ tfootEnter . append ( "tr" )
527+ . append ( "td" )
528+ . attr ( "colspan" , 3 )
529+ . append ( "strong" )
530+ . html ( function ( p ) { return p . postMarkerTooltip . label } ) ;
531+
532+ tfootEnter . append ( "tr" )
533+ . append ( "td" )
534+ . attr ( "colspan" , 3 )
535+ . html ( function ( p ) { return d3 . time . format ( '%x %I %p' ) ( p . postMarkerTooltip . postDate ) } ) ;
536+ }
537+ //END EDIT
538+
518539 var html = table . node ( ) . outerHTML ;
519540 if ( d . footer !== undefined )
520541 html += "<div class='footer'>" + d . footer + "</div>" ;
@@ -4297,6 +4318,7 @@ nv.models.ohlcBarChart = function() {
42974318 var gEnter = wrap . enter ( ) . append ( 'g' ) . attr ( 'class' , 'nvd3 nv-legend' ) . append ( 'g' ) ;
42984319 var g = wrap . select ( 'g' ) ;
42994320
4321+
43004322 wrap . attr ( 'transform' , 'translate(' + margin . left + ',' + margin . top + ')' ) ;
43014323
43024324 var series = g . selectAll ( '.nv-series' )
@@ -4415,12 +4437,22 @@ nv.models.ohlcBarChart = function() {
44154437 return 'translate(' + xPositions [ i % seriesPerRow ] + ',' + ( 5 + Math . floor ( i / seriesPerRow ) * 20 ) + ')' ;
44164438 } ) ;
44174439
4440+ var bg = g . insert ( 'rect' , 'g' )
4441+ . attr ( 'height' , height )
4442+ . attr ( 'width' , legendWidth > 0 ? legendWidth : 0 )
4443+ . attr ( 'transform' , 'translate(-10,-5)' )
4444+ . style ( 'fill' , '#eee' ) ;
4445+
4446+ height = d3 . select ( this . parentNode . parentNode . parentNode ) . attr ( 'height' ) ;
4447+ //console.log('height: ' + height);
4448+
44184449 //position legend as far right as possible within the total width
44194450 if ( rightAlign ) {
4420- g . attr ( 'transform' , 'translate(' + ( width - margin . right - legendWidth ) + ',' + margin . top + ')' ) ;
4451+ g . attr ( 'transform' , 'translate(' + ( width - margin . right - legendWidth ) + ',' + ( height - 50 ) + ')' ) ;
44214452 }
44224453 else {
4423- g . attr ( 'transform' , 'translate(0' + ',' + margin . top + ')' ) ;
4454+ g . attr ( 'transform' , 'translate(0' + ',' + ( height - 50 ) + ')' ) ;
4455+ //console.log(g.attr('transform'));
44244456 }
44254457
44264458 height = margin . top + margin . bottom + ( Math . ceil ( seriesWidths . length / seriesPerRow ) * 20 ) ;
@@ -4575,7 +4607,7 @@ nv.models.line = function() {
45754607 . append ( 'rect' ) ;
45764608
45774609 wrap . select ( '#nv-edge-clip-' + scatter . id ( ) + ' rect' )
4578- . attr ( 'width' , availableWidth )
4610+ . attr ( 'width' , availableWidth > 0 ? availableWidth : 0 )
45794611 . attr ( 'height' , ( availableHeight > 0 ) ? availableHeight : 0 ) ;
45804612
45814613 g . attr ( 'clip-path' , clipEdge ? 'url(#nv-edge-clip-' + scatter . id ( ) + ')' : '' ) ;
@@ -4774,7 +4806,7 @@ nv.models.lineChart = function() {
47744806
47754807 var renderWatch = nv . utils . renderWatch ( dispatch , duration ) ;
47764808
4777- var stateGetter = function ( data ) {
4809+ var stateGetter = function ( data ) {
47784810 return function ( ) {
47794811 return {
47804812 active : data . map ( function ( d ) { return ! d . disabled } )
@@ -4868,11 +4900,13 @@ nv.models.lineChart = function() {
48684900 gEnter . append ( 'g' ) . attr ( 'class' , 'nv-linesWrap' ) ;
48694901 gEnter . append ( 'g' ) . attr ( 'class' , 'nv-legendWrap' ) ;
48704902 gEnter . append ( 'g' ) . attr ( 'class' , 'nv-interactive' ) ;
4903+ gEnter . append ( 'g' ) . attr ( 'class' , 'en-postMarkers' ) ;
48714904
48724905 g . select ( "rect" )
4873- . attr ( "width" , availableWidth )
4906+ . attr ( "width" , availableWidth > 0 ? availableWidth : 0 )
48744907 . attr ( "height" , ( availableHeight > 0 ) ? availableHeight : 0 ) ;
48754908
4909+ //EDIT
48764910 var postSeries ;
48774911 //remove post marker series
48784912 //do this before legend gets drawn
@@ -4882,6 +4916,7 @@ nv.models.lineChart = function() {
48824916 return true ;
48834917 }
48844918 } ) ;
4919+ //END EDIT
48854920
48864921 // Legend
48874922 if ( showLegend ) {
@@ -4932,26 +4967,48 @@ nv.models.lineChart = function() {
49324967
49334968 linesWrap . call ( lines ) ;
49344969
4970+ //EDIT
49354971 //draw post markers
49364972 //gotta do this after setting up the lines so that the scale is ready
49374973 if ( postSeries ) {
4938- var markers = gEnter . append ( 'g' )
4939- . attr ( 'class' , 'en-postMarkers' )
4940- . attr ( 'width' , availableWidth )
4941- . attr ( 'height' , ( availableHeight > 0 ) ? availableHeight : 0 ) ;
4974+ var markers ;
4975+ if ( d3 . select ( '.en-postMarkers' ) . size ( ) ) {
4976+ markers = d3 . select ( '.en-postMarkers' ) ;
4977+ markers . selectAll ( '*' ) . remove ( ) ;
4978+ } else {
4979+ markers = gEnter . append ( 'g' )
4980+ . attr ( 'class' , 'en-postMarkers' )
4981+ . attr ( 'width' , availableWidth )
4982+ . attr ( 'height' , ( availableHeight > 0 ) ? availableHeight : 0 ) ;
4983+ }
4984+ var maxY = availableHeight - 16 ;
4985+ var minX = 0 ;
49424986 postSeries . values . forEach ( function ( markerData , index ) {
4987+ //if the series is disabled, return
4988+ var ret ;
4989+ data . some ( function ( series ) {
4990+ if ( ( series . postURLs . indexOf ( markerData . postURL ) > - 1 || series . postURLs . indexOf ( 'all' ) > - 1 ) && series . disabled ) ret = true ;
4991+ } ) ;
4992+ if ( ret ) return ;
49434993 markerData . x = new Date ( markerData . x ) ;
4944- markers . append ( 'g' )
4994+ //need to figure out the y value of the corresponding point on the corresponding stream
4995+ var markerX = Math . round ( x ( markerData . x ) - 8 >= minX ? x ( markerData . x ) - 8 : minX ) ;
4996+ var markerY = Math . round ( y ( markerData . y ) - 8 <= maxY ? y ( markerData . y ) - 8 : maxY ) ;
4997+ markerData . markerX = markerX ;
4998+ markerData . markerY = markerY ;
4999+ var transform = 'translate(' + markerX + ',' + markerY + ')' ;
5000+ var marker = markers . append ( 'g' )
49455001 . attr ( 'class' , 'marker' )
4946- . attr ( 'transform' , 'translate(' + x ( markerData . x . valueOf ( ) ) + ',0)' )
4947- . append ( 'line ' )
4948- . attr ( 'y2 ' , availableHeight )
4949- . attr ( 'x2 ' , 0 )
4950- . attr ( 'style ' , 'stroke: red ' ) ;
5002+ . attr ( 'transform' , transform )
5003+ . append ( 'svg:image ' )
5004+ . attr ( 'height ' , 16 )
5005+ . attr ( 'width ' , 16 )
5006+ . attr ( 'xlink:href ' , '/admin/images/icons16/' + markerData . network + '.png ') ;
49515007 } ) ;
49525008 //put markers back in so they will be there when update
49535009 data . push ( postSeries ) ;
49545010 }
5011+ //END EDIT
49555012
49565013 // Setup Axes
49575014 if ( showXAxis ) {
@@ -5017,6 +5074,17 @@ nv.models.lineChart = function() {
50175074 if ( indexToHighlight !== null )
50185075 allData [ indexToHighlight ] . highlight = true ;
50195076 }
5077+ //EDIT
5078+ var postMarkerTooltip ;
5079+ postSeries . values . forEach ( function ( markerData ) {
5080+ if ( e . mouseX >= markerData . markerX && e . mouseX <= markerData . markerX + 16 && e . mouseY >= markerData . markerY && e . mouseY <= markerData . markerY + 16 ) {
5081+ postMarkerTooltip = {
5082+ label : markerData . label ,
5083+ postDate : markerData . x
5084+ } ;
5085+ }
5086+ } ) ;
5087+ //END EDIT
50205088
50215089 var xValue = xAxis . tickFormat ( ) ( chart . x ( ) ( singlePoint , pointIndex ) ) ;
50225090 interactiveLayer . tooltip
@@ -5029,7 +5097,8 @@ nv.models.lineChart = function() {
50295097 . data (
50305098 {
50315099 value : xValue ,
5032- series : allData
5100+ series : allData ,
5101+ postMarkerTooltip : postMarkerTooltip
50335102 }
50345103 ) ( ) ;
50355104
@@ -6428,8 +6497,8 @@ nv.models.multiBar = function() {
64286497 . attr ( 'id' , 'nv-edge-clip-' + id )
64296498 . append ( 'rect' ) ;
64306499 wrap . select ( '#nv-edge-clip-' + id + ' rect' )
6431- . attr ( 'width' , availableWidth )
6432- . attr ( 'height' , availableHeight ) ;
6500+ . attr ( 'width' , availableWidth > 0 ? availableWidth : 0 )
6501+ . attr ( 'height' , availableHeight > 0 ? availableHeight : 0 ) ;
64336502
64346503 g . attr ( 'clip-path' , clipEdge ? 'url(#nv-edge-clip-' + id + ')' : '' ) ;
64356504
@@ -7601,10 +7670,11 @@ nv.models.multiBarHorizontalChart = function() {
76017670 if ( showLegend ) {
76027671 legend . width ( availableWidth - controlWidth ( ) ) ;
76037672
7604- if ( multibar . barColor ( ) )
7673+ //COMMENTED
7674+ /*if (multibar.barColor())
76057675 data.forEach(function(series,i) {
76067676 series.color = d3.rgb('#ccc').darker(i * 1.5).toString();
7607- } ) ;
7677+ });*/
76087678
76097679 g . select ( '.nv-legendWrap' )
76107680 . datum ( data )
@@ -7657,6 +7727,10 @@ nv.models.multiBarHorizontalChart = function() {
76577727 . ticks ( nv . utils . calcTicksY ( availableHeight / 24 , data ) )
76587728 . tickSize ( - availableWidth , 0 ) ;
76597729
7730+ //based on 'wrapping long labels' by mike bostock
7731+ //http://bl.ocks.org/mbostock/7555321
7732+ console . log ( 'x axis' ) ;
7733+
76607734 g . select ( '.nv-x.nv-axis' ) . call ( xAxis ) . selectAll ( '.tick text' ) . call ( function ( selection ) {
76617735 selection . each ( function ( ) {
76627736 var text = d3 . select ( this ) ,
@@ -7667,15 +7741,15 @@ nv.models.multiBarHorizontalChart = function() {
76677741 lineHeight = 1.1 , // ems
76687742 y = text . attr ( "y" ) ,
76697743 dy = parseFloat ( text . attr ( "dy" ) ) ,
7670- tspan = text . text ( null ) . append ( "tspan" ) . attr ( "x" , - 5 ) . attr ( "y" , y ) . attr ( "dy" , dy + "em" ) ;
7744+ tspan = text . text ( null ) . append ( "tspan" ) . attr ( "x" , - 5 ) . attr ( "y" , 0 ) . attr ( "dy" , dy + "em" ) ;
76717745 while ( word = words . pop ( ) ) {
76727746 line . push ( word ) ;
76737747 tspan . text ( line . join ( " " ) ) ;
76747748 if ( tspan . node ( ) . getComputedTextLength ( ) > margin . right ) {
76757749 line . pop ( ) ;
76767750 tspan . text ( line . join ( " " ) ) ;
76777751 line = [ word ] ;
7678- tspan = text . append ( "tspan" ) . attr ( "x" , - 5 ) . attr ( "y" , y ) . attr ( "dy" , ++ lineNumber * lineHeight + dy + "em" ) . text ( word ) ;
7752+ tspan = text . append ( "tspan" ) . attr ( "x" , - 5 ) . attr ( "y" , 0 ) . attr ( "dy" , ++ lineNumber * lineHeight + dy + "em" ) . text ( word ) ;
76797753 }
76807754 }
76817755 //offset is height / 4 since position is already displaced by height / 2
@@ -9429,7 +9503,7 @@ nv.models.scatter = function() {
94299503 . append ( 'rect' ) ;
94309504
94319505 wrap . select ( '#nv-edge-clip-' + id + ' rect' )
9432- . attr ( 'width' , availableWidth )
9506+ . attr ( 'width' , availableWidth > 0 ? availableWidth : 0 )
94339507 . attr ( 'height' , ( availableHeight > 0 ) ? availableHeight : 0 ) ;
94349508
94359509 g . attr ( 'clip-path' , clipEdge ? 'url(#nv-edge-clip-' + id + ')' : '' ) ;
0 commit comments