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
80d64752
Commit
80d64752
authored
Mar 20, 2019
by
ryan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
maintain query order
parent
93677f16
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
12 deletions
+42
-12
public/app/plugins/datasource/testdata/datasource.ts
+42
-12
No files found.
public/app/plugins/datasource/testdata/datasource.ts
View file @
80d64752
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
TableModel
from
'app/core/table_model'
;
import
{
DataSourceApi
,
DataQueryOptions
,
TableData
,
TimeSeries
}
from
'@grafana/ui'
;
import
{
DataSourceApi
,
DataQueryOptions
}
from
'@grafana/ui'
;
import
{
TestDataQuery
,
Scenario
}
from
'./types'
;
import
{
TestDataQuery
,
Scenario
}
from
'./types'
;
type
TestData
=
TimeSeries
|
TableData
;
export
interface
TestDataRegistry
{
[
key
:
string
]:
TestData
[];
}
export
class
TestDataDatasource
implements
DataSourceApi
<
TestDataQuery
>
{
export
class
TestDataDatasource
implements
DataSourceApi
<
TestDataQuery
>
{
id
:
number
;
id
:
number
;
...
@@ -42,24 +47,49 @@ export class TestDataDatasource implements DataSourceApi<TestDataQuery> {
...
@@ -42,24 +47,49 @@ export class TestDataDatasource implements DataSourceApi<TestDataQuery> {
},
},
})
})
.
then
(
res
=>
{
.
then
(
res
=>
{
const
data
=
[];
const
data
:
TestData
[]
=
[];
// The results are not in the order we asked for them
if
(
res
.
data
.
results
)
{
if
(
res
.
data
.
results
)
{
const
byRefID
:
TestDataRegistry
=
{};
_
.
forEach
(
res
.
data
.
results
,
queryRes
=>
{
_
.
forEach
(
res
.
data
.
results
,
queryRes
=>
{
const
refId
=
queryRes
.
refId
||
'Result'
+
data
.
length
+
1
;
const
qdata
:
TestData
[]
=
[];
byRefID
[
refId
]
=
qdata
;
if
(
queryRes
.
tables
)
{
if
(
queryRes
.
tables
)
{
for
(
const
table
of
queryRes
.
tables
)
{
for
(
const
table
of
queryRes
.
tables
)
{
const
model
=
new
TableModel
();
qdata
.
push
(
table
as
TableData
);
model
.
rows
=
table
.
rows
;
}
model
.
columns
=
table
.
columns
;
}
if
(
queryRes
.
series
)
{
for
(
const
series
of
queryRes
.
series
)
{
qdata
.
push
({
target
:
series
.
name
,
datapoints
:
series
.
points
,
});
}
}
});
data
.
push
(
model
);
// Return them in the order they were asked for
queries
.
forEach
(
q
=>
{
const
found
=
byRefID
[
q
.
refId
];
if
(
found
)
{
for
(
const
d
of
found
)
{
data
.
push
(
d
);
byRefID
[
q
.
refId
]
=
null
;
}
}
}
}
for
(
const
series
of
queryRes
.
series
)
{
});
data
.
push
({
target
:
series
.
name
,
// In case there are items left over
datapoints
:
series
.
points
,
_
.
forEach
(
byRefID
,
v
=>
{
});
if
(
v
)
{
for
(
const
d
of
v
)
{
data
.
push
(
d
);
}
}
}
});
});
}
}
...
...
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