-
Notifications
You must be signed in to change notification settings - Fork 236
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
[RFR] Responsive chart #249
Changes from 4 commits
d98f6d9
3afe593
5935c75
953e672
6a437fd
d5f3d5f
34a2036
569054a
d04a819
ed82c73
9b7dee7
de5fb75
36ffb89
871acb9
fdbf768
91f2365
eacc059
2be4abb
fd56c95
1ff0a37
f18f262
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,3 +326,9 @@ This parameter configures the minimum zoom level available. Set it to a not-null | |
_Default: Infinity_ | ||
|
||
This parameter configures the maximum zoom level available. Set it to a lower value to prevent your users from zooming in too deeply. | ||
|
||
### destroy | ||
|
||
_Default: () => {}_ | ||
|
||
Function to be executed when you want to destroy the chart. By default, it remove `resize` event and execute the callback. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Function to be executed when you want to destroy the chart. By default, it remove |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,10 @@ import { withinRange } from './withinRange'; | |
|
||
// do not export anything else here to keep window.eventDrops as a function | ||
export default ({ d3 = window.d3, ...customConfiguration }) => { | ||
const chart = selection => { | ||
const initChart = selection => { | ||
const root = selection.selectAll('svg').data(selection.data()); | ||
root.exit().remove(); | ||
|
||
const config = defaultsDeep( | ||
customConfiguration || {}, | ||
defaultConfiguration(d3) | ||
|
@@ -41,10 +44,6 @@ export default ({ d3 = window.d3, ...customConfiguration }) => { | |
|
||
chart._scale = xScale; | ||
|
||
const root = selection.selectAll('svg').data(selection.data()); | ||
|
||
root.exit().remove(); | ||
|
||
const svg = root | ||
.enter() | ||
.append('svg') | ||
|
@@ -73,8 +72,26 @@ export default ({ d3 = window.d3, ...customConfiguration }) => { | |
.call(draw(config, xScale)); | ||
}; | ||
|
||
const chart = selection => { | ||
initChart(selection); | ||
|
||
const updateChart = () => { | ||
selection.selectAll('svg').remove(); | ||
initChart(selection); | ||
}; | ||
|
||
window.addEventListener('resize', updateChart, true); | ||
|
||
chart._removeOnResize = () => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need a function for this single line? :) |
||
window.removeEventListener('resize', updateChart, true); | ||
}; | ||
|
||
chart.scale = () => chart._scale; | ||
chart.filteredData = () => chart._filteredData; | ||
chart.destroy = callback => { | ||
chart._removeOnResize(); | ||
callback(); | ||
}; | ||
|
||
const draw = (config, scale) => selection => { | ||
const { drop: { date: dropDate } } = config; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move it to: https://github.com/marmelab/EventDrops/blob/master/README.md#interface