Skip to content

Commit

Permalink
[1266] WIP styles
Browse files Browse the repository at this point in the history
Bug: #1266
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
  • Loading branch information
florianbarbin committed Jun 15, 2022
1 parent fbc4946 commit 2924c87
Show file tree
Hide file tree
Showing 58 changed files with 3,551 additions and 59 deletions.
Expand Up @@ -17,14 +17,17 @@
import java.util.List;
import java.util.Objects;

import org.eclipse.sirius.components.annotations.Immutable;
import org.eclipse.sirius.components.charts.IChart;
import org.eclipse.sirius.components.charts.barchart.components.BarChartStyle;

/**
* Root concept of the bar-chart representation.
*
* @author fbarbin
*/
public class BarChart implements IChart {
@Immutable
public final class BarChart implements IChart {
public static final String KIND = "BarChart"; //$NON-NLS-1$

private String id;
Expand All @@ -37,16 +40,10 @@ public class BarChart implements IChart {

private List<BarChartEntry> entries;

public BarChart() {
// Used by Jackson
}
private BarChartStyle style;

public BarChart(String id, String descriptionId, String label, List<BarChartEntry> entries) {
this.id = Objects.requireNonNull(id);
this.descriptionId = Objects.requireNonNull(descriptionId);
this.label = Objects.requireNonNull(label);
this.kind = KIND;
this.entries = new ArrayList<>(Objects.requireNonNull(entries));
private BarChart() {
// Prevent instantiation
}

@Override
Expand All @@ -73,10 +70,72 @@ public List<BarChartEntry> getEntries() {
return this.entries;
}

public BarChartStyle getStyle() {
return this.style;
}

public static Builder newBarChart(String id) {
return new Builder(id);
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, descriptionId: {2}, label: {3}, kind: {4}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.descriptionId, this.label, this.kind);
}

/**
* The builder of the bar-chart element props.
*
* @author fbarbin
*/
@SuppressWarnings("checkstyle:HiddenField")
public static final class Builder {

private String id;

private String descriptionId;

private String label;

private List<BarChartEntry> entries;

private BarChartStyle style;

public Builder(String id) {
this.id = Objects.requireNonNull(id);
}

public Builder descriptionId(String descriptionId) {
this.descriptionId = Objects.requireNonNull(descriptionId);
return this;
}

public Builder label(String label) {
this.label = Objects.requireNonNull(label);
return this;

}

public Builder entries(List<BarChartEntry> entries) {
this.entries = new ArrayList<>(entries);
return this;
}

public Builder style(BarChartStyle style) {
this.style = Objects.requireNonNull(style);
return this;
}

public BarChart build() {
BarChart barChart = new BarChart();
barChart.id = Objects.requireNonNull(this.id);
barChart.descriptionId = Objects.requireNonNull(this.descriptionId);
barChart.label = Objects.requireNonNull(this.label);
barChart.kind = KIND;
barChart.entries = Objects.requireNonNull(this.entries);
barChart.style = this.style;
return barChart;
}
}
}
Expand Up @@ -18,8 +18,9 @@
import java.util.UUID;

import org.eclipse.sirius.components.charts.barchart.BarChart;
import org.eclipse.sirius.components.charts.barchart.BarChartDescription;
import org.eclipse.sirius.components.charts.barchart.descriptions.BarChartDescription;
import org.eclipse.sirius.components.charts.barchart.elements.BarChartElementProps;
import org.eclipse.sirius.components.charts.barchart.elements.BarChartElementProps.Builder;
import org.eclipse.sirius.components.representations.Element;
import org.eclipse.sirius.components.representations.IComponent;
import org.eclipse.sirius.components.representations.VariableManager;
Expand Down Expand Up @@ -47,16 +48,20 @@ public Element render() {
String label = barChartDescription.getLabelProvider().apply(variableManager);
List<Number> values = barChartDescription.getValuesProvider().apply(variableManager);
List<String> keys = barChartDescription.getKeysProvider().apply(variableManager);
BarChartStyle barChartStyle = barChartDescription.getStyleProvider().apply(variableManager);

// @formatter:off
BarChartElementProps barChartElementProps = BarChartElementProps.newBarChartElementProps(id)
Builder builder = BarChartElementProps.newBarChartElementProps(id)
.label(label)
.descriptionId(barChartDescription.getId())
.values(values)
.keys(keys)
.build();
.keys(keys);
// @formatter:on

if (barChartStyle != null) {
builder.style(barChartStyle);
}
BarChartElementProps barChartElementProps = builder.build();
return new Element(BarChartElementProps.TYPE, barChartElementProps);
}

Expand Down
Expand Up @@ -16,7 +16,7 @@
import java.util.Optional;

import org.eclipse.sirius.components.charts.barchart.BarChart;
import org.eclipse.sirius.components.charts.barchart.BarChartDescription;
import org.eclipse.sirius.components.charts.barchart.descriptions.BarChartDescription;
import org.eclipse.sirius.components.representations.IProps;
import org.eclipse.sirius.components.representations.VariableManager;

Expand Down
@@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.charts.barchart.components;

import java.text.MessageFormat;
import java.util.Objects;

/**
* The style of a BarChart.
*
* @author fbarbin
*/
public final class BarChartStyle {

private String barsColor;

private BarChartStyle() {
// prevent instantiation
}

public String getBarsColor() {
return this.barsColor;
}

public static Builder newBarChartStyle() {
return new Builder();
}

@Override
public String toString() {
String pattern = "{0} '{'barsColor: {1}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.barsColor);
}

/**
* Builder used to create the BarChart style.
*
* @author fbarbin
*/
@SuppressWarnings("checkstyle:HiddenField")
public static final class Builder {
private String barsColor;

public Builder barsColor(String barsColor) {
this.barsColor = Objects.requireNonNull(barsColor);
return this;
}

public BarChartStyle build() {
BarChartStyle barChartStyle = new BarChartStyle();
barChartStyle.barsColor = this.barsColor; // optional.
return barChartStyle;
}
}

}
Expand Up @@ -10,13 +10,14 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.charts.barchart;
package org.eclipse.sirius.components.charts.barchart.descriptions;

import java.util.List;
import java.util.Objects;
import java.util.function.Function;

import org.eclipse.sirius.components.annotations.Immutable;
import org.eclipse.sirius.components.charts.barchart.components.BarChartStyle;
import org.eclipse.sirius.components.charts.descriptions.IChartDescription;
import org.eclipse.sirius.components.representations.VariableManager;

Expand All @@ -38,8 +39,10 @@ public final class BarChartDescription implements IChartDescription {

private Function<VariableManager, List<String>> keysProvider;

private Function<VariableManager, BarChartStyle> styleProvider;

private BarChartDescription() {
// prevent instantiation;
// prevent instantiation
}

@Override
Expand All @@ -64,6 +67,10 @@ public Function<VariableManager, List<String>> getKeysProvider() {
return this.keysProvider;
}

public Function<VariableManager, BarChartStyle> getStyleProvider() {
return this.styleProvider;
}

public static Builder newBarChartDescription(String id) {
return new Builder(id);
}
Expand All @@ -85,6 +92,8 @@ public static final class Builder {

private Function<VariableManager, List<String>> keysProvider;

private Function<VariableManager, BarChartStyle> styleProvider = variableManager -> null;

public Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand All @@ -109,13 +118,19 @@ public Builder keysProvider(Function<VariableManager, List<String>> keysProvider
return this;
}

public Builder styleProvider(Function<VariableManager, BarChartStyle> styleProvider) {
this.styleProvider = Objects.requireNonNull(styleProvider);
return this;
}

public BarChartDescription build() {
BarChartDescription barChartDescription = new BarChartDescription();
barChartDescription.id = Objects.requireNonNull(this.id);
barChartDescription.label = Objects.requireNonNull(this.label);
barChartDescription.labelProvider = Objects.requireNonNull(this.labelProvider);
barChartDescription.valuesProvider = Objects.requireNonNull(this.valuesProvider);
barChartDescription.keysProvider = Objects.requireNonNull(this.keysProvider);
barChartDescription.styleProvider = Objects.requireNonNull(this.styleProvider);
return barChartDescription;
}
}
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.util.Objects;

import org.eclipse.sirius.components.annotations.Immutable;
import org.eclipse.sirius.components.charts.barchart.components.BarChartStyle;
import org.eclipse.sirius.components.representations.IProps;

/**
Expand All @@ -38,6 +39,8 @@ public final class BarChartElementProps implements IProps {

private List<String> keys;

private BarChartStyle style;

private BarChartElementProps() {
// prevent instantiation
}
Expand All @@ -62,6 +65,10 @@ public List<String> getKeys() {
return this.keys;
}

public BarChartStyle getStyle() {
return this.style;
}

public static Builder newBarChartElementProps(String id) {
return new Builder(id);
}
Expand All @@ -83,6 +90,8 @@ public static final class Builder {

private List<String> keys;

private BarChartStyle style;

public Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand All @@ -107,13 +116,19 @@ public Builder keys(List<String> keys) {
return this;
}

public Builder style(BarChartStyle style) {
this.style = Objects.requireNonNull(style);
return this;
}

public BarChartElementProps build() {
BarChartElementProps barChartElementProps = new BarChartElementProps();
barChartElementProps.id = Objects.requireNonNull(this.id);
barChartElementProps.descriptionId = Objects.requireNonNull(this.descriptionId);
barChartElementProps.label = Objects.requireNonNull(this.label);
barChartElementProps.values = Objects.requireNonNull(this.values);
barChartElementProps.keys = Objects.requireNonNull(this.keys);
barChartElementProps.style = this.style;
return barChartElementProps;
}
}
Expand Down

0 comments on commit 2924c87

Please sign in to comment.