Git Product home page Git Product logo

jcommon's People

Contributors

barney2k7 avatar jfree avatar sebkur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jcommon's Issues

Hybrid bar/scatter chart

Hi, thanks for the chart component and associated jcommon library!

I have a question/possible addition. I am trying to create a specialised form of scatter chart, where one of the series represents the variation in load along a linear distance (e.g. variation of mass at different points on a bridge). I want to show that load series as bars - in effect, a bar graph but with real x-values instead of just categories. The x-axis therefore is distance, the y-axis is mass.

My approach (which may not be the right one anyway) was to try to override getItemShape thus:

xyPlot.setRenderer(new XYLineAndShapeRenderer(false, true)
{
  @Override
  public Shape getItemShape(int aSeries, int anItem)
  {
    Shape itemShape = super.getItemShape(aSeries, anItem);
    String seriesName = xyDataset.getSeriesKey(aSeries).toString();
    if (seriesName.equalsIgnoreCase("Load")
    {
      double x = xyDataset.getXValue(aSeries,anItem);
      double y = xyDataset.getYValue(aSeries,anItem);
      //NEW SHAPE HERE
    }
    return itemShape;
  }
});

For the new shape, I have tried using:

itemShape = ShapeUtilities.createLineRegion(new Line2D.Double(x,y,x,0),barWidth);

However, this seems to have some sort of x-scaling issue; the bars drift further and further from where they should be the further to the right you go. Furthermore, the heights of the bars aren't correct - I think there must be some sort of scaling factor to be applied?

I then tried adding my own shape, by adding this code in ShapeUtilities:

/**
 * Creates a vertical bar
 *
 * @param y  the height of the bar (usually this is the y value of the point)
 * @param w  the width of the bar.
 *
 * @return A bar shape.
 */
public static Shape createBar(double y, float w)
{
  GeneralPath p0 = new GeneralPath();
  p0.moveTo(-w/2, 0);
  p0.lineTo(w/2, 0);
  p0.lineTo(w/2, y);
  p0.lineTo(-w/2, y);
  p0.closePath();
  return p0;
}

I used it thus:

itemShape = ShapeUtilities.createBar(y, barWidth);

However, again, there seems to be some sort of scaling/transformation I need to do to get the desired result.

In summary, is there any simple way of achieving what I want? And am I nearly there with what I've got so far, just can't see the scaling function I need to perform?

Thanks!

EDIT:
I've also tried:

itemShape = new Rectangle2D.Double(-barWidth/2.0F,0,barWidth/2.0F,y);

This gets the rectangles in the correct x-location, and the top of each one is at the correct y-location. But the bottom does not drop all the way down to the x-axis. So I'm nearly there - just need to know how to scale from dataset y-values to chart y-values... (if that's the case, I probably won't be needing to submit a pull request for a createBar in ShapeUtilities - though it still might be useful to someone!)

EDIT2:
I've now also tried:

ValueAxis yAxis = xyPlot.getRangeAxis();
RectangleEdge yAxisEdge = xyPlot.getRangeAxisEdge();
Rectangle2D area = chartPanel.getChartRenderingInfo().getPlotInfo().getPlotArea();
double plotY = yAxis.valueToJava2D(y, area, yAxisEdge);
itemShape = new Rectangle2D.Double(-barWidth,0,barWidth,plotY);

However, although this may well work in some cases, it doesn't work when used inside an overridden GetItemShape, because at that point the chartPanel is not yet visible, so doesn't yet have an area!

So, I created a completely separate renderer:

  private XYLineAndShapeRenderer myXYLineAndShapeRenderer = new XYLineAndShapeRenderer(false,true)
  {
    @Override
    public Shape getItemShape(int aSeries, int anItem)
    {
      //STUFF IN HERE
    }
  };

along with

xyPlot.setRenderer(myXYLineAndShapeRenderer);

...in the chart creation code, hoping that the new renderer would get called when the chart gets painted. But it doesn't - it seems an overridden renderer only gets called if it's added directly using xyPlot.setRenderer(new XYLineAndShapeRenderer(false, true){...} as per the first block of code I showed. And then only if it doesn't need to access chartPanel!

TextUtilities#drawRotatedString(...) is not using argument textX

from https://sourceforge.net/p/jfreechart/bugs/1142/

"In org.jfree.text.TextUtilites I found in the method "public static void drawRotatedString(String text, Graphics2d g2, float textX, float textY, double angle, float rotateX, float rotateY)" a bug:

in the code fragment

if (angle == 0.0) {
    drawAlignedString(text, g2, textY, textY, TextAnchor.BASELINE_LEFT);
    return;
}

Should the method not called like this (textX was not used):
drawAlignedString(text, g2, textX, textY, TextAnchor.BASELINE_LEFT);"

stringToMonthCode bug and general question

I found this library by reading the "Clean Code" book which has a chapter on refactoring SerialDate class.

Were those changes rejected because of being backward incompatible or for some other reason?

What about small bug fixes which the book highlighted, like in stringToMonthCode() which does not return -1 for the cases when the input is a string with a number, i.e. "12345" (it simply returns the parsed number, i.e. 12345 in this case).

VerticalLayout minimum+preferredLayoutSize insets are added twice

both methods starts with declaring width and height as follows

        int height = ins.top + ins.bottom;
        int width = ins.left + ins.right;

and adding the insets again in the return statement

        return new Dimension(width + ins.left + ins.right,
            height + ins.top + ins.bottom);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.