-
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 1 commit
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 |
---|---|---|
|
@@ -327,8 +327,8 @@ _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. | ||
|
||
### removeOnResize | ||
### destroy | ||
|
||
_Default: () => {}_ | ||
|
||
Function to be executed when you want to remove [`resize`](https://developer.mozilla.org/en-US/docs/Web/Events/resize) event. | ||
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,15 +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 onResize = callback => { | ||
window.addEventListener('resize', callback, true); | ||
}; | ||
|
||
const removeOnResize = callback => { | ||
window.removeEventListener('resize', callback, true); | ||
}; | ||
const initChart = selection => { | ||
const root = selection.selectAll('svg').data(selection.data()); | ||
root.exit().remove(); | ||
|
||
const createChart = (root, selection) => { | ||
const config = defaultsDeep( | ||
customConfiguration || {}, | ||
defaultConfiguration(d3) | ||
|
@@ -78,23 +73,25 @@ export default ({ d3 = window.d3, ...customConfiguration }) => { | |
}; | ||
|
||
const chart = selection => { | ||
const root = selection.selectAll('svg').data(selection.data()); | ||
root.exit().remove(); | ||
|
||
createChart(root, selection); | ||
initChart(selection); | ||
|
||
const updateChart = () => { | ||
selection.selectAll('svg').remove(); | ||
createChart(root, selection); | ||
initChart(selection); | ||
}; | ||
|
||
onResize(updateChart); | ||
chart._removeOnResize = () => removeOnResize(updateChart); | ||
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.removeOnResize = () => chart._removeOnResize(); | ||
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