-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
add value color #46
add value color #46
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What it the goal? That color is just stored in database, and never used as far as I've seen.
fullcalendar takes color value into calendar display |
Hum... Okay, but I think there is something missing to achieve that ;) |
Ping? |
sorry, i didn’t see you're message. no other update, it work just with a small change add input color, update database and udpate object event with color value. |
I had something that seems correct with the following changes: diff --git a/lib/GaletteEvents/Repository/Events.php b/lib/GaletteEvents/Repository/Events.php
index 452c38a..8f1bb3f 100644
--- a/lib/GaletteEvents/Repository/Events.php
+++ b/lib/GaletteEvents/Repository/Events.php
@@ -192,6 +192,7 @@ class Events
$end_date = new \DateTime($event->getEndDate(false));
if ($fullcalendar === true) {
$end_date = $end_date->modify('+1 day');
+ $row['textColor'] = $this->getForegoundColor($row['color'] ?? '#ffffff');
}
$row['end'] = $end_date->format('Y-m-d');
@@ -385,4 +386,21 @@ class Events
{
return $this->count;
}
+
+ /**
+ * Get foreground contrasted color for a background color
+ *
+ * @param string $bgcolor Background color in hex format
+ *
+ * @return string
+ */
+ protected function getForegoundColor(string $bgcolor): string
+ {
+ $bgcolor = trim($bgcolor, '#');
+ $r = hexdec(substr($bgcolor,0,2));
+ $g = hexdec(substr($bgcolor,2,2));
+ $b = hexdec(substr($bgcolor,4,2));
+ $yiq = (($r*299)+($g*587)+($b*114))/1000;
+ return ($yiq >= 128) ? 'black' : 'white';
+ }
} |
Adapt foreground color to prevent contrast issues
add input color in an event.