Skip to content

Commit

Permalink
NumberTranslator hook can return undefined.
Browse files Browse the repository at this point in the history
In this case TextObjects will not be created.
  • Loading branch information
jbicker committed Feb 15, 2019
1 parent da9a90e commit c3b17d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions timeline-chart/src/components/time-graph-axis-scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class TimeGraphAxisScale extends TimeGraphComponent {
return stepLength;
}

protected renderVerticalLines(lineColor: number, lineStyle: (label: string) => { lineHeight: number }) {
protected renderVerticalLines(lineColor: number, lineStyle: (label: string | undefined) => { lineHeight: number }) {
if (this.unitController.viewRangeLength > 0) {
const stepLength = this.getStepLength();
const steps = Math.trunc(this.unitController.absoluteRange / stepLength) + 1;
Expand All @@ -84,17 +84,19 @@ export class TimeGraphAxisScale extends TimeGraphComponent {
x: xpos,
y: this._options.height
};
let label = '';
let label;
if (this.unitController.numberTranslator) {
label = this.unitController.numberTranslator(absolutePosition);
const text = new PIXI.Text(label, {
fontSize: 10,
fill: lineColor
});
text.x = position.x + 5;
text.y = this._options.height - (2 * lineStyle(label).lineHeight);
this.labels.push(text);
this._displayObject.addChild(text);
if (label) {
const text = new PIXI.Text(label, {
fontSize: 10,
fill: lineColor
});
text.x = position.x + 5;
text.y = this._options.height - (2 * lineStyle(label).lineHeight);
this.labels.push(text);
this._displayObject.addChild(text);
}
}
this.vline({
position,
Expand All @@ -119,7 +121,7 @@ export class TimeGraphAxisScale extends TimeGraphComponent {
width: this._options.width,
position: this._options.position
});
this.renderVerticalLines(this._options.lineColor || 0x000000, (l) => ({ lineHeight: l === '' ? 5 : 10 }));
this.renderVerticalLines(this._options.lineColor || 0x000000, (l) => ({ lineHeight: l === '' || l === undefined ? 5 : 10 }));
}

zoomAroundLeftViewBorder(zoomStep: number) {
Expand Down
2 changes: 1 addition & 1 deletion timeline-chart/src/time-graph-unit-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class TimeGraphUnitController {
protected selectionRangeChangedHandlers: ((newRange?: TimelineChart.TimeGraphRange) => void)[];
protected _selectionRange?: TimelineChart.TimeGraphRange;

numberTranslator?: (theNumber: number) => string;
numberTranslator?: (theNumber: number) => string | undefined;
scaleSteps?: number[]

constructor(public absoluteRange: number, viewRange?: TimelineChart.TimeGraphRange) {
Expand Down

0 comments on commit c3b17d2

Please sign in to comment.