Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
jet_color.h
Go to the documentation of this file.
1
2// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
3// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
4// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
5// or works. Modified works should carry a notice stating that you changed the software and should note the date and
6// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
7// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
8// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
9// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
10// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
11// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
12// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
13// are solely responsible for determining the appropriateness of using and distributing the software and you assume
14// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
15// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
16// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
17// damage to property. The software developed by NIST employees is not subject to copyright protection within the
18// United States.
19
20#ifndef HEDGEHOG_JET_COLOR_H
21#define HEDGEHOG_JET_COLOR_H
22
23#include <sstream>
24#include <iomanip>
25
27
29namespace hh {
30
33class JetColor : public ColorPicker {
34 public:
36 JetColor() = default;
37
39 ~JetColor() override = default;
40
46 std::string getRGBFromRange(std::chrono::nanoseconds const &value,
47 std::chrono::nanoseconds const &min,
48 std::chrono::nanoseconds const &range) override {
49 double
50 dVal = (double) value.count(), dMin = (double) min.count(), dRange = (double) range.count(),
51 dR = 1, dG = 1, dB = 1;
52
53 std::ostringstream oss;
54
55 if (dVal < dMin + 0.25 * dRange) {
56 dR = 0;
57 dG = (4 * dVal - dMin) / dRange;
58 } else if (dVal < (dMin + 0.5 * dRange)) {
59 dR = 0;
60 dB = 1 + 4 * (dMin + 0.25 * dRange - dVal) / dRange;
61 } else if (dVal < (dMin + 0.75 * dRange)) {
62 dR = 4 * (dVal - dMin - 0.5 * dRange) / dRange;
63 dB = 0;
64 } else {
65 dG = 1 + 4 * (dMin + 0.75 * dRange - dVal) / dRange;
66 dB = 0;
67 }
68
69 oss << "\"#"
70 << std::setfill('0') << std::setw(2) << std::hex << (uint16_t) std::clamp(dR * 255, 0., 255.)
71 << std::setfill('0') << std::setw(2) << std::hex << (uint16_t) std::clamp(dG * 255, 0., 255.)
72 << std::setfill('0') << std::setw(2) << std::hex << (uint16_t) std::clamp(dB * 255, 0., 255.)
73 << "\"";
74
75 return oss.str();
76 }
77};
78
79}
80#endif //HEDGEHOG_JET_COLOR_H
Hedgehog main namespace.
Jet color range.
Definition: jet_color.h:33
~JetColor() override=default
Default destructor.
JetColor()=default
Default constructor.
std::string getRGBFromRange(std::chrono::nanoseconds const &value, std::chrono::nanoseconds const &min, std::chrono::nanoseconds const &range) override
Get RGB value for a duration within a range for the jet color range.
Definition: jet_color.h:46
Color scheme abstraction for dot file generation.
Definition: color_picker.h:30