Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Gephi exported svg are different from its's preview #2901

Open
LaoshuBaby opened this issue Apr 3, 2024 · 0 comments
Open

Comments

@LaoshuBaby
Copy link

LaoshuBaby commented Apr 3, 2024

Expected Behavior

Exported SVG are using straight line for connection between nodes, the same as preview in Gephi.

Current Behavior

Connections between nodes in exported svg/pdf/png are curved ????

Possible Solution

Notice the d="M 721.904907,-2560.862549 A 1466.726016,1466.726016 0,0 1,2294.601074,-3309.099121", it means a arc, so I use this part of python code modify it to "L" in my local environment

import re
import argparse

def convert_arc_to_line(svg_content):
    arc_pattern = r'M\s+([-\d.]+),([-\d.]+)\s+A\s+[-\d.]+,[-\d.]+\s+\d,\d\s+\d,([-\d.]+),([-\d.]+)'
    def line_replacement(match):
        start_x, start_y, end_x, end_y = match.groups()
        return f'M {start_x},{start_y} L {end_x},{end_y}'
    return re.sub(arc_pattern, line_replacement, svg_content)

def main(input_file, output_file):
    with open(input_file, 'r', encoding='utf-8') as file:
        svg_content = file.read()
    svg_content = convert_arc_to_line(svg_content)
    with open(output_file, 'w', encoding='utf-8') as file:
        file.write(svg_content)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Convert arcs to lines in an SVG file.')
    parser.add_argument('input', type=str, help='Input SVG file name')
    parser.add_argument('output', type=str, help='Output SVG file name')
    args = parser.parse_args()
    
    main(args.input, args.output)

I know that Gephi is a project with Java as the main development language, but unfortunately I don’t know Java, so I can’t directly open a PR to modify the code responsible for export in Gephi.

Steps to Reproduce

  1. Open some thing, such as a .gv file or graphml, what ever.
  2. Choose a layout you like, and run
  3. Export to svg/png/pdf

Context

Gephi auto generated svg export file are using source code like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg contentScriptType="text/ecmascript" width="17485.0"
     xmlns:xlink="http://www.w3.org/1999/xlink" zoomAndPan="magnify"
     contentStyleType="text/css"
     viewBox="-8724.000000 -8701.000000 17485.000000 17426.000000"
     height="17426.0" preserveAspectRatio="xMidYMid meet"
     xmlns="http://www.w3.org/2000/svg" version="1.1">
    <g id="edges">
        <path stroke-linecap="round" fill="none" class="id_153269 id_2707990"
              d="M 721.904907,-2560.862549 A 1466.726016,1466.726016 0,0 1,2294.601074,-3309.099121"
              stroke="#000000" stroke-width="1.0" stroke-opacity="1.0"/>

Correct svg source code should be like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg contentScriptType="text/ecmascript" width="17485.0"
     xmlns:xlink="http://www.w3.org/1999/xlink" zoomAndPan="magnify"
     contentStyleType="text/css"
     viewBox="-8724.000000 -8701.000000 17485.000000 17426.000000"
     height="17426.0" preserveAspectRatio="xMidYMid meet"
     xmlns="http://www.w3.org/2000/svg" version="1.1">
    <g id="edges">
        <path stroke-linecap="round" fill="none" class="id_153269 id_2707990"
              d="M 721.904907,-2560.862549 L 2294.601074,-3309.099121"
              stroke="#000000" stroke-width="1.0" stroke-opacity="1.0"/>

Your Environment

Gephi Image

Product Version: Gephi 0.10.1 202301172018

Java: 11.0.17; OpenJDK 64-Bit Server VM 11.0.17+8

系统: Windows 11版本 10.0 运行于amd64上; GBK; zh_CN (gephi)

用户目录: C:\Users\laoshubaby\AppData\Roaming\gephi\0.10

高速缓存目录: C:\Users\laoshubaby\AppData\Local\gephi\Cache\0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant