Save image size when we save full graph to image.

This commit is contained in:
Oleg Sh
2024-08-11 13:09:32 +02:00
parent 451a964127
commit 23ef760b23
8 changed files with 107 additions and 49 deletions

View File

@@ -1,4 +1,4 @@
moduleLoader.beginCacheLoading(["/script/shared/utils.js?v=79","/script/entities/graph/api/index.js?v=79","/script/shared/point.js?v=79","/script/entities/edge/api/index.js?v=79","/script/entities/edge/model/BaseEdge.js?v=79","/script/entities/edge/model/EdgeModel.js?v=79","/script/entities/vertex/api/index.js?v=79","/script/entities/vertex/model/BaseVertex.js?v=79","/script/entities/vertex/model/VertexModel.js?v=79","/script/entities/graph/model/Graph.js?v=79","/script/features/draw_graph/api/index.js?v=79","/script/features/draw_graph/model/BaseBackgroundDrawer.js?v=79","/script/features/draw_graph/model/EdgeStyle.js?v=79","/script/features/draw_graph/model/BaseEdgeDrawer.js?v=79","/script/features/draw_graph/model/VertexShape.js?v=79","/script/features/draw_graph/model/VertexStyle.js?v=79","/script/features/draw_graph/model/BaseVertexDrawer.js?v=79","/script/features/algorithms/api/index.js?v=79","/script/features/algorithms/model/Algorithms.js?v=79","/script/features/algorithms/model/BaseTraversal.js?v=79","/script/features/base_handler/index.js?v=79","/script/features/default_handler/index.js?v=79","/script/features/add_vertices_handler/index.js?v=79","/script/features/connect_vertices_handler/index.js?v=79","/script/features/delete_objects_handler/index.js?v=79","/script/features/algorithm_handler/index.js?v=79","/script/features/serialization/api/index.js?v=79","/script/features/serialization/model/GraphMLCreator.js?v=79","/script/features/enum_vertices/EnumVertices.js?v=79","/script/pages/editor/model/texts.js?v=79","/script/pages/editor/model/UndoStack.js?v=79","/script/pages/editor/model/DiskSaveLoad.js?v=79","/script/pages/editor/model/Application.js?v=79","/script/pages/editor/ui/ya_metrika.js?v=79","/script/pages/editor/ui/editor.js?v=79","/script/pages/editor/ui/main.js?v=79",]);{function onloadEditor(){console.log("onload() call");doIncludeAsync([include("shared/canvas2svg.js"),include("features/group_rename_handler/index.js"),include("features/saved_graph_handler/index.js"),include("features/saved_graph_image_handler/index.js"),include("features/show_adjacency_matrix/index.js"),include("features/show_distance_matrix/index.js"),include("features/show_incidence_matrix/index.js"),include("features/setup_background_style/index.js"),include("features/setup_edge_style/index.js"),include("features/setup_vertex_style/index.js"),]);postLoadPage();}
moduleLoader.beginCacheLoading(["/script/shared/utils.js?v=80","/script/entities/graph/api/index.js?v=80","/script/shared/point.js?v=80","/script/entities/edge/api/index.js?v=80","/script/entities/edge/model/BaseEdge.js?v=80","/script/entities/edge/model/EdgeModel.js?v=80","/script/entities/vertex/api/index.js?v=80","/script/entities/vertex/model/BaseVertex.js?v=80","/script/entities/vertex/model/VertexModel.js?v=80","/script/entities/graph/model/Graph.js?v=80","/script/features/draw_graph/api/index.js?v=80","/script/features/draw_graph/model/BaseBackgroundDrawer.js?v=80","/script/features/draw_graph/model/EdgeStyle.js?v=80","/script/features/draw_graph/model/BaseEdgeDrawer.js?v=80","/script/features/draw_graph/model/VertexShape.js?v=80","/script/features/draw_graph/model/VertexStyle.js?v=80","/script/features/draw_graph/model/BaseVertexDrawer.js?v=80","/script/features/algorithms/api/index.js?v=80","/script/features/algorithms/model/Algorithms.js?v=80","/script/features/algorithms/model/BaseTraversal.js?v=80","/script/features/base_handler/index.js?v=80","/script/features/default_handler/index.js?v=80","/script/features/add_vertices_handler/index.js?v=80","/script/features/connect_vertices_handler/index.js?v=80","/script/features/delete_objects_handler/index.js?v=80","/script/features/algorithm_handler/index.js?v=80","/script/features/serialization/api/index.js?v=80","/script/features/serialization/model/GraphMLCreator.js?v=80","/script/features/enum_vertices/EnumVertices.js?v=80","/script/pages/editor/model/texts.js?v=80","/script/pages/editor/model/UndoStack.js?v=80","/script/pages/editor/model/DiskSaveLoad.js?v=80","/script/pages/editor/model/Application.js?v=80","/script/pages/editor/ui/ya_metrika.js?v=80","/script/pages/editor/ui/editor.js?v=80","/script/pages/editor/ui/main.js?v=80",]);{function onloadEditor(){console.log("onload() call");doIncludeAsync([include("shared/canvas2svg.js"),include("features/group_rename_handler/index.js"),include("features/saved_graph_handler/index.js"),include("features/saved_graph_image_handler/index.js"),include("features/show_adjacency_matrix/index.js"),include("features/show_distance_matrix/index.js"),include("features/show_incidence_matrix/index.js"),include("features/setup_background_style/index.js"),include("features/setup_edge_style/index.js"),include("features/setup_vertex_style/index.js"),]);postLoadPage();}
let modulDir="pages/editor/";doInclude([include("shared/utils.js"),include("entities/graph/api/index.js"),include("features/draw_graph/api/index.js"),include("features/algorithms/api/index.js"),include("features/base_handler/index.js"),include("features/default_handler/index.js"),include("features/add_vertices_handler/index.js"),include("features/connect_vertices_handler/index.js"),include("features/delete_objects_handler/index.js"),include("features/algorithm_handler/index.js"),include("features/serialization/api/index.js"),include("features/enum_vertices/EnumVertices.js"),include("model/texts.js",modulDir),include("model/UndoStack.js",modulDir),include("model/DiskSaveLoad.js",modulDir),include("model/Application.js",modulDir),include("ui/ya_metrika.js",modulDir),include("ui/editor.js",modulDir),include("ui/main.js",modulDir)],onloadEditor);}
function gEncodeToHTML(str)
{if(typeof str!=='string')
@@ -204,8 +204,6 @@ this.model.diameter=parseInt(size);}
BaseVertex.prototype.SetId=function(id)
{this.id=id;if(this.vertexEnumType!=null)
this.mainText=this.vertexEnumType.GetVertexText(id);}
BaseVertex.prototype.diameterFactor=function()
{return new Point(1.0+(this.mainText.length?this.mainText.length/8.0:0),1.5);}
BaseVertex.prototype.IsUndefinedPosition=function()
{return this.hasUndefinedPosition;}
BaseVertex.prototype.HitTest=function(pos)
@@ -235,6 +233,12 @@ style=globalApplication.GetStyle("vertex","common");else
style=globalApplication.GetStyle("vertex","selected",undefined,index-1);return style;}}
BaseVertex.prototype.hasOwnStyleFor=function(index)
{return this.ownStyles.hasOwnProperty(index);}
BaseVertex.prototype.getDefaultDiameterFactor=function(textSize)
{var textFactor=defaultVertexDiameter*8.0/(2.0*textSize);return new Point(1.0+(this.mainText.length?this.mainText.length/textFactor:0),1.5);}
BaseVertex.prototype.getBBox=function(style)
{var textSize=DefaultMainTextFontSize;if(style!==undefined)
{textSize=style.mainTextFontSize;}
var defaultDiameter=(new VertexModel()).diameter;var vertexDiameter=this.model.diameter;var factor=this.getDefaultDiameterFactor(textSize);return new Point(Math.max(factor.x*defaultDiameter,vertexDiameter),Math.max(factor.y*defaultDiameter,vertexDiameter));}
const defaultVertexDiameter=30;function VertexModel()
{this.diameter=globalApplication.GetDefaultVertexSize();}
function Graph()
@@ -549,9 +553,9 @@ Graph.prototype.hasEdges=function()
Graph.prototype.clampPositions=function(viewportSize)
{var diameter=(new VertexModel()).diameter;for(i=0;i<this.vertices.length;i++)
{this.vertices[i].position.x=Math.min(Math.max(this.vertices[i].position.x,diameter),viewportSize.x-diameter);this.vertices[i].position.y=Math.min(Math.max(this.vertices[i].position.y,diameter),viewportSize.y-diameter);}}
Graph.prototype.getGraphBBox=function(viewportSize)
Graph.prototype.getGraphBBox=function(vertexStyle)
{var pointMin=new Point(1e5,1e5);var pointMax=new Point(-1e5,-1e5);var diameter=(new VertexModel()).diameter;for(i=0;i<this.vertices.length;i++)
{var vertex=this.vertices[i];var factor=vertex.diameterFactor();var deltaVector=new Point(factor.x*diameter,factor.y*diameter);pointMin=pointMin.min(vertex.position.subtract(deltaVector));pointMax=pointMax.max(vertex.position.add(deltaVector));}
{var vertex=this.vertices[i];var bbox=vertex.getBBox(vertexStyle==undefined?vertex.getStyleFor(0):vertexStyle);pointMin=pointMin.min(vertex.position.subtract(bbox));pointMax=pointMax.max(vertex.position.add(bbox));}
var max_curve_length=32;for(i=0;i<this.edges.length;i++)
{var edge=this.edges[i];if(edge.model.type==EdgeModels.curve)
{var max_curve=edge.vertex2.position.subtract(edge.vertex1.position).length()/max_curve_length;for(j=0;j<max_curve;j++)