11import _Object$assign from 'babel-runtime/core-js/object/assign' ;
2+ /**
3+ * @fileOverview Bar chart component definition
4+ *
5+ * @author Brian Greig
6+ *
7+ * @requires NPM:d3:Vue
8+ * @requires src/v-chart-plugin.js
9+ */
10+
211/* eslint-env browser */
312var d3 = _Object$assign ( { } , require ( 'd3-selection' ) , require ( 'd3-scale' ) , require ( 'd3-axis' ) , require ( 'd3-ease' ) ) ;
413/**
514 * Builds a Bar Chart.
6- * @constructor
7- * @param {String } mode (init / refresh)
8- * @exports barChart
15+ * @module barChart
916 */
1017
1118var barChart = function chart ( ) {
1219 var _this = this ;
1320
21+ /**
22+ * The SVG that stores the chart
23+ * @member svgContainer
24+ */
1425 var svgContainer = d3 . select ( '#' + this . chartData . selector ) ;
26+ /**
27+ * The configuration of the coordinate system
28+ * @member cs
29+ */
1530 var cs = {
1631 palette : {
1732 fill : '#005792' ,
@@ -33,79 +48,88 @@ var barChart = function chart() {
3348 } ;
3449
3550 /**
36- * @method getWidth
37- * @param {Object } d (svg element)
38- * @description Returns width of the bar
39- */
51+ * Returns width of the bar
52+ * @member getWidth
53+ * @function
54+ * @param {Object } d (svg element)
55+ */
4056 var getWidth = function getWidth ( d ) {
4157 return cs . x . scale ( d . metric ) ;
4258 } ;
4359
4460 /**
45- * @method getHeight
46- * @description Returns height of the bar
47- */
61+ * Returns height of the bar
62+ * @member getHeight
63+ * @function
64+ */
4865 var getHeight = function getHeight ( ) {
4966 return ( _this . displayHeight - cs . x . axisHeight - _this . header - cs . bar . vPadding ) / _this . ds . length - 1 ;
5067 } ;
5168
5269 /**
53- * @method getYCoord
54- * @param {Object } d (svg element)
55- * @param {Object } i (svg element)
56- * @description Returns y axis co-ordinate of the bar
57- */
70+ * Returns y axis co-ordinate of the bar
71+ * @member getYCoord
72+ * @function
73+ * @param {Object } d (svg element)
74+ * @param {Object } i (svg element)
75+ */
5876 var getYCoord = function getYCoord ( d , i ) {
5977 return i * ( _this . displayHeight - cs . x . axisHeight - _this . header ) / _this . ds . length + 1 + _this . header ;
6078 } ;
6179
6280 /**
63- * @method mouseOver
64- * @param {Object } d (svg element)
65- * @description Adds a tooltip on mouse over
66- */
81+ * Adds a tooltip on mouse over
82+ * @member mouseOver
83+ * @function
84+ * @param {Object } d (svg element)
85+ */
6786 var mouseOver = function mouseOver ( d ) {
6887 _this . addTooltip ( d , window . event ) ;
6988 } ;
7089
7190 /**
72- * @method mouseOut
73- * @param {Object } d (svg element)
74- * @description Removes tooltip on mouse out
75- */
91+ * Removes tooltip on mouse out
92+ * @member mouseOut
93+ * @function
94+ * @param {Object } d (svg element)
95+ */
7696 var mouseOut = function mouseOut ( d ) {
7797 _this . removeTooltip ( d ) ;
7898 } ;
7999 /**
80- * @method enter
100+ * Runs when a new element is added to the dataset
101+ * @member enter
102+ * @function
81103 * @param {Object } rects (svg element)
82- * @description Runs when a new element is added to the dataset
83104 */
84105 var enter = function enter ( rects ) {
85106 rects . enter ( ) . append ( 'rect' ) . attr ( 'fill' , cs . palette . fill ) . attr ( 'stroke' , cs . palette . stroke ) . attr ( 'class' , _this . selector ) . attr ( 'width' , getWidth ) . attr ( 'height' , getHeight ) . attr ( 'y' , getYCoord ) . attr ( 'x' , cs . y . axisWidth + cs . bar . hPadding ) . on ( 'mouseover' , mouseOver ) . on ( 'mouseout' , mouseOut ) ;
86107 return rects ;
87108 } ;
88109 /**
89- * @method transition
110+ * Runs when a value of an element in dataset is changed
111+ * @member transition
112+ * @function
90113 * @param {Object } rects (svg element)
91- * @description Runs when a value of an element in dataset is changed
92114 */
93115 var transition = function transition ( rects ) {
94116 rects . transition ( ) . attr ( 'width' , getWidth ) . attr ( 'height' , getHeight ) . attr ( 'y' , getYCoord ) . attr ( 'x' , cs . y . axisWidth + cs . bar . hPadding ) ;
95117 return rects ;
96118 } ;
97119 /**
98- * @method exit
120+ * Runs when an element is removed from the dataset
121+ * @member exit
122+ * @function
99123 * @param {Object } rect (svg element)
100- * @description Runs when an element is removed from the dataset
101124 */
102125 var exit = function exit ( rects ) {
103126 rects . exit ( ) . remove ( ) ;
104127 return rects ;
105128 } ;
106129 /**
107- * @method buildScales
108- * @description builds the scales for the x and y axes
130+ * Builds the scales for the x and y axes
131+ * @member buildScales
132+ * @function
109133 */
110134 var buildScales = function buildScales ( ) {
111135 cs . x . scale = d3 . scaleLinear ( ) . domain ( [ 0 , _this . max ] ) . range ( [ 0 , _this . width - cs . bar . hPadding - cs . y . axisWidth ] ) ;
@@ -118,8 +142,9 @@ var barChart = function chart() {
118142 cs . y . scale = d3 . scaleOrdinal ( ) . domain ( cs . y . domain ) . range ( cs . y . range ) ;
119143 } ;
120144 /**
121- * @method drawAxis
122- * @description draws the x and y axes on the svg
145+ * Draws the x and y axes on the svg
146+ * @member drawAxis
147+ * @function
123148 */
124149 var drawAxis = function drawAxis ( ) {
125150 cs . x . axis = d3 . axisBottom ( ) . ticks ( cs . x . ticks , 's' ) . scale ( cs . x . scale ) ;
@@ -131,7 +156,13 @@ var barChart = function chart() {
131156 if ( _this . ds [ 0 ] . dim ) svgContainer . append ( 'g' ) . attr ( 'class' , 'axis' ) . attr ( 'transform' , 'translate(' + cs . y . xOffset + ', ' + cs . y . yOffset + ')' ) . call ( cs . y . axis ) ;
132157 svgContainer . append ( 'g' ) . attr ( 'class' , 'axis' ) . attr ( 'transform' , 'translate(' + cs . x . xOffset + ', ' + cs . x . yOffset + ')' ) . call ( cs . x . axis ) ;
133158 } ;
134-
159+ /**
160+ * Get the maximum dimension length
161+ * @member getMaxDimLength
162+ * @function
163+ * @param {number } accumulator
164+ * @param {number } currentValue
165+ */
135166 var getMaxDimLength = function getMaxDimLength ( accumulator , currentValue ) {
136167 return currentValue . dim . length > accumulator ? currentValue . dim . length : accumulator ;
137168 } ;
0 commit comments