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
1fa07a82
Commit
1fa07a82
authored
Mar 14, 2019
by
ryan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no inheratance
parent
8be56f8a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
144 additions
and
79 deletions
+144
-79
public/app/plugins/panel/bargauge/BarGaugePanel.tsx
+25
-8
public/app/plugins/panel/gauge/GaugePanel.tsx
+25
-5
public/app/plugins/panel/singlestat2/ProcessedValuesRepeater.tsx
+48
-0
public/app/plugins/panel/singlestat2/SingleStatBase.tsx
+0
-61
public/app/plugins/panel/singlestat2/SingleStatPanel.tsx
+46
-5
No files found.
public/app/plugins/panel/bargauge/BarGaugePanel.tsx
View file @
1fa07a82
// Libraries
// Libraries
import
React
from
'react'
;
import
React
,
{
PureComponent
}
from
'react'
;
// Services & Utils
// Services & Utils
import
{
DisplayValue
}
from
'@grafana/ui'
;
import
{
DisplayValue
,
PanelProps
,
BarGauge
}
from
'@grafana/ui'
;
import
{
config
}
from
'app/core/config'
;
import
{
config
}
from
'app/core/config'
;
// Components
import
{
BarGauge
}
from
'@grafana/ui'
;
// Types
// Types
import
{
BarGaugeOptions
}
from
'./types'
;
import
{
BarGaugeOptions
}
from
'./types'
;
import
{
SingleStatBase
}
from
'../singlestat2/SingleStatBase'
;
import
{
getSingleStatValues
}
from
'../singlestat2/SingleStatPanel'
;
import
{
ProcessedValuesRepeater
}
from
'../singlestat2/ProcessedValuesRepeater'
;
export
class
BarGaugePanel
extends
SingleStatBase
<
BarGaugeOptions
>
{
export
class
BarGaugePanel
extends
PureComponent
<
PanelProps
<
BarGaugeOptions
>
>
{
render
Stat
(
value
:
DisplayValue
,
width
:
number
,
height
:
number
)
{
render
Value
=
(
value
:
DisplayValue
,
width
:
number
,
height
:
number
):
JSX
.
Element
=>
{
const
{
options
}
=
this
.
props
;
const
{
options
}
=
this
.
props
;
return
(
return
(
...
@@ -26,5 +24,24 @@ export class BarGaugePanel extends SingleStatBase<BarGaugeOptions> {
...
@@ -26,5 +24,24 @@ export class BarGaugePanel extends SingleStatBase<BarGaugeOptions> {
theme=
{
config
.
theme
}
theme=
{
config
.
theme
}
/>
/>
);
);
};
getProcessedValues
=
():
DisplayValue
[]
=>
{
return
getSingleStatValues
(
this
.
props
);
};
render
()
{
const
{
height
,
width
,
options
,
panelData
}
=
this
.
props
;
const
{
orientation
}
=
options
;
return
(
<
ProcessedValuesRepeater
getProcessedValues=
{
this
.
getProcessedValues
}
renderValue=
{
this
.
renderValue
}
width=
{
width
}
height=
{
height
}
source=
{
panelData
}
orientation=
{
orientation
}
/>
);
}
}
}
}
public/app/plugins/panel/gauge/GaugePanel.tsx
View file @
1fa07a82
// Libraries
// Libraries
import
React
from
'react'
;
import
React
,
{
PureComponent
}
from
'react'
;
// Services & Utils
// Services & Utils
import
{
config
}
from
'app/core/config'
;
import
{
config
}
from
'app/core/config'
;
...
@@ -9,11 +9,12 @@ import { Gauge } from '@grafana/ui';
...
@@ -9,11 +9,12 @@ import { Gauge } from '@grafana/ui';
// Types
// Types
import
{
GaugeOptions
}
from
'./types'
;
import
{
GaugeOptions
}
from
'./types'
;
import
{
DisplayValue
}
from
'@grafana/ui/src/utils/displayValue'
;
import
{
DisplayValue
,
PanelProps
}
from
'@grafana/ui'
;
import
{
SingleStatBase
}
from
'../singlestat2/SingleStatBase'
;
import
{
getSingleStatValues
}
from
'../singlestat2/SingleStatPanel'
;
import
{
ProcessedValuesRepeater
}
from
'../singlestat2/ProcessedValuesRepeater'
;
export
class
GaugePanel
extends
SingleStatBase
<
GaugeOptions
>
{
export
class
GaugePanel
extends
PureComponent
<
PanelProps
<
GaugeOptions
>
>
{
render
Stat
(
value
:
DisplayValue
,
width
:
number
,
height
:
number
)
{
render
Value
=
(
value
:
DisplayValue
,
width
:
number
,
height
:
number
):
JSX
.
Element
=>
{
const
{
options
}
=
this
.
props
;
const
{
options
}
=
this
.
props
;
return
(
return
(
...
@@ -29,5 +30,24 @@ export class GaugePanel extends SingleStatBase<GaugeOptions> {
...
@@ -29,5 +30,24 @@ export class GaugePanel extends SingleStatBase<GaugeOptions> {
theme=
{
config
.
theme
}
theme=
{
config
.
theme
}
/>
/>
);
);
};
getProcessedValues
=
():
DisplayValue
[]
=>
{
return
getSingleStatValues
(
this
.
props
);
};
render
()
{
const
{
height
,
width
,
options
,
panelData
}
=
this
.
props
;
const
{
orientation
}
=
options
;
return
(
<
ProcessedValuesRepeater
getProcessedValues=
{
this
.
getProcessedValues
}
renderValue=
{
this
.
renderValue
}
width=
{
width
}
height=
{
height
}
source=
{
panelData
}
orientation=
{
orientation
}
/>
);
}
}
}
}
public/app/plugins/panel/singlestat2/ProcessedValuesRepeater.tsx
0 → 100644
View file @
1fa07a82
import
React
,
{
PureComponent
}
from
'react'
;
import
{
VizOrientation
}
from
'@grafana/ui'
;
import
{
VizRepeater
}
from
'@grafana/ui'
;
export
interface
Props
<
T
>
{
width
:
number
;
height
:
number
;
orientation
:
VizOrientation
;
source
:
any
;
// If this changes, the values will be processed
processFlag
?:
boolean
;
// change to force processing
getProcessedValues
:
()
=>
T
[];
renderValue
:
(
value
:
T
,
width
:
number
,
height
:
number
)
=>
JSX
.
Element
;
}
interface
State
<
T
>
{
values
:
T
[];
}
/**
* This is essentially a cache of processed values. This checks for changes
* to the source and then saves the processed values in the State
*/
export
class
ProcessedValuesRepeater
<
T
>
extends
PureComponent
<
Props
<
T
>
,
State
<
T
>>
{
constructor
(
props
:
Props
<
T
>
)
{
super
(
props
);
this
.
state
=
{
values
:
props
.
getProcessedValues
(),
};
}
componentDidUpdate
(
prevProps
:
Props
<
T
>
)
{
const
{
processFlag
,
source
}
=
this
.
props
;
if
(
processFlag
!==
prevProps
.
processFlag
||
source
!==
prevProps
.
source
)
{
this
.
setState
({
values
:
this
.
props
.
getProcessedValues
()
});
}
}
render
()
{
const
{
orientation
,
height
,
width
,
renderValue
}
=
this
.
props
;
const
{
values
}
=
this
.
state
;
return
(
<
VizRepeater
height=
{
height
}
width=
{
width
}
values=
{
values
}
orientation=
{
orientation
}
>
{
({
vizHeight
,
vizWidth
,
value
})
=>
renderValue
(
value
,
vizWidth
,
vizHeight
)
}
</
VizRepeater
>
);
}
}
public/app/plugins/panel/singlestat2/SingleStatBase.tsx
deleted
100644 → 0
View file @
8be56f8a
import
React
,
{
PureComponent
}
from
'react'
;
import
{
processSingleStatPanelData
,
DisplayValue
,
PanelProps
}
from
'@grafana/ui'
;
import
{
config
}
from
'app/core/config'
;
import
{
VizRepeater
,
getDisplayProcessor
}
from
'@grafana/ui'
;
import
{
SingleStatBaseOptions
}
from
'./types'
;
export
interface
State
{
values
:
DisplayValue
[];
}
export
class
SingleStatBase
<
T
extends
SingleStatBaseOptions
>
extends
PureComponent
<
PanelProps
<
T
>
,
State
>
{
constructor
(
props
:
PanelProps
<
T
>
)
{
super
(
props
);
this
.
state
=
{
values
:
this
.
findDisplayValues
(
props
),
};
}
componentDidUpdate
(
prevProps
:
PanelProps
<
T
>
)
{
if
(
this
.
props
.
panelData
!==
prevProps
.
panelData
)
{
this
.
setState
({
values
:
this
.
findDisplayValues
(
this
.
props
)
});
}
}
findDisplayValues
(
props
:
PanelProps
<
T
>
):
DisplayValue
[]
{
const
{
panelData
,
replaceVariables
,
options
}
=
this
.
props
;
const
{
valueOptions
,
valueMappings
}
=
options
;
const
processor
=
getDisplayProcessor
({
unit
:
valueOptions
.
unit
,
decimals
:
valueOptions
.
decimals
,
mappings
:
valueMappings
,
thresholds
:
options
.
thresholds
,
prefix
:
replaceVariables
(
valueOptions
.
prefix
),
suffix
:
replaceVariables
(
valueOptions
.
suffix
),
theme
:
config
.
theme
,
});
return
processSingleStatPanelData
({
panelData
:
panelData
,
stat
:
valueOptions
.
stat
,
}).
map
(
stat
=>
processor
(
stat
.
value
));
}
/**
* Subclasses will fill in appropriatly
*/
renderStat
(
value
:
DisplayValue
,
width
:
number
,
height
:
number
)
{
return
<
div
style=
{
{
width
,
height
,
border
:
'1px solid red'
}
}
>
{
value
.
text
}
</
div
>;
}
render
()
{
const
{
height
,
width
,
options
}
=
this
.
props
;
const
{
orientation
}
=
options
;
const
{
values
}
=
this
.
state
;
return
(
<
VizRepeater
height=
{
height
}
width=
{
width
}
values=
{
values
}
orientation=
{
orientation
}
>
{
({
vizHeight
,
vizWidth
,
value
})
=>
this
.
renderStat
(
value
,
vizWidth
,
vizHeight
)
}
</
VizRepeater
>
);
}
}
public/app/plugins/panel/singlestat2/SingleStatPanel.tsx
View file @
1fa07a82
// Libraries
// Libraries
import
React
,
{
CSSProperties
}
from
'react'
;
import
React
,
{
PureComponent
,
CSSProperties
}
from
'react'
;
// Types
// Types
import
{
SingleStatOptions
}
from
'./types'
;
import
{
SingleStatOptions
}
from
'./types'
;
import
{
DisplayValue
}
from
'@grafana/ui/src/utils/displayValue'
;
import
{
SingleStatBase
}
from
'./SingleStatBase'
;
export
class
SingleStatPanel
extends
SingleStatBase
<
SingleStatOptions
>
{
import
{
processSingleStatPanelData
,
DisplayValue
,
PanelProps
}
from
'@grafana/ui'
;
renderStat
(
value
:
DisplayValue
,
width
:
number
,
height
:
number
)
{
import
{
config
}
from
'app/core/config'
;
import
{
getDisplayProcessor
}
from
'@grafana/ui'
;
import
{
ProcessedValuesRepeater
}
from
'./ProcessedValuesRepeater'
;
export
const
getSingleStatValues
=
(
props
:
PanelProps
<
SingleStatOptions
>
):
DisplayValue
[]
=>
{
const
{
panelData
,
replaceVariables
,
options
}
=
props
;
const
{
valueOptions
,
valueMappings
}
=
options
;
const
processor
=
getDisplayProcessor
({
unit
:
valueOptions
.
unit
,
decimals
:
valueOptions
.
decimals
,
mappings
:
valueMappings
,
thresholds
:
options
.
thresholds
,
prefix
:
replaceVariables
(
valueOptions
.
prefix
),
suffix
:
replaceVariables
(
valueOptions
.
suffix
),
theme
:
config
.
theme
,
});
return
processSingleStatPanelData
({
panelData
:
panelData
,
stat
:
valueOptions
.
stat
,
}).
map
(
stat
=>
processor
(
stat
.
value
));
};
export
class
SingleStatPanel
extends
PureComponent
<
PanelProps
<
SingleStatOptions
>>
{
renderValue
=
(
value
:
DisplayValue
,
width
:
number
,
height
:
number
):
JSX
.
Element
=>
{
const
style
:
CSSProperties
=
{};
const
style
:
CSSProperties
=
{};
style
.
margin
=
'0 auto'
;
style
.
margin
=
'0 auto'
;
style
.
fontSize
=
'250%'
;
style
.
fontSize
=
'250%'
;
...
@@ -21,5 +43,24 @@ export class SingleStatPanel extends SingleStatBase<SingleStatOptions> {
...
@@ -21,5 +43,24 @@ export class SingleStatPanel extends SingleStatBase<SingleStatOptions> {
<
div
style=
{
style
}
>
{
value
.
text
}
</
div
>
<
div
style=
{
style
}
>
{
value
.
text
}
</
div
>
</
div
>
</
div
>
);
);
};
getProcessedValues
=
():
DisplayValue
[]
=>
{
return
getSingleStatValues
(
this
.
props
);
};
render
()
{
const
{
height
,
width
,
options
,
panelData
}
=
this
.
props
;
const
{
orientation
}
=
options
;
return
(
<
ProcessedValuesRepeater
getProcessedValues=
{
this
.
getProcessedValues
}
renderValue=
{
this
.
renderValue
}
width=
{
width
}
height=
{
height
}
source=
{
panelData
}
orientation=
{
orientation
}
/>
);
}
}
}
}
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