CombinedDomainXYPlot和CombinedRangeXYPlot如何与子图共享轴信息 [英] How CombinedDomainXYPlot and CombinedRangeXYPlot share Axis information with subplots

查看:76
本文介绍了CombinedDomainXYPlot和CombinedRangeXYPlot如何与子图共享轴信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关于:


注意-我本来是将它写成一个问题,然后才意识到自己的错误,所以我决定只分享知识,因为我已经输入了所有内容.

Note - I originally wrote this up as a question, and then realize my mistake, so I decided to just share the knowledge since I already had this all typed out.

在JFreeChart中,有两种绘图类型共享一个轴范围并仅绘制一个轴,同时与子图共享该信息.它们是 CombinedDomainXYPlot CombinedRangeXYPlot .我将重点放在 CombinedDomainXyPlot 上,但是出于这个问题的目的,其他应该相同.查看抽奖代码,我们看到:

In JFreeChart, there are two plot types that share an axis range and draw only one axis, while sharing that information with their subplots. These are CombinedDomainXYPlot and CombinedRangeXYPlot. I will focus on CombinedDomainXyPlot, but the other should be identical for the purposes of this question. Looking at the draw code we see:

  ...
  setFixedRangeAxisSpaceForSubplots(null);
  AxisSpace space = calculateAxisSpace(g2, area);
  Rectangle2D dataArea = space.shrink(area, null);

  // set the width and height of non-shared axis of all sub-plots
  setFixedRangeAxisSpaceForSubplots(space);

  // draw the shared axis
  ValueAxis axis = getDomainAxis();
  RectangleEdge edge = getDomainAxisEdge();
  double cursor = RectangleEdge.coordinate(dataArea, edge);
  AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info); // <- draw the share axis
  if (parentState == null) {
    parentState = new PlotState();
  }
  parentState.getSharedAxisStates().put(axis, axisState); // <- put the state of the shared axis in a shared object

  // draw all the subplots
  for (int i = 0; i < this.subplots.size(); i++) {
    XYPlot plot = (XYPlot) this.subplots.get(i);
    PlotRenderingInfo subplotInfo = null;
    if (info != null) {
      subplotInfo = new PlotRenderingInfo(info.getOwner());
      info.addSubplotInfo(subplotInfo);
    }
    plot.draw(g2, this.subplotAreas[i], anchor, parentState, subplotInfo); // <- pass this shared object to the subplot draw function.
  }
  ...

在子图(XYPlot)绘制方法中,我们看到:

in the subplot (XYPlot) draw method, we see:

  domainAxisState = (AxisState) parentState.getSharedAxisStates().get(getDomainAxis());

getDomainAxis()方法被调用 getDomainAxis(0),即:

public ValueAxis getDomainAxis(int index) {
    ValueAxis result = null;
    if (index < this.domainAxes.size()) {
      result = (ValueAxis) this.domainAxes.get(index); //<- try to find this domain axis in self
    }
    if (result == null) { //<- if not found in self ...
      Plot parent = getParent();
      if (parent instanceof XYPlot) {
        XYPlot xy = (XYPlot) parent;
        result = xy.getDomainAxis(index); //<- ...try to get from parent
      }
    }
    return result;
}

此处, parent CombinedDomainXYPlot .这将从 CombinedDomainXYPlot 返回对domainAxis的引用,该引用用于从 parentState 对象中检索 axisState .似乎 getDomainAxis()方法并不用于获取要绘制的轴,仅用于获取对它的引用以用于其他目的.

Here, parent is the CombinedDomainXYPlot. This will return a reference to the domainAxis from CombinedDomainXYPlot, to be used for retrieving the axisState from the parentState object. It seems the getDomainAxis() method is not used for getting an axis to draw, only for getting a reference to it for other purposes.

之所以研究这个问题,是因为我试图使用相同的技术将多个共享轴传递给多个不同的图组,但只绘制一次.这项技术似乎有效,但是现在存在一些故障,因为放大仅获取状态信息的图并不会更新具有轴的主图.

I was looking into this because I was trying to use the same technique to pass multiple shared axes to multiple different groups of plots, but only draw them once. This technique seems to work, but there are glitches right now in that zooming the plots that only get state information does not update the main plot that has the axis... Working on it, but hopefully this information is useful to someone down the line.

谢谢

伊戈尔

推荐答案

有问题的帖子

与上面的状态一样, XYPlot 中的 getDomainAxis()方法显然不用于绘制轴,而只是出于其他目的获得对其的引用.因此,如果您重写此方法以链接到另一个轴并将其状态信息放入共享对象中,则该状态信息将在绘图之间共享.

As state above, the getDomainAxis() method in XYPlot is apparently not used for getting an axis to draw, only for getting a reference to it for other purposes. So if you override this method to link to another axis and put it's state information into a shared object, this state info will be shared between plots.

这篇关于CombinedDomainXYPlot和CombinedRangeXYPlot如何与子图共享轴信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