Skip to content

Commit

Permalink
Current work; not quite there.
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed Jun 16, 2019
1 parent dc50404 commit ff93535
Show file tree
Hide file tree
Showing 10 changed files with 621 additions and 185 deletions.
29 changes: 21 additions & 8 deletions src/components/App.tsx
Expand Up @@ -152,22 +152,34 @@ export default class App extends React.Component<AppProps, AppState> {
console.log("WARNING: ExceLint does not work on protected spreadsheets. Please unprotect the sheet and try again.");
return;
}



let backupName = this.saved_original_sheetname(currentWorksheet.id);
// If it's there already, restore it.
try {
let backupSheet = worksheets.getItemOrNullObject(backupName);
if (backupSheet) {
// Get the current used range.
let destRange = currentWorksheet.getUsedRange(false) as any;
// let destRange = currentWorksheet.getRange("A1") as any;

// Clear all formatting.
destRange.load(['format']);
await context.sync();
destRange.format.fill.clear();

await context.sync();
// Now get the used range again.
destRange = currentWorksheet.getUsedRange(false) as any;

// Grab the backup sheet info.
backupSheet.load(['format', 'address']);
let usedRange = backupSheet.getUsedRange(false) as any;
usedRange.load(['address']);
let backupSheetUsedRange = backupSheet.getUsedRange(false) as any;
backupSheetUsedRange.load(['address']);
await context.sync();

console.log("copying out " + JSON.stringify(usedRange.address));
// destRange.copyFrom(usedRange, Excel.RangeCopyType.formats); // FIX ME FIXME WAS THIS
destRange.copyFrom(usedRange, Excel.RangeCopyType.all); // used for restoring VALUES FIXME NOT NEEDED IN GENERAL
console.log("copying out " + JSON.stringify(backupSheetUsedRange.address));
// destRange.copyFrom(backupSheetUsedRange, Excel.RangeCopyType.formats); // FIX ME FIXME WAS THIS
destRange.copyFrom(backupSheetUsedRange, Excel.RangeCopyType.all); // used for restoring VALUES FIXME NOT NEEDED IN GENERAL
await context.sync();
} else {
console.log("restoreFormats: didn't find the sheet " + backupName);
Expand Down Expand Up @@ -379,7 +391,8 @@ export default class App extends React.Component<AppProps, AppState> {

await setTimeout(() => {}, 0);
t.split("processed formulas");
let refs = Colorize.generate_all_references(formulas);
console.log("UPPER LEFT CORNER = " + JSON.stringify(upperLeftCorner));
let refs = ExcelUtils.generate_all_references(formulas);
t.split("generated all references");
await setTimeout(() => {}, 0);
let processed_data = Colorize.color_all_data(refs);
Expand Down
324 changes: 216 additions & 108 deletions src/components/colorize.js

Large diffs are not rendered by default.

73 changes: 29 additions & 44 deletions src/components/colorize.ts
Expand Up @@ -105,7 +105,9 @@ export class Colorize {
public static process_formulas(formulas: Array<Array<string>>, origin_col: number, origin_row: number): Array<[[number, number], string]> {
let lastHash = 0;
let lastHashString = lastHash.toString();
let output: Array<[[number, number], string]> = [];
let all_deps = {};
let reducer = (acc:[number,number],curr:[number,number]) : [number,number] => [acc[0] + curr[0], acc[1] + curr[1]];
let output: Array<[[number, number], string]> = [];
// Build up all of the columns of colors.
for (let i = 0; i < formulas.length; i++) {
let row = formulas[i];
Expand All @@ -118,28 +120,40 @@ export class Colorize {
// console.log("process_formulas: i = " + i + ", j = " + j);
// console.log("process_formulas: origin_col, row = " + origin_col + ", " + origin_row);
// console.log("process_formulas: row = " + JSON.stringify(cell));
let vec = ExcelUtils.dependencies(cell, j + origin_col + 1, i + origin_row + 1);
if (vec[0] === 0 && vec[1] === 0) {
// let vec = ExcelUtils.dependencies(cell, j + origin_col + 1, i + origin_row + 1);
console.log("about to check " + i + ", " + j);
let vec_array = ExcelUtils.transitive_closure(i, j, origin_row, origin_col, formulas, all_deps);
console.log("vec_array WAS = " + JSON.stringify(vec_array));
vec_array = vec_array.map((x) => [x[1] - i - 1, x[0] - j - 1]);
console.log("RELATIVE transitive closure of " + i + ", " + j + " (vec_array) NOW = " + JSON.stringify(vec_array) + " (i = " + i + ", j = " + j + ", origin_row = " + origin_row + ", origin_col = " + origin_col + ")");
if (vec_array.length == 0) {
// No dependencies! Use a distinguished "0" value (always the same color?).
output.push([[j + origin_col + 1, i + origin_row + 1], "0"]);
} else {
// console.log("process_formulas: vector = " + JSON.stringify(vec));
let hash = this.hash_vector(vec);
let str = "";
if (hash == lastHash) {
let vec = vec_array.reduce(reducer);
console.log("vec = " + JSON.stringify(vec));
if (vec[0] === 0 && vec[1] === 0) {
// No dependencies! Use a distinguished "0" value (always the same color?).
output.push([[j + origin_col + 1, i + origin_row + 1], "0"]);
} else {
lastHash = hash;
lastHashString = hash.toString();
}
str = lastHashString;
// console.log("process_formulas: hash of this vector = " + hash);
// console.log("process_formulas: vector = " + JSON.stringify(vec));
let hash = this.hash_vector(vec);
let str = "";
if (hash == lastHash) {
} else {
lastHash = hash;
lastHashString = hash.toString();
}
str = lastHashString;
// console.log("process_formulas: hash of this vector = " + hash);
output.push([[j + origin_col + 1, i + origin_row + 1], str]);
}
}
}
}
}
}
return output;
}
return output;
}


// public static color_all_data(formulas: Array<Array<string>>, processed_formulas: Array<[[number, number], string]>) {
Expand Down Expand Up @@ -384,35 +398,6 @@ export class Colorize {
}
}

public static generate_all_references(formulas: Array<Array<string>>): { [dep: string]: Array<[number, number]> } {
// Generate all references.
let refs = {};
let counter = 0;
for (let i = 0; i < formulas.length; i++) {
let row = formulas[i];
for (let j = 0; j < row.length; j++) {
let cell = row[j];
counter++;
if (counter % 1000 == 0) {
console.log(counter + " references down");
}

// console.log('origin_col = '+origin_col+', origin_row = ' + origin_row);
if (cell[0] === '=') {
let all_deps = ExcelUtils.all_cell_dependencies(cell); // , origin_col + j, origin_row + i);
for (let dep of all_deps) {
let key = dep.join(',');
refs[key] = true; // refs[key] || [];
// NOTE: we are disabling pushing the src onto the list because we don't need it.
// refs[dep2.join(',')].push(src);
}
}
}
}
return refs;
}


public static hash_vector(vec: Array<number>): number {
let baseX = 0; // was 7;
let baseY = 0; // was 3;
Expand Down
22 changes: 19 additions & 3 deletions src/components/colorutils.js
@@ -1,5 +1,21 @@
"use strict";
// colorutils
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
exports.__esModule = true;
var ColorUtils = /** @class */ (function () {
function ColorUtils() {
Expand Down Expand Up @@ -82,8 +98,8 @@ var ColorUtils = /** @class */ (function () {
};
ColorUtils.adjust_brightness = function (color, multiplier) {
var c = ColorUtils.rgb_ex.exec(color);
var _a = [parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16)], r = _a[0], g = _a[1], b = _a[2];
var _b = ColorUtils.RGBtoHSV(r, g, b), h = _b[0], s = _b[1], v = _b[2];
var _a = __read([parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16)], 3), r = _a[0], g = _a[1], b = _a[2];
var _b = __read(ColorUtils.RGBtoHSV(r, g, b), 3), h = _b[0], s = _b[1], v = _b[2];
v = multiplier * v;
if (v <= 0.0) {
v = 0.0;
Expand All @@ -92,7 +108,7 @@ var ColorUtils = /** @class */ (function () {
v = 0.99;
}
var rgb = ColorUtils.HSVtoRGB(h, s, v);
var _c = rgb.map(function (x) { return Math.round(x).toString(16).padStart(2, '0'); }), rs = _c[0], gs = _c[1], bs = _c[2];
var _c = __read(rgb.map(function (x) { return Math.round(x).toString(16).padStart(2, '0'); }), 3), rs = _c[0], gs = _c[1], bs = _c[2];
var str = '#' + rs + gs + bs;
str = str.toUpperCase();
return str;
Expand Down

0 comments on commit ff93535

Please sign in to comment.