Skip to content

Help on rescaling logarithmic yAxis on filter #1264

@akuji1993

Description

@akuji1993

I have a problem with rescaling my yAxis after filtering on another chart. Here's my code:

var chart = dc.barChart(this.hook);

let xValue = this.xValue;
let yValue = this.yValue;
var ndx = this.chartGroup.getCrossfilter();

var dimension = ndx.dimension((d) => d[xValue]);

var group = dimension.group().reduceSum((d) => d[yValue]);
const getTops = (source_group) => {
  return {
    all: () => source_group.top(50)
  };
};

var fakeGroup = getTops(group);
let groupSize = this.getGroupSize(fakeGroup, yValue);

let minimum = group.top(groupSize)[groupSize-1].value;

chart
  .margins(this.margin)
  .width(this.width)
  .height(this.height)
  .group(fakeGroup)
  .dimension(dimension)
  .x(d3.scale.ordinal())
  .xUnits(dc.units.ordinal)
  .y(d3.scale.log().domain([minimum, this.getMax(yValue)])
    .range(this.height, 0)
    .nice()
    .clamp(true)
  )
  .xAxisLabel(this.xAxisLabel)
  .yAxisLabel(this.yAxisLabel)
  .elasticX(true)
  .ordinalColors(this.color)
  .on('renderlet', (chart) => {
    chart.selectAll('g.x text')
      .attr('dx', '-10')
      .attr('transform', 'rotate(-55)');
  })
  .on('filtered', (chart) => {
  });


chart.ordering((d) => -d.value);
chart.yAxis().ticks(15, ",d").tickSize(5, 10);

window.addEventListener("resize", () => {
  this.calculateSize();
  chart.width(this.width);
  chart.height(this.height);
  chart.transitionDuration(0);
  chart.rescale();
  chart.redraw();
  chart.transitionDuration(750);
});

What I want is, that on 'filtered', the bars are filtering (which happens as expected), but also that the yScale is readjusting, making the top value the one that is still shown and within the filtered range. So if my max value was y:3000 and I filter out this bar and the next biggest y value is 2000, the yAxis should now rescale to have this value as the top value and use its full height to show the remaining bars.

Problem is, I can't get this to work. Every time I include chart.elasticY(true), my data and the yAxisLabel disappear, but no error message is printed. Can you point me in the right direction? What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions