Skip to content

Commit

Permalink
Formula helpers and named expressions with formulas (#167)
Browse files Browse the repository at this point in the history
* Add initial version of calculateFormula()

Issue: #24

* Add test which checks whether external formula is recomputed

* Add possibility to change contents of external formula

* Add possibility to normalize formula

* Refactoring: Introduce ChangeList type

* Add test ensuring that it works for more formulas

* Refactoring: Split test suite into two

* Add basic validation of external formulas

* Add documentation

* External formula is not valid if it has lexical errors

* Literal error is ok (if that's what user want)

* Extract NamedReferences module

* Refactoring: Rename HyperFormula#calculateFormula -> HyperFormula#addNamedExpression

* Add ability to retrieve value of named expression by it's name

Temporarily changing named expression formula is forbidden, need to do
new API for that which does not use -1 sheet internal.

* Allow to add only one expression for given name

* Add assertion ensuring that NamedExpression won't contain duplicates

* Add basic validation of named expressions

* Refactoring: Rename NamedExpressionAlreadyTaken -> NamedExpressionNameIsAlreadyTaken

* Refactoring: Extract error classes out to separate file

They still belongs to the responsibility of the HyperFormula unit, but
majority of this code is just formatting the error. So I think it's
cleaner when they are in separate file.

* Refactoring: Remove unused return value

* Refactoring: Rename ivar NamedExpressions#nextExternalFormulaId -> nextNamedExpressionRow

* Make it possible to retrieve value of non existing named expression

* Add API for removing named expressions

* Refactoring: extract NamedExpressions#buildAddress method

* Refactoring: Remove magic constant

* SparseStrategy will not leak memory in the long run for named expressions

* Allow again to change formulas in named expressions

* Refactoring

* Does not allow to change not existing named expression

* Add possibility to list existing named expressions

* Prerefactoring: Extract class NamedExpression

* Remove unnecessary bang

* Add assertion in NamedExpressions#changeNamedExpressionFormula

* Make named expressions names to be case insensitive

* Refactoring: Extract a NamedExpressionsStore

* Refactoring: Extract method NamedExpressions#storeFormulaInCell

* No longer workarounds for keeping sheet = -1

* Refactoring: Use ChangeList instead of CellValueChange[]

Because in a moment I want to add different kind of element to
ChangeList -- the one which will tell that named expression has changed.

* lint-fix

* Add documentation

* Fixes after merge conflict

* Resolving conflicts is so. much. fun.

Co-authored-by: Jakub Kowalski <kowalski_jakub@hotmail.com>
  • Loading branch information
swistak35 and voodoo11 committed Feb 14, 2020
1 parent f8efea9 commit aa863d9
Show file tree
Hide file tree
Showing 18 changed files with 513 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/ClipboardOperations.ts
Expand Up @@ -3,7 +3,7 @@ import {invalidSimpleCellAddress, simpleCellAddress, SimpleCellAddress} from './
import {CrudOperations} from './CrudOperations'
import {DependencyGraph, EmptyCellVertex, FormulaCellVertex, MatrixVertex, ValueCellVertex} from './DependencyGraph'
import {ValueCellVertexValue} from './DependencyGraph/ValueCellVertex'
import {InvalidArgumentsError} from './HyperFormula'
import {InvalidArgumentsError} from './errors'
import {LazilyTransformingAstService} from './LazilyTransformingAstService'
import {ParserWithCaching} from './parser'

Expand Down
12 changes: 7 additions & 5 deletions src/ContentChanges.ts
Expand Up @@ -9,13 +9,15 @@ export interface CellValueChange {
value: InternalCellValue,
}

export type ChangeList = CellValueChange[]

export class ContentChanges {

public static empty() {
return new ContentChanges()
}

private changes: CellValueChange[] = []
private changes: ChangeList = []

public addAll(other: ContentChanges): ContentChanges {
this.changes.push(...other.changes)
Expand All @@ -32,12 +34,12 @@ export class ContentChanges {
this.addSingleCellValue(newValue, address)
}

public add(...change: CellValueChange[]) {
public add(...change: ChangeList) {
this.changes.push(...change)
}

public exportChanges(exporter: CellValueExporter): CellValueChange[] {
const ret: CellValueChange[] = []
public exportChanges(exporter: CellValueExporter): ChangeList {
const ret: ChangeList = []
for (const i in this.changes) {
ret[i] = {
sheet: this.changes[i].sheet,
Expand All @@ -49,7 +51,7 @@ export class ContentChanges {
return ret
}

public getChanges(): CellValueChange[] {
public getChanges(): ChangeList {
return this.changes
}

Expand Down
3 changes: 2 additions & 1 deletion src/CrudOperations.ts
Expand Up @@ -23,8 +23,9 @@ import {MoveCellsDependencyTransformer} from './dependencyTransformers/moveCells
import {RemoveColumnsDependencyTransformer} from './dependencyTransformers/removeColumns'
import {RemoveRowsDependencyTransformer} from './dependencyTransformers/removeRows'
import {RemoveSheetDependencyTransformer} from './dependencyTransformers/removeSheet'
import {InvalidAddressError, InvalidArgumentsError, NoSheetWithIdError, NoSheetWithNameError} from './errors'
import {buildMatrixVertex} from './GraphBuilder'
import {Index, InvalidAddressError, InvalidArgumentsError, NoSheetWithIdError, NoSheetWithNameError} from './HyperFormula'
import {Index} from './HyperFormula'
import {IBatchExecutor} from './IBatchExecutor'
import {LazilyTransformingAstService} from './LazilyTransformingAstService'
import {ParserWithCaching, ProcedureAst} from './parser'
Expand Down

0 comments on commit aa863d9

Please sign in to comment.