Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:feat: Adds includeEdge flag in EventArrangers. #294

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# [1.0.5] (UnReleased)(https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.5)

- Fixed issue related to auto scroll to initial duration for day
view-[#269](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/269)
view. [#269](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/269)
- Added
feature added a callback for the default header title
- [#241](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/241)
feature added a callback for the default header title. [#241](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/241)
- Added
feature added the quarterHourIndicator for the DayView & halfHourIndicator and
quarterHourIndicator for WeekView
- [#270](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/270)
quarterHourIndicator for WeekView. [#270](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/270)
- Added
feature added Support for changing the week day position(top/bottom) in weekView
- [#283](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/283)
feature added Support for changing the week day position(top/bottom) in weekView. [#283](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/283)
- Adds new flag `includeEdges` in `EventArrangers`. [#290](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/pull/294)

# [1.0.4 - 9 Aug 2023](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.4)

Expand Down
2 changes: 1 addition & 1 deletion lib/src/calendar_event_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CalendarEventData<T extends Object?> {
};

@override
String toString() => toJson().toString();
String toString() => '${toJson()}';

@override
bool operator ==(Object other) {
Expand Down
10 changes: 7 additions & 3 deletions lib/src/event_arrangers/event_arrangers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ part 'merge_event_arranger.dart';

part 'side_event_arranger.dart';

/// {@template event_arranger_arrange_method_doc}
/// This method will arrange all the events in and return List of
/// [OrganizedCalendarEventData].
///
/// {@endtemplate}

abstract class EventArranger<T extends Object?> {
/// [EventArranger] defines how simultaneous events will be arranged.
/// Implement [arrange] method to define how events will be arranged.
Expand All @@ -24,9 +30,7 @@ abstract class EventArranger<T extends Object?> {
///
const EventArranger();

/// This method will arrange all the events in and return List of
/// [OrganizedCalendarEventData].
///
/// {@macro event_arranger_arrange_method_doc}
List<OrganizedCalendarEventData<T>> arrange({
required List<CalendarEventData<T>> events,
required double height,
Expand Down
43 changes: 31 additions & 12 deletions lib/src/event_arrangers/merge_event_arranger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,36 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
/// events. and that will act like one single event.
/// [OrganizedCalendarEventData.events] will gives
/// list of all the combined events.
const MergeEventArranger();

const MergeEventArranger({
this.includeEdges = true,
});

/// Decides whether events that are overlapping on edge
/// (ex, event1 has the same end-time as the start-time of event 2)
/// should be merged together or not.
///
/// If includeEdges is true, it will merge the events else it will not.
///
final bool includeEdges;

/// {@macro event_arranger_arrange_method_doc}
///
/// Make sure that all the events that are passed in [events], must be in
/// ascending order of start time.
@override
List<OrganizedCalendarEventData<T>> arrange({
required List<CalendarEventData<T>> events,
required double height,
required double width,
required double heightPerMinute,
}) {
// TODO: Right now all the events that are passed in this function must be
// sorted in ascending order of the start time.
//
final arrangedEvents = <OrganizedCalendarEventData<T>>[];

for (final event in events) {
// Checks if an event has valid start and end time.
if (event.startTime == null ||
event.endTime == null ||
event.endTime!.getTotalMinutes <= event.startTime!.getTotalMinutes) {
Expand Down Expand Up @@ -56,6 +74,7 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
for (var i = 0; i < arrangeEventLen; i++) {
final arrangedEventStart =
arrangedEvents[i].startDuration.getTotalMinutes;

final arrangedEventEnd =
arrangedEvents[i].endDuration.getTotalMinutes == 0
? Constants.minutesADay
Expand Down Expand Up @@ -122,17 +141,17 @@ class MergeEventArranger<T extends Object?> extends EventArranger<T> {
return arrangedEvents;
}

bool _checkIsOverlapping(int arrangedEventStart, int arrangedEventEnd,
int eventStart, int eventEnd) {
var result = (arrangedEventStart >= eventStart &&
arrangedEventStart <= eventEnd) ||
(arrangedEventEnd >= eventStart && arrangedEventEnd <= eventEnd) ||
(eventStart >= arrangedEventStart && eventStart <= arrangedEventEnd) ||
(eventEnd >= arrangedEventStart && eventEnd <= arrangedEventEnd);
bool _checkIsOverlapping(int eStart1, int eEnd1, int eStart2, int eEnd2) {
final result = (eStart1 >= eStart2 && eStart1 < eEnd2) ||
(eEnd1 > eStart2 && eEnd1 <= eEnd2) ||
(eStart2 >= eStart1 && eStart2 < eEnd1) ||
(eEnd2 > eStart1 && eEnd2 <= eEnd1) ||
(includeEdges &&
(eStart1 == eEnd2 ||
eEnd1 == eStart2 ||
eStart2 == eEnd1 ||
eEnd2 == eStart1));

if (result) {
result = result && (arrangedEventEnd != eventStart);
}
return result;
}
}
20 changes: 18 additions & 2 deletions lib/src/event_arrangers/side_event_arranger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,32 @@ part of 'event_arrangers.dart';
class SideEventArranger<T extends Object?> extends EventArranger<T> {
/// This class will provide method that will arrange
/// all the events side by side.
const SideEventArranger();
const SideEventArranger({
this.includeEdges = false,
});

/// Decides whether events that are overlapping on edge
/// (ex, event1 has the same end-time as the start-time of event 2)
/// should be offset or not.
///
/// If includeEdges is true, it will offset the events else it will not.
///
final bool includeEdges;

/// {@macro event_arranger_arrange_method_doc}
///
/// Make sure that all the events that are passed in [events], must be in
/// ascending order of start time.
@override
List<OrganizedCalendarEventData<T>> arrange({
required List<CalendarEventData<T>> events,
required double height,
required double width,
required double heightPerMinute,
}) {
final mergedEvents = MergeEventArranger<T>().arrange(
final mergedEvents = MergeEventArranger<T>(
includeEdges: includeEdges,
).arrange(
events: events,
height: height,
width: width,
Expand Down
Loading
Loading