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
08a4c9f6
Commit
08a4c9f6
authored
Mar 22, 2019
by
Peter Holmberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move typings to types,
parent
6e05b9f4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
45 deletions
+70
-45
packages/grafana-ui/src/components/BarGauge/BarGauge.tsx
+2
-2
packages/grafana-ui/src/components/Gauge/Gauge.tsx
+2
-3
packages/grafana-ui/src/types/displayValue.ts
+34
-0
packages/grafana-ui/src/types/index.ts
+1
-0
packages/grafana-ui/src/utils/displayValue.test.ts
+11
-10
packages/grafana-ui/src/utils/displayValue.ts
+20
-30
No files found.
packages/grafana-ui/src/components/BarGauge/BarGauge.tsx
View file @
08a4c9f6
...
...
@@ -3,10 +3,10 @@ import React, { PureComponent, CSSProperties, ReactNode } from 'react';
import
tinycolor
from
'tinycolor2'
;
// Utils
import
{
getColorFromHexRgbOrName
,
getThresholdForValue
,
DisplayValue
}
from
'../../utils'
;
import
{
getColorFromHexRgbOrName
,
getThresholdForValue
}
from
'../../utils'
;
// Types
import
{
Themeable
,
TimeSeriesValue
,
Threshold
,
VizOrientation
}
from
'../../types'
;
import
{
DisplayValue
,
Themeable
,
TimeSeriesValue
,
Threshold
,
VizOrientation
}
from
'../../types'
;
const
BAR_SIZE_RATIO
=
0.8
;
...
...
packages/grafana-ui/src/components/Gauge/Gauge.tsx
View file @
08a4c9f6
import
React
,
{
PureComponent
}
from
'react'
;
import
$
from
'jquery'
;
import
{
Threshold
,
GrafanaThemeType
}
from
'../../types'
;
import
{
getColorFromHexRgbOrName
}
from
'../../utils'
;
import
{
Themeable
}
from
'../../index'
;
import
{
DisplayValue
}
from
'../../utils/displayValue
'
;
import
{
DisplayValue
,
Threshold
,
GrafanaThemeType
,
Themeable
}
from
'../../types
'
;
export
interface
Props
extends
Themeable
{
height
:
number
;
...
...
packages/grafana-ui/src/types/displayValue.ts
0 → 100644
View file @
08a4c9f6
import
{
DecimalCount
}
from
'../utils'
;
import
{
ValueMapping
}
from
'./panel'
;
import
{
Threshold
}
from
'./threshold'
;
import
{
GrafanaTheme
}
from
'./theme'
;
export
interface
DisplayValue
{
text
:
string
;
// Show in the UI
numeric
:
number
;
// Use isNaN to check if it is a real number
color
?:
string
;
// color based on configs or Threshold
}
export
interface
DisplayValueOptions
{
unit
?:
string
;
decimals
?:
DecimalCount
;
dateFormat
?:
string
;
// If set try to convert numbers to date
color
?:
string
;
mappings
?:
ValueMapping
[];
thresholds
?:
Threshold
[];
prefix
?:
string
;
suffix
?:
string
;
// Alternative to empty string
noValue
?:
string
;
// Context
isUtc
?:
boolean
;
theme
?:
GrafanaTheme
;
// Will pick 'dark' if not defined
}
export
interface
DecimalInfo
{
decimals
:
number
;
scaledDecimals
:
number
;
}
packages/grafana-ui/src/types/index.ts
View file @
08a4c9f6
...
...
@@ -6,3 +6,4 @@ export * from './datasource';
export
*
from
'./theme'
;
export
*
from
'./threshold'
;
export
*
from
'./input'
;
export
*
from
'./displayValue'
;
packages/grafana-ui/src/utils/displayValue.test.ts
View file @
08a4c9f6
import
{
getDisplayProcessor
,
getColorFromThreshold
,
DisplayProcessor
,
DisplayValue
,
getDecimalsForValue
,
}
from
'./displayValue'
;
import
{
MappingType
,
ValueMapping
}
from
'../types'
;
import
{
getDisplayProcessor
,
getColorFromThreshold
,
DisplayProcessor
,
getDecimalsForValue
}
from
'./displayValue'
;
import
{
DisplayValue
,
MappingType
,
ValueMapping
}
from
'../types'
;
function
assertSame
(
input
:
any
,
processors
:
DisplayProcessor
[],
match
:
DisplayValue
)
{
processors
.
forEach
(
processor
=>
{
...
...
@@ -134,7 +128,7 @@ describe('Format value', () => {
const
result
=
instance
(
value
);
expect
(
result
.
text
).
toEqual
(
'6'
);
expect
(
result
.
text
).
toEqual
(
'6
.0
'
);
});
it
(
'should return formatted value if there are no matching value mappings'
,
()
=>
{
...
...
@@ -147,7 +141,14 @@ describe('Format value', () => {
const
result
=
instance
(
value
);
expect
(
result
.
text
).
toEqual
(
'10'
);
expect
(
result
.
text
).
toEqual
(
'10.0'
);
});
it
(
'should set auto decimals, 1 significant'
,
()
=>
{
const
value
=
'1.23'
;
const
instance
=
getDisplayProcessor
({
decimals
:
null
});
expect
(
instance
(
value
).
text
).
toEqual
(
'1.2'
);
});
it
(
'should return mapped value if there are matching value mappings'
,
()
=>
{
...
...
packages/grafana-ui/src/utils/displayValue.ts
View file @
08a4c9f6
...
...
@@ -3,37 +3,12 @@ import _ from 'lodash';
import
moment
from
'moment'
;
// Utils
import
{
getValueFormat
,
DecimalCount
}
from
'./valueFormats/valueFormats'
;
import
{
getValueFormat
}
from
'./valueFormats/valueFormats'
;
import
{
getMappedValue
}
from
'./valueMappings'
;
import
{
getColorFromHexRgbOrName
}
from
'./namedColorsPalette'
;
// Types
import
{
GrafanaTheme
,
GrafanaThemeType
,
ValueMapping
,
Threshold
}
from
'../types'
;
export
interface
DisplayValue
{
text
:
string
;
// Show in the UI
numeric
:
number
;
// Use isNaN to check if it is a real number
color
?:
string
;
// color based on configs or Threshold
}
export
interface
DisplayValueOptions
{
unit
?:
string
;
decimals
?:
DecimalCount
;
dateFormat
?:
string
;
// If set try to convert numbers to date
color
?:
string
;
mappings
?:
ValueMapping
[];
thresholds
?:
Threshold
[];
prefix
?:
string
;
suffix
?:
string
;
// Alternative to empty string
noValue
?:
string
;
// Context
isUtc
?:
boolean
;
theme
?:
GrafanaTheme
;
// Will pick 'dark' if not defined
}
import
{
DecimalInfo
,
DisplayValue
,
DisplayValueOptions
,
GrafanaTheme
,
GrafanaThemeType
,
Threshold
}
from
'../types'
;
export
type
DisplayProcessor
=
(
value
:
any
)
=>
DisplayValue
;
...
...
@@ -74,8 +49,23 @@ export function getDisplayProcessor(options?: DisplayValueOptions): DisplayProce
if
(
!
isNaN
(
numeric
))
{
if
(
shouldFormat
&&
!
_
.
isBoolean
(
value
))
{
const
decimalInfo
=
getDecimalsForValue
(
value
);
text
=
formatFunc
(
numeric
,
decimalInfo
.
decimals
,
decimalInfo
.
scaledDecimals
,
options
.
isUtc
);
let
decimals
;
let
scaledDecimals
=
0
;
if
(
!
options
.
decimals
)
{
const
decimalInfo
=
getDecimalsForValue
(
value
);
decimals
=
decimalInfo
.
decimals
;
scaledDecimals
=
decimalInfo
.
scaledDecimals
;
}
else
{
decimals
=
options
.
decimals
;
}
console
.
log
(
'coin coin'
,
value
);
console
.
log
(
decimals
);
console
.
log
(
scaledDecimals
);
text
=
formatFunc
(
numeric
,
decimals
,
scaledDecimals
,
options
.
isUtc
);
}
if
(
thresholds
&&
thresholds
.
length
>
0
)
{
color
=
getColorFromThreshold
(
numeric
,
thresholds
,
theme
);
...
...
@@ -152,7 +142,7 @@ export function getColorFromThreshold(value: number, thresholds: Threshold[], th
return
getColorFromHexRgbOrName
(
thresholds
[
0
].
color
,
themeType
);
}
export
function
getDecimalsForValue
(
value
:
number
):
{
decimals
:
number
;
scaledDecimals
:
number
}
{
export
function
getDecimalsForValue
(
value
:
number
):
DecimalInfo
{
const
delta
=
value
/
2
;
let
dec
=
-
Math
.
floor
(
Math
.
log
(
delta
)
/
Math
.
LN10
);
...
...
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