Class FuncDiscreteColorGuide
A color guide that uses a function to get an ID value and gives each ID its own color: the hue IdHues names for the ID when it names one, else the color GetDiscreteRgb(int, double, double) gives it. The value is an identity, not a magnitude: the same ID always gets the same color, and there is no range to configure.
public class FuncDiscreteColorGuide : IColorGuide, IMakeXmlSource, IGetColorGuide
- Inheritance
-
FuncDiscreteColorGuide
- Implements
- Inherited Members
- Extension Methods
Remarks
The guide exists only at runtime: MakeXmlSource(string, string, bool) returns null, so the guide is never written to a file.
Constructors
FuncDiscreteColorGuide(Func<object, double?>)
Initializes a new instance of the FuncDiscreteColorGuide class with one color per ID by GetDiscreteRgb(int, double, double): a tool ID, a file number.
public FuncDiscreteColorGuide(Func<object, double?> valueFunc)
Parameters
FuncDiscreteColorGuide(Func<object, double?>, IReadOnlyDictionary<int, double>)
Initializes a new instance of the FuncDiscreteColorGuide class with a hue per ID: the leaves of a color tree, whose hues the tree names.
public FuncDiscreteColorGuide(Func<object, double?> valueFunc, IReadOnlyDictionary<int, double> idHues)
Parameters
valueFuncFunc<object, double?>The function to get the ID value for coloring.
idHuesIReadOnlyDictionary<int, double>The HSL hue, 0 to 1, of each ID the table names; an ID it does not name is colored by GetDiscreteRgb(int, double, double). Null for one color per ID without a table. Kept by reference and only read: a host that changes the hues builds a new guide with a new table.
Properties
IdHues
Gets the HSL hue, 0 to 1, of each ID the guide names a hue for — the leaves of a color tree, by their ids — as the guide was built with it; null when every ID is colored by GetDiscreteRgb(int, double, double) alone. A host tells a guide built for one table from a guide built for another by this reference.
public IReadOnlyDictionary<int, double> IdHues { get; }
Property Value
ValueFunc
Gets the function that extracts the ID value from the input object for coloring.
public Func<object, double?> ValueFunc { get; }
Property Value
Methods
GetColorGuide()
Get IColorGuide.
public IColorGuide GetColorGuide()
Returns
GetIdRgb(double?)
Gets the color of an ID value under this guide's hue table.
public vec3d_t GetIdRgb(double? value)
Parameters
valuedouble?The ID value.
Returns
- vec3d_t
The hue IdHues names for the ID, at full saturation and half lightness (HslToRgb(double, double, double)), when
valueis an integer in the int range the table names; else GetRgb(double?): one color per ID, and NoValueGreen for null, NaN, a fraction or a value outside the range.
GetRgb(double?)
Gets the color of an ID value.
public static vec3d_t GetRgb(double? value)
Parameters
valuedouble?The ID value. Any integer is an ID, 0 and negative ones included.
Returns
- vec3d_t
GetDiscreteRgb(int, double, double) of the ID; NoValueGreen if
valueis null, NaN, not an integer, or outside the int range.
MakeXmlSource(string, string, bool)
Returns null: the guide is runtime-only and is never written to a file.
public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)
Parameters
baseDirectorystringThe base directory for resolving relative paths
relFilestringThe relative file path for the XML source
exhibitionOnlyboolif true, the extended file creation is suppressed.
Returns
- XElement
An XML element representing the object's state
Remarks
For the demand of easy moving source folder (especially project folder) without configuration file path corruption, the relative file path is applied.
The baseDirectory is typically the folder at the nearest configuration file folder.
Since the folder can be moving with the configuration file.
TryGetRgb(object, out vec3d_t)
Get rgb bystep.
public bool TryGetRgb(object step, out vec3d_t rgb)
Parameters
Returns
- bool
True when this guide has a colour for
step; false when it has none
Remarks
Always returns true, with the color GetIdRgb(double?) gives the step's ID: a step without an ID value gets NoValueGreen, never a false answer, which would be drawn white.
TryGetRgbWithPriority(object, out vec3d_t, out double)
Get color with the showing priority if the showing area overlapped by shrinking. Only effect on CubeTree.
public bool TryGetRgbWithPriority(object step, out vec3d_t rgb, out double attachmentPriority)
Parameters
stepobjectstep
rgbvec3d_trgb, when the method returns true
attachmentPrioritydoublepriority. Larger one takes priority. Set on either answer.
Returns
- bool
True when this guide has a colour for
step; false when it has none and the caller applies its own default
Remarks
Always returns true, with the color TryGetRgb(object, out vec3d_t) gives. The priority is always NaN: an ID has no magnitude to rank by.