00001 #include "ColorAxis.h"
00002 #include "Rainbow.h"
00003
00004 #include "TVirtualPad.h"
00005 #include "TBox.h"
00006
00007
00008 #include <cstring>
00009 #include <iostream>
00010 using namespace std;
00011
00012 ClassImp(ColorAxis)
00013
00014 ColorAxis::ColorAxis(int ncolors, double width, double x1, double y1, double x2, double y2, int ndiv,
00015 Option_t* option)
00016 : RangeAxis(x1,y1,x2,y2,ndiv,option)
00017 , fNcolors(ncolors)
00018 , fWidth(width)
00019 , fScale(1.0)
00020 {
00021 }
00022 ColorAxis::ColorAxis(int ncolors, double width, RangeDouble* range,
00023 double x1, double y1, double x2, double y2, int ndiv,
00024 Option_t* option)
00025 : RangeAxis(range,x1,y1,x2,y2,ndiv,option)
00026 , fNcolors(ncolors)
00027 , fWidth(width)
00028 , fScale(1.0)
00029 {
00030 }
00031 ColorAxis::~ColorAxis()
00032 {
00033 }
00034
00035
00036
00037 void ColorAxis::PaintAxis(double xmin, double ymin, double xmax, double ymax,
00038 double &wmin, double &wmax, int &ndiv, Option_t *chopt,
00039 double, bool)
00040 {
00041
00042 this->PaintPalette();
00043
00044
00045 #if 0
00046 cerr << "(" << xmin << "," << ymin << ") --> "
00047 << "(" << xmax << "," << ymax << "), "
00048 << "[" << wmin << "," << wmax << "]\n";
00049 #endif
00050
00051 if (wmax < wmin) {
00052 cerr << "Warning: wmax(" << wmax << ") < wmin(" << wmin <<"), reversing\n";
00053 std::swap(wmin,wmax);
00054 }
00055 if (wmin == wmax) {
00056 wmin /= 2.0;
00057 if (wmax == 0.0) wmax = 1.0;
00058 else wmax *= 2.0;
00059 }
00060
00061 wmin /= fScale;
00062 wmax /= fScale;
00063
00064 this->RangeAxis::PaintAxis(xmin,ymin,xmax,ymax,wmin,wmax,ndiv,chopt);
00065 }
00066
00067 void ColorAxis::PaintPalette()
00068 {
00069 static Rainbow rainbow;
00070
00071 const char* opt = this->GetOption();
00072 int sign = 1;
00073
00074
00075 if (strstr(opt,"-")) sign = -1;
00076 if (strstr(opt,"+") && strstr(opt,"L")) sign = -1;
00077
00078 double dx=0,dy=0, width=0, height=0;
00079 if (fX1 == fX2) {
00080 dy = (fY2-fY1)/(1.0*fNcolors);
00081 width = sign*fWidth;
00082 }
00083 else {
00084 dx = (fX2-fX1)/(1.0*fNcolors);
00085 height = sign*fWidth;
00086 }
00087
00088
00089
00090
00091 TBox box;
00092 for (int i = 0; i < fNcolors; ++i) {
00093 double x1 = fX1 + i*dx;
00094 double x2 = fX1 + (i+1)*dx + width;
00095 double y1 = fY1 + i*dy;
00096 double y2 = fY1 + (i+1)*dy + height;
00097
00098
00099
00100 double rel = (1.0*i)/(1.0*fNcolors);
00101 int col = rainbow.GetRelativeColor(rel);
00102
00103 box.SetFillColor(col);
00104 box.TAttFill::Modify();
00105
00106 gPad->PaintBox(x1,y1,x2,y2);
00107 }
00108 }