-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
chartjs-java-model/src/test/java/software/xdev/chartjs/model/ChartAxisFormatTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright © 2023 XDEV Software (https://xdev.software) | ||
* | ||
* 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 software.xdev.chartjs.model; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import software.xdev.chartjs.model.charts.BarChart; | ||
import software.xdev.chartjs.model.color.Color; | ||
import software.xdev.chartjs.model.data.BarData; | ||
import software.xdev.chartjs.model.dataset.BarDataset; | ||
import software.xdev.chartjs.model.javascript.JavaScriptFunction; | ||
import software.xdev.chartjs.model.options.BarOptions; | ||
import software.xdev.chartjs.model.options.scale.Scales; | ||
import software.xdev.chartjs.model.options.scale.cartesian.linear.LinearScaleOptions; | ||
import software.xdev.chartjs.model.options.scale.cartesian.linear.LinearTickOptions; | ||
|
||
|
||
@SuppressWarnings("java:S2699") // Done in custom method | ||
class ChartAxisFormatTest extends AbstractChartTest | ||
{ | ||
@Test | ||
void axisTickCallback() | ||
{ | ||
this.createScreenshotAndCompare( | ||
new BarChart(data(), options(l -> l.setCallback(new JavaScriptFunction("(label) => `$${label}`")))), | ||
this.getWebContainer(), | ||
"AxisTickCallback"); | ||
} | ||
|
||
@Test | ||
void format() | ||
{ | ||
this.createScreenshotAndCompare( | ||
new BarChart(data(), options(l -> l.setFormat(new CurrencyFormatOptions("currency", "USD")))), | ||
this.getWebContainer(), | ||
"Format"); | ||
} | ||
|
||
public static class CurrencyFormatOptions | ||
{ | ||
private String style; | ||
private String currency; | ||
|
||
public CurrencyFormatOptions() | ||
{ | ||
} | ||
|
||
public CurrencyFormatOptions(final String style, final String currency) | ||
{ | ||
this.style = style; | ||
this.currency = currency; | ||
} | ||
|
||
public String getStyle() | ||
{ | ||
return this.style; | ||
} | ||
|
||
public void setStyle(final String style) | ||
{ | ||
this.style = style; | ||
} | ||
|
||
public String getCurrency() | ||
{ | ||
return this.currency; | ||
} | ||
|
||
public void setCurrency(final String currency) | ||
{ | ||
this.currency = currency; | ||
} | ||
} | ||
|
||
static BarData data() | ||
{ | ||
final BarDataset dataset1 = new BarDataset() | ||
.setData(65) | ||
.addBackgroundColors(Color.RED); | ||
|
||
return new BarData() | ||
.addLabels("First") | ||
.addDataset(dataset1); | ||
} | ||
|
||
static BarOptions options(final Consumer<LinearTickOptions> configureTickOptions) | ||
{ | ||
final LinearTickOptions linearTickOptions = new LinearTickOptions(); | ||
configureTickOptions.accept(linearTickOptions); | ||
|
||
final BarOptions options = new BarOptions().setAnimation(false); | ||
options | ||
.getScales() | ||
.addScale(Scales.ScaleAxis.Y, new LinearScaleOptions() | ||
.setTicks(linearTickOptions)); | ||
return options; | ||
} | ||
} |
Binary file added
BIN
+12.1 KB
...java-model/src/test/resources/screenshotReferences/BarChartAxisTickCallback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.9 KB
chartjs-java-model/src/test/resources/screenshotReferences/BarChartFormat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.