|
|
@ -113,8 +113,8 @@ c3_chart_internal_fn.clearLegendItemTextBoxCache = function () { |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { |
|
|
|
c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { |
|
|
|
var $$ = this, config = $$.config; |
|
|
|
var $$ = this, config = $$.config; |
|
|
|
var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; |
|
|
|
var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect, x1ForLegendTile, x2ForLegendTile, yForLegendTile; |
|
|
|
var paddingTop = 4, paddingRight = 10, maxWidth = 0, maxHeight = 0, posMin = 10, tileWidth = 15; |
|
|
|
var paddingTop = 4, paddingRight = 10, maxWidth = 0, maxHeight = 0, posMin = 10, tileWidth = config.legend_item_tile_width + 5; |
|
|
|
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 texts, rects, tiles, background; |
|
|
|
var texts, rects, tiles, background; |
|
|
@ -133,7 +133,7 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { |
|
|
|
function updatePositions(textElement, id, index) { |
|
|
|
function updatePositions(textElement, id, index) { |
|
|
|
var reset = index === 0, isLast = index === targetIds.length - 1, |
|
|
|
var reset = index === 0, isLast = index === targetIds.length - 1, |
|
|
|
box = getTextBox(textElement, id), |
|
|
|
box = getTextBox(textElement, id), |
|
|
|
itemWidth = box.width + tileWidth + (isLast && !($$.isLegendRight || $$.isLegendInset) ? 0 : paddingRight), |
|
|
|
itemWidth = box.width + tileWidth + (isLast && !($$.isLegendRight || $$.isLegendInset) ? 0 : paddingRight) + config.legend_padding, |
|
|
|
itemHeight = box.height + paddingTop, |
|
|
|
itemHeight = box.height + paddingTop, |
|
|
|
itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, |
|
|
|
itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, |
|
|
|
areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(), |
|
|
|
areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(), |
|
|
@ -206,10 +206,13 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { |
|
|
|
xForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; |
|
|
|
xForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; |
|
|
|
yForLegend = function (id) { return maxHeight * steps[id]; }; |
|
|
|
yForLegend = function (id) { return maxHeight * steps[id]; }; |
|
|
|
} |
|
|
|
} |
|
|
|
xForLegendText = function (id, i) { return xForLegend(id, i) + 14; }; |
|
|
|
xForLegendText = function (id, i) { return xForLegend(id, i) + 4 + config.legend_item_tile_width; }; |
|
|
|
yForLegendText = function (id, i) { return yForLegend(id, i) + 9; }; |
|
|
|
yForLegendText = function (id, i) { return yForLegend(id, i) + 9; }; |
|
|
|
xForLegendRect = function (id, i) { return xForLegend(id, i); }; |
|
|
|
xForLegendRect = function (id, i) { return xForLegend(id, i); }; |
|
|
|
yForLegendRect = function (id, i) { return yForLegend(id, i) - 5; }; |
|
|
|
yForLegendRect = function (id, i) { return yForLegend(id, i) - 5; }; |
|
|
|
|
|
|
|
x1ForLegendTile = function (id, i) { return xForLegend(id, i) - 2; }; |
|
|
|
|
|
|
|
x2ForLegendTile = function (id, i) { return xForLegend(id, i) - 2 + config.legend_item_tile_width; }; |
|
|
|
|
|
|
|
yForLegendTile = function (id, i) { return yForLegend(id, i) + 4; }; |
|
|
|
|
|
|
|
|
|
|
|
// Define g for legend area
|
|
|
|
// Define g for legend area
|
|
|
|
l = $$.legend.selectAll('.' + CLASS.legendItem) |
|
|
|
l = $$.legend.selectAll('.' + CLASS.legendItem) |
|
|
@ -258,14 +261,10 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { |
|
|
|
.style('fill-opacity', 0) |
|
|
|
.style('fill-opacity', 0) |
|
|
|
.attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) |
|
|
|
.attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) |
|
|
|
.attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); |
|
|
|
.attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); |
|
|
|
l.append('rect') |
|
|
|
l.append('line') |
|
|
|
.attr("class", CLASS.legendItemTile) |
|
|
|
.attr('class', CLASS.legendItemTile) |
|
|
|
.style("pointer-events", "none") |
|
|
|
.style("pointer-events", "none") |
|
|
|
.style('fill', $$.color) |
|
|
|
.attr('stroke-width', config.legend_item_tile_height); |
|
|
|
.attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) |
|
|
|
|
|
|
|
.attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) |
|
|
|
|
|
|
|
.attr('width', 10) |
|
|
|
|
|
|
|
.attr('height', 10); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set background for inset legend
|
|
|
|
// Set background for inset legend
|
|
|
|
background = $$.legend.select('.' + CLASS.legendBackground + ' rect'); |
|
|
|
background = $$.legend.select('.' + CLASS.legendBackground + ' rect'); |
|
|
@ -291,12 +290,14 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { |
|
|
|
.attr('x', xForLegendRect) |
|
|
|
.attr('x', xForLegendRect) |
|
|
|
.attr('y', yForLegendRect); |
|
|
|
.attr('y', yForLegendRect); |
|
|
|
|
|
|
|
|
|
|
|
tiles = $$.legend.selectAll('rect.' + CLASS.legendItemTile) |
|
|
|
tiles = $$.legend.selectAll('line.' + CLASS.legendItemTile) |
|
|
|
.data(targetIds); |
|
|
|
.data(targetIds); |
|
|
|
(withTransition ? tiles.transition() : tiles) |
|
|
|
(withTransition ? tiles.transition() : tiles) |
|
|
|
.style('fill', $$.color) |
|
|
|
.style('stroke', $$.color) |
|
|
|
.attr('x', xForLegend) |
|
|
|
.attr('x1', x1ForLegendTile) |
|
|
|
.attr('y', yForLegend); |
|
|
|
.attr('y1', yForLegendTile) |
|
|
|
|
|
|
|
.attr('x2', x2ForLegendTile) |
|
|
|
|
|
|
|
.attr('y2', yForLegendTile); |
|
|
|
|
|
|
|
|
|
|
|
if (background) { |
|
|
|
if (background) { |
|
|
|
(withTransition ? background.transition() : background) |
|
|
|
(withTransition ? background.transition() : background) |
|
|
|