@grafana/data#dateTimeForTimeZone TypeScript Examples
The following examples show how to use
@grafana/data#dateTimeForTimeZone.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: mapper.ts From grafana-chinese with Apache License 2.0 | 6 votes |
stringToDateTime = (value: string | DateTime, roundUp?: boolean, timeZone?: TimeZone): DateTime => {
if (isDateTime(value)) {
if (timeZone === 'utc') {
return value.utc();
}
return value;
}
if (value.indexOf('now') !== -1) {
if (!dateMath.isValid(value)) {
return dateTime();
}
const parsed = dateMath.parse(value, roundUp, timeZone);
return parsed || dateTime();
}
return dateTimeForTimeZone(timeZone, value, TIME_FORMAT);
}
Example #2
Source File: time.ts From grafana-chinese with Apache License 2.0 | 6 votes |
stringToDateTimeType = (value: string | DateTime, roundUp?: boolean, timeZone?: TimeZone): DateTime => {
if (isDateTime(value)) {
return value;
}
if (value.indexOf('now') !== -1) {
if (!dateMath.isValid(value)) {
return dateTime();
}
const parsed = dateMath.parse(value, roundUp, timeZone);
return parsed || dateTime();
}
return dateTimeForTimeZone(timeZone, value, TIME_FORMAT);
}
Example #3
Source File: ExploreTimeControls.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
onMoveTimePicker = (direction: number) => {
const { range, onChangeTime, timeZone } = this.props;
const { from, to } = getShiftedTimeRange(direction, range);
const nextTimeRange = {
from: dateTimeForTimeZone(timeZone, from),
to: dateTimeForTimeZone(timeZone, to),
};
onChangeTime(nextTimeRange);
};
Example #4
Source File: ExploreTimeControls.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
onZoom = () => {
const { range, onChangeTime, timeZone } = this.props;
const { from, to } = getZoomedTimeRange(range, 2);
const nextTimeRange = {
from: dateTimeForTimeZone(timeZone, from),
to: dateTimeForTimeZone(timeZone, to),
};
onChangeTime(nextTimeRange);
};
Example #5
Source File: actions.ts From grafana-chinese with Apache License 2.0 | 6 votes |
updateTime = (config: {
exploreId: ExploreId;
rawRange?: RawTimeRange;
absoluteRange?: AbsoluteTimeRange;
}): ThunkResult<void> => {
return (dispatch, getState) => {
const { exploreId, absoluteRange: absRange, rawRange: actionRange } = config;
const itemState = getState().explore[exploreId];
const timeZone = getTimeZone(getState().user);
const { range: rangeInState } = itemState;
let rawRange: RawTimeRange = rangeInState.raw;
if (absRange) {
rawRange = {
from: dateTimeForTimeZone(timeZone, absRange.from),
to: dateTimeForTimeZone(timeZone, absRange.to),
};
}
if (actionRange) {
rawRange = actionRange;
}
const range = getTimeRange(timeZone, rawRange);
const absoluteRange: AbsoluteTimeRange = { from: range.from.valueOf(), to: range.to.valueOf() };
getTimeSrv().init({
time: range.raw,
refresh: false,
getTimezone: () => timeZone,
timeRangeUpdated: (): any => undefined,
});
dispatch(changeRangeAction({ exploreId, range, absoluteRange }));
};
}
Example #6
Source File: ExploreGraphPanel.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
renderGraph = () => {
const {
width,
series,
onHiddenSeriesChanged,
timeZone,
absoluteRange,
showPanel,
showingGraph,
showingTable,
showBars,
showLines,
isStacked,
} = this.props;
const { showAllTimeSeries } = this.state;
if (!series) {
return null;
}
const timeRange = {
from: dateTimeForTimeZone(timeZone, absoluteRange.from),
to: dateTimeForTimeZone(timeZone, absoluteRange.to),
raw: {
from: dateTimeForTimeZone(timeZone, absoluteRange.from),
to: dateTimeForTimeZone(timeZone, absoluteRange.to),
},
};
const height = showPanel === false ? 100 : showingGraph && showingTable ? 200 : 400;
const lineWidth = showLines ? 1 : 5;
const seriesToShow = showAllTimeSeries ? series : series.slice(0, MAX_NUMBER_OF_TIME_SERIES);
return (
<GraphSeriesToggler series={seriesToShow} onHiddenSeriesChanged={onHiddenSeriesChanged}>
{({ onSeriesToggle, toggledSeries }: GraphSeriesTogglerAPI) => {
return (
<GraphWithLegend
displayMode={LegendDisplayMode.List}
height={height}
isLegendVisible={true}
placement={'under'}
width={width}
timeRange={timeRange}
timeZone={timeZone}
showBars={showBars}
showLines={showLines}
showPoints={false}
onToggleSort={() => {}}
series={toggledSeries}
isStacked={isStacked}
lineWidth={lineWidth}
onSeriesToggle={onSeriesToggle}
onHorizontalRegionSelected={this.onChangeTime}
>
{/* For logs we are using mulit mode until we refactor logs histogram to use barWidth instead of lineWidth to render bars */}
<Chart.Tooltip mode={showBars ? 'multi' : 'single'} />
</GraphWithLegend>
);
}}
</GraphSeriesToggler>
);
};