use of org.jfree.chart.urls.XYURLGenerator in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ChartFactory method createTimeSeriesChart.
/**
* Creates and returns a time series chart. A time series chart is an
* {@link XYPlot} with a {@link DateAxis} for the x-axis and a
* {@link NumberAxis} for the y-axis. The default renderer is an
* {@link XYLineAndShapeRenderer}.
* <P>
* A convenient dataset to use with this chart is a
* {@link org.jfree.data.time.TimeSeriesCollection}.
*
* @param title the chart title ({@code null} permitted).
* @param timeAxisLabel a label for the time axis ({@code null}
* permitted).
* @param valueAxisLabel a label for the value axis ({@code null}
* permitted).
* @param dataset the dataset for the chart ({@code null} permitted).
* @param legend a flag specifying whether or not a legend is required.
* @param tooltips configure chart to generate tool tips?
* @param urls configure chart to generate URLs?
*
* @return A time series chart.
*/
public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls) {
ValueAxis timeAxis = new DateAxis(timeAxisLabel);
// reduce the default margins
timeAxis.setLowerMargin(0.02);
timeAxis.setUpperMargin(0.02);
NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
// override default
valueAxis.setAutoRangeIncludesZero(false);
XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
XYToolTipGenerator toolTipGenerator = null;
if (tooltips) {
toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
}
XYURLGenerator urlGenerator = null;
if (urls) {
urlGenerator = new StandardXYURLGenerator();
}
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
renderer.setDefaultToolTipGenerator(toolTipGenerator);
renderer.setURLGenerator(urlGenerator);
plot.setRenderer(renderer);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
currentTheme.apply(chart);
return chart;
}
use of org.jfree.chart.urls.XYURLGenerator in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class XYDifferenceRenderer method drawItemPass1.
/**
* Draws the visual representation of a single data item, second pass. In
* the second pass, the renderer draws the lines and shapes for the
* individual points in the two series.
*
* @param x_graphics the graphics device.
* @param x_dataArea the area within which the data is being drawn.
* @param x_info collects information about the drawing.
* @param x_plot the plot (can be used to obtain standard color
* information etc).
* @param x_domainAxis the domain (horizontal) axis.
* @param x_rangeAxis the range (vertical) axis.
* @param x_dataset the dataset.
* @param x_series the series index (zero-based).
* @param x_item the item index (zero-based).
* @param x_crosshairState crosshair information for the plot
* ({@code null} permitted).
*/
protected void drawItemPass1(Graphics2D x_graphics, Rectangle2D x_dataArea, PlotRenderingInfo x_info, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, CrosshairState x_crosshairState) {
Shape l_entityArea = null;
EntityCollection l_entities = null;
if (null != x_info) {
l_entities = x_info.getOwner().getEntityCollection();
}
Paint l_seriesPaint = getItemPaint(x_series, x_item);
Stroke l_seriesStroke = getItemStroke(x_series, x_item);
x_graphics.setPaint(l_seriesPaint);
x_graphics.setStroke(l_seriesStroke);
PlotOrientation l_orientation = x_plot.getOrientation();
RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
double l_x0 = x_dataset.getXValue(x_series, x_item);
double l_y0 = x_dataset.getYValue(x_series, x_item);
double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea, l_domainAxisLocation);
double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea, l_rangeAxisLocation);
if (getShapesVisible()) {
Shape l_shape = getItemShape(x_series, x_item);
if (l_orientation == PlotOrientation.HORIZONTAL) {
l_shape = ShapeUtils.createTranslatedShape(l_shape, l_y1, l_x1);
} else {
l_shape = ShapeUtils.createTranslatedShape(l_shape, l_x1, l_y1);
}
if (l_shape.intersects(x_dataArea)) {
x_graphics.setPaint(getItemPaint(x_series, x_item));
x_graphics.fill(l_shape);
}
l_entityArea = l_shape;
}
// add an entity for the item...
if (null != l_entities) {
if (null == l_entityArea) {
l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2), 4, 4);
}
String l_tip = null;
XYToolTipGenerator l_tipGenerator = getToolTipGenerator(x_series, x_item);
if (null != l_tipGenerator) {
l_tip = l_tipGenerator.generateToolTip(x_dataset, x_series, x_item);
}
String l_url = null;
XYURLGenerator l_urlGenerator = getURLGenerator();
if (null != l_urlGenerator) {
l_url = l_urlGenerator.generateURL(x_dataset, x_series, x_item);
}
XYItemEntity l_entity = new XYItemEntity(l_entityArea, x_dataset, x_series, x_item, l_tip, l_url);
l_entities.add(l_entity);
}
// draw the item label if there is one...
if (isItemLabelVisible(x_series, x_item)) {
drawItemLabel(x_graphics, l_orientation, x_dataset, x_series, x_item, l_x1, l_y1, (l_y1 < 0.0));
}
int datasetIndex = x_plot.indexOf(x_dataset);
updateCrosshairValues(x_crosshairState, l_x0, l_y0, datasetIndex, l_x1, l_y1, l_orientation);
if (0 == x_item) {
return;
}
double l_x2 = x_domainAxis.valueToJava2D(x_dataset.getXValue(x_series, (x_item - 1)), x_dataArea, l_domainAxisLocation);
double l_y2 = x_rangeAxis.valueToJava2D(x_dataset.getYValue(x_series, (x_item - 1)), x_dataArea, l_rangeAxisLocation);
Line2D l_line = null;
if (PlotOrientation.HORIZONTAL == l_orientation) {
l_line = new Line2D.Double(l_y1, l_x1, l_y2, l_x2);
} else if (PlotOrientation.VERTICAL == l_orientation) {
l_line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2);
}
if ((null != l_line) && l_line.intersects(x_dataArea)) {
x_graphics.setPaint(getItemPaint(x_series, x_item));
x_graphics.setStroke(getItemStroke(x_series, x_item));
x_graphics.draw(l_line);
}
}
use of org.jfree.chart.urls.XYURLGenerator in project graphcode2vec by graphcode2vec.
the class XYDifferenceRenderer method drawItemPass1.
/**
* Draws the visual representation of a single data item, second pass. In
* the second pass, the renderer draws the lines and shapes for the
* individual points in the two series.
*
* @param x_graphics the graphics device.
* @param state the rendering state.
* @param x_dataArea the area within which the data is being drawn.
* @param x_plot the plot (can be used to obtain standard color
* information etc).
* @param x_domainAxis the domain (horizontal) axis.
* @param x_rangeAxis the range (vertical) axis.
* @param x_dataset the dataset.
* @param x_series the series index (zero-based).
* @param x_item the item index (zero-based).
* @param selected is the data item selected?
*
* @since 1.2.0
*/
protected void drawItemPass1(Graphics2D x_graphics, XYItemRendererState state, Rectangle2D x_dataArea, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, boolean selected) {
Shape l_entityArea = null;
EntityCollection l_entities = null;
if (state.getInfo() != null) {
l_entities = state.getInfo().getOwner().getEntityCollection();
}
Paint l_seriesPaint = getItemPaint(x_series, x_item, selected);
Stroke l_seriesStroke = getItemStroke(x_series, x_item, selected);
x_graphics.setPaint(l_seriesPaint);
x_graphics.setStroke(l_seriesStroke);
PlotOrientation l_orientation = x_plot.getOrientation();
RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
double l_x0 = x_dataset.getXValue(x_series, x_item);
double l_y0 = x_dataset.getYValue(x_series, x_item);
double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea, l_domainAxisLocation);
double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea, l_rangeAxisLocation);
if (getShapesVisible()) {
Shape l_shape = getItemShape(x_series, x_item, selected);
if (l_orientation == PlotOrientation.HORIZONTAL) {
l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_y1, l_x1);
} else {
l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_x1, l_y1);
}
if (l_shape.intersects(x_dataArea)) {
x_graphics.setPaint(getItemPaint(x_series, x_item, selected));
x_graphics.fill(l_shape);
}
l_entityArea = l_shape;
}
// add an entity for the item...
if (null != l_entities) {
if (null == l_entityArea) {
l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2), 4, 4);
}
String l_tip = null;
XYToolTipGenerator l_tipGenerator = getToolTipGenerator(x_series, x_item, selected);
if (null != l_tipGenerator) {
l_tip = l_tipGenerator.generateToolTip(x_dataset, x_series, x_item);
}
String l_url = null;
XYURLGenerator l_urlGenerator = getURLGenerator(x_series, x_item, selected);
if (null != l_urlGenerator) {
l_url = l_urlGenerator.generateURL(x_dataset, x_series, x_item);
}
XYItemEntity l_entity = new XYItemEntity(l_entityArea, x_dataset, x_series, x_item, l_tip, l_url);
l_entities.add(l_entity);
}
// draw the item label if there is one...
if (isItemLabelVisible(x_series, x_item, selected)) {
drawItemLabel(x_graphics, l_orientation, x_dataset, x_series, x_item, selected, l_x1, l_y1, (l_y1 < 0.0));
}
int l_domainAxisIndex = x_plot.getDomainAxisIndex(x_domainAxis);
int l_rangeAxisIndex = x_plot.getRangeAxisIndex(x_rangeAxis);
XYCrosshairState crosshairState = state.getCrosshairState();
updateCrosshairValues(crosshairState, l_x0, l_y0, l_domainAxisIndex, l_rangeAxisIndex, l_x1, l_y1, l_orientation);
if (0 == x_item) {
return;
}
double l_x2 = x_domainAxis.valueToJava2D(x_dataset.getXValue(x_series, (x_item - 1)), x_dataArea, l_domainAxisLocation);
double l_y2 = x_rangeAxis.valueToJava2D(x_dataset.getYValue(x_series, (x_item - 1)), x_dataArea, l_rangeAxisLocation);
Line2D l_line = null;
if (PlotOrientation.HORIZONTAL == l_orientation) {
l_line = new Line2D.Double(l_y1, l_x1, l_y2, l_x2);
} else if (PlotOrientation.VERTICAL == l_orientation) {
l_line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2);
}
if ((null != l_line) && l_line.intersects(x_dataArea)) {
x_graphics.setPaint(getItemPaint(x_series, x_item, selected));
x_graphics.setStroke(getItemStroke(x_series, x_item, selected));
x_graphics.draw(l_line);
}
}
Aggregations