• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> BoundMap;
50 
51 public:
52   /// Enum of the availible Sequential Color Schemes
53   enum class SequentialScheme {
54     // Schemes based on the ColorBrewer Color schemes of the same name from
55     // http://www.colorbrewer.org/ by Cynthis A Brewer Penn State University.
56     Greys,
57     OrRd,
58     PuBu
59   };
60 
61   ColorHelper(SequentialScheme S);
62 
63   /// Enum of the availible Diverging Color Schemes
64   enum class DivergingScheme {
65     // Schemes based on the ColorBrewer Color schemes of the same name from
66     // http://www.colorbrewer.org/ by Cynthis A Brewer Penn State University.
67     PiYG
68   };
69 
70   ColorHelper(DivergingScheme S);
71 
72   // Sample the gradient at the input point.
73   std::tuple<uint8_t, uint8_t, uint8_t> getColorTuple(double Point) const;
74 
75   std::string getColorString(double Point) const;
76 
77   // Get the Default color, at the moment allways black.
getDefaultColorTuple()78   std::tuple<uint8_t, uint8_t, uint8_t> getDefaultColorTuple() const {
79     return std::make_tuple(0, 0, 0);
80   }
81 
getDefaultColorString()82   std::string getDefaultColorString() const { return "black"; }
83 
84   // Convert a tuple to a string
85   static std::string getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t);
86 };
87 } // namespace xray
88 } // namespace llvm
89 #endif
90