fix(app): meaning colours for common outcomes; detail pages fill the pane
Timeline outcomes: success-like words are green, failures red, rejections orange, retries/advisories amber, skips/cancellations grey; a second word of the same family takes the family's next shade and any other word a distinct hue outside the families, so different outcomes still never share a colour. Run detail, stage page and pipeline Summary no longer cap their width at 840: on an unfolded foldable the sections fill the pane. The unused ReadingWidth helper is removed.
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// The widest a detail's reading body (a run or pipeline Summary, a stage
|
||||
/// page's sections) grows on a wide window, so its text, trailing copy
|
||||
/// buttons and facts stay within reach of the title instead of stretching
|
||||
/// to the window's far edge.
|
||||
const double kReadingMaxWidth = 840;
|
||||
|
||||
/// Caps [child] at [maxWidth] from the leading edge, where the detail's bar
|
||||
/// pieces, header strip and tabs start. It passes the full height through
|
||||
/// unchanged, so a scrollable child fills the height as before; only its
|
||||
/// width is capped.
|
||||
class ReadingWidth extends StatelessWidget {
|
||||
const ReadingWidth({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.maxWidth = kReadingMaxWidth,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final double maxWidth;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
// One structure at every width, so resizing across the cap never
|
||||
// remounts the body (its scroll offset and open sections stay).
|
||||
builder: (context, constraints) {
|
||||
return Align(
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
child: SizedBox(
|
||||
width: math.min(maxWidth, constraints.maxWidth),
|
||||
height: constraints.hasBoundedHeight ? constraints.maxHeight : null,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,28 +1,44 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Colours for recorded outcome names, assigned per run by first appearance.
|
||||
/// Colours for recorded outcome names within one run.
|
||||
///
|
||||
/// Outcome words are pipeline-defined ('approved', 'rejected', 'retry', …), so
|
||||
/// no name is hard-wired to a colour: the same name always gets the same
|
||||
/// colour within a run and two different names never share one. The first
|
||||
/// [_hues] names use well-separated hues; later ones continue around the
|
||||
/// colour wheel by the golden angle so they stay distinct.
|
||||
/// Well-known outcome words get a colour family that matches their meaning —
|
||||
/// success-like words are green, failures red, rejections orange, retries and
|
||||
/// advisories amber, skips and cancellations grey — and every other word gets
|
||||
/// a distinct hue outside those families, by first appearance. The same name
|
||||
/// always gets the same colour, and two different names never share one: a
|
||||
/// second word of the same family takes that family's next shade.
|
||||
class OutcomePalette {
|
||||
OutcomePalette(Iterable<String> outcomes) {
|
||||
final familyUse = <_Family, int>{};
|
||||
var other = 0;
|
||||
for (final outcome in outcomes) {
|
||||
final key = _key(outcome);
|
||||
if (key.isNotEmpty) _index.putIfAbsent(key, () => _index.length);
|
||||
if (key.isEmpty || _swatches.containsKey(key)) continue;
|
||||
final family = _familyOf(key);
|
||||
if (family != null) {
|
||||
final used = familyUse[family] ?? 0;
|
||||
final shades = _familyShades[family]!;
|
||||
if (used < shades.length) {
|
||||
familyUse[family] = used + 1;
|
||||
_swatches[key] = _Swatch.material(shades[used]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_swatches[key] = other < _otherHues.length
|
||||
? _Swatch.material(_otherHues[other])
|
||||
: _Swatch.wheel(other);
|
||||
other += 1;
|
||||
}
|
||||
}
|
||||
|
||||
final Map<String, int> _index = {};
|
||||
final Map<String, _Swatch> _swatches = {};
|
||||
|
||||
static String _key(String outcome) => outcome.trim().toLowerCase();
|
||||
|
||||
/// The position [outcome] was first seen at, or null for a blank or unseen
|
||||
/// name.
|
||||
int? indexOf(String outcome) => _index[_key(outcome)];
|
||||
/// Whether [outcome] was seen (and so has a colour of its own).
|
||||
bool contains(String outcome) => _swatches.containsKey(_key(outcome));
|
||||
|
||||
/// [outcome]'s colour for the host's brightness; an unseen or blank name
|
||||
/// uses the host's secondary text colour.
|
||||
@@ -32,37 +48,107 @@ class OutcomePalette {
|
||||
final brightness = cupertino
|
||||
? CupertinoTheme.brightnessOf(context)
|
||||
: Theme.of(context).brightness;
|
||||
final index = indexOf(outcome);
|
||||
if (index == null) {
|
||||
final swatch = _swatches[_key(outcome)];
|
||||
if (swatch == null) {
|
||||
return cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
}
|
||||
return outcomeColorAt(index, brightness);
|
||||
return swatch.resolve(brightness);
|
||||
}
|
||||
|
||||
/// [outcome]'s colour on a page of [brightness], or null when unseen.
|
||||
Color? colorForBrightness(String outcome, Brightness brightness) =>
|
||||
_swatches[_key(outcome)]?.resolve(brightness);
|
||||
}
|
||||
|
||||
const List<MaterialColor> _hues = [
|
||||
enum _Family { success, failure, rejection, caution, neutral }
|
||||
|
||||
/// The meaning a well-known outcome word carries, if any.
|
||||
_Family? _familyOf(String key) {
|
||||
final word = key.replaceAll(RegExp(r'[\s-]+'), '_');
|
||||
const success = {
|
||||
'success',
|
||||
'succeeded',
|
||||
'ok',
|
||||
'pass',
|
||||
'passed',
|
||||
'approved',
|
||||
'accepted',
|
||||
'done',
|
||||
'completed',
|
||||
'complete',
|
||||
'merged',
|
||||
'landed',
|
||||
};
|
||||
const failure = {'error', 'failure', 'failed', 'fail', 'crashed', 'broken'};
|
||||
const rejection = {
|
||||
'rejected',
|
||||
'reject',
|
||||
'blocked',
|
||||
'denied',
|
||||
'declined',
|
||||
'changes_requested',
|
||||
};
|
||||
const caution = {
|
||||
'retry',
|
||||
'blocked_retryable',
|
||||
'advisory',
|
||||
'warning',
|
||||
'needs_work',
|
||||
'partial',
|
||||
};
|
||||
const neutral = {
|
||||
'skipped',
|
||||
'skip',
|
||||
'canceled',
|
||||
'cancelled',
|
||||
'stopped',
|
||||
'none',
|
||||
};
|
||||
if (success.contains(word)) return _Family.success;
|
||||
if (failure.contains(word)) return _Family.failure;
|
||||
if (rejection.contains(word)) return _Family.rejection;
|
||||
if (caution.contains(word)) return _Family.caution;
|
||||
if (neutral.contains(word)) return _Family.neutral;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Each family's shades, in the order successive distinct words take them.
|
||||
const Map<_Family, List<MaterialColor>> _familyShades = {
|
||||
_Family.success: [Colors.green, Colors.lightGreen, Colors.teal],
|
||||
_Family.failure: [Colors.red, Colors.pink],
|
||||
_Family.rejection: [Colors.deepOrange, Colors.orange],
|
||||
_Family.caution: [Colors.amber, Colors.yellow],
|
||||
_Family.neutral: [Colors.blueGrey, Colors.grey],
|
||||
};
|
||||
|
||||
/// Hues for words with no family, chosen away from the family colours.
|
||||
const List<MaterialColor> _otherHues = [
|
||||
Colors.blue,
|
||||
Colors.green,
|
||||
Colors.deepOrange,
|
||||
Colors.purple,
|
||||
Colors.teal,
|
||||
Colors.pink,
|
||||
Colors.amber,
|
||||
Colors.indigo,
|
||||
Colors.brown,
|
||||
Colors.cyan,
|
||||
Colors.brown,
|
||||
Colors.deepPurple,
|
||||
Colors.lightBlue,
|
||||
];
|
||||
|
||||
/// The colour for the [index]th distinct outcome, readable on the page in
|
||||
/// [brightness] (darker shades on light pages, lighter on dark).
|
||||
Color outcomeColorAt(int index, Brightness brightness) {
|
||||
final dark = brightness == Brightness.dark;
|
||||
if (index < _hues.length) {
|
||||
final hue = _hues[index];
|
||||
return dark ? hue.shade300 : hue.shade800;
|
||||
class _Swatch {
|
||||
const _Swatch.material(MaterialColor this.color) : wheelIndex = null;
|
||||
const _Swatch.wheel(int this.wheelIndex) : color = null;
|
||||
|
||||
final MaterialColor? color;
|
||||
final int? wheelIndex;
|
||||
|
||||
Color resolve(Brightness brightness) {
|
||||
final dark = brightness == Brightness.dark;
|
||||
final material = color;
|
||||
if (material != null) return dark ? material.shade300 : material.shade800;
|
||||
// Past the named hues, continue round the wheel by the golden angle,
|
||||
// starting from a blue-violet so the next words stay clear of the
|
||||
// families' greens, reds, oranges and ambers.
|
||||
final degrees = (230 + wheelIndex! * 137.508) % 360;
|
||||
return HSLColor.fromAHSL(1, degrees, 0.55, dark ? 0.72 : 0.35).toColor();
|
||||
}
|
||||
final degrees = (index * 137.508) % 360;
|
||||
return HSLColor.fromAHSL(1, degrees, 0.6, dark ? 0.7 : 0.35).toColor();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user