Open MaxYari opened 4 years ago
Bump: Any info regarding this?
Ok, I solved it by building a map of d3-time timeInterval
s for possible dataset time periods.
Given I already have dataset time period strings - here's an example:
import { last, timeIntervalBarWidth } from "react-stockcharts/lib/utils";
import { utcDay, utcMinute, utcHour } from "d3-time";
...
var periodToTimeIntervalMap = {
"1m": utcMinute,
"5m": utcMinute.every(5),
"30m": utcMinute.every(30),
"1h": utcHour,
"3h": utcHour.every(3),
"1d": utcDay
}
var timeInterval = periodToTimeIntervalMap[state.dataset.period];
if (!timeInterval) timeInterval = utcMinute;
function barWidthAccessor() {
return 0.8*timeIntervalBarWidth(timeInterval)(...arguments);
};
and then add a param to CandlestickSeries
(or anything else that needs bar/candle width adjusted)
width={barWidthAccessor}
in barWidthAccessor()
returned value is multiplied by 0.8 so bards will have a bit of space inbetween them.
Actually will leave it open, since my solution is a workaround and doesn't solve an underlying issue of absent width auto adjustment. Unless this feature removal was intended - in that case, feel free to close.
Just updated to if 0.7.8. When
CandlestickSeries
is used withoutwidth={timeIntervalBarWidth(utcDay)}
- chart displays thin lines without candle body. In previous versions, candle width was adjusting to timeframe automatically which was quite handy.