Ejemplo n.º 1
0
        protected override ChartEventArgs GetChartEvent(object sender, MouseEventArgs e)
        {
            ElementExpandos ee = Expandos[sender];
            int             i  = ee.YValueIndex;

            int[]    yValueIndices = { i };
            double[] values        = { Model.YValues[i, 0] };

            return(new ChartEventArgs(null, yValueIndices, values, null));
        }
Ejemplo n.º 2
0
        protected override ChartEventArgs GetChartEvent(object sender, MouseEventArgs e)
        {
            ElementExpandos ee = Expandos[sender];
            int             i  = ee.YValueIndex;
            int             j  = ee.SeriesIndex;

            int[] seriesIndices = { j };
            int[] yValueIndices = { i };

            // For now use null for the yValue since there are open-high-low-close values at that location
            return(new ChartEventArgs(seriesIndices, yValueIndices, null, null));
        }
Ejemplo n.º 3
0
        protected override ChartEventArgs GetChartEvent(object sender, MouseEventArgs e)
        {
            ElementExpandos ee = Expandos[sender];
            int             i  = ee.YValueIndex;
            int             j  = ee.SeriesIndex;

            int[]    seriesIndices = { j };
            int[]    yValueIndices = { i };
            double[] yValues       = { Model.YValues[i, j] };
            double[] xValues       = { Model.XValues[i, j] };

            return(new ChartEventArgs(seriesIndices, yValueIndices, yValues, xValues));
        }
Ejemplo n.º 4
0
        protected override ChartEventArgs GetChartEvent(object sender, MouseEventArgs e)
        {
            Point           pt = e.GetPosition(ChartCanvas);
            ElementExpandos ee = Expandos[sender];
            int             i  = ee.SeriesIndex;

            bool       isPerspective = IsPerspective;
            double     yOffset       = YOffsetPerspective;
            ChartModel model         = Model;

            double[,] xValues = model.XValues;
            double[,] yValues = model.YValues;
            int nValues = yValues.GetUpperBound(0) + 1;

            double minYValue = model.MinYValue, maxYValue = model.MaxYValue;
            double minXValue = model.MinXValue, maxXValue = model.MaxXValue;

            double marginLeft = MarginLeft, marginTop = MarginTop;
            double gridWidth  = (ChartCanvas.Width - marginLeft - MarginRight);
            double gridHeight = (ChartCanvas.Height - marginTop - MarginBottom);

            double gridBottom = gridHeight + marginTop + (isPerspective?yOffset:0);
            double dx, dy, xValue = 0.0, yValue = 0.0;
            double nextdy, nextdx;

            for (int j = 0; j < nValues; ++j)
            {
                if (j != nValues - 1)
                {
                    dx     = marginLeft + gridWidth * (xValues[j, i] - minXValue) / (maxXValue - minXValue);
                    nextdx = marginLeft + gridWidth * (xValues[j + 1, i] - minXValue) / (maxXValue - minXValue);

                    if (pt.X > dx && pt.X < (dx + nextdx))
                    {
                        dy     = gridBottom - gridHeight * (yValues[j, i] - minYValue) / (maxYValue - minYValue);
                        nextdy = gridBottom -
                                 gridHeight * (yValues[j + 1, i] - minYValue) / (maxYValue - minYValue);

                        yValue = yValues[j, i] + (yValues[j + 1, i] - yValues[j, i]) * (pt.Y - dy) / (nextdy - dy);
                        xValue = xValues[j, i] + (xValues[j + 1, i] - xValues[j, i]) * (pt.X - dx) / (nextdx - dx);
                        break;
                    }
                }
            }

            int[] seriesIndices = { i };
            //double[] yEventValues = {yValue};
            //double[] xEventValues = {xValue};

            return(new ChartEventArgs(seriesIndices, null, new double[] { yValue }, new double[] { xValue }));
        }
Ejemplo n.º 5
0
        protected override ChartEventArgs GetChartEvent(object sender, MouseEventArgs e)
        {
            Point           pt = e.GetPosition(ChartCanvas);
            ElementExpandos ee = Expandos[sender];
            int             i  = ee.SeriesIndex;

            bool   isPerspective = IsPerspective;
            double yOffset       = YOffsetPerspective;

            ChartModel model = Model;

            double [,] yValues = model.YValues;

            string [] groupLabels = model.GroupLabels;
            int       groupCount  = groupLabels.Length;

            double marginLeft = MarginLeft, marginTop = MarginTop;
            double gridWidth   = (ChartCanvas.Width - marginLeft - MarginRight);
            double gridHeight  = (ChartCanvas.Height - marginTop - MarginBottom);
            int    yValueCount = yValues.GetUpperBound(0) + 1;

            double barWidth = (gridWidth / Math.Max(yValueCount, groupCount));

            double gridBottom = gridHeight + marginTop + (isPerspective?yOffset:0);
            double dx = marginLeft + barWidth / 2, value = 0.0;

            for (int j = 0; j < yValueCount; ++j)
            {
                if (j == yValueCount - 1)
                {
                    continue;
                }

                if (pt.X > dx && pt.X < (dx + barWidth))
                {
                    value = yValues[j, i] + (yValues[j + 1, i] - yValues[j, i]) * (pt.X - dx) / barWidth;
                    break;
                }
                dx += barWidth;
            }

            int[]    seriesIndices = { i };
            double[] values        = { value };

            return(new ChartEventArgs(seriesIndices, null, values, null));
        }
Ejemplo n.º 6
0
        protected override ChartEventArgs GetChartEvent(object sender, MouseEventArgs e)
        {
            Point pt = e.GetPosition(ChartCanvas);

            bool       isRadarArea   = (Type == ChartType.RADAR_AREA);
            ChartModel model         = Model;
            bool       isPerspective = IsPerspective;

            double xOffset = XOffsetPerspective, yOffset = YOffsetPerspective;

            string [] groupLabels = model.GroupLabels;
            int       groupCount  = groupLabels.Length;

            double[,] yValues = model.YValues;
            double minValue = model.MinYValue, maxValue = model.MaxYValue;
            int    yValueCount = yValues.GetUpperBound(0) + 1;

            double marginLeft = MarginLeft, marginTop = MarginTop;
            double gridWidth  = (ChartCanvas.Width - marginLeft - MarginRight);
            double gridHeight = (ChartCanvas.Height - marginTop - MarginBottom);

            double cx = marginLeft + gridWidth / 2, cy = marginTop + gridHeight / 2;
            double radius = Math.Min(gridWidth, gridHeight) / 2;

            int             seriesCount = model.SeriesLabels.Length;
            int             seriesIndex = -1;
            ElementExpandos ee          = Expandos[sender];

            if (pt.X < marginLeft ||
                pt.X > (marginLeft + gridWidth) ||
                pt.Y < marginTop ||
                pt.Y > (marginTop + gridHeight))
            {
                return(null);
            }

            if (!isRadarArea)
            {
                seriesIndex = ee.SeriesIndex;
            }

            _seriesXs = new List <double>(seriesCount);
            _seriesYs = new List <double>(seriesCount);

            double        dx1, dy1, dx2, dy2, value;
            List <int>    seriesIndices = new List <int>(seriesCount);
            List <double> seriesValues  = new List <double>(seriesCount);

            for (int i = 0; i < seriesCount; ++i)
            {
                if (!isRadarArea && (seriesIndex != i))
                {
                    continue;
                }

                for (int j = 0; j < yValueCount; ++j)
                {
                    double nextYVal  = (j != yValueCount - 1)? yValues[j + 1, i]: yValues[0, i];
                    double yPoint    = radius * (yValues[j, i] - minValue) / (maxValue - minValue);
                    double yPoint2   = radius * (nextYVal - minValue) / (maxValue - minValue);
                    double angle     = j * 2.0 * Math.PI / yValueCount,
                           nextAngle = (j + 1) * 2.0 * Math.PI / yValueCount;
                    dx1 = cx + yPoint * Math.Sin(angle);
                    dy1 = cy - yPoint * Math.Cos(angle);

                    dx2 = cx + yPoint2 * Math.Sin(nextAngle);
                    dy2 = cy - yPoint2 * Math.Cos(nextAngle);

                    if (_isPointInPolygon(new double [] { cx, dx1, dx2 }, new double [] { cy, dy1, dy2 }, pt.X, pt.Y))
                    {
                        // find the point on the radar that matches the current mouse
                        // using the angle of the current mouse point
                        double mousePtAngle = Math.Atan2(cy - pt.Y, pt.X - cx);

                        if (mousePtAngle <= Math.PI / 2)
                        {
                            mousePtAngle = Math.PI / 2 - mousePtAngle;
                        }
                        else
                        {
                            mousePtAngle = 3 * Math.PI / 2 + (Math.PI - mousePtAngle);
                        }

                        double ratio = (mousePtAngle - angle) / (nextAngle - angle);

                        value = yValues[j, i] + (nextYVal - yValues[j, i]) * ratio;

                        seriesValues.Add(value);
                        seriesIndices.Add(i);
                        _seriesYs.Add(dy1 + (dy2 - dy1) * ratio);
                        _seriesXs.Add(dx1 + (dx2 - dx1) * ratio);
                        break;
                    }
                }
            }

            return(new ChartEventArgs(seriesIndices.ToArray(), null, seriesValues.ToArray(), null));
        }