- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在开发一种使用图形可视化宏基因组数据的工具,因此开发了 Java JUNG 图形可视化库。
当显示大约 1000 个节点时,我遇到了延迟,无论是通过移动相机还是拖动一些节点。
是否有任何黑客可以用来改善这种情况?我阅读了一些关于将窗口分成 block 的内容,并且只使用正在显示的面板 block ,但我无法理解这一点。
谢谢。
最佳答案
这个问题可能被认为过于宽泛,因为优化的自由度实在是太多了。如果不是重复的话,有些问题至少是相关的( Improve the rendering of a JUNG graph 、 JUNG cannot display large graphs? 或其他)。
但是,我会尝试在这里回答:
一般来说,使用 JUNG,您可以创建一个漂亮的图形,具有令人印象深刻的默认功能(交互)和许多功能,只需几行代码即可轻松完成。在这方面,JUNG 的主要目标并不是绘制具有 1000 个顶点的图形。相反,它旨在绘制具有数十个(或可能只有数百个)顶点和边的图形很好地。
(事实上,从理论和信息可视化的角度来看,绘制具有 >1000 个顶点的图几乎没有任何意义。您将无法直观地从这样的图中提取任何信息- 至少,不是没有过度缩放和平移)
当你想渲染一个有很多顶点和很多边的图形时,有一些选项可以提高性能。 (你没有说边的数量。在很多情况下,这些是最昂贵的东西!)。
根据我的经验,提高渲染性能最重要的事情是......
说真的,这真的很贵。在 JUNG 中,这可以通过
visualizationViewer.getRenderingHints().remove(
RenderingHints.KEY_ANTIALIASING)
除此之外,还有许多提高性能的选项,但当然,它们都取决于您要牺牲的视觉特征。下面的示例显示了一个包含 2500 个顶点和 5000 条边的图。默认情况下,它非常慢。 improvePerformance
方法包含几个有关如何加快可视化速度的选项。即使只禁用抗锯齿,性能在我的(相当慢的)机器上也是可以接受的。
根据评论进行编辑/扩展:
import java.awt.Dimension;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.geom.Point2D;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.apache.commons.collections15.Predicate;
import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.DirectedSparseGraph;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.util.Context;
import edu.uci.ics.jung.graph.util.Pair;
import edu.uci.ics.jung.visualization.Layer;
import edu.uci.ics.jung.visualization.RenderContext;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.decorators.EdgeShape;
import edu.uci.ics.jung.visualization.renderers.BasicEdgeRenderer;
import edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator;
public class JungPerformance
{
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
createAndShowGUI();
}
});
}
private static void createAndShowGUI()
{
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Graph<String, String> g = createGraph();
Dimension size = new Dimension(800,800);
VisualizationViewer<String, String> vv =
new VisualizationViewer<String, String>(
new FRLayout<String, String>(g, size));
DefaultModalGraphMouse<String, Double> graphMouse =
new DefaultModalGraphMouse<String, Double>();
vv.setGraphMouse(graphMouse);
improvePerformance(vv);
f.getContentPane().add(vv);
f.setSize(size);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
// This method summarizes several options for improving the painting
// performance. Enable or disable them depending on which visual features
// you want to sacrifice for the higher performance.
private static <V, E> void improvePerformance(
VisualizationViewer<V, E> vv)
{
// Probably the most important step for the pure rendering performance:
// Disable anti-aliasing
vv.getRenderingHints().remove(RenderingHints.KEY_ANTIALIASING);
// Skip vertices that are not inside the visible area.
doNotPaintInvisibleVertices(vv);
// May be helpful for performance in general, but not appropriate
// when there are multiple edges between a pair of nodes: Draw
// the edges not as curves, but as straight lines:
vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<V,E>());
// May be helpful for painting performance: Omit the arrow heads
// of directed edges
Predicate<Context<Graph<V, E>, E>> edgeArrowPredicate =
new Predicate<Context<Graph<V,E>,E>>()
{
@Override
public boolean evaluate(Context<Graph<V, E>, E> arg0)
{
return false;
}
};
vv.getRenderContext().setEdgeArrowPredicate(edgeArrowPredicate);
}
// Skip all vertices that are not in the visible area.
// NOTE: See notes at the end of this method!
private static <V, E> void doNotPaintInvisibleVertices(
VisualizationViewer<V, E> vv)
{
Predicate<Context<Graph<V, E>, V>> vertexIncludePredicate =
new Predicate<Context<Graph<V,E>,V>>()
{
Dimension size = new Dimension();
@Override
public boolean evaluate(Context<Graph<V, E>, V> c)
{
vv.getSize(size);
Point2D point = vv.getGraphLayout().transform(c.element);
Point2D transformed =
vv.getRenderContext().getMultiLayerTransformer()
.transform(point);
if (transformed.getX() < 0 || transformed.getX() > size.width)
{
return false;
}
if (transformed.getY() < 0 || transformed.getY() > size.height)
{
return false;
}
return true;
}
};
vv.getRenderContext().setVertexIncludePredicate(vertexIncludePredicate);
// NOTE: By default, edges will NOT be included in the visualization
// when ONE of their vertices is NOT included in the visualization.
// This may look a bit odd when zooming and panning over the graph.
// Calling the following method will cause the edges to be skipped
// ONLY when BOTH their vertices are NOT included in the visualization,
// which may look nicer and more intuitive
doPaintEdgesAtLeastOneVertexIsVisible(vv);
}
// See note at end of "doNotPaintInvisibleVertices"
private static <V, E> void doPaintEdgesAtLeastOneVertexIsVisible(
VisualizationViewer<V, E> vv)
{
vv.getRenderer().setEdgeRenderer(new BasicEdgeRenderer<V, E>()
{
@Override
public void paintEdge(RenderContext<V,E> rc, Layout<V, E> layout, E e)
{
GraphicsDecorator g2d = rc.getGraphicsContext();
Graph<V,E> graph = layout.getGraph();
if (!rc.getEdgeIncludePredicate().evaluate(
Context.<Graph<V,E>,E>getInstance(graph,e)))
return;
Pair<V> endpoints = graph.getEndpoints(e);
V v1 = endpoints.getFirst();
V v2 = endpoints.getSecond();
if (!rc.getVertexIncludePredicate().evaluate(
Context.<Graph<V,E>,V>getInstance(graph,v1)) &&
!rc.getVertexIncludePredicate().evaluate(
Context.<Graph<V,E>,V>getInstance(graph,v2)))
return;
Stroke new_stroke = rc.getEdgeStrokeTransformer().transform(e);
Stroke old_stroke = g2d.getStroke();
if (new_stroke != null)
g2d.setStroke(new_stroke);
drawSimpleEdge(rc, layout, e);
// restore paint and stroke
if (new_stroke != null)
g2d.setStroke(old_stroke);
}
});
}
public static Graph<String, String> createGraph()
{
Random random = new Random(0);
int numVertices = 2500;
int numEdges = 5000;
Graph<String, String> g = new DirectedSparseGraph<String, String>();
for (int i=0; i<numVertices; i++)
{
g.addVertex("v"+i);
}
for (int i=0; i<numEdges; i++)
{
int v0 = random.nextInt(numVertices);
int v1 = random.nextInt(numVertices);
g.addEdge("e"+i, "v"+v0, "v"+v1);
}
return g;
}
}
关于java - JUNG - 大图可视化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37740057/
我正在实现一个用于创建图形节点并使用 连接它们的接口(interface)郑 . 我想使用 edge 创建一些可以从一个现有节点移动到另一个节点的节点。两个节点之间作为它们的路径 (它将用于显示一些
我必须创建一个具有其自定义节点类型的图形,并且节点和连接是从 txt 文件中一一读取的。 文件格式是这样的:startNode 属性endNode。 每次阅读一行,我都会创建 2 个节点对象:star
目前,我正在做的是: WeakComponentClusterer wcc = new WeakComponentClusterer(); Collection> ccs = FilterUtils.
我使用 JUNG 来可视化我的图形/网络。 现在我想将图形(如 VisualizationViewer 中所见)保存在图像文件中。我使用 VisualizationViewer(扩展 JPanel)的
我可以做已选 顶点标签红色使用 vertexLabelRenderer 声明如下: DefaultVertexLabelRenderer vertexLabelRenderer=new Default
是否可以更改 JUNG 中的边缘形状?例如,我想让边缘以类似于进度条的方式逐渐改变它的颜色。边缘标签字体大小呢? 谢谢。 最佳答案 是的,有点......另外 - 我不确定你使用的是哪个版本的 JUN
我正在寻找 JUNG 来可视化有向图。 JUNG 2.0.1 下载附带 17 个不同的 jar 文件,其中一些似乎是示例和演示。 有谁知道如果你想使用JUNG,需要哪些真正的库? 最佳答案 没关系,它
我正在尝试对 JUNG 图包中的图进行顶点切割。下面的图片可以最好地解释这一点: 现在,我将从图中删除顶点“c1”: 正如您所看到的,顶点“c1”已从图中删除,但顶点“c2”和“c3”也已删除 当我剪
我在数据库中存储了邻接矩阵,我想使用 Java Jung 以交互方式编辑它们图形包。交互式图形编辑可以在示例GraphEditorDemo中看到。我已经完成了一种方法,该方法将从邻接矩阵中的信息创建图
我正在尝试从 Java Jung Graph 包构建以下内容:EdmondsKarp Object EdmondsKarpMaxFlow alg = new EdmondsKarpMaxFlow(g,
我有一个包含多个组件的未连接图。如何获取每个子图组件的 Graph 实例?例如,考虑以下图表: 我想要的是能够返回这些子图组件。子图组件的示例是具有顶点的图:{c0, c1, c2, c3} 我想要这
我想知道是否有可能/我将如何在 JUNG 中创建这样的东西: 最佳答案 取决于你所说的“类似的事情”是什么意思。如果您想要一个漂亮、整洁的固定图表,那么您最好手工绘制它。 如果您想要一个更通用的图解决
所以我正在使用 JUNG,这对我来说是新事物。我已经实现了一个简单的 GUI,它显示顶点和边,并且通过使用 Transformer 我可以更改形状等。但是我该如何沿着边缘制作图像动画呢? 如果边缘是直
首先,我是 JUNG 的新手。我试图使用 TreeLayout 在 JUNG 中可视化树,但我总是面临顶点标签重叠的问题。当节点和路径数量很多时更是如此。关于如何防止这种重叠有什么想法吗? 我知道顶点
我们用 jung 开发了一个小型图形编辑器,您可以在其中用鼠标绘制图形/网络。我们使用 VisualizationViewer 作为我们绘制的面板。 VisualizationViewer 保存它必须
我想可视化我的 Java 应用程序中的图形,为此我使用 JUNG。问题是我的图形包含大量节点和边,JUNG 提供的哪些布局可以给我最小的交叉边缘?以便图形看起来更好? 最佳答案 JUNG 布局本身并不
我目前正在开发一种使用图形可视化宏基因组数据的工具,因此开发了 Java JUNG 图形可视化库。 当显示大约 1000 个节点时,我遇到了延迟,无论是通过移动相机还是拖动一些节点。 是否有任何黑客可
您好!我的程序有问题。 我在 java 中使用 JUNG 库,当我编译程序时,出现以下两个错误: Error:(43, 61) java: incompatible types: org.apache
我创建了一个 java 程序,该程序从 1 个顶点开始,从那里开始每个周期添加 1 个顶点和 2 条边。它使用静态布局 Layout staticLayout = new StaticLayout(g
我有一组子图,我需要在从中提取它们的图上匹配它们。我还需要计算每个子图在此类图中出现的次数(我需要存储所有可能的匹配项)。考虑到子图和图的边标签必须完美匹配,但是顶点标签不需要相互匹配。我使用 JUN
我是一名优秀的程序员,十分优秀!