All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.diirt.graphene.profile.impl.ProfileHistogram1D Maven / Gradle / Ivy

There is a newer version: 3.1.7
Show newest version
/**
 * Copyright (C) 2010-14 diirt developers. See COPYRIGHT.TXT
 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
 */
package org.diirt.graphene.profile.impl;

import org.diirt.graphene.AreaGraph2DRenderer;
import org.diirt.graphene.Cell1DDatasets;
import org.diirt.graphene.Graph2DRendererUpdate;
import org.diirt.graphene.Cell1DDataset;
import java.awt.Graphics2D;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import org.diirt.graphene.profile.ProfileGraph2D;
import org.diirt.util.array.ArrayDouble;
import org.diirt.util.array.ListNumbers;

/**
 * Handles profiling for Histogram1D.
 * Takes a Histogram1D dataset and repeatedly renders through a AreaGraph2DRenderer.
 * 
 * @author asbarber
 */
public class ProfileHistogram1D extends ProfileGraph2D {
    
    /**
     * Generates Histogram1D data that can be used in rendering.
     * The data is Gaussian and random between 0 and 1.
     * @return data as a histogram
     */
    @Override
    protected Cell1DDataset getDataset() {
        int nSamples = getNumDataPoints();
        
        //Creates data
        Random rand = new Random(1);
        double[] data = new double[nSamples];
        for (int i = 0; i < nSamples; i++) {
            data[i] = rand.nextGaussian();
        }
        
        return Cell1DDatasets.datasetFrom(new ArrayDouble(data), ListNumbers.linearList(0, 1, nSamples));
    }

    /**
     * Returns the renderer used in the render loop.
     * The histogram data is rendered by a AreaGraph2DRenderer.
     * @param imageWidth width of rendered image in pixels
     * @param imageHeight height of rendered image in pixels
     * @return a AreaGraph2DRenderer associated with Histogram1D data
     */
    @Override
    protected AreaGraph2DRenderer getRenderer(int imageWidth, int imageHeight) {
        return new AreaGraph2DRenderer(imageWidth, imageHeight);
    }

    /**
     * Draws the histogram in an area graph.
     * Primary method in the render loop.
     * @param graphics where image draws to
     * @param renderer what draws the image
     * @param data the histogram being drawn
     */
    @Override
    protected void render(Graphics2D graphics, AreaGraph2DRenderer renderer, Cell1DDataset data) {
        renderer.draw(graphics, data);            
    }
    
    /**
     * Returns the name of the graph being profiled.
     * @return Histogram1D title
     */
    @Override
    public String getGraphTitle() {
        return "Histogram1D";
    }

    /**
     * Gets the updates associated with the renderer in a map, linking a 
     * description of the update to the update object.
     * @return map with description of update paired with an update
     */    
    @Override
    public LinkedHashMap getVariations() {
        LinkedHashMap map = new LinkedHashMap<>();
        
        map.put("None", null);
        
        return map;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy