Skip to content
Permalink
Browse files

Add an 'analyze formulas' button and do the appropriate thing wrt dis…

…abling the analysis button.
  • Loading branch information...
dbarowy committed Mar 4, 2019
1 parent eb4a7d2 commit 8aa4f58793316ca6a8d323f40e255f7856cead9d
Showing with 56 additions and 13 deletions.
  1. +10 −0 ExceLintUI/ExceLintRibbon.Designer.cs
  2. +23 −1 ExceLintUI/ExceLintRibbon.cs
  3. +23 −12 ExceLintUI/WorkbookState.cs

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, graph);
var colormap = currentWorkbook.DrawImmutableClusters(cs_filtered, histo, activeWs, graph, this.analyzeFormulas.Checked);

// if checked, analyze data
if (this.enableDataHighlight.Checked)
@@ -153,6 +153,16 @@ private void button2_Click(object sender, RibbonControlEventArgs e)
}

}

private void analyzeFormulas_Click(object sender, RibbonControlEventArgs e)
{
setUIState(currentWorkbook);
}

private void enableDataHighlight_Click(object sender, RibbonControlEventArgs e)
{
setUIState(currentWorkbook);
}
#endregion BUTTON_HANDLERS

#region EVENTS
@@ -365,16 +375,28 @@ private void setUIState(WorkbookState wbs)
// (gets locked when there is no workbook open)
this.RegularityMap.Enabled = true;

// only enable reveal structure button if at least
// one checkbox is checked
if (this.enableDataHighlight.Checked || this.analyzeFormulas.Checked)
{
this.RegularityMap.Enabled = true;
} else
{
this.RegularityMap.Enabled = false;
}

// only enable viewing heatmaps if we are not in the middle of an analysis
if (wbs.Analyze_Enabled)
{
this.RegularityMap.Label = "Reveal Structure";
this.enableDataHighlight.Enabled = true;
this.analyzeFormulas.Enabled = true;
}
else
{
this.RegularityMap.Label = "Hide Structure";
this.enableDataHighlight.Enabled = false;
this.analyzeFormulas.Enabled = false;
}
}
}
@@ -136,7 +136,14 @@ 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, Graph g)
/**
* Color formulas.
* Takes a parameter colorFormulas because in a data-only analysis,
* it is useful to act as if we had colored formulas instead of
* actually coloring them. This option allows us to return the as-if
* colors for use in data coloring without showing formula colors.
*/
public Dictionary<AST.Address, System.Drawing.Color> DrawImmutableClusters(Clusters clusters, ROInvertedHistogram ih, Worksheet ws, Graph g, bool colorFormulas)
{
// we convert from immutable hashsets because the coloring
// code was written using mutable hashsets
@@ -146,7 +153,7 @@ public ExceLint.EntropyModelBuilder2.EntropyModel2 NewEntropyModelForWorksheet2(
var c2 = new HashSet<AST.Address>(c);
hs.Add(c2);
}
var colors = DrawClustersWithHistogram(hs, ih, ws, g);
var colors = DrawClustersWithHistogram(hs, ih, ws, g, colorFormulas);
_button_Analyze_enabled = false;
return colors;
}
@@ -167,7 +174,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, Graph g)
public Dictionary<AST.Address, System.Drawing.Color> DrawClustersWithHistogram(HashSet<HashSet<AST.Address>> clusters, ROInvertedHistogram ih, Worksheet ws, Graph g, bool colorFormulas)
{
// output
var d = new Dictionary<AST.Address, System.Drawing.Color>();
@@ -209,7 +216,7 @@ public void ClearAllColors(Worksheet ws)

foreach (AST.Address addr in cluster)
{
if (!paintColor(addr, c))
if (!paintColor(addr, c, colorFormulas))
{
protCells.Add(addr);
}
@@ -238,7 +245,7 @@ private bool PaintGradient(AST.Address cell, System.Drawing.Color[] cs)
// if there is only one reference, don't use a gradient
if (cs.Length == 1)
{
return paintColor(cell, cs[0]);
return paintColor(cell, cs[0], true);
}

// check cell protection
@@ -417,7 +424,7 @@ public void flagNext(Worksheet ws)
// paint target
foreach(AST.Address a in fix.Target)
{
paintColor(a, System.Drawing.Color.Green);
paintColor(a, System.Drawing.Color.Green, true);
}

// don't update screen until done
@@ -626,19 +633,23 @@ public bool WorksheetProtected(Worksheet w)
}
}

public bool paintColor(AST.Address cell, System.Drawing.Color c)
public bool paintColor(AST.Address cell, System.Drawing.Color c, bool colorFormulas)
{
// check cell protection
if (unProtect(cell) != ProtectionLevel.None)
{
return false;
}

// get cell COM object
var com = ParcelCOMShim.Address.GetCOMObject(cell, _app);

// highlight cell
com.Interior.Color = c;
if (colorFormulas)
{
// get cell COM object
var com = ParcelCOMShim.Address.GetCOMObject(cell, _app);

com.Interior.Color = c;
}


return true;
}
@@ -653,7 +664,7 @@ public void paintRed(AST.Address cell, double intensity)
var c = System.Drawing.Color.FromArgb(A, R, G, B);

// highlight
paintColor(cell, c);
paintColor(cell, c, true);
}

public void saveColors(Worksheet ws)

0 comments on commit 8aa4f58

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