Skip to content
Permalink
Browse files

Gradient fixes. Ready to go.

  • Loading branch information...
dbarowy committed Mar 3, 2019
1 parent f1b9025 commit eb4a7d27514cd8fa0d788359fe275a34a9ca3f90
@@ -1362,6 +1362,7 @@ Global
{EB5D17BF-060E-41FE-AB6E-E916D68FCBA4}.Release|x86.ActiveCfg = Release|x86
{EB5D17BF-060E-41FE-AB6E-E916D68FCBA4}.Release|x86.Build.0 = Release|x86
{EB5D17BF-060E-41FE-AB6E-E916D68FCBA4}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU
{EB5D17BF-060E-41FE-AB6E-E916D68FCBA4}.SingleImage|Any CPU.Build.0 = Release|Any CPU
{EB5D17BF-060E-41FE-AB6E-E916D68FCBA4}.SingleImage|ARM.ActiveCfg = Release|Any CPU
{EB5D17BF-060E-41FE-AB6E-E916D68FCBA4}.SingleImage|ARM.Build.0 = Release|Any CPU
{EB5D17BF-060E-41FE-AB6E-E916D68FCBA4}.SingleImage|x64.ActiveCfg = Release|Any CPU
@@ -7,6 +7,7 @@
using ROInvertedHistogram = System.Collections.Immutable.ImmutableDictionary<AST.Address, System.Tuple<string, ExceLint.Scope.SelectID, ExceLint.Countable>>;
using Fingerprint = ExceLint.Countable;
using System;
using FastDependenceAnalysis;

