Replies: 1 comment 1 reply
-
Hey @mikeebee 👋 thanks for checking out You'll be happy to know Here's a sandbox with a custom Here's a copy of the code, you then just render this as a child of const EndGlyph = ({ dataKey, ...circleProps }: { dataKey: string }) => {
const { xScale, yScale, dataRegistry, colorScale, theme } = useContext(
DataContext
);
// get the series data from the data context registry
const series = dataRegistry.get(dataKey);
// data not registered yet
if (!series || !xScale || !yScale) return null;
// compute the location of the point using the same scales the chart uses
const lastDatum = series.data[series.data.length - 1];
const scaledX = xScale(series.xAccessor(lastDatum));
const scaledY = yScale(series.yAccessor(lastDatum));
// bandwidths are kind of made for rects, correct circle position to
// account for the width of the band (see d3 docs for more)
const bandScaleOffset =
"bandwidth" in xScale && typeof xScale.bandwidth !== "undefined"
? xScale.bandwidth() / 2
: 0;
return typeof scaledX === "number" && typeof scaledY === "number" ? (
<circle
cx={scaledX + bandScaleOffset}
cy={scaledY}
fill={colorScale(dataKey) ?? theme.gridStyles.stroke}
r={5}
{...circleProps}
/>
) : null;
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello all!
I'm new to D3 scales and Visx so I'm hoping it's something silly I'm missing. I'm having an issue correctly positioning a glyph when I change a setting on the
yScale
of an<XYChart />
.I used an
<XYChart />
to create a simple line graph. I also added a custom<Glyph />
to add a point to the last point on the<LineSeries />
.It looks like this
So in this case, it's working perfectly. However, I would like the line on the chart to sit more in the middle. For this, I used the
zero: false
setting on theyScale
. This affected the chart as expected, however, the custom glyph I added isn't affected by this change at all. So it looks like this...Is this the best approach to centre the line on the chart? I would be happy for it to still appear as the first screenshot (in terms of its height), just centred more on the grid if that's easier.
If so, could someone assist me in having the chart and glyph appear as hoped? Also more than happy to hear about better alternatives.
I have a working Sandbox here on
line 34
you can changezero
totrue
to see where the glyph should sit.The function responsible for the glyph position is called
getChartPointPosition
and it is in the utils file in the Sandbox.Many thanks,
Mike
Beta Was this translation helpful? Give feedback.
All reactions