Exemple #1
0
  /**
   * Constructor.
   *
   * @param dimNames names of main plot dimensions (typically "X", "Y", etc);
   * @param useAux whether auxiliary axes are used
   * @param useLabel whether point text labelling is used
   * @param errNdim number of axes for which errors can be plotted
   */
  public PlotStateFactory(String[] dimNames, boolean useAux, boolean useLabel, int errNdim) {
    mainDimNames_ = dimNames;
    useAux_ = useAux;
    useLabel_ = useLabel;
    errNdim_ = errNdim;

    gridParam_ = new BooleanParameter("grid");
    gridParam_.setPrompt("Draw grid lines?");
    gridParam_.setDescription(
        new String[] {
          "<p>If true, grid lines are drawn on the plot.", "If false, they are absent.", "</p>",
        });
    gridParam_.setDefault(true);

    seqParam_ = new DefaultMultiParameter("sequence", ',');
    seqParam_.setPrompt("Defines plot order of subsets");
    seqParam_.setUsage("<suffix>,<suffix>,...");
    seqParam_.setDescription(
        new String[] {
          "<p>Can be used to control the sequence in which different",
          "datasets and subsets are plotted.",
          "This will affect which symbols are plotted on top of,",
          "and so potentially obscure,",
          "which other ones.",
          "The value of this parameter is a comma-separated list of the",
          "\"<code>" + TABLE_VARIABLE + SUBSET_VARIABLE + "</code>\"",
          "suffixes which appear on the",
          "parameters which apply to subsets.",
          "The sets which are named",
          "will be plotted in order, so the first-named one will be",
          "at the bottom (most likely to be obscured).",
          "Note that if this parameter is supplied, then only those sets",
          "which are named will be plotted,",
          "so this parameter may also be used to restrict which plots appear",
          "(though it may not be the most efficient way of doing this).",
          "If no explicit value is supplied for this parameter,",
          "sets will be plotted in some sequence decided by STILTS",
          "(probably alphabetic by suffix).",
          "</p>",
        });
    seqParam_.setNullPermitted(true);

    aaParam_ = new BooleanParameter("antialias");
    aaParam_.setPrompt("Use antialiasing for lines?");
    aaParam_.setDescription(
        new String[] {
          "<p>Controls whether lines are drawn using antialiasing,",
          "where applicable.",
          "If lines are drawn to a bitmapped-type graphics output format",
          "setting this parameter to true smooths the lines out by",
          "using gradations of colour for diagonal lines, and setting it",
          "false simply sets each pixel in the line to on or off.",
          "For vector-type graphics output formats, or for cases in which",
          "no diagonal lines are drawn, the setting of this parameter",
          "has no effect.",
          "Setting it true may slow the plot down slightly.",
          "</p>",
        });
    aaParam_.setDefault(true);
  }
Exemple #2
0
    /**
     * Constructor.
     *
     * @param axName axis name
     */
    public AxisParameterSet(String axName) {
      axName_ = axName.toLowerCase();
      loParam_ = new DoubleParameter(axName_ + "lo");
      loParam_.setPrompt("Lower bound for " + axName_ + " axis");
      loParam_.setDescription(
          new String[] {
            "<p>The lower limit for the plotted " + axName_ + " axis.",
            "If not set, a value will be chosen which is low enough",
            "to accommodate all the data.",
            "</p>",
          });
      loParam_.setNullPermitted(true);

      hiParam_ = new DoubleParameter(axName_ + "hi");
      hiParam_.setPrompt("Upper bound for " + axName_ + " axis");
      hiParam_.setDescription(
          new String[] {
            "<p>The upper limit for the plotted " + axName_ + " axis.",
            "If not set, a value will be chosen which is high enough",
            "to accommodate all the data.",
            "</p>",
          });
      hiParam_.setNullPermitted(true);

      logParam_ = new BooleanParameter(axName_ + "log");
      logParam_.setPrompt("Logarithmic scale on " + axName_ + " axis?");
      logParam_.setDescription(
          new String[] {
            "<p>If false (the default), the scale on the " + axName_,
            "axis is linear; if true it is logarithmic.",
            "</p>",
          });
      logParam_.setDefault("false");

      flipParam_ = new BooleanParameter(axName_ + "flip");
      flipParam_.setPrompt("Reversed direction on " + axName_ + "axis?");
      flipParam_.setDescription(
          new String[] {
            "<p>If set true, the scale on the " + axName_ + " axis",
            "will increase in the opposite sense from usual",
            "(e.g. right to left rather than left to right).",
            "</p>",
          });
      flipParam_.setDefault("false");

      labelParam_ = new Parameter(axName_ + "label");
      labelParam_.setPrompt("Label for axis " + axName_);
      labelParam_.setDescription(
          new String[] {
            "<p>Specifies a label to be used for annotating axis " + axName_ + ".",
            "A default values based on the plotted data will be used",
            "if no value is supplied for this parameter.",
            "</p>",
          });
      labelParam_.setNullPermitted(true);
    }
