Skip to content

Add Plotly.NET.ImageExport project #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 11, 2021
Merged

Add Plotly.NET.ImageExport project #94

merged 10 commits into from
Jul 11, 2021

Conversation

kMutagene
Copy link
Collaborator

@kMutagene kMutagene commented Jul 8, 2021

This PR adds the Plotly.NET.ImageExport project which is focused on providing extensions to save Plotly.NET's GenericCharts as static images.

I designed the project with extensibility in mind. The needed steps to add a new renderer is:

  1. Add a source file with a renderer implementing the IGenericChartRenderer interface
  2. Add a DU representing your renderer to ExportEngine -> Done!

The currently provided Renderer uses PuppeteerSharp to use Chromium as headless browser and supports jpg, png, and svg export. It is heavily inspired by the work of @ilyalatt with https://github.com/ilyalatt/Plotly.NET.PuppeteerRenderer.

this PR eventually
closes #90 ,
closes #21 ,
and closes #65.

Addition of other engines will be tracked in a separate issue once this is merged.

ToDo:

  • add XML docs for API reference
  • add docs
  • investigate wether this library can be used for a static Image Kernel extension for dotnet interactive
  • Add nuget package metadata
  • Add fsdocs metadata

@kMutagene
Copy link
Collaborator Author

kMutagene commented Jul 8, 2021

@ilyalatt please let me know if you want to be added as author to the nuget package that will be released from this eventually, as your work made this possible!

@ilyalatt
Copy link

@ilyalatt please let me know if you want to be added as author to the nuget package that will be released from this eventually, as your work made this possible!

It is not important for me. I think current reference in the code is enough :)

@kMutagene kMutagene changed the title [WIP] Add Plotly.NET.ImageExport project Add Plotly.NET.ImageExport project Jul 11, 2021
@kMutagene kMutagene merged commit e845ba2 into dev Jul 11, 2021
@kMutagene kMutagene deleted the image-export branch October 21, 2021 06:34
@shuganth
Copy link

I am trying to save my plotly.Net chart to a jpg using Plotly.NET.ImageExport but when I try to do that there is no error but the code keeps running forever when it comes to the line maps.SaveJpg(path).
Can any please help ?Thanks

using Plotly.NET;
using Plotly.NET.ImageExport;

namespace Reports
{
    public class picture
    {

        public static void map()
        {
            string[] y = new string[] { "2.0", "1.5", "5.0", "1.5", "3.0", "5.0" };
            string[] x = new string[] { "Belarus", "Moldova", "Lithuania", "Russia", "Romania", "India" };
            
            var maps = ChartMap.Chart.ChoroplethMap<string, string>(locations: x, y, LocationMode: StyleParam.LocationFormat.CountryNames);
            maps.Show();
            string path = @"C:\Users\axx\Documents\Sucess";
            maps.SaveJPG(path); // It gets Stuck here :(
            Console.WriteLine("Done");
            
        }
    
        public static void Main(string[] args)
        {
            map();
        }
    }
}

@WhiteBlackGoose
Copy link
Contributor

Hi, try using the async version please

@shuganth
Copy link

Hi, try using the async version please

If I do that its moving to the next line but it's not saving the file.

@WhiteBlackGoose
Copy link
Contributor

Did you use await?

await maps.SaveJpgAsync()

@shuganth
Copy link

shuganth commented Aug 20, 2022

Did you use await?

await maps.SaveJpgAsync()

I'm a bit stuck here could you please help me out

            string[] y = new string[] { "2.0", "1.5", "5.0", "1.5", "3.0", "5.0" };
            string[] x = new string[] { "Belarus", "Moldova", "Lithuania", "Russia", "Romania", "India" };
            var maps = ChartMap.Chart.ChoroplethMap<string, string>(locations: x, y, LocationMode: StyleParam.LocationFormat.CountryNames);
            maps.Show();
            await maps.SaveJPGAsync("suvve");

Screenshot 2022-08-20 at 3 44 59 PM

@WhiteBlackGoose
Copy link
Contributor

WhiteBlackGoose commented Aug 20, 2022

Uh, right. It's either that you're using an old version or we gracefully forgot to fix API for those methods. Could you try please try updating to the preview version. For it, open your cmd, cd to your project folder (e. g. cd C:/users/you/project) and there run

dotnet new nugetconfig
dotnet nuget add source https://www.myget.org/F/plotly-net-nightly/api/v3/index.json
dotnet add package Plotly.NET.ImageExport --prerelease

@shuganth
Copy link

Uh, right. It's either that you're using an old version or we gracefully forgot to fix API for those methods. Could you try please try updating to the preview version. For it, open your cmd, cd to your project folder (e. g. cd C:/users/you/project) and there run

dotnet new nugetconfig
dotnet nuget add source https://www.myget.org/F/plotly-net-nightly/api/v3/index.json
dotnet add package Plotly.NET.ImageExport --prerelease

Its Worked thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants