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.h =================================================================== --- /dev/null +++ tools/llvm-xray/xray-color-helper.h @@ -0,0 +1,65 @@ +//===-- 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 "llvm/ADT/ArrayRef.h" + +namespace llvm{ +namespace xray{ + +class ColorHelper{ + private: + ArrayRef RedPoly; + ArrayRef GreenPoly; + ArrayRef BluePoly; + double MinIn; + double MaxIn; + + public: + enum class SequentialScheme{ + Blues, + Greens, + Greys, + Oranges, + Purples, + Reds, + BuGn, + BuPu, + GnBu, + OrRd, + PuBu, + PuBuGn, + PuRd, + RdPu, + YlGn, + YlGnBu, + YlOrBr, + YlOrRd + }; + + ColorHelper(SequentialScheme S); + + enum class DivergingScheme{ +BrBG, PiYG,PRGn, PuOr, RdBu, RdGy, RdYlBu, RdYlGn, +Spectral + }; + + ColorHelper(DivergingScheme S); + std::string getColor(double Point); +}; + +} +} +#endif Index: tools/llvm-xray/xray-color-helper.cc =================================================================== --- /dev/null +++ tools/llvm-xray/xray-color-helper.cc @@ -0,0 +1,550 @@ +//===-- 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. +// +// Sequential Color Gradient Polynomials. +// Polynomials based on the Blues color scheme from http://colorbrewer2.org/ +// Polynomials based on the Greens color scheme from http://colorbrewer2.org/ +// Polynomials based on the Greys color scheme from http://colorbrewer2.org/ +// Polynomials based on the Oranges color scheme from http://colorbrewer2.org/ +// Polynomials based on the Purples color scheme from http://colorbrewer2.org/ +// Polynomials based on the Reds color scheme from http://colorbrewer2.org/ +// Polynomials based on the OrRed color scheme from http://colorbrewer2.org/ +// Polynomials based on the BuPu color scheme from http://colorbrewer2.org/ +// Polynomials based on the GnBu color scheme from http://colorbrewer2.org/ +// Polynomials based on the OrRed color scheme from http://colorbrewer2.org/ +// Polynomials based on the PuBu color scheme from http://colorbrewer2.org/ +// Polynomials based on the PuBuGn color scheme from http://colorbrewer2.org/ +// Polynomials based on the PuRd color scheme from http://colorbrewer2.org/ +// Polynomials based on the RdPu color scheme from http://colorbrewer2.org/ +// Polynomials based on the YlGn color scheme from http://colorbrewer2.org/ +// Polynomials based on the YlGnBu color scheme from http://colorbrewer2.org/ +// Polynomials based on the YlOrBr color scheme from http://colorbrewer2.org/ +// Polynomials based on the YlOrRd color scheme from http://colorbrewer2.org/ + +static const double SequentialCoeffs[][3][21] = +{{{-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}, + {-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}, + {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}}, + {{-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}, + {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}, + {-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}}, + {{-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}, + {-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}, + {-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}}, + {{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}, + {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}, + {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}}, + {{-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}, + {-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}, + {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}}, + {{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}, + {-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}, + {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}}, + {{-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}, + {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}, + {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}}, + {{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}, + {-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}, + {-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}}, + {{-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}, + {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}, + {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}}, + {{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}, + {-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}, + {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}}, + {{-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}, + {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}, + {-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}}, + {{-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}, + {-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}, + {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}}, + {{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}, + {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}, + {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}}, + {{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}, + {-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}, + {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}}, + {{-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}, + {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}, + {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}}, + {{-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}, + {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}, + {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}}, + {{-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}, + {-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}, + {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}}, + {{-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}, + {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}, + {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]; +} + +//Diverging Polynomials +// Polynomials based on the BrBG color scheme from http://colorbrewer2.org/ +// Polynomials based on the PiYG color scheme from http://colorbrewer2.org/ +// Polynomials based on the PRGn color scheme from http://colorbrewer2.org/ +// Polynomials based on the PuOr color scheme from http://colorbrewer2.org/ +// Polynomials based on the RdBu color scheme from http://colorbrewer2.org/ +// Polynomials based on the RdGy color scheme from http://colorbrewer2.org/ +// Polynomials based on the RdYlBu color scheme from http://colorbrewer2.org/ +// Polynomials based on the RdYlGn color scheme from http://colorbrewer2.org/ +// Polynomials based on the Spectral color scheme from http://colorbrewer2.org/ + +static const double DivergingCoeffs[][3][21] = +{{{-29.79414825,-15.82865578,147.0833242,61.23646253,-316.0180457, + -87.60817402,391.8652913,47.79626734,-313.3393216,8.784829207,169.7733885, + -24.23057683,-63.2827043,12.69228657,16.58675017,-3.379540497,-3.258337251, + 0.8312171235,0.463877268,-0.7629727531,0.4197305995}, + {-2.317967592,-5.453495854,17.82254551,28.22351166,-59.73542634,-62.68982008, + 114.6926963,77.98804002,-139.2551,-59.32551112,111.1320005,28.0787742,-58.44389346, + -7.834699695,19.52563809,0.9498489,-3.681513498,0.113722102,0.1648878573, + -0.4484305873,0.6824041412},{4.070544047,2.352293185,-27.29964528,-16.5119775, + 80.28905527,47.35577655,-136.2097719,-73.18837265,147.3843585,66.59385296, + -106.0237046,-35.9204506,51.11371004,10.57572018,-16.08344732,-1.268596382, + 2.915494193,-0.07418274197,-0.2859785708,-0.2042854062,0.8391849499}}, + {{62.46977865,-145.3622299,-422.8831753,621.5813126,1130.238037,-1101.616596, + -1586.587628,1058.603215,1292.673026,-614.2552289,-637.4788514,230.5977655, + 196.9581726,-57.14511345,-40.84513789,7.681799454,5.921305126,0.2126851676, + -0.4378435976,-0.7842129202,0.4552123241}, + {5.642897194,4.447028461,-28.41541092,-25.59120911,57.71021368,62.89938517, + -56.82714265,-85.69958705,20.14317752,69.90795352,12.45570663,-33.90260001, + -16.93072806,8.643684985,7.59482331,-0.5765065637,-1.453607438,-0.1372767711, + -0.06112946734,-0.3516627703,0.7686523762}, + {-22.39361941,2.426638068,123.6061041,-10.41058397,-296.8057084,17.77725742, + 407.240226,-14.81578883,-352.9400182,5.431543484,201.9287743,0.04119535236, + -77.69322913,-0.4996196389,20.30959058,0.09107621928,-3.726431101,0.01855789839, + 0.5447856559,-0.4877001528,0.4628202313}}, + {{-97.43160734,-56.492287,474.816242,275.8916586,-983.4620642,-571.7917828, + 1131.928208,657.1228123,-794.4208606,-457.4803282,350.9528448,195.4009889, + -97.80160858,-47.52867012,17.63304589,4.633348223,-2.536293901,0.3561274303, + 0.2337662135,-0.6117111962,0.5882370576}, + {-97.43106302,-56.49260781,474.8136455,275.8930214,-983.4568162,-571.7941924, + 1131.922355,657.125109,-794.4169301,-457.4816047,350.9512152,195.4014075, + -97.80119666,-47.52874943,17.63298479,4.63335719,-2.536288614,0.3561265905, + 0.2337659518,-0.6117107548,0.588236602}, + {-97.4310609,-56.49263178,474.8136,275.8931046,-983.4566522,-571.7942982, + 1131.922092,657.1251584,-794.4166972,-457.4815933,350.9510939,195.401386, + -97.80115857,-47.52874125,17.63297739,4.633356385,-2.536287561,0.3561264227, + 0.2337658606,-0.6117105267,0.5882363625}}, + {{-12.04986549,4.035693262,59.19949461,-10.05859493,-115.7861747, + -4.470131854,105.3716167,41.70315419,-24.02937799,-59.72763037,-40.16929242, + 39.85042347,42.07332232,-12.69160699,-17.77194427,1.411055394,3.449751762, + -0.2198312135,-0.5306284594,-0.08340620125,0.9921066486}, + {7.511783592,1.236837947,-47.51962328,-15.28244893,130.2466138,56.46367062, + -202.6849188,-101.542017,196.9805553,102.518551,-123.8569925,-59.67587748, + 50.58122363,18.46114608,-13.23955115,-2.030997232,2.17280103,-0.01692654497, + -0.1879659126,-0.5359198251,0.5529257739}, + {-50.45603414,84.21532366,293.6914355,-401.6898096,-733.4518232,804.09777, + 1024.314605,-872.322735,-871.7559941,549.4296013,459.1759047,-196.3397406, + -142.7127071,33.36378618,21.63995165,-0.3279114334,-0.3665197395,-0.1948771762, + 0.1548567317,-0.6837377284,0.2350282845}}, + {{-6.671993169,-10.63822951,28.79343562,52.44566174,-44.78150475, + -109.6527449,18.74448872,126.402955,31.28049163,-87.29719376,-52.41248428, + 36.57326927,36.07474765,-8.804875007,-13.38608688,0.9185897196,2.465701971, + 0.1646200628,-0.1087782206,-0.482700337,0.6195998167}, + {-48.93131601,4.584033872,257.0785235,-29.132303,-587.1575819,79.19897963, + 770.4149418,-117.7547785,-647.2214143,102.9078736,367.1930735,-52.57439673, + -144.068929,13.87291094,38.87504835,-0.69647044,-6.781734426,-0.4218946955, + 0.4876635303,-0.4758184825,0.6040057871}, + {-13.71495884,7.696918384,80.72414099,-41.3644824,-210.3291793,95.31624101, + 319.7457597,-122.4291125,-314.3002069,94.94904918,208.6734567,-44.42464055, + -94.46683006,11.27039874,28.4751,-0.8196732791,-5.275134911,-0.1919408347, + 0.4246129394,-0.253722874,0.784395689}}, + {{18.35465487,21.92018495,-94.88088874,-116.336602,204.2441144,264.2023535, + -231.3177271,-333.8428022,137.4797241,254.3349737,-26.95672657,-116.7606126, + -15.83766871,28.9918923,11.07409755,-1.972489884,-2.193600481,-0.7838123946, + -0.2483344603,-0.05107982436,0.9843477937}, + {-10.62528668,-18.13841841,40.75926031,87.00457404,-53.96172646,-177.7350822, + 13.29212566,202.3546609,40.33210389,-141.7219228,-51.13898954,64.60212393, + 29.67489866,-20.48056344,-10.82181142,4.6738776,2.918810854,-0.3663250034, + -0.3648144786,-0.6734509999,0.4156842378}, + {6.711267443,-1.325409584,-36.06662808,10.95239402,85.07058494,-33.7420293, + -115.8486021,53.43481271,100.5236699,-48.28533696,-57.83738177,25.05637193, + 22.37723604,-6.576255524,-5.891807543,0.3322015404,0.8908176853,0.2742881082, + 0.2767185127,-0.5661275773,0.2902067343}}, + {{86.68230929,-78.57277256,-513.032068,288.0275348,1244.143334,-387.7872098, + -1609.112958,202.6036175,1205.875757,15.43183575,-533.0344382,-59.17824409, + 136.5620427,22.04987084,-18.77257499,-2.466933935,0.3062362672,0.09640521674, + 0.4651993354,-0.690369416,0.4003936885}, + {-9.159462824,21.45099967,55.19364031,-116.7893619,-148.4820269,272.6889854, + 234.9715952,-354.8874517,-241.934808,278.7743714,168.6036708,-132.0362587, + -79.70297549,33.95659782,24.6465005,-2.681303644,-4.534568352,-0.5457197309, + 0.2650083021,-0.2916133896,0.7608597722}, + {21.36127309,10.51883732,-112.5320264,-58.87201465,250.6848162,141.126997, + -304.0704873,-188.1712158,213.0100749,150.8808375,-81.06426558,-72.39783485, + 10.81812108,18.46070358,2.412284669,-1.248186505,-0.4480744667,-0.09758351117, + -0.2657961052,-0.6436765469,0.6431266225}}, + {{-13.38640592,9.084035781,70.99225537,-53.38553749,-168.1722415,132.9260996, + 237.8402772,-181.5776284,-225.7357084,146.0648407,150.987317,-67.41161791, + -70.85487463,14.34731144,21.95969894,0.6453165574,-4.305490427,-0.9384143603, + 0.7612328134,-0.08776730364,0.5491624483}, + {-584.1137857,-225.3859801,2844.098482,1117.35204,-5823.361206,-2309.922826, + 6519.614294,2581.98703,-4354.450202,-1694.31508,1783.679591,664.1157447, + -446.8392115,-150.330333,66.82668994,16.95627099,-5.56529127,-0.2927933388, + 0.01610548949,-0.6569287689,0.5878193943}, + {-1.398847067,-17.33646015,6.903800171,91.79060999,-15.28382627,-208.3559102, + 20.79464815,263.7843755,-20.1354165,-202.05687,14.69218882,93.882883,-7.841563767, + -24.02895481,2.79640686,1.949523133,-0.6612229002,0.3691636756,0.0004656279059, + -0.3474256933,0.7764919774}},{{-398.458273,-175.6984489,1918.477174, + 813.8021504,-3907.127369,-1571.564057,4388.286811,1640.984918,-2974.215292, + -1008.199334,1251.121607,374.6043833,-321.9476804,-84.30734558,47.15210526, + 10.94371759,-3.360151784,-0.3212601774,0.08727771372,-0.7137082914,0.4823084657}, + {6.125918442,16.78951938,-30.08561969,-90.13420896,60.1269706,207.5223673, + -59.82592692,-266.458431,25.04437551,206.8050376,6.210578297,-97.1092239, + -12.27458318,24.98932494,5.72466369,-2.064067394,-1.019505411,-0.4080608312, + -0.2072530718,-0.3008504127,0.8000030166}, + {11.13247957,69.11376256,-57.02086876,-363.3723067,119.3126117,818.7635741, + -125.5878905,-1028.883054,58.68541067,782.6748604,7.917027611,-361.8355543, + -23.96384661,92.70030759,11.5793608,-7.696397307,-2.195972497,-2.057952186, + 0.09655068093,0.3753192814,0.7686677867}}, + {{-9.104345093,10.487436,42.39489632,-57.35636521,-80.47503778,135.7862654, + 77.24625604,-182.0853582,-34.28223979,151.7884341,-1.652861987,-80.99829157, + 9.985951626,27.20645991,-5.404271711,-5.25736774,1.503421666,0.2909117046, + -0.4510509688,-0.1130833391,0.9882524562}, + {189.7543488,-65.06371206,-1023.694896,223.6245711,2301.398907,-261.4286239, + -2779.680723,69.95154427,1927.283912,98.8308756,-744.408958,-95.4410116, + 127.4127765,35.79358949,7.730364852,-6.868242504,-6.396223268,0.8199036795, + 0.530501823,-0.7052487977,0.5534418638}, + {97.30393583,49.81619163,-439.2106726,-253.370181,762.4287591,532.037204, + -557.5801799,-592.1068819,-18.53174292,371.8256047,337.2053367,-129.1133033, + -263.1420242,22.44525441,99.74356695,-1.331007351,-19.81833155,-0.2101958786, + 1.714755176,-0.4556634895,0.349434059}}, + {{-79.94683528,-195.0998343,317.498704,930.5807463,-449.933857,-1861.871795, + 181.0071743,2021.133606,205.1345991,-1284.114094,-292.2971292,480.1704773, + 154.3844303,-102.0463946,-41.58352012,11.92953252,6.431904387,-0.2927095343, + -0.6475623786,-0.8869096178,0.4552114657}, + {19.81003715,10.63904277,-105.1814441,-58.33900766,235.7245947,137.11195, + -286.5131656,-179.4245361,199.1720919,141.4310554,-72.80285448,-66.92727465, + 6.912741666,16.98945485,3.765013197,-1.208332861,-0.8348421449,-0.31492176, + -0.1207961086,-0.3319289941,0.6627575968}, + {-2.35024857,-10.79051657,8.470388116,57.92044091,-6.294012611,-133.2953, + -16.67632403,170.9831253,43.36963596,-132.4368046,-46.30880109,61.91639008, + 27.89873659,-15.73500819,-9.778238353,1.206353959,1.688600028,0.1333524351, + -0.1667959888,-0.221662482,0.8117536201}}, + {{113.3160047,-457.3661327,-830.5380332,2069.431988,2404.04789,-3875.29193, + -3677.327381,3857.654788,3275.427078,-2168.416074,-1731.531738,663.0210749, + 517.5040968,-89.83006179,-72.42519932,-0.2035598147,1.078346779,1.44834494, + 0.5433529135,-0.9511410972,0.4054417942}, + {5.63472047,-11.70590562,-38.78047533,56.6865661,116.9679605,-115.54304, + -203.2984729,128.1227836,224.9643437,-82.8513674,-164.9670866,30.37910061, + 80.59474908,-4.867331547,-25.44167106,-0.6737449225,4.648088328,0.4854988843, + -0.3632820443,-0.3796903679,0.6626900435}, + {-11.95329174,42.64364343,78.51445072,-220.6845857,-229.0285343,488.4925573, + 389.6350626,-601.6979603,-426.4370299,447.4534956,311.8433673,-201.4213892, + -152.6970537,49.67080625,48.27672444,-3.407604153,-8.654796412,-1.308405876, + 0.2872541907,-0.1266766836,0.8118780903}}, + {{-24.42976998,51.94768941,119.6949278,-264.0975346,-238.5657214,574.4413506, + 236.4737042,-697.2761818,-97.82380194,515.4949016,-26.53276921,-236.1485118, + 50.93196245,63.43214443,-24.7831838,-6.973206608,5.544852085,-1.442463631, + -0.6984586326,0.3396976154,0.8744756001}, + {-99.53441701,69.95993503,568.7887744,-320.4686269,-1423.257125,581.1866939, + 2028.236005,-501.2451291,-1785.567715,160.6500988,979.6387138,53.15983138, + -317.2425447,-56.91199863,50.23877128,14.33767229,-0.7248639456,-0.281758807, + -0.4936074441,-0.8649586608,0.3960087499}, + {56.41601548,24.1569559,-300.0155534,-135.3367238,675.7333225,324.9404201, + -831.0127522,-434.3995004,593.6996687,349.9122491,-234.4347638,-169.465171, + 36.33814617,44.40824195,4.882315954,-3.667605059,-1.334167444,-0.5368794564, + -0.4133425368,-0.4394312261,0.6901913487}}, + {{6.549436951,27.93251323,-37.66898825,-143.5304982,95.02441885,315.7048339, + -138.4669873,-387.4252105,129.3313483,289.0235034,-81.4442549,-132.8883145, + 35.67985807,35.48260417,-11.22302913,-4.073844458,2.748762101,-0.3878258498, + -0.8560018265,-0.1945109499,0.9685815688}, + {351.6459324,-266.2609228,-1960.474913,1161.031967,4652.395814,-2061.336592, + -6111.340072,1886.89143,4830.16239,-910.618476,-2328.970255,190.9229894, + 656.6703728,7.150851647,-94.7265662,-8.849440167,4.672240698,1.477477265, + 0.03974888899,-0.896988735,0.408990336}, + {15.16029057,6.563256796,-64.77197548,-32.41911268,88.71941878,67.43972728, + 12.16661365,-76.12080509,-178.0947856,49.48773686,236.6250769,-17.36846751, + -158.7807793,1.881540315,59.65581724,0.8446888379,-11.45338929,-0.3607874563, + 0.8265009692,-0.2163726362,0.6315340041}}, + {{-20.4637007,-151.960118,-24.98701568,656.6114048,321.5364687,-1180.351534, + -677.5544657,1155.675987,672.9616595,-685.750066,-372.6288063,262.838037, + 125.8604277,-65.82412717,-29.02303258,8.863178474,4.587751298,0.2801487589, + -0.2619343137,-0.8853977336,0.4709362956}, + {-1.674632217,21.28354598,7.718769744,-112.1491813,-21.2022843,253.0534941, + 46.33013478,-318.2257411,-72.329322,241.8501567,72.94582459,-111.07849, + -45.50797015,27.74332878,16.52446742,-2.07044612,-2.949115658,-0.4072972414, + 0.002930387618,-0.3640926642,0.7765063389}, + {15.26951107,3.253208751,-82.08034082,-24.06468156,190.8147008,70.99716975, + -251.5415726,-111.2017275,207.4517836,101.1926092,-111.7709533,-53.57667127, + 40.26820972,14.79068357,-10.06130642,-1.335692282,2.019018856,-0.04433384417, + -0.3140624713,-0.3792407497,0.4744557647}}, + {{-56.42164188,-32.44995394,271.5876032,148.8117557,-538.7318896, + -283.5973096,551.5636126,289.0451946,-279.7905084,-168.5450773,22.33782852, + 55.59670042,52.72147251,-9.415597316,-28.60170268,0.05567474042,4.992002242, + 0.8332060432,0.6034743337,-0.8192777229,0.2551082153}, + {13.60871451,35.50677923,-73.6829431,-185.8043633,174.4398772,416.5670297, + -238.0809568,-520.5774389,208.2280899,393.3282859,-123.0437716,-180.1809698, + 50.59057003,45.62191317,-14.56049593,-3.774934653,2.918366745,-0.7086120533, + -0.5742113103,-0.4207156359,0.7136589175}, + {24.08683077,19.19101998,-126.496484,-113.7978084,282.0376146,287.502392, + -345.1830876,-402.0187503,248.5980575,336.5130742,-102.7597138,-167.9822903, + 20.21639582,44.78783091,-0.214355564,-3.759389265,-0.04792960614,-0.7830117995, + -0.407851063,0.09394087993,0.7686031044}}, + {{24.21737981,-11.03294031,-126.9332175,53.15931262,294.1220241,-109.8999456, + -400.0784479,127.8934894,357.0325151,-92.04544705,-219.5418057,41.85228966, + 93.64770046,-11.4754683,-26.67535167,1.806927675,4.680071762,-0.4395416695, + -0.7664255201,-0.1187783727,0.9956938261}, + {-10.75358503,-4.540244424,58.80601561,20.58210168,-141.2998232,-37.78958818, + 197.2270919,34.75987842,-178.3107059,-14.62911454,110.0957128,-0.4418640435, + -47.31697289,3.200550392,13.81595232,-1.485158373,-2.462752231,0.6076337509, + 0.17152512,-0.6916811473,0.6000603087}, + {122.2224378,78.60588429,-627.3181641,-412.342546,1377.701928,923.4167527, + -1691.512557,-1146.664169,1274.404019,854.4978503,-610.3485876,-381.7449669, + 187.1453092,92.28374426,-36.00224639,-6.868967408,3.593985035,-1.244638929, + 0.4144196189,-0.3759995452,0.1606412288}}, + {{-18.12753159,2.826412842,104.9056438,-20.20027451,-264.2884103,55.29145932, + 382.6670633,-76.81220165,-355.0990962,57.59651412,223.2416766,-20.75387098, + -97.3155927,0.2144844733,28.79634119,2.658840837,-5.255711708,-1.114072665, + 0.2343465168,0.04362193311,0.9922691904}, + {82.32053956,86.93609883,-373.1269247,-409.1328115,702.5578459,796.1356472, + -723.6074645,-820.5847373,471.2960129,472.5521611,-234.5270097,-142.0254941, + 106.655298,13.14605098,-39.91679279,4.05058819,9.570778139,-0.8277100069, + -1.274620261,-0.7495101184,0.5527369612}, + {68.97058736,43.34637762,-374.7907931,-236.1237084,879.5630411,551.507286, + -1167.076545,-718.1218305,963.4150827,565.2201775,-514.261875,-269.8628247, + 180.1522501,71.8187324,-42.08764554,-7.246970454,6.707476836,-0.6506513354, + -0.352150097,-0.2120256061,0.235190136}}}; + +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. +std::string ColorHelper::getColor(double point) { + 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 llvm::formatv("#{0:X-2}{1:X-2}{2:X-2}", r, g, b); +} + 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,16 @@ /// 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 @@ -370,61 +370,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 { @@ -488,7 +433,7 @@ 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.getColor(S.compare(EC, G.GraphEdgeMax)) << "\""; OS << "];\n"; } @@ -505,7 +450,7 @@ else OS << "\""; if (VC != StatType::NONE) - OS << " color=\"" << getColor(VA.S.compare(VC, G.GraphVertexMax)) << "\""; + OS << " color=\"" << CHelper.getColor(VA.S.compare(VC, G.GraphVertexMax)) << "\""; OS << "];\n"; } OS << "}\n";