Пример #1
0
 // adds a new graph
 public void AddNewGraph(GraphableDescription _graphableDescription)
 {
     // future: add some validation
     graphableDescriptionList.Add(_graphableDescription);
     // also add a new empty List to ListList that will later be filled by AddData
     graphableDataListList.Add(new List <GraphableData>());
 }
Пример #2
0
        // creates empty graphs that are later used to be filled with data
        private void createEmptyGraphs()
        {
            GraphableDescription speedGraph        = new GraphableDescription("Speed", "Speed", "Time [s]", "Speed [m/s]");
            GraphableDescription accelerationGraph = new GraphableDescription("Acceleration", "Acceleration", "Time [s]", "Acceleration [m/s^2]");
            GraphableDescription distanceGraph     = new GraphableDescription("Distance", "Distance", "Time [s]", "Distance [m]");
            GraphableDescription fResGraph         = new GraphableDescription("F(res)", "F(res)", "Time [s]", "F(res) [N]");

            graphCreator.CreateEmptyGraph(speedGraph);
            graphCreator.CreateEmptyGraph(accelerationGraph);
            graphCreator.CreateEmptyGraph(distanceGraph);
            graphCreator.CreateEmptyGraph(fResGraph);
        }
Пример #3
0
        private void createEmptyGraphs()  
        {
            GraphableDescription eKinGraph         = new GraphableDescription("Kinetic Energy", "Kinetic Energy", "Time [s]", "Energy [kJ]");
            GraphableDescription ePotGraph         = new GraphableDescription("Potential Energy", "Potential Energy", "Time [s]", "Energy [kJ]");
            GraphableDescription eTotGraph         = new GraphableDescription("Total Energy", "Total Energy", "Time [s]", "Energy [kJ]");
            GraphableDescription speedGraph        = new GraphableDescription("Speed", "Speed", "Time [s]", "Speed [m/s]");
            GraphableDescription accelerationGraph = new GraphableDescription("Acceleration", "Acceleration", "Time [s]", "Acceleration [m/s^2]");
            GraphableDescription heightGraph       = new GraphableDescription("Height", "Height", "Time [s]", "Height [m]");

            graphCreator.CreateEmptyGraph(eKinGraph);
            graphCreator.CreateEmptyGraph(ePotGraph);
            graphCreator.CreateEmptyGraph(eTotGraph);
            graphCreator.CreateEmptyGraph(speedGraph);
            graphCreator.CreateEmptyGraph(accelerationGraph);
            graphCreator.CreateEmptyGraph(heightGraph);
        }
Пример #4
0
 // creates empty graphs to be filled later
 public void CreateEmptyGraph(GraphableDescription graphableDescription)
 {
     dataSet.AddNewGraph(graphableDescription);
 }
