javascript - Automatically resize d3.js chart y scale based on brush selection -


i'm using d3.js v4.

is there more convenient way find minimum , maximum values of brush selection. meant resize y axis when select period in brush area below.

here method (everything inside function called when brush used) :

  • i find extent limits of selection

    extent = d3.event.selection.map(chartcomponent.x2().invert)) 
  • then have redo array containing selected points: go on each point , compare extent[0] or extent[1] see if in limits. store beginning , end point indices , use data.slice(begin, end) on original data new array.

  • then apply d3.min , d3.max on new array find min , max level.

  • then set y axis use theses limits.

    chart.y().domain([chartcomponent.ymin, chartcomponent.ymax]); chart.yaxisgraph.call(chartcomponent.yaxis(true)); 

do have better idea ?


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -