Commit 83502dce7bdd98d64bf1f8a3042386efd072b4a5

Authored by xp.Huang
2 parents 427cd6da e2460747

Merge branch 'ww' into 'main'

feat: implement chart component render && fix some problem

See merge request huang/thingskit-drawio!26

Too many changes to show.

To preserve performance only 9 of 10 files are displayed.

  1 +<svg viewBox="0 0 79 86" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><linearGradient id="linearGradient-1-1" x1="38.8503086%" y1="0%" x2="61.1496914%" y2="100%"><stop stop-color="#FCFCFD" offset="0%"></stop><stop stop-color="#EEEFF3" offset="100%"></stop></linearGradient><linearGradient id="linearGradient-2-1" x1="0%" y1="9.5%" x2="100%" y2="90.5%"><stop stop-color="#FCFCFD" offset="0%"></stop><stop stop-color="#E9EBEF" offset="100%"></stop></linearGradient><rect id="path-3-1" x="0" y="0" width="17" height="36"></rect></defs><g id="Illustrations" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="B-type" transform="translate(-1268.000000, -535.000000)"><g id="Group-2" transform="translate(1268.000000, 535.000000)"><path id="Oval-Copy-2" d="M39.5,86 C61.3152476,86 79,83.9106622 79,81.3333333 C79,78.7560045 57.3152476,78 35.5,78 C13.6847524,78 0,78.7560045 0,81.3333333 C0,83.9106622 17.6847524,86 39.5,86 Z" fill="#F7F8FC"></path><polygon id="Rectangle-Copy-14" fill="#E5E7E9" transform="translate(27.500000, 51.500000) scale(1, -1) translate(-27.500000, -51.500000) " points="13 58 53 58 42 45 2 45"></polygon><g id="Group-Copy" transform="translate(34.500000, 31.500000) scale(-1, 1) rotate(-25.000000) translate(-34.500000, -31.500000) translate(7.000000, 10.000000)"><polygon id="Rectangle-Copy-10" fill="#E5E7E9" transform="translate(11.500000, 5.000000) scale(1, -1) translate(-11.500000, -5.000000) " points="2.84078316e-14 3 18 3 23 7 5 7"></polygon><polygon id="Rectangle-Copy-11" fill="#EDEEF2" points="-3.69149156e-15 7 38 7 38 43 -3.69149156e-15 43"></polygon><rect id="Rectangle-Copy-12" fill="url(#linearGradient-1-1)" transform="translate(46.500000, 25.000000) scale(-1, 1) translate(-46.500000, -25.000000) " x="38" y="7" width="17" height="36"></rect><polygon id="Rectangle-Copy-13" fill="#F8F9FB" transform="translate(39.500000, 3.500000) scale(-1, 1) translate(-39.500000, -3.500000) " points="24 7 41 7 55 -3.63806207e-12 38 -3.63806207e-12"></polygon></g><rect id="Rectangle-Copy-15" fill="url(#linearGradient-2-1)" x="13" y="45" width="40" height="36"></rect><g id="Rectangle-Copy-17" transform="translate(53.000000, 45.000000)"><mask id="mask-4-1" fill="white"><use xlink:href="#path-3-1"></use></mask><use id="Mask" fill="#E0E3E9" transform="translate(8.500000, 18.000000) scale(-1, 1) translate(-8.500000, -18.000000) " xlink:href="#path-3-1"></use><polygon id="Rectangle-Copy" fill="#D5D7DE" mask="url(#mask-4-1)" transform="translate(12.000000, 9.000000) scale(-1, 1) translate(-12.000000, -9.000000) " points="7 0 24 0 20 18 -1.70530257e-13 16"></polygon></g><polygon id="Rectangle-Copy-18" fill="#F8F9FB" transform="translate(66.000000, 51.500000) scale(-1, 1) translate(-66.000000, -51.500000) " points="62 45 79 45 70 58 53 58"></polygon></g></g></g></svg>
@@ -5030,6 +5030,9 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) { @@ -5030,6 +5030,9 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) {
5030 lastModifiedDate: new Date() 5030 lastModifiedDate: new Date()
5031 }; 5031 };
5032 this.openFileHandle(Editor.defaultContent, Editor.configurationName, file, false, fileHandle); 5032 this.openFileHandle(Editor.defaultContent, Editor.configurationName, file, false, fileHandle);
  5033 + // TODO thingsKit 初始化图表
  5034 + const graph = this.editor.graph
  5035 + Sidebar.prototype.initChartInstance(graph)
