Skip to content

Commit

Permalink
3.0.0 Plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
BiologyTools committed Jun 20, 2023
1 parent 9edb4e2 commit 44680bc
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 13 deletions.
10 changes: 5 additions & 5 deletions BioGTK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<RuntimeIdentifiers>osx-x64;linux-x64;win7-x64;linux-arm64;osx-arm64</RuntimeIdentifiers>
<AssemblyVersion>2.9.0</AssemblyVersion>
<FileVersion>2.9.0</FileVersion>
<AssemblyVersion>3.0.0</AssemblyVersion>
<FileVersion>3.0.0</FileVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>BioGTK</PackageId>
<Title>BioGTK</Title>
<PackageProjectUrl>https://github.com/BiologyTools/BioGTK</PackageProjectUrl>
<PackageIcon>banner.jpg</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageVersion>2.9.0</PackageVersion>
<PackageVersion>3.0.0</PackageVersion>
<RepositoryUrl>https://github.com/BiologyTools/BioGTK</RepositoryUrl>
<PackageTags>Biology; GTK; ImageJ; Bio-Formats; Image-Stacks; Microscopy;</PackageTags>
<PackageLicenseExpression> GPL-3.0-only</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<Description>A .NET application &amp; library for editing &amp; annotating various microscopy image formats. Supports all bioformats supported images. Integrates with ImageJ, running ImageJ filters &amp; macro functions. Supports Windows, Linux and Mac.</Description>
<Version>2.9.0</Version>
<Version>3.0.0</Version>
<Platforms>AnyCPU;x64;ARM64</Platforms>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
<PackageReleaseNotes>GUI bug fixes.</PackageReleaseNotes>
<PackageReleaseNotes>Added Plotting functionality, and find focus function.</PackageReleaseNotes>
<Authors>ErikRepo</Authors>
</PropertyGroup>

Expand Down
95 changes: 94 additions & 1 deletion Glade/Plot.glade
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,103 @@
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="plot">
<property name="can-focus">False</property>
<property name="default-width">600</property>
<property name="default-height">400</property>
<child>
<object class="GtkDrawingArea" id="image">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar" id="MainMenu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkMenuItem" id="fileMenu">
<property name="name">fileMenu</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-bottom">1</property>
<property name="label" translatable="yes">File</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkImageMenuItem" id="saveImageMenu">
<property name="label">Save Image</property>
<property name="name">openImagesMenu</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="use-stock">False</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="saveCSVMenu">
<property name="label">Save CSV</property>
<property name="name">openImagesMenu</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="use-stock">False</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="viewMenu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">View</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkCheckMenuItem" id="barMenu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Bar</property>
<property name="active">True</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="signalMenu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Signal</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="scatterMenu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Scatter</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkDrawingArea" id="image">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
127 changes: 121 additions & 6 deletions Source/Plot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using org.checkerframework.checker.units.qual;
using ScottPlot;
using System.Threading;
using System.IO;

namespace BioGTK
{
Expand All @@ -23,6 +24,19 @@ public class Plot : Gtk.Window
Bitmap bitmap;
List<double[]> data = new List<double[]>();
static Dictionary<string, Plot> plots = new Dictionary<string, Plot>();

public enum PlotType
{
Bar,
Signal,
Scatter
}
PlotType type;
public PlotType Type
{
get { return type; }
set { type = value; }
}
public static Dictionary<string,Plot> Plots
{
get { return plots; }
Expand All @@ -42,11 +56,15 @@ public void UpdateImage()
plot = new ScottPlot.Plot(AllocatedWidth, AllocatedHeight);
foreach (double[] val in data)
{
plot.AddBar(val);
if(type == PlotType.Bar)
plot.AddBar(val);
else
plot.AddSignal(val);
}
file = plot.SaveFig(name + ".png");
this.Title = name;
pixbuf = new Pixbuf(file);
image.QueueDraw();
}

#region Properties
Expand All @@ -56,7 +74,17 @@ public void UpdateImage()
[Builder.Object]
private Gtk.DrawingArea image;
[Builder.Object]
private Gtk.Label label;
private Gtk.MenuItem saveImageMenu;
[Builder.Object]
private Gtk.MenuItem saveCSVMenu;

[Builder.Object]
private Gtk.CheckMenuItem barMenu;
[Builder.Object]
private Gtk.CheckMenuItem signalMenu;
[Builder.Object]
private Gtk.CheckMenuItem scatterMenu;

#pragma warning restore 649
#endregion

Expand All @@ -68,18 +96,31 @@ public void UpdateImage()
public static Plot Create(double[] vals, string name)
{
Builder builder = new Builder(null, "BioGTK.Glade.Plot.glade", null);
return new Plot(builder, builder.GetObject("plot").Handle, vals, name);
return new Plot(builder, builder.GetObject("plot").Handle, vals, name, PlotType.Bar);
}
/// It creates a new instance of the Plot class.
///
/// @return A new instance of the Plot class.
public static Plot Create(double[] vals, string name, PlotType typ)
{
Builder builder = new Builder(null, "BioGTK.Glade.Plot.glade", null);
return new Plot(builder, builder.GetObject("plot").Handle, vals, name, typ);
}


/* It's the constructor of the class. */
protected Plot(Builder builder, IntPtr handle, double[] vals, string name) : base(handle)
protected Plot(Builder builder, IntPtr handle, double[] vals, string name, PlotType typ) : base(handle)
{
_builder = builder;
builder.Autoconnect(this);
this.Title = name;
image.Drawn += Image_Drawn;
image.SizeAllocated += Image_SizeAllocated;
image.ButtonPressEvent += Image_ButtonPressEvent;
barMenu.ButtonPressEvent += BarMenu_ButtonPressEvent;
signalMenu.ButtonPressEvent += SignalMenu_ButtonPressEvent;
scatterMenu.ButtonPressEvent += ScatterMenu_ButtonPressEvent;
saveImageMenu.ButtonPressEvent += SaveImageMenu_ButtonPressEvent;
saveCSVMenu.ButtonPressEvent += SaveCSVMenu_ButtonPressEvent;
this.DeleteEvent += About_DeleteEvent;
data.Add(vals);
this.name = name;
Expand All @@ -89,6 +130,81 @@ protected Plot(Builder builder, IntPtr handle, double[] vals, string name) : bas
else
plots.Add(name,this);
}

private void SaveCSVMenu_ButtonPressEvent(object o, ButtonPressEventArgs args)
{
Gtk.FileChooserDialog filechooser =
new Gtk.FileChooserDialog("Save CSV Plot data.",
this,
FileChooserAction.Save,
"Cancel", ResponseType.Cancel,
"Save", ResponseType.Accept);
if (filechooser.Run() != (int)ResponseType.Accept)
return;

string s = "";
foreach (double[] item in data)
{
for (int i = 0; i < data.Count; i++)
{
s += i + ",";
}
s += Environment.NewLine;
foreach (double d in item)
{
s += d + "," + Environment.NewLine;
}
}
File.WriteAllText(filechooser.Filename, s);
filechooser.Destroy();

}

private void SaveImageMenu_ButtonPressEvent(object o, ButtonPressEventArgs args)
{
Gtk.FileChooserDialog filechooser =
new Gtk.FileChooserDialog("Save PNG Image of Plot.",
this,
FileChooserAction.Save,
"Cancel", ResponseType.Cancel,
"Save", ResponseType.Accept);
if (filechooser.Run() != (int)ResponseType.Accept)
return;
pixbuf.Save(filechooser.Filename,"png");
filechooser.Destroy();

}

private void ScatterMenu_ButtonPressEvent(object o, ButtonPressEventArgs args)
{
signalMenu.Active = false;
barMenu.Active = false;
type = PlotType.Scatter;
UpdateImage();
}

private void SignalMenu_ButtonPressEvent(object o, ButtonPressEventArgs args)
{
scatterMenu.Active = false;
barMenu.Active = false;
type = PlotType.Signal;
UpdateImage();
}

private void BarMenu_ButtonPressEvent(object o, ButtonPressEventArgs args)
{
signalMenu.Active = false;
scatterMenu.Active = false;
type = PlotType.Bar;
UpdateImage();
}

private void Image_ButtonPressEvent(object o, ButtonPressEventArgs args)
{
selected = this;
Recorder.AddLine("Plot.SelectedPlot = Plot.Plots[" + name + "];");
}

System.Threading.Thread th;
static Plot selected;
public static Plot SelectedPlot
Expand All @@ -98,7 +214,6 @@ public static Plot SelectedPlot
static void ShowPlot()
{
selected.Show();
selected.Present();
}

private void Image_SizeAllocated(object o, SizeAllocatedArgs args)
Expand Down
2 changes: 1 addition & 1 deletion Source/TabsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ protected void addOMEImagesToTabClick(object sender, EventArgs a)
protected void saveSelectedTiffClick(object sender, EventArgs a)
{
Gtk.FileChooserDialog filechooser =
new Gtk.FileChooserDialog("Choose the file to open",
new Gtk.FileChooserDialog("Save File",
this,
FileChooserAction.Save,
"Cancel", ResponseType.Cancel,
Expand Down

0 comments on commit 44680bc

Please sign in to comment.