Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Chart implements Serializable {

private ChartType type;

private ChartData<?> data = new ChartData<>();
private ChartData data = new ChartData();

private ChartOptions options;

Expand All @@ -43,11 +43,11 @@ public void setType(final ChartType type) {
this.type = type;
}

public ChartData<?> getData() {
public ChartData getData() {
return data;
}

public void setData(final ChartData<?> data) {
public void setData(final ChartData data) {
this.data = data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected void respond(final AjaxRequestTarget target) {
public void renderHead(final Component component, final IHeaderResponse response) {
super.renderHead(component, response);

if (component.getParent() instanceof final ChartJSPanel components) {
if (component.getParent() instanceof ChartJSPanel components) {
response.render(OnDomReadyHeaderItem.forScript(
components.generateChart(component.getMarkupId())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ChartData<T extends Dataset> implements Serializable {
public class ChartData implements Serializable {

private static final long serialVersionUID = -8489073681001237058L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
public abstract class Dataset implements Serializable {
public class Dataset implements Serializable {

private static final long serialVersionUID = -9143409945075593686L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ private static Chart build(
final String anyType2,
final Map<String, Long> any2ByRealm) {

final List<String> labels = new ArrayList<>();
final List<Long> userValues = new ArrayList<>();
final List<Long> groupValues = new ArrayList<>();
final List<Long> any1Values = new ArrayList<>();
final List<Long> any2Values = new ArrayList<>();
List<String> labels = new ArrayList<>();
List<Long> userValues = new ArrayList<>();
List<Long> groupValues = new ArrayList<>();
List<Long> any1Values = new ArrayList<>();
List<Long> any2Values = new ArrayList<>();

final Set<String> realmSet = new HashSet<>();
Set<String> realmSet = new HashSet<>();
realmSet.addAll(usersByRealm.keySet());
realmSet.addAll(groupsByRealm.keySet());
if (any1ByRealm != null) {
Expand All @@ -106,10 +106,10 @@ private static Chart build(
List<String> realms = new ArrayList<>(realmSet);
realms.sort(Comparator.naturalOrder());

final int limit = Math.min(realms.size(), MAX_REALMS);
int limit = Math.min(realms.size(), MAX_REALMS);

for (int i = 0; i < limit; i++) {
final String realm = realms.get(i);
String realm = realms.get(i);

labels.add(StringUtils.substringAfterLast(realm, "/"));

Expand All @@ -124,35 +124,35 @@ private static Chart build(
}
}

final Chart chart = new Chart();
Chart chart = new Chart();
chart.setType(ChartType.bar);

chart.getData().getLabels().addAll(labels);

chart.getOptions().setResponsive(true);
chart.getOptions().setMaintainAspectRatio(true);

final TooltipOptions tooltip = new TooltipOptions();
TooltipOptions tooltip = new TooltipOptions();
tooltip.setEnabled(true);

final TooltipCallback callbacks = new TooltipCallback();
TooltipCallback callbacks = new TooltipCallback();
callbacks.setLabel("function(context) {return context.dataset.label + ': ' + context.formattedValue;}");

tooltip.setCallbacks(callbacks);

final Plugins plugins = new Plugins();
Plugins plugins = new Plugins();
plugins.setTooltip(tooltip);

chart.getOptions().setPlugins(plugins);

final Scale x = new Scale();
Scale x = new Scale();
x.setDisplay(true);

final Scale y = new Scale();
Scale y = new Scale();
y.setDisplay(true);
y.setMin(0);

final Scales scales = new Scales();
Scales scales = new Scales();
scales.setX(x);
scales.setY(y);

Expand All @@ -172,8 +172,7 @@ private static Chart build(
}

private static Dataset dataset(final String label, final String color, final List<Long> values) {
final Dataset ds = new Dataset() {
};
Dataset ds = new Dataset();
ds.getLabel().add(label);
ds.getBackgroundColor().add(color);
ds.getBorderColor().add(color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,24 @@ private Pair<Chart, Long> build(final Map<String, Boolean> confCompleteness) {
long donePercentage = total == 0 ? 0 : Math.round((double) done * 100 / total);
long todoPercentage = total == 0 ? 0 : 100 - donePercentage;

final Chart resultChart = new Chart();
Chart resultChart = new Chart();
resultChart.setType(ChartType.doughnut);
resultChart.getOptions().setResponsive(true);
resultChart.getOptions().setMaintainAspectRatio(true);

final TooltipOptions tooltip = new TooltipOptions();
TooltipOptions tooltip = new TooltipOptions();
tooltip.setEnabled(true);

final TooltipCallback callbacks = new TooltipCallback();
TooltipCallback callbacks = new TooltipCallback();
callbacks.setLabel("function(context) {return context.label;}");

tooltip.setCallbacks(callbacks);

final Plugins plugins = new Plugins();
Plugins plugins = new Plugins();
plugins.setTooltip(tooltip);
resultChart.getOptions().setPlugins(plugins);

final Dataset ds = new Dataset() {
};
Dataset ds = new Dataset();
ds.getBackgroundColor().add("green");
ds.getBackgroundColor().add("red");
ds.getBorderColor().add("green");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public LoadWidget(final String id, final SystemInfo systeminfo) {

private static Chart build(final SystemInfo systeminfo) {

final List<Double> cpuValues = new ArrayList<>();
final List<Long> memValues = new ArrayList<>();
final List<String> labels = new ArrayList<>();
List<Double> cpuValues = new ArrayList<>();
List<Long> memValues = new ArrayList<>();
List<String> labels = new ArrayList<>();

systeminfo.load().forEach(instant -> {

Expand All @@ -65,23 +65,21 @@ private static Chart build(final SystemInfo systeminfo) {
memValues.add(instant.totalMemory());
});

Dataset cpu = new Dataset() {
};
Dataset cpu = new Dataset();
cpu.getLabel().add("CPU");
cpu.getData().addAll(cpuValues);
cpu.getBorderColor().add("purple");
cpu.getBackgroundColor().add("purple");
cpu.setTension(0.4);

Dataset mem = new Dataset() {
};
Dataset mem = new Dataset();
mem.getLabel().add("MEM");
mem.getData().addAll(memValues);
mem.getBorderColor().add("grey");
mem.getBackgroundColor().add("grey");
mem.setTension(0.4);

ChartData<Dataset> data = new ChartData<>();
ChartData data = new ChartData();
data.getLabels().addAll(labels);
data.getDatasets().addAll(List.of(cpu, mem));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,28 @@ public UsersByStatusWidget(final String id, final Map<String, Long> usersByStatu
}

private static Chart build(final Map<String, Long> usersByStatus) {
final List<String> labels = new ArrayList<>();
final List<Long> values = new ArrayList<>();
List<String> labels = new ArrayList<>();
List<Long> values = new ArrayList<>();

for (Map.Entry<String, Long> entry : usersByStatus.entrySet()) {
labels.add(entry.getKey());
values.add(entry.getValue());
}

final List<String> colors = new ArrayList<>();
List<String> colors = new ArrayList<>();
for (int i = 0; i < values.size(); i++) {
colors.add(COLORS[i % COLORS.length]);
}

Dataset dataset = new Dataset() {
};
Dataset dataset = new Dataset();
dataset.getData().addAll(values);
dataset.getBackgroundColor().addAll(colors);
dataset.getBorderColor().addAll(colors);

List<Dataset> datasets = new ArrayList<>();
datasets.add(dataset);

ChartData<Dataset> data = new ChartData<>();
ChartData data = new ChartData();
data.getLabels().addAll(labels);
data.getDatasets().addAll(datasets);

Expand Down
Loading