Beispiel #1
0
        private void eventMouseDown(object sender, MouseEventArgs e)
        {
            if (baseFunctionList == null)
            {
                return;
            }

            DISPLAY_RANGE range = getDisplayRange();
            double        time  = (((double)e.X) / ((double)range.xMax - range.xMin)) * (range.tMax - range.tMin) + range.tMin;

            // Update the mouse states
            if (e.Button == MouseButtons.Left)
            {
                mouseRight = false;
                mouseLeft  = true;

                // Set the cursor to this location
                setCursor(time, cursorWidth, getRowFromY(e.Y));
            }
            else if (e.Button == MouseButtons.Right)
            {
                mouseRight = true;
                mouseLeft  = false;

                // Set the region start and end to this location
                setSelect(time, time, getRowFromY(e.Y));
            }
        }
Beispiel #2
0
        private DISPLAY_RANGE getDisplayRange()
        {
            // This function gets the display range of the play bar and takes into account zoom.
            DISPLAY_RANGE result = new DISPLAY_RANGE();

            if (baseFunctionList == null)
            {
                return(result);
            }

            result.xMin = 0;
            result.xMax = this.Width - 1;

            if (zoom == 1.0 || baseFunctionList.dataVis == null)
            {
                // No zoom, fill the whole screen
                if (baseFunctionList.dataVis != null)
                {
                    result.tMin = baseFunctionList.dataVis.timeStart;
                    result.tMax = baseFunctionList.dataVis.timeEnd;
                }
                else if (oFunctionMaster.reader_visualization != null && oFunctionMaster.reader_visualization.data != null)
                {
                    result.tMin = 0;
                    result.tMax = oFunctionMaster.reader_visualization.data.timeEnd;
                }
                else
                {
                    result.tMin = 0;
                    result.tMax = 10;
                }
                result.tMinDataset = result.tMin;
                result.tMaxDataset = result.tMax;
            }
            else
            {
                // Zoomed in, lets calculate the variables
                result.tMinDataset = baseFunctionList.dataVis.timeStart;
                result.tMaxDataset = baseFunctionList.dataVis.timeEnd;
                result.tMin        = (zoomCentre - ((result.tMaxDataset - result.tMinDataset) / 2) * zoom);
                result.tMax        = (zoomCentre + ((result.tMaxDataset - result.tMinDataset) / 2) * zoom);

                // Check if these exceed the range on either side
                if (result.tMin < result.tMinDataset)
                {
                    // Shift the range to the right
                    result.tMax -= result.tMin - result.tMinDataset;
                    result.tMin  = result.tMinDataset;
                }
                else if (result.tMax > result.tMaxDataset)
                {
                    // Shift the range to the left
                    result.tMin -= result.tMax - result.tMaxDataset;
                    result.tMax  = result.tMaxDataset;
                }
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Handles mouse move events on the play bar.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void eventMouseMove(object sender, MouseEventArgs e)
        {
            // Get focus to get all on mouse events
            if (!Focused && CanFocus)
            {
                Focus();
            }

            // Set our mouse x and y
            mouseX = e.X;
            mouseY = e.Y;

            // Update the mouse highlight
            foreach (oTimeseriesPlot plot in timeseriesPlots)
            {
                plot.invalidateMouse();
            }

            // Set the cursor to this location
            DISPLAY_RANGE range = getDisplayRange();
            double        time  = (((double)e.X) / ((double)range.xMax - range.xMin)) * (range.tMax - range.tMin) + range.tMin;

            setCursor(time, cursorWidth, getRowFromY(e.Y));

            // Handle mouse buttons
            if (mouseRight)
            {
                // Set the right side of the select to here
                if (time > selectStart)
                {
                    setSelectEnd(time);
                }
                else
                {
                    setSelectEnd(selectStart);
                }
            }

            /*
             * else if ( (Control.ModifierKeys & Keys.Shift) == Keys.Shift )
             * {
             *  // We are changing the size of the tail
             *  double newWidth = cursorTime - time;
             *  if( newWidth >= 0 )
             *  {
             *      this.setCursorWidth(newWidth);
             *  }else
             *  {
             *      // Change the position of the cursor
             *      this.setCursor(time, cursorWidth);
             *  }
             * }
             */

            // Redraw, this will be a double redraw in some cases :(
            redraw = true;
            Render();
        }
Beispiel #4
0
        /// <summary>
        /// Sets the currently active function list.
        /// </summary>
        /// <param name="data">The function list currently viewable.</param>
        public void setData(oFunctionList newList)
        {
            // Update the data
            baseFunctionList = newList;

            // Update all the subplots with the data
            generateSubplotFunctionLists();

            // Set the cursor to the end of the data
            DISPLAY_RANGE range = getDisplayRange();
            double        time  = range.tMaxDataset;

            setCursor(time, cursorWidth, 0);

            // Render any changes immediately
            Render();
        }
Beispiel #5
0
        /// <summary>
        /// Because the mouse wheel event is sent to the main form, this event is forwarded from formMain.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void eventMouseWheel(object sender, MouseEventArgs e)
        {
            // Update the mouse button states
            if (baseFunctionList != null && e.Delta != 0)
            {
                // Update the zoom
                zoom = zoom * Math.Pow(0.9, ((double)e.Delta) / 120.0);
                if (zoom > 1.0)
                {
                    zoom = 1.0;
                }

                // Update the zoom centre such that the t corresponding to the mouse location stays at the same x
                DISPLAY_RANGE range     = getDisplayRange();
                double        timeMouse = (((double)e.X) / ((double)range.xMax - range.xMin)) * (range.tMax - range.tMin) +
                                          range.tMin;
                double leftTimeNew  = timeMouse - (timeMouse - range.tMin) * Math.Pow(0.9, ((double)e.Delta) / 120.0);
                double rightTimeNew = (range.tMax - timeMouse) * Math.Pow(0.9, ((double)e.Delta) / 120.0) + timeMouse;

                zoomCentre = (rightTimeNew + leftTimeNew) / 2;

                if (zoom != lastZoom)
                {
                    // Tell all the timeseries to update their log-plot vertices
                    foreach (oTimeseriesPlot plot in timeseriesPlots)
                    {
                        plot.invalidateLogPlot();
                        plot.invalidateAxis();
                        plot.invalidateCursor();
                        plot.invalidateSelection();
                    }

                    // Redraw
                    redraw = true;
                    Render();
                }

                lastZoom = zoom;
            }
        }
        private void updateLogPlotVertices(DISPLAY_RANGE range, float height, float yOffset, double cursorTime, double cursorWidth)
        {
            // Check that we have a valid device
            if (device != null && functionList != null)
            {
                // Load the data
                List<oSingleData> rawData = this.functionList.getData();

                if (rawData != null && rawData.Count > 0)
                {
                    if (!validLogPlot || lastCallCount != rawData.Count || vertexBufferLogPlot == null || vertexBufferLogPlot.Disposed || range.tMax != lastTime)
                    {
                        // Update the main visualizataion to show the new data

                        // Gather the data
                        List<oSingleData> data = functionList.getDataRange(range.tMax, cursorWidth*2);;
                        //List<oSingleData> data = functionList.getDataRange(range.tMax, range.tMax - lastTime); ;

                        // Now tell the main visualization to redraw
                        mainVisualization.update(data);

                        // Calculate the viewing range information
                        validAxis = false;
                        lastTime = range.tMax;
                        System.Single z = 0.5f;
                        System.Single yMin = 1 + yOffset;
                        System.Single yMax = height - 1 + yOffset;

                        // Create a value array to go with the vertexes
                        double[] functionCount = new double[(int)((range.tMaxDataset - range.tMinDataset) / timeWidth + 0.5)];
                        double[] times = new double[functionCount.Length];
                        for (int i = 0; i < functionCount.Count(); i++)
                        {
                            functionCount[i] = 0;
                            times[i] = 0;
                        }

                        // Loop through the time, calculating the call count associated with each time frame
                        double maxFunctionCount = 0;
                        int index = 0;
                        for (int i = 0; i < functionCount.Count(); i++)
                        {
                            // Process this time step
                            int tmpCount = this.functionList.getDataSize(i * timeWidth + range.tMinDataset, timeWidth);

                            // This time index record is associated with this vertex
                            double count = Math.Log10(tmpCount + 1);

                            double nextCount = 0.0;
                            if (i + 2 < functionCount.Count())
                            {
                                // Calculate the next count
                                nextCount = Math.Log10(this.functionList.getDataSize((i + 1) * timeWidth + range.tMinDataset, timeWidth) + 1);
                            }

                            if (count < 0)
                                count = 0;
                            if (nextCount < 0)
                                nextCount = 0;

                            if ((index == 0 || functionCount[index - 1] != count) || (nextCount != count) || index == functionCount.Length - 1)
                            {
                                // Create a new vertex
                                functionCount[index] = count;

                                // Set the time for this call
                                times[index] = i * timeWidth + range.tMinDataset;

                                if (functionCount[index] > maxFunctionCount)
                                    maxFunctionCount = functionCount[index];

                                index++;
                            }
                        }

                        // Generate the log-graph verticesLogPlot
                        if (maxFunctionCount <= 1)
                        {
                            maxFunctionCount = 1;
                        }

                        // Initialize the vertex array
                        verticesLogPlot = new CustomVertex.TransformedColored[index + 2];

                        // Generate the log-scale frequency plot verticesLogPlot
                        System.Single x;
                        System.Single y;
                        for (int i = 0; i < index; i++)
                        {
                            // Generate this vertex
                            x = (float)((((double)times[i] - range.tMin) / (range.tMax - range.tMin)) * (range.xMax - range.xMin) + range.xMin);
                            y = (float)((yMin - yMax) * (functionCount[i] / maxFunctionCount) + yMax);

                            verticesLogPlot[i] = new CustomVertex.TransformedColored((float)((int)(x)), (float)((int)y), z, 1.0f, Color.FromArgb(255, 255, 255).ToArgb());
                        }

                        // Create the last two vertices
                        x = (float)range.xMax;
                        y = (float)yMax;

                        verticesLogPlot[index] = new CustomVertex.TransformedColored((float)((int)(x)), (float)((int)y), z, 1.0f, Color.FromArgb(255, 255, 255).ToArgb());
                        verticesLogPlot[index + 1] = new CustomVertex.TransformedColored((float)((int)(x)), (float)(10000000000), z, 1.0f, Color.FromArgb(0, 0, 0).ToArgb());

                        // Setup the vertex buffer
                        if (vertexBufferLogPlot != null)
                            vertexBufferLogPlot.Dispose();
                        vertexBufferLogPlot = new VertexBuffer(typeof(CustomVertex.TransformedColored),
                                                             verticesLogPlot.Length,
                                                             device,
                                                             0,
                                                             CustomVertex.TransformedColored.Format,
                                                             Pool.Default);
                        lastCallCount = rawData.Count;

                        try
                        {
                            GraphicsStream stm = vertexBufferLogPlot.Lock(0, 0, 0);
                            stm.Seek(0, SeekOrigin.Begin);
                            stm.Write(verticesLogPlot);
                            vertexBufferLogPlot.Unlock();
                        }
                        catch (Exception ex)
                        {
                            // Do nothing
                        }
                    }

                    validLogPlot = true;
                }
                else
                {
                    // An empty dataset
                    vertexBufferLogPlot = null;
                }
            }
        }
        private void updateCursorVertices(double cursorTime, double cursorWidth, DISPLAY_RANGE range, float height, float yOffset, bool hasCursor)
        {
            if (device == null || functionList == null)
                return;

            if (!validCursor)
            {
                System.Single yMin = 2 + yOffset;
                System.Single yMax = height - 2 + yOffset;

                // If the cursor is in this row, tell the main visualization to redraw with our cursor data.
                if (hasCursor)
                {
                    // Gather the data
                    List<oSingleData> data;
                    if (functionList != null)
                        data = functionList.getDataRange(cursorTime, cursorWidth);
                    else
                        data = new List<oSingleData>(0);

                    // Now tell the main visualization to redraw
                    mainVisualization.update(data);

                    // Create the vertex buffer for the current mouse location
                    if (verticesCursor == null)
                    {
                        // Initialize the vertices
                        verticesCursor = new CustomVertex.TransformedColored[2*5];
                        for (int n = 0; n < verticesCursor.Length; n++)
                        {
                            verticesCursor[n] = new CustomVertex.TransformedColored(0.0f, 0.0f, 0.4f, 1.0f,
                                                                                    Color.FromArgb(255, 255, 0).ToArgb());
                        }
                    }

                    // Set the vertice positions
                    int i = 0;
                    float xEnd = (float) ((cursorTime - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) +
                                 range.xMin;
                    float xStart = (float) ((cursorTime - cursorWidth - range.tMin)/(range.tMax - range.tMin))*
                                   (range.xMax - range.xMin) + range.xMin;
                    verticesCursor[i].X = xEnd - 3;
                    verticesCursor[i++].Y = yMin;
                    verticesCursor[i].X = xEnd + 3;
                    verticesCursor[i++].Y = yMin;

                    verticesCursor[i].X = xEnd - 3;
                    verticesCursor[i++].Y = yMax;
                    verticesCursor[i].X = xEnd + 3;
                    verticesCursor[i++].Y = yMax;

                    verticesCursor[i].X = xEnd;
                    verticesCursor[i++].Y = yMin;
                    verticesCursor[i].X = xEnd;
                    verticesCursor[i++].Y = yMax;

                    verticesCursor[i].X = xStart;
                    verticesCursor[i++].Y = (yMax - yMin) / 2 + yMin;
                    verticesCursor[i].X = xEnd;
                    verticesCursor[i++].Y = (yMax - yMin) / 2 + yMin;

                    verticesCursor[i].X = xStart;
                    verticesCursor[i++].Y = (yMax - yMin) * 0.4f + yMin;
                    verticesCursor[i].X = xStart;
                    verticesCursor[i++].Y = (yMax - yMin) * 0.6f + yMin;

                    // Write the vertex drawing buffers
                    if (vertexBufferCursor != null)
                        vertexBufferCursor.Dispose();
                    vertexBufferCursor = new VertexBuffer(typeof (CustomVertex.TransformedColored),
                                                          verticesCursor.Length,
                                                          device,
                                                          0,
                                                          CustomVertex.TransformedColored.Format,
                                                          Pool.Default);
                    GraphicsStream stm = vertexBufferCursor.Lock(0, 0, 0);
                    stm.Seek(0, SeekOrigin.Begin);
                    stm.Write(verticesCursor);
                    vertexBufferCursor.Unlock();
                }
                else
                {
                    // Cursor is not in this row
                    vertexBufferCursor = null;
                }

                validCursor = true;
            }
        }
        private void updateAxisVertices(DISPLAY_RANGE range, float height, float yOffset)
        {
            if (device == null || functionList == null)
                return;

            if (!validAxis)
            {
                // Update the axis grid vertices
                System.Single z = 0.5f;
                System.Single yMin = yOffset;
                System.Single yMax = height + yOffset;

                // Pick the timescale
                float timecale = (range.tMax - range.tMin > 15 ? 1 : 10 );

                // Calculate the number of vertices
                // 2 vertices per line. 1 main major marker per second, 9 minor markers inbetween.
                int numMarkers = (int)(timecale * (range.tMax - range.tMin));
                verticesAxis = new CustomVertex.TransformedColored[2*numMarkers];

                // Loop through creating the markers
                float firstMarkerTime = ((float)((int)(timecale * range.tMin))) / timecale;
                for (int i = 0; i < numMarkers; i++)
                {
                    Single time = i * (1 / timecale) + firstMarkerTime;

                    // Create this axis line
                    if ((Single) ((int) time) == time)
                    {
                        // Major marker
                        verticesAxis[2*i] =
                            new CustomVertex.TransformedColored(
                                (float)
                                ((int)
                                 ((time - range.tMin)/(range.tMax - range.tMin)*
                                  (range.xMax - range.xMin) + range.xMin)),
                                (float) ((int) yMin), z, 1.0f, Color.FromArgb(150, 255, 150).ToArgb());
                        verticesAxis[2*i + 1] =
                            new CustomVertex.TransformedColored(
                                (float)
                                ((int)
                                 ((time - range.tMin)/(range.tMax - range.tMin)*
                                  (range.xMax - range.xMin) + range.xMin)),
                                (float) ((int) ((yMax-yMin)/2+yMin)), z, 1.0f, Color.FromArgb(150, 255, 150).ToArgb());
                    }
                    else
                    {
                        // Minor Marker
                        verticesAxis[2*i] =
                            new CustomVertex.TransformedColored(
                                (float)
                                ((int)
                                 ((time - range.tMin)/(range.tMax - range.tMin)*
                                  (range.xMax - range.xMin) + range.xMin)),
                                (float) ((int) yMin), z, 1.0f, Color.FromArgb(100, 170, 100).ToArgb());
                        verticesAxis[2*i + 1] =
                            new CustomVertex.TransformedColored(
                                (float)
                                ((int)
                                 ((time - range.tMin)/(range.tMax - range.tMin)*
                                  (range.xMax - range.xMin) + range.xMin)),
                                (float)((int)((yMax - yMin) / 4 + yMin)), z, 1.0f, Color.FromArgb(100, 170, 100).ToArgb());
                    }
                }

                // Write the vertex drawing buffers
                if (verticesAxis.Length > 0)
                {
                    if (vertexBufferAxis != null)
                        vertexBufferAxis.Dispose();
                    vertexBufferAxis = new VertexBuffer(typeof (CustomVertex.TransformedColored),
                                                        verticesAxis.Length,
                                                        device,
                                                        0,
                                                        CustomVertex.TransformedColored.Format,
                                                        Pool.Default);
                    GraphicsStream stm = vertexBufferAxis.Lock(0, 0, 0);
                    stm.Seek(0, SeekOrigin.Begin);
                    stm.Write(verticesAxis);
                    vertexBufferAxis.Unlock();
                }

                validAxis = true;
            }
        }
        /// <summary>
        /// Paint this timeseries
        /// </summary>
        /// <param name="device"></param>
        public void render(double cursorTime, double cursorWidth, double selectStart, double selectEnd, DISPLAY_RANGE range, int mouseX, int mouseY, float height, bool isSelected, bool hasCursor, bool drawAxis)
        {
            try
            {
                // Determine the y-offset
                float yOffset = (height/(float)numRows) * (float) row;

                // Update the vertices as necessary
                updateLogPlotVertices(range, height / (float)numRows, yOffset, cursorTime, cursorWidth);
                updateCursorVertices(cursorTime, cursorWidth, range, height / (float)numRows, yOffset, hasCursor);
                if( drawAxis )
                    updateAxisVertices(range, height / (float)numRows, yOffset);
                updateMouseVertices(mouseX, mouseY, cursorWidth, range, height / (float)numRows, yOffset);
                updateSelectionVertices(selectStart, selectEnd, range, height / (float)numRows, yOffset, isSelected);

                // Draw the main play bar sections
                RenderSelectionBackground();
                if (drawAxis)
                    RenderAxis();
                RenderMouse();
                RenderFrequency();
                RenderCursor();
                RenderName(height / (float)numRows, yOffset);

            }
            catch (Exception ex)
            {
            }
        }
Beispiel #10
0
        private DISPLAY_RANGE getDisplayRange()
        {
            // This function gets the display range of the play bar and takes into account zoom.
            DISPLAY_RANGE result = new DISPLAY_RANGE();
            if (baseFunctionList == null)
                return result;

            result.xMin = 0;
            result.xMax = this.Width - 1;

            if (zoom == 1.0 || baseFunctionList.dataVis == null)
            {
                // No zoom, fill the whole screen
                if (baseFunctionList.dataVis != null)
                {
                    result.tMin = baseFunctionList.dataVis.timeStart;
                    result.tMax = baseFunctionList.dataVis.timeEnd;
                }else if( oFunctionMaster.reader_visualization != null && oFunctionMaster.reader_visualization.data != null )
                {
                    result.tMin = 0;
                    result.tMax = oFunctionMaster.reader_visualization.data.timeEnd;
                }else
                {
                    result.tMin = 0;
                    result.tMax = 10;
                }
                result.tMinDataset = result.tMin;
                result.tMaxDataset = result.tMax;
            }
            else
            {
                // Zoomed in, lets calculate the variables
                result.tMinDataset = baseFunctionList.dataVis.timeStart;
                result.tMaxDataset = baseFunctionList.dataVis.timeEnd;
                result.tMin = (zoomCentre - ((result.tMaxDataset - result.tMinDataset) / 2) * zoom);
                result.tMax = (zoomCentre + ( (result.tMaxDataset - result.tMinDataset) / 2) * zoom);

                // Check if these exceed the range on either side
                if (result.tMin < result.tMinDataset)
                {
                    // Shift the range to the right
                    result.tMax -= result.tMin - result.tMinDataset;
                    result.tMin = result.tMinDataset;
                }
                else if (result.tMax > result.tMaxDataset)
                {
                    // Shift the range to the left
                    result.tMin -= result.tMax - result.tMaxDataset;
                    result.tMax = result.tMaxDataset;
                }

            }

            return result;
        }
Beispiel #11
0
        private void updateCursorVertices(double cursorTime, double cursorWidth, DISPLAY_RANGE range, float height, float yOffset, bool hasCursor)
        {
            if (device == null || functionList == null)
            {
                return;
            }

            if (!validCursor)
            {
                System.Single yMin = 2 + yOffset;
                System.Single yMax = height - 2 + yOffset;

                // If the cursor is in this row, tell the main visualization to redraw with our cursor data.
                if (hasCursor)
                {
                    // Gather the data
                    List <oSingleData> data;
                    if (functionList != null)
                    {
                        data = functionList.getDataRange(cursorTime, cursorWidth);
                    }
                    else
                    {
                        data = new List <oSingleData>(0);
                    }

                    // Now tell the main visualization to redraw
                    mainVisualization.update(data);


                    // Create the vertex buffer for the current mouse location
                    if (verticesCursor == null)
                    {
                        // Initialize the vertices
                        verticesCursor = new CustomVertex.TransformedColored[2 * 5];
                        for (int n = 0; n < verticesCursor.Length; n++)
                        {
                            verticesCursor[n] = new CustomVertex.TransformedColored(0.0f, 0.0f, 0.4f, 1.0f,
                                                                                    Color.FromArgb(255, 255, 0).ToArgb());
                        }
                    }

                    // Set the vertice positions
                    int   i    = 0;
                    float xEnd = (float)((cursorTime - range.tMin) / (range.tMax - range.tMin)) * (range.xMax - range.xMin) +
                                 range.xMin;
                    float xStart = (float)((cursorTime - cursorWidth - range.tMin) / (range.tMax - range.tMin)) *
                                   (range.xMax - range.xMin) + range.xMin;
                    verticesCursor[i].X   = xEnd - 3;
                    verticesCursor[i++].Y = yMin;
                    verticesCursor[i].X   = xEnd + 3;
                    verticesCursor[i++].Y = yMin;

                    verticesCursor[i].X   = xEnd - 3;
                    verticesCursor[i++].Y = yMax;
                    verticesCursor[i].X   = xEnd + 3;
                    verticesCursor[i++].Y = yMax;

                    verticesCursor[i].X   = xEnd;
                    verticesCursor[i++].Y = yMin;
                    verticesCursor[i].X   = xEnd;
                    verticesCursor[i++].Y = yMax;

                    verticesCursor[i].X   = xStart;
                    verticesCursor[i++].Y = (yMax - yMin) / 2 + yMin;
                    verticesCursor[i].X   = xEnd;
                    verticesCursor[i++].Y = (yMax - yMin) / 2 + yMin;

                    verticesCursor[i].X   = xStart;
                    verticesCursor[i++].Y = (yMax - yMin) * 0.4f + yMin;
                    verticesCursor[i].X   = xStart;
                    verticesCursor[i++].Y = (yMax - yMin) * 0.6f + yMin;

                    // Write the vertex drawing buffers
                    if (vertexBufferCursor != null)
                    {
                        vertexBufferCursor.Dispose();
                    }
                    vertexBufferCursor = new VertexBuffer(typeof(CustomVertex.TransformedColored),
                                                          verticesCursor.Length,
                                                          device,
                                                          0,
                                                          CustomVertex.TransformedColored.Format,
                                                          Pool.Default);
                    GraphicsStream stm = vertexBufferCursor.Lock(0, 0, 0);
                    stm.Seek(0, SeekOrigin.Begin);
                    stm.Write(verticesCursor);
                    vertexBufferCursor.Unlock();
                }
                else
                {
                    // Cursor is not in this row
                    vertexBufferCursor = null;
                }

                validCursor = true;
            }
        }
Beispiel #12
0
        private void updateLogPlotVertices(DISPLAY_RANGE range, float height, float yOffset, double cursorTime, double cursorWidth)
        {
            // Check that we have a valid device
            if (device != null && functionList != null)
            {
                // Load the data
                List <oSingleData> rawData = this.functionList.getData();

                if (rawData != null && rawData.Count > 0)
                {
                    if (!validLogPlot || lastCallCount != rawData.Count || vertexBufferLogPlot == null || vertexBufferLogPlot.Disposed || range.tMax != lastTime)
                    {
                        // Update the main visualizataion to show the new data

                        // Gather the data
                        List <oSingleData> data = functionList.getDataRange(range.tMax, cursorWidth * 2);;
                        //List<oSingleData> data = functionList.getDataRange(range.tMax, range.tMax - lastTime); ;

                        // Now tell the main visualization to redraw
                        mainVisualization.update(data);

                        // Calculate the viewing range information
                        validAxis = false;
                        lastTime  = range.tMax;
                        System.Single z    = 0.5f;
                        System.Single yMin = 1 + yOffset;
                        System.Single yMax = height - 1 + yOffset;

                        // Create a value array to go with the vertexes
                        double[] functionCount = new double[(int)((range.tMaxDataset - range.tMinDataset) / timeWidth + 0.5)];
                        double[] times         = new double[functionCount.Length];
                        for (int i = 0; i < functionCount.Count(); i++)
                        {
                            functionCount[i] = 0;
                            times[i]         = 0;
                        }

                        // Loop through the time, calculating the call count associated with each time frame
                        double maxFunctionCount = 0;
                        int    index            = 0;
                        for (int i = 0; i < functionCount.Count(); i++)
                        {
                            // Process this time step
                            int tmpCount = this.functionList.getDataSize(i * timeWidth + range.tMinDataset, timeWidth);

                            // This time index record is associated with this vertex
                            double count = Math.Log10(tmpCount + 1);

                            double nextCount = 0.0;
                            if (i + 2 < functionCount.Count())
                            {
                                // Calculate the next count
                                nextCount = Math.Log10(this.functionList.getDataSize((i + 1) * timeWidth + range.tMinDataset, timeWidth) + 1);
                            }

                            if (count < 0)
                            {
                                count = 0;
                            }
                            if (nextCount < 0)
                            {
                                nextCount = 0;
                            }


                            if ((index == 0 || functionCount[index - 1] != count) || (nextCount != count) || index == functionCount.Length - 1)
                            {
                                // Create a new vertex
                                functionCount[index] = count;

                                // Set the time for this call
                                times[index] = i * timeWidth + range.tMinDataset;

                                if (functionCount[index] > maxFunctionCount)
                                {
                                    maxFunctionCount = functionCount[index];
                                }

                                index++;
                            }
                        }

                        // Generate the log-graph verticesLogPlot
                        if (maxFunctionCount <= 1)
                        {
                            maxFunctionCount = 1;
                        }

                        // Initialize the vertex array
                        verticesLogPlot = new CustomVertex.TransformedColored[index + 2];

                        // Generate the log-scale frequency plot verticesLogPlot
                        System.Single x;
                        System.Single y;
                        for (int i = 0; i < index; i++)
                        {
                            // Generate this vertex
                            x = (float)((((double)times[i] - range.tMin) / (range.tMax - range.tMin)) * (range.xMax - range.xMin) + range.xMin);
                            y = (float)((yMin - yMax) * (functionCount[i] / maxFunctionCount) + yMax);

                            verticesLogPlot[i] = new CustomVertex.TransformedColored((float)((int)(x)), (float)((int)y), z, 1.0f, Color.FromArgb(255, 255, 255).ToArgb());
                        }

                        // Create the last two vertices
                        x = (float)range.xMax;
                        y = (float)yMax;

                        verticesLogPlot[index]     = new CustomVertex.TransformedColored((float)((int)(x)), (float)((int)y), z, 1.0f, Color.FromArgb(255, 255, 255).ToArgb());
                        verticesLogPlot[index + 1] = new CustomVertex.TransformedColored((float)((int)(x)), (float)(10000000000), z, 1.0f, Color.FromArgb(0, 0, 0).ToArgb());


                        // Setup the vertex buffer
                        if (vertexBufferLogPlot != null)
                        {
                            vertexBufferLogPlot.Dispose();
                        }
                        vertexBufferLogPlot = new VertexBuffer(typeof(CustomVertex.TransformedColored),
                                                               verticesLogPlot.Length,
                                                               device,
                                                               0,
                                                               CustomVertex.TransformedColored.Format,
                                                               Pool.Default);
                        lastCallCount = rawData.Count;

                        try
                        {
                            GraphicsStream stm = vertexBufferLogPlot.Lock(0, 0, 0);
                            stm.Seek(0, SeekOrigin.Begin);
                            stm.Write(verticesLogPlot);
                            vertexBufferLogPlot.Unlock();
                        }
                        catch (Exception ex)
                        {
                            // Do nothing
                        }
                    }

                    validLogPlot = true;
                }
                else
                {
                    // An empty dataset
                    vertexBufferLogPlot = null;
                }
            }
        }
Beispiel #13
0
        private void updateSelectionVertices(double selectStart, double selectEnd, DISPLAY_RANGE range, float height, float yOffset, bool isSelected)
        {
            if (device == null || functionList == null)
            {
                return;
            }

            if (!validSelection)
            {
                int colour;
                if (isSelected)
                {
                    colour = Color.FromArgb(80, 80, 80).ToArgb(); // A bit lighter gray
                }
                else
                {
                    colour = Color.FromArgb(40, 40, 40).ToArgb(); // Very dark gray
                }

                // Update the selection vertices
                verticesSelectionBackground = new CustomVertex.TransformedColored[3 * 2]; // Two triangles for a box.

                // General parameters
                System.Single z    = 0.5f;
                System.Single yMin = yOffset;
                System.Single yMax = height + yOffset;

                int i = 0;

                // Draw the background
                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectStart - range.tMin) / (range.tMax - range.tMin)) * (range.xMax - range.xMin) + range.xMin),
                        yMin, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectEnd - range.tMin) / (range.tMax - range.tMin)) * (range.xMax - range.xMin) + range.xMin),
                        yMin, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectEnd - range.tMin) / (range.tMax - range.tMin)) * (range.xMax - range.xMin) + range.xMin),
                        yMax, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectStart - range.tMin) / (range.tMax - range.tMin)) * (range.xMax - range.xMin) + range.xMin),
                        yMin, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectStart - range.tMin) / (range.tMax - range.tMin)) * (range.xMax - range.xMin) + range.xMin),
                        yMax, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectEnd - range.tMin) / (range.tMax - range.tMin)) * (range.xMax - range.xMin) + range.xMin),
                        yMax, z, 1.0f, colour);

                if (vertexBufferSelectionBackground != null)
                {
                    vertexBufferSelectionBackground.Dispose();
                }
                vertexBufferSelectionBackground = new VertexBuffer(typeof(CustomVertex.TransformedColored),
                                                                   verticesSelectionBackground.Length,
                                                                   device,
                                                                   0,
                                                                   CustomVertex.TransformedColored.Format,
                                                                   Pool.Default);

                GraphicsStream stm = vertexBufferSelectionBackground.Lock(0, 0, 0);
                stm.Seek(0, SeekOrigin.Begin);
                stm.Write(verticesSelectionBackground);
                vertexBufferSelectionBackground.Unlock();

                validSelection = true;
            }
        }
