Commit 7faacd55 authored by Evgeny's avatar Evgeny

Add title

parent 7e3a51fd
......@@ -56,6 +56,7 @@ module.exports = (grunt) ->
'src/class.js',
'src/util.js',
'src/api.focus.js',
'src/api.title.js',
'src/api.show.js',
'src/api.zoom.js',
'src/api.load.js',
......@@ -105,7 +106,7 @@ module.exports = (grunt) ->
src: 'c3.css'
dest: 'c3.min.css'
grunt.registerTask 'default', ['concat', 'test', 'posttest']
grunt.registerTask 'default', ['jshint', 'concat', 'test', 'posttest']
grunt.registerTask 'test', ['jasmine']
grunt.registerTask 'build', ['concat', 'posttest']
grunt.registerTask 'build', ['jshint', 'concat', 'posttest']
grunt.registerTask 'posttest', ['cssmin', 'uglify']
c3_chart_fn.title = function(title, hasSubs, isSub) {
var $$ = this.internal;
if (!arguments.length) {
if ($$.data.title) {
return $$.data.title.text();
} else
return undefined;
}
/* Remove title */
if (title === null) {
$$.data.title = undefined;
return;
}
$$.config.chartTitle = title;
$$.api.redrawTitle(hasSubs, isSub);
};
c3_chart_fn.title.show = function() {
var $$ = this.internal;
// Add padding for title
$$.config.padding_top = 42;
$$.cachedRedraw({withLegend: true});
if (!isUndefined($$.data.title)){
$$.data.title.style("display", "block");
}
};
c3_chart_fn.title.hide = function() {
var $$ = this.internal;
if ($$.data.title) {
$$.data.title.style("display", "none");
}
// Remove padding
$$.config.padding_top = 0;
$$.cachedRedraw({withLegend: true});
};
c3.chart.fn.redrawTitle = function(hasSubs, isSub){
var $$ = this.internal;
var title = $$.config.chartTitle;
var x = $$.currentWidth;
if(!hasSubs) x /= 2;
if(isSub) x = 0;
var y = 32;
if (!$$.data.title) {
$$.data.title = $$.svg.append('text')
.attr("class", 'c3-title')
.attr("text-anchor", 'middle')
.attr('x', x)
.attr('y', y);
$$.data.title.append('tspan').text(title);
} else {
$$.data.title
.text(title)
.attr('x', x)
.attr('y', y);
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment