Skip to content

In Chart.withLegendStyle, StyleParam.XAnchorPosition does not seem to have an effect #289

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

Closed
nhirschey opened this issue May 19, 2022 · 2 comments

Comments

@nhirschey
Copy link
Contributor

Description

When I try to orient a legend, YAnchorPosition works as I expect but XAnchorPosition does not seem to have an effect.

Repro steps

#r "nuget: Plotly.NET"

open Plotly.NET

let xs = [1.0 .. 4]
let y1 = xs |> List.map (fun x -> x * 2.0)
let y2 = xs |> List.map (fun x -> x * 3.0)

These charts look the same to me:

// left
[Chart.Line (xs, y1); Chart.Line (xs, y2)]
|> Chart.combine
|> Chart.withTitle("Left")
|> Chart.withLegendStyle(Orientation=StyleParam.Orientation.Horizontal,
                         X=0,
                         XAnchor=StyleParam.XAnchorPosition.Left)
|> Chart.show

// right
[Chart.Line (xs, y1); Chart.Line (xs, y2)]
|> Chart.combine
|> Chart.withTitle("Right")
|> Chart.withLegendStyle(Orientation=StyleParam.Orientation.Horizontal,
                         X=0,
                         XAnchor=StyleParam.XAnchorPosition.Right)
|> Chart.show

image
image

Expected behavior

I expect the left chart to be as it is but I expect the right chart's legend to be right-aligned at x=0.

Actual behavior

the legend positions are the same.

Related information

  • Operating system Windows 11
  • .NET 6,
@kMutagene
Copy link
Collaborator

This seems to be intended. See the plotly.js docs :

Sets the legend's horizontal position anchor. This anchor binds the x position to the "left", "center" or "right" of the legend. Value "auto" anchors legends to the right for x values greater than or equal to 2/3, anchors legends to the left for x values less than or equal to 1/3 and anchors legends with respect to their center otherwise.

Seems like you have to controll the position additionally via increasing X:

Type: number between or equal to -2 and 3
Sets the x position (in normalized coordinates) of the legend. Defaults to "1.02" for vertical legends and defaults to "0" for horizontal legends.

so a combination of X = 1 and XAnchor = "right" should work.

[Chart.Line (xs, y1); Chart.Line (xs, y2)]
|> Chart.combine
|> Chart.withTitle("Left")
|> Chart.withLegendStyle(Orientation=StyleParam.Orientation.Horizontal,
                         X=1,
                         XAnchor=StyleParam.XAnchorPosition.Right)
|> Chart.show

However, this will lead to this result, because XAnchor falsely set the YAnchor attribute currently >.<

image

I patched this already and this will be live with the next release.

image

@nhirschey
Copy link
Contributor Author

That looks great, thank you! Good eye catching the typo causing the bug; that would be hard to catch.

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