Skip to content

Commit

Permalink
after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-odoo committed Apr 17, 2024
1 parent d851480 commit 2738e8c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 49 deletions.
13 changes: 10 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ export const NEWLINE = "\n";
export const FONT_SIZES: number[] = [6, 7, 8, 9, 10, 11, 12, 14, 18, 24, 36];

// Pivot
export const HEADER_STYLE = { fillColor: "#E6F2F3" };
export const TOP_LEVEL_STYLE = { bold: true, fillColor: "#E6F2F3" };
export const MEASURE_STYLE = { fillColor: "#E6F2F3", textColor: "#756f6f" };
export const PIVOT_TABLE_CONFIG = {
hasFilters: false,
totalRow: false,
firstColumn: true,
lastColumn: false,
numberOfHeaders: 1,
bandedRows: true,
bandedColumns: false,
styleId: "TableStyleMedium5",
};
10 changes: 3 additions & 7 deletions src/helpers/pivot/spreadsheet_pivot_table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { HEADER_STYLE, MEASURE_STYLE, TOP_LEVEL_STYLE } from "../../constants";
import { SPTableCell, SPTableColumn, SPTableRow } from "../../types/pivot";

/**
Expand Down Expand Up @@ -116,17 +115,14 @@ export class SpreadsheetPivotTable {
private getPivotCell(col: number, row: number, includeTotal = true): SPTableCell {
const colHeadersHeight = this.columns.length;
if (col === 0 && row === colHeadersHeight - 1) {
return { content: this.rowTitle, isHeader: true, style: HEADER_STYLE };
return { content: this.rowTitle, isHeader: true };
} else if (row <= colHeadersHeight - 1) {
const domain = this.getColHeaderDomain(col, row);
const style = row === colHeadersHeight - 1 ? MEASURE_STYLE : TOP_LEVEL_STYLE;
return { domain, isHeader: true, style };
return { domain, isHeader: true };
} else if (col === 0) {
const rowIndex = row - colHeadersHeight;
const domain = this.getRowDomain(rowIndex);
const indent = this.rows[rowIndex].indent;
const style = indent <= 1 ? TOP_LEVEL_STYLE : indent === 2 ? HEADER_STYLE : undefined;
return { domain, isHeader: true, style };
return { domain, isHeader: true };
} else {
const rowIndex = row - colHeadersHeight;
if (!includeTotal && this.isTotalRow(rowIndex)) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
HIGHLIGHT_COLOR,
MIN_COL_WIDTH,
MIN_ROW_HEIGHT,
PIVOT_TABLE_CONFIG,
SCROLLBAR_WIDTH,
TOPBAR_HEIGHT,
} from "./constants";
Expand Down Expand Up @@ -391,6 +392,7 @@ export function addFunction(functionName: string, functionDescription: AddFuncti
export const constants = {
DEFAULT_LOCALE,
HIGHLIGHT_COLOR,
PIVOT_TABLE_CONFIG,
};

export { PivotRuntimeDefinition } from "./helpers/pivot/pivot_runtime_definition";
Expand Down
56 changes: 18 additions & 38 deletions src/plugins/core/pivot.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PIVOT_TABLE_CONFIG } from "../../constants";
import { deepCopy, deepEquals, isDefined } from "../../helpers";
import { getMaxObjectId, makePivotFormula } from "../../helpers/pivot/pivot_helpers";
import { SpreadsheetPivotTable } from "../../helpers/pivot/spreadsheet_pivot_table";
Expand Down Expand Up @@ -186,8 +187,23 @@ export class PivotCorePlugin extends CorePlugin<CoreState> implements CoreState
this.addPivotFormula(cellPosition, formulaId, pivotCell);
}
}

this.addBorders(position, table);
const pivotZone = {
top: position.row,
bottom: position.row + pivotCells[0].length - 1,
left: position.col,
right: position.col + pivotCells.length - 1,
};
const numberOfHeaders = table.columns.length - 1;
const cmdContent = {
sheetId: position.sheetId,
ranges: [this.getters.getRangeDataFromZone(position.sheetId, pivotZone)],
config: { ...PIVOT_TABLE_CONFIG, numberOfHeaders },
};
//@ts-ignore TODOPRO
if (this.canDispatch("CREATE_TABLE", cmdContent).isSuccessful) {
//@ts-ignore TODOPRO
this.dispatch("CREATE_TABLE", cmdContent);
}
}

private resizeSheet(sheetId: UID, { col, row }: Position, table: SpreadsheetPivotTable) {
Expand Down Expand Up @@ -217,41 +233,6 @@ export class PivotCorePlugin extends CorePlugin<CoreState> implements CoreState
}
}

private addBorders(position: CellPosition, table: SpreadsheetPivotTable) {
const { sheetId, col, row } = position;
const colHeight = table.columns.length;
const colWidth = table.getNumberOfDataColumns();
const totalRow = row + colHeight + table.rows.length - 1;
const headerAndMeasureZone = {
top: row,
bottom: row + colHeight - 1,
left: col,
right: col + colWidth,
};
this.dispatch("SET_ZONE_BORDERS", {
sheetId,
target: [
headerAndMeasureZone,
{
left: col,
right: col + colWidth,
top: totalRow,
bottom: totalRow,
},
{
left: col,
right: col + colWidth,
top: row,
bottom: totalRow,
},
],
border: {
position: "external",
color: "#2D7E84",
},
});
}

private addPivotFormula(position: CellPosition, formulaId: UID, pivotCell: SPTableCell) {
const formula = pivotCell.isHeader ? "PIVOT.HEADER" : "PIVOT.VALUE";
const args = pivotCell.domain
Expand All @@ -261,7 +242,6 @@ export class PivotCorePlugin extends CorePlugin<CoreState> implements CoreState
this.dispatch("UPDATE_CELL", {
...position,
content: pivotCell.content || (args ? makePivotFormula(formula, args) : undefined),
style: pivotCell.style,
});
}

Expand Down
1 change: 0 additions & 1 deletion src/types/pivot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,5 @@ export interface SPTableCell {
isHeader: boolean;
domain?: string[];
content?: string;
style?: Object;
measure?: string;
}

0 comments on commit 2738e8c

Please sign in to comment.