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
8c1a79f2
Unverified
Commit
8c1a79f2
authored
Jan 22, 2021
by
Ryan McKinley
Committed by
GitHub
Jan 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XY Chart: share legend config with timeseries (#30559)
parent
e818bdd7
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
76 additions
and
100 deletions
+76
-100
packages/grafana-ui/src/components/GraphNG/GraphNG.tsx
+4
-0
public/app/plugins/panel/timeseries/config.ts
+47
-0
public/app/plugins/panel/timeseries/module.tsx
+5
-43
public/app/plugins/panel/timeseries/types.ts
+6
-4
public/app/plugins/panel/xychart/XYDimsEditor.tsx
+2
-13
public/app/plugins/panel/xychart/dims.ts
+5
-8
public/app/plugins/panel/xychart/module.tsx
+4
-28
public/app/plugins/panel/xychart/types.ts
+3
-4
No files found.
packages/grafana-ui/src/components/GraphNG/GraphNG.tsx
View file @
8c1a79f2
...
...
@@ -259,6 +259,10 @@ export const GraphNG: React.FC<GraphNGProps> = ({
label
:
seriesConfig
.
fieldName
,
yAxis
:
axisPlacement
===
AxisPlacement
.
Left
?
1
:
2
,
getDisplayValues
:
()
=>
{
if
(
!
legend
.
calcs
?.
length
)
{
return
[];
}
const
fmt
=
field
.
display
??
defaultFormatter
;
const
fieldCalcs
=
reduceField
({
field
,
...
...
public/app/plugins/panel/timeseries/config.ts
View file @
8c1a79f2
...
...
@@ -3,7 +3,10 @@ import {
FieldConfigProperty
,
FieldType
,
identityOverrideProcessor
,
PanelOptionsEditorBuilder
,
SetFieldConfigOptionsArgs
,
standardEditorsRegistry
,
StatsPickerConfigSettings
,
stringOverrideProcessor
,
}
from
'@grafana/data'
;
import
{
...
...
@@ -17,11 +20,13 @@ import {
ScaleDistribution
,
ScaleDistributionConfig
,
GraphGradientMode
,
LegendDisplayMode
,
}
from
'@grafana/ui'
;
import
{
SeriesConfigEditor
}
from
'./HideSeriesConfigEditor'
;
import
{
ScaleDistributionEditor
}
from
'./ScaleDistributionEditor'
;
import
{
LineStyleEditor
}
from
'./LineStyleEditor'
;
import
{
FillBellowToEditor
}
from
'./FillBelowToEditor'
;
import
{
OptionsWithLegend
}
from
'./types'
;
export
const
defaultGraphConfig
:
GraphFieldConfig
=
{
drawStyle
:
DrawStyle
.
Line
,
...
...
@@ -224,3 +229,45 @@ export function getGraphFieldConfig(cfg: GraphFieldConfig): SetFieldConfigOption
},
};
}
export
function
addLegendOptions
(
builder
:
PanelOptionsEditorBuilder
<
OptionsWithLegend
>
)
{
builder
.
addRadio
({
path
:
'legend.displayMode'
,
name
:
'Legend mode'
,
description
:
''
,
defaultValue
:
LegendDisplayMode
.
List
,
settings
:
{
options
:
[
{
value
:
LegendDisplayMode
.
List
,
label
:
'List'
},
{
value
:
LegendDisplayMode
.
Table
,
label
:
'Table'
},
{
value
:
LegendDisplayMode
.
Hidden
,
label
:
'Hidden'
},
],
},
})
.
addRadio
({
path
:
'legend.placement'
,
name
:
'Legend placement'
,
description
:
''
,
defaultValue
:
'bottom'
,
settings
:
{
options
:
[
{
value
:
'bottom'
,
label
:
'Bottom'
},
{
value
:
'right'
,
label
:
'Right'
},
],
},
showIf
:
(
c
)
=>
c
.
legend
.
displayMode
!==
LegendDisplayMode
.
Hidden
,
})
.
addCustomEditor
<
StatsPickerConfigSettings
,
string
[]
>
({
id
:
'legend.calcs'
,
path
:
'legend.calcs'
,
name
:
'Legend calculations'
,
description
:
'Choose a reducer functions / calculations to include in legend'
,
editor
:
standardEditorsRegistry
.
get
(
'stats-picker'
).
editor
as
any
,
defaultValue
:
[],
settings
:
{
allowMultiple
:
true
,
},
showIf
:
(
currentConfig
)
=>
currentConfig
.
legend
.
displayMode
!==
LegendDisplayMode
.
Hidden
,
});
}
public/app/plugins/panel/timeseries/module.tsx
View file @
8c1a79f2
import
{
PanelPlugin
,
standardEditorsRegistry
,
StatsPickerConfigSettings
}
from
'@grafana/data'
;
import
{
GraphFieldConfig
,
LegendDisplayMode
}
from
'@grafana/ui'
;
import
{
PanelPlugin
}
from
'@grafana/data'
;
import
{
GraphFieldConfig
}
from
'@grafana/ui'
;
import
{
TimeSeriesPanel
}
from
'./TimeSeriesPanel'
;
import
{
graphPanelChangedHandler
}
from
'./migrations'
;
import
{
Options
}
from
'./types'
;
import
{
defaultGraphConfig
,
getGraphFieldConfig
}
from
'./config'
;
import
{
addLegendOptions
,
defaultGraphConfig
,
getGraphFieldConfig
}
from
'./config'
;
export
const
plugin
=
new
PanelPlugin
<
Options
,
GraphFieldConfig
>
(
TimeSeriesPanel
)
.
setPanelChangeHandler
(
graphPanelChangedHandler
)
.
useFieldConfig
(
getGraphFieldConfig
(
defaultGraphConfig
))
.
setPanelOptions
((
builder
)
=>
{
builder
.
addRadio
({
builder
.
addRadio
({
path
:
'tooltipOptions.mode'
,
name
:
'Tooltip mode'
,
description
:
''
,
...
...
@@ -22,43 +21,6 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(TimeSeriesPanel
{
value
:
'none'
,
label
:
'Hidden'
},
],
},
})
.
addRadio
({
path
:
'legend.displayMode'
,
name
:
'Legend mode'
,
description
:
''
,
defaultValue
:
LegendDisplayMode
.
List
,
settings
:
{
options
:
[
{
value
:
LegendDisplayMode
.
List
,
label
:
'List'
},
{
value
:
LegendDisplayMode
.
Table
,
label
:
'Table'
},
{
value
:
LegendDisplayMode
.
Hidden
,
label
:
'Hidden'
},
],
},
})
.
addRadio
({
path
:
'legend.placement'
,
name
:
'Legend placement'
,
description
:
''
,
defaultValue
:
'bottom'
,
settings
:
{
options
:
[
{
value
:
'bottom'
,
label
:
'Bottom'
},
{
value
:
'right'
,
label
:
'Right'
},
],
},
showIf
:
(
c
)
=>
c
.
legend
.
displayMode
!==
LegendDisplayMode
.
Hidden
,
})
.
addCustomEditor
<
StatsPickerConfigSettings
,
string
[]
>
({
id
:
'legend.calcs'
,
path
:
'legend.calcs'
,
name
:
'Legend calculations'
,
description
:
'Choose a reducer functions / calculations to include in legend'
,
editor
:
standardEditorsRegistry
.
get
(
'stats-picker'
).
editor
as
any
,
defaultValue
:
[],
settings
:
{
allowMultiple
:
true
,
},
showIf
:
(
currentConfig
)
=>
currentConfig
.
legend
.
displayMode
!==
LegendDisplayMode
.
Hidden
,
});
addLegendOptions
(
builder
);
});
public/app/plugins/panel/timeseries/types.ts
View file @
8c1a79f2
import
{
VizLegendOptions
,
GraphTooltipOptions
}
from
'@grafana/ui'
;
export
interface
GraphOptions
{
// Redraw as time passes
realTimeUpdates
?:
boolean
;
// nothing for now
}
export
interface
Options
{
graph
:
GraphOptions
;
export
interface
OptionsWithLegend
{
legend
:
VizLegendOptions
;
}
export
interface
Options
extends
OptionsWithLegend
{
graph
:
GraphOptions
;
tooltipOptions
:
GraphTooltipOptions
;
}
public/app/plugins/panel/xychart/XYDimsEditor.tsx
View file @
8c1a79f2
import
React
,
{
FC
,
use
Callback
,
use
Memo
}
from
'react'
;
import
React
,
{
FC
,
useMemo
}
from
'react'
;
import
{
css
}
from
'emotion'
;
import
{
IconButton
,
Label
,
Select
,
stylesFactory
,
Switch
,
useTheme
}
from
'@grafana/ui'
;
import
{
IconButton
,
Label
,
Select
,
stylesFactory
,
useTheme
}
from
'@grafana/ui'
;
import
{
SelectableValue
,
getFrameDisplayName
,
...
...
@@ -84,13 +84,6 @@ export const XYDimsEditor: FC<StandardEditorProps<XYDimensionConfig, any, Option
return
v
;
},
[
dims
,
context
.
data
,
value
]);
const
toggleSort
=
useCallback
(()
=>
{
onChange
({
...
value
,
sort
:
!
value
?.
sort
,
});
},
[
value
,
onChange
]);
const
theme
=
useTheme
();
const
styles
=
getStyles
(
theme
);
...
...
@@ -118,10 +111,6 @@ export const XYDimsEditor: FC<StandardEditorProps<XYDimensionConfig, any, Option
});
}
}
/>
<
div
className=
{
styles
.
sorter
}
>
<
Switch
value=
{
value
?.
sort
??
false
}
onClick=
{
toggleSort
}
/>
<
div
onClick=
{
toggleSort
}
>
Sort field
</
div
>
</
div
>
<
br
/>
<
Label
>
Y Fields
</
Label
>
<
div
>
...
...
public/app/plugins/panel/xychart/dims.ts
View file @
8c1a79f2
import
{
DataFrame
,
Field
,
FieldMatcher
,
FieldType
,
getFieldDisplayName
,
sortDataFrame
}
from
'@grafana/data'
;
import
{
DataFrame
,
Field
,
FieldMatcher
,
FieldType
,
getFieldDisplayName
}
from
'@grafana/data'
;
import
{
XYFieldMatchers
}
from
'@grafana/ui/src/components/GraphNG/GraphNG'
;
import
{
XYDimensionConfig
}
from
'./types'
;
...
...
@@ -49,11 +49,6 @@ export function getXYDimensions(cfg: XYDimensionConfig, data?: DataFrame[]): XYD
}
}
// Optionally sort
if
(
cfg
.
sort
)
{
frame
=
sortDataFrame
(
frame
,
xIndex
);
}
let
hasTime
=
false
;
const
x
=
frame
.
fields
[
xIndex
];
const
fields
:
Field
[]
=
[
x
];
...
...
@@ -92,12 +87,14 @@ function getSimpleFieldMatcher(f: Field): FieldMatcher {
if
(
!
f
)
{
return
()
=>
false
;
}
return
(
field
)
=>
f
===
field
;
// the field may change if sorted
return
(
field
)
=>
f
===
field
||
!!
(
f
.
state
&&
f
.
state
===
field
.
state
);
}
function
getSimpleFieldNotMatcher
(
f
:
Field
):
FieldMatcher
{
if
(
!
f
)
{
return
()
=>
false
;
}
return
(
field
)
=>
f
!==
field
;
const
m
=
getSimpleFieldMatcher
(
f
);
return
(
field
)
=>
!
m
(
field
,
undefined
as
any
,
undefined
as
any
);
}
public/app/plugins/panel/xychart/module.tsx
View file @
8c1a79f2
import
{
PanelPlugin
}
from
'@grafana/data'
;
import
{
DrawStyle
,
GraphFieldConfig
,
LegendDisplayMode
}
from
'@grafana/ui'
;
import
{
DrawStyle
,
GraphFieldConfig
}
from
'@grafana/ui'
;
import
{
XYChartPanel
}
from
'./XYChartPanel'
;
import
{
Options
}
from
'./types'
;
import
{
XYDimsEditor
}
from
'./XYDimsEditor'
;
import
{
getGraphFieldConfig
,
defaultGraphConfig
}
from
'../timeseries/config'
;
import
{
getGraphFieldConfig
,
defaultGraphConfig
,
addLegendOptions
}
from
'../timeseries/config'
;
export
const
plugin
=
new
PanelPlugin
<
Options
,
GraphFieldConfig
>
(
XYChartPanel
)
.
useFieldConfig
(
...
...
@@ -32,31 +32,7 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(XYChartPanel)
{
value
:
'none'
,
label
:
'Hidden'
},
],
},
})
.
addRadio
({
path
:
'legend.displayMode'
,
name
:
'Legend mode'
,
description
:
''
,
defaultValue
:
LegendDisplayMode
.
List
,
settings
:
{
options
:
[
{
value
:
LegendDisplayMode
.
List
,
label
:
'List'
},
{
value
:
LegendDisplayMode
.
Table
,
label
:
'Table'
},
{
value
:
LegendDisplayMode
.
Hidden
,
label
:
'Hidden'
},
],
},
})
.
addRadio
({
path
:
'legend.placement'
,
name
:
'Legend placement'
,
description
:
''
,
defaultValue
:
'bottom'
,
settings
:
{
options
:
[
{
value
:
'bottom'
,
label
:
'Bottom'
},
{
value
:
'right'
,
label
:
'Right'
},
],
},
showIf
:
(
c
)
=>
c
.
legend
.
displayMode
!==
LegendDisplayMode
.
Hidden
,
});
addLegendOptions
(
builder
);
});
public/app/plugins/panel/xychart/types.ts
View file @
8c1a79f2
import
{
VizLegendOptions
,
GraphTooltipOptions
}
from
'@grafana/ui'
;
import
{
GraphTooltipOptions
}
from
'@grafana/ui'
;
import
{
OptionsWithLegend
}
from
'../timeseries/types'
;
export
interface
XYDimensionConfig
{
frame
:
number
;
sort
?:
boolean
;
x
?:
string
;
// name | first
exclude
?:
string
[];
// all other numbers except
}
export
interface
Options
{
export
interface
Options
extends
OptionsWithLegend
{
dims
:
XYDimensionConfig
;
legend
:
VizLegendOptions
;
tooltipOptions
:
GraphTooltipOptions
;
}
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