Skip to content

Commit

Permalink
Axis scale improved
Browse files Browse the repository at this point in the history
  • Loading branch information
jbicker committed Feb 7, 2019
1 parent 862499a commit 1356eb2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
14 changes: 6 additions & 8 deletions timeline-chart/src/components/time-graph-axis-scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ export class TimeGraphAxisScale extends TimeGraphComponent {
const realStepLength = viewRangeLength / maxSteps;
const log = Math.log10(realStepLength);
let logRounded = Math.round(log);
if(this.unitController.discreteScale){
logRounded = Math.abs(logRounded);
}
const normalizedStepLength = Math.pow(10, logRounded);
const residual = realStepLength / normalizedStepLength;
const steps = this.unitController.scaleSteps || [1, 1.5, 2, 2.5, 5, 10];
Expand All @@ -75,7 +72,7 @@ export class TimeGraphAxisScale extends TimeGraphComponent {
return stepLength;
}

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

zoomAroundLeftViewBorder(zoomStep: number) {
Expand Down
2 changes: 1 addition & 1 deletion timeline-chart/src/components/time-graph-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export class TimeGraphGrid extends TimeGraphAxisScale {
protected addEvents() { }

render(): void {
this.renderVerticalLines(this.stateController.canvasDisplayHeight, this._options.lineColor || 0xdddddd);
this.renderVerticalLines(this._options.lineColor || 0xdddddd, () => ({ lineHeight: this.stateController.canvasDisplayHeight }));
}
}
1 change: 0 additions & 1 deletion timeline-chart/src/time-graph-unit-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class TimeGraphUnitController {

numberTranslator?: (theNumber: number) => string;
scaleSteps?: number[]
discreteScale?: boolean;

constructor(public absoluteRange: number, viewRange?: TimelineChart.TimeGraphRange) {
this.viewRangeChangedHandlers = [];
Expand Down

0 comments on commit 1356eb2

Please sign in to comment.