1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| private JCDefaultDataSource updateDataSource(JCDefaultDataSource dataSource,
ObjectiveFunction of) {
isMonitoring = true;
// string value label ?
String name = of.getName();
int nbIteration = of.getValues().length;
// initialize variables
ArrayList<Double> datas = new ArrayList<Double>();
String[] intervalLabel = new String[nbIteration];
for (int i = 0; i < nbIteration; i++) {
double value = 0;
for (int j = 0; j < of.getDynamicDataCount(); j++) {
ObjectiveFunctionData data = of.getDynamicData(j);
value += ObjectiveFunctionHelper.getValues(of, data, contextsMap)[i];
}
intervalLabel[i] = String.valueOf(i + 1);
datas.add(value);
}
double[] tmp = new double[datas.size()];
for (int i = 0; i < tmp.length; i++) {
tmp[i] = datas.get(i);
}
// define data source
double[][] x = new double[1][1];
double[][] y = new double[tmp.length][1];
String[] variableLabel = new String[1]; // define simulation
x[0][0] = getSerieLabel(getModelObject(of.getCurrentContext())) - 1;
variableLabel[0] = "" + name; //$NON-NLS-1$
for (int i = 0; i < tmp.length; i++) {
y[i][0] = tmp[i];
}
dataSource.setData(x, y);
dataSource.setSeriesLabels(intervalLabel);
dataSource.setPointLabels(variableLabel);
dataSource.setName(of.getName());
return dataSource;
}
private void initializePlot() {
dataSources = new ArrayList<JCDefaultDataSource>();
int nb = arrayObjectiveFunction.size();
for (int i = 0; i < nb; i++) {
dataSources.add(createDataSource(arrayObjectiveFunction.get(i)));
}
chart = new JCChart();
// il y a quelque developpement a faire ici sur les datasources.
/* JCDefaultChartLabelManager */chartLabelManager = new JCDefaultChartLabelManager();
synchronized (chart) {
chart.setWarningDialog(false);
chart.setAllowUserChanges(true);
chart.setTrigger(0, new EventTrigger(0, EventTrigger.PICK));
chart.setTrigger(1, new EventTrigger(Event.CTRL_MASK, EventTrigger.ZOOM));
chart.setTrigger(2, new EventTrigger(Event.SHIFT_MASK, EventTrigger.TRANSLATE));
if (ConstantsChart.CUSTOMIZE_DEBUG) {
chart.setTrigger(3, new EventTrigger(Event.ALT_MASK, EventTrigger.CUSTOMIZE));
}
Color color = colorTheme.getColor(ColorTheme.Key.CHART_BACKGROUND);
chart.setBackground(color);
chart.getChartArea().setOpaque(true);
chart.getChartArea().setBackground(color);
chart.getChartArea().setAxisBoundingBox(true);
color = colorTheme.getColor(ColorTheme.Key.AREA);
chart.getChartArea().getPlotArea().setBackground(color);
chart.getChartArea().getPlotArea().setForeground(Color.black);
chart.getChartArea().getPlotArea().setRightIsDefault(false);
chart.getChartArea().getPlotArea().setRight(1);
chart.getFooter().setForeground(Color.black);
initializeLegend();
chart.getHeader().setVisible(true);
chart.getHeader().setFont(new Font("Helvetica", Font.BOLD | Font.ITALIC, 12)); //$NON-NLS-1$
((JLabel) chart.getHeader()).setText("Ceci est tooujours dans le test");
chart.setChartLabelManager(chartLabelManager);
for (int i = 0; i < dataSources.size(); i++) {
compteur++;
ChartDataView chartDataView = new ChartDataView();
chart.setDataView(i, chartDataView);
synchronized (chartDataView) {
chartDataView.setBatched(true);
int typeChart;
// if (isMonitoring) {
// typeChart = JCChart.BAR;
// }
// else {
typeChart = JCChart.STACKING_BAR;
// }
chartDataView.setChartType(typeChart);
chartDataView.setDataSource(dataSources.get(i));
initColor(chartDataView, arrayObjectiveFunction.get(i));
chartDataView.setAutoLabel(false);
JCBarChartFormat format = (JCBarChartFormat) chartDataView.getChartFormat();
format.setClusterWidth(80);
format.setClusterOverlap(JCBarChartFormat.BAR_CLUSTER_OVERLAP_MIN);
chartDataView.setBatched(false);
chartLabelManager.generateAutoLabels(chartDataView);
chartDataView.setAutoLabel(true);
if (i > 0) {
chartDataView.setVisibleInLegend(false);
}
}
}
initializeAxis();
}
}
/**
* initialize axis
*/
synchronized private void initializeAxis() {
Color color = colorTheme.getColor(ColorTheme.Key.GRID);
JCAxisTitle jcAxisTitleX;
jcAxisTitleX = new JCAxisTitle("Ceci est le Xtest");
jcAxisTitleX.setPlacement(JCLegend.SOUTH);
final JCAxis xAxis = chart.getDataView(0).getXAxis();
xAxis.setTitle(jcAxisTitleX);
xAxis.getGridStyle().setLineColor(color);
xAxis.getGridStyle().getLineStyle().setPattern(JCLineStyle.SHORT_DASH);
xAxis.setPlacement(JCAxis.MIN);
JCLabelGenerator labelGenerator = new JCLabelGenerator() {
public Object makeLabel(double value, int index) {
double val = value;
if (xAxis.isLogarithmic()) {
val = Math.pow(10, value);
}
return getLabel(val);
}
};
// xAxis.setLabelGenerator(labelGenerator);
xAxis.setAnnotationMethod(JCAxis.POINT_LABELS);
xAxis.setGridVisible(true);
AxisUtil.setExtremaLinear(0, 100);
xAxis.setNumSpacing(AxisUtil.getSpacing());
// JCAxis t = chart.getChartArea().getXAxis(0);
// // define x labels
// int nb = chart.getDataView().size();
// JCValueLabel[] valueLabels = new JCValueLabel[nb];
// for (int i = 0; i < valueLabels.length; i++) {
// String name = chart.getDataView(i).getName();
// valueLabels[i] = new JCValueLabel(i, "" + name); //$NON-NLS-1$
// }
// t.setValueLabels(valueLabels);
// resetAxisX();
// xAxis.setMinIsDefault(false);
// xAxis.setMaxIsDefault(false);
// resetAxisX();
// first axis : placement default
JCAxis yAxis = chart.getDataView(0).getYAxis();
JCAxisTitle jcAxisTitleY = new JCAxisTitle("tEST ENCORE");
jcAxisTitleY.setRotation(ChartText.DEG_270);
jcAxisTitleY.setPlacement(JCLegend.WEST);
initializeYAxis(yAxis, jcAxisTitleY, color, true);
} |
Partager