Skip to content

Commit

Permalink
ttools: generalise ShapeForm to accommodate multiple positions
Browse files Browse the repository at this point in the history
The ShapeMode/ShapeForm colouring machinery can now be used for
multi-point shapes such as links between groups of positions.
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent 9801dc1 commit d501b2d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ttools/src/main/uk/ac/starlink/ttools/plot2/Plotter.java
Expand Up @@ -54,7 +54,7 @@ public interface Plotter<S extends Style> {
* Each of these is turned into a data space position by use of the
* DataGeom presented at layer creation time.
*
* @return number of positional coordinates
* @return number of sets of positional coordinates
*/
int getPositionCount();

Expand Down
Expand Up @@ -42,6 +42,10 @@ public class MarkForm implements ShapeForm {

private static final Color DUMMY_COLOR = Color.GRAY;

public int getPositionCount() {
return 1;
}

public String getFormName() {
return "Mark";
}
Expand Down
Expand Up @@ -33,9 +33,10 @@
import uk.ac.starlink.ttools.plot2.paper.PaperType3D;

/**
* ShapeForm implementation that draws shapes based on the positions of
* more than one data point.
* The actual coordinates required (defining one or more non-central
* ShapeForm implementation that draws shapes based on a single main
* position, and a number of additional positions supplied as
* {@link ShapeForm#getExtraCoords extra} coordinates.
* The extra coordinates required (defining one or more non-central
* data positions) are defined by a supplied {@link MultiPointCoordSet}
* and those coordinates are then plotted by a corresponding
* {@link uk.ac.starlink.ttools.plot.ErrorRenderer}.
Expand Down Expand Up @@ -78,6 +79,10 @@ public MultiPointForm( String name, Icon icon,
rendererKey_ = rendererKey;
}

public int getPositionCount() {
return 1;
}

public String getFormName() {
return name_;
}
Expand Down
Expand Up @@ -126,8 +126,8 @@ Object calculateBinPlan( Surface surface, DataGeom geom,

/**
* Interface to define the actual shape drawing.
* It contains a single method, {@link #paintPoint}, which is called
* once for each point.
* It contains a single method, {@link #paintPoint paintPoint},
* which is called once for each point.
*/
interface ShapePainter {

Expand Down
11 changes: 9 additions & 2 deletions ttools/src/main/uk/ac/starlink/ttools/plot2/layer/ShapeForm.java
Expand Up @@ -10,14 +10,21 @@
/**
* Plotter Form sub-interface for use with ShapeMode.
* This defines the shape of data points plotted, which may be influenced
* by additional data than the actual point position
* (for instance error bar sizes).
* by data other than the actual point position(s), for instance
* error bar sizes.
*
* @author Mark Taylor
* @since 18 Feb 2013
*/
public interface ShapeForm extends ModePlotter.Form {

/**
* Returns the number of data positions per tuple used by this form.
*
* @return number of sets of positional coordinates
*/
int getPositionCount();

/**
* Returns data coordinates additional to the basic position which
* are required to plot a point.
Expand Down
Expand Up @@ -40,7 +40,7 @@ public class ShapePlotter extends AbstractPlotter<ShapeStyle> {
* @param mode colour determiner
*/
public ShapePlotter( String name, ShapeForm form, ShapeMode mode ) {
super( name, form.getFormIcon(), 1,
super( name, form.getFormIcon(), form.getPositionCount(),
PlotUtil.arrayConcat( form.getExtraCoords(),
mode.getExtraCoords() ) );
form_ = form;
Expand Down Expand Up @@ -76,7 +76,7 @@ public PlotLayer createLayer( DataGeom geom, DataSpec dataSpec,
* @return index of first mode-specific coordinate
*/
public int getModeCoordsIndex( DataGeom geom ) {
return geom.getPosCoords().length
return geom.getPosCoords().length * form_.getPositionCount()
+ form_.getExtraCoords().length;
}

Expand Down
Expand Up @@ -51,6 +51,10 @@ public class SizeForm implements ShapeForm {
16, 2, 64, false );
private static final AuxScale SIZE_SCALE = new AuxScale( "globalsize" );

public int getPositionCount() {
return 1;
}

public String getFormName() {
return "Size";
}
Expand Down

0 comments on commit d501b2d

Please sign in to comment.