Beispiel #14
0
        private void updateAxisVertices(DISPLAY_RANGE range, float height, float yOffset)
        {
            if (device == null || functionList == null)
            {
                return;
            }

            if (!validAxis)
            {
                // Update the axis grid vertices
                System.Single z    = 0.5f;
                System.Single yMin = yOffset;
                System.Single yMax = height + yOffset;

                // Pick the timescale
                float timecale = (range.tMax - range.tMin > 15 ? 1 : 10);

                // Calculate the number of vertices
                // 2 vertices per line. 1 main major marker per second, 9 minor markers inbetween.
                int numMarkers = (int)(timecale * (range.tMax - range.tMin));
                verticesAxis = new CustomVertex.TransformedColored[2 * numMarkers];

                // Loop through creating the markers
                float firstMarkerTime = ((float)((int)(timecale * range.tMin))) / timecale;
                for (int i = 0; i < numMarkers; i++)
                {
                    Single time = i * (1 / timecale) + firstMarkerTime;

                    // Create this axis line
                    if ((Single)((int)time) == time)
                    {
                        // Major marker
                        verticesAxis[2 * i] =
                            new CustomVertex.TransformedColored(
                                (float)
                                ((int)
                                 ((time - range.tMin) / (range.tMax - range.tMin) *
                                  (range.xMax - range.xMin) + range.xMin)),
                                (float)((int)yMin), z, 1.0f, Color.FromArgb(150, 255, 150).ToArgb());
                        verticesAxis[2 * i + 1] =
                            new CustomVertex.TransformedColored(
                                (float)
                                ((int)
                                 ((time - range.tMin) / (range.tMax - range.tMin) *
                                  (range.xMax - range.xMin) + range.xMin)),
                                (float)((int)((yMax - yMin) / 2 + yMin)), z, 1.0f, Color.FromArgb(150, 255, 150).ToArgb());
                    }
                    else
                    {
                        // Minor Marker
                        verticesAxis[2 * i] =
                            new CustomVertex.TransformedColored(
                                (float)
                                ((int)
                                 ((time - range.tMin) / (range.tMax - range.tMin) *
                                  (range.xMax - range.xMin) + range.xMin)),
                                (float)((int)yMin), z, 1.0f, Color.FromArgb(100, 170, 100).ToArgb());
                        verticesAxis[2 * i + 1] =
                            new CustomVertex.TransformedColored(
                                (float)
                                ((int)
                                 ((time - range.tMin) / (range.tMax - range.tMin) *
                                  (range.xMax - range.xMin) + range.xMin)),
                                (float)((int)((yMax - yMin) / 4 + yMin)), z, 1.0f, Color.FromArgb(100, 170, 100).ToArgb());
                    }
                }

                // Write the vertex drawing buffers
                if (verticesAxis.Length > 0)
                {
                    if (vertexBufferAxis != null)
                    {
                        vertexBufferAxis.Dispose();
                    }
                    vertexBufferAxis = new VertexBuffer(typeof(CustomVertex.TransformedColored),
                                                        verticesAxis.Length,
                                                        device,
                                                        0,
                                                        CustomVertex.TransformedColored.Format,
                                                        Pool.Default);
                    GraphicsStream stm = vertexBufferAxis.Lock(0, 0, 0);
                    stm.Seek(0, SeekOrigin.Begin);
                    stm.Write(verticesAxis);
                    vertexBufferAxis.Unlock();
                }

                validAxis = true;
            }
        }
