Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
b5261505
Unverified
Commit
b5261505
authored
Jul 17, 2018
by
David
Committed by
GitHub
Jul 17, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12634 from grafana/davkal/explore-step
Explore: calculate query interval based on available width
parents
e318489b
02427ef8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
28 deletions
+33
-28
public/app/containers/Explore/Explore.tsx
+33
-16
public/app/containers/Explore/utils/query.ts
+0
-12
No files found.
public/app/containers/Explore/Explore.tsx
View file @
b5261505
...
@@ -2,16 +2,18 @@ import React from 'react';
...
@@ -2,16 +2,18 @@ import React from 'react';
import
{
hot
}
from
'react-hot-loader'
;
import
{
hot
}
from
'react-hot-loader'
;
import
Select
from
'react-select'
;
import
Select
from
'react-select'
;
import
kbn
from
'app/core/utils/kbn'
;
import
colors
from
'app/core/utils/colors'
;
import
colors
from
'app/core/utils/colors'
;
import
TimeSeries
from
'app/core/time_series2'
;
import
TimeSeries
from
'app/core/time_series2'
;
import
{
decodePathComponent
}
from
'app/core/utils/location_util'
;
import
{
decodePathComponent
}
from
'app/core/utils/location_util'
;
import
{
parse
as
parseDate
}
from
'app/core/utils/datemath'
;
import
ElapsedTime
from
'./ElapsedTime'
;
import
ElapsedTime
from
'./ElapsedTime'
;
import
QueryRows
from
'./QueryRows'
;
import
QueryRows
from
'./QueryRows'
;
import
Graph
from
'./Graph'
;
import
Graph
from
'./Graph'
;
import
Table
from
'./Table'
;
import
Table
from
'./Table'
;
import
TimePicker
,
{
DEFAULT_RANGE
}
from
'./TimePicker'
;
import
TimePicker
,
{
DEFAULT_RANGE
}
from
'./TimePicker'
;
import
{
buildQueryOptions
,
ensureQueries
,
generateQueryKey
,
hasQuery
}
from
'./utils/query'
;
import
{
ensureQueries
,
generateQueryKey
,
hasQuery
}
from
'./utils/query'
;
function
makeTimeSeriesList
(
dataList
,
options
)
{
function
makeTimeSeriesList
(
dataList
,
options
)
{
return
dataList
.
map
((
seriesData
,
index
)
=>
{
return
dataList
.
map
((
seriesData
,
index
)
=>
{
...
@@ -63,8 +65,9 @@ interface IExploreState {
...
@@ -63,8 +65,9 @@ interface IExploreState {
tableResult
:
any
;
tableResult
:
any
;
}
}
// @observer
export
class
Explore
extends
React
.
Component
<
any
,
IExploreState
>
{
export
class
Explore
extends
React
.
Component
<
any
,
IExploreState
>
{
el
:
any
;
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
const
{
datasource
,
queries
,
range
}
=
parseInitialState
(
props
.
routeParams
.
initial
);
const
{
datasource
,
queries
,
range
}
=
parseInitialState
(
props
.
routeParams
.
initial
);
...
@@ -132,6 +135,10 @@ export class Explore extends React.Component<any, IExploreState> {
...
@@ -132,6 +135,10 @@ export class Explore extends React.Component<any, IExploreState> {
}
}
}
}
getRef
=
el
=>
{
this
.
el
=
el
;
};
handleAddQueryRow
=
index
=>
{
handleAddQueryRow
=
index
=>
{
const
{
queries
}
=
this
.
state
;
const
{
queries
}
=
this
.
state
;
const
nextQueries
=
[
const
nextQueries
=
[
...
@@ -214,20 +221,33 @@ export class Explore extends React.Component<any, IExploreState> {
...
@@ -214,20 +221,33 @@ export class Explore extends React.Component<any, IExploreState> {
}
}
};
};
async
runGraphQuery
(
)
{
buildQueryOptions
(
targetOptions
:
{
format
:
string
;
instant
:
boolean
}
)
{
const
{
datasource
,
queries
,
range
}
=
this
.
state
;
const
{
datasource
,
queries
,
range
}
=
this
.
state
;
const
resolution
=
this
.
el
.
offsetWidth
;
const
absoluteRange
=
{
from
:
parseDate
(
range
.
from
,
false
),
to
:
parseDate
(
range
.
to
,
true
),
};
const
{
interval
}
=
kbn
.
calculateInterval
(
absoluteRange
,
resolution
,
datasource
.
interval
);
const
targets
=
queries
.
map
(
q
=>
({
...
targetOptions
,
expr
:
q
.
query
,
}));
return
{
interval
,
range
,
targets
,
};
}
async
runGraphQuery
()
{
const
{
datasource
,
queries
}
=
this
.
state
;
if
(
!
hasQuery
(
queries
))
{
if
(
!
hasQuery
(
queries
))
{
return
;
return
;
}
}
this
.
setState
({
latency
:
0
,
loading
:
true
,
graphResult
:
null
,
queryError
:
null
});
this
.
setState
({
latency
:
0
,
loading
:
true
,
graphResult
:
null
,
queryError
:
null
});
const
now
=
Date
.
now
();
const
now
=
Date
.
now
();
const
options
=
buildQueryOptions
({
const
options
=
this
.
buildQueryOptions
({
format
:
'time_series'
,
instant
:
false
});
format
:
'time_series'
,
interval
:
datasource
.
interval
,
instant
:
false
,
range
,
queries
:
queries
.
map
(
q
=>
q
.
query
),
});
try
{
try
{
const
res
=
await
datasource
.
query
(
options
);
const
res
=
await
datasource
.
query
(
options
);
const
result
=
makeTimeSeriesList
(
res
.
data
,
options
);
const
result
=
makeTimeSeriesList
(
res
.
data
,
options
);
...
@@ -241,18 +261,15 @@ export class Explore extends React.Component<any, IExploreState> {
...
@@ -241,18 +261,15 @@ export class Explore extends React.Component<any, IExploreState> {
}
}
async
runTableQuery
()
{
async
runTableQuery
()
{
const
{
datasource
,
queries
,
range
}
=
this
.
state
;
const
{
datasource
,
queries
}
=
this
.
state
;
if
(
!
hasQuery
(
queries
))
{
if
(
!
hasQuery
(
queries
))
{
return
;
return
;
}
}
this
.
setState
({
latency
:
0
,
loading
:
true
,
queryError
:
null
,
tableResult
:
null
});
this
.
setState
({
latency
:
0
,
loading
:
true
,
queryError
:
null
,
tableResult
:
null
});
const
now
=
Date
.
now
();
const
now
=
Date
.
now
();
const
options
=
buildQueryOptions
({
const
options
=
this
.
buildQueryOptions
({
format
:
'table'
,
format
:
'table'
,
interval
:
datasource
.
interval
,
instant
:
true
,
instant
:
true
,
range
,
queries
:
queries
.
map
(
q
=>
q
.
query
),
});
});
try
{
try
{
const
res
=
await
datasource
.
query
(
options
);
const
res
=
await
datasource
.
query
(
options
);
...
@@ -301,7 +318,7 @@ export class Explore extends React.Component<any, IExploreState> {
...
@@ -301,7 +318,7 @@ export class Explore extends React.Component<any, IExploreState> {
const
selectedDatasource
=
datasource
?
datasource
.
name
:
undefined
;
const
selectedDatasource
=
datasource
?
datasource
.
name
:
undefined
;
return
(
return
(
<
div
className=
{
exploreClass
}
>
<
div
className=
{
exploreClass
}
ref=
{
this
.
getRef
}
>
<
div
className=
"navbar"
>
<
div
className=
"navbar"
>
{
position
===
'left'
?
(
{
position
===
'left'
?
(
<
div
>
<
div
>
...
...
public/app/containers/Explore/utils/query.ts
View file @
b5261505
export
function
buildQueryOptions
({
format
,
interval
,
instant
,
range
,
queries
})
{
return
{
interval
,
range
,
targets
:
queries
.
map
(
expr
=>
({
expr
,
format
,
instant
,
})),
};
}
export
function
generateQueryKey
(
index
=
0
)
{
export
function
generateQueryKey
(
index
=
0
)
{
return
`Q-
${
Date
.
now
()}
-
${
Math
.
random
()}
-
${
index
}
`
;
return
`Q-
${
Date
.
now
()}
-
${
Math
.
random
()}
-
${
index
}
`
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment