]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-xray/xray-color-helper.h
Merge clang trunk r300422 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-xray / xray-color-helper.h
1 //===-- xray-graph.h - XRay Function Call Graph Renderer --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // A class to get a color from a specified gradient.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef XRAY_COLOR_HELPER_H
15 #define XRAY_COLOR_HELPER_H
16
17 #include <tuple>
18
19 #include "llvm/ADT/ArrayRef.h"
20
21 namespace llvm {
22 namespace xray {
23
24 /// The color helper class it a healper class which allows you to easily get a
25 /// color in a gradient. This is used to color-code edges in XRay-Graph tools.
26 ///
27 /// There are two types of color schemes in this class:
28 ///   - Sequential schemes, which are used to represent information from some
29 ///     minimum to some maximum. These take an input in the range [0,1]
30 ///   - Diverging schemes, which are used to represent information representing
31 ///     differenes, or a range that goes from negative to positive. These take
32 ///     an input in the range [-1,1].
33 /// Usage;
34 /// ColorHelper S(ColorHelper::SequentialScheme::OrRd); //Chose a color scheme.
35 /// for (double p = 0.0; p <= 1; p += 0.1){
36 ///   cout() << S.getColor(p) << " \n"; // Sample the gradient at 0.1 intervals
37 /// }
38 ///
39 /// ColorHelper D(ColorHelper::DivergingScheme::Spectral); // Choose a color
40 ///                                                        // scheme.
41 /// for (double p= -1; p <= 1 ; p += 0.1){
42 ///   cout() << D.getColor(p) << " \n"; // sample the gradient at 0.1 intervals
43 /// }
44 class ColorHelper {
45   double MinIn;
46   double MaxIn;
47
48   ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> ColorMap;
49
50 public:
51   /// Enum of the availible Sequential Color Schemes
52   enum class SequentialScheme {
53     // Schemes based on the ColorBrewer Color schemes of the same name from
54     // http://www.colorbrewer.org/ by Cynthis A Brewer Penn State University.
55     Greys,
56     OrRd,
57     PuBu
58   };
59
60   ColorHelper(SequentialScheme S);
61
62   /// Enum of the availible Diverging Color Schemes
63   enum class DivergingScheme {
64     // Schemes based on the ColorBrewer Color schemes of the same name from
65     // http://www.colorbrewer.org/ by Cynthis A Brewer Penn State University.
66     PiYG
67   };
68
69   ColorHelper(DivergingScheme S);
70
71   // Sample the gradient at the input point.
72   std::tuple<uint8_t, uint8_t, uint8_t> getColorTuple(double Point) const;
73
74   std::string getColorString(double Point) const;
75
76   // Convert a tuple to a string
77   static std::string getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t);
78 };
79 }
80 }
81 #endif