vojtamolda / Plotly.swift

Interactive data visualization library for Swift
https://vojtamolda.github.io/Plotly.swift/
MIT License
82 stars 8 forks source link

Embed a Figure in WebView on iOS/ipadOS #11

Closed alew3 closed 4 years ago

alew3 commented 4 years ago

Very excited to see your work on the Tensor4Swift mailing list. Is it possible to be used inside a WebView in an IOS app?

vojtamolda commented 4 years ago

Hello @alew3,

There's a XCode Playground example that uses WebView to display the chart inside of the Playground's liveView. It's using AppKit (i.e. macOS) at the moment but I don't see anything anything specific to prevent it from working with UIKit (i.e. iOS/ipadOS) as well.

Here's the piece of code that creates the WebView: Plotly/Extensions/Playground.swift Here's the link to the Playground: Examples/Playgrounds/

I'm not an iOS/macOS developer so any PRs or feedback to make the embedding easier would be welcome if you decide to try it.

Per issue #7 I'd like to eventually create a dedicated standalone app for chart viewing and to make the app more versatile it could be actually written with Catalyst in mind to make it work anywhere.

vojtamolda commented 4 years ago

@alew3, how did the WebView embedding go? Did you have any luck with it?

vinbrule commented 4 years ago

@vojtamolda Thank so much for the awesome work. I'd like to contribute the functions to make it works on iphone and ipad. I am still looking for starting point. Could you help me? If it's long, we can talk for 20 minutes about the solution on Zoom, Hangout, Skype, etc?

vojtamolda commented 4 years ago

Hello @vinbrule

Thanks a lot for willing to contribute! You made my day.

I have a rough plan for something similar as part of issue #7. I was thinking about designing a reusable PlotlyView that would wrap a WebView and expose a property of type Figure to set the currently displayed chart. The viewer app itself would then be a relatively thin wrapper around this reusable UI component.

Originally, I didn't plan to make it work on iOS/iPadOS. But since there seems to be a lot of demand, I think it can be slightly changed to meet your needs. To make the viewer app work in both worlds #7 can use Catalyst framework. It's relatively new thing but we can get the app to work on any Apple platform from the same codebase.

From the source code perspective, it basically means we'd have to use UIKit instead of AppKit that a "regular" macOS app would use.

vojtamolda commented 4 years ago

We should probably open a new issue just for the development of the PlotlyView and have the discussion there. What do you think?

vinbrule commented 4 years ago

@vojtamolda That is a great idea! Please make it and put some comments, and some very basic starting point in codes if possible. It will significantly reduce the start-ing up time :)

vojtamolda commented 4 years ago

@vinbrule I've created #14 with some starting comments so we can continue the discussion there.

Also, please, send me an email so we can setup a Zoom call to get you up to speed. I wasn't able to dig up any contact info on your GitHub profile.

Good thing is that we're in the same time zone!

vinbrule commented 4 years ago

@vojtamolda sent you a greeting already and now my email on github is public also

alew3 commented 4 years ago

@alew3, how did the WebView embedding go? Did you have any luck with it?

Sorry for not replying faster, unfortunately I'm a newbie in the Swift world and I didn't have time to dig further.

vojtamolda commented 4 years ago

@alew3 No worries. Hopefully, will have something much easier to use for you soon! Check out #14.