You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ab...@apache.org on 2019/12/07 23:10:33 UTC

svn commit: r1871010 - in /poi/trunk/src: examples/src/org/apache/poi/xslf/usermodel/ ooxml/java/org/apache/poi/xddf/usermodel/chart/ ooxml/java/org/apache/poi/xwpf/usermodel/

Author: abearez
Date: Sat Dec  7 23:10:32 2019
New Revision: 1871010

URL: http://svn.apache.org/viewvc?rev=1871010&view=rev
Log:
Miscellaneous fixes for chart functionalities

Modified:
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java

Modified: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java?rev=1871010&r1=1871009&r2=1871010&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java Sat Dec  7 23:10:32 2019
@@ -87,11 +87,9 @@ public class ChartFromScratch {
             Double[] values2 = listSpeakers.toArray(new Double[0]);
 
             try (XMLSlideShow ppt = new XMLSlideShow()) {
-                XSLFSlide slide = ppt.createSlide();
-                XSLFChart chart = ppt.createChart();
-                Rectangle2D rect2D = new java.awt.Rectangle(fromCM(1.5), fromCM(4), fromCM(22), fromCM(14));
-                slide.addChart(chart, rect2D);
-                setBarData(chart, chartTitle, series, categories, values1, values2);
+                createSlideWithChart(ppt, chartTitle, series, categories, values1, values2);
+                createSlideWithChart(ppt, chartTitle, series, categories, values1, values2);
+                createSlideWithChart(ppt, chartTitle, series, categories, values1, values2);
                 // save the result
                 try (OutputStream out = new FileOutputStream("chart-from-scratch.pptx")) {
                     ppt.write(out);
@@ -101,6 +99,15 @@ public class ChartFromScratch {
         System.out.println("Done");
     }
 
+    private static void createSlideWithChart(XMLSlideShow ppt, String chartTitle, String[] series, String[] categories,
+            Double[] values1, Double[] values2) {
+        XSLFSlide slide = ppt.createSlide();
+        XSLFChart chart = ppt.createChart();
+        Rectangle2D rect2D = new java.awt.Rectangle(fromCM(1.5), fromCM(4), fromCM(22), fromCM(14));
+        slide.addChart(chart, rect2D);
+        setBarData(chart, chartTitle, series, categories, values1, values2);
+    }
+
     private static int fromCM(double cm) {
         return (int) (Math.rint(cm * Units.EMU_PER_CENTIMETER));
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java?rev=1871010&r1=1871009&r2=1871010&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java Sat Dec  7 23:10:32 2019
@@ -212,6 +212,7 @@ public class XDDFCategoryAxis extends XD
         final long id = getNextAxId(plotArea);
         ctCatAx = plotArea.addNewCatAx();
         ctCatAx.addNewAxId().setVal(id);
+        ctCatAx.addNewAuto().setVal(false);
         ctCatAx.addNewAxPos();
         ctCatAx.addNewScaling();
         ctCatAx.addNewCrosses();
@@ -220,6 +221,8 @@ public class XDDFCategoryAxis extends XD
         ctCatAx.addNewDelete();
         ctCatAx.addNewMajorTickMark();
         ctCatAx.addNewMinorTickMark();
+        ctCatAx.addNewNumFmt().setSourceLinked(true);
+        ctCatAx.getNumFmt().setFormatCode("");
 
         setPosition(position);
         setOrientation(AxisOrientation.MIN_MAX);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java?rev=1871010&r1=1871009&r2=1871010&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java Sat Dec  7 23:10:32 2019
@@ -236,6 +236,7 @@ public class XDDFDateAxis extends XDDFCh
         final long id = getNextAxId(plotArea);
         ctDateAx = plotArea.addNewDateAx();
         ctDateAx.addNewAxId().setVal(id);
+        ctDateAx.addNewAuto().setVal(false);
         ctDateAx.addNewAxPos();
         ctDateAx.addNewScaling();
         ctDateAx.addNewCrosses();
@@ -244,6 +245,8 @@ public class XDDFDateAxis extends XDDFCh
         ctDateAx.addNewDelete();
         ctDateAx.addNewMajorTickMark();
         ctDateAx.addNewMinorTickMark();
+        ctDateAx.addNewNumFmt().setSourceLinked(true);
+        ctDateAx.getNumFmt().setFormatCode("");
 
         setPosition(position);
         setOrientation(AxisOrientation.MIN_MAX);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=1871010&r1=1871009&r2=1871010&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Sat Dec  7 23:10:32 2019
@@ -123,9 +123,9 @@ public class XWPFDocument extends POIXML
      * Keeps track on all id-values used in this document and included parts, like headers, footers, etc.
      */
     private IdentifierManager drawingIdManager = new IdentifierManager(0L, 4294967295L);
-    
+
     private FootnoteEndnoteIdManager footnoteIdManager = new FootnoteEndnoteIdManager(this);
-    
+
     /**
      * Handles the joy of different headers/footers for different pages
      */
@@ -1356,7 +1356,7 @@ public class XWPFDocument extends POIXML
     public boolean getEvenAndOddHeadings() {
         return settings.getEvenAndOddHeadings();
     }
-    
+
     /**
      * Sets the even-and-odd-headings setting
      * @param enable Set to true to turn on separate even and odd headings.
@@ -1364,7 +1364,7 @@ public class XWPFDocument extends POIXML
     public void setEvenAndOddHeadings(boolean enable) {
         settings.setEvenAndOddHeadings(enable);
     }
-    
+
     /**
      * Returns the mirror margins setting
      *
@@ -1373,7 +1373,7 @@ public class XWPFDocument extends POIXML
     public boolean getMirrorMargins() {
         return settings.getMirrorMargins();
     }
-    
+
     /**
      * Sets the mirror margins setting
      * @param enable Set to true to turn on mirror margins.
@@ -1381,7 +1381,7 @@ public class XWPFDocument extends POIXML
     public void setMirrorMargins(boolean enable) {
         settings.setMirrorMargins(enable);
     }
-    
+
     /**
      * inserts an existing XWPFTable to the arrays bodyElements and tables
      *
@@ -1694,7 +1694,20 @@ public class XWPFDocument extends POIXML
      * @since POI 4.0.0
      */
     public XWPFChart createChart(int width, int height) throws InvalidFormatException, IOException {
+        return createChart(createParagraph().createRun(), width, height);
+    }
 
+    /**
+     *
+     * @param run in which the chart will be attached.
+     * @param width in EMU.
+     * @param height in EMU.
+     * @return the new chart.
+     * @throws InvalidFormatException
+     * @throws IOException
+     * @since POI 4.1.2
+     */
+    public XWPFChart createChart(XWPFRun run, int width, int height) throws InvalidFormatException, IOException {
         //get chart number
         int chartNumber = getNextPartNumber(XWPFRelation.CHART, charts.size() + 1);
 
@@ -1705,7 +1718,7 @@ public class XWPFDocument extends POIXML
         // initialize xwpfchart object
         XWPFChart xwpfChart = rp.getDocumentPart();
         xwpfChart.setChartIndex(chartNumber);
-        xwpfChart.attach(rp.getRelationship().getId(), createParagraph().createRun());
+        xwpfChart.attach(rp.getRelationship().getId(), run);
         xwpfChart.setChartBoundingBox(width, height);
 
         //add chart object to chart list
@@ -1721,7 +1734,7 @@ public class XWPFDocument extends POIXML
      */
     public XWPFFootnote createFootnote() {
         XWPFFootnotes footnotes = this.createFootnotes();
-        
+
         XWPFFootnote footnote = footnotes.createFootnote();
         return footnote;
     }
@@ -1749,7 +1762,7 @@ public class XWPFDocument extends POIXML
      */
     public XWPFEndnote createEndnote() {
         XWPFEndnotes endnotes = this.createEndnotes();
-        
+
         XWPFEndnote endnote = endnotes.createEndnote();
         return endnote;
 
@@ -1769,7 +1782,7 @@ public class XWPFDocument extends POIXML
         }
 
         return endnotes;
-        
+
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org