-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
216 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
using KnowledgePicker.WordCloud.Primitives; | ||
using System.Drawing; | ||
|
||
namespace KnowledgePicker.WordCloud.Coloring | ||
{ | ||
public interface IColorizer | ||
{ | ||
/// <summary> | ||
/// Gets the hex string color for text. | ||
/// Gets color for the specified <paramref name="item"/>. | ||
/// </summary> | ||
/// <returns>Hex string color in format #RRGGBB.</returns> | ||
string GetColorAsHex(); | ||
/// <param name="item">The item being colored.</param> | ||
/// <returns> | ||
/// Can return <see langword="null"/> to use the default color | ||
/// (<see cref="WordCloudInput.TextColor"/>). | ||
/// </returns> | ||
Color? GetColor(LayoutItem item); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/KnowledgePicker.WordCloud/Coloring/SpecificColorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using KnowledgePicker.WordCloud.Primitives; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
|
||
namespace KnowledgePicker.WordCloud.Coloring | ||
{ | ||
/// <summary> | ||
/// Colors specific words with provided colors. | ||
/// </summary> | ||
public class SpecificColorizer : IColorizer | ||
{ | ||
private readonly IReadOnlyDictionary<string, Color> mapping; | ||
private readonly IColorizer? fallback; | ||
|
||
public SpecificColorizer( | ||
IReadOnlyDictionary<string, Color> mapping, | ||
IColorizer? fallback = null) | ||
{ | ||
this.mapping = mapping; | ||
this.fallback = fallback; | ||
} | ||
|
||
public Color? GetColor(LayoutItem item) | ||
{ | ||
if (mapping.TryGetValue(item.Entry.Word, out var color)) | ||
{ | ||
return color; | ||
} | ||
return fallback?.GetColor(item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Drawing; | ||
|
||
namespace KnowledgePicker.WordCloud.Utilities | ||
{ | ||
internal static class ColorUtil | ||
{ | ||
/// <summary> | ||
/// Converts <see cref="Color"/> to hex string. | ||
/// </summary> | ||
public static string ToHexString(this Color c) | ||
{ | ||
return $"#{c.R:X2}{c.G:X2}{c.B:X2}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+486 KB
test/KnowledgePicker.WordCloud.Tests/Assets/specific-colorizer-purple-fallback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+514 KB
test/KnowledgePicker.WordCloud.Tests/Assets/specific-colorizer-random-fallback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.