Search in sources :

Example 1 with StyleProperties

use of org.n52.io.request.StyleProperties in project series-rest-api by 52North.

the class RenderingHintsExtension method getExtras.

@Override
public Map<String, Object> getExtras(DatasetOutput output, IoParameters parameters) {
    if (!hasExtrasToReturn(output, parameters)) {
        return Collections.emptyMap();
    }
    if (hasSeriesConfiguration(output)) {
        final StyleProperties style = createStyle(getSeriesStyle(output));
        checkForBackwardCompatiblity(output, style);
        return wrapSingleIntoMap(style);
    } else if (hasPhenomenonConfiguration(output)) {
        final StyleProperties style = createStyle(getPhenomenonStyle(output));
        checkForBackwardCompatiblity(output, style);
        return wrapSingleIntoMap(style);
    }
    LOGGER.error("No rendering style found for {} (id={})", output, output.getId());
    return Collections.emptyMap();
}
Also used : StyleProperties(org.n52.io.request.StyleProperties)

Example 2 with StyleProperties

use of org.n52.io.request.StyleProperties in project series-rest-api by 52North.

the class ChartIoHandler method getDatasetStyleFor.

protected StyleProperties getDatasetStyleFor(String datasetId) {
    Optional<StyleMetadata> optional = context.getStyleMetadataFor(datasetId);
    StyleMetadata styleMetadata = optional.get();
    return styleMetadata.getStyleProperties();
}
Also used : StyleMetadata(org.n52.io.IoStyleContext.StyleMetadata)

Example 3 with StyleProperties

use of org.n52.io.request.StyleProperties in project series-rest-api by 52North.

the class MultipleChartsRenderer method writeDataToChart.

@Override
public void writeDataToChart(DataCollection<Data<QuantityValue>> data) {
    Map<String, Data<QuantityValue>> allTimeseries = data.getAllSeries();
    List<? extends DatasetOutput<?>> timeseriesMetadatas = getMetadataOutputs();
    int rendererCount = timeseriesMetadatas.size();
    for (int rendererIndex = 0; rendererIndex < timeseriesMetadatas.size(); rendererIndex++) {
        /*
             * For each index put data and its renderer configured to a particular style. As each timeseries
             * may define its custom styling and different chart types we have to loop over all timeseries to
             * configure chart rendering.
             */
        DatasetOutput<?> timeseriesMetadata = timeseriesMetadatas.get(rendererIndex);
        String timeseriesId = timeseriesMetadata.getId();
        StyleProperties style = getDatasetStyleFor(timeseriesId);
        Data<QuantityValue> timeseriesData = allTimeseries.get(timeseriesId);
        String chartId = createChartId(timeseriesMetadata);
        ChartIndexConfiguration configuration = new ChartIndexConfiguration(chartId, rendererIndex);
        configuration.setData(timeseriesData, timeseriesMetadata, style);
        configuration.setRenderer(createRenderer(style));
        if (timeseriesData.hasReferenceValues()) {
            int referenceIndex = rendererCount;
            /*
                 * Configure timeseries reference value renderers with the same metadata and add it at the end
                 * of the plot's renderer list.
                 */
            DatasetMetadata<QuantityValue> metadata = timeseriesData.getMetadata();
            Map<String, Data<QuantityValue>> referenceValues = metadata.getReferenceValues();
            for (Entry<String, Data<QuantityValue>> referencedTimeseries : referenceValues.entrySet()) {
                String referenceTimeseriesId = referencedTimeseries.getKey();
                ReferenceValueOutput<?> referenceOutput = getReferenceValue(referenceTimeseriesId, timeseriesMetadata);
                String referenceChartId = createChartId(timeseriesMetadata, referenceOutput.getLabel());
                Data<QuantityValue> referenceData = referenceValues.get(referenceTimeseriesId);
                ChartIndexConfiguration referenceConfiguration = new ChartIndexConfiguration(referenceChartId, referenceIndex);
                StyleProperties referenceStyle = getTimeseriesStyleFor(timeseriesId, referenceTimeseriesId);
                referenceConfiguration.setReferenceData(referenceData, timeseriesMetadata, referenceStyle);
                referenceConfiguration.setRenderer(createRenderer(referenceStyle));
                referenceIndex++;
            }
        }
    }
}
Also used : Data(org.n52.io.response.dataset.Data) QuantityValue(org.n52.io.response.dataset.quantity.QuantityValue) StyleProperties(org.n52.io.request.StyleProperties)

Example 4 with StyleProperties

use of org.n52.io.request.StyleProperties in project series-rest-api by 52North.

the class TimeseriesMetadataController method addRenderingHints.

// stay backwards compatible
@SuppressWarnings("deprecation")
private TimeseriesMetadataOutput addRenderingHints(TimeseriesMetadataOutput output, IoParameters parameters) {
    final String valueName = TimeseriesMetadataOutput.RENDERING_HINTS;
    Predicate<MetadataExtension<?>> filter = RenderingHintsExtension.class::isInstance;
    Optional<Map<String, Object>> extras = getExtras(output, parameters, filter);
    extras.ifPresent(it -> {
        StyleProperties value = (StyleProperties) it.get(valueName);
        output.setValue(valueName, value, parameters, output::setRenderingHints);
    });
    return output;
}
Also used : StyleProperties(org.n52.io.request.StyleProperties) MetadataExtension(org.n52.io.response.extension.MetadataExtension) MultiValueMap(org.springframework.util.MultiValueMap) Map(java.util.Map)

Example 5 with StyleProperties

use of org.n52.io.request.StyleProperties in project series-rest-api by 52North.

the class IoStyleContext method getReferenceDatasetStyleOptions.

private StyleProperties getReferenceDatasetStyleOptions(StyleMetadata styleMetadata, String referenceDatasetId) {
    StyleProperties styleProperties = styleMetadata.getStyleProperties();
    Map<String, StyleProperties> properties = styleProperties.getReferenceValueStyleProperties();
    return properties.containsKey(referenceDatasetId) ? properties.get(referenceDatasetId) : null;
}
Also used : StyleProperties(org.n52.io.request.StyleProperties)

Aggregations

StyleProperties (org.n52.io.request.StyleProperties)5 Map (java.util.Map)1 StyleMetadata (org.n52.io.IoStyleContext.StyleMetadata)1 Data (org.n52.io.response.dataset.Data)1 DatasetOutput (org.n52.io.response.dataset.DatasetOutput)1 ReferenceValueOutput (org.n52.io.response.dataset.ReferenceValueOutput)1 QuantityData (org.n52.io.response.dataset.quantity.QuantityData)1 QuantityDatasetMetadata (org.n52.io.response.dataset.quantity.QuantityDatasetMetadata)1 QuantityValue (org.n52.io.response.dataset.quantity.QuantityValue)1 MetadataExtension (org.n52.io.response.extension.MetadataExtension)1 MultiValueMap (org.springframework.util.MultiValueMap)1