Skip to content

Commit

Permalink
add showQuoteGrid and showEpochGrid to control Quote and Epoch grid v…
Browse files Browse the repository at this point in the history
…isibility (#292)
  • Loading branch information
osama-deriv authored Jan 19, 2024
1 parent 0a3353f commit 23df801
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lib/src/deriv_chart/chart/basic_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,11 @@ class BasicChartState<T extends BasicChart> extends State<T>
return Stack(
fit: StackFit.expand,
children: <Widget>[
_buildQuoteGridLine(gridLineQuotes),
if (context.read<ChartConfig>().chartAxisConfig.showQuoteGrid)
_buildQuoteGridLine(gridLineQuotes),
_buildChartData(),
_buildQuoteGridLabel(gridLineQuotes),
if (context.read<ChartConfig>().chartAxisConfig.showQuoteGrid)
_buildQuoteGridLabel(gridLineQuotes),
],
);
},
Expand Down
1 change: 1 addition & 0 deletions lib/src/deriv_chart/chart/chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class _ChartState extends State<Chart> with WidgetsBindingObserver {
final ChartConfig chartConfig = ChartConfig(
pipSize: widget.pipSize,
granularity: widget.granularity,
chartAxisConfig: widget.chartAxisConfig,
);

final List<ChartData> chartDataList = <ChartData>[
Expand Down
25 changes: 13 additions & 12 deletions lib/src/deriv_chart/chart/x_axis/x_axis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,21 @@ class _XAxisState extends State<XAxis> with TickerProviderStateMixin {
return Stack(
fit: StackFit.expand,
children: <Widget>[
RepaintBoundary(
child: CustomPaint(
painter: XGridPainter(
timeLabels: _noOverlapGridTimestamps
.map<String>((DateTime time) => timeLabel(time))
.toList(),
xCoords: _noOverlapGridTimestamps
.map<double>((DateTime time) =>
_model.xFromEpoch(time.millisecondsSinceEpoch))
.toList(),
style: _chartTheme.gridStyle,
if (context.read<ChartConfig>().chartAxisConfig.showEpochGrid)
RepaintBoundary(
child: CustomPaint(
painter: XGridPainter(
timeLabels: _noOverlapGridTimestamps
.map<String>((DateTime time) => timeLabel(time))
.toList(),
xCoords: _noOverlapGridTimestamps
.map<double>((DateTime time) =>
_model.xFromEpoch(time.millisecondsSinceEpoch))
.toList(),
style: _chartTheme.gridStyle,
),
),
),
),
Padding(
padding: EdgeInsets.only(
bottom: _chartTheme.gridStyle.xLabelsAreaHeight,
Expand Down
8 changes: 8 additions & 0 deletions lib/src/models/chart_axis_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ChartAxisConfig {
this.initialTopBoundQuote = defaultTopBoundQuote,
this.initialBottomBoundQuote = defaultBottomBoundQuote,
this.maxCurrentTickOffset = defaultMaxCurrentTickOffset,
this.showQuoteGrid = true,
this.showEpochGrid = true,
});

/// Top quote bound target for animated transition.
Expand All @@ -30,6 +32,12 @@ class ChartAxisConfig {
/// Limits panning to the right.
final double maxCurrentTickOffset;

/// Show Quote Grid lines and labels.
final bool showQuoteGrid;

/// Show Epoch Grid lines and labels.
final bool showEpochGrid;

/// Creates a copy of this ChartAxisConfig but with the given fields replaced.
ChartAxisConfig copyWith({
double? initialTopBoundQuote,
Expand Down
10 changes: 9 additions & 1 deletion lib/src/models/chart_config.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import 'package:deriv_chart/deriv_chart.dart';
import 'package:flutter/material.dart';

/// Chart's general configuration.
@immutable
class ChartConfig {
/// Initializes chart's general configuration.
const ChartConfig({required this.granularity, this.pipSize = 4});
const ChartConfig({
required this.granularity,
this.chartAxisConfig = const ChartAxisConfig(),
this.pipSize = 4,
});

/// PipSize, number of decimal digits when showing prices on the chart.
final int pipSize;

/// Granularity.
final int granularity;

/// Chart Axis configuration.
final ChartAxisConfig chartAxisConfig;

@override
bool operator ==(covariant ChartConfig other) =>
pipSize == other.pipSize && granularity == other.granularity;
Expand Down

0 comments on commit 23df801

Please sign in to comment.