]> source.dussan.org Git - poi.git/commitdiff
Apply patches from Peter Kutak from bugs 49334 and 49242 - HSSFChart improvements...
authorNick Burch <nick@apache.org>
Tue, 25 May 2010 15:59:26 +0000 (15:59 +0000)
committerNick Burch <nick@apache.org>
Tue, 25 May 2010 15:59:26 +0000 (15:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@948080 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/RecordFactory.java
src/java/org/apache/poi/hssf/record/UnknownRecord.java
src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java

index 102f6cb529541ac4ad196c141c6131285e7995e7..068ab153af25563a9ca22b7c693684cbf9a923a0 100644 (file)
@@ -34,6 +34,8 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="add">49334 - Track the ValueRangeRecords of charts in HSSFChart, to allow the basic axis operations</action>
+           <action dev="POI-DEVELOPERS" type="add">49242 - Track the LinkDataRecords of charts in HSSFChart</action>
            <action dev="POI-DEVELOPERS" type="add">Improved performance of XSSFWorkbook.write </action>
            <action dev="POI-DEVELOPERS" type="fix">48846 - Avoid NPE when finding cell comments</action>
            <action dev="POI-DEVELOPERS" type="fix">49325 - Ensure that CTPhoneticPr is included in poi-ooxml jar</action>
index da4a065f9b8b7c9092b528f5663ed5370f9d9574..e99534ce623159b96b437569356e897411d9a282 100644 (file)
@@ -210,8 +210,9 @@ public final class RecordFactory {
                TopMarginRecord.class,
                UncalcedRecord.class,
                UseSelFSRecord.class,
-        UserSViewBegin.class,
-        UserSViewEnd.class,
+               UserSViewBegin.class,
+               UserSViewEnd.class,
+               ValueRangeRecord.class,
                VCenterRecord.class,
                VerticalPageBreakRecord.class,
                WindowOneRecord.class,
index 7056cb2c31a1107e4ad16786a1d99eee513683be..20b352456d11b66366db96b4ea1cf64eab0c2e5c 100644 (file)
@@ -241,7 +241,6 @@ public final class UnknownRecord extends StandardRecord {
                        case 0x101B:
                        case 0x101D:
                        case 0x101E:
-                       case 0x101F:
                        case 0x1020:
                        case 0x1021:
                        case 0x1022:
index 725659044c0647ce3921b7df673dc4b144282d93..9192d97d787875353a6bf997a2f4b2e242c3f182 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.poi.hssf.usermodel;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.poi.hssf.record.chart.*;
@@ -37,6 +36,7 @@ import org.apache.poi.hssf.record.UnknownRecord;
 import org.apache.poi.hssf.record.VCenterRecord;
 import org.apache.poi.hssf.record.formula.Area3DPtg;
 import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.chart.LinkedDataRecord;
 
 /**
  * Has methods for construction of a chart object.
@@ -49,8 +49,9 @@ public final class HSSFChart {
        private LegendRecord legendRecord;
        private ChartTitleFormatRecord chartTitleFormat;
        private SeriesTextRecord chartTitleText;
-
-       private List series = new ArrayList();
+       private List<ValueRangeRecord> valueRanges = new ArrayList<ValueRangeRecord>(); 
+       
+       private List<HSSFSeries> series = new ArrayList<HSSFSeries>();
 
        private HSSFChart(ChartRecord chartRecord) {
                this.chartRecord = chartRecord;
@@ -137,13 +138,12 @@ public final class HSSFChart {
         *  these charts yet, as this is very limited support
         */
        public static HSSFChart[] getSheetCharts(HSSFSheet sheet) {
-               List charts = new ArrayList();
+               List<HSSFChart> charts = new ArrayList<HSSFChart>();
                HSSFChart lastChart = null;
-
+               HSSFSeries lastSeries = null;
                // Find records of interest
-               List records = sheet.getSheet().getRecords();
-               for(Iterator it = records.iterator(); it.hasNext();) {
-                       RecordBase r = (RecordBase)it.next();
+               List<RecordBase> records = sheet.getSheet().getRecords();
+               for(RecordBase r : records) {
 
                        if(r instanceof ChartRecord) {
                                lastChart = new HSSFChart((ChartRecord)r);
@@ -155,6 +155,7 @@ public final class HSSFChart {
                        if(r instanceof SeriesRecord) {
                                HSSFSeries series = lastChart.new HSSFSeries( (SeriesRecord)r );
                                lastChart.series.add(series);
+                               lastSeries = series;
                        }
                        if(r instanceof ChartTitleFormatRecord) {
                                lastChart.chartTitleFormat =
@@ -173,6 +174,13 @@ public final class HSSFChart {
                                        lastChart.chartTitleText = str;
                                }
                        }
+                       if(r instanceof LinkedDataRecord) {
+                               LinkedDataRecord data = (LinkedDataRecord)r;
+                               lastSeries.insertData( data );
+                       }
+                       if(r instanceof ValueRangeRecord){
+                               lastChart.valueRanges.add((ValueRangeRecord)r);
+                       }
                }
 
                return (HSSFChart[])
@@ -228,6 +236,35 @@ public final class HSSFChart {
                        throw new IllegalStateException("No chart title found to change");
                }
        }
+       
+       /**
+        * Set value range (basic Axis Options) 
+        * @param axisIndex 0 - primary axis, 1 - secondary axis
+        * @param minimum minimum value; Double.NaN - automatic; null - no change
+        * @param maximum maximum value; Double.NaN - automatic; null - no change
+        * @param majorUnit major unit value; Double.NaN - automatic; null - no change
+        * @param minorUnit minor unit value; Double.NaN - automatic; null - no change
+        */
+       public void setValueRange( int axisIndex, Double minimum, Double maximum, Double majorUnit, Double minorUnit){
+               ValueRangeRecord valueRange = (ValueRangeRecord)valueRanges.get( axisIndex );
+               if( valueRange == null ) return;
+               if( minimum != null ){
+                       valueRange.setAutomaticMinimum(minimum.isNaN());
+                       valueRange.setMinimumAxisValue(minimum);
+               }
+               if( maximum != null ){
+                       valueRange.setAutomaticMaximum(maximum.isNaN());
+                       valueRange.setMaximumAxisValue(maximum);
+               }
+               if( majorUnit != null ){
+                       valueRange.setAutomaticMajor(majorUnit.isNaN());
+                       valueRange.setMajorIncrement(majorUnit);
+               }
+               if( minorUnit != null ){
+                       valueRange.setAutomaticMinor(minorUnit.isNaN());
+                       valueRange.setMinorIncrement(minorUnit);
+               }
+       }
 
        private SeriesIndexRecord createSeriesIndexRecord( int index )
        {
@@ -348,7 +385,7 @@ public final class HSSFChart {
                return new UnknownRecord((short)0x00EC, data);
        }
 
-       private void createAxisRecords( List records )
+       private void createAxisRecords( List<Record> records )
        {
                records.add( createAxisParentRecord() );
                records.add( createBeginRecord() );
@@ -867,11 +904,30 @@ public final class HSSFChart {
        public class HSSFSeries {
                private SeriesRecord series;
                private SeriesTextRecord seriesTitleText;
+               private LinkedDataRecord dataName;
+               private LinkedDataRecord dataValues;
+               private LinkedDataRecord dataCategoryLabels;
+               private LinkedDataRecord dataSecondaryCategoryLabels;
+               private int dataReaded = 0;
 
                /* package */ HSSFSeries(SeriesRecord series) {
                        this.series = series;
                }
 
+               public void insertData(LinkedDataRecord data){
+                       switch(dataReaded){
+                               case 0: dataName = data;
+                               break;
+                               case 1: dataValues = data;
+                               break;
+                               case 2: dataCategoryLabels = data;
+                               break;
+                               case 3: dataSecondaryCategoryLabels = data;
+                               break;
+                       }
+                       dataReaded++;
+               }
+               
                public short getNumValues() {
                        return series.getNumValues();
                }
@@ -905,5 +961,40 @@ public final class HSSFChart {
                                throw new IllegalStateException("No series title found to change");
                        }
                }
+
+               /**
+                * @return record with data names
+                */
+               public LinkedDataRecord getDataName(){
+                       return dataName;
+               }
+               
+               /**
+                * @return record with data values
+                */
+               public LinkedDataRecord getDataValues(){
+                       return dataValues;
+               }
+               
+               /**
+                * @return record with data category labels
+                */
+               public LinkedDataRecord getDataCategoryLabels(){
+                       return dataCategoryLabels;
+               }
+               
+               /**
+                * @return record with data secondary category labels
+                */
+               public LinkedDataRecord getDataSecondaryCategoryLabels() {
+                       return dataSecondaryCategoryLabels;
+               }
+               
+               /**
+                * @return record with series
+                */
+               public SeriesRecord getSeries() {
+                       return series;
+               }
        }
 }