How to determine the bounds of plot area of a JavaFX XYChart - java

I want to get the bounds (i.e. Bounds) of the XYChart plot area, which I define as the area contained within the axes of the plot (i.e. the axes form two legs of a rectangle). The ultimate purpose is to constrain a rubber band rectangle on the plot area. I started with this example and added in the constraint.
Based on the comments from James_D and kleopatra, I created a MVCE. I think the MVCE works remarkably well and compiles without warnings. More importantly, kleopatra's comment led to finding the bug when using the chart-plot-background method. The MVCE implements both methods. The chart-plot-background works for both ValueAxis and CategoryAxis. The axis method currently only works for ValueAxis.
Is using the bounds of .chart-plot-background a reliable method for determining the plot area or is using the value bounds of each axis more reliable? The axis approach definitely has more steps and more code.
Other options
I looked at the JavaFX source and plotArea looked promising but it isn't accessible.
The plotContent member is accessible via lookup(".plot-content") but groups all the data points, some of which may be outside the range set in the axes. Thus, the bounds of plotContent can be larger than the plot area bounds.

Related

How to draw the area around a shape

I worked on a very simple map editor phase for a game in java. The goal is to put some islands with different shape on the map. But there is some constraints:
islands must not be a specific distance far from another island (lets call it L)
islands must not be a specific distance close from another island (lets call it S)
In the game, the island is place with the mouse. The gamer can see areas where the island can be place or not as you can see.
My problem is that I realize my disalow area is not good. For example, the rectangle island have a rectangle disallow area (my first naive attempt) but in fact I must draw area of S around the rectangle ; that leads to a shape like this:
I'm able to draw these kind of areas as long as my shapes are just composed of lines. But my island can have cubic or quadratic curve (and even though i'll need this kind of area for other shapes later).
The closer I manage to do is that:
In this case, the disallow area around the circle must be ... a circle (simple geometry). But as you can see, I have a weird rounded rectangle.
I currently try to transform each segment of the pathiterator of a Shape to get the area. It's not as simple as scaling a shape (remember the rectangle case). I've allready try many ways to transform the shape and get the area.
Question:
Does someone have information, formula, clues, algorithms, libs to get this area from any java.awt.Shape (or PathIterator) and a distance?
http://www.java2s.com/example/java/java.lang/expand-or-shrink-a-shape-in-all-directions-by-a-defined-offset.html
This site describe how to use stroke to get the offset area.
There is just a single modification to solve my problem ; I have to use BasicStroke.JOIN_ROUND to get the good rectangular Shape.
Then I get:

Scatter plot with Jzy3d

I am using Jsy3d to draw a 3d scatter plot in Java. However, I noticed that the drawing order of the points seems to be based on the order of the given List of Points, not on the distance to the camera. Is there a way to fix this?
You are right, rendering is based on point declaration. Why would you change this?
To change the scatter rendering, simply override Scatter.draw(...)
You may use Camera.getDistance(coord) to get the distance to Camera. This method is already used by BarycenterOrderingStrategy in Graph to order the drawables (but this won't work for your scatter as it is a primitive Drawable).

Bar Graph in jFreeChart w bars all start from a specific range

Is it possible to generate a bar graph in jFreeChart where bars all start around a particular value instead of the zero axis? Our team has interest in this view.
Here is an example where the default behavior has the bars all between the value and the origin. We want the bars to be between the value and the mean (average).
I suppose a workaround is we calculate the offset from the mean and plot them in respect to the origin and then hide the axis but then we are not able to show the axis to our users.
Instead of having bar graphs stop at another value besides the origin we are just redefining the graph axis origin to be at the mean and offsetting everything. So instead of something like exposure level we now call the value axis distance from aggregate mean. Not exactly what I was originally looking in the OP but a cleaner solution overall. We'll let the user toggle between the two modes.

JFreeChart grid base axis

I'm using JFreeChart 1.0.14 in Swing application.
I have chart with multiple Y-Axis and I want to change source Axis for chart grid lines. Now them always base on one axis, even if I hide it.
I know there are few similar questions but they are old and I wonder if solution exists now.
If it doesn't what is the best workaround in this task?
For example:
http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=27885&sid=c4c609f3809d29a46e3e2bbccfac361e
There is still no way to do it natively unfortunately.
I was suggested to override XYPlot's drawRangeGridLines method, but I decided to go another way: to make it works you only need to change axis order because grid lines always depend on 0th axis (and its dataset). Make sure your axis has 0th index in plot axis collection.
NumberAxis axis = new NumberAxis(name);
plot.setRangeAxis(0, axis);
I think it's easiest way at this moment.

JFreeChart Crosshair on a combined plot

I'm using a combined plot composed of 2 graph which share the same X axis (by sharing, I mean, the timeframe is the same for the two graph). The upper graph is a regular timeseries while the lower chart is a barchart. I would like to display a crosshair on the combined chart as a whole... Right now I can display crosshair only on each graph separately even thought I have specify on the combined plot that I wanted to display the crosshair. To be more explicit, I can't synchronise both crosshair... Any idea on how to achieve that ?
thanks
It would appear to work if you use a shared domain axis, as discussed here and as shown in CrosshairDemo2? In addition, an sscce might help clarify your usage.

Categories

Resources