-
-
Notifications
You must be signed in to change notification settings - Fork 112
Fix date handling #804
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
Fix date handling #804
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Field from './Field'; | ||
import {UnconnectedNumeric} from './Numeric'; | ||
import {UnconnectedText} from './Text'; | ||
import PropTypes from 'prop-types'; | ||
import React, {Component} from 'react'; | ||
import {connectToContainer} from 'lib'; | ||
import {isDateTime} from 'plotly.js/src/lib'; | ||
import {isJSDate} from 'plotly.js/src/lib/dates'; | ||
|
||
export class UnconnectedNumericOrDate extends Component { | ||
render() { | ||
const fullValueIsDate = | ||
typeof this.props.fullValue === 'string' && | ||
(isDateTime(this.props.fullValue) || isJSDate(this.props.fullValue)); | ||
|
||
return fullValueIsDate ? ( | ||
<UnconnectedText {...this.props} placeholder={'yyyy-mm-dd 00:00:00.00'} /> | ||
) : ( | ||
<UnconnectedNumeric {...this.props} /> | ||
); | ||
} | ||
} | ||
|
||
UnconnectedNumericOrDate.propTypes = { | ||
defaultValue: PropTypes.any, | ||
fullValue: PropTypes.any, | ||
min: PropTypes.number, | ||
max: PropTypes.number, | ||
multiValued: PropTypes.bool, | ||
hideArrows: PropTypes.bool, | ||
showSlider: PropTypes.bool, | ||
step: PropTypes.number, | ||
fullContainer: PropTypes.object, | ||
updatePlot: PropTypes.func, | ||
...Field.propTypes, | ||
}; | ||
|
||
export default connectToContainer(UnconnectedNumericOrDate); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import {UnconnectedDropdown} from './Dropdown'; | |
import {UnconnectedDropdownCustom} from './DropdownCustom'; | ||
import {UnconnectedFlaglist} from './Flaglist'; | ||
import {UnconnectedNumeric} from './Numeric'; | ||
import {UnconnectedNumericOrDate} from './NumericOrDate'; | ||
import {UnconnectedAxisRangeValue} from './AxisRangeValue'; | ||
import {UnconnectedRadio} from './Radio'; | ||
import Info from './Info'; | ||
|
@@ -432,7 +433,7 @@ export const PositioningRef = connectToContainer(UnconnectedDropdown, { | |
}, | ||
}); | ||
|
||
export const PositioningNumeric = connectToContainer(UnconnectedNumeric, { | ||
export const PositioningNumeric = connectToContainer(UnconnectedNumericOrDate, { | ||
modifyPlotProps: (props, context, plotProps) => { | ||
const {fullContainer, fullValue, updatePlot} = plotProps; | ||
if ( | ||
|
@@ -676,3 +677,15 @@ export const HoverColor = connectToContainer(UnconnectedColorPicker, { | |
return plotProps; | ||
}, | ||
}); | ||
|
||
export const BinSize = connectToContainer(UnconnectedNumeric, { | ||
modifyPlotProps: (props, context, plotProps) => { | ||
const {localize: _} = context; | ||
if (typeof plotProps.fullValue === 'string' && plotProps.fullValue[0] === 'M') { | ||
plotProps.fullValue = plotProps.fullValue.substring(1); | ||
plotProps.min = 1; | ||
plotProps.max = 12; | ||
plotProps.units = parseInt(plotProps.fullValue, 10) === 1 ? _('Month') : _('Months'); | ||
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. does plotly.js accept any other format than M for months? D for days? seconds? I'd be surprised if it was only months :) 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. Well actually, from the docs, it does look that months is the only option:
Either that or time in milliseconds, so I could add a richer widgets that allows to do either milliseconds or months 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. Call me "surprised" :) |
||
} | ||
}, | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.