Skip to content

Clone y/y2-axis domain from the other y/y2-axis if no data is bound to one of them #1231

Closed
@michkami

Description

Description

If there is no data bound to y2-axis and y2-axis is shown, it sets the domain of y2-axis to [0, 1].
The same happens if no data is bound to y-axis.
All columns bound to y-axis:
1  All data bound to y

For setting the domain of y2-axis you have to bind atleast one data column to y2-axis.
'data3' bound to y2-axis:
2  One data bound to y2

For the case of showing the both y- and y2-axis and not binding data to one of them, it would be great if it would clone the domain of the opposite y-axis per default.

It would look like this:
All columns bound to y-axis:
3  All data bound to y

'data3' bound to y2-axis:
4  One data bound to y2

It can be achieved by changing following code in domain.js:

97	if (yTargets.length === 0) { // use current domain if target of axisId is none
98		return $$[axisId].domain();
99	}

change to

97	if (yTargets.length === 0) { // use current domain if target of axisId is none
98		return axisId === "y2" ? $$.y.domain() : $$.getYDomain(targets, "y2", false);
99	}

Is there anything against implementing this in billboard?

Steps to check or reproduce

  1. Open CategoryAxis Example
  2. Use the code below.

Example code:

var chart = bb.generate({
  data: {
    columns: [
		['data1', -1000, -750, -500, -250, 0, 250, 500, 750, 1000],
		['data2', -250, 0, 250, 0, -250, 0, 250, 0, -250],
		['data3', 100, 75, 50, 25, 0, -25, -50, -75, -100]
    ],
	axes: {
		data1: 'y',
		data2: 'y',
		data3: 'y'
	}
  },
  axis: {
    x: {
      type: "category",
      categories: [
        "cat1",
        "cat2",
        "cat3",
        "cat4",
        "cat5",
        "cat6",
        "cat7",
        "cat8",
        "cat9"
      ]
    },
	y2: {
		show: true
	}
  },
  bindto: "#categoryAxis"
});

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions