Browse Source

Fix legend background for inset - #326

pull/647/merge
Masayuki Tanaka 10 years ago
parent
commit
b0fd1b787e
  1. 20
      c3.js
  2. 6
      c3.min.js
  3. 2
      src/clip.js
  4. 18
      src/legend.js

20
c3.js

@ -3712,7 +3712,7 @@
var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0;
var withTransition, withTransitionForTransform; var withTransition, withTransitionForTransform;
var hasFocused = $$.legend.selectAll('.' + CLASS.legendItemFocused).size(); var hasFocused = $$.legend.selectAll('.' + CLASS.legendItemFocused).size();
var texts, rects, tiles; var texts, rects, tiles, background;
options = options || {}; options = options || {};
withTransition = getOption(options, "withTransition", true); withTransition = getOption(options, "withTransition", true);
@ -3854,13 +3854,13 @@
.attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend)
.attr('width', 10) .attr('width', 10)
.attr('height', 10); .attr('height', 10);
// Set background for inset legend // Set background for inset legend
if ($$.isLegendInset && maxWidth !== 0) { background = $$.legend.select('.' + CLASS.legendBackground + ' rect');
$$.legend.insert('g', '.' + CLASS.legendItem) if ($$.isLegendInset && maxWidth > 0 && background.size() === 0) {
background = $$.legend.insert('g', '.' + CLASS.legendItem)
.attr("class", CLASS.legendBackground) .attr("class", CLASS.legendBackground)
.append('rect') .append('rect');
.attr('height', $$.getLegendHeight() - 12)
.attr('width', maxWidth * (step + 1) + 10);
} }
texts = $$.legend.selectAll('text') texts = $$.legend.selectAll('text')
@ -3886,6 +3886,12 @@
.attr('x', xForLegend) .attr('x', xForLegend)
.attr('y', yForLegend); .attr('y', yForLegend);
if (background) {
(withTransition ? background.transition() : background)
.attr('height', $$.getLegendHeight() - 12)
.attr('width', maxWidth * (step + 1) + 10);
}
// toggle legend state // toggle legend state
$$.legend.selectAll('.' + CLASS.legendItem) $$.legend.selectAll('.' + CLASS.legendItem)
.classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); }) .classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); })
@ -4288,7 +4294,7 @@
return forHorizontal ? -(1 + left) : -(left - 1); return forHorizontal ? -(1 + left) : -(left - 1);
}; };
c3_chart_internal_fn.getAxisClipY = function (forHorizontal) { c3_chart_internal_fn.getAxisClipY = function (forHorizontal) {
return forHorizontal ? -20 : -4; return forHorizontal ? -10 : -4;
}; };
c3_chart_internal_fn.getXAxisClipX = function () { c3_chart_internal_fn.getXAxisClipX = function () {
var $$ = this; var $$ = this;

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

2
src/clip.js

@ -11,7 +11,7 @@ c3_chart_internal_fn.getAxisClipX = function (forHorizontal) {
return forHorizontal ? -(1 + left) : -(left - 1); return forHorizontal ? -(1 + left) : -(left - 1);
}; };
c3_chart_internal_fn.getAxisClipY = function (forHorizontal) { c3_chart_internal_fn.getAxisClipY = function (forHorizontal) {
return forHorizontal ? -20 : -4; return forHorizontal ? -10 : -4;
}; };
c3_chart_internal_fn.getXAxisClipX = function () { c3_chart_internal_fn.getXAxisClipX = function () {
var $$ = this; var $$ = this;

18
src/legend.js

@ -107,7 +107,7 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0;
var withTransition, withTransitionForTransform; var withTransition, withTransitionForTransform;
var hasFocused = $$.legend.selectAll('.' + CLASS.legendItemFocused).size(); var hasFocused = $$.legend.selectAll('.' + CLASS.legendItemFocused).size();
var texts, rects, tiles; var texts, rects, tiles, background;
options = options || {}; options = options || {};
withTransition = getOption(options, "withTransition", true); withTransition = getOption(options, "withTransition", true);
@ -249,13 +249,13 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
.attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend)
.attr('width', 10) .attr('width', 10)
.attr('height', 10); .attr('height', 10);
// Set background for inset legend // Set background for inset legend
if ($$.isLegendInset && maxWidth !== 0) { background = $$.legend.select('.' + CLASS.legendBackground + ' rect');
$$.legend.insert('g', '.' + CLASS.legendItem) if ($$.isLegendInset && maxWidth > 0 && background.size() === 0) {
background = $$.legend.insert('g', '.' + CLASS.legendItem)
.attr("class", CLASS.legendBackground) .attr("class", CLASS.legendBackground)
.append('rect') .append('rect');
.attr('height', $$.getLegendHeight() - 12)
.attr('width', maxWidth * (step + 1) + 10);
} }
texts = $$.legend.selectAll('text') texts = $$.legend.selectAll('text')
@ -281,6 +281,12 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
.attr('x', xForLegend) .attr('x', xForLegend)
.attr('y', yForLegend); .attr('y', yForLegend);
if (background) {
(withTransition ? background.transition() : background)
.attr('height', $$.getLegendHeight() - 12)
.attr('width', maxWidth * (step + 1) + 10);
}
// toggle legend state // toggle legend state
$$.legend.selectAll('.' + CLASS.legendItem) $$.legend.selectAll('.' + CLASS.legendItem)
.classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); }) .classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); })

Loading…
Cancel
Save