//===-- xray-graph.cpp: XRay Function Call Graph Renderer -----------------===// // // 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. // //===----------------------------------------------------------------------===// #include "xray-color-helper.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" #include <cmath> usingnamespacellvm; usingnamespacexray; // Sequential ColorMaps, which are used to represent information // from some minimum to some maximum. const std::tuple<uint8_t, uint8_t, uint8_t> SequentialMaps[][9] = …; // Sequential Maps extend the last colors given out of range inputs. const std::tuple<uint8_t, uint8_t, uint8_t> SequentialBounds[][2] = …; ColorHelper::ColorHelper(ColorHelper::SequentialScheme S) : … { … } // Diverging ColorMaps, 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]. const std::tuple<uint8_t, uint8_t, uint8_t> DivergingCoeffs[][11] = …; // Diverging maps use out of bounds ranges to show missing data. Missing Right // Being below min, and missing left being above max. const std::tuple<uint8_t, uint8_t, uint8_t> DivergingBounds[][2] = …; ColorHelper::ColorHelper(ColorHelper::DivergingScheme S) : … { … } // Takes a tuple of uint8_ts representing a color in RGB and converts them to // HSV represented by a tuple of doubles static std::tuple<double, double, double> convertToHSV(const std::tuple<uint8_t, uint8_t, uint8_t> &Color) { … } // Takes a double precision number, clips it between 0 and 1 and then converts // that to an integer between 0x00 and 0xFF with proxpper rounding. static uint8_t unitIntervalTo8BitChar(double B) { … } // Takes a typle of doubles representing a color in HSV and converts them to // RGB represented as a tuple of uint8_ts static std::tuple<uint8_t, uint8_t, uint8_t> convertToRGB(const std::tuple<double, double, double> &Color) { … } // The Hue component of the HSV interpolation Routine static double interpolateHue(double H0, double H1, double T) { … } // Interpolates between two HSV Colors both represented as a tuple of doubles // Returns an HSV Color represented as a tuple of doubles static std::tuple<double, double, double> interpolateHSV(const std::tuple<double, double, double> &C0, const std::tuple<double, double, double> &C1, double T) { … } // Get the Color as a tuple of uint8_ts std::tuple<uint8_t, uint8_t, uint8_t> ColorHelper::getColorTuple(double Point) const { … } // A helper method to convert a color represented as tuple of uint8s to a hex // string. std::string ColorHelper::getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t) { … } // Gets a color in a gradient given a number in the interval [0,1], it does this // by evaluating a polynomial which maps [0, 1] -> [0, 1] for each of the R G // and B values in the color. It then converts this [0,1] colors to a 24 bit // color as a hex string. std::string ColorHelper::getColorString(double Point) const { … }