Skip to content

Commit fa9900a

Browse files
feat(commonlib): Move style choices to design tokens dir (#1516)
* Move style choices to design tokens dir Making eaier to manage those choices and override those in the future in one place. * Add default stylize * Update default style: Remove misleading thresholds from grafana by default * Fix typo * Fix generic stat * Revert thresholds * Update panels * Fix topk percentage --------- Co-authored-by: Emily <1282515+Dasomeone@users.noreply.github.com>
1 parent 5270fb9 commit fa9900a

23 files changed

+163
-42
lines changed

common-lib/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.5.0
2+
- [Panels] feat: Move style choices (colors, line styles) to design tokens directory.
3+
14
# 0.4.3
25
- [Signal] fix: No longer aggregates histogram signals after histogram_quantile() as it is pointless aggregation. Aggregation before applying histogram_quantile() is kept and works as expected.
36

common-lib/common/main.libsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
annotations: import './annotations/main.libsonnet',
3+
tokens: import './tokens/main.libsonnet',
34
panels: import './panels.libsonnet',
45
variables: import './variables/variables.libsonnet',
56
utils: import './utils.libsonnet',

common-lib/common/panels/generic/base.libsonnet

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
local g = import '../../g.libsonnet';
2-
2+
local tokens = import '../../tokens/main.libsonnet';
33
local timeSeries = g.panel.timeSeries;
44
local fieldOverride = g.panel.timeSeries.fieldOverride;
55
local custom = timeSeries.fieldConfig.defaults.custom;
66
local defaults = timeSeries.fieldConfig.defaults;
77
local options = timeSeries.options;
8+
local standardOptions = timeSeries.standardOptions;
89

9-
// This is base of ALL panels in the common lib
10+
// This is the base of ALL panels in the common lib
1011
{
1112
new(targets, description=''):
1213
// hidden field to hold styles modifiers
@@ -22,6 +23,19 @@ local options = timeSeries.options;
2223
) else {})
2324
+ self.stylize(),
2425

25-
stylize(): {},
26+
stylize():
27+
standardOptions.color.withMode(tokens.base.colors.mode.default)
28+
+ standardOptions.color.withFixedColor(tokens.base.colors.palette.default)
29+
// remove 0-80(green), >80 red threshold by default.
30+
{
31+
fieldConfig+: {
32+
defaults+: {
33+
thresholds: {
34+
mode: 'absolute',
35+
steps: [],
36+
},
37+
},
38+
},
39+
},
2640

2741
}

common-lib/common/panels/generic/stat/base.libsonnet

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local g = import '../../../g.libsonnet';
2+
local tokens = import '../../../tokens/main.libsonnet';
23
local stat = g.panel.stat;
34
local base = import '../base.libsonnet';
45

@@ -9,6 +10,23 @@ base {
910

1011
stylize(allLayers=true):
1112
(if allLayers then super.stylize() else {})
12-
+ stat.standardOptions.color.withMode('fixed')
13-
+ stat.standardOptions.color.withFixedColor('text'),
13+
+ stat.standardOptions.color.withMode(tokens.base.colors.mode.single)
14+
+ stat.standardOptions.color.withFixedColor(tokens.base.colors.palette.default)
15+
// remove 0-80(green), >80 red threshold by default.
16+
+ {
17+
fieldConfig+: {
18+
defaults+: {
19+
20+
thresholds: {
21+
mode: 'absolute',
22+
steps: [
23+
{
24+
color: tokens.base.colors.palette.default,
25+
value: null,
26+
},
27+
],
28+
},
29+
},
30+
},
31+
},
1432
}

