Skip to content

Commit 59db497

Browse files
committed
Allow title to be disabled by setting it to false.
1 parent c43a894 commit 59db497

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Allowed values - `'pie', 'bar', 'line', 'point', 'area'`
5454

5555
```js
5656
var config = {
57-
title: '', // chart title
57+
title: '', // chart title. If this is false, no title element will be created.
5858
tooltips: true,
5959
labels: false, // labels on data points
6060
// exposed events

src/templates/left.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="angular-charts-template">
2-
<div class='ac-title'>{{acConfig.title}}</div>
2+
<div class='ac-title' ng-if="acConfig.title !== false">{{acConfig.title}}</div>
33
<div class='ac-legend' ng-show='{{acConfig.legend.display}}'>
44
<table>
55
<tr ng-repeat="l in legends">

src/templates/right.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="angular-charts-template">
2-
<div class='ac-title'>{{acConfig.title}}</div>
2+
<div class='ac-title' ng-if="acConfig.title !== false">{{acConfig.title}}</div>
33
<div class='ac-chart'>
44
</div>
55
<div class='ac-legend' ng-show='{{acConfig.legend.display}}'>

test/angular-charts.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('angularCharts', function() {
7676
expect(compileChart).toThrow()
7777
})
7878

79-
it('should throw width/height error', function() {
79+
it('should not throw width/height error if the chart has a width/height', function() {
8080
angular.element(document.body).append('<style type="text/css">#chart { width:150px; height: 300px}</style>')
8181
expect(compileChart).not.toThrow()
8282
})
@@ -89,10 +89,6 @@ describe('angularCharts', function() {
8989
$chart_childrens = angular.element($chart).children()
9090
})
9191

92-
it('should have the right DOM title', function() {
93-
expect($chart.querySelector('.ac-title').innerText).toEqual('Not Products')
94-
})
95-
9692
it('should have the right elements in the legend', function() {
9793

9894
var $legendItems = $chart.querySelector('.ac-legend tbody').children
@@ -209,4 +205,32 @@ describe('angularCharts', function() {
209205

210206
})
211207

208+
describe('title', function() {
209+
beforeEach(function() {
210+
angular.element(document.body).append('<style type="text/css">#chart { width:150px; height: 300px}</style>');
211+
$scope.chartType = 'area';
212+
});
213+
214+
it('should set the title in the title element', function() {
215+
$scope.config.title = 'My Title';
216+
217+
compileChart();
218+
$scope.$digest();
219+
220+
$chart = document.getElementById('chart')
221+
expect($chart.querySelectorAll('.ac-title').length).toBe(1);
222+
expect($chart.querySelector('.ac-title').innerText).toEqual('My Title')
223+
});
224+
225+
it('should not have a title element if the title is an empty string or false', function() {
226+
$scope.config.title = false;
227+
228+
compileChart();
229+
$scope.$digest();
230+
231+
$chart = document.getElementById('chart');
232+
expect($chart.querySelectorAll('.ac-title').length).toBe(0);
233+
});
234+
235+
});
212236
})

0 commit comments

Comments
 (0)