Skip to content

Commit 996961a

Browse files
committed
Reimplement and correct doughnut/pie options
See #293
1 parent b59a055 commit 996961a

File tree

7 files changed

+142
-294
lines changed

7 files changed

+142
-294
lines changed

chartjs-java-model/src/main/java/software/xdev/chartjs/model/options/DoughnutOptions.java

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -16,100 +16,8 @@
1616
package software.xdev.chartjs.model.options;
1717

1818
import software.xdev.chartjs.model.options.animation.DoughnutAnimation;
19-
import software.xdev.chartjs.model.options.elements.ArcElements;
2019

2120

22-
public class DoughnutOptions extends Options<DoughnutOptions, DoughnutAnimation>
21+
public class DoughnutOptions extends DoughnutOptionsBase<DoughnutOptions, DoughnutAnimation>
2322
{
24-
/**
25-
* Default {@code 50}
26-
*
27-
* @see #setCutout(Number cutout)
28-
*/
29-
protected Number cutout;
30-
31-
/**
32-
* Rotation in degrees. Default {@code 0}. {@code 0} is at the top.
33-
*
34-
* @see #setRotation(Number rotation)
35-
*/
36-
protected Number rotation;
37-
38-
/**
39-
* Circumference in degrees. Default {@code 360}.
40-
*
41-
* @see #setCircumference(Number circumference)
42-
*/
43-
protected Number circumference;
44-
45-
protected ArcElements elements;
46-
47-
/**
48-
* @see #setCutout(Number cutoutPercentage)
49-
*/
50-
public Number getCutout()
51-
{
52-
return this.cutout;
53-
}
54-
55-
/**
56-
* The pixels as number of the chart that is cut out of the middle.
57-
*/
58-
public DoughnutOptions setCutout(final Number cutout)
59-
{
60-
this.cutout = cutout;
61-
return this;
62-
}
63-
64-
/**
65-
* @see #setRotation(Number rotation)
66-
*/
67-
public Number getRotation()
68-
{
69-
return this.rotation;
70-
}
71-
72-
/**
73-
* Starting angle to draw arcs from in degrees
74-
*/
75-
public DoughnutOptions setRotation(final Number rotation)
76-
{
77-
this.rotation = rotation;
78-
return this;
79-
}
80-
81-
/**
82-
* @see #setCircumference(Number circumference)
83-
*/
84-
public Number getCircumference()
85-
{
86-
return this.circumference;
87-
}
88-
89-
/**
90-
* Sweep to allow arcs to cover in degrees
91-
*/
92-
public DoughnutOptions setCircumference(final Number circumference)
93-
{
94-
this.circumference = circumference;
95-
return this;
96-
}
97-
98-
/**
99-
* @return {@link ArcElements} instance, or {@code null} if not set
100-
*/
101-
public ArcElements getElements()
102-
{
103-
return this.elements;
104-
}
105-
106-
/**
107-
* @param elements an {@link ArcElements} instance, or {@code null}
108-
* @return this instance for method chaining
109-
*/
110-
public DoughnutOptions setElements(final ArcElements elements)
111-
{
112-
this.elements = elements;
113-
return this;
114-
}
11523
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package software.xdev.chartjs.model.options;
2+
3+
import software.xdev.chartjs.model.options.animation.DoughnutAnimationBase;
4+
5+
6+
/**
7+
* @see <a href="https://github.com/chartjs/Chart.js/blob/v4.4.6/src/types/index.d.ts#L298">ChartJS Source</a>
8+
*/
9+
public abstract class DoughnutOptionsBase<O extends DoughnutOptionsBase<O, A>, A extends DoughnutAnimationBase<A>>
10+
extends Options<O, A>
11+
{
12+
private Number circumference;
13+
private Object cutout; // number or string
14+
private Object offset; // number or number[]
15+
private Object radius; // number or string
16+
private Number rotation;
17+
private Number spacing;
18+
19+
public Number getCircumference()
20+
{
21+
return this.circumference;
22+
}
23+
24+
public DoughnutOptionsBase<O, A> setCircumference(final Number circumference)
25+
{
26+
this.circumference = circumference;
27+
return this.self();
28+
}
29+
30+
public Object getCutout()
31+
{
32+
return this.cutout;
33+
}
34+
35+
public DoughnutOptionsBase<O, A> setCutout(final Object cutout)
36+
{
37+
this.cutout = cutout;
38+
return this.self();
39+
}
40+
41+
public Object getOffset()
42+
{
43+
return this.offset;
44+
}
45+
46+
public DoughnutOptionsBase<O, A> setOffset(final Object offset)
47+
{
48+
this.offset = offset;
49+
return this.self();
50+
}
51+
52+
public Object getRadius()
53+
{
54+
return this.radius;
55+
}
56+
57+
public DoughnutOptionsBase<O, A> setRadius(final Object radius)
58+
{
59+
this.radius = radius;
60+
return this.self();
61+
}
62+
63+
public Number getRotation()
64+
{
65+
return this.rotation;
66+
}
67+
68+
public DoughnutOptionsBase<O, A> setRotation(final Number rotation)
69+
{
70+
this.rotation = rotation;
71+
return this.self();
72+
}
73+
74+
public Number getSpacing()
75+
{
76+
return this.spacing;
77+
}
78+
79+
public DoughnutOptionsBase<O, A> setSpacing(final Number spacing)
80+
{
81+
this.spacing = spacing;
82+
return this.self();
83+
}
84+
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/options/Options.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828

2929

3030
/**
31-
* @see <a href="https://github.com/chartjs/Chart.js/blob/v4.4.3/src/types/index.d.ts#L1588">ChartJS Source</a>
31+
* @see <a href="https://github.com/chartjs/Chart.js/blob/v4.4.7/src/types/index.d.ts#L1588">
32+
* ChartJS Source (Options)</a>
33+
* @see <a href="https://github.com/chartjs/Chart.js/blob/v4.4.7/src/types/index.d.ts#L1756">
34+
* ChartJS Source (AnimationOptons)</a>
3235
*/
3336
public class Options<T extends Options<T, A>, A extends Animation<A>>
3437
{
@@ -43,7 +46,7 @@ public class Options<T extends Options<T, A>, A extends Animation<A>>
4346
protected CoreInteractionOptions interaction;
4447
protected CoreInteractionOptions hover;
4548
protected Animations<A> animations;
46-
protected Boolean animation = true;
49+
protected Object animation; // Not supported by all charts, but usually a boolean or of Type <A>
4750
protected Layout layout;
4851
protected Plugins plugins = new Plugins();
4952

@@ -89,18 +92,12 @@ public T setResponsive(final Boolean responsive)
8992
return this.self();
9093
}
9194

92-
/**
93-
* @see #setAnimation(Boolean)
94-
*/
95-
public Boolean getAnimation()
95+
public Object getAnimation()
9696
{
9797
return this.animation;
9898
}
9999

100-
/**
101-
* Default {@code true} Disables the Animation completely if set to {@code false}.
102-
*/
103-
public T setAnimation(final Boolean animation)
100+
public T setAnimation(final Object animation)
104101
{
105102
this.animation = animation;
106103
return this.self();

chartjs-java-model/src/main/java/software/xdev/chartjs/model/options/PieOptions.java

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -16,101 +16,8 @@
1616
package software.xdev.chartjs.model.options;
1717

1818
import software.xdev.chartjs.model.options.animation.PieAnimation;
19-
import software.xdev.chartjs.model.options.elements.ArcElements;
2019

2120

22-
public class PieOptions extends Options<PieOptions, PieAnimation>
21+
public class PieOptions extends DoughnutOptionsBase<PieOptions, PieAnimation>
2322
{
24-
25-
/**
26-
* Default {@code 50 - for doughnut, 0 - for pie}
27-
*
28-
* @see #setCutoutPercentage(Number cutoutPercentage)
29-
*/
30-
protected Number cutoutPercentage;
31-
32-
/**
33-
* Default {@code -0.5 * Math.PI}
34-
*
35-
* @see #setRotation(Number rotation)
36-
*/
37-
protected Number rotation;
38-
39-
/**
40-
* Default {@code 2 * Math.PI}
41-
*
42-
* @see #setCircumference(Number circumference)
43-
*/
44-
protected Number circumference;
45-
46-
protected ArcElements elements;
47-
48-
/**
49-
* @see #setCutoutPercentage(Number cutoutPercentage)
50-
*/
51-
public Number getCutoutPercentage()
52-
{
53-
return this.cutoutPercentage;
54-
}
55-
56-
/**
57-
* The percentage of the chart that is cut out of the middle.
58-
*/
59-
public PieOptions setCutoutPercentage(final Number cutoutPercentage)
60-
{
61-
this.cutoutPercentage = cutoutPercentage;
62-
return this;
63-
}
64-
65-
/**
66-
* @see #setRotation(Number rotation)
67-
*/
68-
public Number getRotation()
69-
{
70-
return this.rotation;
71-
}
72-
73-
/**
74-
* Starting angle to draw arcs from
75-
*/
76-
public PieOptions setRotation(final Number rotation)
77-
{
78-
this.rotation = rotation;
79-
return this;
80-
}
81-
82-
/**
83-
* @see #setCircumference(Number circumference)
84-
*/
85-
public Number getCircumference()
86-
{
87-
return this.circumference;
88-
}
89-
90-
/**
91-
* Sweep to allow arcs to cover
92-
*/
93-
public PieOptions setCircumference(final Number circumference)
94-
{
95-
this.circumference = circumference;
96-
return this;
97-
}
98-
99-
/**
100-
* @return {@link ArcElements} instance, or {@code null} if not set
101-
*/
102-
public ArcElements getElements()
103-
{
104-
return this.elements;
105-
}
106-
107-
/**
108-
* @param elements an {@link ArcElements} instance, or {@code null}
109-
* @return this instance for method chaining
110-
*/
111-
public PieOptions setElements(final ArcElements elements)
112-
{
113-
this.elements = elements;
114-
return this;
115-
}
11623
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/options/animation/DoughnutAnimation.java

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,6 @@
1515
*/
1616
package software.xdev.chartjs.model.options.animation;
1717

18-
public class DoughnutAnimation extends Animation<DoughnutAnimation>
18+
public class DoughnutAnimation extends DoughnutAnimationBase<DoughnutAnimation>
1919
{
20-
/**
21-
* Default {@code true}
22-
*
23-
* @see #setAnimateRotate(Boolean)
24-
*/
25-
protected Boolean animateRotate;
26-
27-
/**
28-
* Default {@code true}
29-
*
30-
* @see #setAnimateScale(Boolean)
31-
*/
32-
protected Boolean animateScale;
33-
34-
/**
35-
* @see #setAnimateRotate(Boolean)
36-
*/
37-
public Boolean getAnimateRotate()
38-
{
39-
return this.animateRotate;
40-
}
41-
42-
/**
43-
* If true, will animate the rotation of the chart.
44-
*/
45-
public DoughnutAnimation setAnimateRotate(final Boolean animateRotate)
46-
{
47-
this.animateRotate = animateRotate;
48-
return this;
49-
}
50-
51-
/**
52-
* @see #setAnimateScale(Boolean)
53-
*/
54-
public Boolean getAnimateScale()
55-
{
56-
return this.animateScale;
57-
}
58-
59-
/**
60-
* If true, will animate scaling the chart.
61-
*/
62-
public DoughnutAnimation setAnimateScale(final Boolean animateScale)
63-
{
64-
this.animateScale = animateScale;
65-
return this;
66-
}
6720
}

0 commit comments

Comments
 (0)