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

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

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

問題描述

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

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

/// 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;
}

現(xiàn)在對事件進行排序,而不是假設(shè)它們已排序.

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

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

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

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

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

相關(guān)文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創(chuàng)建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設(shè)置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網(wǎng)站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內(nèi)容)
主站蜘蛛池模板: 日韩欧美在线视频 | 国产色婷婷精品综合在线手机播放 | 亚洲va欧美va人人爽午夜 | 91精品久久久久久久 | 精品日韩一区二区 | 日韩在线欧美 | 久久久久免费精品国产小说色大师 | 精品久久久久久 | 99re在线视频 | 麻豆精品国产免费 | 久久久久国产精品www | 国产美女在线播放 | 不卡的av电影 | 亚洲视频一区在线播放 | 国产一区二区精 | 91视频中文| 欧美成人高清 | 天色综合网 | 色悠悠久 | 国产精品美女一区二区 | 久久久久国产一区二区 | 人人擦人人 | 免费激情av | 亚洲黄色av | 国产精品福利视频 | 亚洲成人精选 | 精品日韩一区 | 久久丝袜 | 色综合中文 | 欧美日韩精品一区二区天天拍 | 国产一二三区电影 | 亚洲免费网站 | 羞羞的视频网站 | 欧美日韩黄 | 剑来高清在线观看 | wwwww在线观看 | 久久伊人青青草 | 亚洲天堂av网 | www.久久精品视频 | 国产黄色小视频在线观看 | 啪啪免费网站 |