-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added more chart supports. #144
Conversation
fixed bug while creating chart with bar and line series.
Can one of the admins verify this patch? |
XDDFBarChartData.Series series1 = (XDDFBarChartData.Series) bar.addSeries(xs, ys1); | ||
series1.setTitle("Bars", new CellReference("Sheet1!$B$1")); | ||
bar.setVaryColors(true); | ||
bar.setBarDirection(BarDirection.COL); | ||
chart.plot(bar); | ||
|
||
// the line chart | ||
// the line chart on secondary axis | ||
XDDFLineChartData lines = (XDDFLineChartData) chart.createData(ChartTypes.LINE, lineCategories, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create line series with secondary axis
XDDFLineChartData.Series series2 = (XDDFLineChartData.Series) lines.addSeries(xs, ys2); | ||
series2.updateIdXVal(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update axis value and order value of series.
@@ -17,9 +17,16 @@ Licensed to the Apache Software Foundation (ASF) under one or more | |||
package org.apache.poi.xddf.usermodel.chart; | |||
|
|||
public enum ChartTypes { | |||
AREA, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum for new chart types
@@ -0,0 +1,165 @@ | |||
/* ==================================================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support for area 3d chart
@@ -0,0 +1,168 @@ | |||
/* ==================================================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support for area chart
@@ -0,0 +1,201 @@ | |||
/* ==================================================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support for bar 3d chart
@@ -187,5 +187,16 @@ protected CTAxDataSource getAxDS() { | |||
protected CTNumDataSource getNumDS() { | |||
return series.getVal(); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overrided method to update series id and order id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see these methods, but your comment does not help to understand what problem they were supposed to solve in the first place.
I first of all question their public
visibility. Since I don't think it is good practice to rely on the developer using the library to know when to use and what to expect from them...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we created update methods, because in a chart, we need to provide unique value to each series, now while creating combo chart, i.e. line series and bar series in that case we assigning same values to each series due to that it was corrupting the office file. Now either we can create a new constructor with new parameter i.e. index or can provide an update method to re-assign axis id and order id. so i chose update method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally understood what you were trying to achieve! I had a similar code in a PR that I left aside because of some more changes required after a comment about API requiring changes.
https://github.com/apache/poi/pull/139/files#diff-17a515ee7210ab25ee2bcedbf5e49a87R116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also tried to get all series list in chart data, but as there is no relationship between different series types, so we are left with only series list of particular chart data.
* | ||
* @return this method will add 3D view | ||
*/ | ||
public XDDFView3D getOrAddView3D() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method to add 3d view into chart
Map<Long, XDDFChartAxis> categories = null; | ||
Map<Long, XDDFValueAxis> mapValues = null; | ||
|
||
if(ChartTypes.PIE != type && ChartTypes.PIE3D != type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handled null pointer exception in case of pie chart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you :)
categories = Collections.singletonMap(category.getId(), category); | ||
mapValues = Collections.singletonMap(values.getId(), values); | ||
} | ||
|
||
final CTPlotArea plotArea = getCTPlotArea(); | ||
switch (type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added case to create instance for new added chart
@@ -98,6 +98,10 @@ public XDDFCategoryAxis getCategoryAxis() { | |||
|
|||
protected abstract CTNumDataSource getNumDS(); | |||
|
|||
protected abstract void updateIdXVal(long val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abstract methods to update series id and order id
@@ -0,0 +1,233 @@ | |||
/* ==================================================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support for Line 3d chart
@@ -67,7 +67,11 @@ public Grouping getGrouping() { | |||
} | |||
|
|||
public void setGrouping(Grouping grouping) { | |||
if (chart.getGrouping()!=null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handled case in case of grouping was not created in chart
@@ -0,0 +1,157 @@ | |||
/* ==================================================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support for pie 3d chart
@@ -0,0 +1,168 @@ | |||
/* ==================================================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support for surface 3d chart
@@ -0,0 +1,167 @@ | |||
/* ==================================================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support for surface chart
@@ -0,0 +1,106 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created class to use 3d view
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After formatting details are fixed, we will start discussing some more in depth design decisions.
@@ -134,17 +134,26 @@ public static void main(String[] args) throws Exception { | |||
lineCategories.crossAxis(rightValues); | |||
|
|||
// the bar chart | |||
XDDFBarChartData bar = (XDDFBarChartData) chart.createData(ChartTypes.BAR, lineCategories, rightValues); | |||
XDDFBarChartData bar = (XDDFBarChartData) chart.createData(ChartTypes.BAR, barCategories, leftValues); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you :)
XDDFLineChartData.Series series2 = (XDDFLineChartData.Series) lines.addSeries(xs, ys2); | ||
series2.updateIdXVal(1); | ||
series2.updateOrderVal(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your updateXXXVal()
methods are disguised setters. I am not quite sure this is the best way to achieve your goal (which I still does not understand at this point).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we created update methods, because in a chart, we need to provide unique value to each series, now while creating combo chart, i.e. line series and bar series in that case we assigning same values to each series due to that it was corrupting the office file. Now either we can create a new constructor with new parameter i.e. index or can provide an update method to re-assign axis id and order id. so i chose update method.
SCATTER | ||
SCATTER, | ||
SURFACE, | ||
SURFACE3D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seven new chart types at once!!!
Very impressive, indeed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank u :)
@@ -187,5 +187,16 @@ protected CTAxDataSource getAxDS() { | |||
protected CTNumDataSource getNumDS() { | |||
return series.getVal(); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see these methods, but your comment does not help to understand what problem they were supposed to solve in the first place.
I first of all question their public
visibility. Since I don't think it is good practice to rely on the developer using the library to know when to use and what to expect from them...
public XDDFView3D getOrAddView3D() | ||
{ | ||
CTView3D view3D; | ||
if(chart.isSetView3D()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing whitespace between if
and (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated code.
|
||
@Override | ||
public void setVaryColors(boolean varyColors) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment.
|
||
@Override | ||
public void setShowLeaderLines(boolean showLeaderLines) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment.
view3D.getRotY().setVal(val); | ||
} | ||
else | ||
view3D.addNewRotY().setVal(val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The three lines above don't follow formatting rules for the project...
And the pattern is (wrongly) repeated until the end of this class!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated code.
} | ||
|
||
public int getRotXVal() { | ||
return view3D.getRotX().getVal(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite being internally represented as an int
value, the rotation represents an angle which developers using this library will expect to be expressed in degrees instead of the scaled range allowed by the specs.
We will have to provide a converting mechanism. I am sorry I got it wrong in the first place on the other properties representing angles...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we need to write a utility method for conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am writing that utility method. so if it's completed early so i will check in that code with this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While reading the specs, this is one of the few places where the angles are given as integer values, without scaling by 60,000 to get more precision.
return view3D.getHPercent().getVal(); | ||
} | ||
|
||
public void setHPercentVal(int val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As matter of facts, all the methods names have to be adapted to the conventions used otherwise in the project:
- no
Val
suffix - no unpronounceable name such as
RAngAx
- no shortcut as
RotX
,RotY
orHPercent
butRotationX
,RotationY
andHeightPercent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated method names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated suggested changes.
applied as r1859590 |
closes #139 closes #144 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859676 13f79535-47bb-0310-9956-ffa450edef68
closes apache#139 closes apache#144 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859676 13f79535-47bb-0310-9956-ffa450edef68
Added more chart supports.
fixed bug while creating chart with bar and line series.