Skip to content

Commit

Permalink
note to self - dont set defaults in constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
jens-ox committed May 19, 2022
1 parent 6c3a071 commit d8a3b2e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
11 changes: 6 additions & 5 deletions lib/src/charts/abstractChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export default abstract class AbstractChart {
target,
markers,
baselines,
xAccessor = 'date',
yAccessor = 'value',
xAccessor,
yAccessor,
margin,
buffer,
width,
Expand All @@ -154,6 +154,10 @@ export default abstract class AbstractChart {
brush,
computeDomains
}: IAbstractChart) {
// convert string accessors to functions if necessary
this.xAccessor = makeAccessorFunction(xAccessor ?? 'date')
this.yAccessor = makeAccessorFunction(yAccessor ?? 'value')

// set parameters
this.data = data
this.target = select(target)
Expand All @@ -166,9 +170,6 @@ export default abstract class AbstractChart {
this.showTooltip = showTooltip ?? true
this.tooltipFunction = tooltipFunction

// convert string accessors to functions if necessary
this.xAccessor = makeAccessorFunction(xAccessor)
this.yAccessor = makeAccessorFunction(yAccessor)
this.margin = margin ?? { top: 10, left: 60, right: 20, bottom: 40 }
this.buffer = buffer ?? 10

Expand Down
6 changes: 3 additions & 3 deletions lib/src/charts/scatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export default class ScatterChart extends AbstractChart {
yRug?: Rug
_activePoint: ActivePoint = { i: -1, j: -1 }

constructor({ sizeAccessor = () => 3, xRug = false, yRug = false, ...args }: IScatterChart) {
constructor({ sizeAccessor, xRug, yRug, ...args }: IScatterChart) {
super(args)
this.showXRug = xRug
this.showYRug = yRug
this.showXRug = xRug ?? false
this.showYRug = yRug ?? false

this.sizeAccessor = sizeAccessor ? makeAccessorFunction(sizeAccessor) : () => 3

Expand Down
6 changes: 3 additions & 3 deletions lib/src/components/delaunay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Delaunay {
onLeave: EmptyInteractionFunction

constructor({
points = [],
points,
xAccessor,
yAccessor,
xScale,
Expand All @@ -69,13 +69,13 @@ export default class Delaunay {
aggregate,
defined
}: IDelaunay) {
this.xAccessor = xAccessor
this.yAccessor = yAccessor
this.xScale = xScale
this.yScale = yScale
this.onPoint = onPoint ?? (() => null)
this.onLeave = onLeave ?? (() => null)
this.onClick = onClick ?? this.onClick
this.xAccessor = xAccessor
this.yAccessor = yAccessor
this.aggregate = aggregate ?? this.aggregate

// normalize passed points
Expand Down
4 changes: 2 additions & 2 deletions lib/src/components/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export default class Point extends AbstractShape {
}

get cx(): number {
return this.xScale.scaleObject(this.xAccessor(this.data))!
return this.xScale.scaleObject(this.xAccessor(this.data))
}

get cy(): number {
return this.yScale.scaleObject(this.yAccessor(this.data))!
return this.yScale.scaleObject(this.yAccessor(this.data))
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/src/components/rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ export default class Rect extends AbstractShape {
}

get x(): number {
return this.xScale.scaleObject(this.xAccessor(this.data))!
return this.xScale.scaleObject(this.xAccessor(this.data))
}

get y(): number {
return this.yScale.scaleObject(this.yAccessor(this.data))!
return this.yScale.scaleObject(this.yAccessor(this.data))
}

get width(): number {
return Math.max(0, Math.abs(this.widthAccessor(this.data)))
}

get height(): number {
return Math.max(0, this.yScale.scaleObject(this.heightAccessor(this.data))!)
return Math.max(0, this.yScale.scaleObject(this.heightAccessor(this.data)))
}

/**
Expand Down

0 comments on commit d8a3b2e

Please sign in to comment.