# WidgetTopOffersByPrincipalsLastNyearsComponent

**Kind:** Class

**Source:** `Frontend/src/app/components/dashboard/dashboard-libary/widgets/widget-top-offers-by-principals-last-nyears/widget-top-offers-by-principals-last-nyears.component.ts` (line 22)

**Part of:** [Frontend](subsystem-frontend-src-app)

`WidgetTopOffersByPrincipalsLastNyearsComponent` displays dashboard data for top offers grouped by principal across a configured range of years. It checks feature subscription access, retrieves dashboard data, processes responses, and initializes the related chart during Angular lifecycle updates.

**Extends:** `BaseWidgetComponent`

**Implements:** `OnInit`

## Methods

| Method | Signature | Returns |
|---|---|---|
| `viewData` | `viewData()` | `void` |
| `initializeChart` | `initializeChart(seriesData: undefined, headerData: undefined)` | `void` |
| `checkFeatureSubscription` | `checkFeatureSubscription()` | `boolean` |
| `getDashboardData` | `getDashboardData()` | `void` |
| `afterResponse` | `afterResponse(Data: any[])` | `void` |
| `ngOnChanges` | `ngOnChanges()` | `void` |
| `ngOnInit` | `ngOnInit()` | `void` |
| `setYearColor` | `setYearColor(year: number)` | `string` |
| `onChartInit` | `onChartInit(e: any)` | `void` |
| `onPlannedVisitsChartClick` | `onPlannedVisitsChartClick(e: undefined)` | `void` |
| `setChaching` | `setChaching()` | `void` |
| `getChaching` | `getChaching()` | `void` |
| `onValueChanged` | `onValueChanged(e: undefined)` | `void` |
| `switchChartTypeHandler` | `switchChartTypeHandler()` | `void` |
| `switchChartRefernceCommissionHandler` | `switchChartRefernceCommissionHandler()` | `void` |
| `toggoleOnlyCurrentOffers` | `toggoleOnlyCurrentOffers()` | `void` |
| `toggoleBudgetOffers` | `toggoleBudgetOffers()` | `void` |
| `toggoleFirmOffers` | `toggoleFirmOffers()` | `void` |
| `switchFirmOffers` | `switchFirmOffers()` | `void` |
| `switchBudgetOffers` | `switchBudgetOffers()` | `void` |
| `nextPage` | `nextPage()` | `void` |
| `prevPage` | `prevPage()` | `void` |

## Properties

| Property | Type |
|---|---|
| `_widget` | `Widget` |
| `meAsVendor` | `boolean` |
| `isRefernceCommission` | `boolean` |
| `withoutOptionBar` | `boolean` |
| `onlyCurrentOffers` | `boolean` |
| `numYears` | `number` |
| `_FirmOffers` | `boolean` |
| `_BudgetOffers` | `boolean` |
| `numYearsDatasource` | `any[]` |
| `todayWidgetsEnum` | `any` |
| `branchName` | `string` |
| `maxValueForYaxis` | `number` |
| `initOpts` | `any` |
| `series` | `any[]` |
| `header` | `any[]` |
| `echartsIntance` | `any` |
| `cachingWidgetData` | `CachingWidgetData` |
| `originalDatasource` | `WidgetTopOffers[]` |
| `datasource` | `WidgetTopOffers[]` |
| `originalHeader` | `any[]` |
| `options` | `any` |
| `skip` | `number` |
| `currenFeature` | `number` |
| `seriesData` | `any` |
| `headerData` | `any[]` |
| `showDataOnChart` | `boolean` |

## Where it refuses work

- `WidgetTopOffersByPrincipalsLastNyearsComponent` stops the work with an early return when `this.dashboardLibraryService.checkFeatureSubscription(this.widget.chartEnumId)`.
- `WidgetTopOffersByPrincipalsLastNyearsComponent` stops the work with an early return when `this.showDataOnChart`.

## Diagram

```mermaid
graph LR
  Lifecycle[Angular lifecycle] --> Init[ngOnInit]
  Lifecycle --> Changes[ngOnChanges]
  Init --> Subscription[checkFeatureSubscription]
  Changes --> Subscription
  Subscription -->|Allowed| Data[getDashboardData]
  Data --> Response[afterResponse]
  Response --> Chart[initializeChart]
  Chart --> ChartReady[onChartInit]
  Chart --> YearColor[setYearColor]
  ChartReady --> Click[onPlannedVisitsChartClick]
  Data --> View[viewData]
```

## Usage

```ts
import { Component, ViewChild } from '@angular/core';
import { WidgetTopOffersByPrincipalsLastNyearsComponent } from './widget-top-offers-by-principals-last-nyears.component';

@Component({
  selector: 'app-dashboard-page',
  template: `
    <app-widget-top-offers-by-principals-last-nyears
      #topOffersWidget>
    </app-widget-top-offers-by-principals-last-nyears>
  `
})
export class DashboardPageComponent {
  @ViewChild('topOffersWidget')
  topOffersWidget?: WidgetTopOffersByPrincipalsLastNyearsComponent;

  refreshTopOffers(): void {
    const widget = this.topOffersWidget;

    if (widget?.checkFeatureSubscription()) {
      widget.getDashboardData();
    }
  }
}
```

## AI Coding Instructions

- Keep data retrieval behind `checkFeatureSubscription()` so unavailable features do not request or render dashboard data.
- Let `ngOnInit()` and `ngOnChanges()` coordinate initialization and updates; do not call lifecycle hooks directly from application code.
- Process API results through `afterResponse()` before initializing or updating chart state.
- Keep chart setup in `initializeChart()` and chart event handling in `onChartInit()` and `onPlannedVisitsChartClick()`.
- Use `setYearColor()` when assigning series colors so year-based chart styling remains consistent.

## Used by

2 references from 2 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Imported by (2)

- `WidgetTopOffersByVariantsComponent` — `Frontend/src/app/components/dashboard/dashboard-libary/widgets/widget-top-offers-by-variants/widget-top-offers-by-variants.component.ts`:1
- `DashboardWidgetsModule` — `Frontend/src/app/components/dashboard/dashboard-widgets.module.ts`:1
