feat: add colors for attendance status to lessen the cognitive load

- legend with colors and full form for status abbreviations
This commit is contained in:
Rucha Mahabal 2022-03-28 01:07:18 +05:30
parent e79d292233
commit 865204a541
2 changed files with 44 additions and 6 deletions

View File

@ -77,5 +77,25 @@ frappe.query_reports["Monthly Attendance Sheet"] = {
year_filter.set_input(year_filter.df.default);
}
});
},
formatter: function(value, row, column, data, default_formatter) {
value = default_formatter(value, row, column, data);
const summarized_view = frappe.query_report.get_filter_value('summarized_view');
const group_by = frappe.query_report.get_filter_value('group_by');
if (!summarized_view) {
if ((group_by && column.colIndex > 3) || (!group_by && column.colIndex > 2)) {
if (value == 'P' || value == 'WFH')
value = "<span style='color:green'>" + value + "</span>";
else if (value == 'A')
value = "<span style='color:red'>" + value + "</span>";
else if (value == 'HD')
value = "<span style='color:orange'>" + value + "</span>";
else if (value == 'L')
value = "<span style='color:#318AD8'>" + value + "</span>";
}
}
return value;
}
}

View File

@ -15,13 +15,13 @@ from frappe.query_builder.functions import Count, Extract, Sum
Filters = frappe._dict
status_map = {
'Present': 'P',
'Absent': 'A',
'Half Day': 'HD',
'Holiday': 'H',
'Weekly Off': 'WO',
'Work From Home': 'WFH',
'On Leave': 'L',
'Present': 'P',
'Work From Home': 'WFH'
'Holiday': 'H',
'Weekly Off': 'WO'
}
day_abbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
@ -38,9 +38,26 @@ def execute(filters: Optional[Filters] = None) -> Tuple:
if not data:
return columns, [], None, None
message = get_message() if not filters.summarized_view else ''
chart = get_chart_data(attendance_map, filters)
return columns, data, None, chart
return columns, data, message, chart
def get_message() -> str:
message = ''
colors = ['green', 'red', 'orange', 'green', '#318AD8', '', '']
count = 0
for status, abbr in status_map.items():
message += f"""
<span style='border-left: 2px solid {colors[count]}; padding-right: 12px; padding-left: 5px; margin-right: 3px;'>
{status} - {abbr}
</span>
"""
count += 1
return message
def get_columns(filters: Filters) -> List[Dict]:
@ -492,7 +509,8 @@ def get_chart_data(attendance_map: Dict, filters: Filters) -> Dict:
{'name': 'Leave', 'values': leave},
]
},
'type': 'line'
'type': 'line',
'colors': ['red', 'green', 'blue'],
}
return chart