Skip to content

Commit 183f7e6

Browse files
committed
Charts no longer check if they are drawable
Fixes #201
1 parent 5a9c21c commit 183f7e6

File tree

12 files changed

+19
-232
lines changed

12 files changed

+19
-232
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
## 2.0.2
1+
## 2.1.0
2+
* Charts no longer check if they are drawable #198
3+
* ChartJS behavior: If a chart can't be drawn it will render a empty canvas
4+
* Deprecated methods: ``Chart#toJsonNative`` and ``Chart#isDrawable``
25
* Make ``IndexAxis`` available in all options
36

47
## 2.0.1

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/AbstractChart.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public T setDefaultObjectWriter(final ObjectWriter defaultObjectWriter)
100100
}
101101

102102
@Override
103-
public String toJsonNative()
103+
public String toJson()
104104
{
105105
try
106106
{

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/BarChart.java

-44
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import software.xdev.chartjs.model.data.BarData;
1919
import software.xdev.chartjs.model.data.HomogeneousData;
20-
import software.xdev.chartjs.model.dataset.BarDataset;
2120
import software.xdev.chartjs.model.options.BarOptions;
2221
import software.xdev.chartjs.model.options.Options;
2322

@@ -63,47 +62,4 @@ public String getType()
6362
{
6463
return "bar";
6564
}
66-
67-
/**
68-
* {@inheritDoc}
69-
*
70-
* <p>
71-
* A {@code BarChart} is drawable if:
72-
* </p>
73-
* <ul>
74-
* <li>at least one dataset has at least one data point
75-
* <li>an xAxis scale exists with the id of the xAxisID set on a dataset, if
76-
* such an id set
77-
* <li>a yAxis scale exists with the id of the yAxisID set on a dataset, if
78-
* such an id is set
79-
* <li>there is at least one label in the {@link BarData}
80-
* </ul>
81-
*
82-
* @return true if this {@link BarChart} is drawable in its current state
83-
*/
84-
@Override
85-
public boolean isDrawable()
86-
{
87-
if(this.getData().getLabels().isEmpty())
88-
{
89-
return false;
90-
}
91-
boolean sufficientData = false;
92-
for(final BarDataset dataset : this.getData().getDatasets())
93-
{
94-
if(dataset.getXAxisID() != null && !this.hasScaleWithId(dataset.getXAxisID()))
95-
{
96-
return false;
97-
}
98-
if(dataset.getYAxisID() != null && !this.hasScaleWithId(dataset.getYAxisID()))
99-
{
100-
return false;
101-
}
102-
if(!dataset.getData().isEmpty())
103-
{
104-
sufficientData = true;
105-
}
106-
}
107-
return sufficientData;
108-
}
10965
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/BubbleChart.java

-13
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,4 @@ public String getType()
6262
{
6363
return "bubble";
6464
}
65-
66-
/**
67-
* {@inheritDoc}
68-
*
69-
* <p>
70-
* {@code BubbleChart} is drawable if at least one dataset has at least one data point.
71-
* </p>
72-
*/
73-
@Override
74-
public boolean isDrawable()
75-
{
76-
return this.getData() != null && !this.getData().getDatasets().isEmpty();
77-
}
7865
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/Chart.java

+14-24
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,33 @@ public interface Chart<SELF, O extends Options<?, ?>, D extends AbstractData<?,
3030
@JsonProperty("type")
3131
String getType();
3232

33+
/**
34+
* @deprecated As of 2.1.0 {@link #toJson()} has the same functionality and should be used instead
35+
*/
36+
@Deprecated(since = "2.1.0", forRemoval = true)
37+
default String toJsonNative()
38+
{
39+
return this.toJson();
40+
}
41+
3342
/**
3443
* <p>
3544
* Convert {@code this} instance to Json for use with Chart.js library.
3645
* </p>
3746
*
3847
* @return json representation of {@code this} {@link Chart}
3948
*/
40-
String toJsonNative();
49+
String toJson();
4150

4251
/**
43-
* Same as {@link #toJsonNative()} but also check if the diagram {@link #isDrawable() is drawable}
44-
* @see #toJson()
52+
* @deprecated No functionality implemented as of 2.1.0
4553
*/
46-
default String toJson()
54+
@Deprecated(since = "2.1.0", forRemoval = true)
55+
default boolean isDrawable()
4756
{
48-
if(!this.isDrawable())
49-
{
50-
throw new IllegalArgumentException("Chart is not drawable");
51-
}
52-
return this.toJsonNative();
57+
return true;
5358
}
5459

55-
/**
56-
* <p>
57-
* Optional check to determine whether the current state of this {@link Chart} implementation instance will
58-
* generate
59-
* a drawable JSON string.
60-
* </p>
61-
* <p>
62-
* Implementations provide a best-effort evaluation, and can not guarantee that the serialized chart will be
63-
* rendered correctly.
64-
* </p>
65-
*
66-
* @return true if {@code this} {@link Chart} is drawable in its current state
67-
*/
68-
boolean isDrawable();
69-
7060
SELF setOptions(final O options);
7161

7262
SELF setData(final D data);

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/DoughnutChart.java

-13
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,4 @@ public String getType()
6262
{
6363
return "doughnut";
6464
}
65-
66-
/**
67-
* {@inheritDoc}
68-
*
69-
* <p>
70-
* {@code DoughnutChart} is drawable if at least one dataset has at least one data point.
71-
* </p>
72-
*/
73-
@Override
74-
public boolean isDrawable()
75-
{
76-
return this.getData() != null && !this.getData().getDatasets().isEmpty();
77-
}
7865
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/LineChart.java

-33
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import software.xdev.chartjs.model.data.HomogeneousData;
1919
import software.xdev.chartjs.model.data.LineData;
20-
import software.xdev.chartjs.model.dataset.LineDataset;
2120
import software.xdev.chartjs.model.options.LineOptions;
2221
import software.xdev.chartjs.model.options.Options;
2322

@@ -63,36 +62,4 @@ public String getType()
6362
{
6463
return "line";
6564
}
66-
67-
/**
68-
* {@inheritDoc}
69-
*
70-
* <p>
71-
* {@code LineChart} is drawable if at least one dataset has at least one data point.<br> If an xAxisID is set on a
72-
* dataset, an xAxis scale must exist with that id.
73-
* <br>
74-
* If an yAxisID is set on a dataset, a yAxis scale must exist with that id.
75-
* </p>
76-
*/
77-
@Override
78-
public boolean isDrawable()
79-
{
80-
boolean sufficientData = false;
81-
for(final LineDataset dataset : this.getData().getDatasets())
82-
{
83-
if(dataset.getXAxisID() != null && !this.hasScaleWithId(dataset.getXAxisID()))
84-
{
85-
return false;
86-
}
87-
if(dataset.getYAxisID() != null && !this.hasScaleWithId(dataset.getYAxisID()))
88-
{
89-
return false;
90-
}
91-
if(!dataset.getData().isEmpty())
92-
{
93-
sufficientData = true;
94-
}
95-
}
96-
return sufficientData;
97-
}
9865
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/MixedChart.java

-7
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,4 @@ public String getType()
3737
{
3838
return this.type;
3939
}
40-
41-
@Override
42-
public boolean isDrawable()
43-
{
44-
// Warning: Unchecked
45-
return true;
46-
}
4740
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/PieChart.java

-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import software.xdev.chartjs.model.data.HomogeneousData;
1919
import software.xdev.chartjs.model.data.PieData;
20-
import software.xdev.chartjs.model.dataset.PieDataset;
2120
import software.xdev.chartjs.model.options.Options;
2221
import software.xdev.chartjs.model.options.PieOptions;
2322

@@ -63,24 +62,4 @@ public String getType()
6362
{
6463
return "pie";
6564
}
66-
67-
/**
68-
* {@inheritDoc}
69-
*
70-
* <p>
71-
* {@code PieChart} is drawable if at least one dataset has at least one data point.
72-
* </p>
73-
*/
74-
@Override
75-
public boolean isDrawable()
76-
{
77-
for(final PieDataset dataset : this.getData().getDatasets())
78-
{
79-
if(!dataset.getData().isEmpty())
80-
{
81-
return true;
82-
}
83-
}
84-
return false;
85-
}
8665
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/PolarChart.java

-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import software.xdev.chartjs.model.data.HomogeneousData;
1919
import software.xdev.chartjs.model.data.PolarData;
20-
import software.xdev.chartjs.model.dataset.PolarDataset;
2120
import software.xdev.chartjs.model.options.Options;
2221
import software.xdev.chartjs.model.options.PolarOptions;
2322

@@ -63,24 +62,4 @@ public String getType()
6362
{
6463
return "polarArea";
6564
}
66-
67-
/**
68-
* {@inheritDoc}
69-
*
70-
* <p>
71-
* {@code PolarChart} is drawable if at least one dataset has at least two data points.
72-
* </p>
73-
*/
74-
@Override
75-
public boolean isDrawable()
76-
{
77-
for(final PolarDataset dataset : this.getData().getDatasets())
78-
{
79-
if(dataset.getData().size() >= 2)
80-
{
81-
return true;
82-
}
83-
}
84-
return false;
85-
}
8665
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/RadarChart.java

-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import software.xdev.chartjs.model.data.HomogeneousData;
1919
import software.xdev.chartjs.model.data.RadarData;
20-
import software.xdev.chartjs.model.dataset.RadarDataset;
2120
import software.xdev.chartjs.model.options.Options;
2221
import software.xdev.chartjs.model.options.RadarOptions;
2322

@@ -63,24 +62,4 @@ public String getType()
6362
{
6463
return "radar";
6564
}
66-
67-
/**
68-
* {@inheritDoc}
69-
*
70-
* <p>
71-
* {@code RadarChart} is drawable if at least one dataset has at least three data points.
72-
* </p>
73-
*/
74-
@Override
75-
public boolean isDrawable()
76-
{
77-
for(final RadarDataset dataset : this.getData().getDatasets())
78-
{
79-
if(dataset.getData().size() >= 3)
80-
{
81-
return true;
82-
}
83-
}
84-
return false;
85-
}
8665
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/charts/ScatterChart.java

-33
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import software.xdev.chartjs.model.data.HomogeneousData;
1919
import software.xdev.chartjs.model.data.ScatterData;
20-
import software.xdev.chartjs.model.dataset.ScatterDataset;
2120
import software.xdev.chartjs.model.options.LineOptions;
2221
import software.xdev.chartjs.model.options.Options;
2322

@@ -64,36 +63,4 @@ public String getType()
6463
{
6564
return "scatter";
6665
}
67-
68-
/**
69-
* {@inheritDoc}
70-
*
71-
* <p>
72-
* {@code LineChart} is drawable if at least one dataset has at least one data point.<br> If an xAxisID is set on a
73-
* dataset, an xAxis scale must exist with that id.
74-
* <br>
75-
* If an yAxisID is set on a dataset, a yAxis scale must exist with that id.
76-
* </p>
77-
*/
78-
@Override
79-
public boolean isDrawable()
80-
{
81-
boolean sufficientData = false;
82-
for(final ScatterDataset dataset : this.getData().getDatasets())
83-
{
84-
if(dataset.getXAxisID() != null && !this.hasScaleWithId(dataset.getXAxisID()))
85-
{
86-
return false;
87-
}
88-
if(dataset.getYAxisID() != null && !this.hasScaleWithId(dataset.getYAxisID()))
89-
{
90-
return false;
91-
}
92-
if(!dataset.getData().isEmpty())
93-
{
94-
sufficientData = true;
95-
}
96-
}
97-
return sufficientData;
98-
}
9966
}

0 commit comments

Comments
 (0)