import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class histogramPoints extends allDataPoints {
private aCanvas canvas;
private ArrayList rects;
/*When created it takes the canvas so it can call methods if needed, the data
*and a string, the default category. It then runs setDataPoints so that the
*graph will show the default cateogry. It sends it the ratingsInCat function
*because this will return the number of resaurants in each category in an array
*of ints*/
public histogramPoints(aCanvas c,allData d,int s,allAxis axis,infoArea i) {
super(d,s,axis,i);
canvas=c;
setDataPoints(category);
rects=new ArrayList();//Used later for click detection
}
/*Draws the data, spacing is the horizonal spacing, unit height is each interval
*in pixels, then it randomly assigns colors to each bar and creates a filled
*rectangle to be the bars for each part of the graph*/
void drawData(Graphics g) {
int spacing=axis.getHSpacing();
int unitHeight=axis.getVSpacing();
Graphics2D g2d = (Graphics2D)g;
g.setColor(color);
//get the labels so we can have them pop up in a message dialog if the user clicks
String[]labels=data.getCatLabels(category);
System.out.println("Yar"+data.getCatLabels(category).length);
Rectangle rects[]=new Rectangle[data.getCatLabels(category).length];
System.out.println(rects.length);
for (int x=1;x<rects.length-1;x++){
rects[x].setBounds(50+(spacing*x)-spacing/4, canvas.getHeight()-106,spacing/2,0);
rects[x].setSize(spacing/2, 0);
}
ArrayList restaurants=data.getData();
for (int x=0;x<restaurants.size();x++){
rects=((aRestaurant)restaurants.get(x)).drawBar(rects,category,
unitHeight);
}
for (int x=1;x<rects.length;x++){
g2d.fill(rects[x]);
}
/*rects.add(new histogramBar(new Rectangle(50+(spacing*x)-spacing/4,
canvas.getHeight()-106-getDataPoint(x)*unitHeight, spacing/2,
getDataPoint(x)*unitHeight)
,getDataPoint(x)+" restaurants were rated "+labels[x-1],canvas));*/
}
void doClick(Point p){
for(int x=1;x<rects.size() && !((histogramBar)rects.get(x)).isInside(p,infoDiv) ;x++){}
}
}