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

add value color #46

Merged
merged 1 commit into from
Apr 15, 2024
Merged

add value color #46

merged 1 commit into from
Apr 15, 2024

Conversation

dudjima
Copy link
Contributor

@dudjima dudjima commented Apr 8, 2024

add input color in an event.

Copy link
Member

@trasher trasher left a 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.

lib/GaletteEvents/Event.php Outdated Show resolved Hide resolved
@dudjima
Copy link
Contributor Author

dudjima commented Apr 8, 2024

fullcalendar takes color value into calendar display

@trasher
Copy link
Member

trasher commented Apr 8, 2024

fullcalendar takes color value into calendar display

Hum... Okay, but I think there is something missing to achieve that ;)

@trasher
Copy link
Member

trasher commented Apr 15, 2024

fullcalendar takes color value into calendar display

Hum... Okay, but I think there is something missing to achieve that ;)

Ping?

@dudjima
Copy link
Contributor Author

dudjima commented Apr 15, 2024

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.

@trasher
Copy link
Member

trasher commented Apr 15, 2024

Okay, indeed, this is automatically passed to calendar.

I've just tested, I had to made changes for storage to work; and I've added update scripts; all seems to go well.

From an UI point of view, there is an issue when background color is set to a light color, since text is white:
image

I have no idea how to get that fixed for now

@trasher
Copy link
Member

trasher commented Apr 15, 2024

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';
+    }
 }

@trasher
Copy link
Member

trasher commented Apr 15, 2024

image

Adapt foreground color to prevent contrast issues
@trasher trasher merged commit 88361ed into galette:develop Apr 15, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants