Browse Source

only updateLegend when we actually want to show the legend for the first time

pull/779/head
Bob Renwick 10 years ago
parent
commit
c6d017dc05
  1. 10
      c3.js
  2. 6
      c3.min.js
  3. 10
      src/legend.js

10
c3.js

@ -3662,13 +3662,19 @@
c3_chart_internal_fn.initLegend = function () { c3_chart_internal_fn.initLegend = function () {
var $$ = this; var $$ = this;
$$.legendHasRendered = false;
$$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend')); $$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend'));
if (!$$.config.legend_show) { if (!$$.config.legend_show) {
$$.legend.style('visibility', 'hidden'); $$.legend.style('visibility', 'hidden');
$$.hiddenLegendIds = $$.mapToIds($$.data.targets); $$.hiddenLegendIds = $$.mapToIds($$.data.targets);
return;
} }
// MEMO: call here to update legend box and tranlate for all // MEMO: call here to update legend box and tranlate for all
// MEMO: translate will be upated by this, so transform not needed in updateLegend() // MEMO: translate will be upated by this, so transform not needed in updateLegend()
$$.updateLegendWithDefaults();
};
c3_chart_internal_fn.updateLegendWithDefaults = function () {
var $$ = this;
$$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false});
}; };
c3_chart_internal_fn.updateSizeForLegend = function (legendHeight, legendWidth) { c3_chart_internal_fn.updateSizeForLegend = function (legendHeight, legendWidth) {
@ -3745,6 +3751,9 @@
if (!config.legend_show) { if (!config.legend_show) {
config.legend_show = true; config.legend_show = true;
$$.legend.style('visibility', 'visible'); $$.legend.style('visibility', 'visible');
if (!$$.legendHasRendered) {
$$.updateLegendWithDefaults();
}
} }
$$.removeHiddenLegendIds(targetIds); $$.removeHiddenLegendIds(targetIds);
$$.legend.selectAll($$.selectorLegends(targetIds)) $$.legend.selectAll($$.selectorLegends(targetIds))
@ -3981,6 +3990,7 @@
$$.updateSvgSize(); $$.updateSvgSize();
// Update g positions // Update g positions
$$.transformAll(withTransitionForTransform, transitions); $$.transformAll(withTransitionForTransform, transitions);
$$.legendHasRendered = true;
}; };
c3_chart_internal_fn.initAxis = function () { c3_chart_internal_fn.initAxis = function () {

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

10
src/legend.js

@ -1,12 +1,18 @@
c3_chart_internal_fn.initLegend = function () { c3_chart_internal_fn.initLegend = function () {
var $$ = this; var $$ = this;
$$.legendHasRendered = false;
$$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend')); $$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend'));
if (!$$.config.legend_show) { if (!$$.config.legend_show) {
$$.legend.style('visibility', 'hidden'); $$.legend.style('visibility', 'hidden');
$$.hiddenLegendIds = $$.mapToIds($$.data.targets); $$.hiddenLegendIds = $$.mapToIds($$.data.targets);
return;
} }
// MEMO: call here to update legend box and tranlate for all // MEMO: call here to update legend box and tranlate for all
// MEMO: translate will be upated by this, so transform not needed in updateLegend() // MEMO: translate will be upated by this, so transform not needed in updateLegend()
$$.updateLegendWithDefaults();
};
c3_chart_internal_fn.updateLegendWithDefaults = function () {
var $$ = this;
$$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false});
}; };
c3_chart_internal_fn.updateSizeForLegend = function (legendHeight, legendWidth) { c3_chart_internal_fn.updateSizeForLegend = function (legendHeight, legendWidth) {
@ -83,6 +89,9 @@ c3_chart_internal_fn.showLegend = function (targetIds) {
if (!config.legend_show) { if (!config.legend_show) {
config.legend_show = true; config.legend_show = true;
$$.legend.style('visibility', 'visible'); $$.legend.style('visibility', 'visible');
if (!$$.legendHasRendered) {
$$.updateLegendWithDefaults();
}
} }
$$.removeHiddenLegendIds(targetIds); $$.removeHiddenLegendIds(targetIds);
$$.legend.selectAll($$.selectorLegends(targetIds)) $$.legend.selectAll($$.selectorLegends(targetIds))
@ -319,4 +328,5 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
$$.updateSvgSize(); $$.updateSvgSize();
// Update g positions // Update g positions
$$.transformAll(withTransitionForTransform, transitions); $$.transformAll(withTransitionForTransform, transitions);
$$.legendHasRendered = true;
}; };

Loading…
Cancel
Save