forked from dc-js/dc.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
margin-mixin.js
43 lines (39 loc) · 1.36 KB
/
margin-mixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Margin is a mixin that provides margin utility functions for both the Row Chart and Coordinate Grid
* Charts.
* @name marginMixin
* @memberof dc
* @mixin
* @param {Object} _chart
* @returns {dc.marginMixin}
*/
dc.marginMixin = function (_chart) {
var _margin = {top: 10, right: 50, bottom: 30, left: 30};
/**
* Get or set the margins for a particular coordinate grid chart instance. The margins is stored as
* an associative Javascript array.
* @method margins
* @memberof dc.marginMixin
* @instance
* @example
* var leftMargin = chart.margins().left; // 30 by default
* chart.margins().left = 50;
* leftMargin = chart.margins().left; // now 50
* @param {{top: Number, right: Number, left: Number, bottom: Number}} [margins={top: 10, right: 50, bottom: 30, left: 30}]
* @returns {{top: Number, right: Number, left: Number, bottom: Number}|dc.marginMixin}
*/
_chart.margins = function (margins) {
if (!arguments.length) {
return _margin;
}
_margin = margins;
return _chart;
};
_chart.effectiveWidth = function () {
return _chart.width() - _chart.margins().left - _chart.margins().right;
};
_chart.effectiveHeight = function () {
return _chart.height() - _chart.margins().top - _chart.margins().bottom;
};
return _chart;
};