Skip to content

Commit

Permalink
Add support for polar charts (#481)
Browse files Browse the repository at this point in the history
* Add support for polar charts

- As per [documentation](https://www.highcharts.com/docs/chart-and-series-types/polar-chart):

> Polar charts, also known as radar charts, require the highcharts-more.js file.

I was also tinkering with the idea to just merge the if to the "waterfall" case below as it's essentially the same, but then decided against as it might cause issues in the future.

* docs: Polar chart in test app
  • Loading branch information
MichalBryxi authored Oct 7, 2024
1 parent d628cf5 commit 3b374c9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ember-highcharts/src/components/high-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,10 @@ export default class HighCharts<
const More = await waitForPromise(import('highcharts/highcharts-more'));
More.default(Highcharts);
}

if (this.args.chartOptions?.chart?.polar === true) {
const More = await waitForPromise(import('highcharts/highcharts-more'));
More.default(Highcharts);
}
}
}
4 changes: 4 additions & 0 deletions test-app/app/components/chart-line-polar.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<HighCharts
@content={{this.chartData}}
@chartOptions={{this.chartOptions}}
/>
44 changes: 44 additions & 0 deletions test-app/app/components/chart-line-polar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Component from '@glimmer/component';

const DIRECTIONS = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
const WIND_DATA = [
0, 10, 15, 10, 20, 45, 47, 90, 110, 115, 130, 150, 160, 188, 190, 185, 192,
];

export default class LineBasic extends Component {
chartOptions = {
chart: {
type: 'line',
polar: true,
},
title: {
text: 'Wind direction history',
},
xAxis: {
tickInterval: 45,
min: 0,
max: 360,
labels: {
formatter: function ({ value }) {
return DIRECTIONS[Math.round(value / 45)];
},
},
},
yAxis: {
min: 0,
max: 1,
labels: {
enabled: false,
},
},
tooltip: false,
};

chartData = [
{
name: 'Amisbühl',
data: WIND_DATA.map((x, i) => ({ x, y: i / (WIND_DATA.length - 1) })),
connectEnds: false,
},
];
}
5 changes: 5 additions & 0 deletions test-app/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<ChartBarBasic />
</section>

<section>
<h3>Polar chart</h3>
<ChartLinePolar />
</section>

<section>
<h3>Basic highmaps chart</h3>
<ChartMapBasic />
Expand Down

0 comments on commit 3b374c9

Please sign in to comment.