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 44 45 46 47 48 49 50 51 52 53 54
import {BaseMixin} from './base-mixin';
/**
* Margin is a mixin that provides margin utility functions for both the Row Chart and Coordinate Grid
* Charts.
* @mixin MarginMixin
* @param {Object} Base
* @returns {MarginMixin}
*/
export class MarginMixin extends BaseMixin {
constructor () {
super();
this._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.
* @memberof 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}|MarginMixin}
*/
margins (margins) {
if (!arguments.length) {
return this._margin;
}
this._margin = margins;
return this;
}
/**
* Effective width of the chart excluding margins (in pixels).
*
* @returns {number}
*/
effectiveWidth () {
return this.width() - this.margins().left - this.margins().right;
}
/**
* Effective height of the chart excluding margins (in pixels).
*
* @returns {number}
*/
effectiveHeight () {
return this.height() - this.margins().top - this.margins().bottom;
}
}