use of org.jfree.chart.axis.ValueAxis in project xwiki-platform by xwiki.
the class TableTimeTableXYBuilderTest method testBuildTimeTableXY.
@Test
public void testBuildTimeTableXY() throws Exception {
String content = "| Date | column 2 | column 3 | column 4\n" + "| 2012-01-01 10:30:10 | 12 | 13 | 14 \n" + "| 2012-01-01 10:30:20 | 22 | 23 | 24 \n";
setUpContentExpectation(content);
getDataSource().buildDataset(content, map("type", "xy_line_and_shape", "dataset", "timetable_xy", "range", "A2-D3", "locale", "en_US", "date_format", "yyyy-MM-dd kk:mm:ss", "domain_axis_type", "date"), null);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss", new Locale("en"));
ChartModel chartModel = getDataSource().getChartModel();
Assert.assertTrue(chartModel.getDataset() instanceof TimeTableXYDataset);
Assert.assertTrue(chartModel.getAxis(0) instanceof DateAxis);
Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
TimeTableXYDataset dataset = (TimeTableXYDataset) chartModel.getDataset();
Assert.assertTrue(dataset.getSeriesCount() == 3);
Assert.assertTrue(dataset.getSeriesKey(0).equals(" column 2 "));
Assert.assertTrue(dataset.getSeriesKey(1).equals(" column 3 "));
Assert.assertTrue(dataset.getSeriesKey(2).equals(" column 4"));
Assert.assertTrue(dataset.getTimePeriod(0).getStart().equals(new Date(0)));
Assert.assertTrue(dataset.getTimePeriod(0).getEnd().equals(dateFormat.parse("2012-01-01 10:30:10")));
Assert.assertTrue(dataset.getTimePeriod(1).getStart().equals(dateFormat.parse("2012-01-01 10:30:10")));
Assert.assertTrue(dataset.getTimePeriod(1).getEnd().equals(dateFormat.parse("2012-01-01 10:30:20")));
}
use of org.jfree.chart.axis.ValueAxis in project xwiki-platform by xwiki.
the class TableTimeTableXYBuilderTest method testYearInterval.
@Test
public void testYearInterval() throws Exception {
String content = "| Date | column 2 | column 3 | column 4\n" + "| 1970 | 12 | 13 | 14 \n" + "| 1971 | 22 | 23 | 24 \n";
setUpContentExpectation(content);
getDataSource().buildDataset(content, map("type", "xy_line_and_shape", "dataset", "timetable_xy", "range", "A2-D3", "locale", "en_US", "date_format", "yyyy", "domain_axis_type", "date", "time_period", "year"), null);
ChartModel chartModel = getDataSource().getChartModel();
Assert.assertTrue(chartModel.getDataset() instanceof TimeTableXYDataset);
Assert.assertTrue(chartModel.getAxis(0) instanceof DateAxis);
Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
}
use of org.jfree.chart.axis.ValueAxis in project tdq-studio-se by Talend.
the class ChartDecorator method decorateCategoryPlot.
/**
* DOC bZhou Comment method "decorateCategoryPlot".
*
* @param chart
*/
public static void decorateCategoryPlot(JFreeChart chart, PlotOrientation orientation) {
CategoryPlot plot = chart.getCategoryPlot();
CategoryItemRenderer render = plot.getRenderer();
CategoryAxis domainAxis = plot.getDomainAxis();
// ADD msjian TDQ-5111 2012-4-9: set something look it well
domainAxis.setCategoryMargin(0.1);
domainAxis.setUpperMargin(0.05);
domainAxis.setLowerMargin(0.05);
domainAxis.setCategoryLabelPositionOffset(10);
// TDQ-5111~
ValueAxis valueAxis = plot.getRangeAxis();
// $NON-NLS-1$
Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);
render.setBaseItemLabelFont(font);
// MOD zshen 10998: change the font name 2010-01-16
// $NON-NLS-1$
font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);
domainAxis.setLabelFont(font);
// $NON-NLS-1$
font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);
valueAxis.setLabelFont(font);
// $NON-NLS-1$
font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);
domainAxis.setTickLabelFont(font);
valueAxis.setTickLabelFont(font);
setLegendFont(chart);
// $NON-NLS-1$
font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);
TextTitle title = chart.getTitle();
if (title != null) {
title.setFont(font);
}
font = null;
if (render instanceof BarRenderer) {
CategoryDataset dataset = chart.getCategoryPlot().getDataset();
if (dataset != null) {
int rowCount = dataset.getRowCount();
List<?> columnKeys = dataset.getColumnKeys();
if (!isContainCJKCharacter(columnKeys.toArray())) {
// $NON-NLS-1$
domainAxis.setTickLabelFont(new Font("Tahoma", Font.PLAIN, 10));
}
((BarRenderer) render).setItemMargin(-0.40 * rowCount);
// TDQ-12621 add Tooltip for Lable
for (Object colKey : columnKeys) {
domainAxis.addCategoryLabelToolTip(colKey.toString(), colKey.toString());
}
}
domainAxis.setUpperMargin(0.1);
// TDQ-12621 Only display in 1 line for the label, other chars will be displayed as "..."
domainAxis.setMaximumCategoryLabelLines(1);
// not do this when the bar is horizontal Orientation
if (orientation == null) {
((BarRenderer) render).setMaximumBarWidth(0.2);
}
// TDQ-5111~
}
// ~10998
}
use of org.jfree.chart.axis.ValueAxis in project tdq-studio-se by Talend.
the class ToolTipChartComposite method getTooltipAtPoint.
/**
* This method attempts to get a tooltip by converting the screen X,Y into Chart Area X,Y and then looking for a
* data point in a data set that lies inside a hotspot around that value.
*
* @param point The Java 2D point
* @return A string for the data at the point or null if no data is found.
*/
protected String getTooltipAtPoint(Point point) {
String result = null;
Point2D translatedPoint = this.translateScreenToJava2D(point);
Plot plot = this.getChart().getPlot();
PlotRenderingInfo info = this.getChartRenderingInfo().getPlotInfo();
if (plot instanceof CombinedDomainXYPlot) {
int index = info.getSubplotIndex(translatedPoint);
if (index < 0) {
index = 0;
}
plot = (Plot) ((CombinedDomainXYPlot) plot).getSubplots().get(index);
info = this.getChartRenderingInfo().getPlotInfo().getSubplotInfo(index);
}
if (plot != null && plot instanceof XYPlot) {
XYPlot xyPlot = (XYPlot) plot;
ValueAxis domainAxis = xyPlot.getDomainAxis();
ValueAxis rangeAxis = xyPlot.getRangeAxis();
// had to switch to SWT's rectangle here.
Rectangle screenArea = this.scale(info.getDataArea());
double hotspotSizeX = hotspontsize * this.getScaleX();
double hotspotSizeY = hotspontsize * this.getScaleY();
double x0 = point.getX();
double y0 = point.getY();
double x1 = x0 - hotspotSizeX;
double y1 = y0 + hotspotSizeY;
double x2 = x0 + hotspotSizeX;
double y2 = y0 - hotspotSizeY;
RectangleEdge xEdge = RectangleEdge.BOTTOM;
RectangleEdge yEdge = RectangleEdge.LEFT;
// Switch everything for horizontal charts
if (xyPlot.getOrientation() == PlotOrientation.HORIZONTAL) {
hotspotSizeX = hotspontsize * this.getScaleY();
hotspotSizeY = hotspontsize * this.getScaleX();
x0 = point.getY();
y0 = point.getX();
x1 = x0 + hotspotSizeX;
y1 = y0 - hotspotSizeY;
x2 = x0 - hotspotSizeX;
y2 = y0 + hotspotSizeY;
xEdge = RectangleEdge.LEFT;
yEdge = RectangleEdge.BOTTOM;
}
// OK, here we have to get ourselves back into AWT land...
Rectangle2D r2d = new Rectangle2D.Double();
r2d.setRect(screenArea.x, screenArea.y, screenArea.width, screenArea.height);
double ty0 = rangeAxis.java2DToValue(y0, r2d, yEdge);
double tx1 = domainAxis.java2DToValue(x1, r2d, xEdge);
double ty1 = rangeAxis.java2DToValue(y1, r2d, yEdge);
double tx2 = domainAxis.java2DToValue(x2, r2d, xEdge);
double ty2 = rangeAxis.java2DToValue(y2, r2d, yEdge);
int datasetCount = xyPlot.getDatasetCount();
for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) {
XYDataset dataset = xyPlot.getDataset(datasetIndex);
int seriesCount = dataset.getSeriesCount();
for (int series = 0; series < seriesCount; series++) {
int itemCount = dataset.getItemCount(series);
if (dataset instanceof OHLCDataset) {
// This could be optimized to use a binary search for x first
for (int item = 0; item < itemCount; item++) {
double xValue = dataset.getXValue(series, item);
double yValueHi = ((OHLCDataset) dataset).getHighValue(series, item);
double yValueLo = ((OHLCDataset) dataset).getLowValue(series, item);
// Check hi lo and swap if needed
if (yValueHi < yValueLo) {
double temp = yValueHi;
yValueHi = yValueLo;
yValueLo = temp;
}
// Check if the dataset 'X' value lies between the hotspot (tx1 < xValue < tx2)
if (tx1 < xValue && xValue < tx2) {
// Check if the cursor 'y' value lies between the high and low (low < ty0 < high)
if (yValueLo < ty0 && ty0 < yValueHi) {
return hiLoTips.generateToolTip(dataset, series, item);
}
}
}
} else {
// This could be optimized to use a binary search for x first
for (int item = 0; item < itemCount; item++) {
double xValue = dataset.getXValue(series, item);
double yValue = dataset.getYValue(series, item);
// Check if the dataset 'X' value lies between the hotspot (tx1< xValue < tx2)
if (tx1 < xValue && xValue < tx2) {
// Check if the dataset 'Y' value lies between the hotspot (ty1 < yValue < ty2)
if (ty1 < yValue && yValue < ty2) {
return xyTips.generateToolTip(dataset, series, item);
}
}
}
}
}
}
}
return result;
}
use of org.jfree.chart.axis.ValueAxis in project evosuite by EvoSuite.
the class Plot method createGraph.
@Override
protected JFreeChart createGraph() {
final JFreeChart chart = ChartFactory.createLineChart(null, "Build Number #", this.yLabel, this.dataset, PlotOrientation.VERTICAL, true, true, true);
chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
CategoryAxis domainAxis = new CategoryAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.setCategoryMargin(0.0);
plot.setDomainAxis(domainAxis);
plot.setBackgroundPaint(Color.WHITE);
ValueAxis yAxis = plot.getRangeAxis();
yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// yAxis.setRange(0.0, 100.0);
URLAndTooltipRenderer urlRenderer = new URLAndTooltipRenderer(this.project.getProject());
ColorPalette.apply(urlRenderer);
plot.setRenderer(urlRenderer);
return chart;
}
Aggregations