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.
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:0..<10
0...10
stride(from: 0, to: 1, by: 0.1)
stride(from: 0, through: 1, by: 0.1)
Without conformance to the
Plotable
protocol, using these types requires explicitly constructing an array which results in an awkward syntax:Conformance to
Plotable
allows these types to be used as any other data: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
anddy
attributes. This would save a lot of file size, especially for larger graphs or animations but these attributes are supported only for some charts.