Пример #1
0
        internal ValueGrid(GridRange gr, double low, double up, ValueAxisUnit vAxis, double basevalue)
        {
            double grLower = Double.MaxValue;
            double grUpper = Double.MinValue;

            if (gr != null)
            {
                this.rigid = gr.Rigid;
                grLower    = gr.LowerValue;
                grUpper    = gr.UpperValue;
            }

            this.lower     = low;
            this.upper     = up;
            this.vAxis     = vAxis;
            this.baseValue = basevalue;

            // Fill in the scale values
            double tmp = 1;

            for (int i = 1; i < 7; i++)
            {
                tmp *= baseValue;
                scaleValues[6 - i] = tmp;
            }
            tmp = 1;
            for (int i = 7; i < scaleValues.Length; i++)
            {
                tmp           *= baseValue;
                scaleValues[i] = (1 / tmp);
            }

            // Set an appropriate value axis it not given yet
            SetValueAxis();

            if (!rigid)
            {
                this.lower = (lower == grLower ? grLower : this.vAxis.GetNiceLower(lower));
                this.upper = (upper == grUpper ? grUpper : this.vAxis.GetNiceHigher(upper));
            }
        }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="lower"></param>
 /// <param name="upper"></param>
 /// <param name="rigid"></param>
 public void SetGridRange(double lower, double upper, bool rigid)
 {
     gridRange = new GridRange(lower, upper, rigid);
 }
Пример #3
0
        private void PlotChart(Graphics graphics)
        {
            int lux = x_offset + chart_lpadding;
            int luy = y_offset + CHART_UPADDING;

            //defaultBrush.Color = Color.White;
            //defaultPen.Color = Color.Black;

            //if ( graphDef.Background == null )
            //{
            defaultBrush.Color = graphDef.CanvasColor;
            graphics.FillRectangle(defaultBrush, lux, luy, chartWidth, chartHeight);
            //}

            // Draw the chart area frame
            defaultPen.Color = graphDef.FrameColor;
            graphics.DrawRectangle(defaultPen, lux, luy, chartWidth, chartHeight);

            double val;

            double[] tmpSeries = new double[numPoints];

            GridRange range      = graphDef.GridRange;
            bool      rigid      = (range != null ? range.Rigid : false);
            double    lowerValue = (range != null ? range.LowerValue : Double.MaxValue);
            double    upperValue = (range != null ? range.UpperValue : Double.MinValue);

            // For autoscale, detect lower and upper limit of values
            PlotDef[] plotDefs = graphDef.PlotDefs;
            for (int i = 0; i < plotDefs.Length; i++)
            {
                plotDefs[i].SetSource(sources, sourceIndex);
                Source src = plotDefs[i].Source;

                // Only try autoscale when we do not have a rigid grid
                if (!rigid && src != null)
                {
                    double min = src.GetAggregate(Source.AGG_MINIMUM);
                    double max = src.GetAggregate(Source.AGG_MAXIMUM);

                    // If the plotdef is a stack, evaluate ALL previous values to find a possible max
                    if (plotDefs[i].plotType == PlotDef.PLOT_STACK && i >= 1)
                    {
                        if (plotDefs[i - 1].plotType == PlotDef.PLOT_STACK)                                     // Use this source plus stack of previous ones

                        {
                            for (int j = 0; j < tmpSeries.Length; j++)
                            {
                                val = tmpSeries[j] + plotDefs[i].GetValue(j, timestamps);

                                if (val < lowerValue)
                                {
                                    lowerValue = val;
                                }
                                if (val > upperValue)
                                {
                                    upperValue = val;
                                }

                                tmpSeries[j] = val;
                            }
                        }
                        else                                                                                                                                    // Use this source plus the previous one

                        {
                            for (int j = 0; j < tmpSeries.Length; j++)
                            {
                                val = plotDefs[i - 1].GetValue(j, timestamps) + plotDefs[i].GetValue(j, timestamps);

                                if (val < lowerValue)
                                {
                                    lowerValue = val;
                                }
                                if (val > upperValue)
                                {
                                    upperValue = val;
                                }

                                tmpSeries[j] = val;
                            }
                        }
                    }
                    else                                // Only use min/max of a single datasource
                    {
                        if (min < lowerValue)
                        {
                            lowerValue = min;
                        }
                        if (max > upperValue)
                        {
                            upperValue = max;
                        }
                    }
                }
            }

            vGrid = new ValueGrid(range, lowerValue, upperValue, graphDef.ValueAxis, graphDef.BaseValue);
            tGrid = new TimeGrid(graphDef.StartTime, (graphDef.EndTime != 0? graphDef.EndTime : calculatedEndTime), graphDef.TimeAxis, graphDef.FirstDayOfWeek);

            lowerValue = vGrid.LowerValue;
            upperValue = vGrid.UpperValue;

            // Use a special graph 'object' that takes care of resizing and reversing y coordinates
            ChartGraphics g = new ChartGraphics(graphics);

            g.SetDimensions(chartWidth, chartHeight);
            g.SetXRange(tGrid.StartTime, tGrid.EndTime);
            g.SetYRange(lowerValue, upperValue);

            // Set the chart origin point
            double diff = 1.0d;

            if (lowerValue < 0)
            {
                diff = 1.0d - (lowerValue / (-upperValue + lowerValue));
            }
            graphOriginX = lux;
            graphOriginY = (int)(luy + chartHeight * diff);

            // If the grid is behind the plots, draw it first
            if (!graphDef.FrontGrid)
            {
                PlotChartGrid(g);
            }

            // Use AA if necessary
            if (graphDef.AntiAliasing)
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
            }

            // Prepare clipping area and origin
            graphics.SetClip(new System.Drawing.Rectangle(lux, luy, chartWidth, chartHeight));
            graphics.TranslateTransform(graphOriginX, graphOriginY);

            int lastPlotType = PlotDef.PLOT_LINE;

            int[] parentSeries = new int[numPoints];

            // Pre calculate x positions of the corresponding timestamps
            int[] xValues = new int[timestamps.Length];
            for (int i = 0; i < timestamps.Length; i++)
            {
                xValues[i] = g.GetX(timestamps[i]);
            }

            // Draw all graphed values
            for (int i = 0; i < plotDefs.Length; i++)
            {
                plotDefs[i].Draw(g, xValues, parentSeries, lastPlotType);
                if (plotDefs[i].PlotType != PlotDef.PLOT_STACK)
                {
                    lastPlotType = plotDefs[i].PlotType;
                }
            }

            // Reset clipping area, origin and AA settings
            graphics.TranslateTransform((float)-graphOriginX, (float)-graphOriginY);
            graphics.SetClip(new System.Drawing.Rectangle(0, 0, imgWidth, imgHeight));
            graphics.SmoothingMode = SmoothingMode.None;

            // If the grid is in front of the plots, draw it now
            if (graphDef.FrontGrid)
            {
                PlotChartGrid(g);
            }
        }