Skip to content

Commit 38227c9

Browse files
committed
ensure all bar charts use angled labels for #108; add custom cmd line resolution support
1 parent 4d55ef2 commit 38227c9

File tree

5 files changed

+64
-40
lines changed

5 files changed

+64
-40
lines changed

src/com/ibm/nmon/ReportGenerator.java

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public static void main(String[] args) {
9191
boolean writeChartData = false;
9292

9393
int granularity = -1;
94+
int width = -1;
95+
int height = -1;
9496

9597
for (int i = 0; i < args.length; i++) {
9698
String arg = args[i];
@@ -147,7 +149,7 @@ public static void main(String[] args) {
147149
++i;
148150

149151
if (i > args.length) {
150-
System.err.println("Chart format properties must be specified " + '-' + 'f');
152+
System.err.println("Chart format properties" + " must be specified for " + '-' + 'f');
151153
return;
152154
}
153155

@@ -159,15 +161,15 @@ public static void main(String[] args) {
159161
++i;
160162

161163
if (i > args.length) {
162-
System.err.println("Granularity value must be specified " + '-' + 'g');
164+
System.err.println("Granularity" + " must be specified for " + '-' + 'g');
163165
return;
164166
}
165167

166168
try {
167169
granularity = Integer.parseInt(args[i]) * 1000;
168170
}
169171
catch (NumberFormatException e) {
170-
System.err.println("Granularity value must be an integer " + args[i]);
172+
System.err.println("Granularity" + " value " + args[i] + " must be an integer");
171173
}
172174

173175
break nextarg;
@@ -176,7 +178,7 @@ public static void main(String[] args) {
176178
++i;
177179

178180
if (i > args.length) {
179-
System.err.println("file must be specified for " + '-' + 'h');
181+
System.err.println("file" + " must be specified for " + '-' + 'h');
180182
return;
181183
}
182184

@@ -187,7 +189,7 @@ public static void main(String[] args) {
187189
++i;
188190

189191
if (i > args.length) {
190-
System.err.println("file must be specified for " + '-' + 'i');
192+
System.err.println("file" + " must be specified for " + '-' + 'i');
191193
return;
192194
}
193195

@@ -204,6 +206,36 @@ public static void main(String[] args) {
204206
else if ("nosummary".equals(param)) {
205207
summaryCharts = false;
206208
}
209+
else if ("width".equals(param)) {
210+
++i;
211+
212+
if (i > args.length) {
213+
System.err.println("Width" + " must be specified for " + '-' + '-' + "width");
214+
return;
215+
}
216+
217+
try {
218+
width = Integer.parseInt(args[i]);
219+
}
220+
catch (NumberFormatException e) {
221+
System.err.println("Width" + " value " + args[i] + " must be an integer");
222+
}
223+
}
224+
else if ("height".equals(param)) {
225+
++i;
226+
227+
if (i > args.length) {
228+
System.err.println("Height" + " must be specified for " + '-' + '-' + "height");
229+
return;
230+
}
231+
232+
try {
233+
height = Integer.parseInt(args[i]);
234+
}
235+
catch (NumberFormatException e) {
236+
System.err.println("Height" + " value " + args[i] + " must be an integer");
237+
}
238+
}
207239
else if ("mf".equals(param)) {
208240
++i;
209241

@@ -283,7 +315,7 @@ else if ("chartdata".equals(param)) {
283315
}
284316

285317
ReportGenerator generator = new ReportGenerator(customSummaryCharts, customDataCharts, multiplexedFieldCharts,
286-
multiplexedTypeCharts, granularity);
318+
multiplexedTypeCharts, granularity, width, height);
287319

288320
File outputDirectory = null;
289321

@@ -406,8 +438,23 @@ private static long parseTime(String[] args, int index, char param) {
406438

407439
private boolean writeChartData = false;
408440

441+
private final int width;
442+
private final int height;
443+
409444
private ReportGenerator(List<String> customSummaryCharts, List<String> customDataCharts,
410-
List<String> multiplexedFieldCharts, List<String> multiplexedTypeCharts, int granularity) {
445+
List<String> multiplexedFieldCharts, List<String> multiplexedTypeCharts, int granularity, int width,
446+
int height) {
447+
// use -1 to default to sized set in BaseChartDefinition
448+
if ((width < 1) && (width != -1)) {
449+
throw new IllegalArgumentException("width" + " must be > 0");
450+
}
451+
if (height < 1 && (height != -1)) {
452+
throw new IllegalArgumentException("height" + " must be > 0");
453+
}
454+
455+
this.width = width;
456+
this.height = height;
457+
411458
factory = new ChartFactory(this);
412459
cache = new ReportCache();
413460

@@ -457,7 +504,8 @@ private void parse(List<String> filesToParse) {
457504
if (fileToParse.endsWith(".log") && fileToParse.contains("ReportGenerator")) {
458505
continue;
459506
}
460-
// ignore chart directories from previous executions which may contain CSV files from --rawdata or --chartdata
507+
// ignore chart directories from previous executions
508+
// these may contain CSV files from --rawdata or --chartdata
461509
if (fileToParse.endsWith(".csv") && fileToParse.contains("/charts/")) {
462510
continue;
463511
}
@@ -733,7 +781,8 @@ private boolean saveChart(BaseChartDefinition definition, Iterable<? extends Dat
733781
File chartFile = new File(saveDirectory, definition.getShortName().replace(" ", "_") + ".png");
734782

735783
try {
736-
ChartUtilities.saveChartAsPNG(chartFile, chart, definition.getWidth(), definition.getHeight());
784+
ChartUtilities.saveChartAsPNG(chartFile, chart, width == -1 ? definition.getWidth() : width,
785+
height == -1 ? definition.getHeight() : height);
737786
}
738787
catch (IOException ioe) {
739788
System.err.println("cannot create chart " + chartFile.getName());

src/com/ibm/nmon/gui/chart/ChartFactory.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public ChartFactory(NMONVisualizerApp app) {
3535
this.app = app;
3636

3737
lineChartBuilder = new LineChartBuilder();
38-
lineChartBuilder.addPlugin(new LineChartBuilderPlugin(app));
39-
4038
barChartBuilder = new BarChartBuilder();
4139
intervalChartBuilder = new IntervalChartBuilder();
4240
histogramChartBuilder = new HistogramChartBuilder();
41+
42+
lineChartBuilder.addPlugin(new LineChartBuilderPlugin(app));
4343
}
4444

4545
public void setGranularity(int granularity) {
@@ -67,13 +67,6 @@ public void setFormatter(ChartFormatter formatter) {
6767
histogramChartBuilder.setFormatter(formatter);
6868
}
6969

70-
public void addPlugin(ChartBuilderPlugin plugin) {
71-
lineChartBuilder.addPlugin(plugin);
72-
barChartBuilder.addPlugin(plugin);
73-
intervalChartBuilder.addPlugin(plugin);
74-
histogramChartBuilder.addPlugin(plugin);
75-
}
76-
7770
/**
7871
* Create a chart given a definition and some data.
7972
*

src/com/ibm/nmon/gui/chart/builder/BarChartBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.jfree.chart.axis.NumberAxis;
77
import org.jfree.chart.axis.ValueAxis;
8+
import org.jfree.chart.axis.CategoryLabelPositions;
89

910
import org.jfree.chart.plot.CategoryPlot;
1011

@@ -98,6 +99,9 @@ protected void formatChart() {
9899
plot.getDomainAxis().setCategoryMargin(0.15d);
99100
plot.getDomainAxis().setTickMarksVisible(false);
100101

102+
// assume bar names will usually be hostnames or longer values; draw them on the chart at a 45 degree angle
103+
plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
104+
101105
// position of first bar start and last bar end
102106
// 1.5% of the chart area within the axis will be blank space on each end
103107
plot.getDomainAxis().setLowerMargin(.015);

src/com/ibm/nmon/gui/main/SummaryView.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919

2020
import javax.swing.SwingConstants;
2121

22-
import org.jfree.chart.JFreeChart;
23-
import org.jfree.chart.axis.CategoryLabelPositions;
24-
25-
import org.jfree.chart.plot.CategoryPlot;
26-
2722
import com.ibm.nmon.data.DataSet;
2823

2924
import com.ibm.nmon.interval.Interval;
@@ -32,7 +27,6 @@
3227

3328
import com.ibm.nmon.gui.Styles;
3429
import com.ibm.nmon.gui.chart.BaseChartPanel;
35-
import com.ibm.nmon.gui.chart.builder.ChartBuilderPlugin;
3630

3731
import com.ibm.nmon.gui.report.ReportPanel;
3832

@@ -58,18 +52,6 @@ public SummaryView(NMONVisualizerGui gui) {
5852
singleIntervalReport = new ReportPanel(gui, ReportCache.DEFAULT_SUMMARY_CHARTS_KEY);
5953
singleIntervalReport.setBorder(null); // make consistent with addBorderIfNecessary
6054

61-
singleIntervalReport.addPlugin(new ChartBuilderPlugin() {
62-
@Override
63-
public void configureChart(JFreeChart chart) {
64-
if (chart.getPlot() instanceof CategoryPlot) {
65-
// assume bar names will usually be hostnames
66-
// draw them on the chart at a 45 degree angle
67-
CategoryPlot plot = (CategoryPlot) chart.getPlot();
68-
plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
69-
}
70-
}
71-
});
72-
7355
allIntervalsReport = new ReportPanel(gui, ReportCache.DEFAULT_INTERVAL_CHARTS_KEY);
7456
allIntervalsReport.setBorder(null); // make consistent with addBorderIfNecessary
7557

src/com/ibm/nmon/gui/report/ReportPanel.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,6 @@ public int getPreviousTab() {
288288
return previousTab;
289289
}
290290

291-
public void addPlugin(ChartBuilderPlugin plugin) {
292-
chartFactory.addPlugin(plugin);
293-
}
294-
295291
@Override
296292
public void propertyChange(PropertyChangeEvent evt) {
297293
if ("chart".equals(evt.getPropertyName())) {

0 commit comments

Comments
 (0)