Commit 41c31e0f authored by Rui Vieira's avatar Rui Vieira

Categorise abstract classes. Add simple histogram.

parent da60ad8d
package org.ruivieira.plotlib;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
public abstract class AbstractPlot<T, U> implements Plot {
public abstract class BinaryAbstractPlot<T, U> extends UnaryAbstractPlot<T> implements Plot {
protected final Converter<T> xs;
protected final Converter<U> ys;
protected Optional<String> colour = Optional.empty();
protected Optional<Double> alpha = Optional.empty();
protected Optional<Coordinate> ylim = Optional.empty();
protected final StringBuilder script = new StringBuilder();
public AbstractPlot(Collection<T> x, Collection<U> y) {
this.xs = new Converter<>(x);
public BinaryAbstractPlot(Collection<T> x, Collection<U> y) {
super(x);
this.ys = new Converter<>(y);
}
public AbstractPlot setYLim(Coordinate c) {
public BinaryAbstractPlot setYLim(Coordinate c) {
this.ylim = Optional.of(c);
return this;
}
......@@ -35,7 +29,7 @@ public abstract class AbstractPlot<T, U> implements Plot {
colour.ifPresent(s -> script.append(", color='").append(s).append("'"));
}
public AbstractPlot setAlpha(Double alpha) {
public BinaryAbstractPlot setAlpha(Double alpha) {
this.alpha = Optional.of(alpha);
return this;
}
......
package org.ruivieira.plotlib;
import java.util.Collection;
public abstract class UnaryAbstractPlot<A> implements Plot {
protected final Converter<A> xs;
protected final StringBuilder script = new StringBuilder();
public UnaryAbstractPlot(Collection<A> x) {
this.xs = new Converter<>(x);
}
}
package org.ruivieira.plotlib.plots;
import org.ruivieira.plotlib.Plot;
import org.ruivieira.plotlib.UnaryAbstractPlot;
import java.util.Collection;
public class Histogram<T> extends UnaryAbstractPlot<T> implements Plot {
public Histogram(Collection<T> x) {
super(x);
}
@Override
public String render() {
script.append("plt.hist(")
.append(xs.getConvertedList());
script.append(")\n");
return script.toString();
}
}
package org.ruivieira.plotlib.plots;
import org.ruivieira.plotlib.AbstractPlot;
import org.ruivieira.plotlib.BinaryAbstractPlot;
import org.ruivieira.plotlib.Arguments;
import org.ruivieira.plotlib.Plot;
import java.util.Collection;
import java.util.Optional;
public class InterpolationPlot<T, U> extends AbstractPlot<T, U> implements Plot {
public class InterpolationPlot<T, U> extends BinaryAbstractPlot<T, U> implements Plot {
int steps;
......
package org.ruivieira.plotlib.plots;
import org.ruivieira.plotlib.AbstractPlot;
import org.ruivieira.plotlib.BinaryAbstractPlot;
import org.ruivieira.plotlib.Arguments;
import org.ruivieira.plotlib.Plot;
import org.ruivieira.plotlib.interfaces.Colour;
......@@ -10,7 +10,7 @@ import org.ruivieira.plotlib.interfaces.Marker;
import java.util.Collection;
import java.util.Optional;
public class LinePlot<T, U> extends AbstractPlot<T, U> implements Plot, Marker<LinePlot>, LineStyle<LinePlot>, Colour<LinePlot> {
public class LinePlot<T, U> extends BinaryAbstractPlot<T, U> implements Plot, Marker<LinePlot>, LineStyle<LinePlot>, Colour<LinePlot> {
private Optional<String> marker = Optional.empty();
private Optional<String> linestyle = Optional.empty();
......
package org.ruivieira.plotlib.plots;
import org.ruivieira.plotlib.AbstractPlot;
import org.ruivieira.plotlib.Converter;
import org.ruivieira.plotlib.BinaryAbstractPlot;
import org.ruivieira.plotlib.Plot;
import org.ruivieira.plotlib.interfaces.Colour;
import org.ruivieira.plotlib.interfaces.Marker;
import org.ruivieira.plotlib.interfaces.MarkerSize;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
public class ScatterPlot<T, U> extends AbstractPlot<T, U> implements Plot, Colour<ScatterPlot>, Marker<ScatterPlot>, MarkerSize<ScatterPlot> {
public class ScatterPlot<T, U> extends BinaryAbstractPlot<T, U> implements Plot, Colour<ScatterPlot>, Marker<ScatterPlot>, MarkerSize<ScatterPlot> {
private Optional<String> marker = Optional.empty();
private Optional<Double> markerSize = Optional.empty();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment