Skip to content

Commit

Permalink
deprecate rfdc
Browse files Browse the repository at this point in the history
  • Loading branch information
steveblue committed Nov 14, 2024
1 parent ab61b50 commit fa81ea7
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
documentation.json
.vscode/
.angular/
dist/
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@
"zone.js": "~0.14.7"
},
"devDependencies": {
"@angular-devkit/architect": "^0.1802.11",
"@angular-devkit/architect": "^0.900.0",
"@angular-devkit/build-angular": "~18.2.0",
"@angular-devkit/build-ng-packagr": "0.1002.0",
"@angular-devkit/core": "~18.2.0",
"@angular-devkit/schematics": "~18.2.0",
"@angular-eslint/builder": "~18.2.0",
"@angular-eslint/eslint-plugin": "^18.4.0",
"@angular-eslint/eslint-plugin-template": "^18.4.0",
Expand Down Expand Up @@ -106,7 +104,7 @@
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"ng-packagr": "~18.2.0",
"ng-packagr": "^18.2.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"protractor": "~7.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import { boxData } from '../../../../../../src/app/data';
import { BoxChartModule } from './box-chart.module';
import { cloneLineCoordinates } from './box.component';
import { IVector2D } from '@swimlane/ngx-charts/models/coordinates.model';

@Component({
selector: 'test-component',
Expand Down Expand Up @@ -50,5 +52,87 @@ describe('<ngx-charts-box-chart>', () => {
expect(svg.getAttribute('width')).toBe('400');
expect(svg.getAttribute('height')).toBe('800');
});

it('test simple clone for LineCoordinates', () => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
type LineCoordinates = [IVector2D, IVector2D, IVector2D, IVector2D];
const line1Coordinates: LineCoordinates = [
{
v1: { x: 109.5, y: 245 },
v2: { x: 109.5, y: 107.96610169491527 }
},
{
v1: { x: 121.66666666666667, y: 245 },
v2: { x: 97.33333333333333, y: 245 }
},
{
v1: { x: 150, y: 191.01694915254237 },
v2: { x: 69, y: 191.01694915254237 }
},
{
v1: { x: 121.66666666666667, y: 107.96610169491527 },
v2: { x: 97.33333333333333, y: 107.96610169491527 }
}
];
const line2Coordinates: LineCoordinates = [
{
v1: { x: 254.5, y: 211.77966101694915 },
v2: { x: 254.5, y: 41.52542372881356 }
},
{
v1: { x: 266.6666666666667, y: 211.77966101694915 },
v2: { x: 242.33333333333334, y: 211.77966101694915 }
},
{
v1: { x: 295, y: 149.4915254237288 },
v2: { x: 214, y: 149.4915254237288 }
},
{
v1: { x: 266.6666666666667, y: 41.52542372881356 },
v2: { x: 242.33333333333334, y: 41.52542372881356 }
}
];

const cloneLine1Coordinates = cloneLineCoordinates(line1Coordinates);
const cloneLine2Coordinates = cloneLineCoordinates(line2Coordinates);

expect(cloneLine1Coordinates).toEqual([
{
v1: { x: 109.5, y: 245 },
v2: { x: 109.5, y: 107.96610169491527 }
},
{
v1: { x: 121.66666666666667, y: 245 },
v2: { x: 97.33333333333333, y: 245 }
},
{
v1: { x: 150, y: 191.01694915254237 },
v2: { x: 69, y: 191.01694915254237 }
},
{
v1: { x: 121.66666666666667, y: 107.96610169491527 },
v2: { x: 97.33333333333333, y: 107.96610169491527 }
}
]);
expect(cloneLine2Coordinates).toEqual([
{
v1: { x: 254.5, y: 211.77966101694915 },
v2: { x: 254.5, y: 41.52542372881356 }
},
{
v1: { x: 266.6666666666667, y: 211.77966101694915 },
v2: { x: 242.33333333333334, y: 211.77966101694915 }
},
{
v1: { x: 295, y: 149.4915254237288 },
v2: { x: 214, y: 149.4915254237288 }
},
{
v1: { x: 266.6666666666667, y: 41.52542372881356 },
v2: { x: 242.33333333333334, y: 41.52542372881356 }
}
]);
});
});
});
39 changes: 34 additions & 5 deletions projects/swimlane/ngx-charts/src/lib/box-chart/box.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,47 @@ import { select, BaseType } from 'd3-selection';
import { interpolate } from 'd3-interpolate';
import { easeSinInOut } from 'd3-ease';

import rfdc from 'rfdc';
import { roundedRect } from '../common/shape.helper';
import { id } from '../utils/id';
import { IBoxModel } from '../models/chart-data.model';
import { IVector2D } from '../models/coordinates.model';
import { IPoint, IVector2D } from '../models/coordinates.model';
import { BarOrientation } from '../common/types/bar-orientation.enum';
import { Gradient } from '../common/types/gradient.interface';

const cloneDeep = rfdc();

type LineCoordinates = [IVector2D, IVector2D, IVector2D, IVector2D];

export function clonePoint(original: IPoint): IPoint {
if (!original) {
return original;
}
return {
x: original.x,
y: original.y
};
}

export function cloneVector2d(original: IVector2D): IVector2D {
if (!original) {
return original;
}
return {
v1: clonePoint(original.v1),
v2: clonePoint(original.v2)
};
}

export function cloneLineCoordinates(original: LineCoordinates): LineCoordinates {
if (!original) {
return original;
}
return [
cloneVector2d(original[0]),
cloneVector2d(original[1]),
cloneVector2d(original[2]),
cloneVector2d(original[3])
];
}

@Component({
selector: 'g[ngx-charts-box]',
template: `
Expand Down Expand Up @@ -280,7 +309,7 @@ export class BoxComponent implements OnChanges {
return [...this.lineCoordinates];
}

const lineCoordinates: LineCoordinates = cloneDeep(this.lineCoordinates);
const lineCoordinates: LineCoordinates = cloneLineCoordinates(this.lineCoordinates);

lineCoordinates[1].v1.y =
lineCoordinates[1].v2.y =
Expand Down

0 comments on commit fa81ea7

Please sign in to comment.