久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

日歷事件的可視化.以最大寬度布局事件的算法

Visualization of calendar events. Algorithm to layout events with maximum width(日歷事件的可視化.以最大寬度布局事件的算法)
本文介紹了日歷事件的可視化.以最大寬度布局事件的算法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要你的算法幫助(它將在客戶端使用 javascript 開發,但沒關系,我最感興趣的是算法本身)布置日歷事件,以便每個事件框都有最大寬度.請看下圖:

I need your help with an algorithm (it will be developed on client side with javascript, but doesn't really matter, I'm mostly interested in the algorithm itself) laying out calendar events so that each event box has maximum width. Please see the following picture:

Y 軸是時間.因此,如果測試事件"在中午開始(例如)并且沒有更多的相交,它會占用整個 100% 的寬度.《每周回顧》與《翻滾的基督教青年會》和《安娜/阿米莉亞》有交集,但后兩者沒有交集,所以都占滿了 50%.Test3、Test4 和 Test5 都相交,因此每個的最大寬度為 33.3%.但是 Test7 是 66%,因為 Test3 是 33% 固定的(見上文),所以它占用了所有可用空間,即 66%.

Y axis is time. So if "Test event" starts at noon (for example) and nothing more intersects with it, it takes the whole 100% width. "Weekly review" intersects with "Tumbling YMCA" and "Anna/Amelia", but the latter two are not intersecting, so they all fill up 50%. Test3, Test4 and Test5 are all intersecting, so max width is 33.3% for each. But Test7 is 66% since Test3 is 33% fixed (see above) , so it takes all available space , which is 66%.

我需要一個算法來解決這個問題.

I need an algorithm how to lay this out.

提前致謝

推薦答案

  1. 想象一個只有左邊緣的無限網格.
  2. 每個事件都是一個單元格寬,高度和垂直位置根據開始和結束時間固定.
  3. 嘗試將每個事件放在盡可能靠左的列中,不要與該列中任何較早的事件相交.
  4. 然后,當放置每個連接的事件組時,它們的實際寬度將是該組使用的最大列數的 1/n.
  5. 您還可以展開最左側和最右側的事件以使用剩余空間.

/// Pick the left and right positions of each event, such that there are no overlap.
/// Step 3 in the algorithm.
void LayoutEvents(IEnumerable<Event> events)
{
    var columns = new List<List<Event>>();
    DateTime? lastEventEnding = null;
    foreach (var ev in events.OrderBy(ev => ev.Start).ThenBy(ev => ev.End))
    {
        if (ev.Start >= lastEventEnding)
        {
            PackEvents(columns);
            columns.Clear();
            lastEventEnding = null;
        }
        bool placed = false;
        foreach (var col in columns)
        {
            if (!col.Last().CollidesWith(ev))
            {
                col.Add(ev);
                placed = true;
                break;
            }
        }
        if (!placed)
        {
            columns.Add(new List<Event> { ev });
        }
        if (lastEventEnding == null || ev.End > lastEventEnding.Value)
        {
            lastEventEnding = ev.End;
        }
    }
    if (columns.Count > 0)
    {
        PackEvents(columns);
    }
}

/// Set the left and right positions for each event in the connected group.
/// Step 4 in the algorithm.
void PackEvents(List<List<Event>> columns)
{
    float numColumns = columns.Count;
    int iColumn = 0;
    foreach (var col in columns)
    {
        foreach (var ev in col)
        {
            int colSpan = ExpandEvent(ev, iColumn, columns);
            ev.Left = iColumn / numColumns;
            ev.Right = (iColumn + colSpan) / numColumns;
        }
        iColumn++;
    }
}

/// Checks how many columns the event can expand into, without colliding with
/// other events.
/// Step 5 in the algorithm.
int ExpandEvent(Event ev, int iColumn, List<List<Event>> columns)
{
    int colSpan = 1;
    foreach (var col in columns.Skip(iColumn + 1))
    {
        foreach (var ev1 in col)
        {
            if (ev1.CollidesWith(ev))
            {
                return colSpan;
            }
        }
        colSpan++;
    }
    return colSpan;
}

現在對事件進行排序,而不是假設它們已排序.

Now sorts the events, instead of assuming they is sorted.

Edit2:如果有足夠的空間,現在向右展開事件.

Now expands the events to the right, if there are enough space.

這篇關于日歷事件的可視化.以最大寬度布局事件的算法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 91新视频| 亚洲国产一区在线 | 国产在线aa | 亚洲最大福利网 | 青青久视频| 亚洲一区二区三区在线播放 | 国产精品日日摸夜夜添夜夜av | www.97zyz.com| 91精品国产综合久久福利软件 | 538在线精品 | 日韩精品成人在线 | 久久99深爱久久99精品 | 蜜桃视频在线观看免费视频网站www | 欧美在线高清 | 在线免费观看成人 | 999视频在线播放 | 国产91网站在线观看 | 久在线观看 | 鸡毛片 | 4h影视| 嫩呦国产一区二区三区av | 国产丝袜一区二区三区免费视频 | 久久久精彩视频 | 亚洲综合伊人 | 欧美久久久久久久 | 三极网站| 免费一级片 | 日韩欧美在线视频 | 精久久| 久久久久久国产精品久久 | 狠狠爱免费视频 | 日韩欧美一二三区 | 欧美日韩一区在线观看 | 亚洲国产二区 | 中文字幕av在线 | 91久久久精品国产一区二区蜜臀 | 亚洲免费人成在线视频观看 | 欧美九九九| av天天看 | 国产成人精品午夜 | 日日日操 |