/// <summary> /// Renders the tree using ELK.js. /// </summary> private async Task <string> RenderTree(INodeServices js, TreeLayoutVM tree) { var json = JsonConvert.SerializeObject(tree); var result = await js.InvokeAsync <string>("./External/tree/tree-layout.js", json); if (string.IsNullOrEmpty(result)) { throw new Exception("Failed to render tree: output is empty."); } return(result); }
/// <summary> /// Updates the layout. /// </summary> private async Task SaveLayoutAsync(AppDbContext db, TreeLayoutVM tree, TreeLayout layout) { using var conn = db.GetConnection(); await conn.ExecuteAsync( @"INSERT INTO ""TreeLayouts"" (""Id"", ""LayoutJson"", ""GenerationDate"") VALUES (@Id, @LayoutJson, @GenerationDate)", layout ); // sic! dapper generates incorrect query for "GUID IN (@GUIDS)" with parameters foreach (var batch in tree.Persons.Select(x => x.Id).PartitionBySize(100)) { var ids = batch.Select(x => $"'{x}'").JoinString(", "); await conn.ExecuteAsync($@"UPDATE ""Pages"" SET ""TreeLayoutId"" = '{layout.Id}' WHERE ""Id"" IN ({ids})"); } }
/// <summary> /// Renders the tree using ELK.js. /// </summary> private async Task <string> RenderTree(INodeServices js, TreeLayoutVM tree) { var thoroughness = Interpolator.MapValue( _config.GetDynamicConfig().TreeRenderThoroughness, new IntervalMap(1, 10, 1, 10), new IntervalMap(11, 50, 11, 600), new IntervalMap(51, 100, 301, 15000) ); var json = JsonConvert.SerializeObject(tree); var result = await js.InvokeAsync <string>("./External/tree/tree-layout.js", json, thoroughness); if (string.IsNullOrEmpty(result)) { throw new Exception("Failed to render tree: output is empty."); } return(result); }