Code Monkey home page Code Monkey logo

oxysnel's Introduction

OxySnel

Throw an interactive plot at the screen quickly from a .NET Core 2.0 console application. Old versions seemed to work fine on non-Windows platforms (OSX needs the StartOnThread stuff), but the current version hasn't been tested.

This repo serves the purpose of being a minimal but not completely pointless example of OxyPlot-Avalonia where I can find it; to provide a simple example of OxyPlot under C#, VB, and F#; and to let me test stuff in a non-trivial NuGet package. It's also kind of useful if you need an interactive plot in a hurry.

Minimal API

Only four methods that matter:

  • public static void OxySnel.Snel.StartOnThread(Action starter, bool callbackOffthread)

    Starts OxySnel on the current thread: this may be necessary for some systems (e.g. OSX)

  • public static Task<IPlotWindow> OxySnel.Snel.Show(PlotModel plotModel, string windowTitle = DefaultWindowTitle)

    Opens a new Avalonia window showing the given PlotModel with its own UI Thread.

  • public static Task OxySnel.Snel.Invoke(Action action)

    Invokes an Action on the UI Thread

  • public static void OxySnel.Snel.Kill()

    Kills the OxySnel background stuff permanently. Once you call Show, the application won't end until you call Kill. This aspect of the API is liable to change in the future when I've come up with something less terrible.

Example

// make a plot...
var plot = new PlotModel() { Title = "Time-to-plot" };

// add some series...
var bs = new BarSeries() { BaseValue = 0 };
bs.Items.Add(new BarItem(10));
bs.Items.Add(new BarItem(2));
plot.Series.Add(bs);

// add some axes
var categoryAxis = new CategoryAxis() { Position = AxisPosition.Left, Angle = -90 };
categoryAxis.Labels.Add("Without OxySnel");
categoryAxis.Labels.Add("With OxySnel");
plot.Axes.Add(categoryAxis);

var timeAxis = new LinearAxis() { Position = AxisPosition.Bottom, Title = "Time", Unit = "Money" };
plot.Axes.Add(timeAxis);

// show the plot
OxySnel.Snel.Show(plot);

// pause
Console.ReadKey(true);

// kill it
OxySnel.Snel.Kill();

A more fun example is provided for C#, VB, and F# in the SnelTestCS, SnelTestVB, and SnelTestFS directories.

For OSX, you need to run the UI on the startup thread. Use the OxySnel.Snel.StartOnThread method, e.g.

static void Main(string[] args)
{
    OxySnel.Snel.StartOnThread(() => LogicMain(args), true);
}

static void LogicMain(string[] args)
{
    // do something fun

    // wait and kill
    Console.ReadKey(true);
    OxySnel.Snel.Kill();
}

Package

NuGet Package feed from MyGet: https://www.myget.org/F/oxysnel/api/v3/index.json

From Source

Otherwise:

  1. Clone the repo

    git clone https://github.com/VisualMelon/OxySnel.git

  2. Build it

    dotnet build Source/OxySnel.sln

  3. Run an example?

    dotnet run --project Source/SnelTestCS/SnelTestCS.csproj

    dotnet run --project Source/SnelTestFS/SnelTestVB.fsproj

    dotnet run --project Source/SnelTestFS/SnelTestFS.fsproj

Lazy Plotting API

I might expand the Plot class so that people can be even more lazy. Currently, you need this many lines of code to display a plot (ignoring initialisation and cleanup).

var timePlot = OxySnel.Plot.Linear("X", "Y");
timePlot.Line(xs, ys);
OxySnel.Snel.Show(timePlot);

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.