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

Add preserve space support and documentation for OrganizationChart #17438

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { ImportDoc } from './importdoc';
import { SelectionDoc } from './selectiondoc';
import { StyleDoc } from './styledoc';
import { TemplateDoc } from './templatedoc';
import { PreserveSpaceDoc } from '@/doc/organizationchart/preservespacedoc';

@NgModule({
imports: [CommonModule, RouterModule, AppCodeModule, AppDocModule, OrganizationChartModule],
exports: [AppDocModule],
declarations: [ImportDoc, BasicDoc, TemplateDoc, SelectionDoc, ColoredDoc, StyleDoc, AccessibilityDoc]
declarations: [ImportDoc, BasicDoc, TemplateDoc, SelectionDoc, ColoredDoc, PreserveSpaceDoc, StyleDoc, AccessibilityDoc]
})
export class OrganizationChartDocModule {}
119 changes: 119 additions & 0 deletions apps/showcase/doc/organizationchart/preservespacedoc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { Code } from '@/domain/code';
import { Component } from '@angular/core';
import { TreeNode } from 'primeng/api';

@Component({
selector: 'preserve-space-doc',
standalone: false,
template: `
<app-docsectiontext>
<p>
Use the <i>preserveSpace</i> option when you want to remove extra whitespace in the layout when nodes in the tree are collapsed. This helps optimize the use of screen space and is ideal for reducing empty gaps in dynamic or large
trees.
</p>
</app-docsectiontext>
<div class="card flex justify-center overflow-x-auto">
<p-organization-chart [value]="data" [preserveSpace]="false" [collapsible]="true" />
</div>
<app-code [code]="code" selector="organization-chart-preserve-space-doc"></app-code>
`
})
export class PreserveSpaceDoc {
data: TreeNode[] = [
{
label: 'Argentina',
expanded: true,
children: [
{
label: 'Argentina',
expanded: false,
children: [
{
label: 'Argentina'
},
{
label: 'France'
},
{
label: 'Switzerland'
}
]
},
{
label: 'France',
expanded: true,
children: [
{
label: 'France'
},
{
label: 'Morocco'
},
{
label: 'Switzerland'
}
]
}
]
}
];

code: Code = {
basic: `<p-organization-chart [value]="data" [preserveSpace]="true" [collapsible]="true" />`,

html: `<div class="card flex justify-center">
<p-organization-chart [value]="data" [preserveSpace]="true" [collapsible]="true" />
</div>`,

typescript: `import { Component } from '@angular/core';
import { TreeNode } from 'primeng/api';
import { OrganizationChartModule } from 'primeng/organizationchart';

@Component({
selector: 'organization-chart-preserve-space-doc',
templateUrl: './organization-chart-preserve-space-doc.html',
standalone: true,
imports: [OrganizationChartModule]
})
export class OrganizationChartPreserveSpaceDoc {
data: TreeNode[] = [
{
label: 'Argentina',
expanded: true,
children: [
{
label: 'Argentina',
expanded: false,
children: [
{
label: 'Argentina'
},
{
label: 'France'
},
{
label: 'Switzerland'
}
]
},
{
label: 'France',
expanded: true,
children: [
{
label: 'France'
},
{
label: 'Morocco'
},
{
label: 'Switzerland'
}
]
}
]
}
];
}`
};
}
7 changes: 6 additions & 1 deletion apps/showcase/pages/organizationchart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { OrganizationChartDocModule } from '@/doc/organizationchart/organization
import { SelectionDoc } from '@/doc/organizationchart/selectiondoc';
import { TemplateDoc } from '@/doc/organizationchart/templatedoc';
import { Component } from '@angular/core';
import { PreserveSpaceDoc } from '@/doc/organizationchart/preservespacedoc';

@Component({
template: ` <app-doc docTitle="Angular Organization Chart Component" header="OrganizationChart" description="OrganizationChart visualizes hierarchical organization data." [docs]="docs" [apiDocs]="['OrganizationChart']"></app-doc>`,
Expand All @@ -25,6 +26,11 @@ export class OrganizationChartDemo {
label: 'Basic',
component: BasicDoc
},
{
id: 'preserve-space',
label: 'Preserve Space',
component: PreserveSpaceDoc
},
{
id: 'template',
label: 'Template',
Expand All @@ -40,7 +46,6 @@ export class OrganizationChartDemo {
label: 'Colored',
component: ColoredDoc
},

{
id: 'accessibility',
label: 'Accessibility',
Expand Down
11 changes: 9 additions & 2 deletions packages/primeng/src/organizationchart/organizationchart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,15 @@ export class OrganizationChartNode implements OnDestroy {
}

getChildStyle(node: TreeNode<any>) {
const isNodeVisible = !this.leaf && node.expanded;
if(!this.chart.preserveSpace){
return {
visibility: isNodeVisible ? 'inherit' : 'hidden',
display: isNodeVisible ? undefined : 'none'
};
}
return {
visibility: !this.leaf && node.expanded ? 'inherit' : 'hidden'
visibility: isNodeVisible ? 'inherit' : 'hidden',
};
}

Expand Down Expand Up @@ -175,7 +182,7 @@ export class OrganizationChartNode implements OnDestroy {
standalone: true,
imports: [CommonModule, OrganizationChartNode, SharedModule],
template: `
<div [ngStyle]="style" [class]="styleClass" [ngClass]="{ 'p-organizationchart p-component': true, 'p-organizationchart-preservespace': preserveSpace }" [attr.data-pc-section]="'root'">
<div [ngStyle]="style" [class]="styleClass" [ngClass]="{ 'p-organizationchart p-component': true }" [attr.data-pc-section]="'root'">
<table class="p-organizationchart-table" [collapsible]="collapsible" pOrganizationChartNode [node]="root" *ngIf="root"></table>
</div>
`,
Expand Down
Loading