//
// BarGraph.java
//

/*
VisAD system for interactive analysis and visualization of numerical
data.  Copyright (C) 1996 - 2017 Bill Hibbard, Curtis Rueden, Tom
Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and
Tommy Jasmin.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/

package visad.util;

import javax.swing.*;
import java.awt.*;
import java.rmi.RemoteException;
import visad.*;
import visad.java3d.*;

/** BarGraph provides methods for plotting colored bar graphs in 2D or 3D. */
public class BarGraph {

  // -- Constants --

  protected static final RealType BAR_X = RealType.getRealType("Bar_X");
  protected static final RealType BAR_Y = RealType.getRealType("Bar_Y");
  protected static final RealType BAR_Z = RealType.getRealType("Bar_Z");
  protected static final RealType BAR_R = RealType.getRealType("Bar_Red");
  protected static final RealType BAR_G = RealType.getRealType("Bar_Green");
  protected static final RealType BAR_B = RealType.getRealType("Bar_Blue");
  protected static final FunctionType BOX_2D;
  protected static final FunctionType BOX_3D;
  static {
    FunctionType func2d = null, func3d = null;
    try {
      RealTupleType rgb = new RealTupleType(BAR_R, BAR_G, BAR_B);
      func2d = new FunctionType(new RealTupleType(BAR_X, BAR_Y), rgb);
      func3d = new FunctionType(new RealTupleType(BAR_X, BAR_Y, BAR_Z), rgb);
    }
    catch (VisADException exc) { exc.printStackTrace(); }
    BOX_2D = func2d;
    BOX_3D = func3d;
  }

  // -- 2D bar graph method signatures --

  /**
   * Constructs a 2D bar graph.
   * @param heights Height of each bar
   * @param spacing Spacing between bars (at least 0, and less than 1)
   * @param colors Color of each bar
   */
  
  public static FlatField makeBarGraph2D(float[] heights, float spacing,
    Color[] colors) throws VisADException, RemoteException
  {
    return makeBarGraph2D(BOX_2D, heights, spacing, colors);
  }

  /**
   * Constructs a 2D bar graph.
   * @param type MathType to use, of the form ((X, Y) -> (R, G, B))
   * @param heights Height of each bar
   * @param spacing Spacing between bars (at least 0, and less than 1)
   * @param colors Color of each bar
   */
  
  public static FlatField makeBarGraph2D(FunctionType type, float[] heights,
    float spacing, Color[] colors) throws VisADException, RemoteException
  {
    if (heights == null) throw new VisADException("Heights is null");
    int len = heights.length;
    float[] x1 = new float[len], y1 = new float[len];
    float[] x2 = new float[len], y2 = new float[len];
    float s = spacing / 2;
    for (int i=0; i 

Ads help maintain this website.