/** * Obtains the subset definition object from the environment for a given table. * * @param env execution environment * @param tlabel table parameter label * @param styleFactory factory which can examine the environment for plotting style information */ private SubsetDef[] getSubsetDefinitions( Environment env, String tlabel, StyleFactory styleFactory) throws TaskException { /* Work out which parameter suffixes are being used to identify * different subsets for the table with parameter suffix tlabel. * This is done by finding all the parameters which start * "subset"+tlabel and pulling off their suffixes. These suffixes * are then applied to other parameter stems for obtaining other * per-subset parameter values. */ String[] paramNames = env.getNames(); String stPrefix = SUBSET_PREFIX + tlabel; String[] subLabels = getSuffixes(paramNames, stPrefix); Arrays.sort(subLabels); int nset = subLabels.length; /* If there are no subsets for this table, consider it the same as * a single subset with inclusion of all points. */ if (nset == 0) { Parameter nameParam = createSubsetNameParameter(tlabel); nameParam.setDefault(tlabel); String name = nameParam.stringValue(env); return new SubsetDef[] { new SubsetDef(tlabel, "true", name, styleFactory.getStyle(env, tlabel)), }; } /* If there is at least one subset, gather the information required * to construct a SubsetDef object describing its characteristics. */ else { SubsetDef[] sdefs = new SubsetDef[nset]; for (int is = 0; is < nset; is++) { String stLabel = tlabel + subLabels[is]; String expr = createSubsetExpressionParameter(stLabel).stringValue(env); Parameter nameParam = createSubsetNameParameter(stLabel); nameParam.setDefault(expr); String name = nameParam.stringValue(env); sdefs[is] = new SubsetDef(stLabel, expr, name, styleFactory.getStyle(env, stLabel)); } return sdefs; } }
/** * 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)); }