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

Replace Transform #1761

Closed
domoritz opened this issue Dec 6, 2016 · 17 comments
Closed

Replace Transform #1761

domoritz opened this issue Dec 6, 2016 · 17 comments

Comments

@domoritz
Copy link
Member

domoritz commented Dec 6, 2016

I want to be able to specify what text is shown in the legend for ordinal colors but setting the domain and range only let's me override the colors but not the labels.

See vega/altair#278

@kanitw
Copy link
Member

kanitw commented Dec 6, 2016

Users should simply derive a new data field and use the new field.

That said, I see that this would be painful:

transform: {
    calculate: { 
       expr: "datum.name === 'tom' ? 'Thomas' : datum.name === 'dick' ? ... : ... "
       as: "fullname",  // `field:` in v1
    }
}

Instead of making this specific to legend, I propose that we add a replace transform that can be useful for all of axis label, legend label, text marks, and the future label marks.

transform:  {
   replace: {
      field: 'name',
      as: 'fullname',
      dict: { 'tom' : 'Thomas', 'dick' : 'Richard', ... }
   }
}

@kanitw kanitw mentioned this issue Dec 6, 2016
@kanitw kanitw changed the title Change labels in color legend Replace Transform Jan 10, 2017
@kanitw kanitw added this to the 2.x.x Features & Patches milestone Jan 10, 2017
@kanitw
Copy link
Member

kanitw commented Aug 7, 2017

A syntax that might be more appropriate for the new transform array might be:

transform: [{
   replace: 'name'
   to:  { 'tom' : 'Thomas', 'dick' : 'Richard', ... }
   as: 'fullname'
}]

@kanitw kanitw modified the milestones: 2.x.x Features & Patches, 2.x Data Transforms Sep 22, 2017
@kanitw
Copy link
Member

kanitw commented Mar 4, 2018

The code that @sirahd add to generate sort index in #3423 is definitely useful for this "replace" transform.

@domoritz
Copy link
Member Author

domoritz commented Mar 4, 2018

Yes. Close this then?

@kanitw
Copy link
Member

kanitw commented Mar 4, 2018

? Having reuseable code for this task doesn't mean we support this task by any mean.

@domoritz
Copy link
Member Author

domoritz commented Mar 4, 2018

Oh, I meant close this issue and don't support replace.

@kanitw
Copy link
Member

kanitw commented Mar 4, 2018

Why? The current way to do replace is still super annoying. (Write ugly chains of ternary operator)

@domoritz
Copy link
Member Author

domoritz commented Mar 4, 2018

Never mind. I misunderstood that this issue has some other benefits besides sorting domains.

@kanitw
Copy link
Member

kanitw commented Mar 4, 2018

this issue has some other benefits besides sorting domains.

Yes it does ;)

@domoritz
Copy link
Member Author

domoritz commented Mar 5, 2018

Cool. Somebody implement this then :-P

@kanitw
Copy link
Member

kanitw commented Mar 5, 2018

I wonder if it would be best implemented as a function in Vega expression though so it will benefit the whole stack.

@domoritz
Copy link
Member Author

domoritz commented Mar 5, 2018

I defer that question to @jheer

@kanitw
Copy link
Member

kanitw commented Jul 14, 2018

Actually something like {'Sat': 'Weekend', 'Sun': 'Weekend'}[day] || 'Weekday' would be sufficient for this purpose.

@kanitw kanitw closed this as completed Jul 14, 2018
@domoritz
Copy link
Member Author

We use this in #4020 😛

@domoritz
Copy link
Member Author

It might be worth documenting this somewhere.

@jowens
Copy link

jowens commented Jul 14, 2018

I'm at a loss as to how this was actually fixed / how this can be expressed ... is @kanitw's sat/sun/weekend example how this can be expressed now?

@domoritz
Copy link
Member Author

Yes, you can write a calculate transform with an expression as in @kanitw's comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants