SharpPlot graph into a Windows Form

General APL language issues

SharpPlot graph into a Windows Form

Postby Tomas Gustafsson on Sat Jan 29, 2022 5:17 am

Feeling a bit stupiid indeed.

Task: Get a nice SharpPlot chart into a Subform/Label/whatever area in a form created with ⎕WC.

After having spent hours together with dyalog.com, google, dyalog & sharpplot help files online and offline, I cannot find ANY instruction or sample whatsoever on how to do this. One should think it would be the very first thing to talk about?

Apparently SP (SharpPlot) cannot paint directly into a Windows form with the help of the application's form handle. That sounds fair enough. SP focuses on creating the graph as a script of draw commands, for example in the SVG format. This allows for much wider usage.

Apparently Windows doesn't render SVG natively.

"How do I render SVG in a Windows form?" is a common question on StackOverflow. The replies suggest either using some third party SVG-renderers or embedding a browser control into the form.

I don't like the thought of doing either.

There is (was?) a sharpplot.dws included (earlier?) but Dyalog APL v. 17 seems to have none. I wouldn't use it anyway, no way I'd fill the workspace with (sorry) bloatware - I know this makes me different, because the APL community seems to show great acceptance towards just importing "stuff" upon need, just like that. Not my style, I keep the household extremely clean (otherwise I'm lost)!

SP holds a nice SVG renderer, called SharpPlotViewer. It's a rather huge set, with lots of methods and properties. But it seems absolutely impossible to find any documentation for it. No such is included with the SP help and none seems to be available online, not even at dyalog.com. It seems the documentation simply doesn't exist. My bad, or might it be available somewhere?

SharpPlotViewer has a property called Handle, but passing a ⎕WC-style form handle creates an error at the property-setting moment. That's probably expected, a WinAPI handle isn't compatible with a .net-style form handle. Apparently the handle (a fairly big integer) is a bad number.

SharpPlotViewer also has a method called WindowTarget. Should one send it a .net object reference? In that case, do I then have to abandon the ⎕WC style and move over to the .net form&object handling style?

Keep on fiddling?

Is there any documentation for SharpPlotViewer? I do not want the graph in a spearate form, as the SharpPlotViewer.Show method does (used in all samples). I want to embed several graphs in my application's form!

Über cool graphics tool together with APL + no instruction/sample on how to get it into a form created with APL


That can't be the case, so go ahead and slaughter me, I do feel dumb already :-).

The task is to embed SharpPlot charts in a ⎕WC-created Windows form. How?
Tomas Gustafsson
 
Posts: 101
Joined: Mon Sep 19, 2011 6:43 pm

Re: SharpPlot graph into a Windows Form

Postby paulmansour on Sat Jan 29, 2022 1:48 pm

I'm sure you have been down this route, but does not SharpPlot put out a bunch of formats like PNG, JPEG, BMP, GIF, TIF, and isn't at least one of those suitable for a ⎕WC form?
paulmansour
 
Posts: 418
Joined: Fri Oct 03, 2008 4:14 pm

Re: SharpPlot graph into a Windows Form

Postby Tomas Gustafsson on Sat Jan 29, 2022 3:28 pm

Thanks Paul, yes SharpPlot does indeed output pictures.

Raster images don't feel right, as resizing will make the pixels wreck havoc, as they say :-).

Metafile might be a solution. SharpPlot is apparently able to create (and save) a .net Metafile object but again the Dyalog ⎕WC style Metafile object won't be able to fetch it - it only loads from files. Hence it would require a roundtrip through the disk (as smearing the clipboard programmatically is imho bad practice). I'm still a bit suspicious towards emf scaling capabilities though, but could try!

It just somehow feels the SharpPlotViewer is so very capable (deeming by the amount of methods it holds), that it SHOULD be able to gracefully render into any valid Windows handle...?
Tomas Gustafsson
 
Posts: 101
Joined: Mon Sep 19, 2011 6:43 pm

Re: SharpPlot graph into a Windows Form

Postby Tomas Gustafsson on Sat Jan 29, 2022 5:14 pm

Oh sigh... SharpPlot happily writes the metafile as both

System.Drawing.Imaging.ImageFormat.Wmf and
System.Drawing.Imaging.ImageFormat.Emf

but Dyalog APL is unable to read it:

'test' ⎕WC 'Metafile' 'C:\Folder\test.wmf'
DOMAIN ERROR: The object could not be created

'test' ⎕WC 'Metafile' 'C:\Folder\test.emf'
LIMIT ERROR: The object could not be created ("Felaktig data.")

where "Felaktig data" is Swedish for "erratic data"

Windows Paint however loads and shows both with no problems.

I wonder if the metafile mechanism in APL is outdated, as the doc only talks about wmf, nothing mentioned about emf? In any case the metafile option is unfortunately a no go.
Tomas Gustafsson
 
Posts: 101
Joined: Mon Sep 19, 2011 6:43 pm

Re: SharpPlot graph into a Windows Form

Postby paulmansour on Sat Jan 29, 2022 11:10 pm

Tomas, I stand second to none in my use and admiration of ⎕WC, but I would give the HTMLRenderer another look. (Yes it is 100 MB, but it's cross-platform, and of course ⎕WC needs all of windows to work!)

Depending on what you need to do, you might be able to get rid of SharpPlot all together and write your own SVG. This is on my own to-do list this year for a limited set of charts (bar, line, pie).
paulmansour
 
Posts: 418
Joined: Fri Oct 03, 2008 4:14 pm

Re: SharpPlot graph into a Windows Form

Postby Tomas Gustafsson on Sun Jan 30, 2022 8:28 am

Yeah, I know...

I gave the Bitmap option a try. The idea would be to re-save the bitmap from SharpPlot upon any resize of the ⎕WC form, and then just update the APL Bitmap object accordingly. It works, but there is a problem with the pixels. Sometimes they are strong, when the draw command hits the screen pixels properly, ie. when horizontal and vertical lines get painted with integer pixel addresses. But sometimes the lines become weak (or "different"), when the image pixels match the screen pixels badly. A scaling problem, broken antialiasing.

This is because SharpPlot uses "points", not pixels. There seems to be no way to tell SharpPlot the desired size of it's work area in pixels. Matching one point exactly into one pixel won't work.

There are two ways to save the SharpPlot graph into a bitmap:

Code: Select all
∆sp.SaveImage 'C:\Folder\test.bmp' System.Drawing.Imaging.ImageFormat.Bmp

APL is able to read this bitmap file but the screen pixels won't match well.

Code: Select all
bmp←∆sp.RenderBitmap(72)
bmp.Save 'C:\Folder\test.bmp'

According to SharpPlot documentation, the "∆sp.RenderBitmap(72)" should match one point into one pixel exactly. This creates a valid bitmap (other programs open it) but APL says error when trying to read it.

My fear with HtmlRenderer is (in addition to the overkill 100 MB) that it suddenly wants to connect somewhere. To Google maybe? This is potentially software for the Marine and they will do the monkeyjumps if the firewall suddenly want's permission, or if HtmlRenderer suddenly wants to write some data into another folder on the disk. Needless to say I don't trust Google for one nanosec :-).

Remains to abandon ⎕WC and investigate the .net GUI object model, maybe SharpPlot has something there? (And I do ofc have some homemade charting stuff, just that SharpPlot is so cool!)
Tomas Gustafsson
 
Posts: 101
Joined: Mon Sep 19, 2011 6:43 pm

Re: SharpPlot graph into a Windows Form

Postby Morten|Dyalog on Sun Jan 30, 2022 11:26 am

Within the Chart Wizard code, I found the following snippets of code, which may point to a solution if .NET is acceptable to you:

Code: Select all
     ∆VIEW←⎕NEW'NetControl'(⊂'ClassName' 'System.Windows.Forms.WebBrowser')
...and...
     html←''
     html,←'<!DOCTYPE html>'
     html,←'<html><body>'
     html,←∆sp.RenderSvg ChartWizard.Causeway.SvgMode.FixedAspect
     html,←'</body></html>'
     ∆VIEW.DocumentText←html
User avatar
Morten|Dyalog
 
Posts: 451
Joined: Tue Sep 09, 2008 3:52 pm

Re: SharpPlot graph into a Windows Form

Postby Veli-Matti on Sun Jan 30, 2022 12:27 pm

Tomas,
are you aware of http://www.sharpplot.com?
(for the documentation, that is - your problem may still stay intact)

-Veli-Matti (who HAS integrated the old RainPro in the distributable app ;) )
Veli-Matti
 
Posts: 93
Joined: Sat Nov 28, 2009 3:12 pm

Re: SharpPlot graph into a Windows Form

Postby Tomas Gustafsson on Sun Jan 30, 2022 4:17 pm

@Morten, using the WebBrowser control probably activates the Edge driver&rendering, so hmm... Invoking browsers feels somewhat risky, as authorities often tweak their computers by disabling or limiting things. It's like sticking in the hand in a jungle of security levels & stuff that I don't have too much knowledge about. Would probably work though, but it would be pretty much equal to using the HtmlRenderer.

Might there be any more information about SharpPlot's "SharpPlotViewer" object? Is it Nic who holds this now?

@VM, ya I have checked sharpplot.com, it's pretty much identical to SharpPlot's help files, but lacks a search feature. I'd have wanted to look for keywords like "pixel" or "window", but that won't function there.

The SharpPlotViewer is already loaded, does a tremendous job, means no additional software - it's so close to doing this particular rendering job too? Sure someone must have though of embedding SharpPlot graphs in APL application forms...?

The sharplot.dws won't help either, as it also calls SharpPlotViewer...

So close, it only stands by the wrong window. :-)
Tomas Gustafsson
 
Posts: 101
Joined: Mon Sep 19, 2011 6:43 pm

Re: SharpPlot graph into a Windows Form

Postby PGilbert on Sun Jan 30, 2022 7:19 pm

You could save the plot as a XAML character vector and show it natively in a WPF window or alternatively into a ⎕WC window using Dyalog NetControl with a .Net ElementHost. The XAML drawing will be similar to the SVG drawing (all vector elements, no bitmap) and can be scaled easily.

If any of those 2 suggestions is acceptable let me know and I can work an appropriate example.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Next

Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest