Skip to content

[Bug] setPaneOptions does not fully override existing options when provided with a cloned pane options object #746

@ericschv

Description

@ericschv

Version

10.0.0-alpha8

Steps to Reproduce

  1. Initialize the chart without providing a layout configuration
const chart = init("chart”);
  1. Clone the original pane options before modification (this will become the default pane options)
const defaultPaneOptions = utils.clone(chart.getPaneOptions()[0]);
  1. Modify a pane option field that does not exist in the clone
chart.setPaneOption({
  id: "candle_pane",
  axis: {
   reverse: true,
  },
});
  1. Compare the active pane options before and after reset
console.log(chart.getPaneOptions()[0]);chart.setPaneOptions(defaultPaneOptions);console.log(chart.getPaneOptions()[0]);
  1. Verify that the axis.reverse option still exists and is set to true for “candle_pane” instead of being removed or set to false.

Current Behavior

The setPaneOptions function will merge the input object with the existing pane options. This means you cannot rely on a cloned version of chart's pane options when resetting to a default or setting variations of a chart's pane options. This can make it more difficult to implement certain features, for example, switching between different themes of a chart. To get around this you either have to set default pane options in the init() layout field or create a global pane options object with every pane option field defined:

/* init() approach */

const chart = init("chart", {
      layout: [
        {
          type: "candle",
          options: {
            id: "candle_pane",
            axis: {
              name: "normal",
              reverse: false, // <— must include reverse in order to reset it to a default
              ...
            },
            ...
          },
        },
      ],
    });

/* object reference approach */

const defaultPaneOptions = {
      id: "candle_pane",
      axis: {
        name: "normal",
        reverse: false,
        ...
      },
      ...
} 

chart.setPaneOptions(defaultPaneOptions);

Expected Behavior

I expected to be able to reset any modifications made to the chart's pane options by creating a clone of the initial pane options and passing the clone into setPaneOptions.

const chart = init("chart”);

const defaultPaneOptions= utils.clone(
   chart.getPaneOptions().find(
      (option) => option.id === "candle_pane"
   )
);

chart.setPaneOption({
   id: "candle_pane",
   axis: {
      reverse: true,
   },
});

chart.setPaneOption(defaultPaneOptions);

Environment

- OS: Sequoia v15.6.1 (Mac)
- Browser: Brave 1.81.135 (arm64) (Chromium: 139.0.7258.127)
- Framework: Next.js 15.4.5

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions