Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom improvements #269

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Optional transition on zoom
Added optional arguments to zoomToDomain to allow for transition.
  • Loading branch information
Busteren committed May 15, 2019
commit 9d6ac891b9be31b57e7d210da3ef71d3b1dc8c49
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ In addition to this configuration object, it also exposes some public members al
* **scale()** provides the horizontal scale, allowing you to retrieve bounding dates thanks to `.scale().domain()`,
* **filteredData()** returns an object with both `data` and `fullData` keys containing respectively bounds filtered data and full dataset.
* **draw(config, scale)** redraws chart using given configuration and `d3.scaleTime` scale
* **zoomToDomain(domain)** programmatically zooms to domain, where domain is `[date, date]` (leftmost date, rightmost date). Ignores restrictPan modifier (default D3 behaviour).
* **zoomToDomain(domain, duration = 0, delay = 0, ease = d3.easeLinear)** programmatically zooms to domain, where domain is `[date, date]` (leftmost date, rightmost date). Ignores restrictPan modifier (default D3 behaviour). By default there is no transition as duration is 0, however this can be tweaked to allow for a more visual appealing zoom.
* **destroy()** execute this function before to removing the chart from DOM. It prevents some memory leaks due to event listeners.
* **currentBreakpointLabel** returns current breakpoint (for instance `small`) among a [list of breakpoints](./docs/configuration.md#breakpoints).

Expand Down
18 changes: 14 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default ({
)
);

chart._zoomToDomain = domain => {
chart._zoomToDomain = (domain, duration, delay, ease) => {
const zoomIdentity = getDomainTransform(
d3,
config,
Expand All @@ -95,7 +95,12 @@ export default ({
xScale,
width
);
svg.call(zoomObject.transform, zoomIdentity);
svg
.transition()
.ease(ease)
.delay(delay)
.duration(duration)
.call(zoomObject.transform, zoomIdentity);
};
}

Expand Down Expand Up @@ -126,9 +131,14 @@ export default ({

chart.scale = () => chart._scale;
chart.filteredData = () => chart._filteredData;
chart.zoomToDomain = domain => {
chart.zoomToDomain = (
domain,
duration = 0,
delay = 0,
ease = d3.easeLinear
) => {
if (chart._zoomToDomain) {
chart._zoomToDomain(domain);
chart._zoomToDomain(domain, duration, delay, ease);
}
};
chart.destroy = (callback = () => {}) => {
Expand Down