Пример #5
0
        // charts multiple data sets on one graph
        public void GraphLines(List <GraphableData> graphableDataList, GraphableDescription graphableDescription, int _blockWidthLine, int _blockHeightLine)
        {
            // stop executing if no data
            if (graphableDataList.Count == 0)
            {
                return;
            }

            blockWidthLine  = _blockWidthLine;
            blockHeightLine = _blockHeightLine;
            xAxisTitle      = graphableDescription.XAxisTitle;
            yAxisTitle      = graphableDescription.YAxisTitle;

            // loop through every list and get maximum values and minimum values
            // creates temp new lists
            List <float> xMaxList = new List <float>();
            List <float> yMaxList = new List <float>();
            List <float> xMinList = new List <float>();
            List <float> yMinList = new List <float>();

            for (int i = 0; i < graphableDataList.Count; i++)
            {
                // get max and min from each value set
                // future: maybe do it more efficiently with List.Select() or something
                xMaxList.Add(graphableDataList[i].XDataList.Max());
                yMaxList.Add(graphableDataList[i].YDataList.Max());
                xMinList.Add(graphableDataList[i].XDataList.Min());
                yMinList.Add(graphableDataList[i].YDataList.Min());
            }

            // from those list, again get max and min values
            float xMax = xMaxList.Max();
            float yMax = yMaxList.Max();
            float xMin = xMinList.Min();
            float yMin = yMinList.Min();

            // create arrays with axis label values
            xAxisLabelValues = createAxisLabelValues(xMax, xMin);
            yAxisLabelValues = createAxisLabelValues(yMax, yMin);

            float xLabelMax = xAxisLabelValues[nGridLines];
            float yLabelMax = yAxisLabelValues[nGridLines];
            float xLabelMin = xAxisLabelValues[0];
            float yLabelMin = yAxisLabelValues[0];

            // get ratio to length of axes
            float xFactor = (lengthX - blockWidthLine) / (xLabelMax - xLabelMin);
            float yFactor = (lengthY - blockHeightLine) / (yLabelMax - yLabelMin);

            // scale up / down values
            // List<int[]> scaledXValuesList = new List<int[]>();
            // List<int[]> scaledYValuesList = new List<int[]>();
            List <GraphableData> scaledGraphableDataList = new List <GraphableData>();

            for (int i = 0; i < graphableDataList.Count; i++)
            {
                List <float> scaledXValues = graphableDataList[i].XDataList.Select(x => x * xFactor).ToList();
                List <float> scaledYValues = graphableDataList[i].YDataList.Select(x => x * yFactor).ToList();

                scaledGraphableDataList.Add(new GraphableData(scaledXValues, scaledYValues, graphableDataList[i].Name, graphableDataList[i].Color));
            }

            // draw x and y axes
            colorsAxis = Enumerable.Repeat <Color>(new Color(0.95f, 0.95f, 0.95f), blockWidthLine * blockHeightLine).ToArray <Color>();

            // scale also the min values so we can use them as offset later
            int xLabelMinScaled = (int)(xLabelMin * xFactor);
            int yLabelMinScaled = (int)(yLabelMin * yFactor);

            drawAxis("x", yLabelMinScaled, colorsAxis);
            drawAxis("y", xLabelMinScaled, colorsAxis);

            // set their description
            setAxesTitles();

            // draw grid
            drawGrid();


            for (int i = 0; i < scaledGraphableDataList.Count; i++)
            {
                // loop through xValues and call drawPixelBlock for each xValue-yValue pair
                // add border so that it's drawn within the axes
                Color[] currentColors = Enumerable.Repeat <Color>(scaledGraphableDataList[i].Color, blockWidthLine * blockHeightLine).ToArray <Color>();
                // draw legend
                drawLegend(scaledGraphableDataList[i].Name, scaledGraphableDataList[i].Color, i);

                for (int y = 0; y < scaledGraphableDataList[i].XDataList.Count; y++)
                {
                    // draw each pixel based on start of axis (= border) and origin offset (= xLabelMin and yLabelMin)
                    drawPixelBlock(border - xLabelMinScaled + (int)scaledGraphableDataList[i].XDataList[y], border - yLabelMinScaled + (int)scaledGraphableDataList[i].YDataList[y], blockWidthLine, blockHeightLine, currentColors);

                    // interpolate between current and last pixel
                    // linear interpolation to set pixels between previous and new point
                    if (y > 0)
                    {
                        for (float t = 0.05f; t < 1.0f; t += 0.05f)
                        {
                            int lerpX = (int)Mathf.Lerp(border - xLabelMinScaled + scaledGraphableDataList[i].XDataList[y - 1], border - xLabelMinScaled + scaledGraphableDataList[i].XDataList[y], t);
                            int lerpY = (int)Mathf.Lerp(border - yLabelMinScaled + scaledGraphableDataList[i].YDataList[y - 1], border - yLabelMinScaled + scaledGraphableDataList[i].YDataList[y], t);
                            drawPixelBlock(lerpX, lerpY, blockWidthLine, blockHeightLine, currentColors);
                        }
                    }
                }
            }

            // upload to graphics card
            texture.Apply();
        }