xray-color-helper.h
2.99 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
//===-- xray-graph.h - XRay Function Call Graph Renderer --------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// A class to get a color from a specified gradient.
//
//===----------------------------------------------------------------------===//
#ifndef XRAY_COLOR_HELPER_H
#define XRAY_COLOR_HELPER_H
#include <tuple>
#include "llvm/ADT/ArrayRef.h"
namespace llvm {
namespace xray {
/// The color helper class it a healper class which allows you to easily get a
/// color in a gradient. This is used to color-code edges in XRay-Graph tools.
///
/// There are two types of color schemes in this class:
/// - Sequential schemes, which are used to represent information from some
/// minimum to some maximum. These take an input in the range [0,1]
/// - Diverging schemes, which are used to represent information representing
/// differenes, or a range that goes from negative to positive. These take
/// an input in the range [-1,1].
/// Usage;
/// ColorHelper S(ColorHelper::SequentialScheme::OrRd); //Chose a color scheme.
/// for (double p = 0.0; p <= 1; p += 0.1){
/// cout() << S.getColor(p) << " \n"; // Sample the gradient at 0.1 intervals
/// }
///
/// ColorHelper D(ColorHelper::DivergingScheme::Spectral); // Choose a color
/// // scheme.
/// for (double p= -1; p <= 1 ; p += 0.1){
/// cout() << D.getColor(p) << " \n"; // sample the gradient at 0.1 intervals
/// }
class ColorHelper {
double MinIn;
double MaxIn;
ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> ColorMap;
ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> BoundMap;
public:
/// Enum of the availible Sequential Color Schemes
enum class SequentialScheme {
// Schemes based on the ColorBrewer Color schemes of the same name from
// http://www.colorbrewer.org/ by Cynthis A Brewer Penn State University.
Greys,
OrRd,
PuBu
};
ColorHelper(SequentialScheme S);
/// Enum of the availible Diverging Color Schemes
enum class DivergingScheme {
// Schemes based on the ColorBrewer Color schemes of the same name from
// http://www.colorbrewer.org/ by Cynthis A Brewer Penn State University.
PiYG
};
ColorHelper(DivergingScheme S);
// Sample the gradient at the input point.
std::tuple<uint8_t, uint8_t, uint8_t> getColorTuple(double Point) const;
std::string getColorString(double Point) const;
// Get the Default color, at the moment allways black.
std::tuple<uint8_t, uint8_t, uint8_t> getDefaultColorTuple() const {
return std::make_tuple(0, 0, 0);
}
std::string getDefaultColorString() const { return "black"; }
// Convert a tuple to a string
static std::string getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t);
};
} // namespace xray
} // namespace llvm
#endif