This question has two parts, a technical part about graphics, and a creative part. I'll accept answers primarily re the first part.
The application is to come up with graphical identicons to distinguish data layers. The approach is to leverage the file system and simply tokenize the paths.
This function takes file paths (as generated by say FileNames
) as input, tokenize them, and use the prefix of a hash code (eg MD5 here) to color the path components.
Using the handy position-coded curry "bullet" operator:
\[Bullet] /: f_[pre___, \[Bullet] , post___] :=
With[{n = Length[List@pre], m = Length[List@post]} ,
Curry[f, Join[Range[n], {n + m + 1}, Range[m] + n]][pre, post] ];
The identicon generator becomes:
pathFlagIdenticon[h_] :=
Query[StringSplit[\[Bullet], "/"]] /*
Query[All,
Hash[\[Bullet], "MD5"] /* IntegerDigits[\[Bullet], 8, 36] /*
Query[1 ;; 3 h] /*
BlockMap[
Query[{Total /* OddQ , (#/7 &) /* Apply[RGBColor]} /*
Replace[{{True, rgb_} :> rgb, {False, rgb_} :>
White}]], \[Bullet], 3]] /* Image /*
ImageRotate[\[Bullet], Pi/2] /*
Show[\[Bullet], ImageSize -> {60, 30}, PlotRange -> {{0, 10}, All},
AspectRatio -> 1/3];
The graphics generated by each path component is a vertical column (currently only using a fraction of the hash string) and multiple path components are arranged horizontally - hence "pathFlag", so all files with the same path prefix share the same vertical stripes starting at left.
This works ok eg, given files:
{".DS_Store",
"Readme.gdoc",
"SUBMISSION/Data/Dictionaries/.DS_Store", "SUBMISSION/Data/Dictionaries/heloc_data_dictionary-2-Original.xlsx",
"SUBMISSION/Data/Dictionaries/heloc_data_dictionary-2.tsv",
"SUBMISSION/Data/Dictionaries/helocDataDictionary-Original.gsheet",
"SUBMISSION/Data/Dictionaries/helocDataDictionary.tsv",
"SUBMISSION/Data/Dictionaries/MaxDelq.gsheet",
"SUBMISSION/Data/.DS_Store"\
...}
Gives:
Dataset[files ][All,
StringDrop[\[Bullet], StringLength[path]] /* {pathFlagIdenticon[4],
Identity}] // Normal // Column
(figure shows just a portion)
However, attempting to improve the graphics to include not just colored squares but also other shapes, eg circles,
graphicsRules = With[{z = 1, au = Automatic},
{
{{n_ /; Mod[n, 3] == 0, rgb_}, pos_} :>
Inset[Graphics@{rgb, Disk[]}, pos, {0, 0}, z],
{{n_ /; Mod[n, 3] == 1, rgb_}, pos_} :>
Inset[Graphics@{rgb, Rectangle[]}, pos, {0, 0}, z],
{{n_ /; Mod[n, 3] == 2, rgb_}, pos_} :>
Inset[Graphics@{White, Rectangle[]}, pos, {0, 0}, z]
}
];
Run into problems with Inset
. So first, what are the appropriate Inset
options to render each cell contained in a unit square?
pathFlagWithShapes[h_] :=
Query[StringSplit[\[Bullet], "/"]] /*
Query[All,
Hash[\[Bullet], "MD5"] /* IntegerDigits[\[Bullet], 8, 36] /*
Query[1 ;; 3 h] /*
BlockMap[Query[{Total , (#/7 &) /* Apply[RGBColor]} ], \[Bullet],
3]] /* MapIndexed[
List /* Replace[graphicsRules], \[Bullet], {2}] /* Graphics /*
ImageRotate[\[Bullet], 0*Pi/2] /*
Show[\[Bullet], ImageSize -> 7 {30, 30}, PlotRange -> {All, All},
AspectRatio -> 1/1, Frame -> True];
The output is not as intended:
Dataset[files ][All,
StringDrop[\[Bullet],
StringLength[path]] /* {pathFlagWithShapes[4], Identity}] //
Normal // Column
Why are the graphics ranges going to ~200 when each is being indexMapped to no more than ~10 path components and each graphics element is supposed to be unit size?
That's the technical graphics question.
In addition to circles, would like to add triangle of various orientations, Harvey balls (disks that span not 2Pi angle but some multiple of Pi/2).
The creative part is, perhaps there are other graphical elements that would make the various paths even more distinguishable?