go-plotly icon indicating copy to clipboard operation
go-plotly copied to clipboard

enable using all features of array types

Open PatrickVienne opened this issue 1 year ago • 4 comments

@MetalBlueberry

as requested, separated out in a separate PR the change to enable array types as in JS

PatrickVienne avatar May 18 '24 21:05 PatrickVienne

Enable using array types:

examples/scatter/scatter.html

image

PatrickVienne avatar May 18 '24 22:05 PatrickVienne

@MetalBlueberry ready for review

PatrickVienne avatar May 18 '24 22:05 PatrickVienne

I see the problem here, but I think we can find a better solution than just using interface everywhere.

here is one proposal I just came up with. but it looks promissing.

  • https://github.com/MetalBlueberry/go-plotly/pull/24

We can provably predefine most of the types.

OR would it work with generics? maybe a generic function will solve our problems :blush:

MetalBlueberry avatar May 19 '24 15:05 MetalBlueberry

@MetalBlueberry thanks for checking it and your suggestions. Not sure how generics could help here unfortunately since we can have valuetype (string, int, float), we can have arrays ([]string, []int, []float) and then the pointers as well, which we need to represent nil

So it's almost like we need something like

type ArrayElement struct {
    IsValid bool  // if false -> value is marshalled as 'nil'
    Text     string
    Num    float64
}

// type to use for arrayOK types
type Array []ArrayElement

I'm not convinced yet of this solution as well though.

PatrickVienne avatar May 19 '24 20:05 PatrickVienne

This has been merged already, Thank you :heart:

MetalBlueberry avatar Aug 25 '24 12:08 MetalBlueberry