Skip to content

Commit

Permalink
Configuration of plot fonts.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgobbo committed May 26, 2020
1 parent bf9feed commit 4634470
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 77 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
* Added keys(), values() and items() methods do Subsctiptable.Mapped interface (e.g: BS stream value).

* Run Next command (Menu Shell->Run Next).

* Configuration of plot fonts.


### Changed
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/ch/psi/pshell/plot/LinePlotJFree.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ public class LinePlotJFree extends LinePlotBase {
boolean legendVisible;
boolean showTooltips;

public static final Font TICK_LABEL_FONT = new Font(Font.SANS_SERIF, 0, 10);
public static final Font LABEL_FONT = new Font(Font.SANS_SERIF, 0, 11);

AbstractXYDataset dataY1;
AbstractXYDataset dataY2;
NumberAxis axisX2;
Expand Down Expand Up @@ -589,10 +586,11 @@ public TickUnit getCeilingTickUnit(double size) {
chart.getTitle().setPaint(getAxisTextColor());
}
chart.getLegend().setItemPaint(getAxisTextColor());
chart.getLegend().setItemFont(tickLabelFont);
plot.getDomainAxis().setTickLabelPaint(getAxisTextColor());
plot.getDomainAxis().setLabelPaint(getAxisTextColor());
plot.getRangeAxis().setLabelPaint(getAxisTextColor());
plot.getRangeAxis().setTickLabelPaint(getAxisTextColor());
plot.getRangeAxis().setTickLabelPaint(getAxisTextColor());
plot.getDomainAxis().setLabelFont(labelFont);
plot.getRangeAxis().setLabelFont(labelFont);
plot.getDomainAxis().setTickLabelFont(tickLabelFont);
Expand All @@ -602,19 +600,22 @@ public TickUnit getCeilingTickUnit(double size) {
}
}

@Override
public void setLabelFont(Font f) {
labelFont = f;
XYPlot plot = (XYPlot) chart.getPlot();
XYPlot plot = (XYPlot) chart.getPlot();
plot.getDomainAxis().setLabelFont(f);
plot.getRangeAxis().setLabelFont(f);
if (dataY2 == null) {
plot.getRangeAxis(1).setLabelFont(f);
}
}

@Override
public void setTickLabelFont(Font f) {
tickLabelFont = f;
XYPlot plot = (XYPlot) chart.getPlot();
chart.getLegend().setItemFont(f);
plot.getDomainAxis().setTickLabelFont(f);
plot.getRangeAxis().setTickLabelFont(f);
if (dataY2 == null) {
Expand Down Expand Up @@ -1178,7 +1179,7 @@ public void popupMenuCanceled(PopupMenuEvent e) {
// http://www.jfree.org/phpBB2/viewtopic.php?t=12788&highlight=redraw+speed+performance+problem
void showTooltips() {
tooltips = true;
DecimalFormat dm = new DecimalFormat("0.##########");
DecimalFormat dm = new DecimalFormat("0.##########");
getRenderer(1).setBaseToolTipGenerator(new StandardXYToolTipGenerator("x={1} y={2}", dm, dm));
if (getRenderer(2) != null) {
getRenderer(2).setBaseToolTipGenerator(new StandardXYToolTipGenerator("x={1} y={2}", dm, dm));
Expand Down Expand Up @@ -1463,6 +1464,7 @@ public void chartMouseMoved(ChartMouseEvent event) {
pointers[i].setArrowLength(5);
pointers[i].setTipRadius(10);
pointers[i].setLabelOffset(25);
pointers[i].setFont(tickLabelFont);
chart.getXYPlot().addAnnotation(pointers[i]);
} else {
pointers[i].setText(text);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/psi/pshell/plot/MatrixPlotJFree.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ protected void createChart() {
// Set axis: (plus half bin size on both sides), since we plot the bins centered.
xAxis = new NumberAxis("");
yAxis = new NumberAxis("");
xAxis.setTickLabelFont(LinePlotJFree.TICK_LABEL_FONT);
yAxis.setTickLabelFont(LinePlotJFree.TICK_LABEL_FONT);
xAxis.setTickLabelFont(TICK_LABEL_FONT);
yAxis.setTickLabelFont(TICK_LABEL_FONT);
xAxis.setLabelFont(LinePlotJFree.LABEL_FONT);
yAxis.setLabelFont(LinePlotJFree.LABEL_FONT);
xAxis.setLabelPaint(getAxisTextColor());
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ch/psi/pshell/plot/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ default public String getDisplayableValue(double value) {

default void setPlotOutlineColor(Color c) {};

default void setLabelFont(Font f) {}

default void setTickLabelFont(Font f) {}



@Hidden
public static Plot newPlot(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/ch/psi/pshell/plot/PlotBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ abstract public class PlotBase<T extends PlotSeries> extends MonitoredPanel impl

protected static int SNAPSHOT_WIDTH = 1200;
protected static int SNAPSHOT_HEIGHT = 1000;

protected static Font TICK_LABEL_FONT = new Font(Font.SANS_SERIF, 0, 10);
protected static Font LABEL_FONT = new Font(Font.SANS_SERIF, 0, 11);


final Class seriesType;

Expand Down Expand Up @@ -698,6 +702,23 @@ public static Colormap getDefaultColormap() {

return defaultColormap;
}

public static void setDefaultLabelFont(Font font) {
LABEL_FONT = font;
}

public static Font getDefaultLabelFont() {

return LABEL_FONT;
}

public static void setDefaultTickFont(Font font) {
TICK_LABEL_FONT = font;
}

public static Font getDefaultTickFont() {
return TICK_LABEL_FONT;
}

static public int getMarkerSize() {
String str = System.getProperty(PROPERTY_PLOT_MARKER_SIZE);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/psi/pshell/plot/TimePlotJFree.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class TimePlotJFree extends TimePlotBase {
final TimeSeriesCollection data;
final ChartPanel chartPanel;
final Shape marker;
Font tickLabelFont = LinePlotJFree.TICK_LABEL_FONT;
Font tickLabelFont = TICK_LABEL_FONT;
Font labelFont = LinePlotJFree.LABEL_FONT;


Expand Down Expand Up @@ -142,6 +142,7 @@ public void restoreAutoRangeBounds() {
//chartPanel.setMouseZoomable(true, true);
}

@Override
public void setLabelFont(Font f){
labelFont = f;
XYPlot plot = (XYPlot) chart.getPlot();
Expand All @@ -152,6 +153,7 @@ public void setLabelFont(Font f){
}
}

@Override
public void setTickLabelFont(Font f){
tickLabelFont = f;
XYPlot plot = (XYPlot) chart.getPlot();
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ch/psi/pshell/swing/PlotPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class PlotPanel extends MonitoredPanel {
static public Quality DEFAULT_PLOT_QUALITY = Quality.High;
static public PlotLayout DEFAULT_PLOT_LAYOUT = PlotLayout.Vertical;

public static final Font TITLE_FONT = new Font(Font.SANS_SERIF, Font.BOLD, 13);
static Font TITLE_FONT = new Font(Font.SANS_SERIF, Font.BOLD, 13);
public static final int DEFAULT_RANGE_STEPS = 199;

public static final boolean offscreen = App.isOffscreenPlotting();
Expand All @@ -93,6 +93,14 @@ public PlotPanel() {
updating = new AtomicBoolean(false);
prefs = new PlotPreferences();
}

public static void setTitleFont(Font font) {
TITLE_FONT = font;
}

public static Font getTitleFont() {
return TITLE_FONT;
}

static public String getLinePlotImpl() {
String impl = System.getProperty(PROPERTY_PLOT_IMPL_LINE);
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/ch/psi/pshell/ui/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public enum ScriptPopupDialog {
public Font fontShellCommand;
public Font fontOutput;
public Font fontEditor;
public Font fontPlotLabel;
public Font fontPlotTick;
public Font fontPlotTitle;
public int tabSize = 4;
public int contentWidth;
public Color editorBackground;
Expand Down Expand Up @@ -122,6 +125,10 @@ public static Preferences load(String path) {
preferences.fontEditor = fonts[1];
preferences.fontOutput = fonts[2];
preferences.fontShellCommand = fonts[3];
preferences.fontPlotLabel = fonts[4];
preferences.fontPlotTick = fonts[5];
preferences.fontPlotTitle= fonts[6];
new Font(Font.SANS_SERIF, Font.BOLD, 13);
preferences.defaultPanels = getDefaultPanels();
preferences.consoleLocation = DEFAULT_CONSOLE_LOCATION;
//preferences.propagateVariableEvaluation = true;
Expand Down Expand Up @@ -181,12 +188,18 @@ public static Font[] getDefaultFonts() {
? new Font("Lucida Console", 0, 11)
: new Font(Font.MONOSPACED, 0, 13);
Font commandFont = new Font(Font.SANS_SERIF, 0, 13);
Font plotLabelFont = new Font(Font.SANS_SERIF, 0, 11);
Font plotTickFont = new Font(Font.SANS_SERIF, 0, 10);
Font plotTitleFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);

return new Font[]{
editorFont,
editorFont,
editorFont,
commandFont
commandFont,
plotLabelFont,
plotTickFont,
plotTitleFont
};
}

Expand Down
Loading

0 comments on commit 4634470

Please sign in to comment.