Skip to content

Commit

Permalink
Merge branch 'ChartPalette'
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Nov 28, 2022
2 parents 3c00014 + d7b004c commit 838eea1
Show file tree
Hide file tree
Showing 46 changed files with 994 additions and 709 deletions.
164 changes: 15 additions & 149 deletions Signum.Engine.Extensions/Chart/ChartColorLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,171 +4,37 @@

namespace Signum.Engine.Chart;

public static class ChartColorLogic
public static class ColorPaletteLogic
{
public static ResetLazy<Dictionary<Type, Dictionary<PrimaryKey, string>>> Colors = null!;
public static ResetLazy<Dictionary<Type, ColorPaletteEntity>> ColorPaletteCache = null!;

public static readonly int Limit = 360;

internal static void Start(SchemaBuilder sb)
{
if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
{
sb.Include<ChartColorEntity>()
sb.Include<ColorPaletteEntity>()
.WithSave(ColorPaletteOperation.Save)
.WithDelete(ColorPaletteOperation.Delete)
.WithQuery(() => cc => new
{
Entity = cc,
cc.Related,
cc.Color,
cc.Id,
cc.Type,
cc.CategoryName,
cc.Seed,
});

Colors = sb.GlobalLazy(() =>
Database.Query<ChartColorEntity>()
.Select(cc => new { cc.Related.EntityType, cc.Related.Id, cc.Color })
.AgGroupToDictionary(a => a.EntityType!, gr => gr.ToDictionary(a => a.Id, a => a.Color)),
new InvalidateWith(typeof(ChartColorEntity)));
ColorPaletteCache = sb.GlobalLazy(() =>
Database.Query<ColorPaletteEntity>()
.ToDictionaryEx(cc => cc.Type.ToType()),
new InvalidateWith(typeof(ColorPaletteEntity)));
}
}

public static Dictionary<string, string> Palettes = new Dictionary<string,string>(){
{"Category10", "#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf"},
{"Category20", "#1f77b4 #aec7e8 #ff7f0e #ffbb78 #2ca02c #98df8a #d62728 #ff9896 #9467bd #c5b0d5 #8c564b #c49c94 #e377c2 #f7b6d2 #7f7f7f #c7c7c7 #bcbd22 #dbdb8d #17becf #9edae5"},
{"Category20b", "#393b79 #5254a3 #6b6ecf #9c9ede #637939 #8ca252 #b5cf6b #cedb9c #8c6d31 #bd9e39 #e7ba52 #e7cb94 #843c39 #ad494a #d6616b #e7969c #7b4173 #a55194 #ce6dbd #de9ed6"},
{"Category20c", "#3182bd #6baed6 #9ecae1 #c6dbef #e6550d #fd8d3c #fdae6b #fdd0a2 #31a354 #74c476 #a1d99b #c7e9c0 #756bb1 #9e9ac8 #bcbddc #dadaeb #636363 #969696 #bdbdbd #d9d9d9"},
};

public static void CreateNewPalette(Type type, string palette)
{
AssertFewEntities(type);

var dic = Database.RetrieveAllLite(type).Select(l => new ChartColorEntity { Related = (Lite<Entity>)l }).ToDictionary(a => a.Related);

dic.SetRange(Database.Query<ChartColorEntity>().Where(c => c.Related.EntityType == type).ToDictionary(a => a.Related));

var list = dic.Values.ToList();

var cats = Palettes.GetOrThrow(palette).Split(' ');

for (int i = 0; i < list.Count; i++)
{
list[i].Color = cats[i % cats.Length];
}

list.SaveList();
}

public static void AssertFewEntities(Type type)
{
int count = giCount.GetInvoker(type)();

if (count > Limit)
throw new ApplicationException("Too many {0} ({1}), maximum is {2}".FormatWith(type.NicePluralName(), count, Limit));
}

public static bool HasTooManyEntities(Type type, out int count)
{
count = giCount.GetInvoker(type)();

return count > Limit;
}

public static void SavePalette(ChartPaletteModel model)
{
using (var tr = new Transaction())
{
Type type = TypeLogic.GetType(model.TypeName);

giDeleteColors.GetInvoker(type)();

model.Colors.Where(a => a.Color != null).SaveList();
tr.Commit();
}
}


static readonly GenericInvoker<Func<int>> giCount = new(() => Count<Entity>());
static int Count<T>() where T : Entity
{
return Database.Query<T>().Count();
}

static readonly GenericInvoker<Func<int>> giDeleteColors = new(() => DeleteColors<Entity>());
static int DeleteColors<T>() where T : Entity
{
return (from t in Database.Query<T>() // To filter by type conditions
join cc in Database.Query<ChartColorEntity>() on t.ToLite() equals cc.Related
select cc).UnsafeDelete();
}

public static ChartPaletteModel? GetPalette(Type type, bool allEntities)
{
var dic = ChartColorLogic.Colors.Value.TryGetC(type);

if (allEntities)
{
AssertFewEntities(type);

return new ChartPaletteModel
{
TypeName = TypeLogic.GetCleanName(type),
Colors = Database.RetrieveAllLite(type).Select(l => new ChartColorEntity
{
Related = (Lite<Entity>)l,
Color = dic?.TryGetC(l.Id)!
}).ToMList()
};
}
else
{
if (dic == null)
return null;

if (EnumEntity.IsEnumEntity(type))
{
var lites = EnumEntity.GetEntities(EnumEntity.Extract(type)!).ToDictionary(a => a.Id, a => a.ToLite());

return new ChartPaletteModel
{
TypeName = type.ToTypeEntity().CleanName,
Colors = dic.Select(kvp => new ChartColorEntity
{
Related = lites.GetOrThrow(kvp.Key),
Color = kvp.Value
}).ToMList()
};
}
else
{
return new ChartPaletteModel
{
TypeName = type.ToTypeEntity().CleanName,
Colors = dic.Select(kvp => new ChartColorEntity
{
Related = Lite.Create(type, kvp.Key),
Color = kvp.Value
}).ToMList()
};
}
}
}

public static string? ColorFor(Type type, PrimaryKey id)
{
return Colors.Value.TryGetC(type)?.TryGetC(id);
}

public static string? ColorFor(Lite<Entity> lite)
{
return ColorFor(lite.EntityType, lite.Id);
}

public static string? ColorFor(Entity ident)
{
return ColorFor(ident.GetType(), ident.Id);
}

public static void DeletePalette(Type type)
public static string? ColorFor(Entity entity)
{
Database.Query<ChartColorEntity>().Where(c => c.Related.EntityType == type).UnsafeDelete();
return ColorPaletteCache.Value.TryGetC(entity.GetType())?.SpecificColors.SingleEx(a => a.Entity.Is(entity))?.Color;
}
}
2 changes: 1 addition & 1 deletion Signum.Engine.Extensions/Chart/ChartLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void Start(SchemaBuilder sb, bool googleMapsChartScripts, string[]

PermissionAuthLogic.RegisterTypes(typeof(ChartPermission));

ChartColorLogic.Start(sb);
ColorPaletteLogic.Start(sb);
ChartScriptLogic.Start(sb, googleMapsChartScripts, svgMapUrls);
UserChartLogic.Start(sb);
}
Expand Down
3 changes: 1 addition & 2 deletions Signum.Engine.Extensions/Chart/Scripts/Bars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public BarsChartScript(): base(D3ChartScript.Bars)
},
new ChartScriptParameterGroup("Color Category")
{
new ChartScriptParameter("ColorCategory", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("category10|accent|dark2|paired|pastel1|pastel2|set1|set2|set3|BrBG[K]|PRGn[K]|PiYG[K]|PuOr[K]|RdBu[K]|RdGy[K]|RdYlBu[K]|RdYlGn[K]|Spectral[K]|Blues[K]|Greys[K]|Oranges[K]|Purples[K]|Reds[K]|BuGn[K]|BuPu[K]|OrRd[K]|PuBuGn[K]|PuBu[K]|PuRd[K]|RdPu[K]|YlGnBu[K]|YlGn[K]|YlOrBr[K]|YlOrRd[K]") },
new ChartScriptParameter("ColorCategorySteps", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("3|4|5|6|7|8|9|10|11") }
new ChartScriptParameter("ColorCategory", ChartParameterType.Special) { ValueDefinition = new SpecialParameter(SpecialParameterType.ColorCategory) },
}
};
}
Expand Down
5 changes: 2 additions & 3 deletions Signum.Engine.Extensions/Chart/Scripts/BubblePack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ public BubblePackChartScript() : base(D3ChartScript.BubblePack)
new ChartScriptParameterGroup("Color Scale")
{
new ChartScriptParameter("ColorScale", ChartParameterType.Enum) { ColumnIndex = 3, ValueDefinition = EnumValueList.Parse("ZeroMax|MinMax|Sqrt|Log") },
new ChartScriptParameter("ColorInterpolate", ChartParameterType.Enum) { ColumnIndex = 3, ValueDefinition = EnumValueList.Parse("YlGn|YlGnBu|GnBu|BuGn|PuBuGn|PuBu|BuPu|RdPu|PuRd|OrRd|YlOrRd|YlOrBr|Purples|Blues|Greens|Oranges|Reds|Greys|PuOr|BrBG|PRGn|PiYG|RdBu|RdGy|RdYlBu|Spectral|RdYlGn") },
new ChartScriptParameter("ColorInterpolate", ChartParameterType.Special) { ColumnIndex = 3, ValueDefinition = new SpecialParameter(SpecialParameterType.ColorInterpolate) },
},
new ChartScriptParameterGroup("Color Category")
{
new ChartScriptParameter("ColorCategory", ChartParameterType.Enum) { ColumnIndex = 4, ValueDefinition = EnumValueList.Parse("category10|accent|dark2|paired|pastel1|pastel2|set1|set2|set3|BrBG[K]|PRGn[K]|PiYG[K]|PuOr[K]|RdBu[K]|RdGy[K]|RdYlBu[K]|RdYlGn[K]|Spectral[K]|Blues[K]|Greys[K]|Oranges[K]|Purples[K]|Reds[K]|BuGn[K]|BuPu[K]|OrRd[K]|PuBuGn[K]|PuBu[K]|PuRd[K]|RdPu[K]|YlGnBu[K]|YlGn[K]|YlOrBr[K]|YlOrRd[K]") },
new ChartScriptParameter("ColorCategorySteps", ChartParameterType.Enum) { ColumnIndex = 4, ValueDefinition = EnumValueList.Parse("3|4|5|6|7|8|9|10|11") },
new ChartScriptParameter("ColorCategory", ChartParameterType.Special) { ColumnIndex = 4, ValueDefinition = new SpecialParameter(SpecialParameterType.ColorCategory) },
},
};
}
Expand Down
5 changes: 2 additions & 3 deletions Signum.Engine.Extensions/Chart/Scripts/Bubbleplot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ public BubbleplotChartScript() : base(D3ChartScript.Bubbleplot)
new ChartScriptParameterGroup("Color Scale")
{
new ChartScriptParameter("ColorScale", ChartParameterType.Enum) { ColumnIndex = 0, ValueDefinition = EnumValueList.Parse("Ordinal|ZeroMax|MinMax|Sqrt|Log") },
new ChartScriptParameter("ColorInterpolate", ChartParameterType.Enum) { ColumnIndex = 0, ValueDefinition = EnumValueList.Parse("YlGn|YlGnBu|GnBu|BuGn|PuBuGn|PuBu|BuPu|RdPu|PuRd|OrRd|YlOrRd|YlOrBr|Purples|Blues|Greens|Oranges|Reds|Greys|PuOr|BrBG|PRGn|PiYG|RdBu|RdGy|RdYlBu|Spectral|RdYlGn") },
new ChartScriptParameter("ColorInterpolate", ChartParameterType.Special) { ColumnIndex = 0, ValueDefinition = new SpecialParameter(SpecialParameterType.ColorInterpolate) },
},
new ChartScriptParameterGroup("Color Category")
{
new ChartScriptParameter("ColorCategory", ChartParameterType.Enum) { ColumnIndex = 0, ValueDefinition = EnumValueList.Parse("category10|accent|dark2|paired|pastel1|pastel2|set1|set2|set3|BrBG[K]|PRGn[K]|PiYG[K]|PuOr[K]|RdBu[K]|RdGy[K]|RdYlBu[K]|RdYlGn[K]|Spectral[K]|Blues[K]|Greys[K]|Oranges[K]|Purples[K]|Reds[K]|BuGn[K]|BuPu[K]|OrRd[K]|PuBuGn[K]|PuBu[K]|PuRd[K]|RdPu[K]|YlGnBu[K]|YlGn[K]|YlOrBr[K]|YlOrRd[K]") },
new ChartScriptParameter("ColorCategorySteps", ChartParameterType.Enum) { ColumnIndex = 0, ValueDefinition = EnumValueList.Parse("3|4|5|6|7|8|9|10|11") },
new ChartScriptParameter("ColorCategory", ChartParameterType.Special) { ColumnIndex = 0, ValueDefinition = new SpecialParameter(SpecialParameterType.ColorCategory) },
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine.Extensions/Chart/Scripts/CalendarStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CalendarStreamChartScript() : base(D3ChartScript.CalendarStream)
{
new ChartScriptParameter("StartDate", ChartParameterType.Enum) { ColumnIndex = 0, ValueDefinition = EnumValueList.Parse("Monday|Sunday") },
new ChartScriptParameter("ColorScale", ChartParameterType.Enum) { ColumnIndex = 1, ValueDefinition = EnumValueList.Parse("ZeroMax|MinMax|Sqrt|Log") },
new ChartScriptParameter("ColorInterpolate", ChartParameterType.Enum) { ColumnIndex = 1, ValueDefinition = EnumValueList.Parse("YlGn|YlGnBu|GnBu|BuGn|PuBuGn|PuBu|BuPu|RdPu|PuRd|OrRd|YlOrRd|YlOrBr|Purples|Blues|Greens|Oranges|Reds|Greys|PuOr|BrBG|PRGn|PiYG|RdBu|RdGy|RdYlBu|Spectral|RdYlGn") },
new ChartScriptParameter("ColorInterpolate", ChartParameterType.Special) { ColumnIndex = 1, ValueDefinition = new SpecialParameter(SpecialParameterType.ColorInterpolate) },
}
};
}
Expand Down
3 changes: 1 addition & 2 deletions Signum.Engine.Extensions/Chart/Scripts/Columns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public ColumnsChartScript() : base(D3ChartScript.Columns)
},
new ChartScriptParameterGroup("Color")
{
new ChartScriptParameter("ColorCategory", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("category10|accent|dark2|paired|pastel1|pastel2|set1|set2|set3|BrBG[K]|PRGn[K]|PiYG[K]|PuOr[K]|RdBu[K]|RdGy[K]|RdYlBu[K]|RdYlGn[K]|Spectral[K]|Blues[K]|Greys[K]|Oranges[K]|Purples[K]|Reds[K]|BuGn[K]|BuPu[K]|OrRd[K]|PuBuGn[K]|PuBu[K]|PuRd[K]|RdPu[K]|YlGnBu[K]|YlGn[K]|YlOrBr[K]|YlOrRd[K]") },
new ChartScriptParameter("ColorCategorySteps", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("3|4|5|6|7|8|9|10|11") },
new ChartScriptParameter("ColorCategory", ChartParameterType.Special) { ValueDefinition = new SpecialParameter(SpecialParameterType.ColorCategory) },
new ChartScriptParameter("ForceColor", ChartParameterType.String) { ValueDefinition = new StringValue("") },
}
};
Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine.Extensions/Chart/Scripts/Heatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public HeatmapChartScript() : base(GoogleMapsChartScript.Heatmap)
},
new ChartScriptParameterGroup("Color Gradient")
{
new ChartScriptParameter("ColorGradient", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("Default|Blue-Red|Purple-Blue|Orange-Red|Fire|Emerald|Cobalt|Purples|Greys") },
new ChartScriptParameter("ColorInterpolate", ChartParameterType.Special) { ValueDefinition = new SpecialParameter(SpecialParameterType.ColorInterpolate) },
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions Signum.Engine.Extensions/Chart/Scripts/Markermap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public MarkermapChartScript(): base(GoogleMapsChartScript.Markermap)
new ChartScriptParameterGroup()
{
new ChartScriptParameter("ColorScale", ChartParameterType.Enum) { ColumnIndex = 6, ValueDefinition = EnumValueList.Parse("ZeroMax|MinMax|Sqrt|Log") },
new ChartScriptParameter("ColorSet", ChartParameterType.Enum) { ColumnIndex = 6, ValueDefinition = EnumValueList.Parse("YlGn|YlGnBu|GnBu|BuGn|PuBuGn|PuBu|BuPu|RdPu|PuRd|OrRd|YlOrRd|YlOrBr|Purples|Blues|Greens|Oranges|Reds|Greys|PuOr|BrBG|PRGn|PiYG|RdBu|RdGy|RdYlBu|Spectral|RdYlGn") },
new ChartScriptParameter("ColorCategory", ChartParameterType.Enum) { ColumnIndex = 7, ValueDefinition = EnumValueList.Parse("category10|category20|category20b|category20c|accent|paired|pastel1|pastel2|set1|set2|set3") }
new ChartScriptParameter("ColorInterpolation", ChartParameterType.Special) { ColumnIndex = 6, ValueDefinition = new SpecialParameter(SpecialParameterType.ColorInterpolate) },
new ChartScriptParameter("ColorCategory", ChartParameterType.Special) { ColumnIndex = 7, ValueDefinition = new SpecialParameter(SpecialParameterType.ColorCategory)}
},
new ChartScriptParameterGroup("Zoom")
{
Expand Down
3 changes: 1 addition & 2 deletions Signum.Engine.Extensions/Chart/Scripts/MultiBars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public MultiBarsChartScript() : base(D3ChartScript.MultiBars)
},
new ChartScriptParameterGroup("Color")
{
new ChartScriptParameter("ColorCategory", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("category10|accent|dark2|paired|pastel1|pastel2|set1|set2|set3|BrBG[K]|PRGn[K]|PiYG[K]|PuOr[K]|RdBu[K]|RdGy[K]|RdYlBu[K]|RdYlGn[K]|Spectral[K]|Blues[K]|Greys[K]|Oranges[K]|Purples[K]|Reds[K]|BuGn[K]|BuPu[K]|OrRd[K]|PuBuGn[K]|PuBu[K]|PuRd[K]|RdPu[K]|YlGnBu[K]|YlGn[K]|YlOrBr[K]|YlOrRd[K]") },
new ChartScriptParameter("ColorCategorySteps", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("3|4|5|6|7|8|9|10|11") }
new ChartScriptParameter("ColorCategory", ChartParameterType.Special) { ValueDefinition = new SpecialParameter(SpecialParameterType.ColorCategory) },
}
};
}
Expand Down
3 changes: 1 addition & 2 deletions Signum.Engine.Extensions/Chart/Scripts/MultiColumns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public MultiColumnsChartScript() : base(D3ChartScript.MultiColumns)
},
new ChartScriptParameterGroup("Color Category")
{
new ChartScriptParameter("ColorCategory", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("category10|accent|dark2|paired|pastel1|pastel2|set1|set2|set3|BrBG[K]|PRGn[K]|PiYG[K]|PuOr[K]|RdBu[K]|RdGy[K]|RdYlBu[K]|RdYlGn[K]|Spectral[K]|Blues[K]|Greys[K]|Oranges[K]|Purples[K]|Reds[K]|BuGn[K]|BuPu[K]|OrRd[K]|PuBuGn[K]|PuBu[K]|PuRd[K]|RdPu[K]|YlGnBu[K]|YlGn[K]|YlOrBr[K]|YlOrRd[K]") },
new ChartScriptParameter("ColorCategorySteps", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("3|4|5|6|7|8|9|10|11") }
new ChartScriptParameter("ColorCategory", ChartParameterType.Special) { ValueDefinition = new SpecialParameter(SpecialParameterType.ColorCategory) },
}
};
}
Expand Down
3 changes: 1 addition & 2 deletions Signum.Engine.Extensions/Chart/Scripts/MultiLines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public MultiLinesChartScript(): base(D3ChartScript.MultiLines)
},
new ChartScriptParameterGroup("Color Category")
{
new ChartScriptParameter("ColorCategory", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("category10|accent|dark2|paired|pastel1|pastel2|set1|set2|set3|BrBG[K]|PRGn[K]|PiYG[K]|PuOr[K]|RdBu[K]|RdGy[K]|RdYlBu[K]|RdYlGn[K]|Spectral[K]|Blues[K]|Greys[K]|Oranges[K]|Purples[K]|Reds[K]|BuGn[K]|BuPu[K]|OrRd[K]|PuBuGn[K]|PuBu[K]|PuRd[K]|RdPu[K]|YlGnBu[K]|YlGn[K]|YlOrBr[K]|YlOrRd[K]") },
new ChartScriptParameter("ColorCategorySteps", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("3|4|5|6|7|8|9|10|11") }
new ChartScriptParameter("ColorCategory", ChartParameterType.Special) { ValueDefinition = new SpecialParameter(SpecialParameterType.ColorCategory) },
},
new ChartScriptParameterGroup("Form")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ParallelCoordiantesChartScript(): base(D3ChartScript.ParallelCoordinates)
},
new ChartScriptParameterGroup("Color")
{
new ChartScriptParameter("ColorInterpolate", ChartParameterType.Enum) { ValueDefinition = EnumValueList.Parse("YlGn|YlGnBu|GnBu|BuGn|PuBuGn|PuBu|BuPu|RdPu|PuRd|OrRd|YlOrRd|YlOrBr|Purples|Blues|Greens|Oranges|Reds|Greys|PuOr|BrBG|PRGn|PiYG|RdBu|RdGy|RdYlBu|Spectral|RdYlGn") },
new ChartScriptParameter("ColorInterpolate", ChartParameterType.Special) { ValueDefinition = new SpecialParameter(SpecialParameterType.ColorInterpolate) },
},
new ChartScriptParameterGroup("Form")
{
Expand Down
Loading

3 comments on commit 838eea1

@olmobrutall
Copy link
Collaborator Author

@olmobrutall olmobrutall commented on 838eea1 Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ColorPalette changes

This commit merges a few changes related to chart coloring.

Color Category Combo

New dropdown list in Chart settings to determine the colors of discrete categories, now with preview:

image

Color Scale Combo

New dropdown list in Chart settings to determine the color for values, like in BubblePack, ParallelCoordinates or CalendarStream (maybe makes sense too on Scatterplot / Bubbleplot)?

image

ChartColorEntity -> ChartPaletteEntity

image

ChartColorEntity has been removed. This entity was typically modified using Create / View Palette from Chart settings. And opened a modal (ChartPaletteModel) to determine a stable hard-coded color for a particular instance (using ImplementedByAll)

Unfortunately this approach didn't work for entities with a growing amount of instances, like Users. For this makes more sense to determine a color palette at the type level and automatically calculate an stable color for each instance based on the Id plus a random seed.

image

For enums or low population entities where we want to give a semantic meaning to the color, we can still specify specific colors:

image

How to Update

If you have ChartColorEntity already configured in your application that you want to preserve, feel free to use this snippet in your SQL Migration:

CREATE TABLE chart.ColorPalette(
ID INT IDENTITY NOT NULL,
Ticks BIGINT NOT NULL,
TypeID INT NOT NULL,
CategoryName NVARCHAR(100) NOT NULL,
Seed INT NOT NULL,
CONSTRAINT [PK_chart_ColorPalette] PRIMARY KEY CLUSTERED (ID ASC)
);

EXEC SP_RENAME 'chart.ChartColor' , 'ColorPaletteSpecificColors';
ALTER TABLE chart.ColorPaletteSpecificColors ADD ParentID INT NOT NULL CONSTRAINT DF_TEMP_ParentID DEFAULT 0;
ALTER TABLE chart.ColorPaletteSpecificColors DROP CONSTRAINT [DF_TEMP_ParentID];
ALTER TABLE chart.ColorPaletteSpecificColors ADD [Order] INT NOT NULL CONSTRAINT DF_TEMP_Order DEFAULT 0;
ALTER TABLE chart.ColorPaletteSpecificColors DROP CONSTRAINT [DF_TEMP_Order];
EXEC SP_RENAME 'chart.ColorPaletteSpecificColors.RelatedID_Type' , 'EntityID_Type', 'COLUMN';
EXEC SP_RENAME 'chart.ColorPaletteSpecificColors.RelatedID_Int32' , 'EntityID_Int32', 'COLUMN';
EXEC SP_RENAME 'chart.ColorPaletteSpecificColors.RelatedID_Guid' , 'EntityID_Guid', 'COLUMN';
ALTER TABLE chart.ColorPaletteSpecificColors DROP COLUMN ToStr;
GO

SET IDENTITY_INSERT chart.ColorPalette ON;  
INSERT INTO chart.ColorPalette(Id, Ticks, TypeId, CategoryName, Seed)
SELECT DISTINCT EntityID_Type, 0, EntityID_Type, 'fluent', 1
FROM chart.ColorPaletteSpecificColors
SET IDENTITY_INSERT chart.ColorPalette OFF;  

UPDATE chart.ColorPaletteSpecificColors
SET ParentId = EntityID_Type

ALTER TABLE chart.ColorPalette ADD CONSTRAINT [FK_ColorPalette_TypeID] FOREIGN KEY (TypeID) REFERENCES framework.Type(ID);

ALTER TABLE chart.ColorPaletteSpecificColors ADD CONSTRAINT [FK_ColorPaletteSpecificColors_ParentID] FOREIGN KEY (ParentID) REFERENCES chart.ColorPalette(ID);
EXEC SP_RENAME 'chart.[FK_ChartColor_RelatedID_Type]' , 'FK_ColorPaletteSpecificColors_EntityID_Type', 'OBJECT';


CREATE UNIQUE INDEX [UIX_ColorPalette_TypeID] ON chart.ColorPalette(TypeID);

CREATE INDEX [IX_ColorPaletteSpecificColors_ParentID] ON chart.ColorPaletteSpecificColors(ParentID);
EXEC SP_RENAME 'chart.ColorPaletteSpecificColors.UIX_ChartColor_RelatedID_Type_RelatedID_Int32_RelatedID_Guid' , 'UIX_ColorPaletteSpecificColors_EntityID_Type_EntityID_Int32_EntityID_Guid', 'INDEX';

Remaining things

  • Import/Export pallete to XML using the UserAsset infrastructure
  • Move ColorPalette out of Charting Module and using it also for UserCircle control.

Any help?

@mehdy-karimpour
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely Awesome👍

@goldenauge
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very helpfull for us! :)

Please sign in to comment.