Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to customize chart margins through config object #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ Allowed values - `'pie', 'bar', 'line', 'point', 'area'`
yAxisTickFormat: 's', //refer tickFormats in d3 to edit this value
xAxisMaxTicks: 7, // Optional: maximum number of X axis ticks to show if data points exceed this number
yAxisTickFormat: 's', // refer tickFormats in d3 to edit this value
waitForHeightAndWidth: false // if true, it will not throw an error when the height or width are not defined (e.g. while creating a modal form), and it will be keep watching for valid height and width values
waitForHeightAndWidth: false, // if true, it will not throw an error when the height or width are not defined (e.g. while creating a modal form), and it will be keep watching for valid height and width values
margin: { // Optional: If any margins are present they will override the default margins, expressed in pixels
top: 0,
left: 20,
bottom: 40,
right: 20
}
};
```

Expand Down
20 changes: 12 additions & 8 deletions src/angular-charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,13 @@ angular.module('angularCharts').directive('acChart', function($templateCache, $c
* Setup date attributes
* @type {Object}
*/
var margin = {
var margin = angular.extend({
top: 0,
right: 20,
bottom: 30,
left: 40
};
}, config.margin);

width -= margin.left + margin.right;
height -= margin.top + margin.bottom;

Expand Down Expand Up @@ -430,12 +431,13 @@ angular.module('angularCharts').directive('acChart', function($templateCache, $c
* @return {[type]} [description]
*/
function lineChart() {
var margin = {
var margin = angular.extend({
top: 0,
right: 40,
bottom: 20,
left: 40
};
}, config.margin);

width -= margin.left + margin.right;
height -= margin.top + margin.bottom;

Expand Down Expand Up @@ -655,12 +657,13 @@ angular.module('angularCharts').directive('acChart', function($templateCache, $c
* @return {[type]} [description]
*/
function areaChart() {
var margin = {
var margin = angular.extend({
top: 0,
right: 40,
bottom: 20,
left: 40
};
}, config.margin);

width -= margin.left + margin.right;
height -= margin.top + margin.bottom;

Expand Down Expand Up @@ -903,12 +906,13 @@ angular.module('angularCharts').directive('acChart', function($templateCache, $c


function pointChart() {
var margin = {
var margin = angular.extend({
top: 0,
right: 40,
bottom: 20,
left: 40
};
}, config.margin);

width -= margin.left - margin.right;
height -= margin.top - margin.bottom;

Expand Down