Skip to content

Commit 55f77fe

Browse files
committed
Added showWeekLabels and showMonthLabels properties to heatmap
1 parent 71f5a28 commit 55f77fe

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

lib/src/heatmap.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class HeatMap extends StatefulWidget {
8787
/// The double value of [HeatMapColorTip]'s tip container's size.
8888
final double? colorTipSize;
8989

90+
final bool? showWeekLabels;
91+
92+
final bool? showMonthLabels;
93+
9094
const HeatMap({
9195
Key? key,
9296
required this.colorsets,
@@ -107,6 +111,8 @@ class HeatMap extends StatefulWidget {
107111
this.colorTipHelper,
108112
this.colorTipCount,
109113
this.colorTipSize,
114+
this.showWeekLabels = true,
115+
this.showMonthLabels = true,
110116
}) : super(key: key);
111117

112118
@override
@@ -133,8 +139,7 @@ class _HeatMap extends State<HeatMap> {
133139
// Heatmap Widget.
134140
_scrollableHeatMap(HeatMapPage(
135141
endDate: widget.endDate ?? DateTime.now(),
136-
startDate: widget.startDate ??
137-
DateUtil.oneYearBefore(widget.endDate ?? DateTime.now()),
142+
startDate: widget.startDate ?? DateUtil.oneYearBefore(widget.endDate ?? DateTime.now()),
138143
colorMode: widget.colorMode,
139144
size: widget.size,
140145
fontSize: widget.fontSize,
@@ -146,6 +151,8 @@ class _HeatMap extends State<HeatMap> {
146151
onClick: widget.onClick,
147152
margin: widget.margin,
148153
showText: widget.showText,
154+
showWeekLabels: widget.showWeekLabels,
155+
showMonthLabels: widget.showMonthLabels,
149156
)),
150157

151158
// Show HeatMapColorTip if showColorTip is true.

lib/src/widget/heatmap_page.dart

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ class HeatMapPage extends StatelessWidget {
7575

7676
final bool? showText;
7777

78+
final bool? showWeekLabels;
79+
80+
final bool? showMonthLabels;
81+
7882
HeatMapPage({
7983
Key? key,
8084
required this.colorMode,
@@ -90,6 +94,8 @@ class HeatMapPage extends StatelessWidget {
9094
this.onClick,
9195
this.margin,
9296
this.showText,
97+
this.showWeekLabels,
98+
this.showMonthLabels,
9399
}) : _dateDifferent = endDate.difference(startDate).inDays,
94100
maxValue = DatasetsUtil.getMaxValue(datasets),
95101
super(key: key);
@@ -101,9 +107,7 @@ class HeatMapPage extends StatelessWidget {
101107

102108
// Set cursor(position) to first day of weeks
103109
// until cursor reaches the final week.
104-
for (int datePos = 0 - (startDate.weekday % 7);
105-
datePos <= _dateDifferent;
106-
datePos += 7) {
110+
for (int datePos = 0 - (startDate.weekday % 7); datePos <= _dateDifferent; datePos += 7) {
107111
// Get first day of week by adding cursor's value to startDate.
108112
DateTime _firstDay = DateUtil.changeDay(startDate, datePos);
109113

@@ -114,9 +118,8 @@ class HeatMapPage extends StatelessWidget {
114118
// To make empty space to future day, we have to pass this HeatMapPage's
115119
// endDate to HeatMapColumn's endDate.
116120
startDate: _firstDay,
117-
endDate: datePos <= _dateDifferent - 7
118-
? DateUtil.changeDay(startDate, datePos + 6)
119-
: endDate,
121+
endDate:
122+
datePos <= _dateDifferent - 7 ? DateUtil.changeDay(startDate, datePos + 6) : endDate,
120123
colorMode: colorMode,
121124
numDays: min(endDate.difference(_firstDay).inDays + 1, 7),
122125
size: size,
@@ -147,23 +150,25 @@ class HeatMapPage extends StatelessWidget {
147150
mainAxisSize: MainAxisSize.min,
148151
children: [
149152
// Show week labels to left side of heatmap.
150-
HeatMapWeekText(
151-
margin: margin,
152-
fontSize: fontSize,
153-
size: size,
154-
fontColor: textColor,
155-
),
153+
if (this.showWeekLabels == true)
154+
HeatMapWeekText(
155+
margin: margin,
156+
fontSize: fontSize,
157+
size: size,
158+
fontColor: textColor,
159+
),
156160
Column(
157161
crossAxisAlignment: CrossAxisAlignment.start,
158162
children: [
159163
// Show month labels to top of heatmap.
160-
HeatMapMonthText(
161-
firstDayInfos: _firstDayInfos,
162-
margin: margin,
163-
fontSize: fontSize,
164-
fontColor: textColor,
165-
size: size,
166-
),
164+
if (this.showMonthLabels == true)
165+
HeatMapMonthText(
166+
firstDayInfos: _firstDayInfos,
167+
margin: margin,
168+
fontSize: fontSize,
169+
fontColor: textColor,
170+
size: size,
171+
),
167172

168173
// Heatmap itself.
169174
Row(

0 commit comments

Comments
 (0)