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

Add “Unit” so we automatically append units to axis & legend title. #817

Closed
kanitw opened this issue Dec 2, 2015 · 10 comments
Closed

Comments

@kanitw
Copy link
Member

kanitw commented Dec 2, 2015

In an attempt to make axis title nicer, maybe we add fieldDef.unit or allow describing unit in the schema once we support it (#512).

For example, if fieldDef.unit is ’$’ for mean of ’cost’, the axis title could be ’MEAN(cost) (in $)’.

@kanitw kanitw modified the milestones: 1.x Should have after 1.0 , x.x (Nice to Have) Dec 2, 2015
@kanitw kanitw modified the milestones: x.x (Nice to Have), 1.x.x Patches & Minor Features Jan 12, 2016
@kanitw kanitw changed the title Add “Unit” so we automatically append units to axis title. Add “Unit” so we automatically append units to axis & legend title. Jan 16, 2016
@ayush29feb
Copy link

@kanitw is this what you want to?
image

@domoritz
Copy link
Member

We already use a similar syntax for aggregation functions. I think there are two options here. One is to write "Year in years" and the other is to show the unit with the data on the axis (acceptable for short units such as $).

@kanitw
Copy link
Member Author

kanitw commented Jan 24, 2016

Good question! Here is what I think:

  • unit as part of a field can be considered equivalent to having unit included from the schema.
  • We could introduce showUnit as a property to axis and have these possible values: 'none', 'title' (Showing "Year in years" for the axis title), 'label-prefix' (Showing $100), 'label-suffix` ('Show 100 kg).

@domoritz -- what do you think?

@domoritz
Copy link
Member

Sounds reasonable.
On Jan 23, 2016 19:49, "Kanit Wongsuphasawat" notifications@github.com
wrote:

Good question! Here is what I think:

  • unit as part of a field can be considered equivalent to having unit
    included from the schema.
  • We could introduce showUnit as a property to axis and have these
    possible values: 'none', 'title' (Showing "Year in years" for the axis
    title), 'label-prefix' (Showing $100), 'label-suffix` ('Show 100 kg).

@domoritz https://github.com/domoritz -- what do you think?


Reply to this email directly or view it on GitHub
#817 (comment).

@kanitw
Copy link
Member Author

kanitw commented Jan 24, 2016

Cool. To summarize,

  • add unit to fieldDef (interface & schema)
  • add showUnit as enum to axis (interface & schema). This should be an enum with four values above. The default should be 'title' IMHO. See fieldDef.schema.ts's type for an example of how we declare enum and see config.schema.ts for how to declare default.
    • For 'title' case, modify model.fieldTitle()
    • For label-prefix/suffix, need to modify axis.ts's properties.labels. Probably need to use output's text's template property.

@ayush29feb ayush29feb self-assigned this Jan 25, 2016
@ayush29feb
Copy link

I am a little confused why we have the showUnit in fieldDef.axis and unit in fieldDef

"encoding": {
    "y": {
      "field": "b2",
      "type": "quantitative",
      "unit": "$",
      "axis": {"showUnit": "label-prefix"}
    },
    "x": {"field": "a","type": "ordinal"}
  }

it seems a little weird to define that the unit would be in title inside axis

"encoding": {
    "y": {
      "field": "b2",
      "type": "quantitative",
      "unit": "Pounds",
      "axis": {"showUnit": "title"}
    },
    "x": {"field": "a","type": "ordinal"}
  }

How about this

"encoding": {
    "y": {
      "field": "b2",
      "type": "quantitative",
      "showUnit": {
       "unit": "Pounds",
       "position": "title" 
      }
    },
    "x": {"field": "a","type": "ordinal"}
  }

@ayush29feb
Copy link

If we plan to procced as @kanitw suggested, I am having some trouble accessing axis.showUnit in fieldDef.title method because there is not axis object in the title method

@kanitw
Copy link
Member Author

kanitw commented Feb 6, 2016

Instead of calling fieldDef.title directly you can either make a new axis.title() or pass unit as a parameter to fieldDef.title. (Pick one that seems more appropriate – if you're unsure, let me know -- I can take a closer look.)

ayush29feb pushed a commit that referenced this issue Feb 16, 2016
ayush29feb pushed a commit that referenced this issue Feb 16, 2016
ayush29feb pushed a commit that referenced this issue Feb 16, 2016
ayush29feb pushed a commit that referenced this issue Feb 18, 2016
@kanitw kanitw changed the title Add “Unit” so we automatically append units to axis & legend title. Add “Unit” so we automatically append units to axis & legend title. Apr 8, 2016
@kanitw kanitw modified the milestones: 1.x.x? Patches & Minor Features, 2.x.x Patches & Features Oct 2, 2016
@kanitw
Copy link
Member Author

kanitw commented Oct 20, 2016

Note: An early attempt of this was in #1301.

@kanitw kanitw modified the milestones: 2.x.x Features & Patches, 2.x Visual Encoding Patches Oct 12, 2017
@kanitw
Copy link
Member Author

kanitw commented May 20, 2018

It's easy enough to use title/format to do this, so let's close this.

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