// ReverseAxis:


// To reverse the axis, do both of the following:
// 1) Set the axis ranges in reverse order for the reverse axis values
// 2) Set the appropriate color values for the risk map
// 3) Use the RiskMapPlotModel to get the axis model, and then call the 
//    returned model's setReverseDirection() method with the value true

import com.sas.graphics.components.PlotVariable;
import com.sas.graphics.components.SegmentedRangeModel;
import com.sas.graphics.components.riskmapplot.RiskMapPlot;
import com.sas.graphics.components.riskmapplot.RiskMapPlotTableDataModel;
import com.sas.graphics.components.riskmapplot.SimpleRiskMap;
import javax.swing.table.DefaultTableModel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ReverseAxis extends JPanel {
  private ReverseAxis  theApp;
  public ReverseAxis () {
      setLayout(new BorderLayout());

     Data dataTable = new Data();  // defined below

     RiskMapPlotTableDataModel dataModel=
       new RiskMapPlotTableDataModel(dataTable);
     dataModel.setXVariable(new PlotVariable("Systolic Blood Pressure"));
     dataModel.setYVariable(new PlotVariable("Blood Sugar"));

  // 1) Set the axis ranges in reverse order for the reverse axis values
     SegmentedRangeModel xRange = SegmentedRangeModel.
       newSegmentedRangeModel(new double[]{200, 160, 135, 120, 0});
     SegmentedRangeModel yRange = SegmentedRangeModel.
       newSegmentedRangeModel(new double[]{400, 160, 120, 100, 0});

  // 2) Set the appropriate color values for the risk map
     SimpleRiskMap simpleRiskMap = new SimpleRiskMap(xRange, yRange,
       new Color[]{Color.RED,Color.ORANGE, Color.YELLOW, Color.GREEN},
       SimpleRiskMap.TYPE_BLOCK);

  // 3) Use the RiskMapPlotModel to get the axis model, and then call the 
  //    returned model's setReverseDirection() method with the value true
     RiskMapPlot riskMapPlot = new RiskMapPlot(dataModel);
     riskMapPlot.getGraphModel().setRiskMap(simpleRiskMap);
     riskMapPlot.getGraphModel().getXAxisModel().setReverseDirection(true);
     riskMapPlot.getGraphModel().getYAxisModel().setReverseDirection(true);

     add(riskMapPlot, BorderLayout.CENTER);
  }
  private static class Data extends DefaultTableModel
  {
     private Class   columnClass[] = {Double.class, Double.class};
     private String  columnNames[] = {"Blood Sugar", "Systolic Blood Pressure"};
     private Object  data[][]      = {
       {new Double(140), new Double(95)},
       {new Double(205), new Double(145)},
       {new Double(175), new Double(152)},
       {new Double(300), new Double(142)},
       {new Double(230), new Double(115)},
       {new Double(125), new Double(125)}
     };
     public Data()
     {
       super();
       setDataVector(data, columnNames);
     }
     public Class getColumnClass(int column)
     {
       return columnClass[column];
     }
  }
  public static void main(String[] args) {
     JFrame frame = new JFrame("BIP Graph Sample");
     Container container = frame.getContentPane();
     container.setLayout(new BorderLayout());
     container.setBackground(Color.white);

     JPanel bipPanel = new JPanel();
     bipPanel.setLayout(new BorderLayout());
     ReverseAxis  bipGraphSample = new ReverseAxis();

     bipPanel.add(bipGraphSample, BorderLayout.CENTER);
     container.add(bipPanel, BorderLayout.CENTER);
     frame.setSize(600,450);
     frame.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       }
     );
     frame.setVisible(true);
  }
}