我希望你们中的许多人都听说过 Flipboard。这款 iPad 应用程序最令人惊奇的事情之一是它的内容布局方式会根据 iPad 和 iPad 的方向动态变化。基于流媒体内容。
因此,给定一组文章,人们将使用什么算法来获得最佳布局。最佳的定义可能是 - 最有效的布局(如电路设计)或最美观的布局。
有人知道这样的算法吗?或者解决此类问题的基本方法?这属于“计算几何”吗?
I hope many of you would have heard about Flipboard. One of the most amazing things about this iPad app is the way it lays out the content which changes dynamically based on orientation of iPad & based on the streaming content.
So given a set of articles what algorithms would one use to have the best layout. The definition of best could be - most efficient layout (as in circuit design) or the most aesthetically looking layout.
Anybody know of any such algorithms? or the basic approach to such problems? Does this fall under "computational geometry" ?
发布评论
评论(7)
基于 贾森·摩尔 (Jason Moore) 在 href="https://stackoverflow.com/questions/6265995/flipboards-layout-algorithm/6393263#6393263">他的答案,我想说有十个左右的预定义块大小可以放入其中被放置。内容放置在多大的盒子中取决于各种不同的参数——很多人转发或喜欢的东西可能被认为具有更高的优先级,因此会得到更大的盒子,带有图片、视频或大量文本的项目也可能被优先考虑。这些盒子(最好是经过深思熟虑的尺寸)然后以最佳方式包装在页面上(尽管这不是一个简单的问题,甚至 Flipbook 似乎也失败了,正如 Facebook 流的第二次渲染来自之前链接的博客文章)。
从渲染的 Facebook feed 的外观来看,Flipbook(至少)具有以下预定义的框尺寸(宽度和高度以全宽/高度的百分比给出):
其中一些具有相当明显的分组模式(1/9 引号始终是例如,一次堆叠三个以形成与 1/3 钞票大小相同的块,而其他则可以更自由地包装。对 渲染的 Twitter feed 显示的类似分析一些额外的盒子。
总结
因此,总的来说,该算法似乎相当简单。从几个预定义的(合理选择的)盒子尺寸开始。当呈现新的提要时,执行以下操作:
这里的重点应该放在步骤 1 上,以及制作预定义的框。
澄清一下:我在这里讨论的预定义框大小是针对纵向方向定义的。对于横向,将使用一组不同的框尺寸,如问题中的图片所示。
Based on the screenshots and theories in the blog post linked to by Jason Moore in his answer, I would say that there are ten-or-so predefined block sizes into which content is placed. What size box a piece of content is placed in is based on various different parameters — something that many people retweet or like may be considered higher priority and therefore get a larger box, and items with pictures, videos or lots of text may also be prioritized. These boxes (preferably with well thought-out sizes) are then packed optimally on the pages (though this is not a simple problem, and even Flipbook seems to fail as evidenced by the strange whitespace in the second render of the Facebook stream from the previously linked blog post).
From the looks of the rendered Facebook feed, Flipbook has (at least) the following predefined box sizes (width and height given as percentage of full width/height):
Some of these have fairly obvious grouping patterns (1/9 quotes are always stacked three at a time to form a block the same size of a 1/3 note, for example), while others can be more freely packed. Similar analysis of the rendered Twitter feed show some additional boxes.
Summary
So, in summary the algorithm appears to be fairly simple. Start with a couple of predefined (sensibly selected) box sizes. When new feeds are rendered, do the following:
Emphasis here should be put on step 1, as well as on crafting the predefined boxes.
To clarify: The predefined box sizes I talk about here are defined for the portrait orientation. For landscape, a different set of box sizes would be used as evidenced by the picture in the question.
为了理解 Flipboard 的布局安排,我做了很多尝试。这是我想出的 https://github.com/reefaq/FlipView
没有复杂的其背后的算法也不是复杂的代码,只是一个所有人都能理解的简单代码。
实现了一些功能,如
希望它对你有帮助:)
I had tried a lot with understanding the layout arrangement of flipboard. Here is what i had come up with https://github.com/reefaq/FlipView
There is no complex algorithm behind it nor a complex code, just a simple code which can be understandable for all.
Implemented some of the features like
Hope it helps u :)
声音与Knapsack 算法相关。另请参阅维基百科网站打包问题。
Sounds related to the Knapsack algorithm. See also the Wikipedia site packing problem.
由于声誉较低,我无法发布图像:-) 但这里有 关于布局方法的一些注释作为博客文章。
I was unable to post images because of low reputation karma :-) but here are some notes as a blog post about the layout method.
看看这个 JavaScript 库。
看起来很有趣
http://masonry.desandro.com
(0,1) - 背包方法。
Have a look at this JavaScript Library.
Seems interesting
http://masonry.desandro.com
The (0,1) - knapsack approach.
我想贪心算法会很好地工作。这仅取决于您尝试加载数据的顺序。如果你给每个内容部分一个权重或“值”,并给它大量的选择,贪心算法可以找到具有最高值的最佳布局。
贪心算法
I imagine that a greedy algorithm would work just fine. It just depends on the order in which you try to load the data. if you give each section of content a weight or "value", and give it a large amount to pick from, the greedy algorithm can find the optimal layout with the highest value.
Greedy Algorithm
我的直觉是流媒体内容被分为不同的类别(引用、文章、照片等)。根据每个类别中有多少项目以及这些类别中每个项目的排名,软件可能会将它们放入一些预制的布局中。
以下博客文章展示了大量试图破译 Flipboard 动态布局的深入分析:
复制 Flipboard 第三部分 – Flipboard 如何布局内容
My hunch is that the streaming content is sorted into different categories (quotes, articles, photos, etc.). Based upon how many items are in each category and the ranking of each of the items in those categories, the software probably places them into some pre-made layouts.
The following blog entry shows a lot of in depth analysis trying to decipher the Flipboard's dynamic layouts:
Replicating Flipboard Part III – How Flipboard lays out content