Skip to content

Commit

Permalink
Use a unique mask ID for each percent gauge chart (#1983)
Browse files Browse the repository at this point in the history
* Use a unique mask ID for each percent gauge chart

* (release): 21.1.2
  • Loading branch information
marjan-georgiev authored Jan 24, 2025
1 parent 3688955 commit 47a4f57
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 21.1.2

- Fix: Percent Gauge Chart: Ensures the circle mask ID is unique for each chart

## 21.1.1

- Fix: Percent Gauge Chart: Fixes server-side-rendering
Expand Down
2 changes: 1 addition & 1 deletion projects/swimlane/ngx-charts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swimlane/ngx-charts",
"version": "21.1.1",
"version": "21.1.2",
"description": "Declarative Charting Framework for Angular",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { calculateViewDimensions } from '../../common/view-dimensions.helper';
import { ColorHelper } from '../../common/color.helper';
import { ViewDimensions } from '../../common/types/view-dimension.interface';
import { ScaleType } from '../../common/types/scale-type.enum';
import { id } from '../../utils/id';

@Component({
selector: 'ngx-charts-percent-gauge',
template: `
<ngx-charts-chart [view]="[width, height]" [showLegend]="false" [animations]="animations">
<svg:g class="percent-gauge chart" (click)="onClick()">
<svg:g [attr.transform]="transform">
<mask id="circleMask">
<mask [attr.id]="circleMaskId">
<circle
[attr.r]="radius"
[style.stroke-width]="radius / 5"
Expand All @@ -38,7 +39,7 @@ import { ScaleType } from '../../common/types/scale-type.enum';
[style.stroke-dasharray]="dashes"
/>
<svg:g mask="url(#circleMask)">
<svg:g [attr.mask]="'url(#' + circleMaskId + ')'">
<svg:g [attr.transform]="circleTransform">
<svg:g *ngFor="let tic of ticks" [attr.transform]="tic.transform">
<rect
Expand Down Expand Up @@ -125,6 +126,7 @@ export class PercentGaugeComponent extends BaseChartComponent {
targetRadius: number;
targetTextTransform: string;

circleMaskId: string;
circleTransform: string;
ticks: any[] = [];
ticHeight: number;
Expand All @@ -142,6 +144,8 @@ export class PercentGaugeComponent extends BaseChartComponent {
update(): void {
super.update();

this.circleMaskId = `circleMask${id()}`;

this.margin = [...this.defaultMargin];
if (this.showLabel) {
this.margin[2] = 50;
Expand Down

0 comments on commit 47a4f57

Please sign in to comment.