Git Product home page Git Product logo

p_front_s's Introduction

Result

image info

The problem

The problem consists in rendering events on a calendar, avoiding overlapping events to visually overlap. Your implementation should meet the two following constraints:

  1. Every overlapping event should have the same width as every event it overlaps
  2. Every event should use the maximum width available while satisfying constraint 1

A visual illustration of the problem is given below.

Rendering events on a calendar means here: the relative position of events to the top of the screen and their height is a function of the height of the screen, the start/end time of the calendar, and the start time/duration of the events. For example: if the calendar goes from 00:00 to 24:00 and the screen is 2400px high, an event starting at 12:00 and lasting 1h would be positioned at 1200px of the top of the screen and have a height of 100px.

Using the maximum width available here implies that the width of every group of mutually overlapping events equals the width of the window.

The input

The input (available below) is an array of events occurring on the same date. They have the following structure:

{
  id: 1,
  start: '15:00', // The event starts at 03:00 pm
  duration: 90 // The duration is expressed in minutes
}

The output

Your code should render the events on a webpage in a container spanning the whole window. The top of the page represents 09:00 am. The bottom of the page represents 09:00 pm.

The events should be represented as a div with a background color and a 1px border. The div should display the event's id.

Your implementation should be responsive (i.e. respond to window resize events).

Dependencies

You may use React, any lightweight templating library, or vanilla JS to do the rendering. You may use helper libraries such as lodash, etc. if you wish to. Javascript can be written in ES6.

The easiest way to share your code is a sandbox. If you wish to go with React, you may share a project created with create-react-app, preferably on github.

Browser support

Your code should run in major modern browsers.

Evaluation

Our evaluation criteria are:

  • the correctness of the algorithm
  • the readability of the code (code structure, variables naming, comments,…)

Visual illustration of the problem

1 event

┌────────────┐
|            |
└────────────┘

2 events

┌─────┐┌─────┐
|     |└─────┘
└─────┘

3 events where events 1, 2 and 3 overlap, but events 1 and 3 do not

┌─────┐
|  1  |┌─────┐
└─────┘|     |
       |  2  |
┌─────┐|     |
|  3  |└─────┘
└─────┘

The configuration above meets all constraints. Be careful, something like below would not meet constraint 2 :

┌───┐
| 1 |┌───┐
└───┘|   |
     | 2 |
     |   |┌───┐
     └───┘| 3 |
          └───┘

If we combine cases 1, 2 and 3, you should end up with something like

The schema below assumes the width of event 1 equals the width of the window.

┌────────────┐
|     1      |
└────────────┘

┌─────┐┌─────┐
|     ||  3  |
|  2  |└─────┘
|     |
└─────┘

┌─────┐
|  4  |┌─────┐
└─────┘|     |
       |  5  |
┌─────┐|     |
|  6  |└─────┘
└─────┘

Satisfying both constraints

The schema below assumes the width of event 1 equals the width of the window.

┌────────────┐
|     1      |
└────────────┘

┌─────┐┌─────┐
|     ||  3  |
|  2  |└─────┘
|     |
└─────┘

┌───┐┌───┐
|   || 5 |
| 4 |└───┘
|   |
└───┘

Events 2 et 3 satisfy both constraints. Events 4 and 5 do not.

p_front_s's People

Stargazers

Roman avatar

Watchers

James Cloos avatar hafid denguir avatar

Forkers

qqizi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.