Beispiel #15
0
        /// <summary>
        /// Paint this timeseries
        /// </summary>
        /// <param name="device"></param>
        public void render(double cursorTime, double cursorWidth, double selectStart, double selectEnd, DISPLAY_RANGE range, int mouseX, int mouseY, float height, bool isSelected, bool hasCursor, bool drawAxis)
        {
            try
            {
                // Determine the y-offset
                float yOffset = (height / (float)numRows) * (float)row;

                // Update the vertices as necessary
                updateLogPlotVertices(range, height / (float)numRows, yOffset, cursorTime, cursorWidth);
                updateCursorVertices(cursorTime, cursorWidth, range, height / (float)numRows, yOffset, hasCursor);
                if (drawAxis)
                {
                    updateAxisVertices(range, height / (float)numRows, yOffset);
                }
                updateMouseVertices(mouseX, mouseY, cursorWidth, range, height / (float)numRows, yOffset);
                updateSelectionVertices(selectStart, selectEnd, range, height / (float)numRows, yOffset, isSelected);

                // Draw the main play bar sections
                RenderSelectionBackground();
                if (drawAxis)
                {
                    RenderAxis();
                }
                RenderMouse();
                RenderFrequency();
                RenderCursor();
                RenderName(height / (float)numRows, yOffset);
            }
            catch (Exception ex)
            {
            }
        }
        private void updateMouseVertices(int x, int y, double cursorWidth, DISPLAY_RANGE range, float height, float yOffset)
        {
            if (device == null || functionList == null)
                return;

            if (!validMouse)
            {
                System.Single yMin = yOffset;
                System.Single yMax = height + yOffset;

                // Check if the cursor is in this row
                bool inRow = false;
                if (y >= (int)yMin && y <= (int)yMax)
                    inRow = true;

                // Set the mouse text values
                mouseTextPos = new Point(x + 2, (int) yMin + 3);
                mouseNumCalls =
                    functionList.getDataSize(
                        ((double) (x - range.xMin)/(double) (range.xMax - range.xMin))*(range.tMax - range.tMin) +
                        range.tMin, cursorWidth);

                if (inRow)
                {
                    // Initialize the vertices
                    verticesMouse = new CustomVertex.TransformedColored[4];
                    for (int n = 0; n < verticesMouse.Length; n++)
                        verticesMouse[n] = new CustomVertex.TransformedColored(0.0f, 0.0f, 0.0f, 1.0f,
                                                                               Color.FromArgb(0, 255, 0).
                                                                                   ToArgb());

                    // Set the vertice positions
                    int i = 0;
                    verticesMouse[i].X = x + 2;
                    verticesMouse[i].Y = yMin;
                    verticesMouse[i++].Z = 0.4f;
                    verticesMouse[i].X = x + 2;
                    verticesMouse[i].Y = yMax;
                    verticesMouse[i++].Z = 0.4f;

                    verticesMouse[i].X = x - 2;
                    verticesMouse[i].Y = yMin;
                    verticesMouse[i++].Z = 0.4f;
                    verticesMouse[i].X = x - 2;
                    verticesMouse[i].Y = yMax;
                    verticesMouse[i++].Z = 0.4f;
                }else
                {
                    // Create the vertex buffer for the current mouse location

                    // Initialize the vertices
                    verticesMouse = new CustomVertex.TransformedColored[2];
                    for (int n = 0; n < verticesMouse.Length; n++)
                        verticesMouse[n] = new CustomVertex.TransformedColored(0.0f, 0.0f, 0.0f, 1.0f,
                                                                               Color.FromArgb(0, 100, 0).
                                                                                   ToArgb());

                    // Set the vertice positions
                    int i = 0;
                    verticesMouse[i].X = x;
                    verticesMouse[i].Y = yMin;
                    verticesMouse[i++].Z = 0.4f;

                    verticesMouse[i].X = x;
                    verticesMouse[i].Y = yMax;
                    verticesMouse[i++].Z = 0.4f;
                }

                // Write the vertex drawing buffers
                if (vertexBufferMouse != null)
                    vertexBufferMouse.Dispose();
                vertexBufferMouse = new VertexBuffer(typeof (CustomVertex.TransformedColored),
                                                     verticesMouse.Length,
                                                     device,
                                                     0,
                                                     CustomVertex.TransformedColored.Format,
                                                     Pool.Default);
                GraphicsStream stm = vertexBufferMouse.Lock(0, 0, 0);
                stm.Seek(0, SeekOrigin.Begin);
                stm.Write(verticesMouse);
                vertexBufferMouse.Unlock();

                validMouse = true;
            }
        }
        private void updateSelectionVertices(double selectStart, double selectEnd, DISPLAY_RANGE range, float height, float yOffset, bool isSelected)
        {
            if (device == null || functionList == null)
                return;

            if (!validSelection)
            {
                int colour;
                if (isSelected)
                {
                    colour = Color.FromArgb(80, 80, 80).ToArgb(); // A bit lighter gray
                }else
                {
                    colour = Color.FromArgb(40, 40, 40).ToArgb(); // Very dark gray
                }

                // Update the selection vertices
                verticesSelectionBackground = new CustomVertex.TransformedColored[3*2]; // Two triangles for a box.

                // General parameters
                System.Single z = 0.5f;
                System.Single yMin = yOffset;
                System.Single yMax = height + yOffset;

                int i = 0;

                // Draw the background
                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectStart - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin),
                        yMin, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectEnd - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin),
                        yMin, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectEnd - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin),
                        yMax, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectStart - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin),
                        yMin, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectStart - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin),
                        yMax, z, 1.0f, colour);

                verticesSelectionBackground[i++] =
                    new CustomVertex.TransformedColored(
                        (float)
                        (((selectEnd - range.tMin)/(range.tMax - range.tMin))*(range.xMax - range.xMin) + range.xMin),
                        yMax, z, 1.0f, colour);

                if (vertexBufferSelectionBackground != null)
                    vertexBufferSelectionBackground.Dispose();
                vertexBufferSelectionBackground = new VertexBuffer(typeof (CustomVertex.TransformedColored),
                                                                   verticesSelectionBackground.Length,
                                                                   device,
                                                                   0,
                                                                   CustomVertex.TransformedColored.Format,
                                                                   Pool.Default);

                GraphicsStream stm = vertexBufferSelectionBackground.Lock(0, 0, 0);
                stm.Seek(0, SeekOrigin.Begin);
                stm.Write(verticesSelectionBackground);
                vertexBufferSelectionBackground.Unlock();

                validSelection = true;
            }
        }
