# WidgetTopOffersByClientsLastNyearsComponent

**Kind:** Class

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

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

`WidgetTopOffersByClientsLastNyearsComponent` is an Angular dashboard widget that displays top offers grouped by clients across a recent-year period. It checks feature subscription access, requests dashboard data, prepares chart state, and responds to chart initialization and planned-visit click events.

**Extends:** `BaseWidgetComponent`

**Implements:** `OnInit`

## Methods

| Method | Signature | Returns |
|---|---|---|
| `viewData` | `viewData()` | `void` |
| `checkFeatureSubscription` | `checkFeatureSubscription()` | `boolean` |
| `getDashboardData` | `getDashboardData()` | `void` |
| `initializeChart` | `initializeChart(seriesData: undefined, headerData: undefined)` | `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` |
| `toggoleOnlyCurrentOffers` | `toggoleOnlyCurrentOffers()` | `void` |
| `switchChartRefernceCommissionHandler` | `switchChartRefernceCommissionHandler()` | `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` |
| `numYearsDatasource` | `any[]` |
| `_FirmOffers` | `boolean` |
| `_BudgetOffers` | `boolean` |
| `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

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

## Diagram

```mermaid
graph LR
  Lifecycle[Angular lifecycle] --> Init[ngOnInit]
  Lifecycle --> Changes[ngOnChanges]

  Init --> Subscription[checkFeatureSubscription]
  Changes --> Data[getDashboardData]
  Subscription --> Data

  Data --> Response[afterResponse]
  Response --> Chart[initializeChart]
  Chart --> ChartInit[onChartInit]

  ChartInit --> YearColor[setYearColor]
  ChartInit --> Click[onPlannedVisitsChartClick]
  Click --> View[viewData]
```

## Usage

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

@Component({
  selector: 'app-dashboard-page',
  template: `
    <!-- Render the widget through its configured dashboard template. -->
    <button type="button" (click)="refreshTopOffers()">
      Refresh offers
    </button>
  `
})
export class DashboardPageComponent {
  @ViewChild(WidgetTopOffersByClientsLastNyearsComponent)
  topOffersWidget?: WidgetTopOffersByClientsLastNyearsComponent;

  refreshTopOffers(): void {
    if (!this.topOffersWidget?.checkFeatureSubscription()) {
      return;
    }

    this.topOffersWidget.getDashboardData();
  }
}
```

## AI Coding Instructions

- Keep `checkFeatureSubscription()` ahead of dashboard-data requests when adding refresh or reload paths.
- Route successful data handling through `afterResponse()` so chart setup remains in the existing flow.
- Reinitialize chart state through `initializeChart()` rather than creating chart state directly in lifecycle handlers.
- Preserve the distinction between `ngOnInit()` for initial loading and `ngOnChanges()` for reacting to changed component inputs.
- Handle `onPlannedVisitsChartClick()` through `viewData()` when extending chart click behavior.

## 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
