Skip to content

Commit

Permalink
several bugfixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jbicker committed Jan 21, 2019
1 parent 08342b9 commit dafa50d
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5,221 deletions.
7 changes: 5 additions & 2 deletions timeline-chart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
"version": "0.0.2",
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
"watch": "tsc --watch",
"prepare": "yarn run clean && yarn run build",
"clean": "rimraf lib"
},
"dependencies": {
"@types/lodash.throttle": "^4.1.4",
"@types/pixi.js": "^4.8.2",
"lodash.throttle": "^4.1.1",
"pixi.js": "^4.8.2"
"pixi.js": "^4.8.2",
"rimraf": "latest"
}
}
48 changes: 25 additions & 23 deletions timeline-chart/src/components/time-graph-axis-scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,33 @@ export class TimeGraphAxisScale extends TimeGraphComponent {
}

protected renderVerticalLines(lineHeight: number, lineColor: number) {
const stepLength = this.getStepLength();
const steps = Math.trunc(this.unitController.absoluteRange / stepLength) + 1;
for (let i = 0; i < steps; i++) {
const absolutePosition = stepLength * i;
const xpos = (absolutePosition - this.unitController.viewRange.start) * this.stateController.zoomFactor;
if (xpos >= 0 && xpos < this.stateController.canvasDisplayWidth) {
const position = {
x: xpos,
y: this._options.height
};
if (this.unitController.numberTranslator) {
const label = this.unitController.numberTranslator(absolutePosition);
const text = new PIXI.Text(label, {
fontSize: 10
if (this.unitController.viewRangeLength > 0) {
const stepLength = this.getStepLength();
const steps = Math.trunc(this.unitController.absoluteRange / stepLength) + 1;
for (let i = 0; i < steps; i++) {
const absolutePosition = stepLength * i;
const xpos = (absolutePosition - this.unitController.viewRange.start) * this.stateController.zoomFactor;
if (xpos >= 0 && xpos < this.stateController.canvasDisplayWidth) {
const position = {
x: xpos,
y: this._options.height
};
if (this.unitController.numberTranslator) {
const label = this.unitController.numberTranslator(absolutePosition);
const text = new PIXI.Text(label, {
fontSize: 10
});
text.x = position.x + 5;
text.y = this._options.height - (2 * lineHeight);
this.labels.push(text);
this._displayObject.addChild(text);
}
this.vline({
position,
height: lineHeight * (-1),
color: lineColor
});
text.x = position.x + 5;
text.y = this._options.height - (2 * lineHeight);
this.labels.push(text);
this._displayObject.addChild(text);
}
this.vline({
position,
height: lineHeight * (-1),
color: lineColor
});
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions timeline-chart/src/layer/time-graph-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ export class TimeGraphChart extends TimeGraphChartLayer {

this.unitController.onViewRangeChanged(() => {
this.updateScaleAndPosition();
if (!this.fetching) {
if (!this.fetching && this.unitController.viewRangeLength !== 0) {
this.maybeFetchNewData();
}
});
this.updateScaleAndPosition();
this.maybeFetchNewData();
if (this.unitController.viewRangeLength) {
this.updateScaleAndPosition();
this.maybeFetchNewData();
}
}

update() { }
Expand Down
21 changes: 19 additions & 2 deletions timeline-chart/src/layer/time-graph-vertical-scrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,23 @@ export class TimeGraphVerticalScrollbar extends TimeGraphChartLayer {
}

protected afterAddToContainer() {
this.factor = this.stateController.canvasDisplayHeight / this.rowController.totalHeight;
this.updateFactor();
this.navigatorHandle = new TimeGraphVerticalScrollbarHandle(this.rowController, this.stateController, this.factor);
this.addChild(this.navigatorHandle);
this.rowController.onVerticalOffsetChangedHandler(() => this.update());
this.rowController.onTotalHeightChangedHandler(() => {
this.updateFactor();
this.navigatorHandle.updateFactor(this.factor);
this.update()
});
}

protected updateFactor() {
if (this.rowController.totalHeight) {
this.factor = this.stateController.canvasDisplayHeight / this.rowController.totalHeight;
} else {
this.factor = 0;
}
}

update() {
Expand Down Expand Up @@ -49,7 +62,7 @@ export class TimeGraphVerticalScrollbarHandle extends TimeGraphComponent {
const delta = event.data.global.y - this.mouseStartY;
let ypos = this.oldVerticalOffset + delta;
if (ypos >= 0 && (ypos + this.height) <= this.stateController.canvasDisplayHeight) {
this.rowController.verticalOffset = ypos/this.factor;
this.rowController.verticalOffset = ypos / this.factor;
}
}
}, this._displayObject);
Expand All @@ -60,6 +73,10 @@ export class TimeGraphVerticalScrollbarHandle extends TimeGraphComponent {
this.addEvent('mouseupoutside', moveEnd, this._displayObject);
}

updateFactor(factor: number){
this.factor = factor;
}

render(): void {
this.position = { x: 0, y: this.rowController.verticalOffset * this.factor };
this.height = this.stateController.canvasDisplayHeight * this.factor;
Expand Down
20 changes: 19 additions & 1 deletion timeline-chart/src/time-graph-row-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ export class TimeGraphRowController {
private _verticalOffset: number;
protected selectedRowChangedHandlers: ((row: TimelineChart.TimeGraphRowModel) => void)[] = [];
protected verticalOffsetChangedHandlers: ((verticalOffset: number) => void)[] = [];
protected totalHeightChangedHandlers: ((totalHeight: number) => void)[] = [];

constructor(public rowHeight: number, public totalHeight: number) {
constructor(public rowHeight: number, private _totalHeight: number) {
this._verticalOffset = 0;
}

Expand All @@ -18,6 +19,10 @@ export class TimeGraphRowController {
this.selectedRowChangedHandlers.forEach(h=>h(this._selectedRow));
}

protected handleTotalHeightChanged(){
this.totalHeightChangedHandlers.forEach(h=>h(this._totalHeight));
}

onSelectedRowChangedHandler(handler: (row: TimelineChart.TimeGraphRowModel) => void) {
this.selectedRowChangedHandlers.push(handler);
}
Expand All @@ -26,6 +31,19 @@ export class TimeGraphRowController {
this.verticalOffsetChangedHandlers.push(handler);
}

onTotalHeightChangedHandler(handler: (totalHeight: number) => void) {
this.totalHeightChangedHandlers.push(handler);
}

get totalHeight(): number {
return this._totalHeight;
}

set totalHeight(height: number) {
this._totalHeight = height;
this.handleTotalHeightChanged();
}

get verticalOffset(): number {
return this._verticalOffset;
}
Expand Down
Loading

0 comments on commit dafa50d

Please sign in to comment.