Exemplo n.º 1
0
  public void updateXValues(IScope scope, int chartCycle, int targetNb) {
    Object xval, xlab;
    if (this.useXSource || this.useXLabels) {

      if (this.useXSource) {
        xval = xsource.resolveAgainst(scope).value(scope);
      } else {
        xval = xlabels.resolveAgainst(scope).value(scope);
      }
      if (this.useXLabels) {
        xlab = xlabels.resolveAgainst(scope).value(scope);
      } else {
        xlab = xsource.resolveAgainst(scope).value(scope);
      }

      if (xval instanceof GamaList) {
        IList xv2 = Cast.asList(scope, xval);
        IList xl2 = Cast.asList(scope, xlab);

        if (this.useXSource && xv2.size() > 0 && xv2.get(0) instanceof Number) {
          XSeriesValues = new ArrayList<Double>();
          Xcategories = new ArrayList<String>();
          for (int i = 0; i < xv2.size(); i++) {
            XSeriesValues.add(new Double(Cast.asFloat(scope, xv2.get(i))));
            Xcategories.add(Cast.asString(scope, xl2.get(i)));
          }

        } else {
          if (xv2.size() > Xcategories.size()) {
            Xcategories = new ArrayList<String>();
            for (int i = 0; i < xv2.size(); i++) {
              if (i >= XSeriesValues.size()) {
                XSeriesValues.add(new Double(getXCycleOrPlusOneForBatch(scope, chartCycle)));
              }
              Xcategories.add(Cast.asString(scope, xl2.get(i)));
            }
          }
        }
        if (xv2.size() < targetNb) {
          throw GamaRuntimeException.error(
              "The x-serie length ("
                  + xv2.size()
                  + ") should NOT be shorter than any series length ("
                  + targetNb
                  + ") !",
              scope);
        }

      } else {
        if (this.useXSource && xval instanceof Number) {
          double dvalue = Cast.asFloat(scope, xval);
          String lvalue = Cast.asString(scope, xlab);
          XSeriesValues.add(new Double(dvalue));
          Xcategories.add(lvalue);
        }
        if (targetNb == -1 && !this.forceNoXAccumulate) targetNb = XSeriesValues.size() + 1;
        while (XSeriesValues.size() < targetNb) {
          XSeriesValues.add(new Double(getXCycleOrPlusOneForBatch(scope, chartCycle)));
          Xcategories.add(Cast.asString(scope, xlab));
        }
      }
    }

    if (!this.useXSource && !this.useXLabels) {
      if (targetNb == -1 && !this.forceNoXAccumulate && commonXindex >= XSeriesValues.size())
        targetNb = XSeriesValues.size() + 1;
      while (XSeriesValues.size() < targetNb) {
        addCommonXValue(scope, getXCycleOrPlusOneForBatch(scope, chartCycle));
      }
    }
  }