Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make content's type more generic #473

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions ember-highcharts/src/components/high-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const CHART_TYPES = {
undefined: 'chart',
} as const;

interface HighChartsSignature {
interface HighChartsSignature<Content extends Highcharts.Options['series']> {
Element: HTMLDivElement;
Args: {
/**
Expand All @@ -36,7 +36,7 @@ interface HighChartsSignature {
* The `content` argument matches up with the `series` option in the Highcharts/Highstock/Highmaps API.
* Use this option to set the series data for your chart.
*/
content?: Highcharts.Options['series'];
content?: Content;
/**
* The `chartOptions` argument is a generic object for setting different options with Highcharts/Highstock/Highmaps.
* Use this option to set things like the chart title and axis settings.
Expand All @@ -56,7 +56,9 @@ interface HighChartsSignature {
};
}

export default class HighCharts extends Component<HighChartsSignature> {
export default class HighCharts<
Content extends Highcharts.Options['series'],
> extends Component<HighChartsSignature<Content>> {
get content() {
return this.args.content ?? undefined;
}
Expand Down Expand Up @@ -121,9 +123,9 @@ export default class HighCharts extends Component<HighChartsSignature> {
onDidUpdate(
_elem: unknown,
[content, chartOptions, mode]: [
HighChartsSignature['Args']['content'],
HighChartsSignature['Args']['chartOptions'],
HighChartsSignature['Args']['mode'],
HighChartsSignature<Content>['Args']['content'],
HighChartsSignature<Content>['Args']['chartOptions'],
HighChartsSignature<Content>['Args']['mode'],
],
) {
const { chart } = this;
Expand Down
6 changes: 4 additions & 2 deletions ember-highcharts/src/utils/build-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export const EMPTY_CHART_CONTENT = [
},
] as const;

export default function buildOptions(
export default function buildOptions<
Content extends Highcharts.Options['series'],
>(
theme: Highcharts.Options = {},
options: Highcharts.Options = {},
content?: Highcharts.Options['series'],
content?: Content,
) {
// if 'no-data-to-display' module has been imported, keep empty series
// and leave it to highcharts to show no data label.
Expand Down
6 changes: 4 additions & 2 deletions ember-highcharts/src/utils/chart-data.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type Highcharts from 'highcharts';

export function getSeriesMap(seriesGroup: Array<Highcharts.SeriesOptionsType>) {
export function getSeriesMap<Content extends Highcharts.SeriesOptionsType>(
seriesGroup: Array<Content>,
) {
const seriesMap = seriesGroup.reduce(
(seriesMap, seriesItem) => {
seriesMap[seriesItem.name as string] = seriesItem;
return seriesMap;
},
{} as { [key: string]: Highcharts.SeriesOptionsType },
{} as { [key: string]: Content },
);

return seriesMap;
Expand Down