Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a base class for Plugins #32

Open
sebsoftware opened this issue Jul 30, 2020 · 1 comment
Open

Define a base class for Plugins #32

sebsoftware opened this issue Jul 30, 2020 · 1 comment

Comments

@sebsoftware
Copy link

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);
@crazygit
Copy link

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()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants