【问题标题】:How change color of dotted line in mxgraph如何更改mxgraph中虚线的颜色
【发布时间】:2021-08-06 19:05:33
【问题描述】:

当我们拖动一个顶点时,我想将虚线的颜色从黑色变为红色

问题:我想在拖动时将虚线颜色从黑色变为红色

这是它在拖动时的显示方式

我试图在 mxConstants 中找到拖动时的虚线颜色,但没有找到

function main(container)
        {
            // Checks if the browser is supported
            if (!mxClient.isBrowserSupported())
            {
                // Displays an error message if the browser is not supported.
                mxUtils.error('Browser is not supported!', 200, false);
            }
            else
            {
                // Disables the built-in context menu
                mxEvent.disableContextMenu(container);
                
                // Creates the graph inside the given container
                var graph = new mxGraph(container);

                // Enables rubberband selection
                new mxRubberband(graph);
                
                // Gets the default parent for inserting new cells. This
                // is normally the first child of the root (ie. layer 0).
                var parent = graph.getDefaultParent();
                                
                // Adds cells to the model in a single step
                graph.getModel().beginUpdate();
                try
                {
                    var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);

                }
                finally
                {
                    // Updates the display
                    graph.getModel().endUpdate();
                }
            }
        };
<html>

<head>
    <title>Toolbar example for mxGraph</title>

    <script type="text/javascript">
        mxBasePath = 'https://jgraph.github.io/mxgraph/javascript/src';
    </script>
    <script src="https://jgraph.github.io/mxgraph/javascript/src/js/mxClient.js"></script>
    <script src="./app.js"></script>
</head>

<body onload="main(document.getElementById('graphContainer'))">


    <div id="graphContainer">

    </div>
</body>

</html>

请帮助我提前谢谢!!!

【问题讨论】:

  • 您正在使用insertVertex,并且很难更改拖动对象的预览。如果你使用mxUtils.makeDraggable,我有你想要的解决方案
  • 在我使用mxUtils.makeDraggable的实际项目中,请发布您的解决方案,我会接受您的回答。但请记住,解决方案必须在画布上工作
  • 在画布外我也有解决方案。在画布上,无论我使用insertVertex 还是其他任何东西都没有任何区别

标签: javascript jquery mxgraph


【解决方案1】:

基于this,您可以通过以下代码做到这一点:

mxGraphHandler.prototype.previewColor = 'red';

工作sn-p:

function main(container)
        {
      mxGraphHandler.prototype.previewColor = 'red';
    
            // Checks if the browser is supported
            if (!mxClient.isBrowserSupported())
            {
                // Displays an error message if the browser is not supported.
                mxUtils.error('Browser is not supported!', 200, false);
            }
            else
            {
                // Disables the built-in context menu
                mxEvent.disableContextMenu(container);
                
                // Creates the graph inside the given container
                var graph = new mxGraph(container);

                // Enables rubberband selection
                new mxRubberband(graph);
                
                // Gets the default parent for inserting new cells. This
                // is normally the first child of the root (ie. layer 0).
                var parent = graph.getDefaultParent();
                                
                // Adds cells to the model in a single step
                graph.getModel().beginUpdate();
                try
                {
                    var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);

                }
                finally
                {
                    // Updates the display
                    graph.getModel().endUpdate();
                }
            }
        };
<html>

<head>
    <title>Toolbar example for mxGraph</title>

    <script type="text/javascript">
        mxBasePath = 'https://jgraph.github.io/mxgraph/javascript/src';
    </script>
    <script src="https://jgraph.github.io/mxgraph/javascript/src/js/mxClient.js"></script>
    <script src="./app.js"></script>
</head>

<body onload="main(document.getElementById('graphContainer'))">


    <div id="graphContainer">

    </div>
</body>

</html>

【讨论】:

  • 在画布上仍然是黑色的。请检查一次。它在画布上应该是红色的
  • @Learner 不,它是红色的。检查 sn-p 或给我看你正在看的照片
  • 在黑色罐子上,如果你拖动它会变成黑色
  • 你的意思是在我的 sn-p 中?什么时候把它拖到黑色画布上?
  • @Learner 对我来说它是红色的,我现在显示一张图片
猜你喜欢
  • 2010-12-25
  • 2023-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-20
  • 1970-01-01
  • 2019-10-14
  • 2018-10-01
相关资源
最近更新 更多