|
117 | 117 | 'enabled': true,
|
118 | 118 | 'showHint': true
|
119 | 119 | },
|
| 120 | + 'axes': { |
| 121 | + 'yAxis':{ |
| 122 | + 'visible': true |
| 123 | + }, |
| 124 | + 'xAxis':{ |
| 125 | + 'visible': true |
| 126 | + } |
| 127 | + } |
120 | 128 | },
|
121 | 129 | 'measures': {
|
122 | 130 | 'body_weight' : {
|
|
196 | 204 | mouseWheelDispatcher && mouseWheelDispatcher.offWheel( wheelCallback );
|
197 | 205 | showHoverPointTooltip && drag.offDrag( showHoverPointTooltip );
|
198 | 206 | toolbar && toolbar.remove();
|
| 207 | + yScaleCallback && yScale.offUpdate( yScaleCallback ); |
199 | 208 | };
|
200 | 209 |
|
201 | 210 | //public method for getting the plottable chart component
|
|
450 | 459 | // set up axes
|
451 | 460 | var xScale = new Plottable.Scales.Time();
|
452 | 461 | var yScale = new Plottable.Scales.Linear();
|
| 462 | + var yScaleCallback = null; |
453 | 463 | var domain = primaryMeasureSettings.range;
|
454 | 464 | if( domain ){
|
455 | 465 | yScale.domainMin( domain.min ).domainMax( domain.max );
|
|
526 | 536 | }
|
527 | 537 | } );
|
528 | 538 |
|
529 |
| - //iterate across the data prepared from the omh json data |
| 539 | + |
| 540 | + // If there are thresholds for any of the measures, add them as gridlines |
| 541 | + |
| 542 | + var thresholdValues = []; |
| 543 | + |
| 544 | + d3.entries( measureData ).forEach( function( entry ) { |
| 545 | + |
| 546 | + measure = entry.key; |
| 547 | + |
| 548 | + var thresholds = getMeasureSettings( measure ).thresholds; |
| 549 | + |
| 550 | + if ( thresholds ){ |
| 551 | + thresholdValues.push( thresholds.max ); |
| 552 | + } |
| 553 | + |
| 554 | + }); |
| 555 | + |
| 556 | + if ( thresholdValues.length > 0 ){ |
| 557 | + |
| 558 | + thresholdValues.sort( function(a,b){ return a-b; } ); |
| 559 | + |
| 560 | + var gridlineYScale = new Plottable.Scales.Linear(); |
| 561 | + gridlineYScale.domain( yScale.domain() ); |
| 562 | + gridlineYScale.range( yScale.range() ); |
| 563 | + yScaleCallback = function( updatedScale ){ |
| 564 | + gridlineYScale.domain( updatedScale.domain() ); |
| 565 | + gridlineYScale.range( updatedScale.range() ); |
| 566 | + }; |
| 567 | + yScale.onUpdate( yScaleCallback ); |
| 568 | + var yScaleTickGenerator = function( scale ){ |
| 569 | + var domain = scale.domain(); |
| 570 | + var ticks = thresholdValues; |
| 571 | + return ticks; |
| 572 | + }; |
| 573 | + gridlineYScale.tickGenerator(yScaleTickGenerator); |
| 574 | + |
| 575 | + var gridlineYAxis = new Plottable.Axes.Numeric(gridlineYScale, "right") |
| 576 | + .tickLabelPosition("top") |
| 577 | + .tickLabelPadding( 5 ) |
| 578 | + .showEndTickLabels(true); |
| 579 | + |
| 580 | + var gridlines = new Plottable.Components.Gridlines(null, gridlineYScale); |
| 581 | + |
| 582 | + plots.push( gridlines ); |
| 583 | + plots.push( gridlineYAxis ); |
| 584 | + |
| 585 | + } |
| 586 | + |
| 587 | + //iterate across the data prepared from the omh json data and add plots |
530 | 588 | measures.forEach( function( measure ) {
|
531 | 589 | if ( ! measureData.hasOwnProperty( measure ) ){
|
532 | 590 | return;
|
|
607 | 665 |
|
608 | 666 | }
|
609 | 667 |
|
610 |
| - |
611 |
| - }); |
612 |
| - |
613 |
| - |
614 |
| - //add threshold plotlines |
615 |
| - var thresholdXScale = new Plottable.Scales.Linear().domainMin( 0 ).domainMax( 1 ); |
616 |
| - var thresholdPlot = new Plottable.Plots.Line() |
617 |
| - .x(function(d) { return d.x; }, thresholdXScale ) |
618 |
| - .y(function(d) { return d.y; }, yScale ) |
619 |
| - .attr('stroke','#dedede') |
620 |
| - .attr('stroke-width', LINE_STROKE_WIDTH); |
621 |
| - |
622 |
| - d3.entries( measureData ).forEach(function( entry ) { |
623 |
| - measure = entry.key; |
624 |
| - data = entry.value; |
625 |
| - |
626 |
| - var thresholds = getMeasureSettings( measure ).thresholds; |
627 |
| - |
628 |
| - if ( thresholds ){ |
629 |
| - |
630 |
| - thresholdPlot.addDataset( new Plottable.Dataset( [ |
631 |
| - { x:0, y:thresholds.max }, |
632 |
| - { x:1, y:thresholds.max } |
633 |
| - ] ) ); |
634 |
| - |
635 |
| - } |
636 |
| - |
637 | 668 | });
|
638 | 669 |
|
639 |
| - plots.push( thresholdPlot ); |
640 |
| - |
641 | 670 | plots.push( pointPlot );
|
642 | 671 |
|
643 | 672 | var colorScale = null;
|
|
690 | 719 |
|
691 | 720 |
|
692 | 721 | //build table
|
| 722 | + var xAxisVisible = interfaceSettings.axes.xAxis.visible; |
| 723 | + var yAxisVisible = interfaceSettings.axes.yAxis.visible; |
693 | 724 | var plotGroup = new Plottable.Components.Group( plots );
|
694 |
| - var yAxisGroup = new Plottable.Components.Group( [ yAxis, yLabel ] ); |
| 725 | + var yAxisGroup = yAxisVisible? new Plottable.Components.Group( [ yAxis, yLabel ] ): null; |
695 | 726 | var topRow = [ yAxisGroup, plotGroup ];
|
696 |
| - var bottomRow = [ null, xAxis ]; |
697 |
| - secondaryYAxes.forEach(function( axisComponents ){ |
698 |
| - topRow.push( new Plottable.Components.Group( [ axisComponents.axis, axisComponents.label ] ) ); |
699 |
| - bottomRow.push( null ); |
700 |
| - }); |
| 727 | + var bottomRow = [ null, xAxisVisible? xAxis: null ]; |
| 728 | + if( yAxisVisible ){ |
| 729 | + secondaryYAxes.forEach(function( axisComponents ){ |
| 730 | + topRow.push( new Plottable.Components.Group( [ axisComponents.axis, axisComponents.label ] ) ); |
| 731 | + bottomRow.push( null ); |
| 732 | + }); |
| 733 | + } |
701 | 734 | table = new Plottable.Components.Table([
|
702 | 735 | topRow,
|
703 | 736 | bottomRow
|
|
945 | 978 | };
|
946 | 979 |
|
947 | 980 | var highlightNewHoverPoint = function( point ) {
|
948 |
| - if( hoverPoint !== null ) { |
949 |
| - if( point.datum.omhDatum.body !== hoverPoint.datum.omhDatum.body ){ |
950 |
| - resetGroup( hoverPoint.datum.omhDatum.groupName, hoverPoint.index ); |
| 981 | + if( hoverPoint !== null ) { |
| 982 | + if( point.datum.omhDatum.body !== hoverPoint.datum.omhDatum.body ){ |
| 983 | + resetGroup( hoverPoint.datum.omhDatum.groupName, hoverPoint.index ); |
| 984 | + hoverPoint = point; |
| 985 | + highlightGroup( hoverPoint.datum.omhDatum.groupName, point.index ); |
| 986 | + } |
| 987 | + }else{ |
951 | 988 | hoverPoint = point;
|
952 |
| - highlightGroup( hoverPoint.datum.omhDatum.groupName, point.index ); |
953 | 989 | }
|
954 |
| - }else{ |
955 |
| - hoverPoint = point; |
956 |
| - } |
957 |
| - if ( point.datum === null ) { |
958 |
| - return; |
959 |
| - } |
| 990 | + if ( point.datum === null ) { |
| 991 | + return; |
| 992 | + } |
960 | 993 | };
|
961 | 994 |
|
962 | 995 | //set up plottable's hover-based point selection interaction
|
|
972 | 1005 | var nearestEntity;
|
973 | 1006 | try{
|
974 | 1007 | nearestEntity = pointPlot.entityNearest(p);
|
| 1008 | + highlightNewHoverPoint( nearestEntity ); |
| 1009 | + showHoverPointTooltip(); |
975 | 1010 | } catch( e ) {
|
976 | 1011 | return;
|
977 | 1012 | }
|
978 |
| - highlightNewHoverPoint( nearestEntity ); |
979 |
| - showHoverPointTooltip(); |
980 | 1013 | }.bind(this);
|
981 | 1014 | pointer.onPointerMove( pointerMove );
|
982 | 1015 | pointer.attachTo( pointPlot );
|
|
0 commit comments