1 //===-- xray-graph.h - XRay Function Call Graph Renderer --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // A class to get a color from a specified gradient.
12 //===----------------------------------------------------------------------===//
14 #ifndef XRAY_COLOR_HELPER_H
15 #define XRAY_COLOR_HELPER_H
19 #include "llvm/ADT/ArrayRef.h"
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.
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].
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
39 /// ColorHelper D(ColorHelper::DivergingScheme::Spectral); // Choose a color
41 /// for (double p= -1; p <= 1 ; p += 0.1){
42 /// cout() << D.getColor(p) << " \n"; // sample the gradient at 0.1 intervals
48 ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> ColorMap;
49 ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> BoundMap;
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.
61 ColorHelper(SequentialScheme S);
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.
70 ColorHelper(DivergingScheme S);
72 // Sample the gradient at the input point.
73 std::tuple<uint8_t, uint8_t, uint8_t> getColorTuple(double Point) const;
75 std::string getColorString(double Point) const;
77 // Get the Default color, at the moment allways black.
78 std::tuple<uint8_t, uint8_t, uint8_t> getDefaultColorTuple() const {
79 return std::make_tuple(0, 0, 0);
82 std::string getDefaultColorString() const { return "black"; }
84 // Convert a tuple to a string
85 static std::string getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t);