type
stringclasses 7
values | content
stringlengths 4
9.55k
| repo
stringlengths 7
96
| path
stringlengths 4
178
| language
stringclasses 1
value |
---|---|---|---|---|
FunctionDeclaration |
export function toTooltipHtml(input: string | TooltipRendererResult, defaults?: TooltipRendererResult): string {
if (typeof input === 'string') {
return input;
}
defaults = defaults || {};
const {
content = defaults.content || '',
title = defaults.title || undefined,
color = defaults.color || 'white',
backgroundColor = defaults.backgroundColor || '#888'
} = input;
const titleHtml = title ? `<div class="${Chart.defaultTooltipClass}-title"
style="color: ${color}; background-color: ${backgroundColor}">${title}</div>` : '';
return `${titleHtml}<div class="${Chart.defaultTooltipClass}-content">${content}</div>`;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
FunctionDeclaration |
function getDistance(p1: Point, p2: Point): number {
return Math.sqrt((p1.x - p2.x)**2 + (p1.y - p2.y)**2);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
entries => {
for (const entry of entries) {
if (entry.target === target && entry.intersectionRatio === 0) {
this.toggle(false);
}
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
() => {
this.toggle(true);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
series => series.data = data | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
size => {
if (size.width !== chart.width || size.height !== chart.height) {
chart.scene.resize(size.width, size.height);
chart.fireEvent({ type: 'layoutChange' });
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
() => this.tooltip.toggle() | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
axis => this.detachAxis(axis) | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
a => !a.linkedTo | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
a => a.linkedTo | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
axis => this.attachAxis(axis) | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
series => this.addSeries(series) | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
series => {
this.freeSeries(series);
this.seriesRoot.removeChild(series.group);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
axis => {
const axisName = axis.direction + 'Axis';
const boundSeries: Series[] = [];
this.series.forEach(series => {
if ((series as any)[axisName] === axis) {
boundSeries.push(series);
}
});
axis.boundSeries = boundSeries;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
series => {
if ((series as any)[axisName] === axis) {
boundSeries.push(series);
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
axis => {
const direction = axis.direction;
const directionAxes = directionToAxesMap[direction] || (directionToAxesMap[direction] = []);
directionAxes.push(axis);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
series => {
series.directions.forEach(direction => {
const axisName = direction + 'Axis';
if (!(series as any)[axisName] || force) {
const directionAxes = directionToAxesMap[direction];
if (directionAxes) {
const axis = this.findMatchingAxis(directionAxes, series.getKeys(direction));
if (axis) {
(series as any)[axisName] = axis;
}
}
}
});
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
direction => {
const axisName = direction + 'Axis';
if (!(series as any)[axisName] || force) {
const directionAxes = directionToAxesMap[direction];
if (directionAxes) {
const axis = this.findMatchingAxis(directionAxes, series.getKeys(direction));
if (axis) {
(series as any)[axisName] = axis;
}
}
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
s => s.nodeDataPending = true | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
() => {
this.layoutCallbackId = 0;
this.background.width = this.width;
this.background.height = this.height;
this.performLayout();
if (!this.layoutPending) {
this.fireEvent({ type: 'layoutDone' });
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
() => {
this.dataPending = false;
this.processData();
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
s => s.processData() | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
s => {
const data = s.visible ? s.createNodeData() : [];
this.nodeData.set(s, data);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
(d, s) => {
if (s.visible && s.label.enabled) {
series.push(s);
data.push(s.getLabelData());
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
(l, i) => [series[i], l] | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
s => s.showInLegend | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
series => series.listSeriesItems(legendData) | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
datum => datum.label.text = formatter({
id: datum.id,
itemId: datum.itemId,
value: datum.label.text
}) | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
() => {
this.update();
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
series => {
if (series.updatePending) {
series.update();
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
datum => {
if (!datum.point) {
return;
}
const distance = getDistance(hitPoint, datum.point);
if (distance < minDistance) {
minDistance = distance;
closestDatum = datum;
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
series => series.id === id | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ArrowFunction |
s => s.updatePending = true | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
ClassDeclaration |
export class ChartTooltip extends Observable {
chart: Chart;
element: HTMLDivElement;
private observer?: IntersectionObserver;
@reactive() enabled: boolean = true;
@reactive() class: string = Chart.defaultTooltipClass;
@reactive() delay: number = 0;
/**
* If `true`, the tooltip will be shown for the marker closest to the mouse cursor.
* Only has effect on series with markers.
*/
@reactive() tracking: boolean = true;
constructor(chart: Chart, document: Document) {
super();
this.chart = chart;
this.class = '';
const tooltipRoot = document.body;
const element = document.createElement('div');
this.element = tooltipRoot.appendChild(element);
// Detect when the chart becomes invisible and hide the tooltip as well.
if (window.IntersectionObserver) {
const target = this.chart.scene.canvas.element;
const observer = new IntersectionObserver(entries => {
for (const entry of entries) {
if (entry.target === target && entry.intersectionRatio === 0) {
this.toggle(false);
}
}
}, { root: tooltipRoot });
observer.observe(target);
this.observer = observer;
}
}
destroy() {
const { parentNode } = this.element;
if (parentNode) {
parentNode.removeChild(this.element);
}
if (this.observer) {
this.observer.unobserve(this.chart.scene.canvas.element);
}
}
isVisible(): boolean {
const { element } = this;
if (element.classList) { // if not IE11
return !element.classList.contains(Chart.defaultTooltipClass + '-hidden');
}
// IE11 part.
const classes = element.getAttribute('class');
if (classes) {
return classes.split(' ').indexOf(Chart.defaultTooltipClass + '-hidden') < 0;
}
return false;
}
updateClass(visible?: boolean, constrained?: boolean) {
const classList = [Chart.defaultTooltipClass, this.class];
if (visible !== true) {
classList.push(`${Chart.defaultTooltipClass}-hidden`);
}
if (constrained !== true) {
classList.push(`${Chart.defaultTooltipClass}-arrow`);
}
this.element.setAttribute('class', classList.join(' '));
}
private showTimeout: number = 0;
private constrained = false;
/**
* Shows tooltip at the given event's coordinates.
* If the `html` parameter is missing, moves the existing tooltip to the new position.
*/
show(meta: TooltipMeta, html?: string, instantly = false) {
const el = this.element;
if (html !== undefined) {
el.innerHTML = html;
} else if (!el.innerHTML) {
return;
}
let left = meta.pageX - el.clientWidth / 2;
let top = meta.pageY - el.clientHeight - 8;
this.constrained = false;
if (this.chart.container) {
const tooltipRect = el.getBoundingClientRect();
const minLeft = 0;
const maxLeft = window.innerWidth - tooltipRect.width - 1;
if (left < minLeft) {
left = minLeft;
this.updateClass(true, this.constrained = true);
} else if (left > maxLeft) {
left = maxLeft;
this.updateClass(true, this.constrained = true);
}
if (top < window.pageYOffset) {
top = meta.pageY + 20;
this.updateClass(true, this.constrained = true);
}
}
el.style.left = `${Math.round(left)}px`;
el.style.top = `${Math.round(top)}px`;
if (this.delay > 0 && !instantly) {
this.toggle(false);
this.showTimeout = window.setTimeout(() => {
this.toggle(true);
}, this.delay);
return;
}
this.toggle(true);
}
toggle(visible?: boolean) {
if (!visible) {
window.clearTimeout(this.showTimeout);
if (this.chart.lastPick && !this.delay) {
this.chart.dehighlightDatum();
this.chart.lastPick = undefined;
}
}
this.updateClass(visible, this.constrained);
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
InterfaceDeclaration |
export interface ChartClickEvent extends SourceEvent<Chart> {
event: MouseEvent;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
InterfaceDeclaration |
export interface TooltipMeta {
pageX: number;
pageY: number;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
InterfaceDeclaration |
export interface TooltipRendererResult {
content?: string;
title?: string;
color?: string;
backgroundColor?: string;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
TypeAliasDeclaration |
type Point = { x: number, y: number}; | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
destroy() {
const { parentNode } = this.element;
if (parentNode) {
parentNode.removeChild(this.element);
}
if (this.observer) {
this.observer.unobserve(this.chart.scene.canvas.element);
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
isVisible(): boolean {
const { element } = this;
if (element.classList) { // if not IE11
return !element.classList.contains(Chart.defaultTooltipClass + '-hidden');
}
// IE11 part.
const classes = element.getAttribute('class');
if (classes) {
return classes.split(' ').indexOf(Chart.defaultTooltipClass + '-hidden') < 0;
}
return false;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
updateClass(visible?: boolean, constrained?: boolean) {
const classList = [Chart.defaultTooltipClass, this.class];
if (visible !== true) {
classList.push(`${Chart.defaultTooltipClass}-hidden`);
}
if (constrained !== true) {
classList.push(`${Chart.defaultTooltipClass}-arrow`);
}
this.element.setAttribute('class', classList.join(' '));
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration | /**
* Shows tooltip at the given event's coordinates.
* If the `html` parameter is missing, moves the existing tooltip to the new position.
*/
show(meta: TooltipMeta, html?: string, instantly = false) {
const el = this.element;
if (html !== undefined) {
el.innerHTML = html;
} else if (!el.innerHTML) {
return;
}
let left = meta.pageX - el.clientWidth / 2;
let top = meta.pageY - el.clientHeight - 8;
this.constrained = false;
if (this.chart.container) {
const tooltipRect = el.getBoundingClientRect();
const minLeft = 0;
const maxLeft = window.innerWidth - tooltipRect.width - 1;
if (left < minLeft) {
left = minLeft;
this.updateClass(true, this.constrained = true);
} else if (left > maxLeft) {
left = maxLeft;
this.updateClass(true, this.constrained = true);
}
if (top < window.pageYOffset) {
top = meta.pageY + 20;
this.updateClass(true, this.constrained = true);
}
}
el.style.left = `${Math.round(left)}px`;
el.style.top = `${Math.round(top)}px`;
if (this.delay > 0 && !instantly) {
this.toggle(false);
this.showTimeout = window.setTimeout(() => {
this.toggle(true);
}, this.delay);
return;
}
this.toggle(true);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
toggle(visible?: boolean) {
if (!visible) {
window.clearTimeout(this.showTimeout);
if (this.chart.lastPick && !this.delay) {
this.chart.dehighlightDatum();
this.chart.lastPick = undefined;
}
}
this.updateClass(visible, this.constrained);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
download(fileName?: string) {
this.scene.download(fileName);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
destroy() {
this.tooltip.destroy();
SizeMonitor.unobserve(this.element);
this.container = undefined;
this.cleanupDomListeners(this.scene.canvas.element);
this.scene.container = undefined;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private onLegendPositionChange() {
this.legendAutoPadding.clear();
this.layoutPending = true;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private onCaptionChange(event: PropertyChangeEvent<this, Caption | undefined>) {
const { value, oldValue } = event;
if (oldValue) {
oldValue.removeEventListener('change', this.scheduleLayout, this);
this.scene.root!.removeChild(oldValue.node);
}
if (value) {
value.addEventListener('change', this.scheduleLayout, this);
this.scene.root!.appendChild(value.node);
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected attachAxis(axis: ChartAxis) {
this.scene.root!.insertBefore(axis.group, this.seriesRoot);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected detachAxis(axis: ChartAxis) {
this.scene.root!.removeChild(axis.group);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected scheduleLayout() {
this.layoutPending = true;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private scheduleData() {
// To prevent the chart from thinking the cursor is over the same node
// after a change to data (the nodes are reused on data changes).
this.dehighlightDatum();
this.dataPending = true;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
addSeries(series: Series, before?: Series): boolean {
const { series: allSeries, seriesRoot } = this;
const canAdd = allSeries.indexOf(series) < 0;
if (canAdd) {
const beforeIndex = before ? allSeries.indexOf(before) : -1;
if (beforeIndex >= 0) {
allSeries.splice(beforeIndex, 0, series);
seriesRoot.insertBefore(series.group, before!.group);
} else {
allSeries.push(series);
seriesRoot.append(series.group);
}
this.initSeries(series);
this.seriesChanged = true;
this.axesChanged = true;
return true;
}
return false;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected initSeries(series: Series) {
series.chart = this;
if (!series.data) {
series.data = this.data;
}
series.addEventListener('layoutChange', this.scheduleLayout, this);
series.addEventListener('dataChange', this.scheduleData, this);
series.addEventListener('legendChange', this.updateLegend, this);
series.addEventListener('nodeClick', this.onSeriesNodeClick, this);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected freeSeries(series: Series) {
series.chart = undefined;
series.removeEventListener('layoutChange', this.scheduleLayout, this);
series.removeEventListener('dataChange', this.scheduleData, this);
series.removeEventListener('legendChange', this.updateLegend, this);
series.removeEventListener('nodeClick', this.onSeriesNodeClick, this);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
addSeriesAfter(series: Series, after?: Series): boolean {
const { series: allSeries, seriesRoot } = this;
const canAdd = allSeries.indexOf(series) < 0;
if (canAdd) {
const afterIndex = after ? this.series.indexOf(after) : -1;
if (afterIndex >= 0) {
if (afterIndex + 1 < allSeries.length) {
seriesRoot.insertBefore(series.group, allSeries[afterIndex + 1].group);
} else {
seriesRoot.append(series.group);
}
this.initSeries(series);
allSeries.splice(afterIndex + 1, 0, series);
} else {
if (allSeries.length > 0) {
seriesRoot.insertBefore(series.group, allSeries[0].group);
} else {
seriesRoot.append(series.group);
}
this.initSeries(series);
allSeries.unshift(series);
}
this.seriesChanged = true;
this.axesChanged = true;
}
return false;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
removeSeries(series: Series): boolean {
const index = this.series.indexOf(series);
if (index >= 0) {
this.series.splice(index, 1);
this.freeSeries(series);
this.seriesRoot.removeChild(series.group);
this.seriesChanged = true;
return true;
}
return false;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
removeAllSeries(): void {
this.series.forEach(series => {
this.freeSeries(series);
this.seriesRoot.removeChild(series.group);
});
this._series = []; // using `_series` instead of `series` to prevent infinite recursion
this.seriesChanged = true;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected assignSeriesToAxes() {
this.axes.forEach(axis => {
const axisName = axis.direction + 'Axis';
const boundSeries: Series[] = [];
this.series.forEach(series => {
if ((series as any)[axisName] === axis) {
boundSeries.push(series);
}
});
axis.boundSeries = boundSeries;
});
this.seriesChanged = false;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected assignAxesToSeries(force: boolean = false) {
// This method has to run before `assignSeriesToAxes`.
const directionToAxesMap: { [key in ChartAxisDirection]?: ChartAxis[] } = {};
this.axes.forEach(axis => {
const direction = axis.direction;
const directionAxes = directionToAxesMap[direction] || (directionToAxesMap[direction] = []);
directionAxes.push(axis);
});
this.series.forEach(series => {
series.directions.forEach(direction => {
const axisName = direction + 'Axis';
if (!(series as any)[axisName] || force) {
const directionAxes = directionToAxesMap[direction];
if (directionAxes) {
const axis = this.findMatchingAxis(directionAxes, series.getKeys(direction));
if (axis) {
(series as any)[axisName] = axis;
}
}
}
});
});
this.axesChanged = false;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private findMatchingAxis(directionAxes: ChartAxis[], directionKeys?: string[]): ChartAxis | undefined {
for (let i = 0; i < directionAxes.length; i++) {
const axis = directionAxes[i];
const axisKeys = axis.keys;
if (!axisKeys.length) {
return axis;
} else if (directionKeys) {
for (let j = 0; j < directionKeys.length; j++) {
if (axisKeys.indexOf(directionKeys[j]) >= 0 ) {
return axis;
}
}
}
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
processData(): void {
this.layoutPending = false;
if (this.axesChanged) {
this.assignAxesToSeries(true);
this.assignSeriesToAxes();
}
if (this.seriesChanged) {
this.assignSeriesToAxes();
}
this.series.forEach(s => s.processData());
this.updateLegend();
this.layoutPending = true;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
createNodeData(): void {
this.nodeData.clear();
this.series.forEach(s => {
const data = s.visible ? s.createNodeData() : [];
this.nodeData.set(s, data);
});
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
placeLabels(): Map<Series, PlacedLabel[]> {
const series: Series[] = [];
const data: (readonly PointLabelDatum[])[] = [];
this.nodeData.forEach((d, s) => {
if (s.visible && s.label.enabled) {
series.push(s);
data.push(s.getLabelData());
}
});
const { seriesRect } = this;
const labels: PlacedLabel[][] = seriesRect
? placeLabels(data, { x: 0, y: 0, width: seriesRect.width, height: seriesRect.height })
: [];
return new Map(labels.map((l, i) => [series[i], l]));
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private updateLegend() {
const legendData: LegendDatum[] = [];
this.series.filter(s => s.showInLegend).forEach(series => series.listSeriesItems(legendData));
const { formatter } = this.legend.item.label;
if (formatter) {
legendData.forEach(datum => datum.label.text = formatter({
id: datum.id,
itemId: datum.itemId,
value: datum.label.text
}));
}
this.legend.data = legendData;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
abstract performLayout(): void; | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
update() {
this.updatePending = false;
this.series.forEach(series => {
if (series.updatePending) {
series.update();
}
});
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected positionCaptions() {
const { title, subtitle } = this;
let titleVisible = false;
let subtitleVisible = false;
const spacing = 10;
let paddingTop = spacing;
if (title && title.enabled) {
title.node.x = this.width / 2;
title.node.y = paddingTop;
titleVisible = true;
const titleBBox = title.node.computeBBox(); // make sure to set node's x/y, then computeBBox
if (titleBBox) {
paddingTop = titleBBox.y + titleBBox.height;
}
if (subtitle && subtitle.enabled) {
subtitle.node.x = this.width / 2;
subtitle.node.y = paddingTop + spacing;
subtitleVisible = true;
const subtitleBBox = subtitle.node.computeBBox();
if (subtitleBBox) {
paddingTop = subtitleBBox.y + subtitleBBox.height;
}
}
}
if (title) {
title.node.visible = titleVisible;
}
if (subtitle) {
subtitle.node.visible = subtitleVisible;
}
this.captionAutoPadding = Math.floor(paddingTop);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected positionLegend() {
if (!this.legend.enabled || !this.legend.data.length) {
return;
}
const { legend, captionAutoPadding, legendAutoPadding } = this;
const width = this.width;
const height = this.height - captionAutoPadding;
const legendGroup = legend.group;
const legendSpacing = legend.spacing;
let translationX = 0;
let translationY = 0;
let legendBBox: BBox;
switch (legend.position) {
case 'bottom':
legend.performLayout(width - legendSpacing * 2, 0);
legendBBox = legendGroup.computeBBox();
translationX = (width - legendBBox.width) / 2 - legendBBox.x;
translationY = captionAutoPadding + height - legendBBox.height - legendBBox.y - legendSpacing;
legendAutoPadding.bottom = legendBBox.height;
break;
case 'top':
legend.performLayout(width - legendSpacing * 2, 0);
legendBBox = legendGroup.computeBBox();
translationX = (width - legendBBox.width) / 2 - legendBBox.x;
translationY = captionAutoPadding + legendSpacing - legendBBox.y;
legendAutoPadding.top = legendBBox.height;
break;
case 'left':
legend.performLayout(0, height - legendSpacing * 2);
legendBBox = legendGroup.computeBBox();
translationX = legendSpacing - legendBBox.x;
translationY = captionAutoPadding + (height - legendBBox.height) / 2 - legendBBox.y;
legendAutoPadding.left = legendBBox.width;
break;
default: // case 'right':
legend.performLayout(0, height - legendSpacing * 2);
legendBBox = legendGroup.computeBBox();
translationX = width - legendBBox.width - legendBBox.x - legendSpacing;
translationY = captionAutoPadding + (height - legendBBox.height) / 2 - legendBBox.y;
legendAutoPadding.right = legendBBox.width;
break;
}
// Round off for pixel grid alignment to work properly.
legendGroup.translationX = Math.floor(translationX + legendGroup.translationX);
legendGroup.translationY = Math.floor(translationY + legendGroup.translationY);
this.legendBBox = legendGroup.computeBBox();
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected setupDomListeners(chartElement: HTMLCanvasElement) {
chartElement.addEventListener('mousedown', this._onMouseDown);
chartElement.addEventListener('mousemove', this._onMouseMove);
chartElement.addEventListener('mouseup', this._onMouseUp);
chartElement.addEventListener('mouseout', this._onMouseOut);
chartElement.addEventListener('click', this._onClick);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected cleanupDomListeners(chartElement: HTMLCanvasElement) {
chartElement.removeEventListener('mousedown', this._onMouseDown);
chartElement.removeEventListener('mousemove', this._onMouseMove);
chartElement.removeEventListener('mouseup', this._onMouseUp);
chartElement.removeEventListener('mouseout', this._onMouseOut);
chartElement.removeEventListener('click', this._onClick);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
getSeriesRect(): Readonly<BBox | undefined> {
return this.seriesRect;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration | // x/y are local canvas coordinates in CSS pixels, not actual pixels
private pickSeriesNode(x: number, y: number): {
series: Series,
node: Node
} | undefined {
if (!(this.seriesRect && this.seriesRect.containsPoint(x, y))) {
return undefined;
}
const allSeries = this.series;
let node: Node | undefined = undefined;
for (let i = allSeries.length - 1; i >= 0; i--) {
const series = allSeries[i];
if (!series.visible) {
continue;
}
node = series.pickGroup.pickNode(x, y);
if (node) {
return {
series,
node
};
}
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration | // Provided x/y are in canvas coordinates.
private pickClosestSeriesNodeDatum(x: number, y: number): SeriesNodeDatum | undefined {
if (!this.seriesRect || !this.seriesRect.containsPoint(x, y)) {
return undefined;
}
const allSeries = this.series;
type Point = { x: number, y: number};
function getDistance(p1: Point, p2: Point): number {
return Math.sqrt((p1.x - p2.x)**2 + (p1.y - p2.y)**2);
}
let minDistance = Infinity;
let closestDatum: SeriesNodeDatum | undefined;
for (let i = allSeries.length - 1; i >= 0; i--) {
const series = allSeries[i];
if (!series.visible) {
continue;
}
const hitPoint = series.group.transformPoint(x, y);
series.getNodeData().forEach(datum => {
if (!datum.point) {
return;
}
const distance = getDistance(hitPoint, datum.point);
if (distance < minDistance) {
minDistance = distance;
closestDatum = datum;
}
});
}
return closestDatum;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected onMouseMove(event: MouseEvent): void {
this.handleLegendMouseMove(event);
if (this.tooltip.enabled) {
if (this.tooltip.delay > 0) {
this.tooltip.toggle(false);
}
this.handleTooltip(event);
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected handleTooltip(event: MouseEvent) {
const { lastPick, tooltip: { tracking: tooltipTracking } } = this;
const { offsetX, offsetY } = event;
const pick = this.pickSeriesNode(offsetX, offsetY);
let nodeDatum: SeriesNodeDatum | undefined;
if (pick && pick.node instanceof Shape) {
const { node } = pick;
nodeDatum = node.datum as SeriesNodeDatum;
if (lastPick && lastPick.datum === nodeDatum) {
lastPick.node = node;
lastPick.event = event;
}
// Marker nodes will have the `point` info in their datums.
// Highlight if not a marker node or, if not in the tracking mode, highlight markers too.
if ((!node.datum.point || !tooltipTracking)) {
if (!lastPick // cursor moved from empty space to a node
|| lastPick.node !== node) { // cursor moved from one node to another
this.onSeriesDatumPick(event, node.datum, node, event);
} else if (pick.series.tooltip.enabled) { // cursor moved within the same node
this.tooltip.show(event);
}
// A non-marker node (takes precedence over marker nodes) was highlighted.
// Or we are not in the tracking mode.
// Either way, we are done at this point.
return;
}
}
let hideTooltip = false;
// In tracking mode a tooltip is shown for the closest rendered datum.
// This makes it easier to show tooltips when markers are small and/or plentiful
// and also gives the ability to show tooltips even when the series were configured
// to not render markers.
if (tooltipTracking) {
const closestDatum = this.pickClosestSeriesNodeDatum(offsetX, offsetY);
if (closestDatum && closestDatum.point) {
const { x, y } = closestDatum.point;
const { canvas } = this.scene;
const point = closestDatum.series.group.inverseTransformPoint(x, y);
const canvasRect = canvas.element.getBoundingClientRect();
this.onSeriesDatumPick({
pageX: Math.round(canvasRect.left + window.pageXOffset + point.x),
pageY: Math.round(canvasRect.top + window.pageYOffset + point.y)
}, closestDatum, nodeDatum === closestDatum && pick ? pick.node as Shape : undefined, event);
} else {
hideTooltip = true;
}
}
if (lastPick && (hideTooltip || !tooltipTracking)) {
// Cursor moved from a non-marker node to empty space.
this.dehighlightDatum();
this.tooltip.toggle(false);
this.lastPick = undefined;
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected onMouseDown(event: MouseEvent) {} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected onMouseUp(event: MouseEvent) {} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected onMouseOut(event: MouseEvent) {
this.tooltip.toggle(false);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
protected onClick(event: MouseEvent) {
if (this.checkSeriesNodeClick()) {
return;
}
if (this.checkLegendClick(event)) {
return;
}
this.fireEvent<ChartClickEvent>({
type: 'click',
event
});
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private checkSeriesNodeClick(): boolean {
const { lastPick } = this;
if (lastPick && lastPick.event && lastPick.node) {
const { event, datum } = lastPick;
datum.series.fireNodeClickEvent(event, datum);
return true;
}
return false;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private onSeriesNodeClick(event: SourceEvent<Series>) {
this.fireEvent({ ...event, type: 'seriesNodeClick' });
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private checkLegendClick(event: MouseEvent): boolean {
const datum = this.legend.getDatumForPoint(event.offsetX, event.offsetY);
if (datum) {
const { id, itemId, enabled } = datum;
const series = find(this.series, series => series.id === id);
if (series) {
series.toggleSeriesItem(itemId, !enabled);
if (enabled) {
this.tooltip.toggle(false);
}
this.legend.fireEvent<LegendClickEvent>({
type: 'click',
event,
itemId,
enabled: !enabled
});
return true;
}
}
return false;
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private handleLegendMouseMove(event: MouseEvent) {
if (!this.legend.enabled) {
return;
}
const { offsetX, offsetY } = event;
const datum = this.legend.getDatumForPoint(offsetX, offsetY);
const pointerInsideLegend = this.legendBBox.containsPoint(offsetX, offsetY);
if (pointerInsideLegend) {
if (!this.pointerInsideLegend) {
this.pointerInsideLegend = true;
}
} else if (this.pointerInsideLegend) {
this.pointerInsideLegend = false;
// Dehighlight if the pointer was inside the legend and is now leaving it.
if (this.highlightedDatum) {
this.highlightedDatum = undefined;
this.series.forEach(s => s.updatePending = true);
}
return;
}
const oldHighlightedDatum = this.highlightedDatum;
if (datum) {
const { id, itemId, enabled } = datum;
if (enabled) {
const series = find(this.series, series => series.id === id);
if (series) {
this.highlightedDatum = {
series,
itemId,
datum: undefined
};
}
}
}
// Careful to only schedule updates when necessary.
if ((this.highlightedDatum && !oldHighlightedDatum) ||
(this.highlightedDatum && oldHighlightedDatum &&
(this.highlightedDatum.series !== oldHighlightedDatum.series ||
this.highlightedDatum.itemId !== oldHighlightedDatum.itemId))) {
this.series.forEach(s => s.updatePending = true);
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
private onSeriesDatumPick(meta: TooltipMeta, datum: SeriesNodeDatum, node?: Shape, event?: MouseEvent) {
const { lastPick } = this;
if (lastPick) {
if (lastPick.datum === datum) { return; }
this.dehighlightDatum();
}
this.lastPick = {
datum,
node,
event
};
this.highlightDatum(datum);
const html = datum.series.tooltip.enabled && datum.series.getTooltipHtml(datum);
if (html) {
this.tooltip.show(meta, html);
}
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
highlightDatum(datum: SeriesNodeDatum): void {
this.scene.canvas.element.style.cursor = datum.series.cursor;
this.highlightedDatum = datum;
this.series.forEach(s => s.updatePending = true);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
MethodDeclaration |
dehighlightDatum(): void {
this.scene.canvas.element.style.cursor = 'default';
this.highlightedDatum = undefined;
this.series.forEach(s => s.updatePending = true);
} | HugoUno/ag-grid | charts-packages/ag-charts-community/src/chart/chart.ts | TypeScript |
FunctionDeclaration |
function testLogLevels(logger: ILogger, minLevel: LogLevel) {
const capturingConsole = new CapturingConsole();
(logger as ConsoleLogger).out = capturingConsole;
for (let level = LogLevel.Trace; level < LogLevel.None; level++) {
const message = `Message at LogLevel.${LogLevel[level]}`;
const expectedMessage = `${LogLevel[level]}: Message at LogLevel.${LogLevel[level]}`;
logger.log(level, message);
if (level >= minLevel) {
expect(capturingConsole.messages).toContain(expectedMessage);
} else {
expect(capturingConsole.messages).not.toContain(expectedMessage);
}
}
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
FunctionDeclaration |
function createConnectionBuilder(logger?: ILogger): HubConnectionBuilder {
// We don't want to spam test output with logs. This can be changed as needed
return new HubConnectionBuilder()
.configureLogging(logger || NullLogger.instance);
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
FunctionDeclaration |
function createTestClient(pollSent: PromiseSource<HttpRequest>, pollCompleted: Promise<HttpResponse>, negotiateResponse?: any): TestHttpClient {
let firstRequest = true;
return new TestHttpClient()
.on("POST", "http://example.com/negotiate?negotiateVersion=1", () => negotiateResponse || longPollingNegotiateResponse)
.on("GET", /http:\/\/example.com\?id=123abc&_=.*/, (req) => {
if (firstRequest) {
firstRequest = false;
return new HttpResponse(200);
} else {
pollSent.resolve(req);
return pollCompleted;
}
});
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
FunctionDeclaration |
function eachMissingValue(callback: (val: undefined | null, name: string) => void) {
callback(null, "null");
callback(undefined, "undefined");
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
() => {
const builder = new HubConnectionBuilder();
expect(() => builder.withUrl(val!)).toThrow(/The 'url' argument (is required|should not be empty)./);
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
() => builder.withUrl(val!) | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
(val, name) => {
it(`withHubProtocol throws if protocol is ${name}`, () => {
const builder = new HubConnectionBuilder();
expect(() => builder.withHubProtocol(val!)).toThrow("The 'protocol' argument is required.");
});
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
() => {
const builder = new HubConnectionBuilder();
expect(() => builder.withHubProtocol(val!)).toThrow("The 'protocol' argument is required.");
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
() => builder.withHubProtocol(val!) | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
async () => {
await VerifyLogger.run(async (logger) => {
const pollSent = new PromiseSource<HttpRequest>();
const pollCompleted = new PromiseSource<HttpResponse>();
const testClient = createTestClient(pollSent, pollCompleted.promise)
.on("POST", "http://example.com?id=123abc", (req) => {
// Respond from the poll with the handshake response
pollCompleted.resolve(new HttpResponse(204, "No Content", "{}"));
return new HttpResponse(202);
});
const connection = createConnectionBuilder()
.withUrl("http://example.com", {
...commonHttpOptions,
httpClient: testClient,
logger,
})
.build();
await expect(connection.start()).rejects.toThrow("The underlying connection was closed before the hub handshake could complete.");
expect(connection.state).toBe(HubConnectionState.Disconnected);
expect((await pollSent.promise).url).toMatch(/http:\/\/example.com\?id=123abc.*/);
});
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
async (logger) => {
const pollSent = new PromiseSource<HttpRequest>();
const pollCompleted = new PromiseSource<HttpResponse>();
const testClient = createTestClient(pollSent, pollCompleted.promise)
.on("POST", "http://example.com?id=123abc", (req) => {
// Respond from the poll with the handshake response
pollCompleted.resolve(new HttpResponse(204, "No Content", "{}"));
return new HttpResponse(202);
});
const connection = createConnectionBuilder()
.withUrl("http://example.com", {
...commonHttpOptions,
httpClient: testClient,
logger,
})
.build();
await expect(connection.start()).rejects.toThrow("The underlying connection was closed before the hub handshake could complete.");
expect(connection.state).toBe(HubConnectionState.Disconnected);
expect((await pollSent.promise).url).toMatch(/http:\/\/example.com\?id=123abc.*/);
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
(req) => {
// Respond from the poll with the handshake response
pollCompleted.resolve(new HttpResponse(204, "No Content", "{}"));
return new HttpResponse(202);
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
async () => {
const protocol = new TestProtocol();
const builder = createConnectionBuilder()
.withUrl("http://example.com", HttpTransportType.WebSockets)
.withHubProtocol(protocol);
expect(builder.httpConnectionOptions!.transport).toBe(HttpTransportType.WebSockets);
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |
ArrowFunction |
async () => {
await VerifyLogger.run(async (logger) => {
const protocol = new TestProtocol();
const pollSent = new PromiseSource<HttpRequest>();
const pollCompleted = new PromiseSource<HttpResponse>();
let negotiateRequest!: HttpRequest;
const testClient = createTestClient(pollSent, pollCompleted.promise)
.on("POST", "http://example.com?id=123abc", (req) => {
// Respond from the poll with the handshake response
negotiateRequest = req;
pollCompleted.resolve(new HttpResponse(204, "No Content", "{}"));
return new HttpResponse(202);
});
const connection = createConnectionBuilder()
.withUrl("http://example.com", {
...commonHttpOptions,
httpClient: testClient,
logger,
})
.withHubProtocol(protocol)
.build();
await expect(connection.start()).rejects.toThrow("The underlying connection was closed before the hub handshake could complete.");
expect(connection.state).toBe(HubConnectionState.Disconnected);
expect(negotiateRequest.content).toBe(`{"protocol":"${protocol.name}","version":1}\x1E`);
});
} | 1175169074/aspnetcore | src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts | TypeScript |