Browse Source

Fix zoom - #598

pull/654/head
Masayuki Tanaka 10 years ago
parent
commit
1f4e222883
  1. 29
      c3.js
  2. 4
      c3.min.js
  3. 8
      src/core.js
  4. 21
      src/zoom.js

29
c3.js

@ -418,7 +418,7 @@
c3_chart_internal_fn.redraw = function (options, transitions) {
var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config;
var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType);
var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain, withLegend;
var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain, withLegend, withEventRect;
var hideAxis = $$.hasArcType();
var drawArea, drawBar, drawLine, xForText, yForText;
var duration, durationForExit, durationForAxis;
@ -437,6 +437,7 @@
withUpdateOrgXDomain = getOption(options, "withUpdateOrgXDomain", false);
withTrimXDomain = getOption(options, "withTrimXDomain", true);
withLegend = getOption(options, "withLegend", false);
withEventRect = getOption(options, "withEventRect", true);
withTransitionForExit = getOption(options, "withTransitionForExit", withTransition);
withTransitionForAxis = getOption(options, "withTransitionForAxis", withTransition);
@ -575,8 +576,9 @@
.remove();
// event rects will redrawn when flow called
if (config.interaction_enabled && !options.flow) {
if (config.interaction_enabled && !options.flow && withEventRect) {
$$.redrawEventRect();
if ($$.updateZoom) { $$.updateZoom(); }
}
// transition should be derived from one transition
@ -618,8 +620,6 @@
$$.mapToIds($$.data.targets).forEach(function (id) {
$$.withoutFadeIn[id] = true;
});
if ($$.updateZoom) { $$.updateZoom(); }
};
c3_chart_internal_fn.updateAndRedraw = function (options) {
@ -5087,23 +5087,19 @@
};
c3_chart_internal_fn.initZoom = function () {
var $$ = this, d3 = $$.d3, config = $$.config,
prevZoomTranslate, wheeled = false;
var $$ = this, d3 = $$.d3, config = $$.config;
$$.zoom = d3.behavior.zoom()
.on("zoomstart", function () {
$$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null;
config.zoom_onzoomstart.call($$.api, d3.event.sourceEvent);
})
.on("zoom", function () {
// prevZoomTranslate is needed for the fix of unexpected zoom.translate after remaining zoom
if (prevZoomTranslate && wheeled) {
$$.zoom.translate(prevZoomTranslate);
}
$$.redrawForZoom.call($$);
prevZoomTranslate = $$.zoom.translate();
wheeled = d3.event.sourceEvent.type === 'wheel';
})
.on('zoomend', function () {
$$.redrawEventRect();
$$.updateZoom();
config.zoom_onzoomend.call($$.api, $$.x.orgDomain());
});
$$.zoom.scale = function (scale) {
@ -5126,7 +5122,7 @@
$$.main.selectAll('.' + CLASS.eventRect).call(z);
};
c3_chart_internal_fn.redrawForZoom = function () {
var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain;
var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x;
if (!config.zoom_enabled) {
return;
}
@ -5138,13 +5134,14 @@
zoom.scale(x).updateScaleExtent();
return;
}
if ($$.isCategorized() && x.orgDomain()[0] === orgXDomain[0]) {
x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]);
if ($$.isCategorized() && x.orgDomain()[0] === $$.orgXDomain[0]) {
x.domain([$$.orgXDomain[0] - 1e-10, x.orgDomain()[1]]);
}
$$.redraw({
withTransition: false,
withY: config.zoom_rescale,
withSubchart: false
withSubchart: false,
withEventRect: false
});
if (d3.event.sourceEvent.type === 'mousemove') {
$$.cancelClick = true;

4
c3.min.js vendored

File diff suppressed because one or more lines are too long

8
src/core.js

@ -413,7 +413,7 @@ c3_chart_internal_fn.updateTargets = function (targets) {
c3_chart_internal_fn.redraw = function (options, transitions) {
var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config;
var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType);
var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain, withLegend;
var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain, withLegend, withEventRect;
var hideAxis = $$.hasArcType();
var drawArea, drawBar, drawLine, xForText, yForText;
var duration, durationForExit, durationForAxis;
@ -432,6 +432,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
withUpdateOrgXDomain = getOption(options, "withUpdateOrgXDomain", false);
withTrimXDomain = getOption(options, "withTrimXDomain", true);
withLegend = getOption(options, "withLegend", false);
withEventRect = getOption(options, "withEventRect", true);
withTransitionForExit = getOption(options, "withTransitionForExit", withTransition);
withTransitionForAxis = getOption(options, "withTransitionForAxis", withTransition);
@ -570,8 +571,9 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
.remove();
// event rects will redrawn when flow called
if (config.interaction_enabled && !options.flow) {
if (config.interaction_enabled && !options.flow && withEventRect) {
$$.redrawEventRect();
if ($$.updateZoom) { $$.updateZoom(); }
}
// transition should be derived from one transition
@ -613,8 +615,6 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
$$.mapToIds($$.data.targets).forEach(function (id) {
$$.withoutFadeIn[id] = true;
});
if ($$.updateZoom) { $$.updateZoom(); }
};
c3_chart_internal_fn.updateAndRedraw = function (options) {

21
src/zoom.js

@ -1,21 +1,17 @@
c3_chart_internal_fn.initZoom = function () {
var $$ = this, d3 = $$.d3, config = $$.config,
prevZoomTranslate, wheeled = false;
var $$ = this, d3 = $$.d3, config = $$.config;
$$.zoom = d3.behavior.zoom()
.on("zoomstart", function () {
$$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null;
config.zoom_onzoomstart.call($$.api, d3.event.sourceEvent);
})
.on("zoom", function () {
// prevZoomTranslate is needed for the fix of unexpected zoom.translate after remaining zoom
if (prevZoomTranslate && wheeled) {
$$.zoom.translate(prevZoomTranslate);
}
$$.redrawForZoom.call($$);
prevZoomTranslate = $$.zoom.translate();
wheeled = d3.event.sourceEvent.type === 'wheel';
})
.on('zoomend', function () {
$$.redrawEventRect();
$$.updateZoom();
config.zoom_onzoomend.call($$.api, $$.x.orgDomain());
});
$$.zoom.scale = function (scale) {
@ -38,7 +34,7 @@ c3_chart_internal_fn.updateZoom = function () {
$$.main.selectAll('.' + CLASS.eventRect).call(z);
};
c3_chart_internal_fn.redrawForZoom = function () {
var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain;
var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x;
if (!config.zoom_enabled) {
return;
}
@ -50,13 +46,14 @@ c3_chart_internal_fn.redrawForZoom = function () {
zoom.scale(x).updateScaleExtent();
return;
}
if ($$.isCategorized() && x.orgDomain()[0] === orgXDomain[0]) {
x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]);
if ($$.isCategorized() && x.orgDomain()[0] === $$.orgXDomain[0]) {
x.domain([$$.orgXDomain[0] - 1e-10, x.orgDomain()[1]]);
}
$$.redraw({
withTransition: false,
withY: config.zoom_rescale,
withSubchart: false
withSubchart: false,
withEventRect: false
});
if (d3.event.sourceEvent.type === 'mousemove') {
$$.cancelClick = true;

Loading…
Cancel
Save