Skip to content
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

Expose only Track() to users and internally decide between SingleTrack and PartialTrack? #12

Closed
sehilyi opened this issue Aug 17, 2021 · 3 comments

Comments

@sehilyi
Copy link
Member

sehilyi commented Aug 17, 2021

I am wondering if it makes sense to expose gos.Track() only to users instead of the additional gos.PartialTrack(). I think whenever a user uses overlay alignment with tracks, we can internally consider this as PatialTrack so that users do not have to manually select between SingleTrack and PartialTrack.

bar_overview = bar_base.properties(
    width=300, height=300,
    alignment='overlay',
    tracks=[
        gos.Track(), // since overlay alignment is used with tracks, this is PartialTrack
        gos.Track().mark_brush().encode(x=gos.Channel(linkingId='detail-1')),
        gos.Track().mark_brush().encode(x=gos.Channel(linkingId='detail-2'))
    ]
)
@sehilyi sehilyi changed the title Expose only Track() to users and internally decide between SIngleTrack and PartialTrack? Expose only Track() to users and internally decide between SingleTrack and PartialTrack? Aug 17, 2021
@manzt
Copy link
Member

manzt commented Aug 18, 2021

I think this is a good idea, but unfortunately the types are distinct. Track currently inherits from gosling.schema.Track so it cannot be instantiated without arguments -- this is all autogenerated code that does validation. gos.Track just inherits some additional "mixins" that allow method chaining for assiging properties to the underlying gosling.schema.Track.

Another option would be to export a singleton of PartialTrack for use in this situation:

# gosling/api.py
track = PartialTrack()

# example.py
bar_overview = bar_base.properties(
    width=300, height=300,
    alignment='overlay',
    tracks=[
        gos.track, # since overlay alignment is used with tracks, this is PartialTrack
        gos.track.mark_brush().encode(x=gos.Channel(linkingId='detail-1')),
        gos.track.mark_brush().encode(x=gos.Channel(linkingId='detail-2'))
    ]
)

With that said, there is likely a way to make Track more "magical" and I'll take a look.

@manzt
Copy link
Member

manzt commented Aug 18, 2021

Another option would be to have a gos.track() util that inspects the arguments to decide whether to return a Track vs PartialTrack instance.

bar_overview = gos.track(data=data).properties(
    width=300, height=300,
    alignment='overlay',
    tracks=[
        gos.track(), # since overlay alignment is used with tracks, this is PartialTrack
        gos.track().mark_brush().encode(x=gos.Channel(linkingId='detail-1')),
        gos.track().mark_brush().encode(x=gos.Channel(linkingId='detail-2'))
    ]
)

The less magic the better IMO. And this is clearly a function that just adds some shorthand.

@sehilyi
Copy link
Member Author

sehilyi commented Aug 23, 2021

Closing this for now since I think this is addressed by #19 (comment)

@sehilyi sehilyi closed this as completed Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants