Skip to content

Commit

Permalink
ttools: add grid and axis label colour options for sky plot
Browse files Browse the repository at this point in the history
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent a08d7aa commit 05ec1ba
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
2 changes: 2 additions & 0 deletions topcat/src/docs/sun253.xml
Expand Up @@ -18292,6 +18292,8 @@ introduced since the last version:
can be read.</li>
<li>Fix point counting in layer plots.</li>
<li>Add some padding around auto-ranged plot limits.</li>
<li>Add grid and label colour configuration options to plane and
sky plots.</li>
</ul>
</p></dd>
</dl>
Expand Down
Expand Up @@ -74,6 +74,8 @@ protected SkySys getViewSystem() {
new ConfigSpecifier( new ConfigKey[] {
SkySurfaceFactory.GRID_KEY,
SkySurfaceFactory.SEX_KEY,
StyleKeys.GRID_COLOR,
StyleKeys.AXLABEL_COLOR,
SkySurfaceFactory.CROWD_KEY,
SkySurfaceFactory.AXISLABELLER_KEY,
} ) );
Expand Down
51 changes: 33 additions & 18 deletions ttools/src/main/uk/ac/starlink/ttools/plot2/geom/SkySurface.java
Expand Up @@ -40,8 +40,9 @@ public class SkySurface implements Surface {
private final int gylo_;
private final int gyhi_;
private final SkySys viewSystem_;
private final boolean grid_;
private final SkyAxisLabeller axLabeller_;
private final Color gridColor_;
private final Color axlabelColor_;
private final boolean sexagesimal_;
private final double crowd_;
private final Captioner captioner_;
Expand Down Expand Up @@ -72,23 +73,25 @@ public class SkySurface implements Surface {
* @param yoff y offset of plot centre from plot bounds centre
* in dimensionless units; 0 is centred
* @param viewSystem sky system into which coordinates are projected
* @param grid whether to draw coordinate grid
* @param axLabeller sky axis labelling object
* @param gridColor colour for grid drawing, or null if no grid
* @param axlabelColor colour for axis labels, or null if no labels
* @param sexagesimal whether to use sexagesimal coordinates
* @param crowd tick mark crowding factor, 1 is normal
* @param captioner text rendering object
*/
public SkySurface( Rectangle plotBounds, Projection projection,
double[] rotmat, double zoom, double xoff, double yoff,
SkySys viewSystem, boolean grid,
SkyAxisLabeller axLabeller, boolean sexagesimal,
SkySys viewSystem, SkyAxisLabeller axLabeller,
Color gridColor, Color axlabelColor, boolean sexagesimal,
double crowd, Captioner captioner ) {
gxlo_ = plotBounds.x;
gxhi_ = plotBounds.x + plotBounds.width;
gylo_ = plotBounds.y;
gyhi_ = plotBounds.y + plotBounds.height;
viewSystem_ = viewSystem;
grid_ = grid;
gridColor_ = gridColor;
axlabelColor_ = axlabelColor;
sexagesimal_ = sexagesimal;
crowd_ = crowd;
captioner_ = captioner;
Expand All @@ -115,9 +118,15 @@ public SkySurface( Rectangle plotBounds, Projection projection,
( gxhi_ - gxlo_ ) / gZoom_,
( gyhi_ - gylo_ ) / gZoom_ );
skyFillsBounds_ = projShape.contains( projBounds );
axLabeller_ = axLabeller == null
? SkyAxisLabellers.getAutoLabeller( skyFillsBounds_ )
: axLabeller;
if ( axlabelColor_ == null ) {
axLabeller_ = SkyAxisLabellers.NONE;
}
else if ( axLabeller == null ) {
axLabeller_ = SkyAxisLabellers.getAutoLabeller( skyFillsBounds_ );
}
else {
axLabeller_ = axLabeller;
}
assert this.equals( this );
}

Expand All @@ -133,7 +142,7 @@ public Rectangle getPlotBounds() {
}

public Insets getPlotInsets( boolean withScroll ) {
GridLiner gl = grid_ ? createGridder() : null;
GridLiner gl = gridColor_ == null ? null : createGridder();
return gl == null
? new Insets( 0, 0, 0, 0 )
: axLabeller_.createAxisAnnotation( gl, captioner_ )
Expand Down Expand Up @@ -163,14 +172,16 @@ public void paintBackground( Graphics g ) {
}

public void paintForeground( Graphics g ) {
if ( grid_ ) {
Color color0 = g.getColor();
Graphics2D g2 = (Graphics2D) g;
g2.setColor( Color.GRAY );
GridLiner gl = createGridder();
Color color0 = g.getColor();
Graphics2D g2 = (Graphics2D) g;
GridLiner gl = gridColor_ != null || axlabelColor_ != null
? createGridder()
: null;
if ( gridColor_ != null ) {
if ( gl == null ) {
return;
}
g2.setColor( gridColor_ );
double[][][] lines = gl.getLines();
String[] labels = gl.getLabels();
int nl = labels.length;
Expand All @@ -187,11 +198,13 @@ public void paintForeground( Graphics g ) {
}
g2.draw( path );
}
g2.setColor( Color.BLACK );
}
if ( axlabelColor_ != null ) {
g2.setColor( axlabelColor_ );
axLabeller_.createAxisAnnotation( gl, captioner_ )
.drawLabels( g2 );
g2.setColor( color0 );
}
g2.setColor( color0 );
}

/**
Expand Down Expand Up @@ -632,8 +645,9 @@ public boolean equals( Object o ) {
&& this.xoff_ == other.xoff_
&& this.yoff_ == other.yoff_
&& PlotUtil.equals( this.viewSystem_, other.viewSystem_ )
&& this.grid_ == other.grid_
&& PlotUtil.equals( this.axLabeller_, other.axLabeller_ )
&& PlotUtil.equals( this.gridColor_, other.gridColor_ )
&& PlotUtil.equals( this.axlabelColor_, other.axlabelColor_ )
&& this.sexagesimal_ == other.sexagesimal_
&& this.crowd_ == other.crowd_
&& PlotUtil.equals( this.captioner_, other.captioner_ );
Expand All @@ -656,8 +670,9 @@ public int hashCode() {
code = 23 * code + Float.floatToIntBits( (float) xoff_ );
code = 23 * code + Float.floatToIntBits( (float) yoff_ );
code = 23 * code + PlotUtil.hashCode( viewSystem_ );
code = 23 * code + ( grid_ ? 11 : 77 );
code = 23 * code + PlotUtil.hashCode( axLabeller_ );
code = 23 * code + PlotUtil.hashCode( gridColor_ );
code = 23 * code + PlotUtil.hashCode( axlabelColor_ );
code = 23 * code + ( sexagesimal_ ? 5 : 13 );
code = 23 * code + Float.floatToIntBits( (float) crowd_ );
code = 23 * code + PlotUtil.hashCode( captioner_ );
Expand Down
@@ -1,5 +1,6 @@
package uk.ac.starlink.ttools.plot2.geom;

import java.awt.Color;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -94,12 +95,13 @@ public String valueToString( SkyAxisLabeller labeller ) {

public Surface createSurface( Rectangle plotBounds, Profile p,
SkyAspect aspect ) {

return new SkySurface( plotBounds, aspect.getProjection(),
aspect.getRotation(), aspect.getZoom(),
aspect.getOffsetX(), aspect.getOffsetY(),
p.viewSystem_, p.grid_,
p.axisLabeller_, p.sex_, p.crowd_,
p.captioner_ );
p.viewSystem_, p.axisLabeller_,
p.grid_ ? p.gridColor_ : null, p.axlabelColor_,
p.sex_, p.crowd_, p.captioner_ );
}

public ConfigKey[] getProfileKeys() {
Expand All @@ -111,6 +113,8 @@ public ConfigKey[] getProfileKeys() {
AXISLABELLER_KEY,
SEX_KEY,
CROWD_KEY,
StyleKeys.GRID_COLOR,
StyleKeys.AXLABEL_COLOR,
} ) );
list.addAll( Arrays.asList( StyleKeys.getCaptionerKeys() ) );
return list.toArray( new ConfigKey[ 0 ] );
Expand All @@ -124,9 +128,11 @@ public Profile createProfile( ConfigMap config ) throws ConfigException {
SkyAxisLabeller axLabeller = config.get( AXISLABELLER_KEY );
boolean sex = config.get( SEX_KEY );
double crowd = config.get( CROWD_KEY );
Color gridColor = config.get( StyleKeys.GRID_COLOR );
Color axlabelColor = config.get( StyleKeys.AXLABEL_COLOR );
Captioner captioner = StyleKeys.createCaptioner( config );
return new Profile( proj, reflect, viewSystem, grid, axLabeller,
sex, crowd, captioner );
gridColor, axlabelColor, sex, crowd, captioner );
}

public ConfigKey[] getAspectKeys() {
Expand Down Expand Up @@ -217,6 +223,8 @@ public static class Profile {
private final SkySys viewSystem_;
private final boolean grid_;
private final SkyAxisLabeller axisLabeller_;
private final Color gridColor_;
private final Color axlabelColor_;
private final boolean sex_;
private final double crowd_;
private final Captioner captioner_;
Expand All @@ -229,19 +237,24 @@ public static class Profile {
* @param viewSystem sky system into which coordinates are projected
* @param grid whether to draw coordinate grid
* @param axisLabeller sky axis labelling object
* @param gridColor colour of grid lines
* @param axlabelColor colour of axis labels
* @param sex whether to use sexagesimal coordinates
* @param crowd tick mark crowding factor, 1 is normal
* @param captioner text rendering object
*/
public Profile( Projection projection, boolean reflect,
SkySys viewSystem, boolean grid,
SkyAxisLabeller axisLabeller, boolean sex,
SkyAxisLabeller axisLabeller, Color gridColor,
Color axlabelColor, boolean sex,
double crowd, Captioner captioner ) {
projection_ = projection;
reflect_ = reflect;
viewSystem_ = viewSystem;
grid_ = grid;
axisLabeller_ = axisLabeller;
gridColor_ = gridColor;
axlabelColor_ = axlabelColor;
sex_ = sex;
crowd_ = crowd;
captioner_ = captioner;
Expand Down

0 comments on commit 05ec1ba

Please sign in to comment.