Exemple #3
0
  /**
   * Configures a PlotState object by examining parameter values in a given execution environment.
   * Such an object was presumably previously created by a call to {@link #createPlotState}.
   *
   * @param state plot state to configure
   * @param env execution environment
   */
  protected void configurePlotState(PlotState state, Environment env) throws TaskException {
    int mainNdim = mainDimNames_.length;
    state.setMainNdim(mainNdim);
    String[] paramNames = env.getNames();

    /* Work out which parameter suffixes are being used to identify
     * different tables.  This is done by finding all the parameters
     * which start "table" and pulling off their suffixes.
     * These suffixes are then applied to other parameter stems
     * for obtaining other per-table parameter values. */
    String tPrefix = TABLE_PREFIX;
    String[] tableLabels = getSuffixes(paramNames, tPrefix);
    if (tableLabels.length == 0) {
      tableLabels = new String[] {""};
    }
    Arrays.sort(tableLabels);
    int nTable = tableLabels.length;

    /* Get a list of all the axis names being used.  This includes the
     * main axes and any auxiliary ones. */
    List axNameList = new ArrayList();
    axNameList.addAll(Arrays.asList(mainDimNames_));
    String[] auxLabels;
    if (useAux_) {
      auxLabels = AxisParameterSet.getAuxAxisNames(paramNames);
      Arrays.sort(auxLabels);
      for (int ia = 0; ia < auxLabels.length; ia++) {
        axNameList.add("aux" + auxLabels[ia]);
      }
    } else {
      auxLabels = new String[0];
    }
    String[] allAxNames = (String[]) axNameList.toArray(new String[0]);
    int allNdim = allAxNames.length;

    /* Assemble parameter groups corresponding to each axis. */
    AxisParameterSet[] axParamSets = new AxisParameterSet[allNdim];
    for (int idim = 0; idim < allNdim; idim++) {
      axParamSets[idim] = new AxisParameterSet(allAxNames[idim]);
    }

    /* Construct a PlotData object for the data obtained from each table. */
    PlotData[] datas = new PlotData[nTable];
    String[] coordExprs0 = null;
    StyleFactory styleFactory = createStyleFactory(STYLE_PREFIX);
    List setLabelList = new ArrayList();
    for (int itab = 0; itab < nTable; itab++) {
      String tlabel = tableLabels[itab];
      StarTable table = getInputTable(env, tlabel);
      String[] coordExprs = new String[allNdim];
      for (int idim = 0; idim < allNdim; idim++) {
        Parameter coordParam = axParamSets[idim].createCoordParameter(tlabel);
        if (idim >= mainNdim) {
          coordParam.setNullPermitted(true);
        }
        coordExprs[idim] = coordParam.stringValue(env);
      }
      String[] errExprs = new String[errNdim_];
      for (int idim = 0; idim < errNdim_; idim++) {
        errExprs[idim] = createErrorParameter(mainDimNames_[idim], tlabel).stringValue(env);
      }
      String labelExpr = useLabel_ ? createLabelParameter(tlabel).stringValue(env) : null;
      SubsetDef[] subsetDefs = getSubsetDefinitions(env, tlabel, styleFactory);
      int nset = subsetDefs.length;
      String[] setExprs = new String[nset];
      String[] setNames = new String[nset];
      Style[] setStyles = new Style[nset];
      for (int is = 0; is < nset; is++) {
        SubsetDef sdef = subsetDefs[is];
        setLabelList.add(sdef.label_);
        setExprs[is] = sdef.expression_;
        setNames[is] = sdef.name_;
        setStyles[is] = sdef.style_;
      }
      try {
        TablePlotData plotData =
            createPlotData(
                env, tlabel, table, setExprs, setNames, setStyles, labelExpr, coordExprs, errExprs);
        plotData.checkExpressions();
        datas[itab] = plotData;
      } catch (CompilationException e) {
        throw new TaskException(e.getMessage(), e);
      }
      if (itab == 0) {
        coordExprs0 = coordExprs;
      }
    }

    /* Set up a plot data object which is an aggregation of the data
     * objects from all the input tables. */
    PlotData plotData = new MultiPlotData(datas);

    /* Rearrange the set plot order if required. */
    StringBuffer seqbuf = new StringBuffer();
    for (Iterator it = setLabelList.iterator(); it.hasNext(); ) {
      seqbuf.append(it.next());
      if (it.hasNext()) {
        seqbuf.append(seqParam_.getValueSeparator());
      }
    }
    String seqDefault = seqbuf.toString();
    seqParam_.setDefault(seqDefault);
    String seqString = seqParam_.stringValue(env);
    if (seqString != null && !seqString.equals(seqDefault)) {
      String[] setLabels =
          seqParam_.stringValue(env).split("\\Q" + seqParam_.getValueSeparator() + "\\E");
      int nset = setLabels.length;
      for (int is = 0; is < nset; is++) {
        setLabels[is] = setLabels[is].trim();
      }
      int[] isets = new int[nset];
      for (int is = 0; is < nset; is++) {
        String label = setLabels[is];
        isets[is] = setLabelList.indexOf(label);
        if (isets[is] < 0) {
          String msg =
              "Unknown set identifier \"" + label + "\"; " + "known labels are " + setLabelList;
          throw new ParameterValueException(seqParam_, msg);
        }
      }
      plotData = new SubsetSelectionPlotData(plotData, isets);
    }

    /* Store the calculated plot data object in the plot state. */
    state.setPlotData(plotData);

    /* Configure other per-axis properties. */
    boolean[] logFlags = new boolean[allNdim];
    boolean[] flipFlags = new boolean[allNdim];
    double[][] ranges = new double[allNdim][];
    String[] labels = new String[allNdim];
    for (int idim = 0; idim < allNdim; idim++) {
      AxisParameterSet axParamSet = axParamSets[idim];
      logFlags[idim] = axParamSet.logParam_.booleanValue(env);
      flipFlags[idim] = axParamSet.flipParam_.booleanValue(env);
      ranges[idim] =
          new double[] {
            axParamSet.loParam_.doubleValue(env), axParamSet.hiParam_.doubleValue(env),
          };
      String labelDefault = coordExprs0[idim];
      if (labelDefault == null || labelDefault.trim().length() == 0) {
        labelDefault = idim < mainNdim ? mainDimNames_[idim] : "Aux " + (idim - mainNdim + 1);
      }
      axParamSet.labelParam_.setDefault(labelDefault);
      labels[idim] = axParamSet.labelParam_.stringValue(env);
    }
    state.setLogFlags(logFlags);
    state.setFlipFlags(flipFlags);
    state.setRanges(ranges);
    state.setAxisLabels(labels);

    /* Configure per-auxiliary axis properties. */
    Shader[] shaders = new Shader[auxLabels.length];
    ShaderParameter[] shaderParams = createShaderParameters(auxLabels);
    for (int ia = 0; ia < auxLabels.length; ia++) {
      shaders[ia] = shaderParams[ia].shaderValue(env);
    }
    state.setShaders(shaders);

    /* Configure other properties. */
    state.setGrid(gridParam_.booleanValue(env));
    state.setAntialias(aaParam_.booleanValue(env));
  }