Skip to content

Commit

Permalink
支持secondary区域点击事件
Browse files Browse the repository at this point in the history
  • Loading branch information
ransj committed Apr 4, 2021
1 parent 0142a33 commit 7385632
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
36 changes: 22 additions & 14 deletions lib/k_chart_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class KChartWidget extends StatefulWidget {
final MainState mainState;
final bool volHidden;
final SecondaryState secondaryState;
final Function() onSecondaryTap;
final bool isLine;
final bool isChinese;
final List<String> timeFormat;
Expand All @@ -48,6 +49,7 @@ class KChartWidget extends StatefulWidget {
this.datas, {
this.mainState = MainState.MA,
this.secondaryState = SecondaryState.MACD,
this.onSecondaryTap,
this.volHidden = false,
this.isLine,
this.isChinese = true,
Expand Down Expand Up @@ -106,7 +108,26 @@ class _KChartWidgetState extends State<KChartWidget>
mScrollX = mSelectX = 0.0;
mScaleX = 1.0;
}
final _painter = ChartPainter(
datas: widget.datas,
scaleX: mScaleX,
scrollX: mScrollX,
selectX: mSelectX,
isLongPass: isLongPress,
mainState: widget.mainState,
volHidden: widget.volHidden,
secondaryState: widget.secondaryState,
isLine: widget.isLine,
sink: mInfoWindowStream?.sink,
bgColor: widget.bgColor,
fixedLength: widget.fixedLength,
maDayList: widget.maDayList);
return GestureDetector(
onTapUp: (details) {
if(widget.onSecondaryTap != null && _painter.isInSecondaryRect(details.localPosition)) {
widget.onSecondaryTap();
}
},
onHorizontalDragDown: (details) {
_stopAnimation();
_onDragChanged(true);
Expand Down Expand Up @@ -156,20 +177,7 @@ class _KChartWidgetState extends State<KChartWidget>
children: <Widget>[
CustomPaint(
size: Size(double.infinity, double.infinity),
painter: ChartPainter(
datas: widget.datas,
scaleX: mScaleX,
scrollX: mScrollX,
selectX: mSelectX,
isLongPass: isLongPress,
mainState: widget.mainState,
volHidden: widget.volHidden,
secondaryState: widget.secondaryState,
isLine: widget.isLine,
sink: mInfoWindowStream?.sink,
bgColor: widget.bgColor,
fixedLength: widget.fixedLength,
maDayList: widget.maDayList),
painter: _painter,
),
_buildInfoDialog()
],
Expand Down
5 changes: 5 additions & 0 deletions lib/renderer/chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,9 @@ class ChartPainter extends BaseChartPainter {
dateFormat(DateTime.fromMillisecondsSinceEpoch(date), mFormats);

double getMainY(double y) => mMainRenderer?.getY(y) ?? 0.0;

/// 点是否在SecondaryRect中
bool isInSecondaryRect(Offset point) {
return mSecondaryRect?.contains(point) ?? false;
}
}

0 comments on commit 7385632

Please sign in to comment.