Search in sources :

Example 1 with EqualDashStroke

use of org.cytoscape.ding.impl.strokes.EqualDashStroke in project cytoscape-impl by cytoscape.

the class LineLayer method createChart.

@Override
protected JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createLineChart(// chart title
    null, // domain axis label
    null, // range axis label
    null, // data
    dataset, PlotOrientation.VERTICAL, // include legend
    false, // tooltips
    false, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(TRANSPARENT_COLOR);
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setBackgroundPaint(TRANSPARENT_COLOR);
    plot.setBackgroundAlpha(0.0f);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    if (showRangeZeroBaseline) {
        plot.setRangeZeroBaselineVisible(true);
        plot.setRangeZeroBaselinePaint(axisColor);
        plot.setRangeZeroBaselineStroke(new EqualDashStroke(axisWidth));
    }
    final BasicStroke axisStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    final BasicStroke gridLineStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.5f, new float[] { 0.5f }, 0.0f);
    plot.setRangeGridlineStroke(gridLineStroke);
    final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setVisible(showDomainAxis);
    domainAxis.setAxisLineStroke(axisStroke);
    domainAxis.setAxisLinePaint(axisColor);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setTickMarkStroke(axisStroke);
    domainAxis.setTickMarkPaint(axisColor);
    domainAxis.setTickLabelsVisible(true);
    domainAxis.setTickLabelFont(domainAxis.getTickLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
    domainAxis.setTickLabelPaint(axisColor);
    domainAxis.setCategoryLabelPositions(getCategoryLabelPosition());
    domainAxis.setCategoryMargin(.1);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(showRangeAxis);
    rangeAxis.setAxisLineStroke(axisStroke);
    rangeAxis.setAxisLinePaint(axisColor);
    rangeAxis.setTickMarkStroke(axisStroke);
    rangeAxis.setTickMarkPaint(axisColor);
    rangeAxis.setTickLabelFont(rangeAxis.getLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
    rangeAxis.setTickLabelPaint(axisColor);
    rangeAxis.setLowerMargin(0.0);
    rangeAxis.setUpperMargin(0.0);
    // Set axis range
    if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
        rangeAxis.setLowerBound(range.get(0) * 1.1);
        rangeAxis.setUpperBound(range.get(1) * 1.1);
    }
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseItemLabelGenerator(showItemLabels ? new CustomCategoryItemLabelGenerator(itemLabels) : null);
    renderer.setBaseItemLabelsVisible(showItemLabels);
    renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(itemFontSize));
    renderer.setBaseItemLabelPaint(labelColor);
    final BasicStroke seriesStroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    final List<?> keys = dataset.getRowKeys();
    if (colors != null && colors.size() >= keys.size()) {
        for (int i = 0; i < keys.size(); i++) {
            final Color c = colors.get(i);
            renderer.setSeriesPaint(i, c);
            renderer.setSeriesStroke(i, seriesStroke);
        }
    }
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Color(java.awt.Color) CustomCategoryItemLabelGenerator(org.cytoscape.ding.internal.charts.CustomCategoryItemLabelGenerator) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) EqualDashStroke(org.cytoscape.ding.impl.strokes.EqualDashStroke)

Example 2 with EqualDashStroke

use of org.cytoscape.ding.impl.strokes.EqualDashStroke in project cytoscape-impl by cytoscape.

the class BoxLayer method createChart.

@Override
protected JFreeChart createChart(final BoxAndWhiskerCategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(// chart title
    null, // domain axis label
    null, // range axis label
    null, // data
    dataset, // include legend
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(TRANSPARENT_COLOR);
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setBackgroundPaint(TRANSPARENT_COLOR);
    plot.setBackgroundAlpha(0.0f);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    if (showRangeZeroBaseline) {
        plot.setRangeZeroBaselineVisible(true);
        plot.setRangeZeroBaselinePaint(axisColor);
        plot.setRangeZeroBaselineStroke(new EqualDashStroke(axisWidth));
    }
    final PlotOrientation plotOrientation = orientation == Orientation.HORIZONTAL ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL;
    plot.setOrientation(plotOrientation);
    final BasicStroke axisStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setVisible(showDomainAxis);
    domainAxis.setAxisLineStroke(axisStroke);
    domainAxis.setAxisLinePaint(axisColor);
    domainAxis.setTickMarksVisible(false);
    domainAxis.setTickMarkStroke(axisStroke);
    domainAxis.setTickMarkPaint(axisColor);
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setCategoryMargin(.1);
    domainAxis.setLowerMargin(.025);
    domainAxis.setUpperMargin(.025);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(showRangeAxis);
    rangeAxis.setAxisLineStroke(axisStroke);
    rangeAxis.setAxisLinePaint(axisColor);
    rangeAxis.setTickMarkStroke(axisStroke);
    rangeAxis.setTickMarkPaint(axisColor);
    rangeAxis.setTickLabelFont(rangeAxis.getLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
    rangeAxis.setTickLabelPaint(axisColor);
    rangeAxis.setLowerMargin(0.1);
    rangeAxis.setUpperMargin(0.1);
    // Set axis range
    if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
        rangeAxis.setLowerBound(range.get(0));
        rangeAxis.setUpperBound(range.get(1));
    }
    final BoxAndWhiskerRenderer renderer = (BoxAndWhiskerRenderer) plot.getRenderer();
    renderer.setFillBox(true);
    renderer.setMeanVisible(false);
    // Box chart does not support item labels, anyway
    renderer.setBaseItemLabelsVisible(false);
    final BasicStroke stroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    final List<?> keys = dataset.getRowKeys();
    for (int i = 0; i < keys.size(); i++) {
        renderer.setSeriesStroke(i, stroke);
        renderer.setSeriesOutlineStroke(i, stroke);
        renderer.setSeriesOutlinePaint(i, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
        if (colors != null && colors.size() >= keys.size())
            renderer.setSeriesPaint(i, colors.get(i));
    }
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) BoxAndWhiskerRenderer(org.jfree.chart.renderer.category.BoxAndWhiskerRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) EqualDashStroke(org.cytoscape.ding.impl.strokes.EqualDashStroke)

Example 3 with EqualDashStroke

use of org.cytoscape.ding.impl.strokes.EqualDashStroke in project cytoscape-impl by cytoscape.

the class BarLayer method createChart.

@Override
protected JFreeChart createChart(final CategoryDataset dataset) {
    final PlotOrientation plotOrientation = orientation == Orientation.HORIZONTAL ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL;
    final JFreeChart chart;
    if (type == BarChartType.STACKED)
        chart = ChartFactory.createStackedBarChart(// chart title
        null, // domain axis label
        null, // range axis label
        null, // data
        dataset, plotOrientation, // include legend
        false, // tooltips
        false, // urls
        false);
    else
        chart = ChartFactory.createBarChart(// chart title
        null, // domain axis label
        null, // range axis label
        null, // data
        dataset, plotOrientation, // include legend
        false, // tooltips
        false, // urls
        false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(TRANSPARENT_COLOR);
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setBackgroundPaint(TRANSPARENT_COLOR);
    plot.setBackgroundAlpha(0.0f);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    if (showRangeZeroBaseline) {
        plot.setRangeZeroBaselineVisible(true);
        plot.setRangeZeroBaselinePaint(axisColor);
        plot.setRangeZeroBaselineStroke(new EqualDashStroke(axisWidth));
    }
    final BasicStroke axisStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setVisible(showDomainAxis);
    domainAxis.setAxisLineStroke(axisStroke);
    domainAxis.setAxisLinePaint(axisColor);
    domainAxis.setTickMarkStroke(axisStroke);
    domainAxis.setTickMarkPaint(axisColor);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setTickLabelsVisible(true);
    domainAxis.setTickLabelFont(domainAxis.getTickLabelFont().deriveFont(axisFontSize));
    domainAxis.setTickLabelPaint(axisColor);
    domainAxis.setCategoryLabelPositions(getCategoryLabelPosition());
    domainAxis.setCategoryMargin((type == BarChartType.STACKED || singleCategory) ? separation : 0.1);
    domainAxis.setLowerMargin(.025);
    domainAxis.setUpperMargin(.025);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(showRangeAxis);
    rangeAxis.setAxisLineStroke(axisStroke);
    rangeAxis.setAxisLinePaint(axisColor);
    rangeAxis.setTickMarkStroke(axisStroke);
    rangeAxis.setTickMarkPaint(axisColor);
    rangeAxis.setTickLabelFont(rangeAxis.getLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
    rangeAxis.setTickLabelPaint(axisColor);
    rangeAxis.setLowerMargin(0.1);
    rangeAxis.setUpperMargin(0.1);
    // Set axis range
    if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
        rangeAxis.setLowerBound(range.get(0));
        rangeAxis.setUpperBound(range.get(1));
    }
    if (type != BarChartType.STACKED) {
        if (type == BarChartType.HEAT_STRIPS || type == BarChartType.UP_DOWN) {
            final Color up = (colors.size() > 0) ? colors.get(0) : Color.LIGHT_GRAY;
            final Color zero = (colors.size() > 2) ? colors.get(1) : Color.BLACK;
            final Color down = (colors.size() > 2) ? colors.get(2) : (colors.size() > 1 ? colors.get(1) : Color.GRAY);
            plot.setRenderer(new UpDownColorBarRenderer(up, zero, down));
        } else if (singleCategory) {
            plot.setRenderer(new SingleCategoryRenderer());
        }
    }
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setDrawBarOutline(true);
    renderer.setBaseItemLabelGenerator(showItemLabels ? new CustomCategoryItemLabelGenerator(itemLabels) : null);
    renderer.setBaseItemLabelsVisible(showItemLabels);
    renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(itemFontSize));
    renderer.setBaseItemLabelPaint(labelColor);
    renderer.setItemMargin(separation);
    if (type != BarChartType.STACKED && showItemLabels) {
        double angle = orientation == Orientation.HORIZONTAL ? 0 : -Math.PI / 2;
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, angle));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, angle));
    }
    final BasicStroke borderStroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    final List<?> keys = dataset.getRowKeys();
    for (int i = 0; i < keys.size(); i++) {
        renderer.setSeriesOutlineStroke(i, borderStroke);
        renderer.setSeriesOutlinePaint(i, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
        if (type != BarChartType.UP_DOWN && type != BarChartType.HEAT_STRIPS) {
            Color c = DEFAULT_ITEM_BG_COLOR;
            if (colors != null && colors.size() > i)
                c = colors.get(i);
            renderer.setSeriesPaint(i, c);
        }
    }
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) CustomCategoryItemLabelGenerator(org.cytoscape.ding.internal.charts.CustomCategoryItemLabelGenerator) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) EqualDashStroke(org.cytoscape.ding.impl.strokes.EqualDashStroke) Paint(java.awt.Paint) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) RectangleInsets(org.jfree.ui.RectangleInsets) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition)

Aggregations

BasicStroke (java.awt.BasicStroke)3 EqualDashStroke (org.cytoscape.ding.impl.strokes.EqualDashStroke)3 JFreeChart (org.jfree.chart.JFreeChart)3 CategoryAxis (org.jfree.chart.axis.CategoryAxis)3 NumberAxis (org.jfree.chart.axis.NumberAxis)3 CategoryPlot (org.jfree.chart.plot.CategoryPlot)3 RectangleInsets (org.jfree.ui.RectangleInsets)3 Color (java.awt.Color)2 CustomCategoryItemLabelGenerator (org.cytoscape.ding.internal.charts.CustomCategoryItemLabelGenerator)2 PlotOrientation (org.jfree.chart.plot.PlotOrientation)2 Paint (java.awt.Paint)1 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)1 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)1 BoxAndWhiskerRenderer (org.jfree.chart.renderer.category.BoxAndWhiskerRenderer)1 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)1 StandardBarPainter (org.jfree.chart.renderer.category.StandardBarPainter)1