chart icon indicating copy to clipboard operation
chart copied to clipboard

Define a base class for Plugins

Open sebsoftware opened this issue 5 years ago • 1 comments

Instead of a placeholder object inside the options a Plugins object would be better.

It can be easily integrated as

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, 
getterVisibility = JsonAutoDetect.Visibility.NONE, 
setterVisibility = JsonAutoDetect.Visibility.NONE)

public class Plugins extends HashMap<String, Object> {
	private static final long serialVersionUID = -3402095836685671301L;

}

i.E. a configuration for the color schemes plugin can be set with

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
public class ColorSchemes {

	private String scheme;

	public String getScheme() {
		return this.scheme;
	}

	public ColorSchemes setScheme(final String scheme) {
		this.scheme = scheme;
		return this;
	}

}

and can be set:

	ColorSchemes colorschemes = new ColorSchemes();
	colorschemes.setScheme("tableau.HueCircle19");
	plugins.put("colorschemes", colorschemes);

sebsoftware avatar Jul 30 '20 12:07 sebsoftware

for someone who use kotlin can use mapof() function

fun getChat(): String {
    val dataset = BarDataset()
        .setData(65, 59, 80, 81, 56, 55, 40)
        .addBackgroundColor(Color(255, 99, 132, 0.5))
        .addBorderColor(Color(255, 99, 132))
        .setBorderWidth(1)

    val data = BarData()
        .addLabels("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
        .addDataset(dataset)

    val plugin = mapOf(
        "datalabels" to mapOf(
            "anchor" to "center",
            "align" to "center",
            "color" to "#666",
            "font" to mapOf("weight" to "normal")
        )
    )
    val option = BarOptions()
        .setTitle(Title().setDisplay(true).setText("Sample Bar Chat"))
        .setPlugins(plugin)
    return BarChart(data).setOptions(option).toJson()
}

crazygit avatar Aug 27 '21 08:08 crazygit