Skip to content

Add point and order attributes to chart dataset #28

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions data/src/main/java/nl/crashdata/chartjs/data/ChartJsDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,24 @@ public interface ChartJsDataset<E extends Serializable> extends Serializable
@JsonProperty("hoverBorderWidth")
List<Integer> getHoverBorderWidth();

@JsonProperty("pointBackgroundColor")
List<ChartJsRGBAColor> getPointBackgroundColor();

@JsonProperty("pointBorderColor")
List<ChartJsRGBAColor> getPointBorderColor();

@JsonProperty("pointBorderWidth")
List<Integer> getPointBorderWidth();

@JsonProperty("pointRadius")
List<Integer> getPointRadius();

@JsonProperty("fill")
ChartJsFill getFill();

@JsonProperty("stack")
String getStack();

@JsonProperty("order")
Integer getOrder();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ public class SimpleChartJsDataset<V extends Serializable> implements ChartJsData

private List<Integer> hoverBorderWidth;

private List<ChartJsRGBAColor> pointBackgroundColor;

private List<ChartJsRGBAColor> pointBorderColor;

private List<Integer> pointBorderWidth;

private List<Integer> pointRadius;

private ChartJsFill fill;

private String stack;

private Integer order;

private List<V> data;

@Override
Expand Down Expand Up @@ -108,13 +118,57 @@ public void setHoverBorderWidth(List<Integer> hoverBorderWidth)
this.hoverBorderWidth = hoverBorderWidth;
}

@Override
public List<ChartJsRGBAColor> getPointBackgroundColor()
{
return pointBackgroundColor;
}

public void setPointBackgroundColor(List<ChartJsRGBAColor> pointBackgroundColor)
{
this.pointBackgroundColor = pointBackgroundColor;
}

@Override
public List<ChartJsRGBAColor> getPointBorderColor()
{
return pointBorderColor;
}

public void setPointBorderColor(List<ChartJsRGBAColor> pointBorderColor)
{
this.pointBorderColor = pointBorderColor;
}

@Override
public List<Integer> getPointBorderWidth()
{
return pointBorderWidth;
}

public void setPointBorderWidth(List<Integer> pointBorderWidth)
{
this.pointBorderWidth = pointBorderWidth;
}

@Override
public List<Integer> getPointRadius()
{
return pointRadius;
}

public void setPointRadius(List<Integer> pointRadius)
{
this.pointRadius = pointRadius;
}

@Override
public ChartJsFill getFill()
{
return fill;
}

public void setFill(ChartJsFill fill)
public void setFill(ChartJsFill fill)
{
this.fill = fill;
}
Expand All @@ -128,6 +182,15 @@ public void setStack(String stack) {
this.stack = stack;
}

@Override
public Integer getOrder() {
return order;
}

public void setOrder(Integer order) {
this.order = order;
}

@Override
public List<V> getData()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ public class SimpleChartJsDatasetBuilder<E extends Serializable>

private List<Integer> hoverBorderWidth;

private List<ChartJsRGBAColor> pointBackgroundColor;

private List<ChartJsRGBAColor> pointBorderColor;

private List<Integer> pointBorderWidth;

private List<Integer> pointRadius;

private String label;

private ChartJsFill fill = ChartJsFill.DISABLED;

private String stack;

private Integer order;

private List<E> data = new ArrayList<>();

public SimpleChartJsDatasetBuilder<E>
Expand Down Expand Up @@ -74,6 +84,31 @@ public SimpleChartJsDatasetBuilder<E> withHoverBorderWidths(List<Integer> hoverB
return this;
}

public SimpleChartJsDatasetBuilder<E>
withPointBackgroundColors(List<ChartJsRGBAColor> pointBackgroundColors)
{
this.pointBackgroundColor = pointBackgroundColors;
return this;
}

public SimpleChartJsDatasetBuilder<E> withPointBorderColors(List<ChartJsRGBAColor> pointBorderColors)
{
this.pointBorderColor = pointBorderColors;
return this;
}

public SimpleChartJsDatasetBuilder<E> withPointBorderWidths(List<Integer> pointBorderWidths)
{
this.pointBorderWidth = pointBorderWidths;
return this;
}

public SimpleChartJsDatasetBuilder<E> withPointRadiuses(List<Integer> pointRadiuses)
{
this.pointRadius = pointRadiuses;
return this;
}

