Skip to content

Commit

Permalink
Fixed DI for diff chart
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Apr 2, 2024
1 parent 4d7d9e8 commit a66695c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion projects/planner/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ import { ProfileComparatorService } from './shared/diff/profileComparatorService
import { GasesComparisonService } from './shared/diff/gases-comparison.service';
import { ResultsComparison } from './shared/diff/results-comparison.service';
import { SelectedDiffWaypoint } from './shared/diff/selected-diff-waypoint.service';
import { ChartPlotterFactory } from './shared/chartPlotter';
import { ResamplingService } from "./shared/ResamplingService";

const ANGULAR_MODULES = [
AppRoutingModule,
Expand Down Expand Up @@ -209,7 +211,9 @@ const SERVICES = [
WayPointsService,
ProfileComparatorService,
GasesComparisonService,
ResultsComparison
ResultsComparison,
ResamplingService,
ChartPlotterFactory
];

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SelectedWaypoint } from '../../shared/selectedwaypointService';
import { DiveSchedules } from '../../shared/dive.schedules';
import { ReloadDispatcher } from '../../shared/reloadDispatcher';
import { SelectedDiffWaypoint } from '../../shared/diff/selected-diff-waypoint.service';
import { ChartPlotterFactory } from '../../shared/chartPlotter';

describe('ProfileDifferenceChartComponent', () => {
let component: ProfileDifferenceChartComponent;
Expand All @@ -23,6 +24,7 @@ describe('ProfileDifferenceChartComponent', () => {
DiveSchedules,
ReloadDispatcher,
SelectedDiffWaypoint,
ChartPlotterFactory
]
});
fixture = TestBed.createComponent(ProfileDifferenceChartComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ export class ProfileDifferenceChartComponent extends Streamed implements OnInit
private plotter: ChartPlotter;

constructor(
private units: UnitConversion,
chartPlotterFactory: ChartPlotterFactory,
private selectedWaypoints: SelectedDiffWaypoint,
private profileComparatorService: ProfileComparatorService) {
super();

const resampling = new ResamplingService(units);
const chartPlotterFactory = new ChartPlotterFactory(resampling, this.units);
const profileATraces = chartPlotterFactory.wthNamePrefix('Profile A ')
.create(() => this.profileA);
const profileBTraces = chartPlotterFactory
Expand All @@ -39,7 +37,7 @@ export class ProfileDifferenceChartComponent extends Streamed implements OnInit
.wthEventLineColor('rgb(118,119,120)')
.create(() => this.profileB);

this.plotter = new ChartPlotter('diveplot', this.units, profileBTraces, profileATraces);
this.plotter = new ChartPlotter('diveplot', chartPlotterFactory, profileBTraces, profileATraces);

this.profileComparatorService.selectionChanged$.pipe(takeUntil(this.unsubscribe$))
.subscribe(() => {
Expand Down
10 changes: 5 additions & 5 deletions projects/planner/src/app/shared/chartPlotter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Injectable } from '@angular/core';
import * as Plotly from 'plotly.js-basic-dist';
import _ from 'lodash';
import { UnitConversion } from './UnitConversion';
import { ResamplingService } from './ResamplingService';
import { DiveResults } from './diveresults';
import * as Plotly from 'plotly.js-basic-dist';
import { DateFormats } from './formaters';
import { WayPoint } from './models';
import { Ceiling, Event } from 'scuba-physics';
import _ from 'lodash';

// TODO merge with profileChart component drawing methods
@Injectable()
export class ChartPlotterFactory {
public static readonly depthLineColorA = 'rgb(31, 119, 180)';
public static readonly depthLineColorB = 'rgb(141, 143, 144)';
Expand Down Expand Up @@ -250,10 +252,8 @@ export class ChartPlotter {
private layout: Partial<Plotly.Layout>;

/** Provide traces in reverse order to keep the last on top */
constructor(public elementName: string, private units: UnitConversion, ...traceBuilders: DiveTracesBuilder[]) {
constructor(public elementName: string, chartPlotterFactory: ChartPlotterFactory, ...traceBuilders: DiveTracesBuilder[]) {
this.builders = traceBuilders;
const resampling = new ResamplingService(units);
const chartPlotterFactory = new ChartPlotterFactory(resampling, this.units);
this.cursor1 = chartPlotterFactory.createCursor();
this.layout = chartPlotterFactory.createLayout();
this.options = chartPlotterFactory.createOptions();
Expand Down

0 comments on commit a66695c

Please sign in to comment.