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

New Line-Pie Combo Chart #1917

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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 @@ -239,6 +239,7 @@ export class LineChartComponent extends BaseChartComponent implements OnInit {

@Output() activate: EventEmitter<any> = new EventEmitter();
@Output() deactivate: EventEmitter<any> = new EventEmitter();
@Output() tooltipCurrent: EventEmitter<any> = new EventEmitter();

@ContentChild('tooltipTemplate') tooltipTemplate: TemplateRef<any>;
@ContentChild('seriesTooltipTemplate') seriesTooltipTemplate: TemplateRef<any>;
Expand Down Expand Up @@ -442,6 +443,7 @@ export class LineChartComponent extends BaseChartComponent implements OnInit {

updateHoveredVertical(item): void {
this.hoveredVertical = item.value;
this.tooltipCurrent.emit(this.hoveredVertical)
kedij777 marked this conversation as resolved.
Show resolved Hide resolved
this.deactivateAll();
}

Expand Down
68 changes: 68 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,72 @@
(select)="onSelect($event)"
>
</combo-chart-component>

<div *ngIf="chartType === 'combo-chart-line-pie-component'">
<div class = "top-pie-chart">
kedij777 marked this conversation as resolved.
Show resolved Hide resolved
<ngx-charts-pie-chart
class="chart-container"
[view]="view"
[scheme]="colorScheme"
[results]="pieTempData"
[animations]="animations"
[explodeSlices]="explodeSlices"
[labels]="showLabels"
[doughnut]="doughnut"
[arcWidth]="arcWidth"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipText]="pieTooltipText"
(dblclick)="dblclick($event)"
(select)="select($event)"
(activate)="activate($event)"
(deactivate)="deactivate($event)"
>
</ngx-charts-pie-chart>
</div>
<div class = "bottom-line-chart">
kedij777 marked this conversation as resolved.
Show resolved Hide resolved
<ngx-charts-line-chart
[view]="view"
kedij777 marked this conversation as resolved.
Show resolved Hide resolved
class="chart-container"
[scheme]="colorScheme"
[schemeType]="schemeType"
[results]="dateDataWithOrWithoutRange"
[animations]="animations"
[legend]="showLegend"
[legendTitle]="legendTitle"
[legendPosition]="legendPosition"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
[autoScale]="autoScale"
[xScaleMin]="xScaleMin"
[xScaleMax]="xScaleMax"
[yScaleMin]="yScaleMin"
[yScaleMax]="yScaleMax"
[timeline]="timeline"
[showGridLines]="showGridLines"
[curve]="curve"
[rangeFillOpacity]="rangeFillOpacity"
[roundDomains]="roundDomains"
[tooltipDisabled]="tooltipDisabled"
[trimXAxisTicks]="trimXAxisTicks"
[trimYAxisTicks]="trimYAxisTicks"
[maxXAxisTickLength]="maxXAxisTickLength"
[maxYAxisTickLength]="maxYAxisTickLength"
[wrapTicks]="wrapTicks"
(select)="select($event)"
(activate)="activate($event)"
(deactivate)="deactivate($event)"
(tooltipCurrent)="getTooltipCurrent($event)"
>
</ngx-charts-line-chart>
</div>
</div>

<ngx-charts-heat-map
*ngIf="chartType === 'heat-map'"
class="chart-container"
Expand Down Expand Up @@ -1158,6 +1224,8 @@ <h3 (click)="dataVisible = !dataVisible" style="cursor: pointer">
<pre *ngIf="chart.inputFormat === 'bubbleInteractive'">{{ bubbleDemoTempData | json }}</pre>
<pre *ngIf="chart.inputFormat === 'comboChart'">{{ barChart | json }}</pre>
<pre *ngIf="chart.inputFormat === 'comboChart'">{{ lineChartSeries | json }}</pre>
<pre *ngIf="chart.inputFormat === 'linePieCombo'">{{ pieTempData | json }}</pre>
<pre *ngIf="chart.inputFormat === 'linePieCombo'">{{ dateDataWithOrWithoutRange | json }}</pre>
<pre *ngIf="chart.inputFormat === 'timelineFilter'">{{ timelineFilterBarData | json }}</pre>
<div>
<label>
Expand Down
17 changes: 17 additions & 0 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,20 @@ main {
color: $color-text-med;
}
}

.top-pie-chart {
position: absolute;
top: 30%;
left: 50%;
width: 100%;
transform: translate(-50%, -50%);
}

.bottom-line-chart {
position: absolute;
bottom: 30%;
left: 50%;
width: 100%;
transform: translate(-50%, -50%);
}

41 changes: 41 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class AppComponent implements OnInit {
dateDataWithRange: any[];
calendarData: any[];
statusData: any[];
pieTempData: any[];
sparklineData: any[];
timelineFilterBarData: any[];
graph: { links: any[]; nodes: any[] };
Expand Down Expand Up @@ -118,6 +119,7 @@ export class AppComponent implements OnInit {
strokeColor: string = '#FFFFFF';
strokeWidth: number = 2;
wrapTicks = false;
tempXValueForComboPie: any;

curves = {
Basis: shape.curveBasis,
Expand Down Expand Up @@ -297,6 +299,7 @@ export class AppComponent implements OnInit {
this.setColorScheme('cool');
this.calendarData = this.getCalendarData();
this.statusData = this.getStatusData();
this.pieTempData = this.getPieTempData();
this.sparklineData = generateData(1, false, 30);
this.timelineFilterBarData = timelineFilterBarData();
}
Expand Down Expand Up @@ -538,6 +541,11 @@ export class AppComponent implements OnInit {
console.log('Deactivate', JSON.parse(JSON.stringify(data)));
}

getTooltipCurrent(data) {
this.tempXValueForComboPie = data;
this.pieTempData = this.getPieTempData();
}

getInterpolationType(curveType) {
return this.curves[curveType] || this.curves['default'];
}
Expand Down Expand Up @@ -636,6 +644,39 @@ export class AppComponent implements OnInit {
return this.calcStatusData(sales, dur);
}

getPieTempData() {
if (this.tempXValueForComboPie){
kedij777 marked this conversation as resolved.
Show resolved Hide resolved
let data = [];
this.dateDataWithOrWithoutRange.forEach(item => {
const dataPoint = item.series.find(data => data.name === this.tempXValueForComboPie);
data.push({ name: item.name,
value: dataPoint.value,
extra: {
code: item.name.toLowerCase()
}});
kedij777 marked this conversation as resolved.
Show resolved Hide resolved
})
kedij777 marked this conversation as resolved.
Show resolved Hide resolved
return data;
} else {
let sumResult = []
this.dateDataWithOrWithoutRange.forEach(countryData => {
const countryName = countryData.name;
let sum = 0;
countryData.series.forEach(seriesItem => {
sum += seriesItem.value;
kedij777 marked this conversation as resolved.
Show resolved Hide resolved
});
const resultItem = {
name: countryName,
value: sum,
extra: {
code: countryName.toLowerCase().replace(/\s/g, '_') // Convert spaces to underscores
}
kedij777 marked this conversation as resolved.
Show resolved Hide resolved
};
sumResult.push(resultItem);
});
return sumResult;
}
}

calcStatusData(sales = this.statusData[0].value, dur = this.statusData[2].value) {
const ret = sales * this.salePrice;
const cost = ((sales * dur) / 60 / 60 / 1000) * this.personnelCost;
Expand Down
40 changes: 40 additions & 0 deletions src/app/chartTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,46 @@ const chartGroups = [
'tooltipDisabled'
]
},
{
name: 'Line Pie Combo Chart',
selector: 'combo-chart-line-pie-component',
inputFormat: 'linePieCombo',
options: [
'animations',
'colorScheme',
'schemeType',
'showXAxis',
'showYAxis',
'gradient',
'showLegend',
'legendTitle',
'legendPosition',
'showXAxisLabel',
'xAxisLabel',
'showYAxisLabel',
'yAxisLabel',
'autoScale',
'timeline',
'showGridLines',
'curve',
'rangeFillOpacity',
'roundDomains',
'tooltipDisabled',
'xScaleMin',
'xScaleMax',
'yScaleMin',
'yScaleMax',
'trimXAxisTicks',
'trimYAxisTicks',
'rotateXAxisTicks',
'maxXAxisTickLength',
'maxYAxisTickLength',
'wrapTicks',
'doughnut',
'arcWidth',
'explodeSlices'
]
},
{
name: 'Heat Map - Calendar',
selector: 'calendar',
Expand Down