void Value_PositionChanged(object sender, GraphX.Models.VertexPositionEventArgs args) { if (gg_arearesize.IsChecked == true) { var zoomtop = gg_zoomctrl.TranslatePoint(new Point(0, 0), gg_Area); //dg_Area.UpdateLayout(); var zoombottom = new Point(gg_Area.ActualWidth, gg_Area.ActualHeight); var pos = args.Position; if (pos.X < zoomtop.X) { GraphAreaBase.SetX(args.VertexControl, zoomtop.X, true); } if (pos.Y < zoomtop.Y) { GraphAreaBase.SetY(args.VertexControl, zoomtop.Y, true); } if (pos.X > zoombottom.X) { GraphAreaBase.SetX(args.VertexControl, zoombottom.X, true); } if (pos.Y > zoombottom.Y) { GraphAreaBase.SetY(args.VertexControl, zoombottom.Y, true); } } }
void Value_PositionChanged(object sender, GraphX.Models.VertexPositionEventArgs args) { var zoomtop = zoomctrl.TranslatePoint(new Point(0, 0), Area); var zoombottom = new Point(Area.ActualWidth, Area.ActualHeight); var pos = args.OffsetPosition; if (pos.X < zoomtop.X) { GraphAreaBase.SetX(args.VertexControl, zoomtop.X + 1, true); } if (pos.Y < zoomtop.Y) { GraphAreaBase.SetY(args.VertexControl, zoomtop.Y + 1, true); } if (pos.X > zoombottom.X) { GraphAreaBase.SetX(args.VertexControl, zoombottom.X, true); } if (pos.Y > zoombottom.Y) { GraphAreaBase.SetY(args.VertexControl, zoombottom.Y, true); } }
void dg_Area_Drop(object sender, DragEventArgs e) { if (!e.Data.GetDataPresent(typeof(object))) { return; } //how to get dragged data by its type var pos = dg_zoomctrl.TranslatePoint(e.GetPosition(dg_zoomctrl), dg_Area); var data = new DataVertex(); ThemedDataStorage.FillDataVertex(data); dg_Area.LogicCore.Graph.AddVertex(data); var vc = new VertexControl(data); dg_Area.AddVertex(data, vc); GraphAreaBase.SetX(vc, pos.X); GraphAreaBase.SetY(vc, pos.Y, true); /*if (dg_Area.VertexList.Count() == 1) * { * var of = VisualTreeHelper.GetOffset(vc); * const int offset = 400; * dg_zoomctrl.ZoomTo(new Rect(of.X - offset, of.Y - offset, vc.ActualWidth + offset * 2, vc.ActualHeight + offset * 2)); * } * else dg_zoomctrl.ZoomToFill();*/ }
void dg_Area_Drop(object sender, System.Windows.DragEventArgs e) { if (e.Data.GetDataPresent(typeof(object))) { //how to get dragged data by its type var myobject = e.Data.GetData(typeof(object)) as object; var pos = dg_zoomctrl.TranslatePoint(e.GetPosition(dg_zoomctrl), dg_Area); var data = new DataVertex(); dg_Area.Graph.AddVertex(data); var vc = new VertexControl(data); dg_Area.AddVertex(data, vc); //dg_Area.RelayoutGraph(true); GraphAreaBase.SetX(vc, pos.X + (dg_Area.UseNativeObjectArrange ? dg_Area.Translation.X : 0), true); GraphAreaBase.SetY(vc, pos.Y + (dg_Area.UseNativeObjectArrange ? dg_Area.Translation.Y : 0), true); if (dg_Area.VertexList.Count == 1) { var of = System.Windows.Media.VisualTreeHelper.GetOffset(vc); int offset = 400; dg_zoomctrl.ZoomTo(new Rect(of.X - offset, of.Y - offset, vc.ActualWidth + offset * 2, vc.ActualHeight + offset * 2)); /* //FOR ZoomControl * zoomctrl.Mode = GraphX.Controls.ZoomControlModes.Original; */ } else { dg_zoomctrl.FitToBounds(); } } }
private double ExaggeratedSnappingYModifier(GraphAreaBase area, DependencyObject obj, double val) { if (dg_snapExaggerate.IsChecked ?? false) { return(System.Math.Round(val * 0.01) * 100.0); } return(DragBehaviour.GlobalYSnapModifier(area, obj, val)); }
//Set pixelformat of image. /////!!! private static PixelFormat pixelFormat = PixelFormats.Pbgra32; /// <summary> /// Method exports the GraphArea to an png image. /// </summary> /// <param name="surface">GraphArea control</param> /// <param name="path">Image destination path</param> /// <param name="imgdpi">Optional image DPI parameter</param> /// <param name="imgQuality">Optional image quality parameter (for some formats like JPEG)</param> public static void ExportToImage(GraphAreaBase surface, Uri path, ImageType itype, bool useZoomControlSurface = false, double imgdpi = DefaultDPI, int imgQuality = 100) { //TODO //Create a render bitmap and push the surface to it /*Visual vis = surface; if (useZoomControlSurface) { if (surface.Parent != null && surface.Parent is IZoomControl) vis = (surface.Parent as IZoomControl).PresenterVisual; else if(surface.Parent!=null && surface.Parent is FrameworkElement && (surface.Parent as FrameworkElement).Parent is IZoomControl) vis = ((surface.Parent as FrameworkElement).Parent as IZoomControl).PresenterVisual; } var renderBitmap = new RenderTargetBitmap( //(int)surface.ActualWidth, //(int)surface.ActualHeight, (int)((vis as UIElement).DesiredSize.Width * (imgdpi / DefaultDPI) + 100), (int)((vis as UIElement).DesiredSize.Height * (imgdpi / DefaultDPI) + 100), imgdpi, imgdpi, pixelFormat); //Render the graphlayout onto the bitmap. renderBitmap.Render(vis); //Create a file stream for saving image using (FileStream outStream = new FileStream(path.LocalPath, FileMode.Create)) { //Use png encoder for our data BitmapEncoder encoder; switch (itype) { case ImageType.PNG: encoder = new PngBitmapEncoder(); break; case ImageType.JPEG: encoder = new JpegBitmapEncoder() { QualityLevel = imgQuality }; break; case ImageType.BMP: encoder = new BmpBitmapEncoder(); break; case ImageType.GIF: encoder = new GifBitmapEncoder(); break; case ImageType.TIFF: encoder = new TiffBitmapEncoder(); break; default: throw new GX_InvalidDataException("ExportToImage() -> Unknown output image format specified!"); } //Push the rendered bitmap to it encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); //Save the data to the stream encoder.Save(outStream); }*/ }
public override void RunVertexAnimation() { //custom event signal preparations _vMaxCount = VertexStorage.Count; _vCounter = 0; var defaultValues = IsDefaultCoordinates(); foreach (var item in VertexStorage) { if (item.Key is EdgeControl) { throw new GX_InvalidDataException("AnimateVertex() -> Got edge control instead vertex control!"); } var control = item.Key as Control; if (defaultValues) { GraphAreaBase.SetX(control, GraphAreaBase.GetFinalX(control)); GraphAreaBase.SetY(control, GraphAreaBase.GetFinalY(control)); CreateStory(control, 0, 1, (o2, e2) => { _vCounter++; if (_vCounter == _vMaxCount) { OnCompleted(); } }).Begin(); } else { CreateStory(control, 1, 0, (o, e) => { if (!VertexStorage.ContainsKey(item.Key)) { return; //just in case of... who knows what? } GraphAreaBase.SetX(control, GraphAreaBase.GetFinalX(control)); GraphAreaBase.SetY(control, GraphAreaBase.GetFinalY(control)); CreateStory(control, 0, 1, (o2, e2) => { _vCounter++; if (_vCounter == _vMaxCount) { OnCompleted(); } }).Begin(); }).Begin(); } } }
public override void RunVertexAnimation() { _maxCount = VertexStorage.Count * 2; _counter = 0; foreach (var item in VertexStorage) { var control = item.Key as Control; double from = GraphAreaBase.GetX(control); from = double.IsNaN(from) ? 0.0 : from; //create the animation for the horizontal position var animationX = new DoubleAnimation( from, item.Value.X, Duration, FillBehavior.HoldEnd); animationX.Completed += (s, e) => { control.BeginAnimation(GraphAreaBase.XProperty, null); control.SetValue(GraphAreaBase.XProperty, item.Value.X); _counter++; if (_counter == _maxCount) { OnCompleted(); } }; control.BeginAnimation(GraphAreaBase.XProperty, animationX, HandoffBehavior.Compose); from = GraphAreaBase.GetY(control); from = (double.IsNaN(from) ? 0.0 : from); //create an animation for the vertical position var animationY = new DoubleAnimation( from, item.Value.Y, Duration, FillBehavior.HoldEnd); animationY.Completed += (s, e) => { control.BeginAnimation(GraphAreaBase.YProperty, null); control.SetValue(GraphAreaBase.YProperty, item.Value.Y); _counter++; if (_counter == _maxCount) { OnCompleted(); } }; control.BeginAnimation(GraphAreaBase.YProperty, animationY, HandoffBehavior.Compose); } }
private VertexControl CreateVertexControl(Point position) { var data = new DataVertex("Vertex " + (graphArea.VertexList.Count + 1)) { ImageId = ShowcaseHelper.Rand.Next(0, ThemedDataStorage.EditorImages.Count) }; graphArea.LogicCore.Graph.AddVertex(data); var vc = new VertexControl(data); graphArea.AddVertex(data, vc); GraphAreaBase.SetX(vc, position.X, true); GraphAreaBase.SetY(vc, position.Y, true); return(vc); }
public static void ShowPrintPreview(GraphAreaBase surface, string description = "") { //TODO /* try { var printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { printDialog.PrintVisual(surface, description); } } catch (Exception ex) { new MessageDialog("Unexpected exception occured while trying to acces default printer. Please ensure that default printer is installed in your OS!").Show(); }*/ }
private void OnGiveFeedback(object sender, GiveFeedbackEventArgs e) { if (LinkPreviewBehavior.LinkPreview == null) { return; } // TODO cached this maybe. not efficient here GraphAreaBase graphArea = AssociatedObject.FindVisualParentOfType <GraphAreaBase>(); ZoomControl zoomControl = graphArea.FindVisualParentOfType <ZoomControl>(); Vector halfsize = new Vector((double)(e.OriginalSource as UIElement).GetValue(FrameworkElement.WidthProperty) / 2.0, (double)(e.OriginalSource as UIElement).GetValue(FrameworkElement.HeightProperty) / 2.0); LinkPreviewBehavior.LinkPreview.SetCurrentValue(UIElement.IsEnabledProperty, true); LinkPreviewBehavior.LinkPreview.Start = (e.OriginalSource as UIElement).TranslatePoint(new Point(0, 0), graphArea) + halfsize; LinkPreviewBehavior.LinkPreview.End = zoomControl.TranslatePoint(MouseHelper.GetMousePosition(zoomControl), graphArea); }
private static void UpdateCoordinates(DependencyObject obj, double horizontalChange, double verticalChange) { if (double.IsNaN(GraphAreaBase.GetX(obj))) { GraphAreaBase.SetX(obj, 0, true); } if (double.IsNaN(GraphAreaBase.GetY(obj))) { GraphAreaBase.SetY(obj, 0, true); } //move the object var x = GraphAreaBase.GetX(obj) + horizontalChange; GraphAreaBase.SetX(obj, x, true); var y = GraphAreaBase.GetY(obj) + verticalChange; GraphAreaBase.SetY(obj, y, true); }
void butGroupedGraph_Click(object sender, RoutedEventArgs e) { CreateNewArea(); dg_Area.LogicCore.Graph = ShowcaseHelper.GenerateDataGraph(10, true); dg_Area.LogicCore.Graph.Vertices.Take(5).ForEach(a => a.GroupId = 1); dg_Area.LogicCore.Graph.Vertices.Where(a => a.GroupId == 0).ForEach(a => a.GroupId = 2); dg_Area.LogicCore.DefaultOverlapRemovalAlgorithm = OverlapRemovalAlgorithmTypeEnum.None; //generate group params var prms = new List <AlgorithmGroupParameters <DataVertex, DataEdge> > { new AlgorithmGroupParameters <DataVertex, DataEdge> { GroupId = 1, LayoutAlgorithm = new RandomLayoutAlgorithm <DataVertex, DataEdge, GraphExample>( new RandomLayoutAlgorithmParams { Bounds = new Rect(0, 0, 500, 500) }), // ZoneRectangle = new Rect(0, 0, 500, 500) }, new AlgorithmGroupParameters <DataVertex, DataEdge> { GroupId = 2, LayoutAlgorithm = new RandomLayoutAlgorithm <DataVertex, DataEdge, GraphExample>( new RandomLayoutAlgorithmParams { Bounds = new Rect(0, 0, 500, 500) }), // ZoneRectangle = new Rect(1000, 0, 500, 500) } }; var gParams = new GroupingLayoutAlgorithmParameters <DataVertex, DataEdge>(prms, true); //generate grouping algo dg_Area.LogicCore.ExternalLayoutAlgorithm = new GroupingLayoutAlgorithm <DataVertex, DataEdge, BidirectionalGraph <DataVertex, DataEdge> >(dg_Area.LogicCore.Graph, null, gParams); //generate graphs dg_Area.GenerateGraph(); //generate group visuals foreach (var item in prms) { if (!item.ZoneRectangle.HasValue) { continue; } var rect = new Rectangle { Width = item.ZoneRectangle.Value.Width, Height = item.ZoneRectangle.Value.Height, Fill = item.GroupId == 1 ? Brushes.Blue : Brushes.Black, Opacity = .5 }; dg_Area.InsertCustomChildControl(0, rect); GraphAreaBase.SetX(rect, item.ZoneRectangle.Value.X); GraphAreaBase.SetY(rect, item.ZoneRectangle.Value.Y); } dg_zoomctrl.ZoomToFill(); }
public override void RunVertexAnimation() { _maxCount = VertexStorage.Count * 2; _counter = 0; foreach (var item in VertexStorage) { var control = item.Key as Control; var from = GraphAreaBase.GetX(control); from = double.IsNaN(from) ? 0.0 : from; #if WPF //create the animation for the horizontal position var animationX = new DoubleAnimation( from, item.Value.X, Duration, FillBehavior.HoldEnd); animationX.Completed += (s, e) => { control.BeginAnimation(GraphAreaBase.XProperty, null); control.SetValue(GraphAreaBase.XProperty, item.Value.X); _counter++; if (_counter == _maxCount) { OnCompleted(); } }; control.BeginAnimation(GraphAreaBase.XProperty, animationX, HandoffBehavior.Compose); from = GraphAreaBase.GetY(control); from = (double.IsNaN(from) ? 0.0 : from); //create an animation for the vertical position var animationY = new DoubleAnimation( from, item.Value.Y, Duration, FillBehavior.HoldEnd); animationY.Completed += (s, e) => { control.BeginAnimation(GraphAreaBase.YProperty, null); control.SetValue(GraphAreaBase.YProperty, item.Value.Y); _counter++; if (_counter == _maxCount) { OnCompleted(); } }; control.BeginAnimation(GraphAreaBase.YProperty, animationY, HandoffBehavior.Compose); #elif METRO var to = item.Value.X; //Here we implement workaround for WinRT stupid limitations: // - Can't animate custom attached props //First we set final coordinate that doesn't affect rendering // --> Already set in GraphArea computation logic <-- GraphAreaBase.SetFinalX(control, to); //And now we animate Canvas.Left property that affect rendering AnimationHelper.CreateDoubleAnimation(from, to, Duration.TotalMilliseconds, "(Canvas.Left)", control, null, (s, e) => { //After animation is complete we set X coordinate to FinalX stored earlier //This is needed to maintain old coordinates system and avoid major changes in overall library GraphAreaBase.SetX(control, GraphAreaBase.GetFinalX(control)); _counter++; if (_counter == _maxCount) { OnCompleted(); } }).Begin(); //Repeat the same for Y coordinates from = GraphAreaBase.GetY(control); from = (double.IsNaN(from) ? 0.0 : from); to = item.Value.Y; //GraphAreaBase.SetFinalY(control, to); AnimationHelper.CreateDoubleAnimation(from, to, Duration.TotalMilliseconds, "(Canvas.Top)", control, null, (s, e) => { GraphAreaBase.SetY(control, GraphAreaBase.GetFinalY(control)); _counter++; if (_counter == _maxCount) { OnCompleted(); } }).Begin(); #else throw new NotImplementedException(); #endif } }
private void GenerateGraph() { graphArea.ClearLayout(); var logicCore = new LogicCoreExample() { Graph = ShowcaseHelper.GenerateDataGraph(10) }; logicCore.Graph.Vertices.Take(5).ForEach(a => a.GroupId = 1); logicCore.Graph.Vertices.Where(a => a.GroupId == 0).ForEach(a => a.GroupId = 2); logicCore.DefaultOverlapRemovalAlgorithm = OverlapRemovalAlgorithmTypeEnum.None; //generate group params var prms = new List <AlgorithmGroupParameters <DataVertex, DataEdge> > { new AlgorithmGroupParameters <DataVertex, DataEdge> { GroupId = 1, LayoutAlgorithm = new RandomLayoutAlgorithm <DataVertex, DataEdge, GraphExample>( new RandomLayoutAlgorithmParams { Bounds = new Rect(10, 10, 490, 490) }), }, new AlgorithmGroupParameters <DataVertex, DataEdge> { GroupId = 2, LayoutAlgorithm = new RandomLayoutAlgorithm <DataVertex, DataEdge, GraphExample>( new RandomLayoutAlgorithmParams { Bounds = new Rect(10, 10, 490, 490) }), } }; var gParams = new GroupingLayoutAlgorithmParameters <DataVertex, DataEdge>(prms, true) { OverlapRemovalAlgorithm = logicCore.AlgorithmFactory.CreateFSAA <object>(100, 100), ArrangeGroups = cbArrangeGroups.IsChecked ?? false, }; //generate grouping algo logicCore.ExternalLayoutAlgorithm = new GroupingLayoutAlgorithm <DataVertex, DataEdge, BidirectionalGraph <DataVertex, DataEdge> >(logicCore.Graph, null, gParams); graphArea.LogicCore = logicCore; //generate graphs graphArea.GenerateGraph(); //generate group visuals foreach (var item in prms) { if (!item.ZoneRectangle.HasValue) { continue; } var rect = GenerateGroupBorder(item); graphArea.InsertCustomChildControl(0, rect); GraphAreaBase.SetX(rect, item.ZoneRectangle.Value.X - _groupInnerPadding * .5); GraphAreaBase.SetY(rect, item.ZoneRectangle.Value.Y - _groupInnerPadding * .5 - _headerHeight); } zoomControl.ZoomToFill(); }
/// <summary> /// /// </summary> /// <param name="graphArea"></param> public NodeGraphControlFactory(GraphAreaBase graphArea) { FactoryRootArea = graphArea; }
public GraphControlFactory(GraphAreaBase graphArea) { FactoryRootArea = graphArea; }
public VisualGraphControlFactory(GraphAreaBase graphArea) : base(graphArea) { }
internal ElementBuilderControlFactory(GraphAreaBase area) : base(area) { }