Beispiel #18
0
        private void updateMouseVertices(int x, int y, double cursorWidth, DISPLAY_RANGE range, float height, float yOffset)
        {
            if (device == null || functionList == null)
            {
                return;
            }

            if (!validMouse)
            {
                System.Single yMin = yOffset;
                System.Single yMax = height + yOffset;

                // Check if the cursor is in this row
                bool inRow = false;
                if (y >= (int)yMin && y <= (int)yMax)
                {
                    inRow = true;
                }

                // Set the mouse text values
                mouseTextPos  = new Point(x + 2, (int)yMin + 3);
                mouseNumCalls =
                    functionList.getDataSize(
                        ((double)(x - range.xMin) / (double)(range.xMax - range.xMin)) * (range.tMax - range.tMin) +
                        range.tMin, cursorWidth);


                if (inRow)
                {
                    // Initialize the vertices
                    verticesMouse = new CustomVertex.TransformedColored[4];
                    for (int n = 0; n < verticesMouse.Length; n++)
                    {
                        verticesMouse[n] = new CustomVertex.TransformedColored(0.0f, 0.0f, 0.0f, 1.0f,
                                                                               Color.FromArgb(0, 255, 0).
                                                                               ToArgb());
                    }

                    // Set the vertice positions
                    int i = 0;
                    verticesMouse[i].X   = x + 2;
                    verticesMouse[i].Y   = yMin;
                    verticesMouse[i++].Z = 0.4f;
                    verticesMouse[i].X   = x + 2;
                    verticesMouse[i].Y   = yMax;
                    verticesMouse[i++].Z = 0.4f;

                    verticesMouse[i].X   = x - 2;
                    verticesMouse[i].Y   = yMin;
                    verticesMouse[i++].Z = 0.4f;
                    verticesMouse[i].X   = x - 2;
                    verticesMouse[i].Y   = yMax;
                    verticesMouse[i++].Z = 0.4f;
                }
                else
                {
                    // Create the vertex buffer for the current mouse location

                    // Initialize the vertices
                    verticesMouse = new CustomVertex.TransformedColored[2];
                    for (int n = 0; n < verticesMouse.Length; n++)
                    {
                        verticesMouse[n] = new CustomVertex.TransformedColored(0.0f, 0.0f, 0.0f, 1.0f,
                                                                               Color.FromArgb(0, 100, 0).
                                                                               ToArgb());
                    }

                    // Set the vertice positions
                    int i = 0;
                    verticesMouse[i].X   = x;
                    verticesMouse[i].Y   = yMin;
                    verticesMouse[i++].Z = 0.4f;

                    verticesMouse[i].X   = x;
                    verticesMouse[i].Y   = yMax;
                    verticesMouse[i++].Z = 0.4f;
                }

                // Write the vertex drawing buffers
                if (vertexBufferMouse != null)
                {
                    vertexBufferMouse.Dispose();
                }
                vertexBufferMouse = new VertexBuffer(typeof(CustomVertex.TransformedColored),
                                                     verticesMouse.Length,
                                                     device,
                                                     0,
                                                     CustomVertex.TransformedColored.Format,
                                                     Pool.Default);
                GraphicsStream stm = vertexBufferMouse.Lock(0, 0, 0);
                stm.Seek(0, SeekOrigin.Begin);
                stm.Write(verticesMouse);
                vertexBufferMouse.Unlock();

                validMouse = true;
            }
        }