public class Box extends ChartObject{ //public variables //private variables private float yVal; private color m_color; //distributional information private TDistribution tdist; private float popSize; private double Sn; private float m_margin; /****************************************** Getters ******************************************/ public color getColor(){ return m_color; }//end getColor public float getAlpha(float y){ double yA = (Math.abs(y-yVal))/(Sn*(1.0)/sqrt(popSize)); double p = 2*(1-tdist.cumulativeProbability(yA)); return min(255, map((float)p, 0.0, 0.05, 0.0, 255.0)); }//end getAlpha public float getMean(){ return yVal; } public String getLabel(){ if(m_label!=null){ return m_label; } else{ return ""; } } public float getStdDev(){ return (float)Sn; } /****************************************** Private Methods ******************************************/ private void calcMargin(float margin,int n){ tdist = new TDistribution((float)n-1); double A = tdist.inverseCumulativeProbability(0.975); Sn = margin*Math.sqrt(n)/A; m_margin = margin; }//end calcMargin /****************************************** Constructors ******************************************/ public Box(float value,color barColor,float margin,int n){ yVal = value; m_color = barColor; popSize = n; m_margin = margin; calcMargin(margin,n); }//end Bar public Box(float value,color barColor,float margin,int n,String label){ yVal = value; m_color = barColor; popSize = n; calcMargin(margin,n); m_label = label; x_tick = true; tickSize = DEFAULT_TICK_SIZE; m_margin = margin; }//end Bar /****************************************** Draw Method ******************************************/ public void draw(int curX,int barWidth,float startY,float endY,float dataMin,float dataMax){ float dataY; float dataQ1; float h = startY-endY; dataY = map(yVal,dataMin,dataMax,startY,endY); stroke(0); line(curX,dataY,curX+barWidth-1,dataY); float q1 = (float)tdist.inverseCumulativeProbability(0.25); q1 = (float)( (q1*(Sn/sqrt(popSize)))); dataQ1 = dataY-map(yVal+q1,dataMin,dataMax,startY,endY); line(curX,dataY+dataQ1, curX+barWidth-1, dataY+dataQ1); line(curX,dataY-dataQ1, curX+barWidth-1, dataY-dataQ1); line(curX,dataY+dataQ1, curX, dataY-dataQ1); line(curX+barWidth-1,dataY+dataQ1, curX+barWidth-1, dataY-dataQ1); float margin1 = map(yVal+m_margin,dataMin,dataMax,startY,endY); line(curX,margin1,curX+barWidth-1,margin1); float margin2 = map(yVal-m_margin,dataMin,dataMax,startY,endY); line(curX,margin2,curX+barWidth-1,margin2); line(curX+(barWidth/2.0),margin2,curX+(barWidth/2.0),dataY-dataQ1); line(curX+(barWidth/2.0),margin1,curX+(barWidth/2.0),dataY+dataQ1); stroke(0); fill(0); if(x_tick){ line(curX+(barWidth/2.0),startY,curX+(barWidth/2.0),startY+tickSize); } if(m_label !=null){ text(m_label,curX+(barWidth/2.0)-(textWidth(m_label)/2.0),startY+tickSize+textAscent()); } }//draw }//end class