public SimpleChartJsDatasetBuilder<E> withBackgroundColor(ChartJsRGBAColor backgroundColor)
{
this.backgroundColor = Collections.singletonList(backgroundColor);
Expand Down Expand Up @@ -111,6 +146,30 @@ public SimpleChartJsDatasetBuilder<E> withHoverBorderWidth(Integer hoverBorderWi
return this;
}

public SimpleChartJsDatasetBuilder<E> withPointBackgroundColor(ChartJsRGBAColor pointBackgroundColor)
{
this.pointBackgroundColor = Collections.singletonList(pointBackgroundColor);
return this;
}

public SimpleChartJsDatasetBuilder<E> withPointBorderColor(ChartJsRGBAColor pointBorderColor)
{
this.pointBorderColor = Collections.singletonList(pointBorderColor);
return this;
}

public SimpleChartJsDatasetBuilder<E> withPointBorderWidth(Integer pointBorderWidth)
{
this.pointBorderWidth = Collections.singletonList(pointBorderWidth);
return this;
}

public SimpleChartJsDatasetBuilder<E> withPointRadius(Integer pointRadius)
{
this.pointRadius = Collections.singletonList(pointRadius);
return this;
}

public SimpleChartJsDatasetBuilder<E> withLabel(String label)
{
this.label = label;
Expand All @@ -123,6 +182,12 @@ public SimpleChartJsDatasetBuilder<E> withStack(String stack)
return this;
}

public SimpleChartJsDatasetBuilder<E> withOrder(Integer order)
{
this.order = order;
return this;
}

public SimpleChartJsDatasetBuilder<E> withDataPoints(List<E> dataPoints)
{
this.data = dataPoints;
Expand Down Expand Up @@ -163,9 +228,14 @@ public SimpleChartJsDataset<E> build() throws IllegalStateException
ret.setHoverBackgroundColor(hoverBackgroundColor);
ret.setHoverBorderColor(hoverBorderColor);
ret.setHoverBorderWidth(hoverBorderWidth);
ret.setPointBackgroundColor(pointBackgroundColor);
ret.setPointBorderColor(pointBorderColor);
ret.setPointBorderWidth(pointBorderWidth);
ret.setPointRadius(pointRadius);
ret.setData(data);
ret.setFill(fill);
ret.setStack(stack);
ret.setOrder(order);
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import nl.crashdata.chartjs.data.ChartJsConfig;
import nl.crashdata.chartjs.data.ChartJsDataset;
import nl.crashdata.chartjs.serialization.ChartJsObjectMapperFactory;
import nl.crashdata.chartjs.wicket.resources.ChartJSCSSResourceReference;
import nl.crashdata.chartjs.wicket.resources.ChartJSJavaScriptResourceReference;
import nl.crashdata.chartjs.wicket.resources.ChartJsCssResourceReference;
import nl.crashdata.chartjs.wicket.resources.ChartJsJavaScriptResourceReference;

public class SimpleGraphPanel<T extends ChartJsConfig< ? >> extends GenericPanel<T>
{
Expand Down Expand Up @@ -50,8 +50,8 @@ public void renderHead(IHeaderResponse response)
super.renderHead(response);

response
.render(JavaScriptHeaderItem.forReference(ChartJSJavaScriptResourceReference.get()));
response.render(CssHeaderItem.forReference(ChartJSCSSResourceReference.get()));
.render(JavaScriptHeaderItem.forReference(ChartJsJavaScriptResourceReference.get()));
response.render(CssHeaderItem.forReference(ChartJsCssResourceReference.get()));
response.render(OnDomReadyHeaderItem
.forScript("moment.locale('" + Session.get().getLocale().toLanguageTag() + "');\n"
+ "Chart.platform.disableCSSInjection = true;\n" + "document.getElementById(\""
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nl.crashdata.chartjs.wicket.resources;

import static nl.crashdata.chartjs.wicket.resources.ChartJSJavaScriptResourceReference.*;
import static nl.crashdata.chartjs.wicket.resources.ChartJsJavaScriptResourceReference.*;

import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.request.resource.JavaScriptResourceReference;

public final class ChartJSJavaScriptResourceReference extends JavaScriptResourceReference
public final class ChartJsJavaScriptResourceReference extends JavaScriptResourceReference
{
private static final long serialVersionUID = 1L;

static final String CHARTJS_VERSIONED_NAME = "chart.v2.9.3";

private static final String CHARTJS_JS_NAME = CHARTJS_VERSIONED_NAME + ".js";

private static final ChartJSJavaScriptResourceReference INSTANCE =
new ChartJSJavaScriptResourceReference();
private static final ChartJsJavaScriptResourceReference INSTANCE =
new ChartJsJavaScriptResourceReference();

private ChartJSJavaScriptResourceReference()
private ChartJsJavaScriptResourceReference()
{
super(ChartJSJavaScriptResourceReference.class, CHARTJS_JS_NAME);
super(ChartJsJavaScriptResourceReference.class, CHARTJS_JS_NAME);
}

public static ChartJSJavaScriptResourceReference get()
public static ChartJsJavaScriptResourceReference get()
{
return INSTANCE;
}
Expand Down