コード例 #1
0
        public override void OnCalculateMinMax()
        {
            MinValue = double.MaxValue;
            MaxValue = double.MinValue;

            if (!IsVisible)
            {
                return;
            }

            if (ChartAnchors.Any(a => !a.IsEditing))
            {
                foreach (ChartAnchor ca in ChartAnchors)
                {
                    MinValue = Math.Min(MinValue, ca.Price);
                    MaxValue = Math.Max(MaxValue, ca.Price);
                }
            }
        }
コード例 #2
0
        public override bool IsVisibleOnChart(ChartControl chartControl, ChartScale chartScale, DateTime firstTimeOnChart, DateTime lastTimeOnChart)
        {
            if (DrawingState == DrawingState.Building)
            {
                return(true);
            }

            float      minX       = float.MaxValue;
            float      maxX       = float.MinValue;
            ChartPanel chartPanel = chartControl.ChartPanels[PanelIndex];

            foreach (Point pt in ChartAnchors.Select(a => a.GetPoint(chartControl, chartPanel, chartScale)))
            {
                minX = (float)Math.Min(minX, pt.X);
                maxX = (float)Math.Max(maxX, pt.X);
            }

            DateTime leftWidthTime  = chartControl.GetTimeByX((int)minX);
            DateTime rightWidthTime = chartControl.GetTimeByX((int)maxX);

            return(leftWidthTime <= lastTimeOnChart && rightWidthTime >= firstTimeOnChart);
        }
コード例 #3
0
        public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint)
        {
            Point p = dataPoint.GetPoint(chartControl, chartPanel, chartScale);

            switch (DrawingState)
            {
            case DrawingState.Building:
                if (ChartAnchors.Count == 0)
                {
                    ChartAnchors.Add(new ChartAnchor {
                        DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchor, IsEditing = true, DrawingTool = this
                    });
                }

                foreach (ChartAnchor ca in ChartAnchors)
                {
                    if (ca.IsEditing)
                    {
                        dataPoint.CopyDataValues(ca);
                        ca.IsEditing = false;
                    }
                }

                ChartAnchor clickTestAnchor = GetClosestAnchor(chartControl, chartPanel, chartScale, cursorSensitivity, p);

                if (ChartAnchors.Count > 1 && doubleClickTimer.IsEnabled && clickTestAnchor != null && clickTestAnchor != ChartAnchors[ChartAnchors.Count - 1])
                {
                    // ChartAnchors[ChartAnchors.Count - 1] is the 'temp anchor'
                    ChartAnchors.Remove(ChartAnchors[ChartAnchors.Count - 1]);
                    PathToolSegments.Remove(PathToolSegments[PathToolSegments.Count - 1]);
                    doubleClickTimer.Stop();
                    DrawingState = DrawingState.Normal;
                    IsSelected   = false;
                }
                else
                {
                    ChartAnchor ca = new ChartAnchor {
                        DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchor, IsEditing = true, DrawingTool = this
                    };

                    dataPoint.CopyDataValues(ca);
                    ChartAnchors.Add(ca);

                    if (ChartAnchors.Count > 1)
                    {
                        PathToolSegments.Add(new PathToolSegment(ChartAnchors[ChartAnchors.Count - 2], ChartAnchors[ChartAnchors.Count - 1], string.Format("{0} {1}", Custom.Resource.NinjaScriptDrawingToolPathSegment, PathToolSegments.Count + 1)));

                        if (!doubleClickTimer.IsEnabled)
                        {
                            doubleClickTimer.Start();
                        }
                    }
                }
                break;

            case DrawingState.Normal:
                editingAnchor = GetClosestAnchor(chartControl, chartPanel, chartScale, cursorSensitivity, p);

                if (editingAnchor != null)
                {
                    editingAnchor.IsEditing = true;
                    DrawingState            = DrawingState.Editing;
                }
                else
                {
                    if (GetCursor(chartControl, chartPanel, chartScale, p) != null)
                    {
                        DrawingState = DrawingState.Moving;
                    }
                }
                break;
            }
        }
コード例 #4
0
ファイル: Polygon.cs プロジェクト: theprofe8/nt8
        public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint)
        {
            Point p = dataPoint.GetPoint(chartControl, chartPanel, chartScale);

            switch (DrawingState)
            {
            case DrawingState.Building:
                if (ChartAnchors.Count == 0)
                {
                    ChartAnchors.Add(new ChartAnchor {
                        DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchor, IsEditing = true, DrawingTool = this
                    });
                }

                foreach (ChartAnchor ca in ChartAnchors)
                {
                    if (ca.IsEditing)
                    {
                        dataPoint.CopyDataValues(ca);
                        ca.IsEditing = false;
                    }
                }

                if (ChartAnchors.Count > 2 && (GetCursor(chartControl, chartPanel, chartScale, p) == Cursors.Cross || DateTime.Now.Subtract(lastClick).TotalMilliseconds <= 200))
                {
                    ChartAnchors.Remove(ChartAnchors[ChartAnchors.Count - 1]);
                    DrawingState = DrawingState.Normal;
                    IsSelected   = false;
                }
                else
                {
                    ChartAnchor ca = new ChartAnchor {
                        DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchor, IsEditing = true, DrawingTool = this
                    };
                    dataPoint.CopyDataValues(ca);
                    ChartAnchors.Add(ca);
                }

                lastClick = DateTime.Now;
                break;

            case DrawingState.Normal:
                editingAnchor = GetClosestAnchor(chartControl, chartPanel, chartScale, cursorSensitivity, p);
                if (editingAnchor != null)
                {
                    editingAnchor.IsEditing = true;
                    DrawingState            = DrawingState.Editing;
                }
                else
                {
                    if (GetCursor(chartControl, chartPanel, chartScale, p) != null)
                    {
                        DrawingState = DrawingState.Moving;
                    }
                    else if (!IsPointInsidePolygon(chartControl, chartPanel, chartScale, p))
                    {
                        IsSelected = false;
                    }
                }
                break;
            }
        }