5033 //加载数据结束 5036 //加载数据结束
5034 5037
5035 // if (id == null || id.length == 0) 5038 // if (id == null || id.length == 0)
@@ -8,10 +8,9 @@ @@ -8,10 +8,9 @@
8 * @param {number} x X-coordinate of the point. 8 * @param {number} x X-coordinate of the point.
9 * @param {number} y Y-coordinate of the point. 9 * @param {number} y Y-coordinate of the point.
10 */ 10 */
11 -LocalFile = function(ui, data, title, temp, fileHandle, desc)  
12 -{ 11 +LocalFile = function (ui, data, title, temp, fileHandle, desc) {
13 DrawioFile.call(this, ui, data); 12 DrawioFile.call(this, ui, data);
14 - 13 +
15 this.title = title; 14 this.title = title;
16 this.mode = (temp) ? null : App.MODE_DEVICE; 15 this.mode = (temp) ? null : App.MODE_DEVICE;
17 this.fileHandle = fileHandle; 16 this.fileHandle = fileHandle;
@@ -27,8 +26,7 @@ mxUtils.extend(LocalFile, DrawioFile); @@ -27,8 +26,7 @@ mxUtils.extend(LocalFile, DrawioFile);
27 * @param {number} dx X-coordinate of the translation. 26 * @param {number} dx X-coordinate of the translation.
28 * @param {number} dy Y-coordinate of the translation. 27 * @param {number} dy Y-coordinate of the translation.
29 */ 28 */
30 -LocalFile.prototype.isAutosave = function()  
31 -{ 29 +LocalFile.prototype.isAutosave = function () {
32 return this.fileHandle != null && !this.invalidFileHandle && DrawioFile.prototype.isAutosave.apply(this, arguments); 30 return this.fileHandle != null && !this.invalidFileHandle && DrawioFile.prototype.isAutosave.apply(this, arguments);
33 }; 31 };
34 32
@@ -36,8 +34,7 @@ LocalFile.prototype.isAutosave = function() @@ -36,8 +34,7 @@ LocalFile.prototype.isAutosave = function()
36 * Specifies if the autosave checkbox should be shown in the document 34 * Specifies if the autosave checkbox should be shown in the document
37 * properties dialog. Default is false. 35 * properties dialog. Default is false.
38 */ 36 */
39 -LocalFile.prototype.isAutosaveOptional = function()  
40 -{ 37 +LocalFile.prototype.isAutosaveOptional = function () {
41 return this.fileHandle != null; 38 return this.fileHandle != null;
42 }; 39 };
43 40
@@ -47,8 +44,7 @@ LocalFile.prototype.isAutosaveOptional = function() @@ -47,8 +44,7 @@ LocalFile.prototype.isAutosaveOptional = function()
47 * @param {number} dx X-coordinate of the translation. 44 * @param {number} dx X-coordinate of the translation.
48 * @param {number} dy Y-coordinate of the translation. 45 * @param {number} dy Y-coordinate of the translation.
49 */ 46 */
50 -LocalFile.prototype.getMode = function()  
51 -{ 47 +LocalFile.prototype.getMode = function () {
52 return this.mode; 48 return this.mode;
53 }; 49 };
54 50
@@ -58,8 +54,7 @@ LocalFile.prototype.getMode = function() @@ -58,8 +54,7 @@ LocalFile.prototype.getMode = function()
58 * @param {number} dx X-coordinate of the translation. 54 * @param {number} dx X-coordinate of the translation.
59 * @param {number} dy Y-coordinate of the translation. 55 * @param {number} dy Y-coordinate of the translation.
60 */ 56 */
61 -LocalFile.prototype.getTitle = function()  
62 -{ 57 +LocalFile.prototype.getTitle = function () {
63 return this.title; 58 return this.title;
64 }; 59 };
65 60
@@ -69,8 +64,7 @@ LocalFile.prototype.getTitle = function() @@ -69,8 +64,7 @@ LocalFile.prototype.getTitle = function()
69 * @param {number} dx X-coordinate of the translation. 64 * @param {number} dx X-coordinate of the translation.
70 * @param {number} dy Y-coordinate of the translation. 65 * @param {number} dy Y-coordinate of the translation.
71 */ 66 */
72 -LocalFile.prototype.isRenamable = function()  
73 -{ 67 +LocalFile.prototype.isRenamable = function () {
74 return true; 68 return true;
75 }; 69 };
76 70
@@ -80,8 +74,7 @@ LocalFile.prototype.isRenamable = function() @@ -80,8 +74,7 @@ LocalFile.prototype.isRenamable = function()
80 * @param {number} dx X-coordinate of the translation. 74 * @param {number} dx X-coordinate of the translation.
81 * @param {number} dy Y-coordinate of the translation. 75 * @param {number} dy Y-coordinate of the translation.
82 */ 76 */
83 -LocalFile.prototype.save = function(revision, success, error)  
84 -{ 77 +LocalFile.prototype.save = function (revision, success, error) {
85 this.saveAs(this.title, success, error); 78 this.saveAs(this.title, success, error);
86 }; 79 };
87 80
@@ -91,8 +84,7 @@ LocalFile.prototype.save = function(revision, success, error) @@ -91,8 +84,7 @@ LocalFile.prototype.save = function(revision, success, error)
91 * @param {number} dx X-coordinate of the translation. 84 * @param {number} dx X-coordinate of the translation.
92 * @param {number} dy Y-coordinate of the translation. 85 * @param {number} dy Y-coordinate of the translation.
93 */ 86 */
94 -LocalFile.prototype.saveAs = function(title, success, error)  
95 -{ 87 +LocalFile.prototype.saveAs = function (title, success, error) {
96 this.saveFile(title, false, success, error); 88 this.saveFile(title, false, success, error);
97 }; 89 };
98 90
@@ -102,24 +94,21 @@ LocalFile.prototype.saveAs = function(title, success, error) @@ -102,24 +94,21 @@ LocalFile.prototype.saveAs = function(title, success, error)
102 * @param {number} dx X-coordinate of the translation. 94 * @param {number} dx X-coordinate of the translation.
103 * @param {number} dy Y-coordinate of the translation. 95 * @param {number} dy Y-coordinate of the translation.
104 */ 96 */
105 -LocalFile.prototype.saveAs = function(title, success, error)  
106 -{ 97 +LocalFile.prototype.saveAs = function (title, success, error) {
107 this.saveFile(title, false, success, error); 98 this.saveFile(title, false, success, error);
108 }; 99 };
109 100
110 /** 101 /**
111 * Adds all listeners. 102 * Adds all listeners.
112 */ 103 */
113 -LocalFile.prototype.getDescriptor = function()  
114 -{ 104 +LocalFile.prototype.getDescriptor = function () {
115 return this.desc; 105 return this.desc;
116 }; 106 };
117 107
118 /** 108 /**
119 * Updates the descriptor of this file with the one from the given file. 109 * Updates the descriptor of this file with the one from the given file.
120 */ 110 */
121 -LocalFile.prototype.setDescriptor = function(desc)  
122 -{ 111 +LocalFile.prototype.setDescriptor = function (desc) {
123 this.desc = desc; 112 this.desc = desc;
124 }; 113 };
125 114
@@ -129,14 +118,11 @@ LocalFile.prototype.setDescriptor = function(desc) @@ -129,14 +118,11 @@ LocalFile.prototype.setDescriptor = function(desc)
129 * @param {number} dx X-coordinate of the translation. 118 * @param {number} dx X-coordinate of the translation.
130 * @param {number} dy Y-coordinate of the translation. 119 * @param {number} dy Y-coordinate of the translation.
131 */ 120 */
132 -LocalFile.prototype.getLatestVersion = function(success, error)  
133 -{  
134 - if (this.fileHandle == null)  
135 - { 121 +LocalFile.prototype.getLatestVersion = function (success, error) {
  122 + if (this.fileHandle == null) {
136 success(null); 123 success(null);
137 } 124 }
138 - else  
139 - { 125 + else {
140 this.ui.loadFileSystemEntry(this.fileHandle, success, error); 126 this.ui.loadFileSystemEntry(this.fileHandle, success, error);
141 } 127 }
142 }; 128 };
@@ -147,69 +133,60 @@ LocalFile.prototype.getLatestVersion = function(success, error) @@ -147,69 +133,60 @@ LocalFile.prototype.getLatestVersion = function(success, error)
147 * @param {number} dx X-coordinate of the translation. 133 * @param {number} dx X-coordinate of the translation.
148 * @param {number} dy Y-coordinate of the translation. 134 * @param {number} dy Y-coordinate of the translation.
149 */ 135 */
150 -LocalFile.prototype.saveFile = function(title, revision, success, error, useCurrentData)  
151 -{  
152 - if (title != this.title)  
153 - { 136 +LocalFile.prototype.saveFile = function (title, revision, success, error, useCurrentData) {
  137 + if (title != this.title) {
154 this.fileHandle = null; 138 this.fileHandle = null;
155 this.desc = null; 139 this.desc = null;
156 } 140 }
157 - 141 +
158 this.title = title; 142 this.title = title;
159 143
160 // Updates data after changing file name 144 // Updates data after changing file name
161 - if (!useCurrentData)  
162 - { 145 + if (!useCurrentData) {
163 this.updateFileData(); 146 this.updateFileData();
164 } 147 }
165 - 148 +
166 var binary = this.ui.useCanvasForExport && /(\.png)$/i.test(this.getTitle()); 149 var binary = this.ui.useCanvasForExport && /(\.png)$/i.test(this.getTitle());
167 this.setShadowModified(false); 150 this.setShadowModified(false);
168 var savedData = this.getData(); 151 var savedData = this.getData();
169 -  
170 - var done = mxUtils.bind(this, function()  
171 - { 152 +
  153 + var done = mxUtils.bind(this, function () {
172 this.setModified(this.getShadowModified()); 154 this.setModified(this.getShadowModified());
173 this.contentChanged(); 155 this.contentChanged();
174 -  
175 - if (success != null)  
176 - { 156 +
  157 + if (success != null) {
177 success(); 158 success();
178 } 159 }
179 }); 160 });
180 -  
181 - var doSave = mxUtils.bind(this, function(data)  
182 - {  
183 - if (this.fileHandle != null)  
184 - { 161 +
  162 + var doSave = mxUtils.bind(this, function (data) {
  163 + if (this.fileHandle != null) {
185 // Sets shadow modified state during save 164 // Sets shadow modified state during save
186 - if (!this.savingFile)  
187 - { 165 + if (!this.savingFile) {
188 this.savingFileTime = new Date(); 166 this.savingFileTime = new Date();
189 this.savingFile = true; 167 this.savingFile = true;
190 -  
191 - var errorWrapper = mxUtils.bind(this, function(e)  
192 - { 168 +
  169 + var errorWrapper = mxUtils.bind(this, function (e) {
193 this.savingFile = false; 170 this.savingFile = false;
194 -  
195 - if (error != null)  
196 - { 171 +
  172 + if (error != null) {
197 // Wraps error object to offer save status option 173 // Wraps error object to offer save status option
198 - error({error: e}); 174 + error({ error: e });
199 } 175 }
200 }); 176 });
201 - 177 +
202 // Saves a copy as a draft while saving 178 // Saves a copy as a draft while saving
203 this.saveDraft(); 179 this.saveDraft();
204 // 修改开始 180 // 修改开始
205 - try  
206 - { 181 + try {
207 //调用API,保存数据到数据库 182 //调用API,保存数据到数据库
208 - var desc = {name: Editor.configurationName,  
209 - type: "",  
210 - webkitRelativePath: "",  
211 - lastModified: new Date().getTime(),  
212 - lastModifiedDate: new Date()}; 183 + var desc = {
  184 + name: Editor.configurationName,
  185 + type: "",
  186 + webkitRelativePath: "",
  187 + lastModified: new Date().getTime(),
  188 + lastModifiedDate: new Date()
  189 + };
213 this.savingFile = false; 190 this.savingFile = false;
214 this.desc = desc; 191 this.desc = desc;
215 this.fileSaved(savedData, this.desc, done, errorWrapper); 192 this.fileSaved(savedData, this.desc, done, errorWrapper);
@@ -217,17 +194,25 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr @@ -217,17 +194,25 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr
217 // Deletes draft after saving 194 // Deletes draft after saving
218 this.removeDraft(); 195 this.removeDraft();
219 Editor.defaultContent = savedData; 196 Editor.defaultContent = savedData;
220 - var configurationContentList=[];  
221 - var configurationContent = {"name":"第 1 页",  
222 - "id":Editor.configurationContentId,"content":savedData,"type":1}; 197 + var configurationContentList = [];
  198 + const basicAttr = Sidebar.prototype.enumCellBasicAttribute
  199 + const allCell = (this.ui.editor.graph.getDefaultParent().children || []).filter(item => item.getAttribute(basicAttr.COMPONENT_TYPE))
  200 + const contentId = this.ui.currentPage.node.id
  201 + var configurationContent = {
  202 + name: "第 1 页",
  203 + id: Editor.configurationContentId,
  204 + contentId,
  205 + content: savedData,
  206 + type: 1,
  207 + nodeIds: allCell.map(item => item.id)
  208 + };
223 configurationContentList.push(configurationContent); 209 configurationContentList.push(configurationContent);
224 - var parmam = {"configurationId":Editor.configurationId,"configurationContentList":configurationContentList};  
225 - defHttp.put("/yt/configuration/content",parmam).then(res=>{ 210 + var parmam = { configurationId: Editor.configurationId, configurationContentList };
  211 + defHttp.put("/yt/configuration/content", parmam).then(res => {
226 console.log(res) 212 console.log(res)
227 }) 213 })
228 } 214 }
229 - catch (e)  
230 - { 215 + catch (e) {
231 errorWrapper(e); 216 errorWrapper(e);
232 } 217 }
233 // 修改结束 218 // 修改结束
@@ -277,20 +262,16 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr @@ -277,20 +262,16 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr
277 // }), errorWrapper); 262 // }), errorWrapper);
278 } 263 }
279 } 264 }
280 - else  
281 - {  
282 - if (this.ui.isOfflineApp() || this.ui.isLocalFileSave())  
283 - { 265 + else {
  266 + if (this.ui.isOfflineApp() || this.ui.isLocalFileSave()) {
284 this.ui.doSaveLocalFile(data, title, (binary) ? 267 this.ui.doSaveLocalFile(data, title, (binary) ?
285 'image/png' : 'text/xml', binary); 268 'image/png' : 'text/xml', binary);
286 } 269 }
287 - else  
288 - {  
289 - if (data.length < MAX_REQUEST_SIZE)  
290 - { 270 + else {
  271 + if (data.length < MAX_REQUEST_SIZE) {
291 var dot = title.lastIndexOf('.'); 272 var dot = title.lastIndexOf('.');
292 var format = (dot > 0) ? title.substring(dot + 1) : 'xml'; 273 var format = (dot > 0) ? title.substring(dot + 1) : 'xml';
293 - 274 +
294 // Do not update modified flag 275 // Do not update modified flag
295 new mxXmlRequest(SAVE_URL, 'format=' + format + 276 new mxXmlRequest(SAVE_URL, 'format=' + format +
296 '&xml=' + encodeURIComponent(data) + 277 '&xml=' + encodeURIComponent(data) +
@@ -298,31 +279,26 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr @@ -298,31 +279,26 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr
298 ((binary) ? '&binary=1' : '')). 279 ((binary) ? '&binary=1' : '')).
299 simulate(document, '_blank'); 280 simulate(document, '_blank');
300 } 281 }
301 - else  
302 - {  
303 - this.ui.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'), mxUtils.bind(this, function()  
304 - { 282 + else {
  283 + this.ui.handleError({ message: mxResources.get('drawingTooLarge') }, mxResources.get('error'), mxUtils.bind(this, function () {
305 mxUtils.popup(data); 284 mxUtils.popup(data);
306 })); 285 }));
307 } 286 }
308 } 287 }
309 - 288 +
310 done(); 289 done();
311 } 290 }
312 }); 291 });
313 -  
314 - if (binary)  
315 - { 292 +
  293 + if (binary) {
316 var p = this.ui.getPngFileProperties(this.ui.fileNode); 294 var p = this.ui.getPngFileProperties(this.ui.fileNode);
317 295
318 - this.ui.getEmbeddedPng(mxUtils.bind(this, function(imageData)  
319 - { 296 + this.ui.getEmbeddedPng(mxUtils.bind(this, function (imageData) {
320 doSave(imageData); 297 doSave(imageData);
321 }), error, (this.ui.getCurrentFile() != this) ? 298 }), error, (this.ui.getCurrentFile() != this) ?
322 savedData : null, p.scale, p.border); 299 savedData : null, p.scale, p.border);
323 } 300 }
324 - else  
325 - { 301 + else {
326 doSave(savedData); 302 doSave(savedData);
327 } 303 }
328 }; 304 };
@@ -333,13 +309,11 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr @@ -333,13 +309,11 @@ LocalFile.prototype.saveFile = function(title, revision, success, error, useCurr
333 * @param {number} dx X-coordinate of the translation. 309 * @param {number} dx X-coordinate of the translation.
334 * @param {number} dy Y-coordinate of the translation. 310 * @param {number} dy Y-coordinate of the translation.
335 */ 311 */
336 -LocalFile.prototype.rename = function(title, success, error)  
337 -{ 312 +LocalFile.prototype.rename = function (title, success, error) {
338 this.title = title; 313 this.title = title;
339 this.descriptorChanged(); 314 this.descriptorChanged();
340 -  
341 - if (success != null)  
342 - { 315 +
  316 + if (success != null) {
343 success(); 317 success();
344 } 318 }
345 }; 319 };
@@ -348,8 +322,7 @@ LocalFile.prototype.rename = function(title, success, error) @@ -348,8 +322,7 @@ LocalFile.prototype.rename = function(title, success, error)
348 * Returns the location as a new object. 322 * Returns the location as a new object.
349 * @type mx.Point 323 * @type mx.Point
350 */ 324 */
351 -LocalFile.prototype.open = function()  
352 -{ 325 +LocalFile.prototype.open = function () {
353 this.ui.setFileData(this.getData()); 326 this.ui.setFileData(this.getData());
354 this.installListeners(); 327 this.installListeners();
355 }; 328 };
@@ -993,6 +993,14 @@ EditorUi.prototype.selectPage = function(page, quiet, viewState) @@ -993,6 +993,14 @@ EditorUi.prototype.selectPage = function(page, quiet, viewState)
993 catch (e) 993 catch (e)
994 { 994 {
995 this.handleError(e); 995 this.handleError(e);
  996 + } finally {
  997 + // TODO thingskit instance chart
  998 + Sidebar.prototype.chartsInstanceMapping.forEach(item => {
  999 + item.dispose()
  1000 + })
  1001 + Sidebar.prototype.chartsInstanceMapping.clear()
  1002 + const graph = this.editor.graph
  1003 + Sidebar.prototype.initChartInstance(graph)
996 } 1004 }
997 }; 1005 };
998 1006
@@ -2079,4 +2087,4 @@ EditorUi.prototype.createPageMenu = function(page, label) @@ -2079,4 +2087,4 @@ EditorUi.prototype.createPageMenu = function(page, label)
2079 }; 2087 };
2080 2088
2081 mxCodecRegistry.register(codec); 2089 mxCodecRegistry.register(codec);
2082 -})();  
  2090 +})();