common-lib/common/panels/generic/stat/info.libsonnet

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local g = import '../../../g.libsonnet';
2+
local tokens = import '../../../tokens/main.libsonnet';
23
local base = import './base.libsonnet';
34
local stat = g.panel.stat;
45
// Simple info panel prototype with text or count of things.
@@ -7,8 +8,8 @@ base {
78
stylize(allLayers=true):
89
(if allLayers then super.stylize() else {})
910
// Style choice: No color for simple text panels by default
10-
+ stat.options.withColorMode('fixed')
11-
+ stat.standardOptions.color.withFixedColor('text')
11+
+ stat.standardOptions.color.withMode(tokens.base.colors.mode.single)
12+
+ stat.standardOptions.color.withFixedColor(tokens.base.colors.palette.text)
1213
// Style choice: No graph
1314
+ stat.options.withGraphMode('none')
1415
// Show last value by default, not mean.

common-lib/common/panels/generic/stat/percentage.libsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local g = import '../../../g.libsonnet';
2+
local tokens = import '../../../tokens/main.libsonnet';
23
local stat = g.panel.stat;
34
local base = import './base.libsonnet';
45
// This panel can be used to display gauge metrics with possible values range 0-100%.
@@ -11,7 +12,7 @@ base {
1112
+ stat.standardOptions.withUnit('percent')
1213
+ stat.options.withColorMode('value')
1314
// Change color from blue(cold) to red(hot)
14-
+ stat.standardOptions.color.withMode('continuous-BlYlRd')
15+
+ stat.standardOptions.color.withMode(tokens.base.colors.mode.coldhot)
1516
+ stat.standardOptions.withMax(100)
1617
+ stat.standardOptions.withMin(0)
1718
// Show last value by default, not mean.

common-lib/common/panels/generic/table/cold_hot_gauge.libsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local timeSeries = g.panel.timeSeries;
44
local percentage = import '../timeSeries/percentage.libsonnet';
55
local fieldOverride = g.panel.timeSeries.fieldOverride;
66
local fieldConfig = g.panel.timeSeries.fieldConfig;
7+
local tokens = import '../../../tokens/main.libsonnet';
78
local base = import './base.libsonnet';
89
// This panel can be used to display gauge metrics in table columns with unknown max/min values.
910
// Examples: Network bandwidth, RPS.
@@ -19,7 +20,7 @@ base {
1920
+ fieldOverride.byName.withProperty('custom.cellOptions', { type: 'gauge', mode: 'basic' })
2021
+ fieldOverride.byName.withProperty('fieldMinMax', true)
2122
+ fieldOverride.byName.withPropertiesFromOptions(
22-
timeSeries.standardOptions.color.withMode('continuous-BlYlRd')
23+
timeSeries.standardOptions.color.withMode(tokens.base.colors.mode.coldhot)
2324
),
2425
),
2526
}

common-lib/common/panels/generic/timeSeries/base.libsonnet

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local g = import '../../../g.libsonnet';
2+
local tokens = import '../../../tokens/main.libsonnet';
23

34
local timeSeries = g.panel.timeSeries;
45
local fieldOverride = g.panel.timeSeries.fieldOverride;
@@ -14,16 +15,11 @@ base {
1415

1516
stylize(allLayers=true):
1617
(if allLayers then super.stylize() else {})
17-
// Style choice: Make lines more thick
18-
+ custom.withLineWidth(2)
19-
// Style choice: Opacity level
20-
+ custom.withFillOpacity(30)
21-
// Style choice: Don't show points on lines
22-
+ custom.withShowPoints('never')
23-
// Style choice: Opacity gradient
24-
+ custom.withGradientMode('opacity')
25-
// Style choice: Smoother lines
26-
+ custom.withLineInterpolation('smooth')
18+
+ custom.withLineWidth(tokens.panels.timeSeries.lines.width.default)
19+
+ custom.withFillOpacity(tokens.panels.timeSeries.lines.opacity.default)
20+
+ custom.withShowPoints(tokens.panels.timeSeries.lines.showPoints.default)
21+
+ custom.withGradientMode(tokens.panels.timeSeries.lines.gradientMode.default)
22+
+ custom.withLineInterpolation(tokens.panels.timeSeries.lines.interpolation.default)
2723
// Style choice: Show all values in tooltip, sorted
2824
+ options.tooltip.withMode('multi')
2925
+ options.tooltip.withSort('desc')

common-lib/common/panels/generic/timeSeries/percentage.libsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local g = import '../../../g.libsonnet';
2+
local tokens = import '../../../tokens/main.libsonnet';
23
local timeSeries = g.panel.timeSeries;
34
local base = import './base.libsonnet';
45
// This panel can be used to display gauge metrics with possible values range 0-100%.
@@ -9,7 +10,7 @@ base {
910
+ timeSeries.standardOptions.withDecimals(1)
1011
+ timeSeries.standardOptions.withUnit('percent')
1112
// Change color from blue(cold) to red(hot)
12-
+ timeSeries.standardOptions.color.withMode('continuous-BlYlRd')
13+
+ timeSeries.standardOptions.color.withMode(tokens.base.colors.mode.coldhot)
1314
+ timeSeries.fieldConfig.defaults.custom.withGradientMode('scheme')
1415
+ timeSeries.standardOptions.withMax(100)
1516
+ timeSeries.standardOptions.withMin(0),

common-lib/common/panels/generic/timeSeries/threshold.libsonnet

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local g = import '../../../g.libsonnet';
2+
local tokens = import '../../../tokens/main.libsonnet';
23
local timeSeries = g.panel.timeSeries;
34
local fieldOverride = g.panel.timeSeries.fieldOverride;
45
local fieldConfig = g.panel.timeSeries.fieldConfig;
@@ -15,8 +16,8 @@ local fieldConfig = g.panel.timeSeries.fieldConfig;
1516
}
1617
)
1718
+ fieldConfig.defaults.custom.withFillOpacity(0)
18-
+ timeSeries.standardOptions.color.withMode('fixed')
19-
+ timeSeries.standardOptions.color.withFixedColor('light-orange'),
19+
+ timeSeries.standardOptions.color.withMode(tokens.base.colors.mode.single)
20+
+ timeSeries.standardOptions.color.withFixedColor(tokens.base.colors.palette.threshold),
2021
stylizeByRegexp(regexp):
2122
timeSeries.standardOptions.withOverridesMixin(
2223
fieldOverride.byRegexp.new(regexp)

0 commit comments

Comments
 (0)