Skip to content
Snippets Groups Projects
Commit 9282bd61 authored by Alex Nugent's avatar Alex Nugent
Browse files

Merge branch 'refs/heads/master' of

parents 91701cce 1ea4a23f
No related branches found
No related tags found
No related merge requests found
#Tue May 31 11:25:17 CEST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
File deleted
......@@ -98,16 +98,15 @@ public class AxisPair implements IChartPart {
}
public static int getTickSpace(int workingSpace) {
int tickSpace = (int) (workingSpace * 0.95);
return tickSpace;
}
public static int getLeftMargin(int workingSpace, int tickSpace) {
public static int getMargin(int workingSpace, int tickSpace) {
int marginSpace = workingSpace - tickSpace;
int leftMargin = (int) (marginSpace / 2.0);
return leftMargin;
int margin = (int) (marginSpace / 2.0);
return margin;
}
@Override
......
......@@ -131,47 +131,51 @@ public class AxisTick implements IChartPart {
*/
private void determineAxisTick() {
System.out.println("workingSpace= " + workingSpace);
int tickSpace = AxisPair.getTickSpace(workingSpace);
int leftMargin = AxisPair.getLeftMargin(workingSpace, tickSpace);
System.out.println("tickSpace= " + tickSpace);
int margin = AxisPair.getMargin(workingSpace, tickSpace);
final BigDecimal MIN = new BigDecimal(new Double(axis.getMin()).toString());
BigDecimal firstPosition;
BigDecimal tickStep = getGridStep();
BigDecimal gridStep = getGridStep(tickSpace);
if (MIN.remainder(tickStep).doubleValue() <= 0) {
firstPosition = MIN.subtract(MIN.remainder(tickStep));
double xyz = MIN.remainder(gridStep).doubleValue();
if (xyz <= 0.0) {
firstPosition = MIN.subtract(MIN.remainder(gridStep));
} else {
firstPosition = MIN.subtract(MIN.remainder(tickStep)).add(tickStep);
firstPosition = MIN.subtract(MIN.remainder(gridStep)).add(gridStep);
}
for (BigDecimal b = firstPosition; b.doubleValue() <= axis.getMax(); b = b.add(tickStep)) {
for (BigDecimal b = firstPosition; b.doubleValue() <= axis.getMax(); b = b.add(gridStep)) {
// System.out.println("b= " + b);
tickLabels.add(format(b.doubleValue()));
int tickLabelPosition = (int) (leftMargin + ((b.doubleValue() - axis.getMin()) / (axis.getMax() - axis.getMin()) * tickSpace));
int tickLabelPosition = (int) (margin + ((b.doubleValue() - axis.getMin()) / (axis.getMax() - axis.getMin()) * tickSpace));
// System.out.println("tickLabelPosition= " + tickLabelPosition);
// a check if all axis data are the exact same values
if (Math.abs(axis.getMax() - axis.getMin()) / 5 == 0.0) {
tickLabelPosition = (int) (leftMargin + tickSpace / 2.0);
tickLabelPosition = (int) (margin + tickSpace / 2.0);
}
tickLocations.add(tickLabelPosition);
}
}
private BigDecimal getGridStep() {
private BigDecimal getGridStep(int tickSpace) {
double length = Math.abs(axis.getMax() - axis.getMin());
double gridStepHint = length / workingSpace * DEFAULT_TICK_MARK_STEP_HINT;
double gridStepHint = length / tickSpace * DEFAULT_TICK_MARK_STEP_HINT;
// gridStepHint --> mantissa * 10 ** exponent
// e.g. 724.1 --> 7.241 * 10 ** 2
double mantissa = gridStepHint;
int exponent = 0;
if (mantissa == 0) {
// mantissa = 0.0;
exponent = 1;
} else if (mantissa < 1) {
while (mantissa < 1) {
mantissa *= 10.0;
......
......@@ -68,11 +68,11 @@ public class AxisTickLabels implements IChartPart {
for (int i = 0; i < axisTick.getTickLabels().size(); i++) {
String tickLabel = axisTick.getTickLabels().get(i);
int tickLocation = axisTick.getTickLocations().get(axisTick.getTickLocations().size() - i - 1); // reverse traverse
int tickLocation = axisTick.getTickLocations().get(i);
TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false));
Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0);
layout.draw(g, xOffset, (int) (yOffset + tickLocation + tickLabelBounds.getHeight() / 2.0));
layout.draw(g, xOffset, (int) (yOffset + axis.getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0));
if (tickLabelBounds.getWidth() > maxTickLabelWidth) {
maxTickLabelWidth = (int) tickLabelBounds.getWidth();
......
......@@ -57,7 +57,7 @@ public class AxisTickMarks implements IChartPart {
g.setColor(foreground);
if (axis.getDirection() == Axis.Direction.Y) {
if (axis.getDirection() == Axis.Direction.Y) { // Y-Axis
int xOffset = (int) (axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + AxisTick.AXIS_TICK_PADDING);
int yOffset = (int) (axis.getPaintZone().getY());
......@@ -68,7 +68,7 @@ public class AxisTickMarks implements IChartPart {
g.setColor(foreground);
g.setStroke(stroke);
g.drawLine(xOffset, yOffset + tickLocation, xOffset + TICK_LENGTH, yOffset + tickLocation);
g.drawLine(xOffset, yOffset + (int) (axis.getPaintZone().getHeight() - tickLocation), xOffset + TICK_LENGTH, yOffset + (int) (axis.getPaintZone().getHeight() - tickLocation));
}
......@@ -77,7 +77,7 @@ public class AxisTickMarks implements IChartPart {
// g.setColor(Color.blue);
// g.draw(bounds);
} else {
} else { // X-Axis
int xOffset = (int) (axis.getPaintZone().getX());
int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - AxisTick.AXIS_TICK_PADDING);
......
......@@ -53,11 +53,11 @@ public class PlotContent implements IChartPart {
// X-Axis
int xTickSpace = AxisPair.getTickSpace((int) bounds.getWidth());
int xLeftMargin = AxisPair.getLeftMargin((int) bounds.getWidth(), xTickSpace);
int xLeftMargin = AxisPair.getMargin((int) bounds.getWidth(), xTickSpace);
// Y-Axis
int yTickSpace = AxisPair.getTickSpace((int) bounds.getHeight());
int yLeftMargin = AxisPair.getLeftMargin((int) bounds.getHeight(), yTickSpace);
int yTopMargin = AxisPair.getMargin((int) bounds.getHeight(), yTickSpace);
// data points
double[] xData = series.getxData();
......@@ -72,8 +72,16 @@ public class PlotContent implements IChartPart {
for (int i = 0; i < xData.length; i++) {
if (Double.isInfinite(xData[i]) || Double.isNaN(xData[i])) {
throw new RuntimeException("Infinite or NaN values in xAxis Data not allowed!!!");
}
if (Double.isInfinite(yData[i]) || Double.isNaN(yData[i])) {
throw new RuntimeException("Infinite or NaN values in yAxis Data not allowed!!!");
}
int xTransform = (int) (xLeftMargin + ((xData[i] - xMin) / (xMax - xMin) * xTickSpace));
int yTransform = (int) (bounds.getHeight() - (yLeftMargin + (yData[i] - yMin) / (yMax - yMin) * yTickSpace));
int yTransform = (int) (bounds.getHeight() - (yTopMargin + (yData[i] - yMin) / (yMax - yMin) * yTickSpace));
// a check if all y data are the exact same values
if (Math.abs(xMax - xMin) / 5 == 0.0) {
......
......@@ -73,8 +73,8 @@ public class PlotSurface implements IChartPart {
g.setColor(foreground);
g.setStroke(stroke);
g.drawLine((int) bounds.getX(), (int) (bounds.getY() + tickLocation), (int) (bounds.getX() + bounds.getWidth() - 2), (int) (bounds.getY() + tickLocation));
// System.out.println("bounds.getY()= " + bounds.getY());
g.drawLine((int) bounds.getX(), (int) (bounds.getY() + bounds.getHeight() - tickLocation), (int) (bounds.getX() + bounds.getWidth() - 2), (int) (bounds.getY() + bounds.getHeight() - tickLocation));
}
// vertical
......
/**
* Copyright 2011 Xeiam LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xeiam.xcharts.example;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.xeiam.xcharts.Chart;
import com.xeiam.xcharts.JChartPanel;
import com.xeiam.xcharts.series.Series;
import com.xeiam.xcharts.series.SeriesMarker;
/**
* Demonstrated/Tests plotting horizontal and vertical lines
*
* @author timmolter
*/
public class SwingChart4 {
private static void createAndShowGUI() {
// generates linear data
double[] yData1 = new double[] { 0.0, 0.0, 0.0, -10.0, 15.0, 15.0 };
// Create and set up the window.
JFrame frame = new JFrame("XChart");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);
// Create Chart
Chart chart = new Chart(800, 600);
// Customize Chart
chart.setChartTitle("Sample Chart");
chart.setXAxisTitle("X");
chart.setYAxisTitle("Y");
chart.setChartTitleVisible(false);
chart.setChartLegendVisible(false);
chart.setAxisTitlesVisible(false);
// Series
Series series1 = chart.addSeries("y=0", null, yData1);
series1.setMarker(SeriesMarker.NONE);
// Swing
JPanel chartPanel = new JChartPanel(chart);
// add the panel to the content pane
frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
// Display the window
frame.pack();
frame.setLocationRelativeTo(null); // centers on screen
frame.setVisible(true);
}
public static void main(String[] args) {
// Schedule a job for the event-dispatching thread:
// creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment