@grafana/data#DefaultTimeZone TypeScript Examples
The following examples show how to use
@grafana/data#DefaultTimeZone.
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: explore.ts From grafana-chinese with Apache License 2.0 | 5 votes |
export function buildQueryTransaction(
queries: DataQuery[],
queryOptions: QueryOptions,
range: TimeRange,
scanning: boolean
): QueryTransaction {
const configuredQueries = queries.map(query => ({ ...query, ...queryOptions }));
const key = queries.reduce((combinedKey, query) => {
combinedKey += query.key;
return combinedKey;
}, '');
const { interval, intervalMs } = getIntervals(range, queryOptions.minInterval, queryOptions.maxDataPoints);
// Most datasource is using `panelId + query.refId` for cancellation logic.
// Using `format` here because it relates to the view panel that the request is for.
// However, some datasources don't use `panelId + query.refId`, but only `panelId`.
// Therefore panel id has to be unique.
const panelId = `${key}`;
const request: DataQueryRequest = {
app: CoreApp.Explore,
dashboardId: 0,
// TODO probably should be taken from preferences but does not seem to be used anyway.
timezone: DefaultTimeZone,
startTime: Date.now(),
interval,
intervalMs,
// TODO: the query request expects number and we are using string here. Seems like it works so far but can create
// issues down the road.
panelId: panelId as any,
targets: configuredQueries, // Datasources rely on DataQueries being passed under the targets key.
range,
requestId: 'explore',
rangeRaw: range.raw,
scopedVars: {
__interval: { text: interval, value: interval },
__interval_ms: { text: intervalMs, value: intervalMs },
},
maxDataPoints: queryOptions.maxDataPoints,
exploreMode: queryOptions.mode,
};
return {
queries,
request,
scanning,
id: generateKey(), // reusing for unique ID
done: false,
latency: 0,
};
}
Example #2
Source File: actions.test.ts From grafana-chinese with Apache License 2.0 | 5 votes |
setup = (updateOverides?: Partial<ExploreUpdateState>) => {
const exploreId = ExploreId.left;
const containerWidth = 1920;
const eventBridge = {} as Emitter;
const ui = { dedupStrategy: LogsDedupStrategy.none, showingGraph: false, showingLogs: false, showingTable: false };
const timeZone = DefaultTimeZone;
const range = testRange;
const urlState: ExploreUrlState = {
datasource: 'some-datasource',
queries: [],
range: range.raw,
mode: ExploreMode.Metrics,
ui,
};
const updateDefaults = makeInitialUpdateState();
const update = { ...updateDefaults, ...updateOverides };
const initialState = {
user: {
orgId: '1',
timeZone,
},
explore: {
[exploreId]: {
initialized: true,
urlState,
containerWidth,
eventBridge,
update,
datasourceInstance: { name: 'some-datasource' },
queries: [] as DataQuery[],
range,
ui,
refreshInterval: {
label: 'Off',
value: 0,
},
},
},
};
return {
initialState,
exploreId,
range,
ui,
containerWidth,
eventBridge,
};
}
Example #3
Source File: Graph.tsx From grafana-chinese with Apache License 2.0 | 4 votes |
draw() {
if (this.element === null) {
return;
}
const {
width,
series,
timeRange,
showLines,
showBars,
showPoints,
isStacked,
lineWidth,
timeZone,
onHorizontalRegionSelected,
} = this.props;
if (!width) {
return;
}
const ticks = width / 100;
const min = timeRange.from.valueOf();
const max = timeRange.to.valueOf();
const yaxes = this.getYAxes(series);
const flotOptions: any = {
legend: {
show: false,
},
series: {
stack: isStacked,
lines: {
show: showLines,
linewidth: lineWidth,
zero: false,
},
points: {
show: showPoints,
fill: 1,
fillColor: false,
radius: 2,
},
bars: {
show: showBars,
fill: 1,
// Dividig the width by 1.5 to make the bars not touch each other
barWidth: showBars ? this.getBarWidth() / 1.5 : 1,
zero: false,
lineWidth: lineWidth,
},
shadowSize: 0,
},
xaxis: {
show: true,
mode: 'time',
min: min,
max: max,
label: 'Datetime',
ticks: ticks,
timeformat: timeFormat(ticks, min, max),
timezone: timeZone ?? DefaultTimeZone,
},
yaxes,
grid: {
minBorderMargin: 0,
markings: [],
backgroundColor: null,
borderWidth: 0,
hoverable: true,
clickable: true,
color: '#a1a1a1',
margin: { left: 0, right: 0 },
labelMarginX: 0,
mouseActiveRadius: 30,
},
selection: {
mode: onHorizontalRegionSelected ? 'x' : null,
color: '#666',
},
crosshair: {
mode: 'x',
},
};
try {
$.plot(
this.element,
series.filter(s => s.isVisible),
flotOptions
);
} catch (err) {
console.log('Graph rendering error', err, flotOptions, series);
throw new Error('Error rendering panel');
}
}