-
Notifications
You must be signed in to change notification settings - Fork 0
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
test date input for time slider and adjust input element #1095
Changes from 1 commit
4839c8b
931de5b
a772b99
aafb235
2ba81b1
291d302
f82ccf6
1716200
9efbed8
f8801c5
b1b2c1e
d94500b
16088c0
2b32107
6bb10a9
eceed45
9366590
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 |
---|---|---|
|
@@ -44,9 +44,6 @@ export type TimeSliderProps = { | |
debounceRateMs?: number; | ||
/** all user-interaction disabled */ | ||
disabled?: boolean; | ||
/** for resetting disabled left and right arrow buttons when changing brush bounds */ | ||
setDisableLeftArrow?: (value: boolean) => void; | ||
setDisableRightArrow?: (value: boolean) => void; | ||
}; | ||
|
||
// using forwardRef | ||
|
@@ -66,8 +63,6 @@ function TimeSlider(props: TimeSliderProps) { | |
debounceRateMs = 500, | ||
disabled = false, | ||
xAxisRange, | ||
setDisableLeftArrow, | ||
setDisableRightArrow, | ||
} = props; | ||
|
||
const resizeTriggerAreas: ResizeTriggerAreas[] = disabled | ||
|
@@ -96,49 +91,6 @@ function TimeSlider(props: TimeSliderProps) { | |
const getXData = (d: TimeSliderDataProp) => new Date(d.x); | ||
const getYData = (d: TimeSliderDataProp) => d.y; | ||
|
||
const onBrushChange = useMemo( | ||
() => | ||
debounce((domain: Bounds | null) => { | ||
if (!domain) return; | ||
const { x0, x1 } = domain; | ||
|
||
// computing the offset of 2 pixel (SAFE_PIXEL) in domain (milliseconds) | ||
// https://github.com/airbnb/visx/blob/86a851cb3bf622b013b186f02f955bcd6548a87f/packages/visx-brush/src/Brush.tsx#L14 | ||
const brushOffset = | ||
xBrushScale.invert(2).getTime() - xBrushScale.invert(0).getTime(); | ||
|
||
// compensating the offset | ||
// x0 and x1 are millisecond value | ||
const startDate = millisecondTodate(x0 + brushOffset); | ||
const endDate = millisecondTodate(x1 - brushOffset); | ||
|
||
setSelectedRange({ | ||
// don't let range go outside the xAxisRange, if provided | ||
start: xAxisRange | ||
? startDate < xAxisRange.start | ||
? xAxisRange.start | ||
: startDate | ||
: startDate, | ||
end: xAxisRange | ||
? endDate > xAxisRange.end | ||
? xAxisRange.end | ||
: endDate | ||
: endDate, | ||
}); | ||
// resetting disabled left and arrow buttons | ||
if (setDisableLeftArrow) setDisableLeftArrow(false); | ||
if (setDisableRightArrow) setDisableRightArrow(false); | ||
}, debounceRateMs), | ||
[setSelectedRange, xAxisRange] | ||
); | ||
|
||
// Cancel any pending onBrushChange requests when this component is unmounted | ||
useEffect(() => { | ||
return () => { | ||
onBrushChange.cancel(); | ||
}; | ||
}, []); | ||
|
||
// bounds | ||
const xBrushMax = Math.max(width - margin.left - margin.right, 0); | ||
// take 70 % of given height considering axis tick/tick labels at the bottom | ||
|
@@ -189,6 +141,46 @@ function TimeSlider(props: TimeSliderProps) { | |
? selectedRange.start + ':' + selectedRange.end | ||
: 'no_brush'; | ||
|
||
const onBrushChange = useMemo( | ||
() => | ||
debounce((domain: Bounds | null) => { | ||
if (!domain) return; | ||
const { x0, x1 } = domain; | ||
|
||
// computing the offset of 2 pixel (SAFE_PIXEL) in domain (milliseconds) | ||
// https://github.com/airbnb/visx/blob/86a851cb3bf622b013b186f02f955bcd6548a87f/packages/visx-brush/src/Brush.tsx#L14 | ||
const brushOffset = | ||
xBrushScale.invert(2).getTime() - xBrushScale.invert(0).getTime(); | ||
|
||
// compensating the offset | ||
// x0 and x1 are millisecond value | ||
const startDate = millisecondTodate(x0 + brushOffset); | ||
const endDate = millisecondTodate(x1 - brushOffset); | ||
|
||
setSelectedRange({ | ||
// don't let range go outside the xAxisRange, if provided | ||
start: xAxisRange | ||
? startDate < xAxisRange.start | ||
? xAxisRange.start | ||
: startDate | ||
: startDate, | ||
end: xAxisRange | ||
? endDate > xAxisRange.end | ||
? xAxisRange.end | ||
: endDate | ||
: endDate, | ||
}); | ||
}, debounceRateMs), | ||
[setSelectedRange, xAxisRange, debounceRateMs, xBrushScale] | ||
); | ||
|
||
// Cancel any pending onBrushChange requests when this component is unmounted | ||
useEffect(() => { | ||
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. Nice! |
||
return () => { | ||
onBrushChange.cancel(); | ||
}; | ||
}, [onBrushChange]); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,12 +140,12 @@ export default function TimeSliderQuickFilter({ | |
}, | ||
}; | ||
}, [ | ||
variableMetadata?.variable, | ||
variable, | ||
subsettingClient, | ||
filters, | ||
extendedDisplayRange?.start, | ||
extendedDisplayRange?.end, | ||
extendedDisplayRange, | ||
studyId, | ||
variableMetadata, | ||
]); | ||
|
||
const timeSliderData = useQuery({ | ||
|
@@ -234,7 +234,11 @@ export default function TimeSliderQuickFilter({ | |
<p> | ||
Expand the panel with the{' '} | ||
<ChevronRight transform={'matrix(0,1,-1,0,0,0)'} /> tab or click{' '} | ||
<a style={{ cursor: 'pointer' }} onClick={() => setMinimized(false)}> | ||
<a | ||
href="/#" | ||
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. I this something your IDE inserted? I think that happened once before. I don't think we want it...? 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. @bobular Thank you for your reviews 👍 Yes it shows warning like "no href". The "/#" actually do nothing and it is one of recommended ways: otherwise, warning message recommends to use button element, but it is not the case for this. 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. In Firefox the 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. Oops, I didn't check Firefox. Okay then I will remove it and merge Thanks @bobular 👍 |
||
style={{ cursor: 'pointer' }} | ||
onClick={() => setMinimized(false)} | ||
> | ||
here | ||
</a>{' '} | ||
to reveal further controls that allow you to... | ||
|
@@ -270,9 +274,6 @@ export default function TimeSliderQuickFilter({ | |
end: newRange.max as string, | ||
}; | ||
updateConfig({ ...config, selectedRange: newSelectedRange }); | ||
// resetting disabled left and arrow buttons | ||
setDisableLeftArrow(false); | ||
setDisableRightArrow(false); | ||
} | ||
}, | ||
[config, updateConfig] | ||
|
@@ -290,7 +291,7 @@ export default function TimeSliderQuickFilter({ | |
updateConfig({ ...config, selectedRange: newSelectedRange }); | ||
} | ||
}, | ||
[config, updateConfig, extendedDisplayRange, selectedRange] | ||
[config, updateConfig, selectedRange] | ||
); | ||
|
||
// enabling/disabling date range arrows | ||
|
@@ -369,9 +370,6 @@ export default function TimeSliderQuickFilter({ | |
axisColor={!active ? '#888' : '#000'} | ||
// disable user-interaction | ||
disabled={!active} | ||
// for resetting disabled left and arrow buttons when changing brush bounds | ||
setDisableLeftArrow={setDisableLeftArrow} | ||
setDisableRightArrow={setDisableRightArrow} | ||
/> | ||
) : ( | ||
<Spinner size={25} /> | ||
|
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.
Thanks for spotting those missing deps!