Page 1 of 1

Bar Charts: "Invert if negative" (CT_InvertSolidFillFmt)

PostPosted: Fri Sep 29, 2017 1:46 am
by Exandra
Hello,

Our chart library needs the word feature "Invert if negative" for solid fills (bar charts), but docx4j doesn't seem support them. At least I didn't find a way to unmarshal the required XML code or programmatically implement them.

"Invert if negative" is in Word implemented like this:

Code: Select all
               <c:extLst>
                  <c:ext uri="{6F2FDCE9-48DA-4B69-8628-5D25D57E5C99}" xmlns:c14="http://schemas.microsoft.com/office/drawing/2007/8/2/chart">
                     <c14:invertSolidFillFmt>
                        <c14:spPr xmlns:c14="http://schemas.microsoft.com/office/drawing/2007/8/2/chart">
                           <a:solidFill>
                              <a:srgbClr val="C0504D"/>
                           </a:solidFill>
                           <a:ln>
                              <a:noFill/>
                           </a:ln>
                           <a:effectLst/>
                        </c14:spPr>
                     </c14:invertSolidFillFmt>
                  </c:ext>
               </c:extLst>


The docx4j webapp is able to generate c:extLst and c:ext. Everything below that node is missing. The required tags are in chart20070802.xsd.

Before I try to implement the required classes by hand (ouch), I'd like to know whether someone from the docx4j team could commit these classes to the repository. Or maybe someone could explain how to generate these classes from the schema definition. I tried the following command:
Code: Select all
xjc chart20070802.xsd -d foo -no-header -target 2.0 –extension

But parsing failed with three warnings and one error.
  • Warnings: Missing orel.xsd, oartspproperties.xsd, ChartDrawing.xsd, Chart.xsd.
  • Error: a:CT_ShapeProperties couldn’t be resolved as “type definition”

Is there any chance to implement c14:invertSolidFillFmt, c14:spPr, a:solidFill ...?

Re: Bar Charts: "Invert if negative" (CT_InvertSolidFillFmt)

PostPosted: Tue Oct 03, 2017 3:02 am
by jason
Adding this now.

Will be in a nightly today or tomorrow and in the next release of docx4j (3.3.6) due later this week.

Note the other chart related namespaces at https://msdn.microsoft.com/en-us/librar ... =office.12).aspx

Are any others of those critical to you right now?

Re: Bar Charts: "Invert if negative" (CT_InvertSolidFillFmt)

PostPosted: Tue Oct 03, 2017 4:48 am
by jason
See now https://github.com/plutext/docx4j/commi ... 48636e?w=1

Please note that for an Excel chart part such as:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  <c:date1904 val="0"/>
  <c:lang val="en-US"/>
  <c:roundedCorners val="0"/>
  <mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <mc:Choice Requires="c14" xmlns:c14="http://schemas.microsoft.com/office/drawing/2007/8/2/chart">
      <c14:style val="102"/>
    </mc:Choice>
    <mc:Fallback>
      <c:style val="2"/>
    </mc:Fallback>
  </mc:AlternateContent>
  <c:chart>
    <c:autoTitleDeleted val="0"/>
    <c:plotArea>
      <c:layout/>
      <c:barChart>
:
:
 
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


docx4j currently drops the mc:AlternateContent element. To address that, mc:AlternateContent would need to be added to the c:chartSpace content model.

If you need further help with c:extLst/c:ext, please attach a sample docx.

Re: Bar Charts: "Invert if negative" (CT_InvertSolidFillFmt)

PostPosted: Wed Oct 04, 2017 10:32 pm
by Exandra
Thanks for the fast reply. I've run into a few problems to implement the final "Invert if negative" feature:

  • JAXB couldn't initialize org.docx4j.dml.chart.x2007 context due to a missing ObjectFactory.class or jaxb.index.
  • Missing XmlRootElement in CTInvertSolidFillFmt

I've created an ObjectFactory by Copy&Paste:
Code: Select all
/*
*  Copyright 2007-2008, Plutext Pty Ltd.
*   
*  This file is part of docx4j.

    docx4j is licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.

    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

*/


package org.docx4j.dml.chart.x2007;

import javax.xml.bind.annotation.XmlRegistry;


/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the org.docx4j.dml.chart.x2007 package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups.  Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {


    /**
     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.docx4j.dml.chart.x2007
     *
     */
    public ObjectFactory() {
    }

    /**
     * Create an instance of {@link CTBooleanFalse }
     *
     */
    public CTBooleanFalse createCTBooleanFalse() {
        return new CTBooleanFalse();
    }

    /**
     * Create an instance of {@link CTBooleanTrue }
     *
     */
    public CTBooleanTrue createCTBooleanTrue() {
        return new CTBooleanTrue();
    }

    /**
     * Create an instance of {@link CTInvertSolidFillFmt }
     *
     */
    public CTInvertSolidFillFmt createCTInvertSolidFillFmt() {
        return new CTInvertSolidFillFmt();
    }

    /**
     * Create an instance of {@link CTPivotOptions }
     *
     */
    public CTPivotOptions createCTPivotOptions() {
        return new CTPivotOptions();
    }

    /**
     * Create an instance of {@link CTStyle }
     *
     */
    public CTStyle createCTStyle() {
        return new CTStyle();
    }


}


And I've added:
Code: Select all
import javax.xml.bind.annotation.XmlRootElement;
...
@XmlRootElement(name = "invertSolidFillFmt")

To my CTInvertSolidFillFmt.java.

Using the "XML unmarshal-way", I run into problems with the c: and a: namespaces. But I've never really used this way anyway. Probably a problem in front of my display and not a problem of docx4j. ;)

But the programmatic way works for me, yeah. :D

Re: Bar Charts: "Invert if negative" (CT_InvertSolidFillFmt)

PostPosted: Thu Oct 05, 2017 6:21 pm
by jason
Exandra wrote:JAXB couldn't initialize org.docx4j.dml.chart.x2007 context due to a missing ObjectFactory.class or jaxb.index.


XJC did generate OF, but somehow I didn't push it; done now: https://github.com/plutext/docx4j/commi ... 4cab67e018

Exandra wrote:@XmlRootElement(name = "invertSolidFillFmt")


Yes, that's ok here, so thanks, copied your code :-)

Exandra wrote:Using the "XML unmarshal-way", I run into problems with the c: and a: namespaces.


If you give an example of what you mean, I'll try to help. Be sure you declare those namespaces.