Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- |-------|-------|-------|-------|-------|-------|
- nov dec jan feb mar apr may
- |-------|-------|-------|-------|-------|-------|
- nov dec jan feb mar apr
- // scale is your usual x scale. change dates on the domain by 15 days
- var d0 = scale.domain()[0];
- d0.setDate(d0.getDate() - 15);
- var d1 = scale.domain()[1];
- d1.setDate(d1.getDate() - 15);
- // use this new x scale for the axis only
- new_scale = d3.time.scale().domain([d0, d1]).range(scale.range());
- d3.svg.axis().scale(new_scale);
- // ticksDistance is constant for a specific x_scale
- const getTicksDistance = (scale, ticks) => {
- const tcks = scale.ticks(ticks);
- const spaces = []
- for(let i=0; i < tcks.length - 1; i++){
- spaces.push(scale(tcks[i+1]) - scale(tcks[i]))
- }
- return spaces;
- };
- const ticksSpacingTime = getTicksDistance(x_scale_time, d3.timeMonth.every(1));
- svg.append("g")
- .attr("class", "x-axis-shifted")
- .attr("transform", "translate(0,100)")
- .call(x_axis)
- .selectAll("text")
- .attr("x", (d,i) => ticksSpacingTime[i]/2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement