Exemplo n.º 1
0
 /**
  * Applies the data from the graph's template to this chart
  *
  * @param data a Vector<DateValueTuple> of measurements that should be used to scale the lines
  *     returned by the template
  */
 private void applyTemplate(Vector data) {
   if (currentTemplate != null) {
     Vector lines = currentTemplate.getLines(data);
     if (lines != null) {
       Enumeration en = lines.elements();
       while (en.hasMoreElements()) {
         Vector dataPoints = (Vector) en.nextElement();
         for (int i = 0; i < dataPoints.size(); i++) {
           chart.insertItem((LinePointsItem) dataPoints.elementAt(i));
         }
       }
       chart.startNewLine();
     }
   }
 }
Exemplo n.º 2
0
  /** Do the initial setup for the Chart */
  private void init() {
    // #style lineChart
    chart = new LineChart("");
    chart.setUseDefaultColor(false);

    chart.setFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    chart.setDrawAxis(true);
    chart.setPreferredSize(240, 200);
    chart.setMargins(5, 3, 30, 35);
    chart.makeShadowVisible(true);
    chart.setShadowColor(20, 20, 20);
    chart.setColor(0, 0, 0);
    chart.resetData();

    // chart.setMaxYScaleFactor(100);
    // chart.setMaxXScaleFactor(18);
    wec.init();
  }
Exemplo n.º 3
0
 /** Commits the data line (not the template lines), onto the actual chart widget */
 private void applyData() {
   for (int i = 0; i < chartXPointsArray.length; i++) {
     chart.insertItem(
         "", chartYPointsArray[i].intValue(), chartXPointsArray[i].intValue(), 0, 0, 255);
   }
 }
Exemplo n.º 4
0
 /*
  * (non-Javadoc)
  * @see org.javarosa.formmanager.view.chatterbox.widget.ExpandedWidget#updateWidget(org.javarosa.core.model.QuestionDef)
  */
 protected void updateWidget(FormEntryPrompt prompt) {
   currentTemplate = (IGraphTemplate) templates.get(prompt.getPromptAttributes());
   chart.resetData();
   applyTemplate(data);
   applyData();
 }
Exemplo n.º 5
0
  /*
   * (non-Javadoc)
   * @see org.javarosa.formmanager.view.chatterbox.widget.ExpandedWidget#setWidgetValue(java.lang.Object)
   */
  protected void setWidgetValue(Object o) {
    if (o instanceof Vector) {
      data = (Vector) o;

      int numPoints = data.size();

      int scaledRes = resolution / numPoints;

      chartXPointsArray = new Integer[numPoints];
      chartYPointsArray = new Integer[numPoints];

      Long minDate = null;
      Long maxDate = null;

      Integer minVal = null;
      Integer maxVal = null;

      Enumeration en = data.elements();
      while (en.hasMoreElements()) {
        DateValueTuple tuple = (DateValueTuple) en.nextElement();
        long time = tuple.date.getTime();
        if (minDate == null || minDate.longValue() > time) {
          minDate = new Long(time);
        }
        if (maxDate == null || maxDate.longValue() < time) {
          maxDate = new Long(time);
        }

        int val = tuple.value;
        if (minVal == null || minVal.intValue() > val) {
          minVal = new Integer(val);
        }
        if (maxVal == null || maxVal.intValue() < val) {
          maxVal = new Integer(val);
        }
      }

      long dateSpan = maxDate.longValue() - minDate.longValue();
      if (dateSpan == 0) {
        dateSpan = 1;
      }
      // int valSpan = maxVal.intValue() - minVal.intValue();

      long dateRes = dateSpan / numPoints;

      // int valRes = valSpan / numPoints;

      Vector xpoints = new Vector();
      Vector ypoints = new Vector();
      en = data.elements();
      while (en.hasMoreElements()) {
        DateValueTuple tuple = (DateValueTuple) en.nextElement();
        long time = tuple.date.getTime();
        long timeUnit = (time - minDate.longValue()) * scaledRes;
        long scaledTime = (timeUnit / dateRes);
        int intScaled = (int) scaledTime;
        int finalTime = intScaled;
        Integer xPoint = new Integer(finalTime);
        Integer val = new Integer(tuple.value);

        xpoints.addElement(xPoint);
        ypoints.addElement(val);
      }
      xpoints.copyInto(chartXPointsArray);
      ypoints.copyInto(chartYPointsArray);

      // chart.setMaxYScaleFactor((maxVal.intValue()*2)/3);
      // chart.setMinYScaleFactor(minVal.intValue());

      chart.resetData();
      applyTemplate(data);
      applyData();
    }
  }