615 if(xData != null) xa.invalidateRange(xData); 616 if(yData != null) ya.invalidateRange(yData); 617 } 618 } 619 620 /** 621 * Called to update and layout the plot children. This should include all work to updates nodes representing 622 * the plot on top of the axis and grid lines etc. The origin is the top left of the plot area, the plot area with 623 * can be got by getting the width of the x axis and its height from the height of the y axis. 624 */ 625 protected abstract void layoutPlotChildren(); 626 627 /** @inheritDoc */ 628 @Override protected final void layoutChartChildren(double top, double left, double width, double height) { 629 if(getData() == null) return; 630 if (!rangeValid) { 631 rangeValid = true; 632 if(getData() != null) updateAxisRange(); 633 } 634 // snap top and left to pixels 635 top = snapPosition(top); 636 left = snapPosition(left); 637 // get starting stuff 638 final Axis<X> xa = getXAxis(); 639 final ObservableList<Axis.TickMark<X>> xaTickMarks = xa.getTickMarks(); 640 final Axis<Y> ya = getYAxis(); 641 final ObservableList<Axis.TickMark<Y>> yaTickMarks = ya.getTickMarks(); 642 // check we have 2 axises and know their sides 643 if (xa == null || ya == null) return; 644 // try and work out width and height of axises 645 double xAxisWidth = 0; 646 double xAxisHeight = 30; // guess x axis height to start with 647 double yAxisWidth = 0; 648 double yAxisHeight = 0; 649 for (int count=0; count<5; count ++) { 650 yAxisHeight = snapSize(height - xAxisHeight); 651 if (yAxisHeight < 0) { 652 yAxisHeight = 0; 653 } 654 yAxisWidth = ya.prefWidth(yAxisHeight); 655 xAxisWidth = snapSize(width - yAxisWidth); 656 if (xAxisWidth < 0) { 657 xAxisWidth = 0; 658 } 659 double newXAxisHeight = xa.prefHeight(xAxisWidth); 660 if (newXAxisHeight == xAxisHeight) break; 661 xAxisHeight = newXAxisHeight; 662 } 663 // round axis sizes up to whole integers to snap to pixel 664 xAxisWidth = Math.ceil(xAxisWidth); 665 xAxisHeight = Math.ceil(xAxisHeight); 666 yAxisWidth = Math.ceil(yAxisWidth); 667 yAxisHeight = Math.ceil(yAxisHeight); 668 // calc xAxis height 669 double xAxisY = 0; 670 switch(xa.getEffectiveSide()) { 671 case TOP: 672 xa.setVisible(true); 673 xAxisY = top+1; 674 top += xAxisHeight; 675 break; | 615 if(xData != null) xa.invalidateRange(xData); 616 if(yData != null) ya.invalidateRange(yData); 617 } 618 } 619 620 /** 621 * Called to update and layout the plot children. This should include all work to updates nodes representing 622 * the plot on top of the axis and grid lines etc. The origin is the top left of the plot area, the plot area with 623 * can be got by getting the width of the x axis and its height from the height of the y axis. 624 */ 625 protected abstract void layoutPlotChildren(); 626 627 /** @inheritDoc */ 628 @Override protected final void layoutChartChildren(double top, double left, double width, double height) { 629 if(getData() == null) return; 630 if (!rangeValid) { 631 rangeValid = true; 632 if(getData() != null) updateAxisRange(); 633 } 634 // snap top and left to pixels 635 top = snapPositionY(top); 636 left = snapPositionX(left); 637 // get starting stuff 638 final Axis<X> xa = getXAxis(); 639 final ObservableList<Axis.TickMark<X>> xaTickMarks = xa.getTickMarks(); 640 final Axis<Y> ya = getYAxis(); 641 final ObservableList<Axis.TickMark<Y>> yaTickMarks = ya.getTickMarks(); 642 // check we have 2 axises and know their sides 643 if (xa == null || ya == null) return; 644 // try and work out width and height of axises 645 double xAxisWidth = 0; 646 double xAxisHeight = 30; // guess x axis height to start with 647 double yAxisWidth = 0; 648 double yAxisHeight = 0; 649 for (int count=0; count<5; count ++) { 650 yAxisHeight = snapSizeY(height - xAxisHeight); 651 if (yAxisHeight < 0) { 652 yAxisHeight = 0; 653 } 654 yAxisWidth = ya.prefWidth(yAxisHeight); 655 xAxisWidth = snapSizeX(width - yAxisWidth); 656 if (xAxisWidth < 0) { 657 xAxisWidth = 0; 658 } 659 double newXAxisHeight = xa.prefHeight(xAxisWidth); 660 if (newXAxisHeight == xAxisHeight) break; 661 xAxisHeight = newXAxisHeight; 662 } 663 // round axis sizes up to whole integers to snap to pixel 664 xAxisWidth = Math.ceil(xAxisWidth); 665 xAxisHeight = Math.ceil(xAxisHeight); 666 yAxisWidth = Math.ceil(yAxisWidth); 667 yAxisHeight = Math.ceil(yAxisHeight); 668 // calc xAxis height 669 double xAxisY = 0; 670 switch(xa.getEffectiveSide()) { 671 case TOP: 672 xa.setVisible(true); 673 xAxisY = top+1; 674 top += xAxisHeight; 675 break; |