Skip to content

Commit

Permalink
Freeplane format attempt + new properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jsboige committed Apr 25, 2024
1 parent 0e5870a commit af992ca
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,19 @@ static int GetUnixTime(DateTime utcTime)
}

[XmlRoot(ElementName = "map")]
[XmlInclude(typeof(FreeplaneMap))]
public class FreemindMap
{
[XmlElement(ElementName = "node")]
public Node Node { get; set; }

[XmlAttribute(AttributeName = "version")]
public string Version { get; set; } = "1.0.1";
public virtual string Version { get; set; } = "1.0.1";
}

public class FreeplaneMap : FreemindMap
{
[XmlAttribute(AttributeName = "version")]
public override string Version { get; set; } = "freeplane 1.11.5";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MindMapCreatorConfig : ParallelFallacyDocumentCreatorConfigBase<Min

public override string GetLogTitle()
{
return "Generating Freemind, SVG & Html Mindmaps";
return "Generating Freemind/Freeplane, SVG & Html Mindmaps";
}

public override string GetLogMessage()
Expand Down Expand Up @@ -58,6 +58,7 @@ public override string GetLogMessage()
DocumentName = "links.svg",
SvgWidth = "200vh",
SvgHeight = "450vh",
SvgViewBox = "0 0 8500 20000",
WrapNodeByLink = true,
SetSVGNodeAttributes = false,
RemoveImages = true
Expand All @@ -68,6 +69,7 @@ public override string GetLogMessage()
DocumentName = "content.svg",
SvgWidth = "96vw",
SvgHeight = "93vh",
SvgViewBox = "0 0 8500 20000",
WrapNodeByLink = false,
SetSVGNodeAttributes = true,
RemoveImages = true,
Expand Down Expand Up @@ -96,17 +98,18 @@ public override string GetLogMessage()
},
new MindMapDocumentConfig()
{
Enabled = false,
Enabled = true,
DocumentName = "Argumentum_Fallacies_MindMap_cards_fr.mm",
Format = MindMapFormat.Freemind,
DataSet = KnownDataSets.FallaciesTaxonomy,
InsertCardsThumbnails = true,
ThumbnailsCardSetName = KnownCardSets.FallaciesWebThumbnails,
Translations = new List<(string sourceLang, string destLang)>(new[]
{
("fr", "en"),
("fr", "ru"),
("fr", "pt")
}),
//Translations = new List<(string sourceLang, string destLang)>(new[]
//{
// ("fr", "en"),
// ("fr", "ru"),
// ("fr", "pt")
//}),
ImageFormat = MagickFormat.Png,
TargetDensity = 0,
SVGMaps = new List<SVGFreemindMap>(new[]
Expand All @@ -116,6 +119,7 @@ public override string GetLogMessage()
Enabled = true,
DocumentName = "links.svg",
WrapNodeByLink = true,
RemoveImages = true,
SetSVGNodeAttributes = false,
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class MindMapDocumentConfig : FallacyDocumentConfigBase


const string DefaultTitleExpression = @"{fallacy.TextFr}";

public MindMapFormat Format { get; set; } = MindMapFormat.Freemind;

public string TitleExpression { get; set; } = DefaultTitleExpression;

[IgnoreDataMember]
Expand Down Expand Up @@ -280,7 +283,16 @@ private void CreateFreemindmap(IList<Fallacy> fallacies, AssetConverterConfig co
else
{
Logger.Log($"Creating Freemind mind map {DocumentName}");
var freemindMap = new FreemindMap();
FreemindMap freemindMap;
if (Format == MindMapFormat.Freeplane)
{
freemindMap = new FreeplaneMap();
}
else
{
freemindMap = new FreemindMap();
}

var nodesByPath = new Dictionary<string, Node>(fallacies.Count);
CreateFallacyNodes(freemindMap, fallacies, nodesByPath, config, language);

Expand Down Expand Up @@ -540,12 +552,19 @@ private async Task ProcessSvgFilesAsync(IList<Fallacy> fallacies, string fileNam
return;
}
XDocument svgDoc = XDocument.Load(svgFilePath);


svgDoc.Root.SetAttributeValue("viewBox", "0 0 8500 20000");
svgDoc.Root.SetAttributeValue("width", svgFreemindMap.SvgWidth);
svgDoc.Root.SetAttributeValue("height", svgFreemindMap.SvgHeight);

if (!string.IsNullOrEmpty(svgFreemindMap.SvgViewBox))
{
svgDoc.Root.SetAttributeValue("viewBox", svgFreemindMap.SvgViewBox);
}
if (!string.IsNullOrEmpty(svgFreemindMap.SvgWidth))
{
svgDoc.Root.SetAttributeValue("width", svgFreemindMap.SvgWidth);
}
if (!string.IsNullOrEmpty(svgFreemindMap.SvgHeight))
{
svgDoc.Root.SetAttributeValue("height", svgFreemindMap.SvgHeight);
}

XNamespace svgNamespace = "http://www.w3.org/2000/svg";
XNamespace xlinkNamespace = "http://www.w3.org/1999/xlink";
Expand Down Expand Up @@ -655,8 +674,21 @@ private void UpdateSvgWithFallacies(SVGFreemindMap svgMap, IList<Fallacy> fallac
// Optionally remove all SVG images
if (svgMap.RemoveImages)
{
var imageTags = svgDoc.Descendants(svgNamespace + "image").ToList();
imageTags.Remove();
switch (this.Format)
{
case MindMapFormat.Freemind:
var imageTags = svgDoc.Descendants(svgNamespace + "image").ToList();
imageTags = imageTags.Where(i => i.Attributes("width").All(wAttr => wAttr.Value != "60")).ToList();
imageTags.Remove();
break;
case MindMapFormat.Freeplane:
var iconGroups = svgDoc.Descendants(svgNamespace + "g").Where(g => g.Elements(svgNamespace + "path").Any(x => x.Attributes("stroke").Any(att => att.Value == "none"))).ToList();
iconGroups.Remove();
break;
default:
throw new ArgumentOutOfRangeException();
}

}
}

Expand Down Expand Up @@ -923,4 +955,10 @@ protected override DocumentConfig GetClone()
return CloneMindMap();
}
}

public enum MindMapFormat
{
Freemind,
Freeplane
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ public class SVGFreemindMap : DocumentConfig, ICloneable

public bool SetSVGNodeAttributes { get; set; }

public string SvgWidth { get; set; } = "200vh";
public string SvgWidth { get; set; }

public string SvgHeight { get; set; } = "450vh";
public string SvgHeight { get; set; }


public string SvgViewBox { get; set; }

public bool WrapNodeByLink { get; set; }

Expand Down

0 comments on commit af992ca

Please sign in to comment.