manipulateChart

/** 
 * Manipulates the given chart. The chart is what you get 
 * by inserting an diagram into the form editor.
 * 
 * 1. Converts the measuring date into the Age of the patient.
 * 2. Centers the diagram on the data series graph.
 * 3. Clears the unnecessary graphs, so there would be shown.
 * 4. The age of the patient will be given in month or years,
 *    depending on the latest measuring date.
 * 
 * NEEDED FUNCTIONS:
 *  - changeGraphDateToPatientAge()
 *  - calculateAge()
 *  - clearSeriesOfDiagram()
 *  - convertXValueFromYearsToMonth
 * 
 * @param diagramToManipulate:
 * The diagram, that shall be manipulated
 * 
 * @param dataGraphIndex:
 * The index of the graph containing the patient's data
 * 
 * @param graphsToClear:
 * Those graph that shall not be shown
 */
function manipulateChart (diagramToManipulate, dataGraphIndex, graphsToClear) {
   /* ======================================== */
   var plot = diagramToManipulate.getChart().getXYPlot();
   var dataGraphIndex = plot.getDataset().getSeriesCount() - 1;
 
   // converts the date to the age of the patient at this point of time
   var ranges = changeGraphDateToPatientAge(getBirthdayOfCurrentPatient(), 
         diagramToManipulate, dataGraphIndex);
 
   if (ranges != null) {
      // centers the diagram on the data series
      plot.getDomainAxis().setRange(ranges[0].getLowerBound() - 0.25, 
            ranges[0].getUpperBound() + 0.25);
      plot.getRangeAxis().setRange(ranges[1].getLowerBound() - 0.25, 
            ranges[1].getUpperBound() + 0.25);
   }
 
   /* Clears the graphs of the boys, if the patient is a girl,
    * or the graph of the girls, if the patient is a boy.
    */
   var graphsToClear = new Array(dataGraphIndex / 2);
   var add;
   if ("male".equals(patient.getGender())) {
      add = 0;
   } else {
      add = graphsToClear.length;
   }
 
   for (var i = 0; i < graphsToClear.length; i++) {
      graphsToClear[i] = i + add;
   }
 
   clearSeriesOfDiagram(diagramToManipulate, graphsToClear);
 
   if (ranges != null && ranges[0].getUpperBound() < 5) {
      /* if the patients age at the latest measuring point is lower 
       * than 5 years, convert the age from years to month, to give 
       * a better overview.
       */
      convertXValueFromYearsToMonth(diagramToManipulate);
 
      // change the description at the x-axis
      plot.getDomainAxis().setLabel(plot.getDomainAxis().
            getLabel().replace("year", "month"));
   } else {
      // change the description at the x-axis
      plot.getDomainAxis().setLabel(plot.getDomainAxis().
            getLabel().replace("month", "year"));
   }
   /* ======================================== */
}