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

Disable default strokeDash for legend #1344

Merged
merged 6 commits into from
May 11, 2016
Merged

Conversation

YuhanLu
Copy link
Contributor

@YuhanLu YuhanLu commented May 10, 2016

Fix #1314
Now legend won't take strokeDash and strokeDashOffset from config for all marks.

the following spec create the correct legend symbol now.

{
  "data": {"url": "data/stocks.csv", "formatType":"csv"},
  "mark": "line",
  "encoding": {
    "x": {"field": "date", "type": "temporal"},
    "y": {"field": "price", "type": "quantitative"},
    "color": {"field": "symbol", "type": "nominal"}
  },
  "config": {
    "mark": {
      "strokeWidth": 1,
      "strokeDash": [ 24, 20 ] ,
      "strokeDashOffset": 24
    }
  }
}

vega

@@ -30,8 +30,7 @@ export function buildModel(spec: Spec, parent: Model, parentGivenName: string):
}

// TODO: figure if we really need opacity in both
export const STROKE_CONFIG = ['stroke', 'strokeWidth',
'strokeDash', 'strokeDashOffset', 'strokeOpacity', 'opacity'];
export const STROKE_CONFIG = ['stroke', 'strokeWidth', 'strokeOpacity', 'opacity'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right fix. This would make strokeDash unused for both legend and marks.

Why don't you modify the Line 128 in legend.ts like I suggested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this before I got your suggestion. I will fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Sounds good then ;)

@YuhanLu
Copy link
Contributor Author

YuhanLu commented May 10, 2016

Fixed it by eliminating the default strokeDash and strokeDashOffset for all marks

@@ -146,9 +146,9 @@ export namespace properties {
applyMarkConfig(symbols, model,
channel === COLOR ?
/* For color's legend, do not set fill (when filled) or stroke (when unfilled) property from config because the the legend's `fill` or `stroke` scale should have precedence */
without(FILL_STROKE_CONFIG, [ filled ? 'fill' : 'stroke']) :
without(FILL_STROKE_CONFIG, [ filled ? 'fill' : 'stroke', 'strokeDash', 'strokeDashOffset']) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would organize this chunk of the code a bit so that the comments still make sense.

Ideally I would do something like:

let config = channel === COLOR ? 
  /* For color's legend, do not set fill (when filled) or stroke (when unfilled) property from config because the the legend's `fill` or `stroke` scale should have precedence */
  ... : 
  /* For other legend, no need to omit. */
  ...;
config = without(config, ['strokeDash', 'strokeDashOffset'])

applyMarkConfig(symbols, model, config)

@YuhanLu
Copy link
Contributor Author

YuhanLu commented May 10, 2016

Fixed the style.

@kanitw
Copy link
Member

kanitw commented May 10, 2016

Can you add test? (and for future PRs, please add screenshot to help reviewers review PR easier.)

@YuhanLu
Copy link
Contributor Author

YuhanLu commented May 11, 2016

tests and screenshot are added

I remove "for any mark" because you only test point here.  (testing point is sufficient but adding "for any mark" in the description left the impression that you're testing all mark types.)
@kanitw kanitw merged commit 97a7bad into master May 11, 2016
@kanitw kanitw deleted the zl/disable-strokeDash-legend branch May 11, 2016 04:36
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

Successfully merging this pull request may close these issues.

None yet

2 participants