software.xdev.chartjs.model.charts.Chart Maven / Gradle / Ivy
/*
* 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.charts;
import com.fasterxml.jackson.annotation.JsonProperty;
import software.xdev.chartjs.model.data.AbstractData;
import software.xdev.chartjs.model.options.Options;
@SuppressWarnings("java:S119") // SELF means the Chart itself... Not a problem
public interface Chart, D extends AbstractData, ?>>
{
/**
* @return type of this {@link Chart} implementation for proper drawing in JavaScript.
*/
@JsonProperty("type")
String getType();
/**
*
* Convert {@code this} instance to Json for use with Chart.js library.
*
*
* @return json representation of {@code this} {@link Chart}
*/
String toJsonNative();
/**
* Same as {@link #toJsonNative()} but also check if the diagram {@link #isDrawable() is drawable}
* @see #toJson()
*/
default String toJson()
{
if(!this.isDrawable())
{
throw new IllegalArgumentException("Chart is not drawable");
}
return this.toJsonNative();
}
/**
*
* Optional check to determine whether the current state of this {@link Chart} implementation instance will
* generate
* a drawable JSON string.
*
*
* Implementations provide a best-effort evaluation, and can not guarantee that the serialized chart will be
* rendered correctly.
*
*
* @return true if {@code this} {@link Chart} is drawable in its current state
*/
boolean isDrawable();
SELF setOptions(final O options);
SELF setData(final D data);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy