initChartRenderer method
void
initChartRenderer(
)
override
Implementation
@override
void initChartRenderer() {
if (datas != null && datas!.isNotEmpty) {
var t = datas![0];
fixedLength =
NumberUtil.getMaxDecimalLength(t.open, t.close, t.high, t.low);
}
// 初始化主图表渲染器
if (isShowMainState) {
double mainRectHeight =
mainHeight ?? (mDisplayHeight * 0.6); // 使用自定义或默认高度
mMainRect = Rect.fromLTRB(0, 0, mWidth, mainRectHeight); // 主图区域定义
// print('[initChartRenderer] Main Renderer Initialized');
} else {
mMainRect = Rect.fromLTRB(0, 0, 0, 0); // 主图表高度设置为 0
}
mMainRenderer = MainRenderer(
mMainRect,
mMainMaxValue,
mMainMinValue,
mTopPadding,
mainState,
isLine,
fixedLength,
this.chartStyle,
this.chartColors,
this.scaleX,
verticalTextAlignment,
maDayList,
trendLineState,
);
if (mVolRect != null) {
double volRectHeight =
secondaryHeight ?? (mDisplayHeight * 0.2); // 使用次图高度或默认值
mVolRect = Rect.fromLTRB(
0,
mMainRect.bottom + mChildPadding,
mWidth,
mMainRect.bottom + mChildPadding + volRectHeight,
);
mVolRenderer = VolRenderer(
mVolRect!,
mVolMaxValue,
mVolMinValue,
mChildPadding,
fixedLength,
this.chartStyle,
this.chartColors) as BaseChartRenderer?;
// print(
// '[initChartRenderer] Volume Renderer Initialized: Rect = $mVolRect');
}
secondaryRenderers.clear();
// double secondaryTop = mMainRect.bottom + (mVolRect?.height ?? 0) + mChildPadding;
double secondaryTop =
mVolRect?.bottom ?? mMainRect.bottom; // 基于成交量图的底部作为初始位置
for (int i = 0; i < secondaryStates.length; i++) {
double secondaryRectHeight = secondaryHeight ??
(mDisplayHeight * 0.2) - mChildPadding; // 使用自定义或默认高度
double newSecondaryRectHeight = i * (secondaryRectHeight + mChildPadding);
if (i == 0) newSecondaryRectHeight = newSecondaryRectHeight + 10;
Rect secondaryRect = Rect.fromLTRB(
0,
secondaryTop + newSecondaryRectHeight, // 累积次图高度
mWidth,
secondaryTop + ((i + 1) * secondaryRectHeight) + (i * mChildPadding),
);
// 这里从BaseChartPainter里拿对应的 max/min Map
SecondaryState st = secondaryStates[i];
double secMax = mSecondaryMaxMap[st] ?? 0;
double secMin = mSecondaryMinMap[st] ?? 0;
SecondaryRenderer renderer = SecondaryRenderer(
secondaryRect,
secondaryRect,
secMax,
secMin,
mChildPadding,
secondaryStates[i],
fixedLength,
this.chartStyle,
this.chartColors,
);
secondaryRenderers.add(renderer);
// print('[initChartRenderer] Initialized Secondary Renderer [$i]: '
// 'State: ${secondaryStates[i]}, Rect: $secondaryRect');
}
// print(
// '[initChartRenderer] Secondary Renderers Count: ${secondaryRenderers.length}');
}