Git Product home page Git Product logo

loki's Introduction

Loki is a collection of graph visualization and interaction tools for Blueprints.NET based graph data models hosted in Microsoft Windows Presentation Framework, Silverlight or HTML5 environments.

An example for the usage of Loki within WPF

WPF has a very nice canvas tool for drawing all kinds of visual stuff. Loki provides an extention to this class called GraphCanvas which makes it easy to draw a customized Blueprints.NET graph. The new canvas provides a build-in property graph which can be used like a normal property graph but is subscribed to all (at the moment at least to a lot of...) vertex and edge manipulation methods so you can see all programmatically changes to the graph immediately.

  1. Add the GraphCanvas.WPF project to your solution

  2. Adapt your MainWindow.xaml to something like this...

    <Grid>
        <Loki:GraphCanvas Grid.Column         = "0"
                          HorizontalAlignment = "Stretch"
                          Name                = "GraphCanvas"
                          VerticalAlignment   = "Stretch"
                          ClipToBounds        = "True"
                          ToolTip             = "Graph canvas"
                          SnapsToDevicePixels = "True" />
    </Grid>
    
  3. Adapt your MainWindow.cs to something like this...

    using System; using System.Windows;

    namespace de.ahzf.Loki.WPFDemo {

    public partial class MainWindow : Window
    {
    
        public MainWindow()
        {
    
            InitializeComponent();
    
            // Customize the vertices caption
            GraphCanvas.VertexCaption = v =>
            {
                Object Name;
                if (v.TryGetProperty("Name", out Name))
                    return Name as String;
                else
                    return v.Id.ToString();
            };
    
            var Graph = GraphCanvas.Graph;
    
            var Alice = Graph.AddVertex(v => v.SetProperty("Name", "Alice"));
            var Bob   = Graph.AddVertex(v => v.SetProperty("Name", "Bob"  ));
            var Carol = Graph.AddVertex(v => v.SetProperty("Name", "Carol"));
            var Dave  = Graph.AddVertex(v => v.SetProperty("Name", "Dave" ));
    
            var e1    = Graph.AddEdge(Alice, "friends", Bob  );
            var e2    = Graph.AddEdge(Bob,   "friends", Carol);
            var e3    = Graph.AddEdge(Alice, "friends", Carol);
            var e4    = Graph.AddEdge(Carol, "friends", Dave );
    
            // Customize the vertices tooltip
            GraphCanvas.VertexToolTip = v => {
                Object Name;
                if (v.TryGetProperty("Name", out Name))
                    return Name as String;
                else
                    return v.Id.ToString();
            };
    
            // Customize the edges tooltip
            GraphCanvas.EdgeToolTip = e => e.Label;
    
        }
    
    }
    

    }

  4. And finally your result will be something like this...

WPFDemo small

loki's People

Contributors

ahzf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.