Loading src/fullcalendar/eventSources/eventSource.js +3 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ * */ import { generateTextColorForHex, generateAlphaColor, } from '../../utils/color.js' import getTimezoneManager from '../../services/timezoneDataProviderService' import { getUnixTimestampFromDate } from '../../utils/date.js' Loading @@ -38,9 +38,9 @@ export default function(store) { const source = { id: calendar.id, // coloring backgroundColor: calendar.color, backgroundColor: generateAlphaColor(calendar.color, 0.1), borderColor: calendar.color, textColor: generateTextColorForHex(calendar.color), textColor: calendar.color, // html foo events: async({ start, end, timeZone }, successCallback, failureCallback) => { let timezoneObject = getTimezoneManager().getTimezoneForId(timeZone) Loading src/utils/color.js +17 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,23 @@ export function isLight({ red, green, blue }) { return (brightness > 130) } /** * Returns the rgba representation of a hexColor and an alpha value * * @param {String} hexColor The hex color to get a text color for * @param {Number} alpha The alpha-value of the rgba * @returns {String} The rgba value */ export function generateAlphaColor(hexColor, alpha) { const { red, green, blue, } = hexToRGB(hexColor) return `rgba(${red}, ${green}, ${blue}, ${alpha})` } /** * Get a text-color that's readable on a given background color * Loading tests/javascript/unit/fullcalendar/eventSources/eventSource.test.js +22 −22 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ */ import eventSource from "../../../../../src/fullcalendar/eventSources/eventSource.js"; import { generateTextColorForHex } from '../../../../../src/utils/color.js' import { generateAlphaColor } from '../../../../../src/utils/color.js' import getTimezoneManager from '../../../../../src/services/timezoneDataProviderService' import { getUnixTimestampFromDate } from '../../../../../src/utils/date.js' import { eventSourceFunction } from '../../../../../src/fullcalendar/eventSources/eventSourceFunction.js' Loading @@ -34,7 +34,7 @@ jest.mock('../../../../../src/fullcalendar/eventSources/eventSourceFunction.js') describe('fullcalendar/eventSource test suite', () => { beforeEach(() => { generateTextColorForHex.mockClear() generateAlphaColor.mockClear() getTimezoneManager.mockClear() getUnixTimestampFromDate.mockClear() eventSourceFunction.mockClear() Loading @@ -48,20 +48,20 @@ describe('fullcalendar/eventSource test suite', () => { readOnly: false } generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') const eventSourceFunction = eventSource(store) expect(eventSourceFunction(calendar)).toEqual({ id: 'calendar-id-123', backgroundColor: '#ff00ff', backgroundColor: 'rgba(255, 0, 255, 0.1)', borderColor: '#ff00ff', textColor: '#00ff00', textColor: '#ff00ff', events: expect.any(Function) }) expect(generateTextColorForHex).toHaveBeenCalledTimes(1) expect(generateTextColorForHex).toHaveBeenNthCalledWith(1, '#ff00ff') expect(generateAlphaColor).toHaveBeenCalledTimes(1) expect(generateAlphaColor).toHaveBeenNthCalledWith(1, '#ff00ff', 0.1) }) it('should provide an eventSource for a given read-only calendar', () => { Loading @@ -72,21 +72,21 @@ describe('fullcalendar/eventSource test suite', () => { readOnly: true } generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') const eventSourceFunction = eventSource(store) expect(eventSourceFunction(calendar)).toEqual({ id: 'calendar-id-123', backgroundColor: '#ff00ff', backgroundColor: 'rgba(255, 0, 255, 0.1)', borderColor: '#ff00ff', textColor: '#00ff00', textColor: '#ff00ff', events: expect.any(Function), editable: false }) expect(generateTextColorForHex).toHaveBeenCalledTimes(1) expect(generateTextColorForHex).toHaveBeenNthCalledWith(1, '#ff00ff') expect(generateAlphaColor).toHaveBeenCalledTimes(1) expect(generateAlphaColor).toHaveBeenNthCalledWith(1, '#ff00ff', 0.1) }) it('should provide an eventSource function to provide events - fetch new timerange', async () => { Loading Loading @@ -118,8 +118,8 @@ describe('fullcalendar/eventSource test suite', () => { .mockReturnValueOnce(1234) .mockReturnValueOnce(5678) generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') eventSourceFunction .mockReturnValueOnce([{ fcEventId: 1 }, { fcEventId: 2 }]) Loading Loading @@ -188,8 +188,8 @@ describe('fullcalendar/eventSource test suite', () => { .mockReturnValueOnce(1234) .mockReturnValueOnce(5678) generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') eventSourceFunction .mockReturnValueOnce([{ fcEventId: 1 }, { fcEventId: 2 }]) Loading Loading @@ -254,8 +254,8 @@ describe('fullcalendar/eventSource test suite', () => { .mockReturnValueOnce(1234) .mockReturnValueOnce(5678) generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') eventSourceFunction .mockReturnValueOnce([{ fcEventId: 1 }, { fcEventId: 2 }]) Loading Loading @@ -323,8 +323,8 @@ describe('fullcalendar/eventSource test suite', () => { .mockReturnValueOnce(1234) .mockReturnValueOnce(5678) generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') eventSourceFunction .mockReturnValueOnce([{ fcEventId: 1 }, { fcEventId: 2 }]) Loading Loading
src/fullcalendar/eventSources/eventSource.js +3 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ * */ import { generateTextColorForHex, generateAlphaColor, } from '../../utils/color.js' import getTimezoneManager from '../../services/timezoneDataProviderService' import { getUnixTimestampFromDate } from '../../utils/date.js' Loading @@ -38,9 +38,9 @@ export default function(store) { const source = { id: calendar.id, // coloring backgroundColor: calendar.color, backgroundColor: generateAlphaColor(calendar.color, 0.1), borderColor: calendar.color, textColor: generateTextColorForHex(calendar.color), textColor: calendar.color, // html foo events: async({ start, end, timeZone }, successCallback, failureCallback) => { let timezoneObject = getTimezoneManager().getTimezoneForId(timeZone) Loading
src/utils/color.js +17 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,23 @@ export function isLight({ red, green, blue }) { return (brightness > 130) } /** * Returns the rgba representation of a hexColor and an alpha value * * @param {String} hexColor The hex color to get a text color for * @param {Number} alpha The alpha-value of the rgba * @returns {String} The rgba value */ export function generateAlphaColor(hexColor, alpha) { const { red, green, blue, } = hexToRGB(hexColor) return `rgba(${red}, ${green}, ${blue}, ${alpha})` } /** * Get a text-color that's readable on a given background color * Loading
tests/javascript/unit/fullcalendar/eventSources/eventSource.test.js +22 −22 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ */ import eventSource from "../../../../../src/fullcalendar/eventSources/eventSource.js"; import { generateTextColorForHex } from '../../../../../src/utils/color.js' import { generateAlphaColor } from '../../../../../src/utils/color.js' import getTimezoneManager from '../../../../../src/services/timezoneDataProviderService' import { getUnixTimestampFromDate } from '../../../../../src/utils/date.js' import { eventSourceFunction } from '../../../../../src/fullcalendar/eventSources/eventSourceFunction.js' Loading @@ -34,7 +34,7 @@ jest.mock('../../../../../src/fullcalendar/eventSources/eventSourceFunction.js') describe('fullcalendar/eventSource test suite', () => { beforeEach(() => { generateTextColorForHex.mockClear() generateAlphaColor.mockClear() getTimezoneManager.mockClear() getUnixTimestampFromDate.mockClear() eventSourceFunction.mockClear() Loading @@ -48,20 +48,20 @@ describe('fullcalendar/eventSource test suite', () => { readOnly: false } generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') const eventSourceFunction = eventSource(store) expect(eventSourceFunction(calendar)).toEqual({ id: 'calendar-id-123', backgroundColor: '#ff00ff', backgroundColor: 'rgba(255, 0, 255, 0.1)', borderColor: '#ff00ff', textColor: '#00ff00', textColor: '#ff00ff', events: expect.any(Function) }) expect(generateTextColorForHex).toHaveBeenCalledTimes(1) expect(generateTextColorForHex).toHaveBeenNthCalledWith(1, '#ff00ff') expect(generateAlphaColor).toHaveBeenCalledTimes(1) expect(generateAlphaColor).toHaveBeenNthCalledWith(1, '#ff00ff', 0.1) }) it('should provide an eventSource for a given read-only calendar', () => { Loading @@ -72,21 +72,21 @@ describe('fullcalendar/eventSource test suite', () => { readOnly: true } generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') const eventSourceFunction = eventSource(store) expect(eventSourceFunction(calendar)).toEqual({ id: 'calendar-id-123', backgroundColor: '#ff00ff', backgroundColor: 'rgba(255, 0, 255, 0.1)', borderColor: '#ff00ff', textColor: '#00ff00', textColor: '#ff00ff', events: expect.any(Function), editable: false }) expect(generateTextColorForHex).toHaveBeenCalledTimes(1) expect(generateTextColorForHex).toHaveBeenNthCalledWith(1, '#ff00ff') expect(generateAlphaColor).toHaveBeenCalledTimes(1) expect(generateAlphaColor).toHaveBeenNthCalledWith(1, '#ff00ff', 0.1) }) it('should provide an eventSource function to provide events - fetch new timerange', async () => { Loading Loading @@ -118,8 +118,8 @@ describe('fullcalendar/eventSource test suite', () => { .mockReturnValueOnce(1234) .mockReturnValueOnce(5678) generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') eventSourceFunction .mockReturnValueOnce([{ fcEventId: 1 }, { fcEventId: 2 }]) Loading Loading @@ -188,8 +188,8 @@ describe('fullcalendar/eventSource test suite', () => { .mockReturnValueOnce(1234) .mockReturnValueOnce(5678) generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') eventSourceFunction .mockReturnValueOnce([{ fcEventId: 1 }, { fcEventId: 2 }]) Loading Loading @@ -254,8 +254,8 @@ describe('fullcalendar/eventSource test suite', () => { .mockReturnValueOnce(1234) .mockReturnValueOnce(5678) generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') eventSourceFunction .mockReturnValueOnce([{ fcEventId: 1 }, { fcEventId: 2 }]) Loading Loading @@ -323,8 +323,8 @@ describe('fullcalendar/eventSource test suite', () => { .mockReturnValueOnce(1234) .mockReturnValueOnce(5678) generateTextColorForHex .mockReturnValue('#00ff00') generateAlphaColor .mockReturnValue('rgba(255, 0, 255, 0.1)') eventSourceFunction .mockReturnValueOnce([{ fcEventId: 1 }, { fcEventId: 2 }]) Loading