]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-xray/xray-color-helper.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-xray / xray-color-helper.h
1 //===-- xray-graph.h - XRay Function Call Graph Renderer --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // A class to get a color from a specified gradient.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef XRAY_COLOR_HELPER_H
14 #define XRAY_COLOR_HELPER_H
15
16 #include <tuple>
17
18 #include "llvm/ADT/ArrayRef.h"
19
20 namespace llvm {
21 namespace xray {
22
23 /// The color helper class it a healper class which allows you to easily get a
24 /// color in a gradient. This is used to color-code edges in XRay-Graph tools.
25 ///
26 /// There are two types of color schemes in this class:
27 ///   - Sequential schemes, which are used to represent information from some
28 ///     minimum to some maximum. These take an input in the range [0,1]
29 ///   - Diverging schemes, which are used to represent information representing
30 ///     differenes, or a range that goes from negative to positive. These take
31 ///     an input in the range [-1,1].
32 /// Usage;
33 /// ColorHelper S(ColorHelper::SequentialScheme::OrRd); //Chose a color scheme.
34 /// for (double p = 0.0; p <= 1; p += 0.1){
35 ///   cout() << S.getColor(p) << " \n"; // Sample the gradient at 0.1 intervals
36 /// }
37 ///
38 /// ColorHelper D(ColorHelper::DivergingScheme::Spectral); // Choose a color
39 ///                                                        // scheme.
40 /// for (double p= -1; p <= 1 ; p += 0.1){
41 ///   cout() << D.getColor(p) << " \n"; // sample the gradient at 0.1 intervals
42 /// }
43 class ColorHelper {
44   double MinIn;
45   double MaxIn;
46
47   ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> ColorMap;
48   ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> BoundMap;
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   // Get the Default color, at the moment allways black.
77   std::tuple<uint8_t, uint8_t, uint8_t> getDefaultColorTuple() const {
78     return std::make_tuple(0, 0, 0);
79   }
80
81   std::string getDefaultColorString() const { return "black"; }
82
83   // Convert a tuple to a string
84   static std::string getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t);
85 };
86 } // namespace xray
87 } // namespace llvm
88 #endif