我正在尝试以编程方式关闭图形中每个单元格的格式化文本,以便避免在mxgraph编辑器(类似于Draw.io)中使用Not supported by viewer
这是我的尝试:
graph.stopEditing();
graph.getModel().beginUpdate();
try
{
var cells = graph.getChildCells(graph.getDefaultParent());
cells.forEach(function (cell)
{
var state = graph.getView().getState(cell);
if (state == null)
{
return;
}
if (state.style['html'] != '1') {
return;
}
var label = graph.convertValueToString(state.cell);
if (mxUtils.getValue(state.style, 'nl2Br', '1') != '0')
{
label = label.replace(/\n/g, '').replace(/<br\s*.?>/g, '\n');
}
// Removes HTML tags
var temp = document.createElement('div');
temp.innerHTML = label;
label = mxUtils.extractTextWithWhitespace(temp.childNodes);
graph.cellLabelChanged(state.cell, label);
graph.setCellStyles('html', null);
});
ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['html'],
'values', ['0'], 'cells', cells));
}
finally
{
graph.getModel().endUpdate();
}
但是它似乎不起作用(例如,如果我从“格式”面板中的复选框中将其关闭,则它会起作用;但是通过这种方式,我仍然可以获得[Not supported by viewer]
的输出在我的SVG中)
我在做什么错了?
答案 0 :(得分:0)
替换:
DispatchQueue.global(qos: .background).async { [weak self] () -> Void in
if let url = NSURL(string: "https://restcountries.eu/data/est.svg"){
if let data = NSData(contentsOf: url as URL) {
let imageAux = UIImage(data: data as Data)
DispatchQueue.main.async {
let anSVGImage: SVGKImage = SVGKImage(data: data as Data)
cell.imgFlag.image = nSVGImage.uiImage
}
}
}
}
具有:
graph.setCellStyles('html', null);