Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reposition labels with canvas crosshair / line annotation #1628

Open
artemiusgreat opened this issue Sep 21, 2020 · 3 comments · May be fixed by #1632
Open

Cannot reposition labels with canvas crosshair / line annotation #1628

artemiusgreat opened this issue Sep 21, 2020 · 3 comments · May be fixed by #1632

Comments

@artemiusgreat
Copy link

artemiusgreat commented Sep 21, 2020

Trying to use this example in combination with canvas candlestick chart.
https://d3fc.io/examples/annotation-canvas-crosshair/

Setting X and Y labels for crosshair annotation.

const crosshair = fc
  .annotationCanvasCrosshair()
  .xLabel(o => 'x')
  .yLabel(o => 'y');

For some reason, it shows only X label.
https://codepen.io/artemiusgreat/pen/xxVQEbW

Where is Y label?

@ColinEberhardt
Copy link
Member

Crosshairs use the line annotation component - where the label position is typically adjusted using the decorate pattern. However, I've just noticed that with the canvas line annotation the decorate function is called at a location where I don't think you can reposition the labels without repositioning the line itself!

I'll look at fixing this. In the meantime, how about using SVG instead?

const stream = fc.randomFinancial().stream();
//const data = stream.take(500);
const data = {
  series: stream.take(50),
  crosshair: []
};

var x = d3.scaleTime();
var y = d3.scaleLinear();

const xExtent = fc.extentDate()
  .accessors([d => d.date])

const yExtent = fc.extentLinear()
  .accessors([d => d.high, d => d.low])
  .pad([0.1, 0.1])


const candlesticks = fc.autoBandwidth(fc.seriesCanvasCandlestick())
			.widthFraction(0.75)
			.crossValue(d => d.date)
			.openValue(d => d.open)
			.highValue(d => d.high)
			.lowValue(d => d.low)
			.closeValue(d => d.close)
 
const crosshair = fc
  .annotationSvgCrosshair()
  .xLabel(o => 'x')
  .yLabel(o => 'y');

const canvasMulti = fc.seriesCanvasMulti()
			.series([candlesticks])
      .mapping((data, index, series) => data.series);

const svgMulti = fc.seriesSvgMulti()
			.series([crosshair])
      .mapping((data, index, series) => data.crosshair);

const chart = fc.chartCartesian(x, y)
  .canvasPlotArea(canvasMulti)
  .svgPlotArea(svgMulti);

function render() {
  d3.select('#zoom-chart')
    .datum(data)
    .call(chart);  
  
   // add the pointer component to the plot-area, re-rendering
  // each time the event fires.
  var pointer = fc.pointer()
    .on('point', (event) => {
      data.crosshair = [event[0]];
      render();
    });

  d3.select('#zoom-chart d3fc-svg.plot-area')
    .call(pointer); 
}

function updateData() {
  chart
    .xDomain(xExtent(data.series))
    .yDomain(yExtent(data.series));

  render();
}

updateData()

@ColinEberhardt ColinEberhardt changed the title Crosshair's Y label is not displayed on the candlestick chart Cannot reposition labels with canvas crosshair / line annotation Sep 21, 2020
@ColinEberhardt
Copy link
Member

See also #1158

@JaaduGit
Copy link

Hey is it issue fixed i am facing the same problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants