package graphs;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import odor.Odor;
import org.tc33.jheatchart.HeatChart;
/**
* Uses JHeatGraph to produce Odor battery heat graph
* @author pedro
*
*/
public class OdorSparsnessHeatJGraph
{
private double [][] odorComparisonData;
private HeatChart chart;
private JFrame chartFrame;
public OdorSparsnessHeatJGraph(Odor[] battery)
{
if (battery == null)
{
throw new java.lang.IllegalArgumentException();
}
odorComparisonData = new double[battery.length][battery.length];
for (int x=0; x<battery.length; x++)
{
for (int y=0; y<battery.length; y++)
{
odorComparisonData[x][y] = battery[x].compareTo(battery[y]);
}
}
chart = new HeatChart(odorComparisonData);
chart.setTitle("Odor Heat Map");
chart.setXAxisLabel("Odor Num");
chart.setYAxisLabel("Odor Num");
chart.setHighValueColour(Color.RED);
chart.setLowValueColour(Color.BLUE);
chartFrame = new JFrame();
JLabel imageLabel = new JLabel();
chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
imageLabel.setIcon(new ImageIcon(chart.getChartImage()));
chartFrame.setTitle("Odor Comparison HeatGraph");
chartFrame.setLayout(new FlowLayout());
chartFrame.add(imageLabel);
double[] standardDevs = new double[battery.length];
for (int x=0; x<battery.length; x++)
{
standardDevs[x] = battery[x].getStandardDeviation();
}
chartFrame.add(new JLabel("Avg. STDev: "+util.Util.arraySum(standardDevs)/(battery.length)));
chartFrame.pack();
chartFrame.setVisible(true);
}
public void setTitle(String arg0)
{
chartFrame.setTitle(arg0);
}
}