Issue Details (XML | Word | Printable)

Key: XWIKI-2883
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Asiri Rathnayake
Reporter: Vincent Massol
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XWiki Core

Implement Chart macro for new rendering

Created: 26/Nov/08 14:22   Updated: 22/Jun/09 18:24
Component/s: Rendering 2.0
Affects Version/s: 1.7 M3
Fix Version/s: 2.0 M1

File Attachments: 1. Text File XWIKI-2833-1-error-message.txt (12 kB)
2. Text File XWIKI-2833-1.patch (44 kB)
3. Text File XWIKI-2833-2.patch (60 kB)
4. Text File XWIKI-2833-pre1.patch (38 kB)
5. Text File XWIKI-2833-pre2.patch (38 kB)

Image Attachments:

1. chart.png
(326 kB)
Issue Links:
Dependency

Date of First Response: 09/Mar/09 16:56
Resolution Date: 22/Jun/09 18:24
Tests: Unit
Development Priority: Medium


 Description  « Hide

 All   Comments   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Dan M added a comment - 09/Mar/09 16:56 - edited
This is a sketchy implementation, only the basic features are implemented, so far. It provides a working component, currently it accepts data from xdom tables only.

Bellow you have an example that illustrates the macro's usage with what's been done so far:

|Category | Sales ($)
|Category 1 | 1000000
|Category 2 |  1500000
|Category 3 |  500000

{{chart chartType="pie" sourceType="xdom" table_number="1" range="A1-B4" /}}

Unit tests and checkstyle validations are going to be added in the future.


Vincent Massol added a comment - 12/Mar/09 17:57
There's no way this can be done for 1.8 final. Moving it to 1.9M1.

Dan M added a comment - 18/Mar/09 18:40
Yet another pre-release. If everything is ok, next time I'm going to add the test cases.

Dan M added a comment - 06/Apr/09 16:11 - edited
Guys, I've added support for the following chart types (besides the existing pie type):
-bar
-line
-area

Unless you notice some other issues to do, I now only have to refurbish a little the source code and to add test cases. Bellow you have an example of usage for the chart macro, after making these modifications and the output is the one from the attached screenshot. (chart.png)

|AAA | BBB ($)
|Category 1 | 200
|Category 2 | 500
|Category 3 | 300


{{chart chartType="pie" source="type:XDOM; table_number:0;range:A1-B3;" height="30" /}}

{{chart chartType="bar" source="type:XDOM; table_number:0;range:A1-B3;" height="60"/}}

|Aaa  | 1.0 | 2.0 | 3.0 | 4.0 | 5.0 | 6.0 | 9.0
|First  | 1.0 | 4.0 | 3.0 | 5.0 | 5.0 | 7.0 | 8.0
|Second | 5.0 | 7.0 | 6.0 | 8.0 | 4.0 | 4.0 | 2.0
|Third  | 3.0 | 4.0 | 4.0 | 3.0 | 2.0 | 3.0 | 6.0 

{{chart chartType="line" source="type:XDOM; table_number:1;range:A1-C3;series:rows" title="line (xy_line_and_shape, default)" /}}

{{chart chartType="area" source="type:XDOM; table_number:1;series:rows" /}}

Vincent Massol added a comment - 06/Apr/09 16:28
Nice.

Some questions:

  • what is the "renderer:circle" option and why is it defined in the "source" parameter?
  • what type of sources do you support?
  • I'd prefer chartType to be named "type" to avoid duplication and be consistent with "source", "height", etc attributes.
  • can the chart contain data (with a special source type - it could be the default when not specified), as in:
{{chart ...}}
| 1.0 | 2.0
| 3.0 | 4.0
{{/chart}}
  • Can the source reference tables in other documents? Can the tables be named (using a custom parameter for example)?

I haven't looked at implementation yet.


Dan M added a comment - 08/Apr/09 16:30
Hi,
Well, let me answer those questions one by one:
-the "renderer:circle" option currently doesn't have any effect on the macro, i used it for testing purposes and removed it after that.
-currently, we have only XDOM sources, which take the data from a table nested within a XDOM tree
-"chartType" has been renamed to "type"
-i could create a special source type (i could name it "inlineDataSource) to make the chart take the data from a table nested within the macro's body as in the example
-right now it cannot reference other documents, for this to happen i see the following approach:
  • add a "document" parameter to the source description, as in:
    {{chart type="bar" source="type:XDOM;  document:Main.MyDocument" / }}
  • making the data source internally use the org.xwiki.rendering.parser.Parser to parse the given document (i think it's possible to do that without expanding the macros, for avoiding getting into infinite loops) and generate its xdom tree and extract the data within it

I look forward for getting your feedback.


Dan M added a comment - 16/Apr/09 16:55
This patch covers everything except for the tests, where I'm stuck with a problem: if try to write a simple test, it fails with the following error: java.lang.AbstractMethodError: gnu.xml.dom.DomDocument.adoptNode(Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; (more details in XWIKI-2833-1-error-message.txt)
So, I'm thinking, after I return from vacation, to write ordinary JUnit test cases and manually call CharMacro.execute() and test the output instead of writing rendering tests. So far this is the only solution that comes to my mind to overcome that error.

Excepting that issue, the macro should perform ok. I've added support for grabbing data from other documents, too, as well as from the macro body. An example of using these new features:

Inline:
{{chart type="pie" source="type:inline;range:A1-B4; height:166; width: 77"}}
|AAA | BBB ($)
|Category 1 | 20
|Category 2 | 500
|Category 3 | 300
{{/chart}}

From another document :
{{chart type="pie" source="type:xdom; document:Main.Table; table_number:0;range:A1-B4 " height="100" width="77" /}}

Best regards,
Dan


Dan M added a comment - 07/May/09 20:19
This one includes tests, as well. As I said before, I wrote ordinary JUnit test cases and manually called CharMacro.execute() to test the result instead of writing rendering tests. So this is it, please let me know what you think about it.
I look forward to getting to know what else needs to be done in order for this macro to be commited.

Vincent Massol added a comment - 19/May/09 13:07
Needed for stats