This tutorial gives a stepwise instruction on how extend a timeseries entry component with a new html-template. This tutorial can be used as a follow up of Integrate a D3 timeseries component.
add scss
support
.angular-cli.json
the parameter defaults.styleExt
from css
to scss
restucture of the view to have two other divs beside the diagram
app.component.html
to ```html
<div class="diagram">
<n52-d3-timeseries-graph [datasetIds]="datasetIdsMultiple" [selectedDatasetIds]="selectedIds" [datasetOptions]="datasetOptionsMultiple" [timeInterval]="timespan" (onTimespanChanged)="timespanChanged($event)" [graphOptions]="diagramOptionsD3"></n52-d3-timeseries-graph>
</div>
<div class="bottom">
<div class="left">
<!-- here comes the common timeseries entry component -->
</div>
<div class="right">
<!-- here comes the extended timeseries entry component -->
</div>
</div>
```
app.component.css
to app.component.scss
and adjust it to```scss
:host {
.diagram {
height: 500px;
flex: 1;
}
.bottom {
display: flex;
flex-direction: row;
.left,
.right {
width: 50%;
}
}
}
```
app.component.ts
to app.component.scss
install @helgoland/depiction
add HelgolandDatasetlistModule
to import
```bash
npm i @helgoland/depiction
```
HelgolandDatasetlistModule
in app.modul.ts
to the import list therefor you need to import it:```typescript
import { HelgolandDatasetlistModule } from '@helgoland/depiction';
```
```bash
npm i typescript@~2.6
```
add SettingsService
to provider
ExtendedSettingsService
which will extend a SettingsService
in your project and add the missing imports (SettingsService
, Settings
of @helgoland/core
and Injectable
of @angular/core
)```typescript
@Injectable()
export class ExtendedSettingsService extends SettingsService<Settings> {
constructor() {
super();
this.setSettings({
// TODO add settings here or load it from somewhere else...
});
}
}
```
ExtendedSettingsService
in the list of the providers ```typescript
{
provide: SettingsService,
useClass: ExtendedSettingsService
}
```
add n52-timeseries-entry
to app.component.html
(integrate this in the previous created div with the class left
)
<div>Common timeseries entries</div>
<div *ngFor="let id of datasetIdsMultiple">
<n52-timeseries-entry [datasetId]="id" [selected]="isSelected(id)" [datasetOptions]="datasetOptionsMultiple.get(id)" [timeInterval]="timespan" (onSelectDataset)="selectDataset($event, id)"></n52-timeseries-entry>
</div>
add selectDataset
-method to AppComponent
class (handles the selection of a dataset triggered inside the timeseries-entry-component)
public selectDataset(selected: boolean, id: string) {
if (selected) {
this.selectedIds.push(id);
} else {
this.selectedIds.splice(this.selectedIds.findIndex((entry) => entry === id), 1);
}
}
add isSelected
-method to AppComponent
class (informs the timeseries-entry-component, if the dataset is selected)
public isSelected(id: string) {
return this.selectedIds.indexOf(id) > -1;
}
with a ng serve
you should see now the diagram and the listed timeseries entries, by clicking an entry you can highligh it in the diagram
```bash
npm i @angular/cdk@^5.0.0 @angular/material@^5.0.0
```
app.module.ts
with MatCardModule
and MatButtonModule
in the import list and import them from @angular/material
styles.scss
```css
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
```
ExtendedTimeseriesEntryComponent
- this will generate a component with a basic template an style sheet. The component is also added to the app.module.ts
to the declarations
list ng generate component extended-timeseries
extended-timeseries.component.html
to ```html
<div style="padding: 5px;">
<mat-card class="example-card">
<mat-card-header>
<div mat-card-avatar [ngStyle]="{'background-color': datasetOptions.color}" (click)="changeColor();"></div>
<mat-card-title>{{phenomenonLabel}} - {{uom}}</mat-card-title>
<mat-card-subtitle>{{platformLabel}}</mat-card-subtitle>
</mat-card-header>
<mat-card-actions>
<button mat-button (click)="toggleSelection()">Highlight</button>
</mat-card-actions>
</mat-card>
</div>
```
extended-timeseries.component.ts
export class ExtendedTimeseriesComponent extends TimeseriesEntryComponent {
public changeColor() {
this.datasetOptions.color = this.color.getColor();
this.onUpdateOptions.emit(this.datasetOptions);
}
}
app-extended-timeseries
to app.component.html
(integrate this in the previous created div with the class right
) <div>Extended timeseries entries</div>
<div *ngFor="let id of datasetIdsMultiple">
<app-extended-timeseries [datasetId]="id" [selected]="isSelected(id)" [datasetOptions]="datasetOptionsMultiple.get(id)" [timeInterval]="timespan" (onSelectDataset)="selectDataset($event, id)" (onUpdateOptions)="updateOptions($event, id)">
</app-extended-timeseries>
</div>
updateOptions
-method to AppComponent class (this method is bound with the app-extended-timeseries
component and reacts on dataset option changes) public updateOptions(option: DatasetOptions, id: string) {
this.datasetOptionsMultiple.set(id, option);
}