Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
bb9ccbe51a
5 changed files with 74 additions and 57 deletions
|
|
@ -3,6 +3,6 @@
|
|||
[ngStyle]=" {'left.px': this.position.left, 'top.px': this.position.top}"
|
||||
id="chartjs-tooltip">
|
||||
<span [style.background]="item.color" class="tooltip-color"></span>
|
||||
{{ item.title }} {{ item.body }}
|
||||
{{ item.title }} : {{item.body}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -227,25 +227,6 @@ export class ErvuChartV2 extends Control implements Filterable {
|
|||
chartOptions.plugins = chartOptions.plugins ? chartOptions.plugins : {};
|
||||
|
||||
chartOptions.plugins.legend = this.legend ? this.legend : {};
|
||||
chartOptions.plugins.tooltip = {
|
||||
enabled: false, //Disables default tooltip from charjs (we'll use a custom tooltip)
|
||||
external: (context) => {
|
||||
if (this.showTooltip) {
|
||||
if (!context || !this.chartTooltip) {
|
||||
return;
|
||||
}
|
||||
const positionX = this.chart.canvas.offsetLeft;
|
||||
const positionY = this.chart.canvas.offsetTop;
|
||||
|
||||
this.tooltipModel = context.tooltip;
|
||||
this.tooltipPosition = {
|
||||
'left': positionX + context.tooltip.caretX,
|
||||
'top': positionY + context.tooltip.caretY
|
||||
}
|
||||
this.cd.markForCheck();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (this.title && this.title.text) {
|
||||
chartOptions.plugins.title = this.title;
|
||||
|
|
@ -316,14 +297,43 @@ export class ErvuChartV2 extends Control implements Filterable {
|
|||
Object.assign(chartOptions, this.options);
|
||||
}
|
||||
|
||||
chartConfig.tooltips = {
|
||||
let labelGroups: string[][];
|
||||
if (chartConfig.type == 'doughnut' && datasets.length > 1) { //Group labels only for the doughnut with inner rings
|
||||
labelGroups = this.splitLabels(chartConfig.data.labels, datasets);
|
||||
}
|
||||
|
||||
chartOptions.plugins.tooltip = {
|
||||
enabled: false, //Disables default tooltip from charjs (we'll use a custom tooltip)
|
||||
external: (context) => {
|
||||
if (this.showTooltip) {
|
||||
if (!context || !this.chartTooltip) {
|
||||
return;
|
||||
}
|
||||
const positionX = this.chart.canvas.offsetLeft;
|
||||
const positionY = this.chart.canvas.offsetTop;
|
||||
|
||||
this.tooltipModel = context.tooltip;
|
||||
this.tooltipPosition = {
|
||||
'left': positionX + context.tooltip.caretX,
|
||||
'top': positionY + context.tooltip.caretY
|
||||
}
|
||||
this.cd.markForCheck();
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
title: function (tooltipItem, data) {
|
||||
return data.labels[tooltipItem[0].index]
|
||||
title: function (tooltipItems) {
|
||||
const item = tooltipItems[0];
|
||||
if (!labelGroups) {
|
||||
return item.label || '';
|
||||
}
|
||||
return labelGroups[item.datasetIndex][item.dataIndex] || '';
|
||||
},
|
||||
label: function (tooltipItem, data) {
|
||||
let dataset = data.datasets[tooltipItem.datasetIndex];
|
||||
return dataset.label + ": " + dataset.data[tooltipItem.index];
|
||||
label: function (tooltipItem) {
|
||||
const dataset = tooltipItem.dataset;
|
||||
if (dataset.type == 'bar' || dataset.type == 'line') {
|
||||
return dataset.data[tooltipItem.dataIndex].y.toLocaleString();
|
||||
}
|
||||
return dataset.data[tooltipItem.dataIndex].toLocaleString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -355,6 +365,19 @@ export class ErvuChartV2 extends Control implements Filterable {
|
|||
.map(val => val.y = '');
|
||||
}
|
||||
|
||||
private splitLabels(labels: string[], datasets: { data: number[] }[]) {
|
||||
let result: string[][] = [];
|
||||
let startIndex = 0;
|
||||
datasets.forEach((dataset) => {
|
||||
const length = dataset.data.length;
|
||||
const endIndex = startIndex + length;
|
||||
result.push(labels.slice(startIndex, endIndex));
|
||||
startIndex = endIndex;
|
||||
})
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
clear() { //todo SUPPORT-4909
|
||||
throw new UnsupportedOperationError("Unsupported operation");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
AdvancedProperty,
|
||||
AnalyticalScope,
|
||||
Behavior,
|
||||
ChartFontFamily,
|
||||
|
|
@ -18,9 +19,12 @@ export class BarDataLabelChartPlugin extends Behavior implements ChartPlugin {
|
|||
|
||||
public labelAxis = 'y';
|
||||
|
||||
public weight: number = 500;
|
||||
public size: number = 12;
|
||||
public family: ChartFontFamily = ChartFontFamily.SANS_SERIF;
|
||||
@AdvancedProperty()
|
||||
public defaultFontFamily: string = ChartFontFamily.SANS_SERIF;
|
||||
@AdvancedProperty()
|
||||
public defaultFontWeight: string = '500';
|
||||
@AdvancedProperty()
|
||||
public defaultFontSize: number = 14;
|
||||
|
||||
public useStaticColor: boolean = true;
|
||||
@Visible('useStaticColor == true')
|
||||
|
|
@ -31,11 +35,17 @@ export class BarDataLabelChartPlugin extends Behavior implements ChartPlugin {
|
|||
afterDatasetDraw(chart: Chart, args: { index: number; meta: ChartMeta }): void {
|
||||
let ctx = chart.ctx;
|
||||
let data = chart.data.datasets[args.index];
|
||||
|
||||
const fixRatio = window.devicePixelRatio;
|
||||
const textFontSize = () => {
|
||||
return fixRatio > 1 ? Math.round(this.defaultFontSize / fixRatio) : this.defaultFontSize;
|
||||
}
|
||||
|
||||
args.meta.data.forEach((datapoint: any, i) => {
|
||||
ctx.font = ChartUtils.getFont({
|
||||
family: this.family,
|
||||
weight: String(this.weight),
|
||||
size: this.size
|
||||
family: this.defaultFontFamily,
|
||||
weight: String(this.defaultFontWeight),
|
||||
size: textFontSize()
|
||||
});
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillStyle = this.useStaticColor ? this.color : datapoint.options.backgroundColor;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -5968,7 +5968,7 @@
|
|||
<children id="68355668-b4ac-44f9-ae87-1af8c269dbcc">
|
||||
<prototypeId>ba24d307-0b91-4299-ba82-9d0b52384ff2</prototypeId>
|
||||
<componentRootId>68355668-b4ac-44f9-ae87-1af8c269dbcc</componentRootId>
|
||||
<name>Факт предоставления отсрочки или освобждения от призыва</name>
|
||||
<name>Факт предоставления отсрочки или освобождения от призыва</name>
|
||||
<container>false</container>
|
||||
<childrenReordered>false</childrenReordered>
|
||||
<scripts id="cf4526a1-96ab-4820-8aa9-62fb54c2b64c">
|
||||
|
|
@ -5986,7 +5986,7 @@
|
|||
<entry>
|
||||
<key>initialValue</key>
|
||||
<value>
|
||||
<simple>"Факт предоставления отсрочки или освобждения от призыва"</simple>
|
||||
<simple>"Факт предоставления отсрочки или освобождения от призыва"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue