vojtamolda / Plotly.swift

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

Plotting of Stride and Range objects #13

Closed vojtamolda closed 4 years ago

vojtamolda commented 4 years ago

Swift's Foundation library contains a few frequently used data types that are hidden in the plain sight. However, they are common enough to justify a direct plotting support. There's in total 4 flavors the Range and Stride objects:

Without conformance to the Plotable protocol, using these types requires explicitly constructing an array which results in an awkward syntax:

let scatter = Scatter(x: [Int](0...10), [Int](y: 0..<11))

Conformance to Plotable allows these types to be used as any other data:

let scatter = Scatter(x: 0...10, y: 0..<11)

The implementation will iterate through elements of the object and encode them to Plotly's JSON representation.

At the moment, I don't see a simple way to support the "sparse" encoding of sequential data that can be done with x0, dx, y0 and dy attributes. This would save a lot of file size, especially for larger graphs or animations but these attributes are supported only for some charts.

vojtamolda commented 4 years ago

Done!