Index: test/tools/llvm-xray/X86/graph-color-simple-case.yaml =================================================================== --- test/tools/llvm-xray/X86/graph-color-simple-case.yaml +++ test/tools/llvm-xray/X86/graph-color-simple-case.yaml @@ -32,15 +32,15 @@ #EDGE: digraph xray { -#EDGE-DAG: F0 -> F7 [label="7.{{[0-9]*}}e+01" color="#B00100"]; -#EDGE-DAG: F0 -> F2 [label="2.{{[0-9]*}}e+01" color="#FD9965"]; -#EDGE-DAG: F0 -> F9 [label="9.{{[0-9]*}}e+01" color="#7F0000"]; -#EDGE-DAG: F0 -> F4 [label="4.{{[0-9]*}}e+01" color="#E8543b"]; -#EDGE-DAG: F0 -> F6 [label="6.{{[0-9]*}}e+01" color="#C5140a"]; -#EDGE-DAG: F0 -> F1 [label="1.{{[0-9]*}}e+01" color="#FDC58c"]; -#EDGE-DAG: F0 -> F8 [label="8.{{[0-9]*}}e+01" color="#990101"]; -#EDGE-DAG: F0 -> F3 [label="3.{{[0-9]*}}e+01" color="#F5744d"]; -#EDGE-DAG: F0 -> F5 [label="5.{{[0-9]*}}e+01" color="#D83323"]; +#EDGE-DAG: F0 -> F7 [label="7.{{[0-9]*}}e+01" color="#B80400"]; +#EDGE-DAG: F0 -> F2 [label="2.{{[0-9]*}}e+01" color="#FD9861"]; +#EDGE-DAG: F0 -> F9 [label="9.{{[0-9]*}}e+01" color="#A71800"]; +#EDGE-DAG: F0 -> F4 [label="4.{{[0-9]*}}e+01" color="#E9553C"]; +#EDGE-DAG: F0 -> F6 [label="6.{{[0-9]*}}e+01" color="#C81507"]; +#EDGE-DAG: F0 -> F1 [label="1.{{[0-9]*}}e+01" color="#FDC68E"]; +#EDGE-DAG: F0 -> F8 [label="8.{{[0-9]*}}e+01" color="#AB0B00"]; +#EDGE-DAG: F0 -> F3 [label="3.{{[0-9]*}}e+01" color="#F5744F"]; +#EDGE-DAG: F0 -> F5 [label="5.{{[0-9]*}}e+01" color="#D9331F"]; #EDGE-DAG: F7 [label="@(7)"]; #EDGE-DAG: F2 [label="@(2)"]; #EDGE-DAG: F9 [label="@(9)"]; @@ -63,13 +63,13 @@ #VERTEX-DAG: F0 -> F8 [label=""]; #VERTEX-DAG: F0 -> F3 [label=""]; #VERTEX-DAG: F0 -> F5 [label=""]; -#VERTEX-DAG: F7 [label="{@(7)|7.{{[0-9]*}}e+01}" color="#B00100"]; -#VERTEX-DAG: F2 [label="{@(2)|2.{{[0-9]*}}e+01}" color="#FD9965"]; -#VERTEX-DAG: F9 [label="{@(9)|9.{{[0-9]*}}e+01}" color="#7F0000"]; -#VERTEX-DAG: F4 [label="{@(4)|4.{{[0-9]*}}e+01}" color="#E8543b"]; -#VERTEX-DAG: F6 [label="{@(6)|6.{{[0-9]*}}e+01}" color="#C5140a"]; -#VERTEX-DAG: F1 [label="{@(1)|1.{{[0-9]*}}e+01}" color="#FDC58c"]; -#VERTEX-DAG: F8 [label="{@(8)|8.{{[0-9]*}}e+01}" color="#990101"]; -#VERTEX-DAG: F3 [label="{@(3)|3.{{[0-9]*}}e+01}" color="#F5744d"]; -#VERTEX-DAG: F5 [label="{@(5)|5.{{[0-9]*}}e+01}" color="#D83323"]; +#VERTEX-DAG: F7 [label="{@(7)|7.{{[0-9]*}}e+01}" color="#B80400"]; +#VERTEX-DAG: F2 [label="{@(2)|2.{{[0-9]*}}e+01}" color="#FD9861"]; +#VERTEX-DAG: F9 [label="{@(9)|9.{{[0-9]*}}e+01}" color="#A71800"]; +#VERTEX-DAG: F4 [label="{@(4)|4.{{[0-9]*}}e+01}" color="#E9553C"]; +#VERTEX-DAG: F6 [label="{@(6)|6.{{[0-9]*}}e+01}" color="#C81507"]; +#VERTEX-DAG: F1 [label="{@(1)|1.{{[0-9]*}}e+01}" color="#FDC68E"]; +#VERTEX-DAG: F8 [label="{@(8)|8.{{[0-9]*}}e+01}" color="#AB0B00"]; +#VERTEX-DAG: F3 [label="{@(3)|3.{{[0-9]*}}e+01}" color="#F5744F"]; +#VERTEX-DAG: F5 [label="{@(5)|5.{{[0-9]*}}e+01}" color="#D9331F"]; #VERTEX-NEXT: } Index: tools/llvm-xray/CMakeLists.txt =================================================================== --- tools/llvm-xray/CMakeLists.txt +++ tools/llvm-xray/CMakeLists.txt @@ -9,6 +9,7 @@ set(LLVM_XRAY_TOOLS func-id-helper.cc xray-account.cc + xray-color-helper.cc xray-converter.cc xray-extract.cc xray-extract.cc Index: tools/llvm-xray/xray-color-helper-gen.wls =================================================================== --- /dev/null +++ tools/llvm-xray/xray-color-helper-gen.wls @@ -0,0 +1,211 @@ +#!/usr/local/bin/wolframscript +(* This file generates the arrays in graph-color-helper.cc and the enum types + in graph-color-helper.h, run the output through clang-format before copying + the definitions output into the c files. + + The tables below are from the ColorBrewer color schemes from + http://www.colorbrewer.org/ by Cynthia A. Brewer of + Pennsylvania State University and are used under the following license + + Apache-Style Software License for ColorBrewer software and ColorBrewer + Color Schemes + + Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State + University. + + Licensed under the Apache License, Version 2.0 (the "License"); you may not + use this file except in compliance with the License. You may obtain a copy of + the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License. + + The derived work embeded is otherwise under the University of Illinois + Open Source License. See LICENSE.TXT for details.*) +Print["static const double SequentialCoeffs[][3][21] ="]; +ColorSets = { + {"Blues", {8, 7, + 8}, {{247, 222, 198, 158, 107, 66, 33, 8, 8}, {251, 235, 219, + 202, 174, 146, 113, 81, 48}, {255, 247, 239, 225, 214, 198, 181, + 156, 107}}}, {"Greens", {14, 6, + 8}, {{247, 229, 199, 161, 116, 65, 35, 0, 0}, {252, 245, 233, + 217, 196, 171, 139, 109, 68}, {245, 224, 192, 155, 118, 93, 69, + 44, 27}}}, + {"Greys", {8, 8, + 8}, {{255, 240, 217, 189, 150, 115, 82, 37, 0}, {255, 240, 217, + 189, 150, 115, 82, 37, 0}, {255, 240, 217, 189, 150, 115, 82, + 37, 0}}}, + {"Oranges", {9, 7, + 1 0}, {{255, 254, 253, 253, 253, 241, 217, 166, 127}, {245, 230, + 208, 174, 141, 105, 72, 54, 39}, {235, 206, 162, 107, 60, 19, 1, + 3, 4}}}, + {"Purples", {5, 10, + 9}, {{252, 239, 218, 188, 158, 128, 106, 84, 63}, {251, 237, 218, + 189, 154, 125, 81, 39, 0}, {253, 245, 235, 220, 200, 186, 163, + 143, 125}}}, + {"Reds", {10, 8, + 7}, {{255, 254, 252, 252, 251, 239, 203, 165, 103}, {245, 224, + 187, 146, 106, 59, 24, 15, 0}, {240, 210, 161, 114, 74, 44, 29, + 21, 13}}}, + + {"BuGn", {11, 9, + 8}, {{247, 229, 204, 153, 102, 65, 35, 0, 0}, {252, 245, 236, + 216, 194, 174, 139, 109, 68}, {253, 249, 230, 201, 164, 118, 69, + 44, 27}}}, + {"BuPu", {9, 15, + 7}, {{247, 224, 191, 158, 140, 140, 136, 129, 77}, {252, 236, + 211, 188, 150, 107, 65, 15, 0}, {253, 244, 230, 218, 198, 177, + 157, 124, 75}}}, + {"GnBu", {13, 8, + 1 1}, {{247, 224, 204, 168, 123, 78, 43, 8, 8}, {252, 243, 235, + 221, 204, 179, 140, 104, 64}, {240, 219, 197, 181, 196, 211, + 190, 172, 129}}}, + {"OrRd", {7, 10, + 1 3}, {{255, 254, 253, 253, 252, 239, 215, 179, 127}, {247, 232, + 212, 187, 141, 101, 48, 0, 0}, {236, 200, 158, 132, 89, 72, 31, + 0, 0}}}, + {"PuBu", {12, 9, + 8}, {{255, 236, 208, 166, 116, 54, 5, 4, 2}, {247, 231, 209, 189, + 169, 144, 112, 90, 56}, {251, 242, 230, 219, 207, 192, 176, + 141, 88}}}, + {"PuBuGn", {15, 9, + 1 2}, {{255, 236, 208, 166, 103, 54, 2, 1, 1}, {247, 226, 209, + 189, 169, 144, 129, 108, 70}, {251, 240, 230, 219, 207, 192, + 138, 89, 54}}}, + {"PuRd", {10, 13, + 1 1}, {{247, 231, 212, 201, 223, 231, 206, 152, 103}, {244, 225, + 185, 148, 101, 41, 18, 0, 0}, {249, 239, 218, 199, 176, 138, 86, + 67, 31}}}, + {"RdPu", {8, 1 5, + 1 2}, {{255, 253, 252, 250, 247, 221, 174, 122, 73}, {247, 224, + 197, 159, 104, 52, 1, 1, 0}, {243, 221, 192, 181, 161, 151, 126, + 119, 106}}}, + {"YlGn", {15, 9, + 9}, {{255, 247, 217, 173, 120, 65, 35, 0, 0}, {255, 252, 240, + 221, 198, 171, 132, 104, 69}, {229, 185, 163, 142, 121, 93, 67, + 55, 41}}}, + {"YlGnBu", {11, 9, + 9}, {{255, 237, 199, 127, 65, 29, 34, 37, 8}, {255, 248, 233, + 205, 182, 145, 94, 52, 29}, {217, 177, 180, 187, 196, 192, 168, + 148, 88}}}, + {"YlOrBr", {8, 6, + 1 1}, {{255, 255, 254, 254, 254, 236, 204, 153, 102}, {255, 247, + 227, 196, 153, 112, 76, 52, 37}, {229, 188, 145, 79, 41, 20, 2, + 4, 6}}}, + {"YlOrRd", {9, 12, + 1 0}, {{255, 255, 254, 254, 253, 252, 227, 189, 128}, {255, 237, + 217, 178, 141, 78, 26, 0, 0}, {204, 160, 118, 76, 60, 42, 28, + 38, 38}}} + }; +ConvertCol[CS_, { nri_, ngi_, nbi_}, min_, max_] := +(* The Algorithm here works by interpolating using a cubic-spline in LAB space + whilst this works well here, it may not be what you want. Annother way to + generate the sampled interpolation is to do a search using CIEDE2000 + bisection to generate a table, this may result in a more linear output in + some situations*) + Module[{Cols, LabCols, SplineInterpolate, data, sp, + InterpolatedCols, RIORC, GIORC, BIORC, data2, fit4, fit5, p, + Coeff, temp}, Cols := RGBColor @@@ (CS/255); + LabCols := ColorConvert[Cols, "LAB"]; + SplineInterpolate[l_] := Interpolation[l, Method -> "Spline"]; + data := Transpose[{ConstantArray[ + Range[min, max, (max - min)/(Length[Cols] - 1)], 3], + Transpose[List @@@ LabCols]}, {3, 1, 2}]; + sp = SplineInterpolate /@ data; + InterpolatedCols[x_] := + ColorConvert[LABColor[sp[[1]][x], sp[[2]][x], sp[[3]][x]], + "RGB"]; + RIORC[x_] := InterpolatedCols[x][[1]]; + GIORC[x_] := InterpolatedCols[x][[2]]; + BIORC[x_] := InterpolatedCols[x][[3]]; + data2[f_, x_] := + Transpose[{Table[x, {x, min, max, 0.001}], + Table[f[x], {x, min, max, 0.001}]}]; + fit4[x_, nr_, ng_, nb_] := {Fit[data2[RIORC, x], x^Range[0, nr], x], + Fit[data2[GIORC, x], x^Range[0, ng], x], + Fit[data2[BIORC, x], x^Range[0, nb], x]}; + fit5[y_] := Evaluate[fit4[x, nri, ngi, nbi] /. x -> y]; + p := Plot[{fit5[x][[1]] - RIORC[x], fit5[x][[2]] - GIORC[x], + fit5[x][[3]] - BIORC[x], 0.005, -0.005}, {x, min, max}, + PlotStyle -> {Red, Green, Blue}, PlotRange -> {-0.01, 0.01}]; + Coeff := + SetPrecision[{Reverse[CoefficientList[fit5[x][[1]], x]], + Reverse[CoefficientList[fit5[x][[2]], x]], + Reverse[CoefficientList[fit5[x][[3]], x]]}, 10]; + temp := {Cols, + BarLegend[{RGBColor[fit5[#]] &}, {min, max}, + LegendLayout -> "Row"]}; + {Cols, + BarLegend[{RGBColor[fit5[#]] &, {min, max}}, + LegendLayout -> "Row"], p, Coeff}]; +ConvertNo[i_] := {ColorSets[[i]][[1]], {20, 20, 20}, + ConvertCol[Transpose[ColorSets[[i]][[3]]], {20, 20, 20}, 0, + 1]}; +Print[ + StringReplace[ + ToString[CForm[ + Transpose[ + Transpose[ + Map[ConvertNo, + Range[1, Length[ColorSets]]]][[3]]][[4]]]], {"List(" -> "{", + ")" -> "}"}]]; +Print[";"]; + +Print["enum class SequentialScheme"]; +Print[ToString[ + Transpose[Map[ConvertNo, Range[1, Length[ColorSets]]]][[1]]]]; +Print[";"]; + +Print["// Differential Coefficients"]; +Print["static const double DifferentialCoeffs[][3][21] ="]; +ColorSets = {{"BrBG", {11, 10, + 15}, {{84, 140, 191, 223, 246, 245, 199, 128, 53, 1, 0}, {48, 81, + 129, 194, 232, 245, 234, 205, 151, 102, 60}, {5, 10, 45, 125, + 195, 245, 229, 193, 143, 94, 48}}}, {"PiYG", {10, 20, + 12}, {{142, 197, 222, 241, 253, 247, 230, 184, 127, 77, 39}, {1, + 27, 119, 182, 224, 247, 245, 225, 188, 146, 100}, {82, 125, 174, + 218, 239, 247, 208, 134, 65, 33, 25}}}, {"PRGn", {13, 15, + 15}, {{64, 118, 153, 194, 231, 247, 217, 166, 90, 27, 0}, {0, 42, + 112, 165, 212, 247, 240, 219, 174, 120, 68}, {75, 131, 171, + 207, 232, 247, 211, 160, 97, 55, 27}}}, {"PuOr", {13, 16, + 15}, {{127, 179, 224, 253, 254, 247, 216, 178, 128, 84, 45}, {59, + 88, 130, 184, 224, 247, 218, 171, 115, 39, 0}, {8, 6, 20, 99, + 182, 247, 235, 210, 172, 136, 75}}}, {"RdBu", {12, 20, + 13}, {{103, 178, 214, 244, 253, 247, 209, 146, 67, 33, 5}, {0, + 24, 96, 165, 219, 247, 229, 197, 147, 102, 48}, {31, 43, 77, + 130, 199, 247, 240, 222, 195, 172, 97}}}, + + {"RdGy", {14, 20, + 16}, {{103, 178, 214, 244, 253, 255, 224, 186, 135, 77, 26}, {0, + 24, 96, 165, 219, 255, 224, 186, 135, 77, 26}, {31, 43, 77, 130, + 199, 255, 224, 186, 135, 77, 26}}}, {"RdYlBu", {12, 14, + 16}, {{165, 215, 244, 253, 254, 255, 224, 171, 116, 69, 49}, {0, + 48, 109, 174, 224, 255, 243, 217, 173, 117, 54}, {38, 39, 67, + 97, 144, 191, 248, 233, 209, 180, 149}}}, {"RdYlGn", {17, 13, + 17}, {{165, 215, 244, 253, 254, 255, 217, 166, 102, 26, 0}, {0, + 48, 109, 174, 224, 255, 239, 217, 189, 152, 104}, {38, 39, 67, + 97, 139, 191, 139, 106, 99, 80, 55}}}, {"Spectral", {11, 12, + 18}, {{158, 213, 244, 253, 254, 255, 230, 171, 102, 50, 94}, {1, + 62, 109, 174, 224, 255, 245, 221, 194, 136, 79}, {66, 79, 67, + 97, 139, 191, 152, 164, 165, 189, 162}}}}; +ConvertNo[i_] := {ColorSets[[i]][[1]], ColorSets[[i]][[2]], + ConvertCol[Transpose[ColorSets[[i]][[3]]], {20, 20, 20}, -1, 1]}; +Print[ + StringReplace[ + ToString[CForm[ + Transpose[ + Transpose[ + Map[ConvertNo, + Range[1, Length[ColorSets]]]][[3]]][[4]]]], {"List(" -> "{", + ")" -> "}"}]]; +Print[";"]; + +Print["enum class DifferentialScheme"]; +Print[ToString[ + Transpose[Map[ConvertNo, Range[1, Length[ColorSets]]]][[1]]]]; +Print[";"]; Index: tools/llvm-xray/xray-color-helper.h =================================================================== --- /dev/null +++ tools/llvm-xray/xray-color-helper.h @@ -0,0 +1,107 @@ +//===-- xray-graph.h - XRay Function Call Graph Renderer --------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// A class to get a color from a specified gradient. +// +//===----------------------------------------------------------------------===// + +#ifndef XRAY_COLOR_HELPER_H +#define XRAY_COLOR_HELPER_H + +#include + +#include "llvm/ADT/ArrayRef.h" + +namespace llvm { +namespace xray { + +/// The color helper class it a healper class which allows you to easily get a +/// color in a gradient. This is used to color-code edges in XRay-Graph tools. +/// +/// There are two types of color schemes in this class: +/// - Sequential schemes, which are used to represent information from some +/// minimum to some maximum. These take an input in the range [0,1] +/// - Diverging schemes, 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]. +/// Usage; +/// ColorHelper S(ColorHelper::SequentialScheme::OrRd); //Chose a color scheme. +/// for (double p = 0.0; p <= 1; p += 0.1){ +/// cout() << S.getColor(p) << " \n"; // Sample the gradient at 0.1 intervals +/// } +/// +/// ColorHelper D(ColorHelper::DivergingScheme::Spectral); // Choose a color +/// // scheme. +/// for (double p= -1; p <= 1 ; p += 0.1){ +/// cout() << D.getColor(p) << " \n"; // sample the gradient at 0.1 intervals +/// } +class ColorHelper { +private: + double MinIn; + double MaxIn; + + ArrayRef RedPoly; + ArrayRef GreenPoly; + ArrayRef BluePoly; + +public: + /// Enum of the availible Sequential Color Schemes + enum class SequentialScheme { + // Schemes based on the ColorBrewer Color schemes of the same name from + // http://www.colorbrewer.org/ by Cynthis A Brewer Penn State University. + Blues, + Greens, + Greys, + Oranges, + Purples, + Reds, + BuGn, + BuPu, + GnBu, + OrRd, + PuBu, + PuBuGn, + PuRd, + RdPu, + YlGn, + YlGnBu, + YlOrBr, + YlOrRd + }; + + ColorHelper(SequentialScheme S); + + /// Enum of the availible Diverging Color Schemes + enum class DivergingScheme { + // Schemes based on the ColorBrewer Color schemes of the same name from + // http://www.colorbrewer.org/ by Cynthis A Brewer Penn State University. + BrBG, + PiYG, + PRGn, + PuOr, + RdBu, + RdGy, + RdYlBu, + RdYlGn, + Spectral + }; + + ColorHelper(DivergingScheme S); + + // Sample the gradient at the input point. + std::tuple getColorTuple(double Point) const; + + std::string getColorString(double Point) const; + + // Convert a tuple to a string + static std::string getColorString(std::tuple t); +}; +} +} +#endif Index: tools/llvm-xray/xray-color-helper.cc =================================================================== --- /dev/null +++ tools/llvm-xray/xray-color-helper.cc @@ -0,0 +1,684 @@ +//===-- xray-graph.cc - XRay Function Call Graph Renderer -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// A class to get a color from a specified gradient. +// +//===----------------------------------------------------------------------===// +#include + +#include "xray-color-helper.h" +#include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; +using namespace xray; + +// Static Polynomials for the ColorHelper. +// +// In order to calculate these polynomials, +// 1. Convert the color scheme samples from sRGB to LAB color space. +// 2. Interpolate between the descrete colors in LAB space using a cubic +// spline interpolation. +// 3. Sample this interpolation at 100 points and convert to sRGB. +// 4. Calculate a polynomial fit for these 100 points for each of R G and B. +// We used a polynomial of varying based on the lowest degree polynomial +// having an error less than 1 part in 200. +// 5. Extract these polynomial coefficients from matlab as a set of constants. +// +// Polynomials for Sequential schemes, which are used to represent information +// from some minimum to some maximum. These take an input in the range [0,1] + +static const double SequentialCoeffs[][3][21] = { + {// polynomials based on the blues color scheme from + // http://colorbrewer2.org/ + {// red polynomial coefficients + -6.878460665e6, 5.961432639e7, -2.307067298e8, 5.170718862e8, + -7.138743566e8, 5.503115096e8, -3.409350245e7, -4.849896433e8, + 6.794988641e8, -5.465668628e8, 3.031777048e8, -1.218030809e8, + 3.587557215e7, -7.703409716e6, 1.183859548e6, -126184.8818, + 8887.335496, -390.6627665, 11.74112013, -1.11154342, + 0.9688321898}, + {// green polynomial coefficients + -2.54152823e6, 2.257620781e7, -8.894369426e7, 2.012050497e8, + -2.770684225e8, 2.080728321e8, -2.958460016e6, -1.920419046e8, + 2.519433145e8, -1.898368254e8, 9.73431972e7, -3.555404588e7, + 9.354256083e6, -1.764742155e6, 235011.8538, -21491.83607, + 1290.806243, -45.94629786, 0.4316964353, -0.46857367, + 0.9843293031}, + {// blue polynomial coefficients + 1.560517092e6, -1.423671932e7, 5.726787567e7, -1.314842876e8, + 1.82553982e8, -1.368880076e8, 159616.1176, 1.279999586e8, + -1.641210606e8, 1.201496379e8, -5.916511774e7, 2.041722108e7, + -4.963864504e6, 839604.315, -96179.75043, 7138.156113, + -318.7211607, 3.33961507, 1.458423792, -0.3771610563, + 0.9999999067}}, + {// polynomials based on the greens color scheme from + // http://colorbrewer2.org/ + {// red polynomial coefficients + -3.62525046e7, 2.924236792e8, -1.042671855e9, 2.123415039e9, + -2.599204929e9, 1.642006242e9, 2.702067439e8, -1.738507562e9, + 1.974660805e9, -1.359160152e9, 6.508106396e8, -2.256406209e8, + 5.71635436e7, -1.050509728e7, 1.372112383e6, -123004.0468, + 7164.041044, -246.8718053, 2.327555732, -0.35769083, + 0.9686621343}, + {// green polynomial coefficients + 1.70070164e6, -1.448980139e7, 5.455815372e7, -1.175030886e8, + 1.531363911e8, -1.065881801e8, -6.092754155e6, 1.037335106e8, + -1.287462997e8, 9.495846376e7, -4.878175979e7, 1.828531084e7, + -5.065547031e6, 1.032204704e6, -151922.8637, 15645.79306, + -1073.451276, 46.1118335, -1.913352463, -0.1111091252, + 0.9882111289}, + {// blue polynomial coefficients + -1.371140351e6, 1.40161522e7, -6.255670424e7, 1.589602688e8, + -2.464045502e8, 2.163157526e8, -3.791252841e7, -1.7191798e8, + 2.683392816e8, -2.269855371e8, 1.297004016e8, -5.301371774e7, + 1.575774294e7, -3.399342763e6, 524255.508, -56178.27079, + 3994.278313, -172.5722494, 1.870513973, -0.4519871193, + 0.9608843031}}, + {// polynomials based on the greys color scheme from + // http://colorbrewer2.org/ + {// red polynomial coefficients + -2.233771148e7, 1.902249034e8, -7.188772724e8, 1.561146118e9, + -2.063716843e9, 1.476170824e9, 3.756706085e7, -1.402655868e9, + 1.793619474e9, -1.349091033e9, 7.028492629e8, -2.656795043e8, + 7.380059917e7, -1.500799713e7, 2.198525287e6, -225318.1378, + 15418.40201, -651.6129557, 13.25225819, -0.4195849806, + 1.000352876}, + {// green polynomial coefficients + -2.233789316e7, 1.902264928e8, -7.188834781e8, 1.561160153e9, + -2.063736432e9, 1.476186208e9, 3.756573148e7, -1.402669078e9, + 1.793638556e9, -1.349106822e9, 7.02858336e8, -2.656833241e8, + 7.380179659e7, -1.500827632e7, 2.198573078e6, -225323.9965, + 15418.89653, -651.6400018, 13.25312826, -0.4195985451, + 1.0003522}, + {// blue polynomial coefficients + -2.233789787e7, 1.902265285e8, -7.188835966e8, 1.561160375e9, + -2.063736677e9, 1.476186335e9, 3.756578175e7, -1.402669236e9, + 1.79363871e9, -1.349106916e9, 7.028583767e8, -2.65683337e8, + 7.380179963e7, -1.500827685e7, 2.198573146e6, -225324.0024, + 15418.89688, -651.6400148, 13.25312917, -0.4195984386, + 1.000351807}}, + {// polynomials based on the oranges color scheme from + // http://colorbrewer2.org/ + {// red polynomial coefficients + 1.15811692e6, -1.013084515e7, 3.994611655e7, -9.20062579e7, + 1.316203388e8, -1.066805202e8, 1.148636145e7, 9.079334506e7, + -1.324658915e8, 1.0780688e8, -5.937456836e7, 2.323478131e7, + -6.528789929e6, 1.307491538e6, -182776.547, 17216.17261, + -1035.593699, 38.06135679, -1.110242687, 0.006878012505, + 0.9999949379}, + {// green polynomial coefficients + 1.549672343e6, -1.453367759e7, 5.971463986e7, -1.393097642e8, + 1.957275748e8, -1.481901131e8, 977419.4527, 1.379237496e8, + -1.770560307e8, 1.292856027e8, -6.335108759e7, 2.170999868e7, + -5.231196681e6, 875361.9727, -99117.58207, 7290.742067, + -327.9214672, 4.555734391, 0.4119729909, -0.4765369457, + 0.96078222}, + {// blue polynomial coefficients + 2.20840773e7, -1.80350851e8, 6.499406274e8, -1.334887592e9, + 1.643167724e9, -1.038534909e9, -1.781212705e8, 1.105785647e9, + -1.240440988e9, 8.379667773e8, -3.900531451e8, 1.297572071e8, + -3.098782318e7, 5.237769437e6, -606728.9582, 45392.76886, + -1947.345448, 32.65749466, -1.220531486, -0.7144206116, + 0.9216283769}}, + {// polynomials based on the purples color scheme from + // http://colorbrewer2.org/ + {// red polynomial coefficients + -3.433976326e6, 2.865272513e7, -1.058746879e8, 2.243130002e8, + -2.883595727e8, 1.984346539e8, 1.214218566e7, -1.93555985e8, + 2.412315003e8, -1.799932055e8, 9.415635455e7, -3.614014131e7, + 1.029103622e7, -2.15820078e6, 326419.5691, -34405.96444, + 2401.89892, -104.3393161, 1.944583232, -0.3532081596, + 0.9882882183}, + {// green polynomial coefficients + -2.245422607e6, 2.252728466e7, -9.976263328e7, 2.53658941e8, + -3.964050192e8, 3.545947122e8, -7.090269518e7, -2.746620253e8, + 4.437096725e8, -3.84409029e8, 2.246711968e8, -9.391473131e7, + 2.854026858e7, -6.289342209e6, 989245.0502, -107867.5088, + 7783.143182, -347.3032915, 8.467253113, -0.511181449, + 0.9845167981}, + {// blue polynomial coefficients + 628950.3659, -2.909833289e6, 643067.8932, 2.43180905e7, + -7.363251057e7, 9.958827993e7, -4.897058692e7, -5.484597841e7, + 1.283179385e8, -1.26970807e8, 8.003475814e7, -3.505869346e7, + 1.096250472e7, -2.454417398e6, 388734.8552, -42415.25785, + 3049.093896, -135.0666194, 3.237269316, -0.2758838656, + 0.9922326548}}, + {// polynomials based on the reds color scheme from http://colorbrewer2.org/ + {// red polynomial coefficients + 8.385219503e6, -7.192588762e7, 2.733544744e8, -5.960041522e8, + 7.896486522e8, -5.648941738e8, -1.550972284e7, 5.375738206e8, + -6.849566804e8, 5.131253926e8, -2.659726317e8, 9.98471277e7, + -2.745230212e7, 5.491973654e6, -783224.4276, 76825.90914, + -4893.107946, 184.7763055, -3.909907357, 0.03808163708, + 0.9999101619}, + {// green polynomial coefficients + -5.322904495e6, 4.357747828e7, -1.575306942e8, 3.249262039e8, + -4.026975924e8, 2.586147457e8, 3.823322039e7, -2.70129857e8, + 3.103580964e8, -2.156547091e8, 1.045421355e8, -3.693874376e7, + 9.643251742e6, -1.856335173e6, 259750.5072, -25693.09347, + 1714.959354, -66.78383653, -2.142654814, -0.2770523242, + 0.9608221135}, + {// blue polynomial coefficients + 244959.5242, -2.856785311e6, 1.432490568e7, -4.060067586e7, + 7.032613152e7, -7.089683976e7, 2.241670171e7, 4.829252823e7, + -9.092816593e7, 8.539368992e7, -5.316781236e7, 2.34528147e7, + -7.459478353e6, 1.704904642e6, -275211.5706, 30434.40534, + -2198.948821, 105.1241083, -7.903704865, -0.3502352058, + 0.9411237819}}, + {// polynomials based on the bugn color scheme from http://colorbrewer2.org/ + {// red polynomial coefficients + -1.610837435e7, 1.259535365e8, -4.353476269e8, 8.598768739e8, + -1.021263706e9, 6.226418772e8, 1.190383884e8, -6.715236591e8, + 7.577593349e8, -5.274456551e8, 2.593280442e8, -9.366212644e7, + 2.502063864e7, -4.885907581e6, 678925.7957, -64315.87626, + 3891.837144, -145.3025128, 5.090021548, -0.7788246313, + 0.9686281578}, + {// green polynomial coefficients + 5.563958709e6, -4.506618425e7, 1.598296967e8, -3.192828475e8, + 3.740459662e8, -2.092763403e8, -7.282124203e7, 2.517228516e8, + -2.417273525e8, 1.361655189e8, -4.810693374e7, 9.476074689e6, + -182167.3649, -459831.5366, 138008.5076, -20933.69118, + 1851.799995, -98.44120337, 3.898935932, -0.3545216994, + 0.988301982}, + {// blue polynomial coefficients + 4.963749539e6, -4.337442087e7, 1.680194454e8, -3.738342934e8, + 5.069382503e8, -3.755618592e8, 3.926591786e6, 3.461995241e8, + -4.572758404e8, 3.514691268e8, -1.866480401e8, 7.186002707e7, + -2.0320576e7, 4.20277597e6, -625017.3384, 64845.77092, + -4476.171047, 192.6896157, -7.012761207, 0.2117428151, + 0.9920548709}}, + {// polynomials based on the bupu color scheme from http://colorbrewer2.org/ + {// red polynomial coefficients + 1.848673863e6, -1.438237416e7, 4.808618721e7, -8.760041053e7, + 8.65448955e7, -2.630381593e7, -4.188229855e7, 5.722867623e7, + -2.428577719e7, -9.51723673e6, 1.885035041e7, -1.244819579e7, + 4.973843237e6, -1.325918443e6, 240504.1624, -29307.09292, + 2309.623754, -106.2301435, 0.2181578508, -0.4862205374, + 0.9687022921}, + {// green polynomial coefficients + -9.492200219e7, 8.079891387e8, -3.052047933e9, 6.62634927e9, + -8.762965607e9, 6.282479538e9, 1.326433408e8, -5.944807408e9, + 7.645820331e9, -5.78817344e9, 3.040998715e9, -1.162001647e9, + 3.271274814e8, -6.758761389e7, 1.00810734e7, -1.053753787e6, + 73628.8595, -3184.178153, 71.88636211, -0.9101594277, + 0.9900733426}, + {// blue polynomial coefficients + -5.727589563e6, 4.840403222e7, -1.80774436e8, 3.856607326e8, + -4.957346072e8, 3.348376831e8, 3.376895629e7, -3.385118492e8, + 4.003544091e8, -2.802022594e8, 1.342507712e8, -4.579918412e7, + 1.120305133e7, -1.946728078e6, 235101.7407, -19034.54914, + 976.2277309, -24.57891842, -1.830285184, -0.07100435952, + 0.9921564302}}, + {// polynomials based on the gnbu color scheme from http://colorbrewer2.org/ + {// red polynomial coefficients + -7.085467669e7, 6.01893687e8, -2.271995728e9, 4.93728611e9, + -6.549512165e9, 4.732600184e9, 4.852014502e7, -4.437323291e9, + 5.777027756e9, -4.419495478e9, 2.347416685e9, -9.073196231e8, + 2.584034383e8, -5.397599541e7, 8.12697486e6, -855492.8345, + 60016.45351, -2611.995281, 65.28469137, -1.670498557, + 0.9701016026}, + {// green polynomial coefficients + 5.702178762e6, -4.821349106e7, 1.801646381e8, -3.847375705e8, + 4.95628347e8, -3.369252102e8, -3.036089134e7, 3.374011067e8, + -4.04128074e8, 2.872230197e8, -1.406966397e8, 4.957145335e7, + -1.269928358e7, 2.354597949e6, -310963.301, 28444.25727, + -1723.744612, 61.22611245, 0.03069390984, -0.3887530794, + 0.9882114022}, + {// blue polynomial coefficients + 2.341754365e7, -1.985901298e8, 7.450147977e8, -1.599289652e9, + 2.075468946e9, -1.430281667e9, -1.051488615e8, 1.413951542e9, + -1.72031705e9, 1.238567071e9, -6.147912299e8, 2.196866638e8, + -5.712720177e7, 1.075454478e7, -1.440812838e6, 133329.2981, + -8129.641406, 302.4171449, -5.977466386, -0.6107867231, + 0.9410760344}}, + {// polynomials based on the orrd color scheme from http://colorbrewer2.org/ + {// red polynomial coefficients + 3.308750476e6, -2.815278217e7, 1.05743225e8, -2.265214885e8, + 2.91645703e8, -1.961885023e8, -2.191242415e7, 2.002089655e8, + -2.332412986e8, 1.600263964e8, -7.442998837e7, 2.426431408e7, + -5.522554786e6, 849227.2743, -81352.97684, 3769.104205, + 58.34188297, -19.18743939, 1.627529493, -0.1091596013, + 1.000028864}, + {// green polynomial coefficients + -7.187999589e6, 4.814645311e7, -1.329771869e8, 1.802170111e8, + -7.978760979e7, -1.091114566e8, 1.750501528e8, -3.747808679e7, + -1.49663875e8, 2.19168179e8, -1.668657234e8, 8.368439726e7, + -2.936997675e7, 7.315393873e6, -1.28227859e6, 154204.4602, + -12171.57216, 589.6223242, -16.98380486, -0.1334890311, + 0.9681926267}, + {// blue polynomial coefficients + 1.636920783e7, -1.337382568e8, 4.821999652e8, -9.927367497e8, + 1.232376612e9, -8.035682178e8, -9.284128343e7, 8.153848013e8, + -9.760496785e8, 7.152402174e8, -3.732132545e8, 1.450650256e8, + -4.240831561e7, 9.228252503e6, -1.458212359e6, 161181.0867, + -11823.36466, 548.0816668, -19.47280868, -0.4252852112, + 0.9251654633}}, + {// polynomials based on the pubu color scheme from http://colorbrewer2.org/ + {// red polynomial coefficients + -6.15311718e7, 5.130457343e8, -1.895015309e9, 4.012623585e9, + -5.148793498e9, 3.518183671e9, 2.619314338e8, -3.475642029e9, + 4.258611487e9, -3.112435836e9, 1.582802144e9, -5.855869319e8, + 1.594882673e8, -3.182431612e7, 4.571999725e6, -458604.5962, + 30608.57342, -1263.237763, 28.14833557, -0.8122457793, + 1.000598008}, + {// green polynomial coefficients + 5.015065362e6, -4.390242927e7, 1.704822597e8, -3.805802767e8, + 5.185671644e8, -3.875642082e8, 8.24545075e6, 3.538991808e8, + -4.730005932e8, 3.669924019e8, -1.967410797e8, 7.648224967e7, + -2.183467203e7, 4.555295369e6, -682198.5328, 71097.63347, + -4914.235605, 212.7334295, -6.966892761, -0.245104215, + 0.9685187022}, + {// blue polynomial coefficients + -3.287988502e6, 2.727455978e7, -9.970300564e7, 2.074104733e8, + -2.58269376e8, 1.653343626e8, 2.665390234e7, -1.746035224e8, + 1.966715766e8, -1.32928229e8, 6.185876331e7, -2.061102583e7, + 4.959658955e6, -855989.093, 104015.8099, -8628.294586, + 465.7447728, -13.33621902, -0.7991210319, -0.180187943, + 0.9843158555}}, + { // polynomials based on the pubugn color scheme from + // http://colorbrewer2.org/ + {// red polynomial coefficients + -1.253586354e8, 1.027765485e9, -3.729086638e9, 7.743691303e9, + -9.708379296e9, 6.389118325e9, 7.469487965e8, -6.525994753e9, + 7.709571289e9, -5.477073903e9, 2.70753817e9, -9.7147873e8, + 2.556629549e8, -4.906051999e7, 6.739230986e6, -641899.3964, + 40336.16294, -1547.260234, 30.84696844, -0.7447147149, + 1.00052349}, + {// green polynomial coefficients + -2.636947337e6, 2.065088315e7, -7.068129727e7, 1.36020306e8, + -1.53169332e8, 8.152739004e7, 3.089097818e7, -9.927499869e7, + 9.659662742e7, -5.886727304e7, 2.549434188e7, -8.261060047e6, + 2.048359729e6, -386963.4428, 53900.12311, -5227.15293, + 325.9384465, -15.51527991, 2.138283646, -0.8422522218, + 0.9686265047}, + {// Blue polynomial coefficients + 1.16563668e7, -9.53559683e7, 3.433119015e8, -7.019742068e8, + 8.556278009e8, -5.278727006e8, -1.077648951e8, 5.747917052e8, + -6.263189534e8, 4.122237931e8, -1.867896892e8, 6.04265049e7, + -1.402185885e7, 2.30016709e6, -257700.4161, 18455.42223, + -732.0166848, 8.810490008, 0.5625799601, -0.382085938, + 0.9843409742}}, + {// Polynomials based on the PuRd color scheme from http://colorbrewer2.org/ + {// Red polynomial coefficients + 1.643622642e7, -1.390988914e8, 5.208647209e8, -1.115812501e9, + 1.443438053e9, -9.87001514e8, -8.476715248e7, 9.867012737e8, + -1.183281957e9, 8.374644423e8, -4.056315814e8, 1.398664568e8, + -3.454627289e7, 6.042174226e6, -728605.1433, 57857.48559, + -2800.197002, 71.1729823, -0.8868320342, -0.4708528421, + 0.9686637642}, + {// Green polynomial coefficients + 1.253924194e7, -9.384505005e7, 3.026340546e8, -5.34752309e8, + 5.19893324e8, -1.713717015e8, -2.172471905e8, 3.27855405e8, + -1.860414042e8, 2.162883579e7, 4.19988092e7, -3.455217938e7, + 1.457863697e7, -3.963682593e6, 728543.6541, -90279.58116, + 7288.808678, -346.6642633, 2.570538457, -0.01825326375, + 0.957140793}, + {// Blue polynomial coefficients + 1.225069174e7, -1.078308201e8, 4.209820647e8, -9.448585341e8, + 1.294823204e9, -9.752324245e8, 2.822585622e7, 8.847497704e8, + -1.190845899e9, 9.278502881e8, -4.990445177e8, 1.945463189e8, + -5.568628699e7, 1.164951253e7, -1.750140682e6, 183096.3621, + -12714.02971, 549.7394828, -16.29798723, 0.17474818, + 0.97618134}}, + {// Polynomials based on the RdPu color scheme from http://colorbrewer2.org/ + {// Red polynomial coefficients + 1.009007533e7, -8.647409838e7, 3.284229929e8, -7.15440282e8, + 9.460959897e8, -6.730078116e8, -2.492012202e7, 6.463303972e8, + -8.135715842e8, 6.011980536e8, -3.060673144e8, 1.12273316e8, + -3.001889113e7, 5.822314814e6, -805532.3686, 77205.59251, + -4894.210055, 187.3783725, -2.796279811, -0.1297711209, + 0.9999279395}, + {// Green polynomial coefficients + -5.596279513e7, 4.4073891e8, -1.525131874e9, 2.987670582e9, + -3.459933872e9, 1.951051377e9, 6.09936545e8, -2.292082693e9, + 2.311280607e9, -1.414858186e9, 5.852420154e8, -1.652812489e8, + 3.021181863e7, -2.850393141e6, -86063.08, 62960.25987, + -8192.206251, 517.9372802, -16.07700273, -0.5076354515, + 0.9680424486}, + {// Blue polynomial coefficients + 1.861942113e6, -1.459578007e7, 5.033774865e7, -9.932095991e7, + 1.198777386e8, -8.030445868e7, -33512.01666, 7.219444612e7, + -1.038318614e8, 9.395579256e7, -6.185252517e7, 3.014858578e7, + -1.0743951e7, 2.739663543e6, -486926.1499, 58344.48681, + -4499.806329, 223.6063548, -11.75143099, -0.05050733327, + 0.9528188349}}, + {// Polynomials based on the YlGn color scheme from http://colorbrewer2.org/ + {// Red polynomial coefficients + -4.012406252e7, 3.242608668e8, -1.158116889e9, 2.361629549e9, + -2.892880228e9, 1.826211626e9, 3.053859595e8, -1.937840897e9, + 2.192633887e9, -1.50106127e9, 7.131192944e8, -2.445932811e8, + 6.11543284e7, -1.110228373e7, 1.450702341e6, -136263.2656, + 9449.161455, -504.1733456, 15.93244359, -0.2031111083, + 1.000544876}, + {// Green polynomial coefficients + 7.08030015e6, -6.001726902e7, 2.251039286e8, -4.834076283e8, + 6.28507731e8, -4.359433312e8, -2.719919829e7, 4.266866124e8, + -5.262711873e8, 3.848437089e8, -1.949933974e8, 7.15370427e7, + -1.91883765e7, 3.726079941e6, -508551.2337, 45856.29528, + -2357.375587, 34.7166996, 1.128416447, -0.02844604088, + 1.000092497}, + {// Blue polynomial coefficients + 2.166407279e6, -1.933196311e7, 7.609689939e7, -1.710202529e8, + 2.323230005e8, -1.695589112e8, -3.718314693e6, 1.611675284e8, + -2.033468224e8, 1.485019764e8, -7.381131502e7, 2.611702798e7, + -6.66387053e6, 1.225977751e6, -161437.0773, 14988.73196, + -954.5558573, 31.17039696, 5.005020529, -1.984112131, + 0.8980124853}}, + { // Polynomials based on the YlGnBu color scheme from + // http://colorbrewer2.org/ + {// Red polynomial coefficients + -1.269693464e7, 1.082492673e8, -4.10631883e8, 8.988376244e8, + -1.206441314e9, 8.935165683e8, -2.078547022e7, -8.125442615e8, + 1.099610578e9, -8.705252124e8, 4.799902453e8, -1.932776104e8, + 5.745382476e7, -1.251411653e7, 1.956464796e6, -212314.5037, + 15197.49388, -669.47562, 15.76554707, -0.6520450118, + 1.000370628}, + {// Green polynomial coefficients + 1.289638447e7, -1.103699162e8, 4.182881088e8, -9.083468032e8, + 1.195370137e9, -8.421008378e8, -4.183095504e7, 8.173103819e8, + -1.015172421e9, 7.412188186e8, -3.722402296e8, 1.343618034e8, + -3.525183724e7, 6.692606372e6, -904905.6461, 84722.88235, + -5250.921377, 195.5830359, -3.381105056, -0.2052140057, + 0.9999227287}, + {// Blue polynomial coefficients + 7.702499767e6, -6.617684798e7, 2.5103416e8, -5.43676389e8, + 7.098813799e8, -4.901970782e8, -3.8065985e7, 4.86516445e8, + -5.863454728e8, 4.163118648e8, -2.025768661e8, 7.049347709e7, + -1.773838612e7, 3.217417412e6, -415350.8546, 37301.06519, + -2246.869326, 70.38726438, 9.366949142, -2.402058038, + 0.8509368048}}, + {// Polynomials based on the YlOrBr color scheme from + // http://colorbrewer2.org/ + {// Red polynomial coefficients + -2.120852519e6, 1.666356448e7, -5.73337161e7, 1.113964152e8, + -1.280446994e8, 7.281417237e7, 1.931975136e7, -8.159953948e7, + 8.823372895e7, -6.201226868e7, 3.28674582e7, -1.376891801e7, + 4.539039949e6, -1.135785911e6, 204832.4685, -25016.42, + 1914.257203, -83.07619442, 1.762620629, -0.01379695972, + 1.000018077}, + {// Green polynomial coefficients + -2.588789539e6, 2.316050565e7, -9.222213588e7, 2.11890434e8, + -2.98762575e8, 2.34685138e8, -1.690813454e7, -2.054070474e8, + 2.883294933e8, -2.300401364e8, 1.256492307e8, -4.939709027e7, + 1.416594397e7, -2.952230167e6, 439927.6855, -45529.02608, + 3124.281932, -131.4336322, 1.280753242, -0.0712575005, + 1.000067072}, + {// Blue polynomial coefficients + 3.307686044e7, -2.856392357e8, 1.093766732e9, -2.404859162e9, + 3.217144401e9, -2.333317459e9, -3.295198001e7, 2.197926614e9, + -2.830876544e9, 2.131661638e9, -1.107391991e9, 4.158792066e8, + -1.143837138e8, 2.296798632e7, -3.316599009e6, 334936.1549, + -22606.64884, 934.9249536, -17.12823716, -1.451762785, + 0.8975390837}}, + {// Polynomials based on the YlOrRd color scheme from + // http://colorbrewer2.org/ + {// Red polynomial coefficients + -1.546374055e6, 1.623518432e7, -7.456071469e7, 1.955268568e8, + -3.145729337e8, 2.915182025e8, -6.905693935e7, -2.165405238e8, + 3.673240411e8, -3.285297958e8, 1.982514175e8, -8.590197933e7, + 2.720662666e7, -6.280353611e6, 1.037112163e6, -118240.9859, + 8797.869289, -393.3988812, 9.299244393, -0.09162058588, + 1.000202179}, + {// Green polynomial coefficients + 2.947060155e7, -2.469190068e8, 9.172677248e8, -1.955372265e9, + 2.529467908e9, -1.749432009e9, -1.096969758e8, 1.713944364e9, + -2.118143078e9, 1.552817721e9, -7.888095341e8, 2.902680578e8, + -7.8312587e7, 1.54341351e7, -2.188305714e6, 217075.7465, + -14400.40266, 583.5886937, -9.827690551, -0.7246105337, + 0.9996986903}, + {// Blue polynomial coefficients + 2.032146301e7, -1.782958446e8, 6.936351548e8, -1.549863966e9, + 2.109691448e9, -1.56721725e9, 1.539783571e7, 1.447617005e9, + -1.904315337e9, 1.45227381e9, -7.616244538e8, 2.880634493e8, + -7.961125792e7, 1.602256964e7, -2.312266324e6, 232589.8168, + -15576.67693, 639.6994008, -12.36245741, -1.431405461, + 0.7996766376}}}; + +ColorHelper::ColorHelper(ColorHelper::SequentialScheme S) + : MinIn(0.0), MaxIn(1.0), RedPoly(SequentialCoeffs[static_cast(S)][0]), + GreenPoly(SequentialCoeffs[static_cast(S)][1]), + BluePoly(SequentialCoeffs[static_cast(S)][2]) {} + +// Polynoials for Diverging schemes, 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]. + +static const double DivergingCoeffs[][3][21] = { + {// Polynomials based on the BrBG color scheme from http://colorbrewer2.org/ + {// Red polynomial coefficients + -286.8803187, -271.0452371, 1307.17252, 1265.974006, -2455.080169, + -2453.398789, 2436.554177, 2541.772396, -1347.24971, -1506.99162, + 381.2615938, 502.922459, -21.75840734, -83.74216656, -20.02371555, + 4.690059113, 7.673707511, 0.1237809241, -2.466309743, -0.4702714827, + 0.9602215101}, + {// Green polynomial coefficients + -46.19251062, -1.452259431, 161.3149443, 0.6929269596, -127.1961266, + 13.11775937, -229.5851105, -32.41621892, 576.1713757, 33.67386122, + -536.2025292, -18.06889859, 259.951356, 5.578247001, -64.81603763, + -1.590389667, 7.181956384, 0.4854203858, -1.376756074, 0.002981412093, + 0.9608753667}, + {// Blue polynomial coefficients + 337.3592683, 72.08948633, -1887.764167, -350.3143402, 4592.376254, + 717.3743192, -6367.0447, -800.2279575, 5537.728964, 521.487216, + -3128.891132, -194.7066381, 1145.924794, 36.59560151, -262.4932686, + -2.528425638, 36.26198661, -0.02090920749, -4.313761131, 0.3363451691, + 0.9601544236}}, + {// Polynomials based on the PiYG color scheme from http://colorbrewer2.org/ + {// Red polynomial coefficients + -221.9986656, 38.16161687, 1181.184619, -192.070912, -2708.270945, + 408.9614096, 3503.904375, -477.4671994, -2815.95126, 330.5192813, + 1461.145503, -136.2785922, -494.0793405, 31.22609216, 106.8058372, + -2.580139677, -13.19327877, -0.4687617931, -0.1612386706, -0.2046262802, + 0.9688248217}, + {// Green polynomial coefficients + 25.82837592, -478.0082591, 265.405487, 1958.953608, -1322.827865, + -3278.514666, 2295.320802, 2888.256833, -1994.993957, -1440.005462, + 937.8839818, 404.6402812, -230.1148382, -58.76139211, 23.44055027, + 3.37044763, 0.535250268, 0.05330372069, -1.240930319, 0.2010813874, + 0.9678130494}, + {// Blue polynomial coefficients + 127.2590941, 121.3567389, -702.3480066, -581.4223954, 1689.666737, + 1168.308166, -2325.62112, -1269.810307, 2018.40464, 796.6120092, + -1144.962817, -277.0130212, 423.6712973, 38.61926557, -99.04623753, + 5.835964702, 14.97831583, -2.374692916, -2.760079928, -0.2226730232, + 0.9682680843}}, + {// Polynomials based on the PRGn color scheme from http://colorbrewer2.org/ + {// Red polynomial coefficients + 204.5490507, -27.65300055, -1120.488759, 133.1944464, 2672.687692, + -277.9208263, -3649.309824, 322.7560381, 3146.369061, -219.2697835, + -1773.346135, 80.26392084, 649.1217692, -8.846513303, -147.7165962, + -3.119126437, 20.14500477, 0.6244174934, -2.854065767, -0.1558194072, + 0.9683336484}, + {// Green polynomial coefficients + 532.6549899, -88.02462462, -2815.327587, 503.8548115, 6346.364167, + -1162.894745, -7991.283605, 1414.614893, 6190.858326, -983.2182366, + -3068.06345, 389.2494083, 981.9924784, -79.44804498, -200.5076373, + 5.719631555, 25.27616156, 0.01491982701, -2.801054305, 0.2688173836, + 0.9684528359}, + {// Blue polynomial coefficients + 311.2546054, -25.50051851, -1724.851285, 128.2756425, 4160.871991, + -271.6495062, -5729.441944, 312.2490477, 4957.181083, -208.1012163, + -2789.752733, 78.4589146, 1018.360861, -14.75213819, -232.5794148, + 1.392182317, 31.62398422, -0.2698552767, -3.434601085, -0.1967457325, + 0.968053245}}, + {// Polynomials based on the PuOr color scheme from http://colorbrewer2.org/ + {// Red polynomial coefficients + 95.78127728, 18.38985413, -596.8851382, -93.79022636, 1618.2046, + 209.1866474, -2497.134855, -268.4852222, 2405.984962, 217.260549, + -1490.478109, -111.8330908, 587.2428165, 34.00063143, -139.451315, + -4.832556853, 17.79738326, 0.3226938543, -1.692799501, -0.3799133533, + 0.968399353}, + {// Green polynomial coefficients + 698.8240788, 191.1247911, -3587.477113, -972.5865558, 7862.842655, + 2055.803534, -9632.891088, -2337.892978, 7262.975538, 1542.489216, + -3504.000025, -588.0247207, 1093.13072, 118.9190801, -218.8471537, + -9.983931451, 27.96346124, 0.08456491363, -3.374689252, -0.05152039101, + 0.9683888724}, + {// Blue polynomial coefficients + 868.3136566, -392.8367984, -4406.097187, 1859.479526, 9606.744481, + -3669.427482, -11819.11056, 3896.050784, 9081.331992, -2393.864045, + -4563.717487, 850.6895674, 1522.396938, -163.6279724, -331.3606021, + 13.07598447, 45.82671494, 0.08678772177, -5.1295052, 0.5030938165, + 0.9674927817}}, + {// Polynomials based on the RdBu color scheme from http://colorbrewer2.org/ + {// Red polynomial coefficients + 42.65730984, 61.69594478, -268.5082989, -279.8541241, 759.2709387, + 522.3437947, -1255.280193, -513.6066686, 1319.16626, 282.0131744, + -895.6261994, -83.96314268, 380.7667161, 11.03215386, -93.46753849, + 1.310871959, 12.18578, -0.7591023959, -1.921591619, -0.4049557865, + 0.9683767145}, + {// Green polynomial coefficients + 582.8393444, -488.9961581, -2707.709964, 2151.793689, 5414.088282, + -3938.663025, -6173.86839, 3888.488885, 4493.193764, -2242.273173, + -2200.279444, 758.7630922, 730.7208378, -139.6230898, -158.0436507, + 9.971104545, 21.06121406, 0.5612577187, -2.870266159, 0.06627786897, + 0.9681621401}, + {// Blue polynomial coefficients + 245.4521993, -149.8049301, -1329.175967, 744.5996419, 3126.808126, + -1558.538803, -4192.1157, 1772.768846, 3530.163462, -1172.102391, + -1937.932067, 439.2670982, 696.1564849, -78.56276349, -161.361064, + 0.868299158, 24.73872638, 1.278983204, -3.450561273, 0.3548215807, + 0.9679669391}}, + {// Polynomials based on the RdGy color scheme from http://colorbrewer2.org/ + {// Red polynomial coefficients + 200.779838, -72.39966367, -1128.518995, 341.9795345, 2766.639255, + -689.6225198, -3878.946935, 781.9704613, 3422.255537, -555.414299, + -1964.772834, 260.7181972, 730.225286, -81.36937896, -168.2472131, + 15.68238947, 22.01925163, -1.453239956, -2.175988468, -0.243237772, + 0.9960948388}, + {// Green polynomial coefficients + 940.7677018, -420.7050933, -4603.913055, 1812.820476, 9740.153737, + -3230.273468, -11738.58697, 3084.710995, 8935.33313, -1713.150687, + -4487.738645, 561.6920218, 1499.120736, -103.9671121, -325.1759042, + 8.579319324, 43.66350008, 0.3122312879, -4.565733055, 0.02734696098, + 0.9990447212}, + {// Blue polynomial coefficients + 733.5413369, -89.60801863, -3924.443717, 436.5250141, 9073.83589, + -894.9867935, -11881.22991, 997.2145393, 9703.153392, -646.0541777, + -5134.781715, 236.034792, 1774.359381, -38.47774727, -395.2349401, + -1.936842144, 55.83884497, 1.070142333, -5.923523993, 0.2087748593, + 0.9984364827}}, + {// Polynomials based on the RdYlBu color scheme from + // http://colorbrewer2.org/ + {// Red polynomial coefficients + 100.5640809, -143.2110992, -536.1763222, 712.6904278, 1236.051845, + -1514.345767, -1616.794176, 1795.276584, 1326.186936, -1303.604188, + -714.5232564, 600.5253766, 259.2145873, -176.9118243, -64.22162849, + 33.55875388, 10.97970845, -4.032401207, -1.859487304, -0.1741625397, + 0.9975579015}, + {// Green polynomial coefficients + 157.1315885, 23.30412834, -891.9484002, -122.9285878, 2206.580416, + 272.6368214, -3115.524588, -332.6337764, 2761.921725, 244.2692057, + -1592.464136, -110.8889094, 597.1039153, 31.23541744, -140.9962331, + -5.791854905, 19.9875453, 0.7379492306, -2.684051174, 0.1648749349, + 0.9989005944}, + {// Blue polynomial coefficients + -516.928314, 92.31764334, 2876.395139, -431.5094756, -6963.025321, + 838.4884303, 9614.238906, -866.5411897, -8334.733423, 495.8189498, + 4696.949371, -133.7230604, -1715.530449, -7.45662151, 389.2822531, + 17.33700584, -48.93246234, -5.732024307, 1.900464099, 1.218743648, + 0.749644179}}, + {// Polynomials based on the RdYlGn color scheme from + // http://colorbrewer2.org/ + {// Red polynomial coefficients + 732.4272124, 279.2799655, -3392.120456, -1091.849632, 6710.903709, + 1669.211429, -7477.169774, -1216.023629, 5225.998723, 364.295343, + -2419.945767, 38.99715772, 761.7236137, -57.91950295, -162.3346609, + 16.26859824, 22.32473808, -2.293046909, -2.47172868, -0.2858202513, + 0.9949095976}, + {// Green polynomial coefficients + 251.890129, 16.90544074, -1389.671372, -88.06769591, 3331.531447, + 190.4794802, -4547.456613, -222.7778476, 3891.00638, 152.5022623, + -2165.080413, -61.37965972, 785.9341802, 14.30983655, -181.6655313, + -2.698804081, 25.78443217, 0.8113015417, -3.066838422, 0.1189456738, + 0.9991959903}, + {// Blue polynomial coefficients + 1173.593514, 44.07895932, -6247.909427, -214.5536782, 14356.94479, + 437.7349577, -18655.76142, -482.081786, 15098.81168, 305.20836, + -7914.739114, -106.8980209, 2716.412839, 16.54113718, -606.3128679, + -0.2186538388, 86.06853345, 0.2321550651, -7.670512605, -0.009873688717, + 0.7471257761}}, + {// Polynomials based on the Spectral color scheme from + // http://colorbrewer2.org/ + {// Red polynomial coefficients + -84.5665128, -54.32427971, 451.3125991, 299.1940572, -995.396544, + -676.6266255, 1173.55485, 816.3214919, -798.2896896, -574.5613518, + 313.1962074, 247.028054, -63.64150115, -69.75037531, 2.63746188, + 15.89238144, 1.994514531, -3.169520463, -1.304779191, -0.1289884193, + 0.9979164574}, + {// Green polynomial coefficients + 144.3335588, 180.232998, -770.5400873, -893.0144697, 1766.148539, + 1872.305393, -2282.104767, -2145.204698, 1838.583862, 1441.113853, + -968.5268065, -560.1619716, 342.2169512, 113.6942778, -82.11825453, + -9.316182101, 13.5539401, 0.3030588026, -2.388685763, 0.202163616, + 0.9981316447}, + {// Blue polynomial coefficients + 1011.625406, -203.1663574, -5669.184567, 984.3724757, 13841.1377, + -2005.211052, -19298.49623, 2215.97605, 16905.03781, -1418.791508, + -9622.161085, 507.3227885, 3544.416666, -77.13771193, -813.0360708, + -7.009308922, 107.9927114, 3.837930693, -7.631058172, -0.006325506806, + 0.747497562}}}; + +ColorHelper::ColorHelper(ColorHelper::DivergingScheme S) + : MinIn(-1.0), MaxIn(1.0), RedPoly(DivergingCoeffs[static_cast(S)][0]), + GreenPoly(DivergingCoeffs[static_cast(S)][1]), + BluePoly(DivergingCoeffs[static_cast(S)][2]) {} + +// Evaluates a polynomial given the coefficints provided in an ArrayRef +// evaluating: +// +// p(x) = a[n-0]*x^0 + a[n-1]*x^1 + ... a[n-n]*x^n +// +// at x_0 using Horner's Method for both performance and stability reasons. +static double polyEval(ArrayRef a, double x_0) { + double B = 0; + for (const auto &c : a) + B = c + B * x_0; + + return B; +} + +// 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 uintIntervalTo8bitChar(double B) { + double n = std::max(std::min(B, 1.0), 0.0); + return static_cast(255 * n + 0.5); +} + +// 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 tuple of color components. +std::tuple +ColorHelper::getColorTuple(double Point) const { + Point = std::max(std::min(Point, MaxIn), MinIn); + + uint8_t r = uintIntervalTo8bitChar(polyEval(RedPoly, Point)); + uint8_t g = uintIntervalTo8bitChar(polyEval(GreenPoly, Point)); + uint8_t b = uintIntervalTo8bitChar(polyEval(BluePoly, Point)); + + return std::make_tuple(r, g, b); +} + +// A helper method to convert a color represented as tuple of uint8s to a hex +// string. +std::string +ColorHelper::getColorString(std::tuple t) { + return llvm::formatv("#{0:X-2}{1:X-2}{2:X-2}", std::get<0>(t), std::get<1>(t), + std::get<2>(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 { + return getColorString(getColorTuple(Point)); +} Index: tools/llvm-xray/xray-graph.h =================================================================== --- tools/llvm-xray/xray-graph.h +++ tools/llvm-xray/xray-graph.h @@ -19,6 +19,7 @@ #include #include "func-id-helper.h" +#include "xray-color-helper.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Errc.h" @@ -97,7 +98,7 @@ PerThreadFunctionStackMap PerThreadFunctionStack; /// Usefull object for getting human readable Symbol Names. - FuncIdConversionHelper &FuncIdHelper; + const FuncIdConversionHelper &FuncIdHelper; bool DeduceSiblingCalls = false; TimestampT CurrentMaxTSC = 0; @@ -117,11 +118,15 @@ /// Normalises latency statistics for each edge and vertex by CycleFrequency; void normalizeStatistics(double CycleFrequency); + /// An object to color gradients + ColorHelper CHelper; + public: /// Takes in a reference to a FuncIdHelper in order to have ready access to /// Symbol names. - explicit GraphRenderer(FuncIdConversionHelper &FuncIdHelper, bool DSC) - : FuncIdHelper(FuncIdHelper), DeduceSiblingCalls(DSC) { + explicit GraphRenderer(const FuncIdConversionHelper &FuncIdHelper, bool DSC) + : FuncIdHelper(FuncIdHelper), DeduceSiblingCalls(DSC), + CHelper(ColorHelper::SequentialScheme::OrRd) { G[0] = {}; } Index: tools/llvm-xray/xray-graph.cc =================================================================== --- tools/llvm-xray/xray-graph.cc +++ tools/llvm-xray/xray-graph.cc @@ -374,61 +374,6 @@ return S.str(); } -// Evaluates a polynomial given the coefficints provided in an ArrayRef -// evaluating: -// -// p(x) = a[n-0]*x^0 + a[n-1]*x^1 + ... a[n-n]*x^n -// -// at x_0 using Horner's Method for both performance and stability reasons. -static double polyEval(ArrayRef a, double x_0) { - double B = 0; - for (const auto &c : a) { - B = c + B * x_0; - } - return B; -} - -// 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 uintIntervalTo8bitChar(double B) { - double n = std::max(std::min(B, 1.0), 0.0); - return static_cast(255 * n + 0.5); -} - -// 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. -// -// In order to calculate these polynomials, -// 1. Convert the OrRed9 color scheme from http://colorbrewer2.org/ from sRGB -// to LAB color space. -// 2. Interpolate between the descrete colors in LAB space using a cubic -// spline interpolation. -// 3. Sample this interpolation at 100 points and convert to sRGB. -// 4. Calculate a polynomial fit for these 100 points for each of R G and B. -// We used a polynomial of degree 9 arbitrarily based on a fuzzy goodness -// of fit metric (using human judgement); -// 5. Extract these polynomial coefficients from matlab as a set of constants. -static std::string getColor(double point) { - assert(point >= 0.0 && point <= 1); - const static double RedPoly[] = {-38.4295, 239.239, -600.108, 790.544, - -591.26, 251.304, -58.0983, 6.62999, - -0.325899, 1.00173}; - const static double GreenPoly[] = {-603.634, 2338.15, -3606.74, 2786.16, - -1085.19, 165.15, 11.2584, -6.11338, - -0.0091078, 0.965469}; - const static double BluePoly[] = {-325.686, 947.415, -699.079, -513.75, - 1127.78, -732.617, 228.092, -33.8202, - 0.732108, 0.913916}; - - uint8_t r = uintIntervalTo8bitChar(polyEval(RedPoly, point)); - uint8_t g = uintIntervalTo8bitChar(polyEval(GreenPoly, point)); - uint8_t b = uintIntervalTo8bitChar(polyEval(BluePoly, point)); - - return llvm::formatv("#{0:X-2}{1:X-2}{2:x-2}", r, g, b); -} - // Returns the quotient between the property T of this and another TimeStat as // a double double GraphRenderer::TimeStat::compare(StatType T, const TimeStat &O) const { @@ -492,7 +437,8 @@ OS << "F" << E.first.first << " -> " << "F" << E.first.second << " [label=\"" << S.getAsString(ET) << "\""; if (EC != StatType::NONE) - OS << " color=\"" << getColor(S.compare(EC, G.GraphEdgeMax)) << "\""; + OS << " color=\"" << CHelper.getColorString(S.compare(EC, G.GraphEdgeMax)) + << "\""; OS << "];\n"; } @@ -508,7 +454,8 @@ else OS << "\""; if (VC != StatType::NONE) - OS << " color=\"" << getColor(VA.S.compare(VC, G.GraphVertexMax)) << "\""; + OS << " color=\"" << CHelper.getColorString(VA.S.compare(VC, G.GraphVertexMax)) + << "\""; OS << "];\n"; } OS << "}\n";