turbopascal | Web-based Turbo Pascal compiler | Interpreter library
kandi X-RAY | turbopascal Summary
kandi X-RAY | turbopascal Summary
Web-based Turbo Pascal compiler.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of turbopascal
turbopascal Key Features
turbopascal Examples and Code Snippets
Community Discussions
Trending Discussions on turbopascal
QUESTION
I've included a code snippet that hopefully should sum things up nicely and is represented in a sort of 'Fill in the blanks' kind of state.
If it helps to understand the origin of the problem by seeing it in a larger context, what I'm ultimately doing is showing a daily view schedule on calendar on a phone, probably similar to how the calendar on your phone works. When events begin to overlap in time, represented by the vertical y axis here I want to be able to optimize the width and positioning of those events, not overlapping them and not hiding more than I have to for the content - but when there are too many being able to indicate things are hidden.
I'm not looking for any CSS/HTML based solutions despite the sample being in javascript - the DOM structure is more or less set in stone, just looking for an algorithm that might do what I'm looking for, if it's in C++, TurboPascal, Assembly, Java, whatever doesn't really matter. In my example expected results the more complex the scenario the results are more like rough estimates, and it comes across in the demo as well when rendering my expected results - I don't even really have a terrific method for doing the math in my head once things start getting weird.
The objective is to fill in the function optimizeLeftAndRightXStartPointsForNormalizedRectangleAreaWithoutOverlapping = (rectangles,minimumArea,minimumWidth,xMin,xMax)=>{}
ANSWER
Answered 2019-Nov-26 at 15:24The algorithm in this answer attempts to arrange rectangles inside a fixed-width bounding box. Input to the algorithm is an array of rectangles whose topY
and bottomY
are specified. The algorithm computes the leftX
and rightX
for each rectangle. Rectangles are sized and positioned to avoid overlap. For example, the image below shows 7 rectangles that have been arranged by the algorithm. In region 1, the maximum overlap is 2, so the rectangles are drawn half width. Region 2 has no overlap, so the rectangle is full width. And region 3 has overlap 3, and therefore rectangles are one-third the width of the bounding box.
The algorithm has three major steps:
- Fill the
eventQueue
based on the information in the input array. Each rectangle spawns two events: anEVENT_START
with thetopY
, and anEVENT_STOP
with thebottomY
. TheeventQueue
is a priority queue, where the priority is based on the three values that define an event (evaluated in the order shown):y
: lowery
values have priority.type
: EVENT_STOP has priority over EVENT_START.rectID
: lowerrectID
values have priority.
- Search for the end of a region while:
- storing the events into a
regionQueue
. TheregionQueue
is a simple FIFO, which allows the events to be processed a second time, after the extent of the region has been determined. - keeping track of the
maxOverlap
(which is limited by a function parameter). ThemaxOverlap
determines the width of all rectangles within the region.
- storing the events into a
- Drain the
regionQueue
while computing the X values for each rectangle in the region. This part of the algorithm employs an array calledusedColumns
. Each entry in that array is either-1
(indicates that the column is not in use) or arectID
(indicates which rectangle is using the column). When anEVENT_START
is popped from theregionQueue
, a column is assigned to the rectangle. When anEVENT_STOP
is popped from theregionQueue
, the column is returned to the unused (-1) state.
The input to the algorithm is an array of rectangles. The topY
and bottomY
values of those rectangles must be filled by the caller. The leftX
and rightX
values must be initialized to -1. If the X values are still -1 when the algorithm finishes, the rectangle could not be assigned a location because the overlapLimit
was exceeded. All the other rectangles have a full set of coordinates, and are ready to be drawn.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install turbopascal
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page