@@ -166,7 +166,12 @@ @@ -166,7 +166,12 @@
166 /** 166 /**
167 * @description 组件类型 167 * @description 组件类型
168 */ 168 */
169 - COMPONENT_TYPE: 'componentType' 169 + COMPONENT_TYPE: 'componentType',
  170 +
  171 + /**
  172 + * @description 图表实例ID
  173 + */
  174 + CHART_INSTANCE_ID: 'chartInstanceId'
170 } 175 }
171 176
172 /** 177 /**
@@ -248,7 +253,9 @@ @@ -248,7 +253,9 @@
248 */ 253 */
249 Sidebar.prototype.enumPermissionPanel = { 254 Sidebar.prototype.enumPermissionPanel = {
250 DATA_SOURCE: 'dataSource', 255 DATA_SOURCE: 'dataSource',
251 - DISPLAY_TYPE: 'displayType', 256 + // DISPLAY_TYPE: 'displayType',
  257 + LINE_CHART_EXPAND: 'lineChartExpandDataSource',
  258 + BAR_CHART_EXPAND: 'barChartExpandDataSource',
252 INTERACTION: 'interaction', 259 INTERACTION: 'interaction',
253 DYNAMIC_EFFECT: 'dynamicEffect', 260 DYNAMIC_EFFECT: 'dynamicEffect',
254 VAR_IMAGE: 'variableImage' 261 VAR_IMAGE: 'variableImage'
@@ -596,6 +603,7 @@ @@ -596,6 +603,7 @@
596 // Defines all entries for the sidebar. This is used in the MoreShapes dialog. Create screenshots using the savesidebar URL parameter and 603 // Defines all entries for the sidebar. This is used in the MoreShapes dialog. Create screenshots using the savesidebar URL parameter and
597 // http://www.alderg.com/merge.html for creating a vertical stack of PNG images if multiple sidebars are part of an entry. 604 // http://www.alderg.com/merge.html for creating a vertical stack of PNG images if multiple sidebars are part of an entry.
598 //更多图形里面的加载,可以加载自己定义的图形库,同时要提供对应的图片 605 //更多图形里面的加载,可以加载自己定义的图形库,同时要提供对应的图片
  606 + var stdEntries = []
599 // var stdEntries = [{title: mxResources.get('general'), id: 'general', image: IMAGE_PATH + '/sidebar-general.png'}, 607 // var stdEntries = [{title: mxResources.get('general'), id: 'general', image: IMAGE_PATH + '/sidebar-general.png'},
600 // {title: mxResources.get('basic'), id: 'basic', image: IMAGE_PATH + '/sidebar-basic.png'}, 608 // {title: mxResources.get('basic'), id: 'basic', image: IMAGE_PATH + '/sidebar-basic.png'},
601 // {title: mxResources.get('arrows'), id: 'arrows2', image: IMAGE_PATH + '/sidebar-arrows2.png'}, 609 // {title: mxResources.get('arrows'), id: 'arrows2', image: IMAGE_PATH + '/sidebar-arrows2.png'},
@@ -604,7 +612,7 @@ @@ -604,7 +612,7 @@
604 //更多图形,显示出来的的标题跟id,同时包括图片 612 //更多图形,显示出来的的标题跟id,同时包括图片
605 613
606 // TODO thingsKit 设置数据绑定展示面板 614 // TODO thingsKit 设置数据绑定展示面板
607 - const { DISPLAY_TYPE, DYNAMIC_EFFECT, DATA_SOURCE, VAR_IMAGE, INTERACTION } = this.enumPermissionPanel 615 + const { LINE_CHART_EXPAND, BAR_CHART_EXPAND, DYNAMIC_EFFECT, DATA_SOURCE, VAR_IMAGE, INTERACTION } = this.enumPermissionPanel
608 const { LINE, LINE_CHART, REAL_TIME, TITLE, VARIABLE, DEFAULT, BAR_CHART } = this.enumComponentType 616 const { LINE, LINE_CHART, REAL_TIME, TITLE, VARIABLE, DEFAULT, BAR_CHART } = this.enumComponentType
609 this.setComponentPermission(LINE, [DYNAMIC_EFFECT]) 617 this.setComponentPermission(LINE, [DYNAMIC_EFFECT])
610 this.setComponentPermission(DEFAULT, [DYNAMIC_EFFECT]) 618 this.setComponentPermission(DEFAULT, [DYNAMIC_EFFECT])
@@ -612,8 +620,8 @@ @@ -612,8 +620,8 @@
612 this.setComponentPermission(TITLE, [INTERACTION, DYNAMIC_EFFECT]) 620 this.setComponentPermission(TITLE, [INTERACTION, DYNAMIC_EFFECT])
613 this.setComponentPermission(VAR_IMAGE, [DATA_SOURCE, INTERACTION, VAR_IMAGE]) 621 this.setComponentPermission(VAR_IMAGE, [DATA_SOURCE, INTERACTION, VAR_IMAGE])
614 this.setComponentPermission(VARIABLE, [DATA_SOURCE, INTERACTION, DYNAMIC_EFFECT]) 622 this.setComponentPermission(VARIABLE, [DATA_SOURCE, INTERACTION, DYNAMIC_EFFECT])
615 - this.setComponentPermission(BAR_CHART, [DATA_SOURCE, DISPLAY_TYPE, DYNAMIC_EFFECT])  
616 - this.setComponentPermission(LINE_CHART, [DATA_SOURCE, DISPLAY_TYPE, DYNAMIC_EFFECT]) 623 + this.setComponentPermission(BAR_CHART, [DATA_SOURCE, BAR_CHART_EXPAND, DYNAMIC_EFFECT])
  624 + this.setComponentPermission(LINE_CHART, [DATA_SOURCE, LINE_CHART_EXPAND, DYNAMIC_EFFECT])
617 625
618 var thingskitEntries = [ 626 var thingskitEntries = [
619 { title: "风机", id: 'fan', image: IMAGE_PATH + '/thingskit/风机.png' }, 627 { title: "风机", id: 'fan', image: IMAGE_PATH + '/thingskit/风机.png' },
@@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
36 return this.createEdgeTemplateFromCells([ cell ], 60, 40, '线条'); 36 return this.createEdgeTemplateFromCells([ cell ], 60, 40, '线条');
37 })), 37 })),
38 this.addEntry('real time', mxUtils.bind(this, function () { 38 this.addEntry('real time', mxUtils.bind(this, function () {
39 - const template = `<div class="thingKit-component__real-time"><div class="real-time__date"></div> <div style="font-size:30px" class="real-time__now">时间</div></div>` 39 + const template = `<div class="thingKit-component__real-time"><div class="real-time__date">%currentDate%</div> <div style="font-size:30px" class="real-time__now">HH:mm:ss</div></div>`
40 const cell = new mxCell(template, new mxGeometry(0, 0, 180, 60), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;'); 40 const cell = new mxCell(template, new mxGeometry(0, 0, 180, 60), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;');
41 cell.vertex = true; 41 cell.vertex = true;
42 this.setCellAttributes(cell, { 42 this.setCellAttributes(cell, {
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 /** 24 /**
25 * @description cell id key 25 * @description cell id key
26 */ 26 */
27 - CHART_CELL_ID: 'chartInstanceId', 27 + CHART_INSTANCE_ID: 'chartInstanceId',
28 28
29 /** 29 /**
30 * @description 图表容器 class name 30 * @description 图表容器 class name
@@ -143,7 +143,7 @@ @@ -143,7 +143,7 @@
143 const basicAttr = this.enumCellBasicAttribute 143 const basicAttr = this.enumCellBasicAttribute
144 this.setCellAttributes(cell, { 144 this.setCellAttributes(cell, {
145 [basicAttr.COMPONENT_TYPE]: chartType, 145 [basicAttr.COMPONENT_TYPE]: chartType,
146 - [enumConst.CHART_CELL_ID]: id, 146 + [basicAttr.CHART_INSTANCE_ID]: id,
147 [enumConst.CHART_CELL_WIDTH]: width, 147 [enumConst.CHART_CELL_WIDTH]: width,
148 [enumConst.CHART_CELL_HEIGHT]: height, 148 [enumConst.CHART_CELL_HEIGHT]: height,
149 }) 149 })
@@ -194,6 +194,7 @@ @@ -194,6 +194,7 @@
194 const chartOptionMapping = this.chartOptionMapping 194 const chartOptionMapping = this.chartOptionMapping
195 const chartsInstanceMapping = this.chartsInstanceMapping 195 const chartsInstanceMapping = this.chartsInstanceMapping
196 const chartDom = document.getElementById(id); 196 const chartDom = document.getElementById(id);
  197 + if (!chartDom) return
197 chartDom.style.width = `${width}px` 198 chartDom.style.width = `${width}px`
198 chartDom.style.height = `${height}px` 199 chartDom.style.height = `${height}px`
199 const myChart = echarts.init(chartDom); 200 const myChart = echarts.init(chartDom);
@@ -208,7 +209,8 @@ @@ -208,7 +209,8 @@
208 * @returns {*} 209 * @returns {*}
209 */ 210 */
210 Sidebar.prototype.getCellId = function (cell) { 211 Sidebar.prototype.getCellId = function (cell) {
211 - return this.graph.getAttributeForCell(cell, enumConst.CHART_CELL_ID) 212 + const basicAttr = this.enumCellBasicAttribute
  213 + return this.graph.getAttributeForCell(cell, basicAttr.CHART_INSTANCE_ID)
212 } 214 }
213 215
214 /** 216 /**
@@ -238,7 +240,7 @@ @@ -238,7 +240,7 @@
238 const id = self.generatorChartsId() 240 const id = self.generatorChartsId()
239 const geo = Object.assign(graph.model.getGeometry(cell), { width: 400, height: 400 }) 241 const geo = Object.assign(graph.model.getGeometry(cell), { width: 400, height: 400 })
240 cell.setGeometry(geo) 242 cell.setGeometry(geo)
241 - self.graph.setAttributeForCell(cell, enumConst.CHART_CELL_ID, id); 243 + self.graph.setAttributeForCell(cell, basicAttr.CHART_INSTANCE_ID, id);
242 self.graph.setAttributeForCell(cell, enumConst.CHART_CELL_WIDTH, enumConst.CHART_CELL_DEFAULT_WIDTH); 244 self.graph.setAttributeForCell(cell, enumConst.CHART_CELL_WIDTH, enumConst.CHART_CELL_DEFAULT_WIDTH);
243 self.graph.setAttributeForCell(cell, enumConst.CHART_CELL_HEIGHT, enumConst.CHART_CELL_DEFAULT_HEIGHT); 245 self.graph.setAttributeForCell(cell, enumConst.CHART_CELL_HEIGHT, enumConst.CHART_CELL_DEFAULT_HEIGHT);
244 self.graph.setAttributeForCell(cell, 'label', self.createChartsNode(id)) 246 self.graph.setAttributeForCell(cell, 'label', self.createChartsNode(id))
@@ -281,7 +283,8 @@ @@ -281,7 +283,8 @@
281 self.graph.setAttributeForCell(cell, enumConst.CHART_CELL_WIDTH, width) 283 self.graph.setAttributeForCell(cell, enumConst.CHART_CELL_WIDTH, width)
282 self.graph.setAttributeForCell(cell, enumConst.CHART_CELL_HEIGHT, height) 284 self.graph.setAttributeForCell(cell, enumConst.CHART_CELL_HEIGHT, height)
283 const instance = chartsInstanceMapping.get(id) 285 const instance = chartsInstanceMapping.get(id)
284 - instance.resize() 286 +
  287 + instance && instance.resize()
285 } 288 }
286 cellResized.apply(this, arguments) 289 cellResized.apply(this, arguments)
287 } 290 }
@@ -327,10 +330,10 @@ @@ -327,10 +330,10 @@
327 */ 330 */
328 Sidebar.prototype.initChartInstance = function (graph) { 331 Sidebar.prototype.initChartInstance = function (graph) {
329 const basicAttr = this.enumCellBasicAttribute 332 const basicAttr = this.enumCellBasicAttribute
330 - const allCell = graph.getDefaultParent().children 333 + const allCell = graph.getDefaultParent().children || []
331 const domIdMapping = new Map() 334 const domIdMapping = new Map()
332 for (const cell of allCell) { 335 for (const cell of allCell) {
333 - const chartInstanceId = graph.getAttributeForCell(cell, enumConst.CHART_CELL_ID) 336 + const chartInstanceId = graph.getAttributeForCell(cell, basicAttr.CHART_INSTANCE_ID)
334 if (Sidebar.prototype.isChartCell(cell) && chartInstanceId) { 337 if (Sidebar.prototype.isChartCell(cell) && chartInstanceId) {
335 const width = graph.getAttributeForCell(cell, enumConst.CHART_CELL_WIDTH) 338 const width = graph.getAttributeForCell(cell, enumConst.CHART_CELL_WIDTH)
336 const height = graph.getAttributeForCell(cell, enumConst.CHART_CELL_HEIGHT) 339 const height = graph.getAttributeForCell(cell, enumConst.CHART_CELL_HEIGHT)
@@ -352,15 +355,17 @@ @@ -352,15 +355,17 @@
352 /** 355 /**
353 * @description 初始化图表 356 * @description 初始化图表
354 */ 357 */
355 - const openFileHandle = EditorUi.prototype.openFileHandle  
356 - EditorUi.prototype.openFileHandle = function () {  
357 - try {  
358 - openFileHandle.apply(this, arguments)  
359 - } finally {  
360 - const graph = this.editor.graph  
361 - Sidebar.prototype.initChartInstance(graph)  
362 - }  
363 - } 358 + // const openFileHandle = EditorUi.prototype.openFileHandle
  359 + // EditorUi.prototype.openFileHandle = function () {
  360 + // console.log('enter open file')
  361 + // try {
  362 + // openFileHandle.apply(this, arguments)
  363 + // } finally {
  364 + // console.log('openFileHandle')
  365 + // const graph = this.editor.graph
  366 + // Sidebar.prototype.initChartInstance(graph)
  367 + // }
  368 + // }
364 369
365 /** 370 /**
366 * @description 实例化 echarts 371 * @description 实例化 echarts
@@ -372,5 +377,17 @@ @@ -372,5 +377,17 @@
372 Sidebar.prototype.initChartInstance(this) 377 Sidebar.prototype.initChartInstance(this)
373 } 378 }
374 } 379 }
  380 +
  381 + // const selectPage = EditorUi.prototype.selectPage
  382 + // EditorUi.prototype.selectPage = function () {
  383 + // try {
  384 + // selectPage.apply(this, arguments)
  385 +
  386 + // } finally {
  387 + // Sidebar.prototype.chartsInstanceMapping.clear()
  388 + // const graph = this.editor.graph
  389 + // Sidebar.prototype.initChartInstance(graph)
  390 + // }
  391 + // }
375 })(); 392 })();
376 393
@@ -3379,6 +3379,8 @@ EditorUi.prototype.lightboxFit = function(maxHeight) @@ -3379,6 +3379,8 @@ EditorUi.prototype.lightboxFit = function(maxHeight)
3379 this.editor.graph.maxFitScale = this.lightboxMaxFitScale; 3379 this.editor.graph.maxFitScale = this.lightboxMaxFitScale;
3380 this.editor.graph.fit(border, null, null, null, null, null, maxHeight); 3380 this.editor.graph.fit(border, null, null, null, null, null, maxHeight);
3381 this.editor.graph.maxFitScale = null; 3381 this.editor.graph.maxFitScale = null;
  3382 + // TODO thingsKit lightbox 默认缩放为1
  3383 + this.editor.graph.view.setScale(1);
3382 } 3384 }
3383 }; 3385 };
3384 3386