Skip to content

Commit

Permalink
Namespace added to TimeGraphModel
Browse files Browse the repository at this point in the history
  • Loading branch information
jbicker committed Jan 17, 2019
1 parent 65fd87f commit 0cdba42
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 107 deletions.
12 changes: 6 additions & 6 deletions example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TimeGraphChartCursors } from "timeline-chart/lib/layer/time-graph-chart
import { TimeGraphChartSelectionRange } from "timeline-chart/lib/layer/time-graph-chart-selection-range";
import { TimeGraphAxisCursors } from "timeline-chart/lib/layer/time-graph-axis-cursors";
// import { timeGraph } from "timeline-chart/lib/test-data";
import { TimeGraphRowElementModel, TimeGraphRowModel, TimeGraphRange } from "timeline-chart/lib/time-graph-model";
import { TimelineChart } from "timeline-chart/lib/time-graph-model";
import { TimeGraphRowElement, TimeGraphRowElementStyle } from "timeline-chart/lib/components/time-graph-row-element";
import { TestDataProvider } from "./test-data-provider";
import { TimeGraphChartGrid } from "timeline-chart/lib/layer/time-graph-chart-grid";
Expand All @@ -34,7 +34,7 @@ container.style.width = styleConfig.mainWidth + "px";

const testDataProvider = new TestDataProvider(styleConfig.mainWidth);
let timeGraph = testDataProvider.getData({});
const unitController = new TimeGraphUnitController(timeGraph.totalRange);
const unitController = new TimeGraphUnitController(timeGraph.totalLength);
unitController.numberTranslator = (theNumber: number) => {
const milli = Math.floor(theNumber / 1000000);
const micro = Math.floor((theNumber % 1000000) / 1000);
Expand Down Expand Up @@ -78,12 +78,12 @@ const timeGraphChartGridLayer = new TimeGraphChartGrid('timeGraphGrid', rowHeigh
timeGraphChartContainer.addLayer(timeGraphChartGridLayer);

const timeGraphChart = new TimeGraphChart('timeGraphChart', {
dataProvider: (range: TimeGraphRange, resolution: number) => {
dataProvider: (range: TimelineChart.TimeGraphRange, resolution: number) => {
const length = range.end - range.start;
const overlap = ((length * 20) - length) / 2;
const start = range.start - overlap > 0 ? range.start - overlap : 0;
const end = range.end + overlap < unitController.absoluteRange ? range.end + overlap : unitController.absoluteRange;
const newRange: TimeGraphRange = { start, end };
const newRange: TimelineChart.TimeGraphRange = { start, end };
const newResolution: number = resolution * 0.1;
timeGraph = testDataProvider.getData({ range: newRange, resolution: newResolution });
if (selectedElement) {
Expand All @@ -101,7 +101,7 @@ const timeGraphChart = new TimeGraphChart('timeGraphChart', {
resolution: newResolution
};
},
rowElementStyleProvider: (model: TimeGraphRowElementModel) => {
rowElementStyleProvider: (model: TimelineChart.TimeGraphRowElementModel) => {
const styles: TimeGraphRowElementStyle[] = [
{
color: 0x11ad1b,
Expand Down Expand Up @@ -129,7 +129,7 @@ const timeGraphChart = new TimeGraphChart('timeGraphChart', {
borderWidth: model.selected ? 1 : 0
};
},
rowStyleProvider: (row: TimeGraphRowModel) => {
rowStyleProvider: (row: TimelineChart.TimeGraphRowModel) => {
return {
backgroundColor: 0xe0ddcf,
backgroundOpacity: row.selected ? 0.6 : 0,
Expand Down
4 changes: 2 additions & 2 deletions example/src/test-arrows.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TimeGraphArrow } from "timeline-chart/lib/time-graph-model";
import { TimelineChart } from "timeline-chart/lib/time-graph-model";

export const timeGraphArrows: TimeGraphArrow[] = [
export const timeGraphArrows: TimelineChart.TimeGraphArrow[] = [
{
sourceId: 1,
destinationId: 2,
Expand Down
22 changes: 11 additions & 11 deletions example/src/test-data-provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TimeGraphModel, TimeGraphRowModel, TimeGraphRowElementModel, TimeGraphRange, TimeGraphArrow } from "timeline-chart/lib/time-graph-model";
import { timeGraphEntries } from "./test-entries";
import { timeGraphStates } from "./test-states";
import { timeGraphArrows } from "./test-arrows";
import { TimelineChart } from "timeline-chart/lib/time-graph-model";

export namespace TestData {
/**
Expand Down Expand Up @@ -129,15 +129,15 @@ export namespace TestData {

export class TestDataProvider {
protected absoluteStart: number;
protected totalRange: number;
protected totalLength: number;
protected timeGraphEntries: object[];
protected timeGraphRows: object[];
protected canvasDisplayWidth: number;

constructor(canvasDisplayWidth: number) {
this.timeGraphEntries = timeGraphEntries.model.entries;
this.timeGraphRows = timeGraphStates.model.rows;
this.totalRange = 0;
this.totalLength = 0;

this.canvasDisplayWidth = canvasDisplayWidth;

Expand All @@ -152,19 +152,19 @@ export class TestDataProvider {
row.states.forEach((state: TestData.TimeGraphState, stateIndex: number) => {
if (state.value > 0) {
const end = state.startTime + state.duration - entry.startTime;
this.totalRange = end > this.totalRange ? end : this.totalRange;
this.totalLength = end > this.totalLength ? end : this.totalLength;
}
});
}
})
}

getData(opts: { range?: TimeGraphRange, resolution?: number }): TimeGraphModel {
const rows: TimeGraphRowModel[] = [];
const range = opts.range || { start: 0, end: this.totalRange };
const resolution = opts.resolution || this.totalRange / this.canvasDisplayWidth;
getData(opts: { range?: TimelineChart.TimeGraphRange, resolution?: number }): TimelineChart.TimeGraphModel {
const rows: TimelineChart.TimeGraphRowModel[] = [];
const range = opts.range || { start: 0, end: this.totalLength };
const resolution = opts.resolution || this.totalLength / this.canvasDisplayWidth;
timeGraphEntries.model.entries.forEach((entry: any, rowIndex: number) => {
const states: TimeGraphRowElementModel[] = [];
const states: TimelineChart.TimeGraphRowElementModel[] = [];
const row = timeGraphStates.model.rows.find(row => row.entryID === entry.id);
let hasStates = false;
if (row) {
Expand Down Expand Up @@ -198,7 +198,7 @@ export class TestDataProvider {
}
});
})
let arrows: TimeGraphArrow[] = [];
let arrows: TimelineChart.TimeGraphArrow[] = [];
timeGraphArrows.forEach(arrow => {
arrows.push({
sourceId: arrow.sourceId,
Expand All @@ -214,7 +214,7 @@ export class TestDataProvider {
id: "",
arrows,
rows,
totalRange: this.totalRange
totalLength: this.totalLength
}
}
}
4 changes: 2 additions & 2 deletions timeline-chart/src/components/time-graph-axis-scale.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { TimeGraphComponent, TimeGraphInteractionHandler, TimeGraphStyledRect, TimeGraphComponentOptions } from "./time-graph-component";
import { TimeGraphUnitController } from "../time-graph-unit-controller";
import { TimeGraphRange } from "../time-graph-model";
import { TimeGraphStateController } from "../time-graph-state-controller";
import * as _ from "lodash";
import { TimelineChart } from "../time-graph-model";

export class TimeGraphAxisScale extends TimeGraphComponent {

protected mouseStartY: number;
protected mouseStartX: number;
protected oldViewRange: TimeGraphRange;
protected oldViewRange: TimelineChart.TimeGraphRange;
protected mouseIsDown: boolean = false;
protected labels: PIXI.Text[];

Expand Down
8 changes: 4 additions & 4 deletions timeline-chart/src/components/time-graph-row-element.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TimeGraphComponent, TimeGraphStyledRect } from "./time-graph-component";
import { TimeGraphRow } from "./time-graph-row";
import { TimeGraphRowElementModel, TimeGraphRange } from "../time-graph-model";
import { TimelineChart } from "../time-graph-model";

export interface TimeGraphRowElementStyle {
color?: number
Expand All @@ -15,8 +15,8 @@ export class TimeGraphRowElement extends TimeGraphComponent {

constructor(
id: string,
protected _options: TimeGraphRowElementModel,
protected range: TimeGraphRange,
protected _options: TimelineChart.TimeGraphRowElementModel,
protected range: TimelineChart.TimeGraphRange,
protected _row: TimeGraphRow,
style: TimeGraphRowElementStyle = { color: 0xfffa66, height: 14 },
displayObject?:PIXI.Graphics
Expand All @@ -38,7 +38,7 @@ export class TimeGraphRowElement extends TimeGraphComponent {
};
}

get model(): TimeGraphRowElementModel {
get model(): TimelineChart.TimeGraphRowElementModel {
return this._options;
}

Expand Down
4 changes: 2 additions & 2 deletions timeline-chart/src/components/time-graph-row.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TimeGraphComponent, TimeGraphElementPosition, TimeGraphRect } from "./time-graph-component";
import { TimeGraphRowModel } from "../time-graph-model";
import { TimelineChart } from "../time-graph-model";

export interface TimeGraphRowStyle {
backgroundColor?: number
Expand All @@ -15,7 +15,7 @@ export class TimeGraphRow extends TimeGraphComponent {
id: string,
protected _options: TimeGraphRect,
protected _rowIndex: number,
public readonly model: TimeGraphRowModel,
public readonly model: TimelineChart.TimeGraphRowModel,
protected style: TimeGraphRowStyle = {lineOpacity:0.5, lineThickness: 1, backgroundOpacity: 0}) {
super(id);
}
Expand Down
12 changes: 6 additions & 6 deletions timeline-chart/src/layer/time-graph-chart-arrows.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TimeGraphArrowComponent, TimeGraphArrowCoordinates } from "../components/time-graph-arrow";
import { TimeGraphElementPosition } from "../components/time-graph-component";
import { TimeGraphArrow } from "../time-graph-model";
import { TimelineChart } from "../time-graph-model";
import { TimeGraphChartLayer } from "./time-graph-chart-layer";

export class TimeGraphChartArrows extends TimeGraphChartLayer {

protected arrows: Map<TimeGraphArrow, TimeGraphArrowComponent>;
protected arrows: Map<TimelineChart.TimeGraphArrow, TimeGraphArrowComponent>;

protected afterAddToContainer() {
this.unitController.onViewRangeChanged(() => this.update());
Expand All @@ -15,7 +15,7 @@ export class TimeGraphChartArrows extends TimeGraphChartLayer {
});
}

protected getCoordinates(arrow: TimeGraphArrow): TimeGraphArrowCoordinates {
protected getCoordinates(arrow: TimelineChart.TimeGraphArrow): TimeGraphArrowCoordinates {
const relativeStartPosition = arrow.range.start - this.unitController.viewRange.start;
const start: TimeGraphElementPosition = {
x: relativeStartPosition * this.stateController.zoomFactor,
Expand All @@ -28,14 +28,14 @@ export class TimeGraphChartArrows extends TimeGraphChartLayer {
return { start, end };
}

protected addArrow(arrow: TimeGraphArrow) {
protected addArrow(arrow: TimelineChart.TimeGraphArrow) {
const coords = this.getCoordinates(arrow);
const arrowComponent = new TimeGraphArrowComponent('arrow', coords);
this.arrows.set(arrow, arrowComponent);
this.addChild(arrowComponent);
}

addArrows(arrows: TimeGraphArrow[]): void {
addArrows(arrows: TimelineChart.TimeGraphArrow[]): void {
if (!this.stateController) {
throw ('Add this TimeGraphChartArrows to a container before adding arrows.');
}
Expand All @@ -53,7 +53,7 @@ export class TimeGraphChartArrows extends TimeGraphChartLayer {
}
}

protected updateArrow(arrow: TimeGraphArrow) {
protected updateArrow(arrow: TimelineChart.TimeGraphArrow) {
const { start, end } = this.getCoordinates(arrow);
const arrowComponent = this.arrows.get(arrow);
if (arrowComponent) {
Expand Down
6 changes: 3 additions & 3 deletions timeline-chart/src/layer/time-graph-chart-cursors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TimeGraphCursor } from "../components/time-graph-cursor";
import { TimeGraphRowElementModel } from "../time-graph-model";
import { TimelineChart } from "../time-graph-model";
import { TimeGraphChartLayer } from "./time-graph-chart-layer";
import { TimeGraphRowController } from "../time-graph-row-controller";
import { TimeGraphChart } from "./time-graph-chart";
Expand Down Expand Up @@ -82,7 +82,7 @@ export class TimeGraphChartCursors extends TimeGraphChartLayer {
protected navigateOrSelectLeft() {
const row = this.rowController.selectedRow;
const states = row.states;
const nextIndex = states.findIndex((rowElementModel: TimeGraphRowElementModel) => {
const nextIndex = states.findIndex((rowElementModel: TimelineChart.TimeGraphRowElementModel) => {
const selStart = this.unitController.selectionRange ? (this.shiftKeyDown ? this.unitController.selectionRange.end : this.unitController.selectionRange.start) : 0;
return rowElementModel.range.start >= selStart;
});
Expand All @@ -106,7 +106,7 @@ export class TimeGraphChartCursors extends TimeGraphChartLayer {
protected navigateOrSelectRight() {
const row = this.rowController.selectedRow;
const states = row.states;
const nextIndex = states.findIndex((rowElementModel: TimeGraphRowElementModel) => {
const nextIndex = states.findIndex((rowElementModel: TimelineChart.TimeGraphRowElementModel) => {
const cursorPosition = this.unitController.selectionRange ? (this.shiftKeyDown ? this.unitController.selectionRange.end : this.unitController.selectionRange.start) : 0;
return rowElementModel.range.start > cursorPosition;
});
Expand Down
40 changes: 20 additions & 20 deletions timeline-chart/src/layer/time-graph-chart.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TimeGraphRowElement, TimeGraphRowElementStyle } from "../components/time-graph-row-element";
import { TimeGraphRow, TimeGraphRowStyle } from "../components/time-graph-row";
import { TimeGraphRowModel, TimeGraphRowElementModel, TimeGraphRange } from "../time-graph-model";
import { TimelineChart } from "../time-graph-model";
import { TimeGraphComponent } from "../components/time-graph-component";
import { TimeGraphChartLayer } from "./time-graph-chart-layer";
import { TimeGraphRowController } from "../time-graph-row-controller";
Expand All @@ -14,21 +14,21 @@ export interface TimeGraphRowElementMouseInteractions {
}

export interface TimeGraphChartProviders {
dataProvider: (range: TimeGraphRange, resolution: number) => { rows: TimeGraphRowModel[], range: TimeGraphRange, resolution: number } | undefined
rowElementStyleProvider?: (el: TimeGraphRowElementModel) => TimeGraphRowElementStyle | undefined
rowStyleProvider?: (row: TimeGraphRowModel) => TimeGraphRowStyle | undefined
dataProvider: (range: TimelineChart.TimeGraphRange, resolution: number) => { rows: TimelineChart.TimeGraphRowModel[], range: TimelineChart.TimeGraphRange, resolution: number } | undefined
rowElementStyleProvider?: (el: TimelineChart.TimeGraphRowElementModel) => TimeGraphRowElementStyle | undefined
rowStyleProvider?: (row: TimelineChart.TimeGraphRowModel) => TimeGraphRowStyle | undefined
}

export type TimeGraphRowStyleHook = (row: TimeGraphRowModel) => TimeGraphRowStyle | undefined;
export type TimeGraphRowStyleHook = (row: TimelineChart.TimeGraphRowModel) => TimeGraphRowStyle | undefined;

export class TimeGraphChart extends TimeGraphChartLayer {

protected rows: TimeGraphRowModel[];
protected rows: TimelineChart.TimeGraphRowModel[];
protected rowElementMouseInteractions: TimeGraphRowElementMouseInteractions;
protected selectedElementModel: TimeGraphRowElementModel;
protected selectedElementChangedHandler: ((el: TimeGraphRowElementModel) => void)[] = [];
protected selectedElementModel: TimelineChart.TimeGraphRowElementModel;
protected selectedElementChangedHandler: ((el: TimelineChart.TimeGraphRowElementModel) => void)[] = [];

protected providedRange: TimeGraphRange;
protected providedRange: TimelineChart.TimeGraphRange;
protected providedResolution: number;

protected fetching: boolean;
Expand Down Expand Up @@ -141,7 +141,7 @@ export class TimeGraphChart extends TimeGraphChartLayer {
this.selectedElementChangedHandler.forEach(handler => handler(this.selectedElementModel));
}

protected addRow(row: TimeGraphRowModel, height: number, rowIndex: number) {
protected addRow(row: TimelineChart.TimeGraphRowModel, height: number, rowIndex: number) {
const rowId = 'row_' + rowIndex;
const length = row.range.end - row.range.start;
const rowStyle = this.providers.rowStyleProvider ? this.providers.rowStyleProvider(row) : undefined;
Expand All @@ -158,10 +158,10 @@ export class TimeGraphChart extends TimeGraphChartLayer {
this.selectRow(row);
}).bind(this));
this.addChild(rowComponent);
row.states.forEach((rowElementModel: TimeGraphRowElementModel, elementIndex: number) => {
row.states.forEach((rowElementModel: TimelineChart.TimeGraphRowElementModel, elementIndex: number) => {
const start = rowElementModel.range.start;
const end = rowElementModel.range.end;
const range: TimeGraphRange = {
const range: TimelineChart.TimeGraphRange = {
start,
end
};
Expand Down Expand Up @@ -202,29 +202,29 @@ export class TimeGraphChart extends TimeGraphChartLayer {
}).bind(this));
}

protected addRows(rows: TimeGraphRowModel[], height: number) {
protected addRows(rows: TimelineChart.TimeGraphRowModel[], height: number) {
if (!this.stateController) {
throw ('Add this TimeGraphChart to a container before adding rows.');
}
this.rowController.rowHeight = height;
rows.forEach((row: TimeGraphRowModel, index: number) => {
rows.forEach((row: TimelineChart.TimeGraphRowModel, index: number) => {
this.addRow(row, height, index);
});
}

protected setRowModel(rows: TimeGraphRowModel[]) {
protected setRowModel(rows: TimelineChart.TimeGraphRowModel[]) {
this.rows = rows;
}

registerRowElementMouseInteractions(interactions: TimeGraphRowElementMouseInteractions) {
this.rowElementMouseInteractions = interactions;
}

onSelectedRowElementChanged(handler: (el: TimeGraphRowElementModel) => void) {
onSelectedRowElementChanged(handler: (el: TimelineChart.TimeGraphRowElementModel) => void) {
this.selectedElementChangedHandler.push(handler);
}

getRowModels(): TimeGraphRowModel[] {
getRowModels(): TimelineChart.TimeGraphRowModel[] {
return this.rows;
}

Expand All @@ -235,19 +235,19 @@ export class TimeGraphChart extends TimeGraphChartLayer {
return element as TimeGraphRowElement;
}

selectRow(row: TimeGraphRowModel) {
selectRow(row: TimelineChart.TimeGraphRowModel) {
if (this.rowController.selectedRow) {
delete this.rowController.selectedRow.selected;
}
this.rowController.selectedRow = row;
row.selected = true;
}

getSelectedRowElement(): TimeGraphRowElementModel {
getSelectedRowElement(): TimelineChart.TimeGraphRowElementModel {
return this.selectedElementModel;
}

selectRowElement(model: TimeGraphRowElementModel) {
selectRowElement(model: TimelineChart.TimeGraphRowElementModel) {
if (this.selectedElementModel) {
delete this.selectedElementModel.selected;
}
Expand Down
Loading

0 comments on commit 0cdba42

Please sign in to comment.