@@ -836,6 +836,12 @@ Graph3d.prototype.redraw = function() {
836
836
case Graph3d . STYLE . BAR :
837
837
pointDrawingMethod = Graph3d . prototype . _redrawBarGraphPoint ;
838
838
break ;
839
+ case Graph3d . STYLE . BARCOLOR :
840
+ pointDrawingMethod = Graph3d . prototype . _redrawBarColorGraphPoint ;
841
+ break ;
842
+ case Graph3d . STYLE . BARSIZE :
843
+ pointDrawingMethod = Graph3d . prototype . _redrawBarSizeGraphPoint ;
844
+ break ;
839
845
}
840
846
841
847
if ( pointDrawingMethod !== undefined ) {
@@ -851,9 +857,6 @@ Graph3d.prototype.redraw = function() {
851
857
}
852
858
else if ( this . style === Graph3d . STYLE . LINE ) {
853
859
this . _redrawDataLine ( ) ;
854
- } else if ( this . style === Graph3d . STYLE . BARCOLOR ||
855
- this . style === Graph3d . STYLE . BARSIZE ) {
856
- this . _redrawDataBar ( ) ;
857
860
}
858
861
else {
859
862
// style is DOT, DOTLINE, DOTCOLOR, DOTSIZE
@@ -1577,12 +1580,19 @@ Graph3d.prototype._redrawDataDot = function() {
1577
1580
} ;
1578
1581
1579
1582
1583
+ // -----------------------------------------------------------------------------
1584
+ // Methods for drawing points per graph style.
1585
+ // -----------------------------------------------------------------------------
1586
+
1580
1587
/**
1581
1588
* Draw a bar element in the view with the given properties.
1582
1589
*/
1583
1590
Graph3d . prototype . _redrawBar = function ( ctx , point , xWidth , yWidth , color , borderColor ) {
1584
1591
var i , j , surface , corners ;
1585
1592
1593
+ ctx . lineJoin = 'round' ;
1594
+ ctx . lineCap = 'round' ;
1595
+
1586
1596
// calculate all corner points
1587
1597
var me = this ;
1588
1598
var point3d = point . point ;
@@ -1661,24 +1671,50 @@ Graph3d.prototype._redrawBar = function(ctx, point, xWidth, yWidth, color, borde
1661
1671
1662
1672
1663
1673
/**
1664
- * Draw single datapoint for graph style 'Bar '.
1674
+ * Draw single datapoint for graph style 'bar '.
1665
1675
*/
1666
1676
Graph3d . prototype . _redrawBarGraphPoint = function ( ctx , point ) {
1667
- var i , j , surface , corners ;
1677
+ var xWidth = this . xBarWidth / 2 ;
1678
+ var yWidth = this . yBarWidth / 2 ;
1679
+
1680
+ // calculate Hue from the current value. At zMin the hue is 240, at zMax the hue is 0
1681
+ var hue = ( 1 - ( point . point . z - this . zMin ) * this . scale . z / this . verticalRatio ) * 240 ;
1682
+ var color = this . _hsv2rgb ( hue , 1 , 1 ) ;
1683
+ var borderColor = this . _hsv2rgb ( hue , 1 , 0.8 ) ;
1684
+
1685
+ this . _redrawBar ( ctx , point , xWidth , yWidth , color , borderColor ) ;
1686
+ } ;
1668
1687
1669
- ctx . lineJoin = 'round' ;
1670
- ctx . lineCap = 'round' ;
1671
1688
1689
+ /**
1690
+ * Draw single datapoint for graph style 'bar-color'.
1691
+ */
1692
+ Graph3d . prototype . _redrawBarColorGraphPoint = function ( ctx , point ) {
1672
1693
var xWidth = this . xBarWidth / 2 ;
1673
1694
var yWidth = this . yBarWidth / 2 ;
1674
1695
1696
+ // calculate the color based on the value
1697
+ var hue = ( 1 - ( point . point . value - this . valueMin ) * this . scale . value ) * 240 ;
1698
+ var color = this . _hsv2rgb ( hue , 1 , 1 ) ;
1699
+ var borderColor = this . _hsv2rgb ( hue , 1 , 0.8 ) ;
1700
+
1701
+ this . _redrawBar ( ctx , point , xWidth , yWidth , color , borderColor ) ;
1702
+ } ;
1703
+
1704
+
1705
+ /**
1706
+ * Draw single datapoint for graph style 'bar-size'.
1707
+ */
1708
+ Graph3d . prototype . _redrawBarSizeGraphPoint = function ( ctx , point ) {
1709
+ // calculate size for the bar
1710
+ var fraction = ( point . point . value - this . valueMin ) / ( this . valueMax - this . valueMin ) ;
1711
+ var xWidth = ( this . xBarWidth / 2 ) * ( fraction * 0.8 + 0.2 ) ;
1712
+ var yWidth = ( this . yBarWidth / 2 ) * ( fraction * 0.8 + 0.2 ) ;
1713
+
1675
1714
1676
1715
// determine color
1677
- var hue , color , borderColor ;
1678
- // calculate Hue from the current value. At zMin the hue is 240, at zMax the hue is 0
1679
- hue = ( 1 - ( point . point . z - this . zMin ) * this . scale . z / this . verticalRatio ) * 240 ;
1680
- color = this . _hsv2rgb ( hue , 1 , 1 ) ;
1681
- borderColor = this . _hsv2rgb ( hue , 1 , 0.8 ) ;
1716
+ var color = this . dataColor . fill ;
1717
+ var borderColor = this . dataColor . stroke ;
1682
1718
1683
1719
this . _redrawBar ( ctx , point , xWidth , yWidth , color , borderColor ) ;
1684
1720
} ;
@@ -1707,131 +1743,9 @@ Graph3d.prototype._redrawDataGraph = function(pointDrawMethod) {
1707
1743
} ;
1708
1744
1709
1745
1710
- /**
1711
- * Draw all datapoints as bars.
1712
- * This function can be used when the style is 'bar', 'bar-color', or 'bar-size'
1713
- */
1714
- Graph3d . prototype . _redrawDataBar = function ( ) {
1715
- var ctx = this . _getContext ( ) ;
1716
- var i , j , surface , corners ;
1717
-
1718
- if ( this . dataPoints === undefined || this . dataPoints . length <= 0 )
1719
- return ; // TODO: throw exception?
1720
-
1721
- this . _calcTranslations ( this . dataPoints ) ;
1722
-
1723
- ctx . lineJoin = 'round' ;
1724
- ctx . lineCap = 'round' ;
1725
-
1726
- // draw the datapoints as bars
1727
- var xWidth = this . xBarWidth / 2 ;
1728
- var yWidth = this . yBarWidth / 2 ;
1729
- for ( i = 0 ; i < this . dataPoints . length ; i ++ ) {
1730
- var point = this . dataPoints [ i ] ;
1731
-
1732
- // TODO: Remove code for style `Bar` here - it has been refactored to separate routine
1733
-
1734
- // determine color
1735
- var hue , color , borderColor ;
1736
- if ( this . style === Graph3d . STYLE . BARCOLOR ) {
1737
- // calculate the color based on the value
1738
- hue = ( 1 - ( point . point . value - this . valueMin ) * this . scale . value ) * 240 ;
1739
- color = this . _hsv2rgb ( hue , 1 , 1 ) ;
1740
- borderColor = this . _hsv2rgb ( hue , 1 , 0.8 ) ;
1741
- }
1742
- else if ( this . style === Graph3d . STYLE . BARSIZE ) {
1743
- color = this . dataColor . fill ;
1744
- borderColor = this . dataColor . stroke ;
1745
- }
1746
- else {
1747
- // calculate Hue from the current value. At zMin the hue is 240, at zMax the hue is 0
1748
- hue = ( 1 - ( point . point . z - this . zMin ) * this . scale . z / this . verticalRatio ) * 240 ;
1749
- color = this . _hsv2rgb ( hue , 1 , 1 ) ;
1750
- borderColor = this . _hsv2rgb ( hue , 1 , 0.8 ) ;
1751
- }
1752
-
1753
- // calculate size for the bar
1754
- if ( this . style === Graph3d . STYLE . BARSIZE ) {
1755
- xWidth = ( this . xBarWidth / 2 ) * ( ( point . point . value - this . valueMin ) / ( this . valueMax - this . valueMin ) * 0.8 + 0.2 ) ;
1756
- yWidth = ( this . yBarWidth / 2 ) * ( ( point . point . value - this . valueMin ) / ( this . valueMax - this . valueMin ) * 0.8 + 0.2 ) ;
1757
- }
1758
-
1759
- // calculate all corner points
1760
- var me = this ;
1761
- var point3d = point . point ;
1762
- var top = [
1763
- { point : new Point3d ( point3d . x - xWidth , point3d . y - yWidth , point3d . z ) } ,
1764
- { point : new Point3d ( point3d . x + xWidth , point3d . y - yWidth , point3d . z ) } ,
1765
- { point : new Point3d ( point3d . x + xWidth , point3d . y + yWidth , point3d . z ) } ,
1766
- { point : new Point3d ( point3d . x - xWidth , point3d . y + yWidth , point3d . z ) }
1767
- ] ;
1768
- var bottom = [
1769
- { point : new Point3d ( point3d . x - xWidth , point3d . y - yWidth , this . zMin ) } ,
1770
- { point : new Point3d ( point3d . x + xWidth , point3d . y - yWidth , this . zMin ) } ,
1771
- { point : new Point3d ( point3d . x + xWidth , point3d . y + yWidth , this . zMin ) } ,
1772
- { point : new Point3d ( point3d . x - xWidth , point3d . y + yWidth , this . zMin ) }
1773
- ] ;
1774
-
1775
- // calculate screen location of the points
1776
- top . forEach ( function ( obj ) {
1777
- obj . screen = me . _convert3Dto2D ( obj . point ) ;
1778
- } ) ;
1779
- bottom . forEach ( function ( obj ) {
1780
- obj . screen = me . _convert3Dto2D ( obj . point ) ;
1781
- } ) ;
1782
-
1783
- // create five sides, calculate both corner points and center points
1784
- var surfaces = [
1785
- { corners : top , center : Point3d . avg ( bottom [ 0 ] . point , bottom [ 2 ] . point ) } ,
1786
- { corners : [ top [ 0 ] , top [ 1 ] , bottom [ 1 ] , bottom [ 0 ] ] , center : Point3d . avg ( bottom [ 1 ] . point , bottom [ 0 ] . point ) } ,
1787
- { corners : [ top [ 1 ] , top [ 2 ] , bottom [ 2 ] , bottom [ 1 ] ] , center : Point3d . avg ( bottom [ 2 ] . point , bottom [ 1 ] . point ) } ,
1788
- { corners : [ top [ 2 ] , top [ 3 ] , bottom [ 3 ] , bottom [ 2 ] ] , center : Point3d . avg ( bottom [ 3 ] . point , bottom [ 2 ] . point ) } ,
1789
- { corners : [ top [ 3 ] , top [ 0 ] , bottom [ 0 ] , bottom [ 3 ] ] , center : Point3d . avg ( bottom [ 0 ] . point , bottom [ 3 ] . point ) }
1790
- ] ;
1791
- point . surfaces = surfaces ;
1792
-
1793
- // calculate the distance of each of the surface centers to the camera
1794
- for ( j = 0 ; j < surfaces . length ; j ++ ) {
1795
- surface = surfaces [ j ] ;
1796
- var transCenter = this . _convertPointToTranslation ( surface . center ) ;
1797
- surface . dist = this . showPerspective ? transCenter . length ( ) : - transCenter . z ;
1798
- // TODO: this dept calculation doesn't work 100% of the cases due to perspective,
1799
- // but the current solution is fast/simple and works in 99.9% of all cases
1800
- // the issue is visible in example 14, with graph.setCameraPosition({horizontal: 2.97, vertical: 0.5, distance: 0.9})
1801
- }
1802
-
1803
- // order the surfaces by their (translated) depth
1804
- surfaces . sort ( function ( a , b ) {
1805
- var diff = b . dist - a . dist ;
1806
- if ( diff ) return diff ;
1807
-
1808
- // if equal depth, sort the top surface last
1809
- if ( a . corners === top ) return 1 ;
1810
- if ( b . corners === top ) return - 1 ;
1811
-
1812
- // both are equal
1813
- return 0 ;
1814
- } ) ;
1815
-
1816
- // draw the ordered surfaces
1817
- ctx . lineWidth = this . _getStrokeWidth ( point ) ;
1818
- ctx . strokeStyle = borderColor ;
1819
- ctx . fillStyle = color ;
1820
- // NOTE: we start at j=2 instead of j=0 as we don't need to draw the two surfaces at the backside
1821
- for ( j = 2 ; j < surfaces . length ; j ++ ) {
1822
- surface = surfaces [ j ] ;
1823
- corners = surface . corners ;
1824
- ctx . beginPath ( ) ;
1825
- ctx . moveTo ( corners [ 3 ] . screen . x , corners [ 3 ] . screen . y ) ;
1826
- ctx . lineTo ( corners [ 0 ] . screen . x , corners [ 0 ] . screen . y ) ;
1827
- ctx . lineTo ( corners [ 1 ] . screen . x , corners [ 1 ] . screen . y ) ;
1828
- ctx . lineTo ( corners [ 2 ] . screen . x , corners [ 2 ] . screen . y ) ;
1829
- ctx . lineTo ( corners [ 3 ] . screen . x , corners [ 3 ] . screen . y ) ;
1830
- ctx . fill ( ) ;
1831
- ctx . stroke ( ) ;
1832
- }
1833
- }
1834
- } ;
1746
+ // -----------------------------------------------------------------------------
1747
+ // End methods for drawing points per graph style.
1748
+ // -----------------------------------------------------------------------------
1835
1749
1836
1750
1837
1751
/**
0 commit comments