예제 #1
0
  /**
   * Resolves arguments, creates local variables and fills the vars and overlists
   *
   * @param c
   * @return list of arguments
   */
  protected final GeoElement[] resArgsForZip(Command c) {
    // check if there is a local variable in arguments
    int numArgs = c.getArgumentNumber();
    vars = new GeoElement[numArgs / 2];
    over = new GeoList[numArgs / 2];
    Construction cmdCons = (Construction) c.getKernel().getConstruction();

    for (int varPos = 1; varPos < numArgs; varPos += 2) {
      String localVarName = c.getVariableName(varPos);
      if (localVarName == null) {
        throw argErr(app, c.getName(), c.getArgument(varPos));
      }

      // add local variable name to construction

      GeoElement num = null;

      // initialize first value of local numeric variable from initPos

      boolean oldval = cons.isSuppressLabelsActive();
      cons.setSuppressLabelCreation(true);
      GeoList gl = (GeoList) resArg(c.getArgument(varPos + 1))[0];
      cons.setSuppressLabelCreation(oldval);
      num = gl.get(0).copyInternal(cons);

      cmdCons.addLocalVariable(localVarName, num);
      // set local variable as our varPos argument
      c.setArgument(varPos, new ExpressionNode(c.getKernel(), num));
      vars[varPos / 2] = num.toGeoElement();
      over[varPos / 2] = gl;
      // resolve all command arguments including the local variable just
      // created

      // remove local variable name from kernel again

    }
    GeoElement[] arg = resArgs(c);
    for (GeoElement localVar : vars) cmdCons.removeLocalVariable(localVar.getLabel());
    return arg;
  }
 public AlgoNormalQuantilePlot(Construction cons, String label, GeoList inputList) {
   this(cons, inputList);
   outputList.setLabel(label);
 }
  @Override
  public final void compute() {

    // validate
    size = inputList.size();
    if (!inputList.isDefined() || size == 0) {
      outputList.setUndefined();
      return;
    }

    // convert geoList to sorted array of double
    sortedData = new double[size];
    for (int i = 0; i < size; i++) {
      GeoElement geo = inputList.get(i);
      if (geo.isNumberValue()) {
        NumberValue num = (NumberValue) geo;
        sortedData[i] = num.getDouble();

      } else {
        outputList.setUndefined();
        return;
      }
    }
    Arrays.sort(sortedData);

    // create the z values
    calculateZValues(size);

    // prepare output list. Pre-existing geos will be recycled,
    // but extra geos are removed when outputList is too long
    outputList.setDefined(true);
    for (int i = outputList.size() - 1; i >= size; i--) {
      GeoElement extraGeo = outputList.get(i);
      extraGeo.remove();
      outputList.remove(extraGeo);
    }
    int oldListSize = outputList.size();

    // iterate through the sorted data and create the normal quantile points

    boolean suppressLabelCreation = cons.isSuppressLabelsActive();
    cons.setSuppressLabelCreation(true);

    for (int i = 0; i < sortedData.length; i++) {
      if (i < oldListSize) ((GeoPoint) outputList.get(i)).setCoords(sortedData[i], zValues[i], 1.0);
      else outputList.add(new GeoPoint(cons, null, sortedData[i], zValues[i], 1.0));
    }

    // create qq line segment and add it to the list
    outputList.add(getQQLineSegment());

    cons.setSuppressLabelCreation(suppressLabelCreation);
  }
예제 #4
0
  public final GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();

    switch (n) {
      case 0:
        Calendar cal = Calendar.getInstance();
        GeoNumeric ms = new GeoNumeric(cons, cal.get(Calendar.MILLISECOND));
        GeoNumeric secs = new GeoNumeric(cons, cal.get(Calendar.SECOND));
        GeoNumeric mins = new GeoNumeric(cons, cal.get(Calendar.MINUTE));
        GeoNumeric hours = new GeoNumeric(cons, cal.get(Calendar.HOUR_OF_DAY));
        GeoNumeric date = new GeoNumeric(cons, cal.get(Calendar.DAY_OF_MONTH));
        int d = cal.get(Calendar.DAY_OF_WEEK);
        GeoNumeric day = new GeoNumeric(cons, d);
        int m = cal.get(Calendar.MONTH) + 1;
        GeoNumeric month = new GeoNumeric(cons, m);
        GeoNumeric year = new GeoNumeric(cons, cal.get(Calendar.YEAR));
        GeoText monthStr = new GeoText(cons);
        monthStr.setTextString(app.getPlain("Month." + m));

        GeoText dayStr = new GeoText(cons);
        dayStr.setTextString(app.getPlain("Day." + d));

        GeoList list = new GeoList(cons);
        list.setLabel(c.getLabel());

        list.add(ms);
        list.add(secs);
        list.add(mins);
        list.add(hours);
        list.add(date);
        list.add(month);
        list.add(year);
        list.add(monthStr);
        list.add(dayStr);
        list.add(day);
        list.update();

        GeoElement[] ret = {list};
        return ret;

      default:
        throw argNumErr(app, c.getName(), n);
    }
  }