Repository navigation
Expand file tree
/
Copy pathItemColors.cs
More file actions
102 lines (90 loc) · 3.3 KB
/
Copy pathItemColors.cs
File metadata and controls
102 lines (90 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// SPDX-FileCopyrightText: Copyright (c) 2005-2026, OPC Federation AISBL
// SPDX-License-Identifier: MIT
using Avalonia.Media;
using UaLens.Themes;
namespace UaLens.Views;
/// <summary>
/// 12-colour palette used to give every monitored item a stable, distinct
/// colour in the AnimationCanvas (Dots-mode lanes and Bars-mode segments)
/// and in the ScottPlot views (Signal / Histogram / Heatmap). Keyed by
/// <c>ItemId</c> so a given item retains its colour across add/remove
/// operations of other items. Wraps around when more items than palette
/// slots are subscribed.
/// </summary>
internal static class ItemColors
{
public static int Count => s_dark.Length;
/// <summary>
/// Stable palette slot for a given monitored-item identity.
/// </summary>
public static int IndexForItemId(int id)
{
return ((id % Count) + Count) % Count;
}
/// <summary>
/// Theme-aware Avalonia brush without changing the item's palette slot.
/// </summary>
public static IBrush ForItemId(int id)
{
return ForItemId(id, ChartTheme.IsLight);
}
public static IBrush ForItemId(int id, bool isLight)
{
return (isLight ? s_lightBrushes : s_darkBrushes)[IndexForItemId(id)];
}
/// <summary>
/// Stable <see cref="ScottPlot.Color"/> for a given monitored-item id.
/// Sharing this palette across the Avalonia canvas and the ScottPlot
/// views keeps a given item the same colour everywhere.
/// </summary>
public static ScottPlot.Color ScottPlotForItemId(int id)
{
return ScottPlotForItemId(id, ChartTheme.IsLight);
}
public static ScottPlot.Color ScottPlotForItemId(int id, bool isLight)
{
Color color = (isLight ? s_light : s_dark)[IndexForItemId(id)];
return new ScottPlot.Color(color.R, color.G, color.B);
}
private static IBrush[] BuildBrushes(Color[] colors)
{
var brushes = new IBrush[colors.Length];
for (int i = 0; i < colors.Length; i++)
{
brushes[i] = new SolidColorBrush(colors[i]);
}
return brushes;
}
private static readonly Color[] s_dark =
[
Color.FromRgb(0x22, 0xC5, 0x5E),
Color.FromRgb(0xF5, 0x9E, 0x0B),
Color.FromRgb(0x06, 0xB6, 0xD4),
Color.FromRgb(0xEC, 0x49, 0x99),
Color.FromRgb(0x60, 0xA5, 0xFA),
Color.FromRgb(0xFB, 0x71, 0x85),
Color.FromRgb(0xFA, 0xCC, 0x15),
Color.FromRgb(0x4A, 0xDE, 0x80),
Color.FromRgb(0xC0, 0x84, 0xFC),
Color.FromRgb(0xF8, 0x71, 0x71),
Color.FromRgb(0x2D, 0xD4, 0xBF),
Color.FromRgb(0xD9, 0xF9, 0x9D)
];
private static readonly Color[] s_light =
[
Color.FromRgb(0x16, 0x65, 0x34),
Color.FromRgb(0x92, 0x40, 0x0E),
Color.FromRgb(0x0E, 0x74, 0x90),
Color.FromRgb(0xBE, 0x18, 0x5D),
Color.FromRgb(0x1D, 0x4E, 0xD8),
Color.FromRgb(0xBE, 0x12, 0x3C),
Color.FromRgb(0x85, 0x4D, 0x0E),
Color.FromRgb(0x15, 0x80, 0x3D),
Color.FromRgb(0x7E, 0x22, 0xCE),
Color.FromRgb(0xB9, 0x1C, 0x1C),
Color.FromRgb(0x0F, 0x76, 0x6E),
Color.FromRgb(0x4D, 0x7C, 0x0F)
];
private static readonly IBrush[] s_darkBrushes = BuildBrushes(s_dark);
private static readonly IBrush[] s_lightBrushes = BuildBrushes(s_light);
}