comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2780:772d0c8100d3

Improved 'line-to-curve' rendering. flys-artifacts/trunk@4519 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 25 May 2012 13:34:46 +0000
parents 5543492f2da4
children 55f91fae8a7b
comparison
equal deleted inserted replaced
2779:e57816cf41d5 2780:772d0c8100d3
179 } // class AxisDataset 179 } // class AxisDataset
180 180
181 /** Enumerator over existing axes. */ 181 /** Enumerator over existing axes. */
182 protected abstract YAxisWalker getYAxisWalker(); 182 protected abstract YAxisWalker getYAxisWalker();
183 183
184 protected static float ANNOTATIONS_AXIS_OFFSET = 0.02f;
185
184 public static final int AXIS_SPACE = 5; 186 public static final int AXIS_SPACE = 5;
185 187
186 /** The logger that is used in this generator. */ 188 /** The logger that is used in this generator. */
187 private static Logger logger = Logger.getLogger(XYChartGenerator.class); 189 private static Logger logger = Logger.getLogger(XYChartGenerator.class);
188 190
708 logger.debug("Unknown zone type found."); 710 logger.debug("Unknown zone type found.");
709 return new Color(255, 0, 0); 711 return new Color(255, 0, 0);
710 } 712 }
711 } 713 }
712 714
715 protected static XYLineAnnotation createGroundStickAnnotation(
716 Area area, float pos, ThemeAccess.LineStyle lineStyle
717 ) {
718 // Style the line.
719 if (lineStyle != null) {
720 return new XYLineAnnotation(
721 pos, area.atGround(),
722 pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET),
723 new BasicStroke(lineStyle.getWidth()),lineStyle.getColor());
724 }
725 else {
726 return new XYLineAnnotation(
727 pos, area.atGround(),
728 pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET));
729 }
730 }
731
732
733 protected static XYLineAnnotation createRightStickAnnotation(
734 Area area, float pos, ThemeAccess.LineStyle lineStyle
735 ) {
736 // Style the line.
737 if (lineStyle != null) {
738 return new XYLineAnnotation(
739 area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos,
740 area.atRight(), pos,
741 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
742 }
743 else {
744 return new XYLineAnnotation(
745 area.atRight(), pos,
746 area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos);
747 }
748 }
749
750
751 protected static XYLineAnnotation createLeftStickAnnotation(
752 Area area, float pos, ThemeAccess.LineStyle lineStyle
753 ) {
754 // Style the line.
755 if (lineStyle != null) {
756 return new XYLineAnnotation(
757 area.atLeft(), pos,
758 area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos,
759 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
760 }
761 else {
762 return new XYLineAnnotation(
763 area.atLeft(), pos,
764 area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos);
765 }
766 }
713 767
714 /** 768 /**
715 * Add a text and a line annotation. 769 * Add a text and a line annotation.
716 * @param area convenience to determine positions in plot. 770 * @param area convenience to determine positions in plot.
717 */ 771 */
722 ThemeAccess.LineStyle lineStyle, 776 ThemeAccess.LineStyle lineStyle,
723 ThemeAccess.TextStyle textStyle 777 ThemeAccess.TextStyle textStyle
724 ) { 778 ) {
725 // OPTIMIZE pre-calculate area-related values 779 // OPTIMIZE pre-calculate area-related values
726 final float TEXT_OFF = 0.03f; 780 final float TEXT_OFF = 0.03f;
727 final float LINE_OFF = 0.02f;
728 781
729 XYLineAnnotation lineAnnotation = null; 782 XYLineAnnotation lineAnnotation = null;
730 XYTextAnnotation textAnnotation = null; 783 XYTextAnnotation textAnnotation = null;
731 784
732 int rendererIndex = 0; 785 int rendererIndex = 0;
734 if (annotation.atX()) { 787 if (annotation.atX()) {
735 textAnnotation = new CollisionFreeXYTextAnnotation( 788 textAnnotation = new CollisionFreeXYTextAnnotation(
736 annotation.getText(), annotation.getPos(), area.ofGround(TEXT_OFF)); 789 annotation.getText(), annotation.getPos(), area.ofGround(TEXT_OFF));
737 // OPTIMIZE externalize the calculation involving PI. 790 // OPTIMIZE externalize the calculation involving PI.
738 textAnnotation.setRotationAngle(270f*Math.PI/180f); 791 textAnnotation.setRotationAngle(270f*Math.PI/180f);
739 // Style the line. 792 lineAnnotation = createGroundStickAnnotation(
740 if (lineStyle != null) { 793 area, annotation.getPos(), lineStyle);
741 lineAnnotation = new XYLineAnnotation(annotation.getPos(),
742 area.atGround(), annotation.getPos(), area.ofGround(LINE_OFF),
743 new BasicStroke(lineStyle.getWidth()),lineStyle.getColor());
744 }
745 else {
746 lineAnnotation = new XYLineAnnotation(annotation.getPos(),
747 area.atGround(), annotation.getPos(), area.ofGround(LINE_OFF));
748 }
749 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT); 794 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT);
750 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT); 795 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT);
751 } 796 }
752 else { 797 else {
753 // Do the more complicated case where we stick to the Y-Axis. 798 // Do the more complicated case where we stick to the Y-Axis.
762 } 807 }
763 else { 808 else {
764 rendererIndex = dataset.getPlotAxisIndex(); 809 rendererIndex = dataset.getPlotAxisIndex();
765 } 810 }
766 811
812 // Stick to the "right" (opposed to left) Y-Axis.
767 if (rendererIndex != 0) { 813 if (rendererIndex != 0) {
768 // OPTIMIZE: Pass a different area to this function, 814 // OPTIMIZE: Pass a different area to this function,
769 // do the adding to renderer outside (let this 815 // do the adding to renderer outside (let this
770 // function return the annotations). 816 // function return the annotations).
771 // Note that this path is travelled rarely. 817 // Note that this path is travelled rarely.
772 Area area2 = new Area(plot.getDomainAxis(), plot.getRangeAxis(rendererIndex)); 818 Area area2 = new Area(plot.getDomainAxis(), plot.getRangeAxis(rendererIndex));
773 textAnnotation = new CollisionFreeXYTextAnnotation( 819 textAnnotation = new CollisionFreeXYTextAnnotation(
774 annotation.getText(), area2.ofRight(TEXT_OFF), annotation.getPos()); 820 annotation.getText(), area2.ofRight(TEXT_OFF), annotation.getPos());
775 textAnnotation.setRotationAnchor(TextAnchor.CENTER_RIGHT); 821 textAnnotation.setRotationAnchor(TextAnchor.CENTER_RIGHT);
776 textAnnotation.setTextAnchor(TextAnchor.CENTER_RIGHT); 822 textAnnotation.setTextAnchor(TextAnchor.CENTER_RIGHT);
777 // Style the line. 823 lineAnnotation = createRightStickAnnotation(
778 if (lineStyle != null) { 824 area2, annotation.getPos(), lineStyle);
779 lineAnnotation = new XYLineAnnotation(area2.ofRight(LINE_OFF), 825 // TODO line to curve
780 annotation.getPos(), area2.atRight(), 826 if (!Float.isNaN(annotation.getHitPoint())) {
781 annotation.getPos(), new BasicStroke(lineStyle.getWidth()), 827 // TODO let line be styled and respect X/Y-ness.
782 lineStyle.getColor()); 828 // New line annotation to hit curve.
783 } 829 XYLineAnnotation hitLineAnnotation = new XYLineAnnotation(
784 else { 830 area2.atRight(), annotation.getPos(),
785 lineAnnotation = new XYLineAnnotation(area2.atRight(), 831 annotation.getHitPoint(), annotation.getPos());
786 annotation.getPos(), area2.ofRight(LINE_OFF), annotation.getPos()); 832 XYLineAnnotation lineBackAnnotation = new XYLineAnnotation(
833 annotation.getHitPoint(), annotation.getPos(),
834 annotation.getHitPoint(), area2.atGround());
835 plot.getRenderer(rendererIndex).addAnnotation(hitLineAnnotation,
836 org.jfree.ui.Layer.BACKGROUND);
837 plot.getRenderer(rendererIndex).addAnnotation(lineBackAnnotation,
838 org.jfree.ui.Layer.BACKGROUND);
787 } 839 }
788 } 840 }
789 else { 841 else {
790 textAnnotation = new CollisionFreeXYTextAnnotation( 842 textAnnotation = new CollisionFreeXYTextAnnotation(
791 annotation.getText(), area.ofLeft(TEXT_OFF), annotation.getPos()); 843 annotation.getText(), area.ofLeft(TEXT_OFF), annotation.getPos());
792 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT); 844 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT);
793 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT); 845 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT);
794 // Style the line. 846 lineAnnotation = createLeftStickAnnotation(area, annotation.getPos(), lineStyle);
795 if (lineStyle != null) { 847 // TODO line to curve
796 lineAnnotation = new XYLineAnnotation(area.atLeft(), 848 if (!Float.isNaN(annotation.getHitPoint())) {
797 annotation.getPos(), area.ofLeft(LINE_OFF), 849 // TODO let line be styled and respect X/Y-ness.
798 annotation.getPos(), new BasicStroke(lineStyle.getWidth()), 850 // New line annotation to hit curve.
799 lineStyle.getColor()); 851 XYLineAnnotation hitLineAnnotation = new XYLineAnnotation(area.atLeft(),
800 } 852 annotation.getPos(), annotation.getHitPoint(), annotation.getPos());
801 else { 853 XYLineAnnotation lineBackAnnotation = new XYLineAnnotation(
802 lineAnnotation = new XYLineAnnotation(area.atLeft(), 854 annotation.getHitPoint(), annotation.getPos(),
803 annotation.getPos(), area.ofLeft(LINE_OFF), annotation.getPos()); 855 annotation.getHitPoint(), area.atGround());
856 plot.getRenderer(rendererIndex).addAnnotation(hitLineAnnotation,
857 org.jfree.ui.Layer.BACKGROUND);
858 plot.getRenderer(rendererIndex).addAnnotation(lineBackAnnotation,
859 org.jfree.ui.Layer.BACKGROUND);
804 } 860 }
805 } 861 }
806 } 862 }
807 863
808 // Style the text. 864 // Style the text.
811 } 867 }
812 868
813 // Add the Annotations to renderer. 869 // Add the Annotations to renderer.
814 plot.getRenderer(rendererIndex).addAnnotation(textAnnotation, 870 plot.getRenderer(rendererIndex).addAnnotation(textAnnotation,
815 org.jfree.ui.Layer.FOREGROUND); 871 org.jfree.ui.Layer.FOREGROUND);
816 if (!Float.isNaN(annotation.getHitPoint())) {
817 // TODO let line be styled and respect X/Y-ness.
818 // New line annotation to hit curve.
819 XYLineAnnotation hitLineAnnotation = new XYLineAnnotation(area.atLeft(),
820 annotation.getPos(), annotation.getHitPoint(), annotation.getPos());
821 XYLineAnnotation lineBackAnnotation = new XYLineAnnotation(
822 annotation.getHitPoint(), annotation.getPos(),
823 annotation.getHitPoint(), area.atGround());
824 plot.getRenderer(rendererIndex).addAnnotation(hitLineAnnotation,
825 org.jfree.ui.Layer.BACKGROUND);
826 plot.getRenderer(rendererIndex).addAnnotation(lineBackAnnotation,
827 org.jfree.ui.Layer.BACKGROUND);
828 }
829 plot.getRenderer(rendererIndex).addAnnotation(lineAnnotation, 872 plot.getRenderer(rendererIndex).addAnnotation(lineAnnotation,
830 org.jfree.ui.Layer.FOREGROUND); 873 org.jfree.ui.Layer.FOREGROUND);
831 } 874 }
832 875
833 876

http://dive4elements.wald.intevation.org