Skip to content

Commit

Permalink
Fix inset legend step - #326
Browse files Browse the repository at this point in the history
  • Loading branch information
masayuki0812 committed Jun 9, 2014
1 parent faf7af1 commit 98d3519
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
19 changes: 15 additions & 4 deletions c3.js
Expand Up @@ -184,8 +184,9 @@
var __legend_show = getConfig(['legend', 'show'], true),
__legend_position = getConfig(['legend', 'position'], 'bottom'),
__legend_inset_anchor = getConfig(['legend', 'inset', 'anchor'], 'top-left'),
__legend_inset_x = getConfig(['legend', 'inset', 'x'], 0),
__legend_inset_x = getConfig(['legend', 'inset', 'x'], 10),
__legend_inset_y = getConfig(['legend', 'inset', 'y'], 0),
__legend_inset_step = getConfig(['legend', 'inset', 'step']),
__legend_item_onclick = getConfig(['legend', 'item', 'onclick']),
__legend_item_onmouseover = getConfig(['legend', 'item', 'onmouseover']),
__legend_item_onmouseout = getConfig(['legend', 'item', 'onmouseout']),
Expand Down Expand Up @@ -670,7 +671,17 @@
return __legend_show ? isLegendRight || isLegendInset ? legendItemWidth * (legendStep + 1) : currentWidth : 0;
}
function getLegendHeight() {
return __legend_show ? isLegendRight ? currentHeight : isLegendInset ? (c3.data.targets.length * Math.max(20, legendItemHeight)) + 20 : Math.max(20, legendItemHeight) * (legendStep + 1) : 0;
var h = 0;
if (__legend_show) {
if (isLegendRight) {
h = currentHeight;
} else if (isLegendInset) {
h = __legend_inset_step ? Math.max(20, legendItemHeight) * (__legend_inset_step + 1) : height;
} else {
h = Math.max(20, legendItemHeight) * (legendStep + 1);
}
}
return h;
}

//-- Scales --//
Expand Down Expand Up @@ -4581,7 +4592,7 @@
}
}
steps[id] = step;
margins[step] = margin;
margins[step] = isLegendInset ? 10 : margin;
offsets[id] = totalLength;
totalLength += itemLength;
}
Expand Down Expand Up @@ -4693,7 +4704,7 @@
.style('stroke', 'lightgray')
.style('stroke-width', 1)
.attr('height', getLegendHeight() - 10)
.attr('width', maxWidth);
.attr('width', maxWidth * (step + 1) + 10);
}

texts = legend.selectAll('text')
Expand Down

0 comments on commit 98d3519

Please sign in to comment.