namespace ExceLintUI
{
@@ -162,7 +163,7 @@ public ClusterColorer(Clustering cs, double degreeStart, double degreeEnd, doubl
/// degreeEnd = 360 and offset = 45, the effective degreeStart is 45 mod 360 and
/// the effective degreeEnd is 405 mod 360.</param>
/// <param name="ih">An InvertedHistogram so that coloring is fingerprint-sensitive.</param>
public ClusterColorer(Clustering clustering, double degreeStart, double degreeEnd, double offset, ROInvertedHistogram ih)
public ClusterColorer(Clustering clustering, double degreeStart, double degreeEnd, double offset, ROInvertedHistogram ih, Graph g)
{
// merge clusters by fingerprint
var x = MergeClustersByFingerprint(clustering, ih);
@@ -175,9 +176,23 @@ public ClusterColorer(Clustering clustering, double degreeStart, double degreeEn
// rank clusters by their degree and break ties using fingerprint (if given fingerprints)
// also sort clusters so that repainting on subsequent
// runs produces a stable coloring
Cluster[] csSorted =
cs.OrderByDescending(c => neighbors[c].Count)
.ThenBy(c => ih[c.First()].Item3.ToString()).ToArray();
//Cluster[] csSorted =
// cs.OrderByDescending(c => neighbors[c].Count)
// .ThenBy(c => ih[c.First()].Item3.ToString()).ToArray();
// size of biggest cluster
var maxsz = cs.Select(c => c.Count).Max();
var csSorted = cs.OrderBy(hs =>
{
var first = hs.First();
if (!g.isFormula(first))
{
return 0;
}
else
{
return maxsz - hs.Count;
}
}).ThenBy(c => ih[c.First()].Item3.ToString()).ToArray();

// greedily assign colors by degree, largest first;
// aka Welsh-Powell heuristic

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -73,7 +73,7 @@ private void RegularityMap_Click(object sender, RibbonControlEventArgs e)
CurrentWorkbook.saveColors(activeWs);

// paint formulas
var colormap = currentWorkbook.DrawImmutableClusters(cs_filtered, histo, activeWs);
var colormap = currentWorkbook.DrawImmutableClusters(cs_filtered, histo, activeWs, graph);

// if checked, analyze data
if (this.enableDataHighlight.Checked)
@@ -105,7 +105,7 @@ private void RegularityMap_Click(object sender, RibbonControlEventArgs e)
private Clusters ClusterFingerprints(Tuple<AST.Address, Countable>[] fs)
{
// group by fingerprint and turn into ImmutableClustering
var cs = fs.GroupBy(kvp => kvp.Item2);
var cs = fs.GroupBy(kvp => kvp.Item2.LocationFree);
var ctmp = new HashSet<ImmutableHashSet<AST.Address>>();
foreach (var group in cs)
{
@@ -124,10 +124,34 @@ private Clusters ClusterFingerprints(Tuple<AST.Address, Countable>[] fs)
return ctmp.ToImmutableHashSet();
}

private void ClearEverything_Click(object sender, RibbonControlEventArgs e)
/**
* For troubleshooting colorstops, which are largely undocumented
*/
private void button2_Click(object sender, RibbonControlEventArgs e)
{
currentWorkbook.resetTool();
setUIState(currentWorkbook);
var app = Globals.ThisAddIn.Application;

// get cursor location
var cursor = (Excel.Range)app.Selection;

if (cursor.Count == 1)
{
// user selected a single cell
var gradient = (cursor.Interior.Gradient as Excel.LinearGradient);
var cs = gradient.ColorStops;
String s = "";
foreach (var c in cs)
{
var c1 = (Excel.ColorStop)c;
s += "color: " + c1.Color.ToString() + "\n";
s += "tintandshade: " + c1.TintAndShade.ToString() + "\n";
s += "position: " + c1.Position.ToString() + "\n";
s += "themecolor: " + c1.ThemeColor.ToString() + "\n";
s += "------------\n";
}
System.Windows.Forms.MessageBox.Show(s);
}

}
#endregion BUTTON_HANDLERS

@@ -136,7 +136,7 @@ public ExceLint.EntropyModelBuilder2.EntropyModel2 NewEntropyModelForWorksheet2(
return ExceLint.ModelBuilder.initEntropyModel2(_app, conf, g, Progress.NOPProgress());
}

public Dictionary<AST.Address, System.Drawing.Color> DrawImmutableClusters(Clusters clusters, ROInvertedHistogram ih, Worksheet ws)
public Dictionary<AST.Address, System.Drawing.Color> DrawImmutableClusters(Clusters clusters, ROInvertedHistogram ih, Worksheet ws, Graph g)
{
// we convert from immutable hashsets because the coloring
// code was written using mutable hashsets
@@ -146,7 +146,7 @@ public ExceLint.EntropyModelBuilder2.EntropyModel2 NewEntropyModelForWorksheet2(
var c2 = new HashSet<AST.Address>(c);
hs.Add(c2);
}
var colors = DrawClustersWithHistogram(hs, ih, ws);
var colors = DrawClustersWithHistogram(hs, ih, ws, g);
_button_Analyze_enabled = false;
return colors;
}
@@ -167,7 +167,7 @@ public void ClearAllColors(Worksheet ws)
/*
* Colors cells and returns assigned colors
*/
public Dictionary<AST.Address, System.Drawing.Color> DrawClustersWithHistogram(HashSet<HashSet<AST.Address>> clusters, ROInvertedHistogram ih, Worksheet ws)
public Dictionary<AST.Address, System.Drawing.Color> DrawClustersWithHistogram(HashSet<HashSet<AST.Address>> clusters, ROInvertedHistogram ih, Worksheet ws, Graph g)
{
// output
var d = new Dictionary<AST.Address, System.Drawing.Color>();
@@ -180,13 +180,30 @@ public void ClearAllColors(Worksheet ws)
ClearAllColors(ws);

// init cluster color map
ClusterColorer clusterColors = new ClusterColorer(clusters, 0, 360, 180+50, ih);
ClusterColorer clusterColors = new ClusterColorer(clusters, 0, 360, 180+50, ih, g);

// do we stumble across protected cells along the way?
var protCells = new List<AST.Address>();

// size of biggest cluster
var maxsz = clusters.Select(c => c.Count).Max();

// order clusters
var clusters_o = clusters.OrderBy(hs =>
{
var first = hs.First();
if (!g.isFormula(first))
{
return 0;
}
else
{
return maxsz - hs.Count;
}
}).ToArray();

// paint
foreach (var cluster in clusters)
foreach (var cluster in clusters_o)
{
System.Drawing.Color c = clusterColors.GetColor(cluster);

@@ -239,20 +256,23 @@ private bool PaintGradient(AST.Address cell, System.Drawing.Color[] cs)
// set gradient as horizontal
(com.Interior.Gradient as Excel.LinearGradient).Degree = 0;

// clear existing color stops
(com.Interior.Gradient as Excel.LinearGradient).ColorStops.Clear();

// calculate stop increment
var incr = 1.0 / cs.Length;
var incr = 1.0 / (cs.Length - 1);

// first stop
(com.Interior.Gradient as Excel.LinearGradient).ColorStops.Add(.001).Color = cs[0];
(com.Interior.Gradient as Excel.LinearGradient).ColorStops.Add(0).Color = cs[0];

// middle stops
for (int i = 1; i < cs.Length; i++)
for (int i = 1; i < cs.Length - 1; i++)
{
(com.Interior.Gradient as Excel.LinearGradient).ColorStops.Add(.001 + i * incr).Color = cs[i];
(com.Interior.Gradient as Excel.LinearGradient).ColorStops.Add(i * incr).Color = cs[i];
}

// last stop
(com.Interior.Gradient as Excel.LinearGradient).ColorStops.Add(.001).Color = cs[cs.Length - 1];
(com.Interior.Gradient as Excel.LinearGradient).ColorStops.Add(1).Color = cs[cs.Length - 1];

return true;
}
@@ -335,8 +355,11 @@ public void ColorDataWithMap(Dictionary<AST.Address, HashSet<AST.Address>> refer
// do we stumble across protected cells along the way?
var protCells = new List<AST.Address>();

// order referents
var referents_o = referents.ToArray();

// paint
foreach (var kvp in referents)
foreach (var kvp in referents_o)
{
// grab formula refs, sort by address,
// then select colors
@@ -350,8 +350,9 @@
<row><td>ExceLintUI.Content_Files</td><td>{44A57184-731F-463C-8C65-3389B15C06C6}</td><td>INSTALLDIR</td><td>2</td><td/><td>excelintui.content_files</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
<row><td>ExceLintUI.Primary_output</td><td>{746545FA-9E00-463B-81AF-CE217AF26A4B}</td><td>INSTALLDIR</td><td>2</td><td/><td>excelintui.primary_output</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
<row><td>ExcelParser.Primary_Output</td><td>{58BE93BF-3CB1-4FAE-BB23-59BDD1C37C8B}</td><td>INSTALLDIR</td><td>2</td><td/><td>excelparser.primary_output</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
<row><td>ExcelParser.Primary_Output1</td><td>{2BB8087C-9FD2-4147-A35A-28D894B6320E}</td><td>INSTALLDIR</td><td>2</td><td/><td>excelparser.primary_output</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
<row><td>ExcelParser.Primary_Output1</td><td>{8A5948D1-F8F1-489A-B91F-234D24ED7DE6}</td><td>INSTALLDIR</td><td>2</td><td/><td>excelparser.primary_output</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
<row><td>ExcelParserConsole.Primary_Output</td><td>{20E4350E-5010-4C98-8DA1-CA47CE089A93}</td><td>INSTALLDIR</td><td>2</td><td/><td>excelparserconsole.primary_o</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
<row><td>ExcelParserConsole.Primary_Output1</td><td>{01943864-5DCB-4402-BC9C-1F5F2DF97351}</td><td>INSTALLDIR</td><td>2</td><td/><td>excelparserconsole.primary_o</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
<row><td>FParsec.Primary_Output</td><td>{A7230356-8961-4E4E-9E5D-16E912D2D0DB}</td><td>INSTALLDIR</td><td>2</td><td/><td>fparsec.primary_output</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
<row><td>FParsec.Primary_Output1</td><td>{F1C514C0-0113-4A3E-BA88-6D67B96EFB28}</td><td>INSTALLDIR</td><td>2</td><td/><td>fparsec.primary_output</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
<row><td>FParsecCS.Primary_output</td><td>{8271F1C2-668F-47F4-8CEA-EAD4A0EC0831}</td><td>INSTALLDIR</td><td>2</td><td/><td>fparseccs.primary_output</td><td>17</td><td/><td/><td/><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td><td>/LogFile=</td></row>
@@ -1897,6 +1898,7 @@
<row><td>AlwaysInstall</td><td>ExcelParser.Primary_Output</td></row>
<row><td>AlwaysInstall</td><td>ExcelParser.Primary_Output1</td></row>
<row><td>AlwaysInstall</td><td>ExcelParserConsole.Primary_Output</td></row>
<row><td>AlwaysInstall</td><td>ExcelParserConsole.Primary_Output1</td></row>
<row><td>AlwaysInstall</td><td>FParsec.Primary_Output</td></row>
<row><td>AlwaysInstall</td><td>FParsec.Primary_Output1</td></row>
<row><td>AlwaysInstall</td><td>FParsecCS.Primary_output</td></row>
@@ -1934,6 +1936,7 @@
<row><td>excelintui.primary_output</td><td>ExceLintUI.Primary_output</td><td>ExceLintUI.Primary output</td><td>0</td><td/><td/><td/><td>1</td><td>&lt;ExceLintUI&gt;|Built</td><td>3</td><td/></row>
<row><td>excelintui.vsto</td><td>ISX_DEFAULTCOMPONENT</td><td>EXCELI~1.VST|ExceLintUI.vsto</td><td>0</td><td/><td/><td/><td>1</td><td>&lt;VSSolutionFolder&gt;\ExceLintUI\bin\Debug\ExceLintUI.vsto</td><td>1</td><td/></row>
<row><td>excelparser.primary_output</td><td>ExcelParser.Primary_Output1</td><td>ExcelParser.Primary Output</td><td>0</td><td/><td/><td/><td>1</td><td>&lt;ExcelParser1&gt;|Built</td><td>3</td><td/></row>
<row><td>excelparserconsole.primary_o</td><td>ExcelParserConsole.Primary_Output1</td><td>ExcelParserConsole.Primary Output</td><td>0</td><td/><td/><td/><td>1</td><td>&lt;ExcelParserConsole1&gt;|Built</td><td>3</td><td/></row>
<row><td>fastdependenceanalysis.prima</td><td>FastDependenceAnalysis.Primary_output</td><td>FastDependenceAnalysis.Primary output</td><td>0</td><td/><td/><td/><td>1</td><td>&lt;FastDependenceAnalysis&gt;|Built</td><td>3</td><td/></row>
<row><td>fparsec.primary_output</td><td>FParsec.Primary_Output1</td><td>FParsec.Primary Output</td><td>0</td><td/><td/><td/><td>1</td><td>&lt;FParsec1&gt;|Built</td><td>3</td><td/></row>
<row><td>fparseccs.primary_output</td><td>FParsecCS.Primary_output1</td><td>FParsecCS.Primary output</td><td>0</td><td/><td/><td/><td>1</td><td>&lt;FParsecCS1&gt;|Built</td><td>3</td><td/></row>
@@ -2092,8 +2095,9 @@
<row><td>ExceLintUI.Content_Files</td><td/><td/><td>_0A776A07_6591_4BB6_A933_D20E6CCAD96D_FILTER</td><td/><td/><td/><td/></row>
<row><td>ExceLintUI.Primary_output</td><td/><td/><td>_F22DDAED_4541_4137_9CD8_53FF3702D14D_FILTER</td><td/><td/><td/><td/></row>
<row><td>ExcelParser.Primary_Output</td><td/><td/><td>_187C4082_C24D_4C9C_AEB8_946B8ADA1BEF_FILTER</td><td/><td/><td/><td/></row>
<row><td>ExcelParser.Primary_Output1</td><td/><td/><td>_0240F5AC_740E_4E7B_9144_0C30E5271569_FILTER</td><td/><td/><td/><td/></row>
<row><td>ExcelParser.Primary_Output1</td><td/><td/><td>_D205270D_4D7B_4F3F_A9E9_931371F02101_FILTER</td><td/><td/><td/><td/></row>
<row><td>ExcelParserConsole.Primary_Output</td><td/><td/><td>_F98D1558_4C8B_4510_9554_208F0705D1AE_FILTER</td><td/><td/><td/><td/></row>
<row><td>ExcelParserConsole.Primary_Output1</td><td/><td/><td>_0ABBF234_FC86_4B2A_969B_80635E907FB6_FILTER</td><td/><td/><td/><td/></row>
<row><td>FParsec.Primary_Output</td><td/><td/><td>_67AA6D17_6FE7_4AAF_93D9_C78F26A6292C_FILTER</td><td/><td/><td/><td/></row>
<row><td>FParsec.Primary_Output1</td><td/><td/><td>_8273E257_7323_4C33_955C_9C77DC43A73A_FILTER</td><td/><td/><td/><td/></row>
<row><td>FParsecCS.Primary_output</td><td/><td/><td>_83FECCB4_E0D9_459F_B7C6_297A5420FC60_FILTER</td><td/><td/><td/><td/></row>
@@ -2398,6 +2402,7 @@
<row><td>ExcelParser</td><td>Depends\parcel\Parcel\ExcelParser.fsproj</td><td/><td>2</td></row>
<row><td>ExcelParser1</td><td>parcel\Parcel\ExcelParser.fsproj</td><td/><td>2</td></row>
<row><td>ExcelParserConsole</td><td>Depends\parcel\ParcelConsole\ExcelParserConsole.fsproj</td><td/><td>2</td></row>
<row><td>ExcelParserConsole1</td><td>parcel\ParcelConsole\ExcelParserConsole.fsproj</td><td/><td>2</td></row>
<row><td>FParsec</td><td>Depends\parcel\FParsec\FParsec.fsproj</td><td/><td>2</td></row>
<row><td>FParsec1</td><td>parcel\FParsec\FParsec.fsproj</td><td/><td>2</td></row>
<row><td>FParsecCS</td><td>Depends\parcel\FParsecCS\FParsecCS.csproj</td><td/><td>2</td></row>
@@ -61,6 +61,10 @@
<Name>ExcelParser</Name>
<Project>{6DE2A2B9-C029-4BDB-8992-D16276471D9F}</Project>
</ProjectReference>
<ProjectReference Include="..\parcel\ParcelConsole\ExcelParserConsole.fsproj">
<Name>ExcelParserConsole</Name>
<Project>{EB5D17BF-060E-41FE-AB6E-E916D68FCBA4}</Project>
</ProjectReference>
<ProjectReference Include="..\parcel\FParsec\FParsec.fsproj">
<Name>FParsec</Name>
<Project>{D8A416FA-BE7D-4929-8A6A-DA28B206853C}</Project>

0 comments on commit eb4a7d2

Please sign in to comment.
You can’t perform that action at this time.