@opitzconsulting/pie-chart
Version:
animated pie chart component
803 lines (796 loc) • 82 kB
JavaScript
import { Injectable, NgModule, Component, Input, ElementRef, Output, EventEmitter, defineInjectable } from '@angular/core';
import { select, interpolate, arc } from 'd3';
import { BrowserModule } from '@angular/platform-browser';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var PieChartService = /** @class */ (function () {
function PieChartService() {
}
PieChartService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] },
];
/** @nocollapse */
PieChartService.ctorParameters = function () { return []; };
/** @nocollapse */ PieChartService.ngInjectableDef = defineInjectable({ factory: function PieChartService_Factory() { return new PieChartService(); }, token: PieChartService, providedIn: "root" });
return PieChartService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var PieChartComponent = /** @class */ (function () {
/**
* constructor
* @param element
*/
function PieChartComponent(element) {
this.element = element;
/**
* chart data, which should be displayed
*/
this.data = [];
/**
* chart width in pixel
*/
this.width = 250;
/**
* chart height in pixel
*/
this.height = 250;
/**
* duration of animation transition
*/
this.duration = 1000;
/**
* inner spacing in pixel, if greater than 0 it defines the radius of the empty circle in the middle
*/
this.innerSpacing = 0;
/**
* outer spacing in pixel
*/
this.outerSpacing = 1;
/**
* fired when user clicks on a chart entry
*/
this.chartClick = new EventEmitter();
/**
* fired when user hovers a chart entry
*/
this.chartHover = new EventEmitter();
/**
* current chart data with angle and path definitions, it will be consistent to the representation
*/
this.curData = [];
/**
* end chart data with angle and path definitions, it will representate the end state and used only for interpolation
*/
this.endData = [];
/**
* copy of last processed data, used to identify changes in ngDoCheck that Angular overlooked
*/
this.lastData = [];
/**
* Function for interrupt a running chart animation. Necessary because if transition is still active
* when a new transition is started, tween factory function from previos transition will still be fired
* until end of transition is reached. For entries which have a started transition the tween factory
* function will be fired multiple times with different tween interpolation range!
*/
this.interrupt = undefined;
}
/**
* Creates a deep copy of an variable. Do not use this function with recursive objects or
* browser objects like window or document.
* ToDo: should be outsourced.
* @param v
*/
/**
* Creates a deep copy of an variable. Do not use this function with recursive objects or
* browser objects like window or document.
* ToDo: should be outsourced.
* @template T
* @param {?} v
* @return {?}
*/
PieChartComponent.prototype.deepCopy = /**
* Creates a deep copy of an variable. Do not use this function with recursive objects or
* browser objects like window or document.
* ToDo: should be outsourced.
* @template T
* @param {?} v
* @return {?}
*/
function (v) {
return JSON.parse(JSON.stringify(v));
};
/**
* @return {?}
*/
PieChartComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
this.tooltip = /** @type {?} */ (this.element.nativeElement.querySelector('div.pie-chart-tooltip'));
};
/**
* Fired when Angular (re-)sets data-bound properties. This function does not fire when changed data in bound objects or arrays.
* Angular only checks references.
* @param changes
*/
/**
* Fired when Angular (re-)sets data-bound properties. This function does not fire when changed data in bound objects or arrays.
* Angular only checks references.
* @param {?} changes
* @return {?}
*/
PieChartComponent.prototype.ngOnChanges = /**
* Fired when Angular (re-)sets data-bound properties. This function does not fire when changed data in bound objects or arrays.
* Angular only checks references.
* @param {?} changes
* @return {?}
*/
function (changes) {
// check if entries in bound data property has changed
this.detectDataChange();
};
/**
* Fired during every change detection run to detect and act upon changes that Angular can't or won't detect on its own.
*/
/**
* Fired during every change detection run to detect and act upon changes that Angular can't or won't detect on its own.
* @return {?}
*/
PieChartComponent.prototype.ngDoCheck = /**
* Fired during every change detection run to detect and act upon changes that Angular can't or won't detect on its own.
* @return {?}
*/
function () {
// check if entries in bound data property has changed
this.detectDataChange();
};
/**
* Checks whether the data property has changed. This function also check whether only an item property has
* changed. In case of change the chart will be rendered.
*/
/**
* Checks whether the data property has changed. This function also check whether only an item property has
* changed. In case of change the chart will be rendered.
* @return {?}
*/
PieChartComponent.prototype.detectDataChange = /**
* Checks whether the data property has changed. This function also check whether only an item property has
* changed. In case of change the chart will be rendered.
* @return {?}
*/
function () {
// fast check: if items were added or removed
var /** @type {?} */ dataChanged = (this.data.length !== this.lastData.length);
// detail check:
if (dataChanged === false) {
// loop all items
for (var /** @type {?} */ idx = 0; idx < this.data.length; ++idx) {
var /** @type {?} */ a = this.data[idx];
var /** @type {?} */ b = this.lastData[idx];
// check internal item properties
dataChanged = dataChanged || (a.caption !== b.caption || a.color !== b.color || a.value !== b.value);
// for optimization, stop if change detected
if (dataChanged)
break;
}
}
// if change detected
if (dataChanged) {
// render chart
this.render();
// copy current data to identify changes
this.lastData = this.deepCopy(this.data);
}
};
/**
* Generates a random color for a chart item.
*/
/**
* Generates a random color for a chart item.
* @param {?} value
* @return {?}
*/
PieChartComponent.prototype.generateRandomColor = /**
* Generates a random color for a chart item.
* @param {?} value
* @return {?}
*/
function (value) {
var /** @type {?} */ hue2rgb = function (p, q, t) {
if (t < 0)
t += 1;
if (t > 1)
t -= 1;
if (t < 1 / 6)
return p + (q - p) * 6 * t;
if (t < 1 / 2)
return q;
if (t < 2 / 3)
return p + (q - p) * (2 / 3 - t) * 6;
return p;
};
// make sure, generated color does not exists yet in data array
var /** @type {?} */ color;
var /** @type {?} */ uniqueColorGenerated = false;
while (uniqueColorGenerated === false) {
var /** @type {?} */ h = (Math.random() + 0.618033988749895) % 1;
var /** @type {?} */ s = .5;
var /** @type {?} */ l = .6;
var /** @type {?} */ q = l + s - l * s;
var /** @type {?} */ p = 2 * l - q;
var /** @type {?} */ r = hue2rgb(p, q, h + 1 / 3);
var /** @type {?} */ g = hue2rgb(p, q, h);
var /** @type {?} */ b = hue2rgb(p, q, h - 1 / 3);
color = '#'
+ Math.round(r * 255).toString(16)
+ Math.round(g * 255).toString(16)
+ Math.round(b * 255).toString(16);
uniqueColorGenerated = (this.data.map(function (d) { return d.color; }).filter(function (d) { return d === color; }).length === 0);
}
return color;
};
/**
* generates a pie chart item definition
* @param item
* @param index
* @param value
* @param startAngle
* @param endAngle
*/
/**
* generates a pie chart item definition
* @param {?} item
* @param {?} index
* @param {?} value
* @param {?} startAngle
* @param {?} endAngle
* @return {?}
*/
PieChartComponent.prototype.generatePieArcData = /**
* generates a pie chart item definition
* @param {?} item
* @param {?} index
* @param {?} value
* @param {?} startAngle
* @param {?} endAngle
* @return {?}
*/
function (item, index, value, startAngle, endAngle) {
// generate definition
var /** @type {?} */ result = {
data: item,
index: index,
value: value,
startAngle: startAngle,
endAngle: endAngle,
padAngle: 0,
innerRadius: this.radius - 40,
outerRadius: this.radius
};
// generate svg path d-attribute from definition
(/** @type {?} */ (result.data)).path = this.pathGenerator(result);
// return definition
return result;
};
/**
* Checks whether items were deleted and initiate delete transition for these items.
*/
/**
* Checks whether items were deleted and initiate delete transition for these items.
* @return {?}
*/
PieChartComponent.prototype.detectDeletedEntries = /**
* Checks whether items were deleted and initiate delete transition for these items.
* @return {?}
*/
function () {
var _this = this;
// loop current state entries
this.curData.forEach(function (curItem, idx) {
// only check if current entry is not marked as deleted
if (curItem.data.deleted !== true) {
// check if entry not exists anymore
var /** @type {?} */ isDeleted = (_this.data.filter(function (item) { return item.caption === curItem.data.caption; }).length === 0);
// if entry is deleted
if (isDeleted) {
// mark entry in current state as deleted
// mark entry in current state as deleted
_this.curData[idx].data.deleted = true;
// mark entry in end state as deleted and set value to 0 for transtion
// mark entry in end state as deleted and set value to 0 for transtion
_this.endData[idx].data.deleted = true;
_this.endData[idx].value = 0;
}
}
});
};
/**
* Checks whether items were inserted and initiate insert transition for these items.
*/
/**
* Checks whether items were inserted and initiate insert transition for these items.
* @return {?}
*/
PieChartComponent.prototype.detectInsertedEntries = /**
* Checks whether items were inserted and initiate insert transition for these items.
* @return {?}
*/
function () {
var _this = this;
// loop given data array
this.data.forEach(function (item, idx) {
// check if entry is new
var /** @type {?} */ isInserted = (_this.curData.filter(function (curItem) { return curItem.data.deleted !== true && curItem.data.caption === item.caption; }).length === 0);
// if entry is new
if (isInserted) {
{
var /** @type {?} */ d = _this.generatePieArcData(_this.deepCopy(item), idx, 0, -1, -1);
_this.curData.splice(idx, 0, d);
}
{
var /** @type {?} */ d = _this.generatePieArcData(_this.deepCopy(item), idx, item.value, -1, -1);
_this.endData.splice(idx, 0, d);
}
}
});
};
/**
* Checks whether items were moved and initiate transition for these items.
*/
/**
* Checks whether items were moved and initiate transition for these items.
* @return {?}
*/
PieChartComponent.prototype.detectMovedEntries = /**
* Checks whether items were moved and initiate transition for these items.
* @return {?}
*/
function () {
// separate index in current state array
var /** @type {?} */ curIndex = 0;
// loop data array
for (var /** @type {?} */ index = 0; index < this.data.length; ++index) {
// find next index in current state array, skip items marked as deleted
while (this.curData[curIndex].data.deleted)
++curIndex;
// check if item is moved by comparing captions
if (this.data[index].caption !== this.curData[curIndex].data.caption) {
{
// mark item in current state array as deleted
this.curData[curIndex].data.deleted = true;
// mark item in end state array as deleted and set value to 0 for transition
this.endData[curIndex].data.deleted = true;
this.endData[curIndex].value = 0;
}
{
var /** @type {?} */ item = this.deepCopy(this.data[index]);
var /** @type {?} */ d = this.generatePieArcData(item, -1, 0, -1, -1);
this.curData.splice(curIndex, 0, d);
}
{
var /** @type {?} */ item = this.deepCopy(this.data[index]);
var /** @type {?} */ d = this.generatePieArcData(item, -1, item.value, -1, -1);
this.endData.splice(curIndex, 0, d);
}
// because of inserting item to the array's, increment index twice
++curIndex;
}
++curIndex;
}
};
/**
* Synchronize state arrays (curData / endData) with given items (data).
*/
/**
* Synchronize state arrays (curData / endData) with given items (data).
* @return {?}
*/
PieChartComponent.prototype.syncItems = /**
* Synchronize state arrays (curData / endData) with given items (data).
* @return {?}
*/
function () {
var _this = this;
// sync values and colors
this.data.forEach(function (item, index) {
// find item index in state array's
var /** @type {?} */ curIndex = 0;
for (var /** @type {?} */ i = 0; i < _this.curData.length; ++i) {
if (!_this.curData[i].data.deleted && _this.curData[i].data.caption === item.caption) {
curIndex = i;
break;
}
}
// update value in state entries
// update value in state entries
_this.curData[curIndex].data.value = item.value;
_this.endData[curIndex].data.value = item.value;
// update value in end state entry for transition
// update value in end state entry for transition
_this.endData[curIndex].value = item.value;
// update color in end state entry for transition
// update color in end state entry for transition
_this.endData[curIndex].data.color = item.color;
});
};
/**
* will be triggerd to animate chart changes.
* important! this method musst be called within a setTimeout function because of angulars
* rendering cycle.
*/
/**
* will be triggerd to animate chart changes.
* important! this method musst be called within a setTimeout function because of angulars
* rendering cycle.
* @return {?}
*/
PieChartComponent.prototype.animateChanges = /**
* will be triggerd to animate chart changes.
* important! this method musst be called within a setTimeout function because of angulars
* rendering cycle.
* @return {?}
*/
function () {
var _this = this;
// get svg element reference
var /** @type {?} */ svg = (/** @type {?} */ (this.element.nativeElement.querySelector('svg')));
// reference all path elements in svg element
var /** @type {?} */ paths = select(svg).selectAll('path');
// define interruption function to stop running animations
this.interrupt = function () {
// call paths interrupt method
paths.interrupt();
// delete interupt definition
delete _this.interrupt;
};
// start path animation
paths
.transition()
.duration(this.duration)
.attrTween('pie-tween-dummy', function (arg0, idx, nodeList) {
// create interpolation functions to calculate step values
var /** @type {?} */ iValue = interpolate(_this.curData[idx].value, _this.endData[idx].value);
var /** @type {?} */ iStartAngle = interpolate(_this.curData[idx].startAngle, _this.endData[idx].startAngle);
var /** @type {?} */ iEndAngle = interpolate(_this.curData[idx].endAngle, _this.endData[idx].endAngle);
var /** @type {?} */ iColor = interpolate(_this.curData[idx].data.color, _this.endData[idx].data.color);
// return factory function for animation steps
return function (t) {
// interpolate values by given transition value
// interpolate values by given transition value
_this.curData[idx].value = iValue(t);
_this.curData[idx].startAngle = iStartAngle(t);
_this.curData[idx].endAngle = iEndAngle(t);
_this.curData[idx].data.color = iColor(t);
// generate new path
// generate new path
_this.curData[idx].data.path = _this.pathGenerator(_this.curData[idx]);
// return empty string. This is only necessary for typescript compiler. Nothing should be changed here.
return '';
};
})
.on('end', function (arg0, idx, nodeList) {
// when transition is complete for the last item
if (idx === nodeList.length - 1) {
// remove as deleted marked entries
// remove as deleted marked entries
_this.cleanStateItems();
// Delete interupt definition, because everything has finished and nothing can be interrupted.
delete _this.interrupt;
}
});
};
/**
* Must be called after transition ends to remove entries in curData and endData which are marked
* as deleted.
*/
/**
* Must be called after transition ends to remove entries in curData and endData which are marked
* as deleted.
* @return {?}
*/
PieChartComponent.prototype.cleanStateItems = /**
* Must be called after transition ends to remove entries in curData and endData which are marked
* as deleted.
* @return {?}
*/
function () {
// clean current state array
for (var /** @type {?} */ i = this.curData.length - 1; i >= 0; --i) {
if (this.curData[i].data.deleted === true) {
this.curData.splice(i, 1);
}
}
// clean end state array
for (var /** @type {?} */ i = this.endData.length - 1; i >= 0; --i) {
if (this.endData[i].data.deleted === true) {
this.endData.splice(i, 1);
}
}
};
/**
* Checks whether all items have assigned color values and if necessary completes colors in given data array.
*/
/**
* Checks whether all items have assigned color values and if necessary completes colors in given data array.
* @return {?}
*/
PieChartComponent.prototype.initColors = /**
* Checks whether all items have assigned color values and if necessary completes colors in given data array.
* @return {?}
*/
function () {
var _this = this;
// loop all entries
this.data.forEach(function (item) {
// if no color is assigned
if (!item.color) {
// generate random color for item
item.color = _this.generateRandomColor(item.value);
}
});
};
/**
* Returns maximal angle of current state items.
*/
/**
* Returns maximal angle of current state items.
* @return {?}
*/
PieChartComponent.prototype.getMaxAngle = /**
* Returns maximal angle of current state items.
* @return {?}
*/
function () {
var /** @type {?} */ maxAngle = 0;
this.curData.forEach(function (curItem) {
if (curItem.endAngle > maxAngle) {
maxAngle = curItem.endAngle;
}
});
return maxAngle;
};
/**
* Calculates angles for current and end state items.
* @param maxAngle last maximal angle in current state to avoid "jumping" transitions
*/
/**
* Calculates angles for current and end state items.
* @param {?} maxAngle last maximal angle in current state to avoid "jumping" transitions
* @return {?}
*/
PieChartComponent.prototype.calculateAngles = /**
* Calculates angles for current and end state items.
* @param {?} maxAngle last maximal angle in current state to avoid "jumping" transitions
* @return {?}
*/
function (maxAngle) {
var _this = this;
{
// calculate sum of values
var /** @type {?} */ total_1 = this.curData.reduce(function (p, c) { return p + c.value; }, 0);
// loop items and calculate start and end angles, initialize rendering
var /** @type {?} */ lastAngle_1 = 0;
this.curData.forEach(function (item, idx) {
// calculate angles by last used maximal angle. without data (total=0) simulate 0 values, so draw items in clockwise direction.
var /** @type {?} */ nextAngle = lastAngle_1 + ((maxAngle) / ((total_1 === 0) ? 1 : total_1)) * item.value;
item.startAngle = lastAngle_1;
item.endAngle = nextAngle;
item.index = idx;
item.data.path = _this.pathGenerator(item);
lastAngle_1 = nextAngle;
});
}
{
// calculate sum of values
var /** @type {?} */ total_2 = this.endData.reduce(function (p, c) { return p + c.value; }, 0);
// loop items and calculate start and end angles, initialize rendering
var /** @type {?} */ lastAngle_2 = 0;
this.endData.forEach(function (item, idx) {
// calculate angles with circumference. without data (total=0) simulate 0 values, so draw items in anti-clockwise direction.
var /** @type {?} */ nextAngle = lastAngle_2 + ((2 * Math.PI) / ((total_2 === 0) ? 1 : total_2)) * item.value;
item.startAngle = lastAngle_2;
item.endAngle = nextAngle;
item.index = idx;
item.data.path = _this.pathGenerator(item);
lastAngle_2 = nextAngle;
});
}
};
/**
* fired when mouse enters a pie chart path element and shows tooltip
* @param {?} event
* @return {?}
*/
PieChartComponent.prototype.overPath = /**
* fired when mouse enters a pie chart path element and shows tooltip
* @param {?} event
* @return {?}
*/
function (event) {
// get tooltip-text of path element
var /** @type {?} */ txt = (/** @type {?} */ (event.target)).getAttribute('tooltip');
// show tooltip and assign text
select(this.tooltip)
.html(txt)
.style('display', 'block')
.transition()
.duration(250)
.style('opacity', 1);
// get index
var /** @type {?} */ idx = parseInt((/** @type {?} */ (event.target)).getAttribute('idx'), 10);
// get caption of element
var /** @type {?} */ caption = this.curData[idx].data.caption;
// get original data by caption
var /** @type {?} */ item = this.data.filter(function (d) { return d.caption === caption; })[0];
// if data found then emit chart click event
if (item) {
this.chartHover.emit(item);
}
};
/**
* fired when mouse moves over a pie chart path element and adjusts tooltip
* @param {?} event
* @return {?}
*/
PieChartComponent.prototype.movePath = /**
* fired when mouse moves over a pie chart path element and adjusts tooltip
* @param {?} event
* @return {?}
*/
function (event) {
// aggregate scroll positions, because event.page* properties are relative to top left corner of document
var /** @type {?} */ offsetX = 0;
var /** @type {?} */ offsetY = 0;
var /** @type {?} */ element = (/** @type {?} */ (this.tooltip.parentElement));
while (element) {
offsetX += element.scrollLeft;
offsetY += element.scrollTop;
element = element.parentElement;
}
// adjust tooltip
select(this.tooltip)
.style('top', (event.pageY - offsetY + 10) + 'px')
.style('left', (event.pageX - offsetX + 10) + 'px');
};
/**
* fired when mouse leaves a pie chart path element and hides tooltip
* @param {?} event
* @return {?}
*/
PieChartComponent.prototype.outPath = /**
* fired when mouse leaves a pie chart path element and hides tooltip
* @param {?} event
* @return {?}
*/
function (event) {
var _this = this;
// hide tooltip
select(this.tooltip)
.transition()
.duration(250)
.style('opacity', 0)
.on('end', function () {
select(_this.tooltip).style('display', 'none');
});
};
/**
* fired when user clicks on a pie chart path element
* @param {?} event
* @return {?}
*/
PieChartComponent.prototype.clickPath = /**
* fired when user clicks on a pie chart path element
* @param {?} event
* @return {?}
*/
function (event) {
// get index
var /** @type {?} */ idx = parseInt((/** @type {?} */ (event.target)).getAttribute('idx'), 10);
// get caption of element
var /** @type {?} */ caption = this.curData[idx].data.caption;
// get original data by caption
var /** @type {?} */ item = this.data.filter(function (d) { return d.caption === caption; })[0];
// if data found then emit chart click event
if (item) {
this.chartClick.emit(item);
}
};
/**
* main rendering function
*/
/**
* main rendering function
* @return {?}
*/
PieChartComponent.prototype.render = /**
* main rendering function
* @return {?}
*/
function () {
var _this = this;
// interrupt possible running animations
if (this.interrupt)
this.interrupt();
// initialize chart colors
this.initColors();
// calculate radius
this.radius = Math.min(this.width, this.height) / 2;
// calculate middle of chart
this.center = "translate(" + this.width / 2 + ", " + this.height / 2 + ")";
// create path generator
this.pathGenerator = arc().outerRadius(this.radius - this.outerSpacing).innerRadius(this.innerSpacing);
// get current maximal angle, necessary to avoid "jumping" transitions
var /** @type {?} */ maxAngle = this.getMaxAngle();
// check data array for deleted entries and assign transition configuration
this.detectDeletedEntries();
// check data array for inserted entries and assign transition configuration
this.detectInsertedEntries();
// check data array for moved entries and assign transition configuration
this.detectMovedEntries();
// synchronize data entries with current and end state entries
this.syncItems();
// calculate angles for current and end state entries
this.calculateAngles(maxAngle);
// important! use setTimeout because angular first must exec change detection
setTimeout(function () {
// start change animations
// start change animations
_this.animateChanges();
}, 0);
};
PieChartComponent.decorators = [
{ type: Component, args: [{
selector: 'oc-pie-chart',
template: "<div class=\"pie-chart-tooltip\"></div>\n<svg [attr.width]=\"width\" [attr.height]=\"height\">\n <g [attr.transform]=\"center\">\n <path *ngFor=\"let d of curData; let idx = index;\" [attr.idx]=\"idx\" \n [attr.fill]=\"d.data.color\" [attr.d]=\"d.data.path\" [attr.tooltip]=\"d.data.caption\"\n (mouseover)=\"overPath($event)\" (mousemove)=\"movePath($event);\" (mouseout)=\"outPath($event)\" (click)=\"clickPath($event)\" />\n </g>\n</svg>",
styles: ["div.pie-chart-tooltip{position:fixed;display:none;opacity:0;font:12px sans-serif;color:#fff;background-color:rgba(35,47,52,.8);padding:5px}path{opacity:.7;stroke:#fff;stroke-width:2px}path:hover{opacity:1;stroke:#e3e3e3}"]
},] },
];
/** @nocollapse */
PieChartComponent.ctorParameters = function () { return [
{ type: ElementRef }
]; };
PieChartComponent.propDecorators = {
data: [{ type: Input }],
width: [{ type: Input }],
height: [{ type: Input }],
duration: [{ type: Input }],
innerSpacing: [{ type: Input }],
outerSpacing: [{ type: Input }],
chartClick: [{ type: Output }],
chartHover: [{ type: Output }]
};
return PieChartComponent;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var PieChartModule = /** @class */ (function () {
function PieChartModule() {
}
PieChartModule.decorators = [
{ type: NgModule, args: [{
imports: [BrowserModule],
declarations: [PieChartComponent],
exports: [PieChartComponent]
},] },
];
return PieChartModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
export { PieChartService, PieChartComponent, PieChartModule };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3BpdHpjb25zdWx0aW5nLXBpZS1jaG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