public class LineChart
extends javax.swing.JComponent
This project was carried out at:
and supported byGenOpt Copyright (c) 1998-2021, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
protected int |
chartDX
x extension of chart
|
protected int |
chartDY
y extension of the chart
|
protected boolean |
chartInitialized |
protected java.awt.Font |
foLa
label Font
|
protected java.awt.Font |
foSuTi
sub title Font
|
protected java.awt.Font |
foTi
title Font
|
protected java.awt.font.FontRenderContext |
frc
FontRenderContext of Graphics2D
|
protected int |
ins
inset around everything
|
protected int |
insChaNorth
inset of the chart on the north side
|
protected int |
insChaWest
inset of the chart on the west side
|
protected int[] |
insNameNorth
inset of each serie name on the north side
|
protected int[] |
insNameWest
inset of each serie name on the west side
|
protected int |
insXLabNorth
inset of x-axis label on the north side
|
protected int |
insY0LabNorth
inset of the y0 label on the north side
|
protected int |
insY1LabNorth
inset of the y1 label on the north side
|
protected int |
insYHalfLabNorth
inset of the y half label on the north side
|
protected int[] |
insYLab
inset of each y-axis label
|
static int |
INTEGER |
protected int |
labAsc
ascent of label
|
private static double |
LG_10
the natural logarithm (base e) of 10
|
private static double |
LN10
Natural logarithmus of 10
|
protected static int |
MANTISSA_LENGTH
lenght of mantissa field
|
protected int |
MINPOI
number of points for which the graph is drawn
|
protected int |
nSer
number of data series in the chart
|
protected static int |
NSERMAX
maximum number of data serie that can be displayed at once
|
private static int |
NUMBER_OF_COLORS
the number of available colors
|
protected static int |
NUMBER_OF_DIGITS
number of digits after decimal point
|
static int |
NUMBER_OF_MINOR_Y_GRIDLINES |
static int |
SCIENTIFIC |
private static long |
serialVersionUID
The serial version number
|
protected DataSerie[] |
serie
the data serie
|
private static java.awt.Color[] |
STANDARD_COLOR
the standard color to be assigned
|
protected java.awt.font.TextLayout |
subTitLay
sub title TextLayout
|
protected java.lang.String |
titLab
title label
|
protected java.awt.font.TextLayout |
titLay
title TextLayout
|
protected double |
x0
x-axis minimum in displayed units (not pixels)
|
protected double |
x0Last
x-axis minimum of the last rendering in displayed units (not pixels)
|
protected double |
x1
x-axis maximum in displayed units (not pixels)
|
protected double |
x1Last
x-axis maximum of the last rendering in displayed units (not pixels)
|
protected java.lang.String |
xAxiLab
x-axis label
|
private double |
xAxiLen
x-axis lenght in x units
|
protected double[] |
xAxiTic
x-axis ticks
|
protected int |
xNumFor
number format of x-axis label
|
protected double[] |
y0
y-axis minimum in displayed units (not pixels)
|
protected double[] |
y0Last
y-axis minimum of the last rendering in displayed units (not pixels)
|
protected double[] |
y1
y-axis maximum in displayed units (not pixels)
|
protected double[] |
y1Last
y-axis maximum of the last rendering in displayed units (not pixels)
|
protected double[] |
yAxiLenVal
y-axis lenght in displayed units (not pixels)
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
LineChart()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(DataSerie ds)
adds a data serie to the chart
|
protected void |
computeXAxisTicks()
gets the x maximum label
|
protected void |
drawBox(java.awt.Graphics g)
draws the box around the chart
|
protected void |
drawLegend(java.awt.Graphics g)
draws the chart label
|
protected void |
drawTitle(java.awt.Graphics2D g)
draws the chart title
|
protected void |
drawWholeChart(java.awt.Graphics2D g)
draws the whole chart
|
protected java.lang.String |
getAxisLabel(double x)
gets an axis label
|
private int |
getLabelStringWidth(java.lang.String label) |
protected int |
getMaxPoints()
gets the maximal number of data in all series
|
static double[] |
getTicks(double xMin,
double xMax)
gets the label ticks
|
protected java.lang.String[] |
getXAxisLabel()
gets the x axis labels
|
protected int |
getXPointOffset(double x)
gets the offset of an x-value, measured in pixels
from the west border of the chart surrounding box
|
protected int |
getYPointOffset(double y,
int i)
gets the offset of an y-value, measured in pixels
from the north border of the chart surrounding box
|
protected void |
initialize(java.awt.Graphics g)
initializes the space of the chart (used if no data are available yet)
|
protected static boolean |
isEven(int i)
checks whether argument is an even number or an odd number
|
void |
paint(java.awt.Graphics g)
paints the chart (or the message if chart cannot be initialize yet)
|
void |
removeAllSeries()
clears all data series
|
void |
renderNewPoints()
renders the new data points without repainting the whole chart
|
private boolean |
requireRescale()
checks if the chart requires a rescaling
|
private void |
safeDrawChartLines(java.awt.Graphics g)
draws the lines of the chart
|
void |
setSerie(DataSerie ds)
sets new values of a serie.
|
void |
setSubTitle()
sets the sub title
|
void |
setTitle(java.lang.String title)
sets the title
|
void |
setXAxisLabel(java.lang.String label)
sets the x-axis label
|
void |
setXNumberFormat(int format)
sets the number format for the x-axis label
|
private void |
storeScale()
stores the current values of the x and y scale
|
protected void |
updateInsets()
updates the insets around the chart
|
protected void |
updateYScale()
updates the y min values and the y axis length (in displayed units)
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private static final long serialVersionUID
private static final double LN10
public static final int INTEGER
public static final int SCIENTIFIC
public static final int NUMBER_OF_MINOR_Y_GRIDLINES
protected boolean chartInitialized
protected DataSerie[] serie
protected int nSer
protected static final int NSERMAX
protected java.awt.font.FontRenderContext frc
protected java.lang.String titLab
protected java.lang.String xAxiLab
protected double[] xAxiTic
protected double x0
protected double x1
protected double x0Last
protected double x1Last
protected double[] yAxiLenVal
protected double[] y0
protected double[] y1
protected double[] y0Last
protected double[] y1Last
protected java.awt.Font foTi
protected java.awt.font.TextLayout titLay
protected java.awt.font.TextLayout subTitLay
protected java.awt.Font foSuTi
protected java.awt.Font foLa
protected int labAsc
protected int ins
protected int insChaWest
protected int insChaNorth
protected int insXLabNorth
protected int insY0LabNorth
protected int insYHalfLabNorth
protected int insY1LabNorth
protected int[] insYLab
protected int[] insNameNorth
protected int[] insNameWest
protected int xNumFor
protected int chartDX
protected int chartDY
protected final int MINPOI
protected static int MANTISSA_LENGTH
protected static int NUMBER_OF_DIGITS
private static double LG_10
private static final java.awt.Color[] STANDARD_COLOR
private static final int NUMBER_OF_COLORS
private double xAxiLen
public final void setXNumberFormat(int format)
format
- the number formatpublic final void setSubTitle()
public final void setTitle(java.lang.String title)
title
- the title of the chartpublic final void setXAxisLabel(java.lang.String label)
label
- the x-axis labelpublic final void removeAllSeries()
public final void add(DataSerie ds) throws java.lang.IllegalArgumentException
ds
- the data serieif
- the name of the serie is not uniquejava.lang.IllegalArgumentException
public final void setSerie(DataSerie ds) throws java.lang.IllegalArgumentException
ds
- the data seriejava.lang.IllegalArgumentException
- if the serie is not registered yetprotected final java.lang.String getAxisLabel(double x)
x
- the number to be parsedpublic static final double[] getTicks(double xMin, double xMax)
xMin
- the minimum data point of the axisxMax
- the maximum data point of the axisprotected final java.lang.String[] getXAxisLabel()
protected final void computeXAxisTicks()
protected final void updateYScale()
private int getLabelStringWidth(java.lang.String label)
protected final void updateInsets()
protected static final boolean isEven(int i)
i
- the argument to be testedtrue
if i is even, false
otherwiseprotected final int getMaxPoints()
public void paint(java.awt.Graphics g)
paint
in class javax.swing.JComponent
g
- the Graphics Objectprivate final boolean requireRescale()
true
if the chart requires a rescaling
false
otherwisepublic final void renderNewPoints()
private void safeDrawChartLines(java.awt.Graphics g)
g
- reference to graphics objectprotected void drawTitle(java.awt.Graphics2D g)
g
- the Graphics Objectprotected final void drawLegend(java.awt.Graphics g)
g
- the Graphics Objectprotected final void drawBox(java.awt.Graphics g)
g
- the Graphics Objectprotected final int getXPointOffset(double x)
x
- the x-value (not in pixels)protected final int getYPointOffset(double y, int i)
y
- the function value f(x)i
- the number of the data serie to which the point belongs toprivate final void storeScale()
protected final void drawWholeChart(java.awt.Graphics2D g)
g
- the Graphics Objectprotected void initialize(java.awt.Graphics g)
g
- the Graphics Object