8.mxGraph 命名空间与 Hello World 示例实践.md
moboyou 2025-07-21 17:26 17 浏览
2.2.2 General JavaScript Development 常规 JavaScript 开发
2.2.2.1 JavaScript Obfuscation/ JavaScript 混淆
[翻译]
默认情况下,当您将 JavaScript 交付到浏览器客户端时,您将整个 JavaScript 源代码交付给客户端。然后,该 JavaScript 在浏览器中被解释和运行。在客户端运行时,无法对 JavaScript 进行任何程度的加密,因为 JavaScript 源代码必须被 JavaScript 解释器理解,而解释型语言没有二进制中间形式。
[原文]
By default, when you deliver JavaScript to a browser client, you deliver the entire source to that JavaScript. That JavaScript is then interpreted and run on the browser. It is not possible to encrypt the JavaScript to any extent on the client at the point it is run, since the JavaScript source must be understood by the JavaScript interpretor and interpreted languages do not have a binary intermediate form.
- deliver /d'lvr/ 交付
- interpreted /n'trprtd/ 解释的
- encrypt /n'krpt/ 加密
- interpretor /n'trprtr/ 解释器
- binary /'banri/ 二进制的
[翻译]
可以在传输中加密 JavaScript,并在客户端解密后运行,但客户端仍然可以在解密后访问源代码。
[原文]
It would be possible to encrypt the JavaScript in transmission and have it decrypted and run on the client, but the client would still be able to access the source after decryption.
- transmission /traens'mn/ 传输
- decrypted /di'krptd/ 解密的
- access /'aekses/ 访问
[翻译]
我们不进行混淆,因为方法名称构成了公共 API,并且输入/输出需要在通信两端理解混淆。
[原文]
We do not obfuscate because the method names form a public API and I/O would need to understand the obfuscation at both communication ends.
- obfuscate /'ɑbfsket/ 混淆
- public /'pblk/ 公共的
- API /e pi 'a/ 应用程序编程接口
- communication /kmjun'ken/ 通信
2.2.2.2 Namespaces 命名空间
[翻译]
标准 JavaScript 中不存在命名空间的概念,因此在创建新类名称时要格外小心。在 mxGraph 中,所有类都以“mx-”前缀开头,以避免意外冲突或覆盖原型。
[原文]
The concept of namespaces does not exist in standised JavaScript, so take great care when creating new class names. In mxGraph, all of the classes begin with the prefix “mx-”, to avoid clashes or overriding prototypes unintentionally.
- namespaces /'nemspesz/ 命名空间
- standardised /'staendrdazd/ 标准化的
- prefix /'prifks/ 前缀
- clashes /klaez/ 冲突
- overriding /ovr'rad/ 覆盖
2.3 Hello World! 你好,世界!
[翻译]
mxGraph 的“你好,世界!”是一个简单的客户端示例,显示两个带标签“Hello”和“World!”的连接顶点。该示例展示了以下内容:
- 创建一个链接 mxGraph 客户端 JavaScript 的 HTML 页面,
- 创建一个放置 mxGraph 的容器,
- 向该图添加所需的单元。
[原文]
Hello World in mxGraph consists of a simple client-side example that displays two connected vertices with the labels “Hello” and “World!”. The example demonstrates the following things:
- Creating an HTML page that links the mxGraph client JavaScript,
- Creating a container to place the mxGraph into,
- Adds the required cells to that graph.
- consists /kn'ssts/ 包含
- client-side /'klant sad/ 客户端
- vertices /'vrtsiz/ 顶点
- labels /'leblz/ 标签
- container /kn'tenr/ 容器
[翻译]
示例的源代码 helloworld.html 可以在 mxGraph 的评估版和完整版的示例目录中找到。HTML 源代码包含两个主要部分:头部和主体。这些部分包含以下主要元素,您可以将其视为构建基本 mxGraph 应用程序的模板:
[原文]
The source code for the example, helloworld.html, can be found below and in the examples directory of both the evaluation and full versions of mxGraph. The HTML source contains two main sections, the head and the body. These contain the following main elements that you can consider a template for building a basic mxGraph application:
- source /srs/ 源代码
- evaluation /vaelju'en/ 评估
- sections /'seknz/ 部分
- head /hed/ 头部
- template /'templt/ 模板
[翻译]
- mxBasePath:这是一个 JavaScript 变量,定义了 css、images、resources 和 js 目录所在的目录。它是 JavaScript 代码,需要放在 script 标签内。此变量必须在加载 mxClient.js 之前定义,且不应以斜杠结尾。
- mxClient.js:这是 mxGraph 库的路径。如果 HTML 文件在本地执行,路径可能是本地计算机或公共互联网路径。如果 HTML 页面从 Web 服务器下载,路径通常是公共互联网路径。
- 容器创建:在代码底部,在 body 元素中,定义了网页加载时调用的函数(onload 的值)。它传入一个 div 容器作为参数,该容器定义在下方。此 div 是 mxGraph 组件将放置的容器。在本例中,应用了网格背景,常用于图表应用程序。在创建容器时,除背景和容器宽度高度外,未描述图的其他视觉部分。 注意:如果您不希望出现滚动条,应始终使用 overflow:hidden 样式。
[原文]
- mxBasePath: This is a JavaScript variable that defines the directory within which the css, images, resources and js directories are expected to be found. It is JavaScript code and needs to be placed with in a script tag. This must come before the line loading mxClient.js and should not have a trailing slash.
- mxClient.js: This is the path to mxGraph library. If the HTML file is executed locally, the path might be local to the computer or a public Internet path. If the html page were downloaded from a web server, the path would generally be a public Internet path.
- Creation of the container: At the bottom of the code, in the body element, the function that is called on loading the web page is defined (the value of onload). It passes in a div container as a parameter, that is defined underneath. This div is the container the mxGraph component will be placed within. In this example a grid background is applied, as commonly used in diagramming applications. No other part of the graph visuals are described at container creation, other than the background and the container width and height.
Note that the overflow:hidden style should always be used if you want no scrollbars to appear.
- variable /'vaeribl/ 变量
- directory /d'rektri/ 目录
- script /skrpt/ 脚本
- trailing /'trel/ 末尾的
- scrollbars /'skrolbɑrz/ 滚动条
[翻译]
- 入口函数:文件的主要代码是页面加载时执行的入口方法,在本例中是 JavaScript 代码,必须位于 JavaScript 脚本元素内。任何 mxGraph 应用程序的前几行应检查浏览器是否受支持,如果不支持则适当退出。如果浏览器受支持,则在 div 容器中创建 mxGraph,并在 begin/end 更新调用之间向图添加三个单元。
[原文]
- The entry function: The main code of the file is the entry method executed on page load in this case. This is JavaScript code and must be within a JavaScript script element. The first lines of any mxGraph application should be to check the browser is supported and exit appropriately if not. If the browser is supported, a mxGraph is created within the div container and three cells are added to the graph between the begin/end update calls.
- entry /'entri/ 入口
- executed /'ekskjutd/ 执行
- appropriately /'propritli/ 适当地
- supported /s'prtd/ 支持的
- cells /selz/ 单元
mxGraph 你好世界示例 / The mxGraph HelloWorld example
<html>
<head>
<title>Hello, World! example for mxGraph</title>
<!-- Sets the basepath for the library if not in same directory -->
<script type="text/javascript">
mxBasePath = '../src';
</script>
<!-- Loads and initializes the library -->
<script type="text/javascript" src="../src/js/mxClient.js"></script>
<!-- Example code -->
<script type="text/javascript">
// Program starts here. Creates a sample graph in the
// DOM node with the specified ID. This function is invoked
// from the onLoad event handler of the document (see below).
function main(container)
{
// Checks if the browser is supported
if (!mxClient.isBrowserSupported())
{
mxUtils.error('Browser is not supported!', 200, false);
}
else
{
// 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);
var v2 = graph.insertVertex(parent, null,
'World!', 200, 150, 80, 30);
var e1 = graph.insertEdge(parent, null, '', v1, v2);
}
finally
{
// Updates the display
graph.getModel().endUpdate();
}
}
};
</script>
</head>
<!-- Page passes the container for the graph to the program -->
<body onload="main(document.getElementById('graphContainer'))">
<!-- Creates a container for the graph with a grid wallpaper -->
<div id="graphContainer"
style="overflow:hidden;width:321px;height:241px;background:url('editors/images/grid.gif')">
</div>
</body>
</html>
[翻译]
本练习中需要注意的重要概念包括:
- mxClient.js 是一个将 mxGraph 所有 JavaScript 源代码合并的 JavaScript 文件。从 Web 服务器下载时,将所有 JavaScript 作为一个文件获取比多个单独文件快得多,因为每个文件都需要请求/确认的开销。通常速度提升至少为 2 倍,尽管这取决于服务器与一个客户端保持并行套接字的能力。
- JavaScript 代码及其依赖项都放置在 head 元素中。
- Internet Explorer 默认启用了安全选项,当尝试从本地文件系统运行 JavaScript 时会提示用户。此选项可在选项菜单中禁用,但请注意,从本地文件系统运行不是 mxGraph 的部署场景,仅在开发期间可能发生。
- 您的应用程序可以编写并链接到应用程序中,可以在 HTML 文件内,也可以在单独的 JavaScript 源代码中,通过类似于示例中 mxClient.js 文件的方式链接到 HTML 中。
[原文]
Important concepts to note in this exercise are:
- mxClient.js is a JavaScript file combining all of the JavaScript source code of mxGraph. When downloading from a web server, obtaining all the JavaScript as one file is much faster than as lots of separate files, due to the overhead of the requests/acknowledgements required for each file. The speed increase is usually at least x2, although it varies with the capacity of the server to have parallel sockets open with one client.
- The JavaScript code and its dependencies are all placed within the head element.
- Internet Explorer has, by default, security options enabled that cause a user prompt when attempting to run JavaScript from the local file system. This can be disabled in the options menu, but note that running from the local file system is not a deployment scenario of mxGraph, this would only happen during development.
- Your application can be written and linked into the application either within the HTML file, or in separate JavaScript source code that is linked into the html in the way the mxClient.js file is in the example.
- combining /km'ban/ 合并
- overhead /'ovrhed/ 开销
- acknowledgements /k'nɑldmnts/ 确认
- sockets /'sɑkts/ 套接字
- prompt /prɑmpt/ 提示
相关推荐
- Excel技巧:SHEETSNA函数一键提取所有工作表名称批量生产目录
-
首先介绍一下此函数:SHEETSNAME函数用于获取工作表的名称,有三个可选参数。语法:=SHEETSNAME([参照区域],[结果方向],[工作表范围])(参照区域,可选。给出参照,只返回参照单元格...
- Excel HOUR函数:“小时”提取器_excel+hour函数提取器怎么用
-
一、函数概述HOUR函数是Excel中用于提取时间值小时部分的日期时间函数,返回0(12:00AM)到23(11:00PM)之间的整数。该函数在时间数据分析、考勤统计、日程安排等场景中应用广泛。语...
- Filter+Search信息管理不再难|多条件|模糊查找|Excel函数应用
-
原创版权所有介绍一个信息管理系统,要求可以实现:多条件、模糊查找,手动输入的内容能去空格。先看效果,如下图动画演示这样的一个效果要怎样实现呢?本文所用函数有Filter和Search。先用filter...
- FILTER函数介绍及经典用法12:FILTER+切片器的应用
-
EXCEL函数技巧:FILTER经典用法12。FILTER+切片器制作筛选按钮。FILTER的函数的经典用法12是用FILTER的函数和切片器制作一个筛选按钮。像左边的原始数据,右边想要制作一...
- office办公应用网站推荐_office办公软件大全
-
以下是针对Office办公应用(Word/Excel/PPT等)的免费学习网站推荐,涵盖官方教程、综合平台及垂直领域资源,适合不同学习需求:一、官方权威资源1.微软Office官方培训...
- WPS/Excel职场办公最常用的60个函数大全(含卡片),效率翻倍!
-
办公最常用的60个函数大全:从入门到精通,效率翻倍!在职场中,WPS/Excel几乎是每个人都离不开的工具,而函数则是其灵魂。掌握常用的函数,不仅能大幅提升工作效率,还能让你在数据处理、报表分析、自动...
- 收藏|查找神器Xlookup全集|一篇就够|Excel函数|图解教程
-
原创版权所有全程图解,方便阅读,内容比较多,请先收藏!Xlookup是Vlookup的升级函数,解决了Vlookup的所有缺点,可以完全取代Vlookup,学完本文后你将可以应对所有的查找难题,内容...
- 批量查询快递总耗时?用Excel这个公式,自动计算揽收到签收天数
-
批量查询快递总耗时?用Excel这个公式,自动计算揽收到签收天数在电商运营、物流对账等工作中,经常需要统计快递“揽收到签收”的耗时——比如判断某快递公司是否符合“3天内送达”的服务承...
- Excel函数公式教程(490个实例详解)
-
Excel函数公式教程(490个实例详解)管理层的财务人员为什么那么厉害?就是因为他们精通excel技能!财务人员在日常工作中,经常会用到Excel财务函数公式,比如财务报表分析、工资核算、库存管理等...
- Excel(WPS表格)Tocol函数应用技巧案例解读,建议收藏备用!
-
工作中,经常需要从多个单元格区域中提取唯一值,如体育赛事报名信息中提取唯一的参赛者信息等,此时如果复制粘贴然后去重,效率就会很低。如果能合理利用Tocol函数,将会极大地提高工作效率。一、功能及语法结...
- Excel中的SCAN函数公式,把计算过程理清,你就会了
-
Excel新版本里面,除了出现非常好用的xlookup,Filter公式之外,还更新一批自定义函数,可以像写代码一样写公式其中SCAN函数公式,也非常强大,它是一个循环函数,今天来了解这个函数公式的计...
- Excel(WPS表格)中多列去重就用Tocol+Unique组合函数,简单高效
-
在数据的分析和处理中,“去重”一直是绕不开的话题,如果单列去重,可以使用Unique函数完成,如果多列去重,如下图:从数据信息中可以看到,每位参赛者参加了多项运动,如果想知道去重后的参赛者有多少人,该...
- Excel(WPS表格)函数Groupby,聚合统计,快速提高效率!
-
在前期的内容中,我们讲了很多的统计函数,如Sum系列、Average系列、Count系列、Rank系列等等……但如果用一个函数实现类似数据透视表的功能,就必须用Groupby函数,按指定字段进行聚合汇...
- Excel新版本,IFS函数公式,太强大了!
-
我们举一个工作实例,现在需要计算业务员的奖励数据,右边是公司的奖励标准:在新版本的函数公式出来之前,我们需要使用IF函数公式来解决1、IF函数公式IF函数公式由三个参数组成,IF(判断条件,对的时候返...
- Excel不用函数公式数据透视表,1秒完成多列项目汇总统计
-
如何将这里的多组数据进行汇总统计?每组数据当中一列是不同菜品,另一列就是该菜品的销售数量。如何进行汇总统计得到所有的菜品销售数量的求和、技术、平均、最大、最小值等数据?不用函数公式和数据透视表,一秒就...
- 一周热门
- 最近发表
-
- Excel技巧:SHEETSNA函数一键提取所有工作表名称批量生产目录
- Excel HOUR函数:“小时”提取器_excel+hour函数提取器怎么用
- Filter+Search信息管理不再难|多条件|模糊查找|Excel函数应用
- FILTER函数介绍及经典用法12:FILTER+切片器的应用
- office办公应用网站推荐_office办公软件大全
- WPS/Excel职场办公最常用的60个函数大全(含卡片),效率翻倍!
- 收藏|查找神器Xlookup全集|一篇就够|Excel函数|图解教程
- 批量查询快递总耗时?用Excel这个公式,自动计算揽收到签收天数
- Excel函数公式教程(490个实例详解)
- Excel(WPS表格)Tocol函数应用技巧案例解读,建议收藏备用!
- 标签列表
-
- 外键约束 oracle (36)
- oracle的row number (32)
- 唯一索引 oracle (34)
- oracle in 表变量 (28)
- oracle导出dmp导出 (28)
- 多线程的创建方式 (29)
- 多线程 python (30)
- java多线程并发处理 (32)
- 宏程序代码一览表 (35)
- c++需要学多久 (25)
- css class选择器用法 (25)
- css样式引入 (30)
- css教程文字移动 (33)
- php简单源码 (36)
- php个人中心源码 (25)
- php小说爬取源码 (23)
- 云电脑app源码 (22)
- html画折线图 (24)
- docker好玩的应用 (28)
- linux有没有pe工具 (34)
- 可以上传视频的网站源码 (25)
- 随机函数如何生成小数点数字 (31)
- 随机函数excel公式总和不变30个数据随机 (33)
- 所有excel函数公式大全讲解 (22)
- 有动图演示excel函数公式大全讲解 (32)
