Feature Example: Choosing which way a queue builds
Warning
This example has not yet been updated to reflect all of the new features and recommendations from vidigi 2.0.0, which have further simplified the process of adding vidigi to your model and accessing and modifying your animation.
For now, all of the code below will still work, but check out the getting started page for a full guide to the recommended way to use vidigi 2.0.0.
In every vidigi animation so far, a queue has built up from right to left: the x you give an event in event_position_df is the front of the queue (the bottom-right corner), and each waiting entity is drawn one gap_between_entities further to the left.
That is a fine default, but it fights with a lot of entity icons. The person-walking emoji, the ambulance, the car - plenty of them face right, so a queue that grows leftwards has everyone walking away from the thing they are waiting for. Putting the front of the queue at the bottom-left, with the tail extending right, lines the icons up with the direction of travel.
queue_direction controls this. It takes "left" (the default, unchanged behaviour) or "right", and it is accepted by animate_activity_log, generate_animation and generate_animation_df. For finer control, an individual EventPosition can carry its own direction, which overrides the animation-wide setting for just that stage.
Model setup
The single-step clinic model from example_1_simplest_case - patients arrive, queue for a treatment cubicle, are treated, and leave. Arrivals comfortably outpace the four cubicles, so a long queue builds - exactly what we want to look at.
Nothing new here - queue_direction is not passed, so it takes its default of "left". The x values in event_position_df are the front of each queue and the rightmost cubicle; everything stacks up leftwards from there.
Flipping the whole animation: queue_direction="right"
The same call with one extra argument. Now each x is the bottom-left corner: the front of every queue sits there and the line extends to the right, wrapped rows included. The resource cubicles lay out rightwards too, so a patient in treatment stays on the same side they queued on, and the stage labels move to the left of each anchor so the queue no longer runs over them.
One stage at a time: the per-event direction column
queue_direction sets the default for the animation; any EventPosition with its own direction overrides it. Here the global setting is left at "left", but the treatment queue and the cubicles are told to build right - handy when a background image or floor plan means different parts of the pathway face different ways.
If you use the three-step pipeline (reshape_for_animations → generate_animation_df → generate_animation) rather than animate_activity_log, pass queue_direction to bothgenerate_animation_df and generate_animation.
A right-building queue can run past the right edge of the plot; vidigi grows the figure margin on that side automatically, the same way it already does on the left.