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

Enable Update of Plot Axis Range from Button #414

Closed
mg-yolo-enterprises opened this issue Aug 31, 2023 · 1 comment
Closed

Enable Update of Plot Axis Range from Button #414

mg-yolo-enterprises opened this issue Aug 31, 2023 · 1 comment
Labels
Area: Core API Area: MissingAbstraction Plotly.js functionality that has to be implemented

Comments

@mg-yolo-enterprises
Copy link

It would be helpful to be able to use an UpdateMenu to permit a user to change the range of a plot's axis.

This seems possible, based on example code for Plotly for Python:
https://community.plotly.com/t/pre-defined-range-buttons/39267/3

However I don't see how it's possible to do this from Plotly.NET, based on the need to send an axis start and end value.

I've attempted this with the following code, and several variations:

var buttons = new List<UpdateMenuButton>();
for (var time = timeInterval.StartInterval; time < timeInterval.EndInterval; time = time.AddHours(1))
{
    buttons.Add(UpdateMenuButton.init(
        Label: $"{time:h:mm tt}", 
        Method: StyleParam.UpdateMethod.Relayout,
        Args: new[] { "xaxis.range", 
            $"{time:yyyy-MM-dd HH:mm:ss} - {time.AddHours(1):yyyy-MM-dd HH:mm:ss}" }
        ));
}

and

.WithLayout(layout: Layout.init<iConv>(UpdateMenus: new []{UpdateMenu.init(Buttons: buttons)}))

Using the above code, the UpdateMenu appears, the labels are correct, and selecting something does change the X axis range. However, it always changes to 1/1/2000 - 12/31/2000 rather than the desired range.

@kMutagene
Copy link
Collaborator

Hi @mg-yolo-enterprises, thanks for reporting this.

I played around a little and it seems like IEnumerable<string> is just not enough for modelling Args, as the correct json for your example is

"buttons": [
 {
  "args": [
   "xaxis.range",
   [
    "2015-07-01",
    "2015-09-01"
   ]
  ],
  "label": "Custom",
  "method": "relayout"
 }
]

note that the range argument is a real json array with two values, something you cannot put there with just a string.

So we need to allow any type of object in the Args array to solve this.

@kMutagene kMutagene added Area: MissingAbstraction Plotly.js functionality that has to be implemented Area: Core API labels Sep 4, 2023
@kMutagene kMutagene added this to the Plotly.NET 5.0 milestone Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Core API Area: MissingAbstraction Plotly.js functionality that has to be implemented
Projects
None yet
Development

No branches or pull requests

2 participants