Skip to content

Commit

Permalink
feat: fix code changes for chart.js 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Apr 5, 2021
1 parent 7442aab commit 8110414
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/controllers/LogarithmicParallelCoordinatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export class LogarithmicParallelCoordinatesController extends ParallelCoordinate
static readonly id = 'logarithmicPcp';

static readonly defaults: any = /* #__PURE__ */ {
...ParallelCoordinatesController.defaults,
datasetElementType: LogarithmicAxis.id,
};

static readonly overrides: any = /* #__PURE__ */ ParallelCoordinatesController.overrides;
}

export interface ILogarithmicParallelCoordinatesControllerDatasetOptions
Expand Down
26 changes: 14 additions & 12 deletions src/controllers/ParallelCoordinatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export class ParallelCoordinatesController extends DatasetController<'pcp', Line
ds.yAxisID = ds.label;
super.linkScales();
this._cachedMeta.vScale = this._cachedMeta.dataset as any;
this._cachedMeta.vScale = this._cachedMeta.dataset as any;
}

private resolveAxisOptions(mode: UpdateMode) {
return (this.resolveDatasetElementOptions(mode) as unknown) as ILinearAxisOptions;
}

addElements(): void {
Expand All @@ -52,12 +57,11 @@ export class ParallelCoordinatesController extends DatasetController<'pcp', Line

Object.assign(scale, {
id: meta.yAxisID,
type: this.dataElementType.id,
axis: 'y',
type: this.datasetElementType.id,
chart: this.chart,
ctx: this.chart.ctx,
});
scale.init({} as any);
scale.init(this.resolveAxisOptions('reset'));
}

update(mode: UpdateMode): void {
Expand Down Expand Up @@ -132,8 +136,8 @@ export class ParallelCoordinatesController extends DatasetController<'pcp', Line
const x = meta.xScale?.getPixelForTick(metaIndex) ?? 0;
const yScale = m.vScale;
const y = reset
? m.yScale?.getBasePixel()
: m.yScale?.getPixelForValue((m._parsed[index] as Record<string, number>)[yScale?.axis ?? 'y'], index);
? yScale?.getBasePixel()
: yScale?.getPixelForValue((m._parsed[index] as Record<string, number>)[yScale?.axis ?? 'y'], index);

return {
x,
Expand Down Expand Up @@ -214,12 +218,10 @@ export class ParallelCoordinatesController extends DatasetController<'pcp', Line
static readonly defaults: any = /* #__PURE__ */ {
datasetElementType: LinearAxis.id,
dataElementType: LineSegment.id,
datasets: {
animation: {
numbers: {
type: 'number',
properties: ['x', 'y', 'x1', 'y1', 'axisWidth', 'xCPn', 'yCPn', 'xCPp1', 'yCPp1', 'borderWidth'],
},
animations: {
numbers: {
type: 'number',
properties: ['x', 'y', 'x1', 'y1', 'axisWidth', 'xCPn', 'yCPn', 'xCPp1', 'yCPp1', 'borderWidth'],
},
},
};
Expand All @@ -229,7 +231,7 @@ export class ParallelCoordinatesController extends DatasetController<'pcp', Line
x: {
type: PCPScale.id,
offset: true,
gridLines: {
grid: {
drawBorder: false,
display: false,
},
Expand Down
13 changes: 13 additions & 0 deletions src/elements/LinearAxis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface IAxisProps {
}

const scaleDefaults = {
axis: 'y',
// a dummy scriptable option to enforce a context environment
dummyOption: (_ctx: unknown) => 0,
axisWidth: 10,
Expand Down Expand Up @@ -81,6 +82,11 @@ export class LinearAxis extends LinearScale<ILinearAxisOptions> {
return r;
}

// eslint-disable-next-line class-methods-use-this
_computeLabelArea(): void {
return undefined;
}

draw(c: unknown): void {
const ctx = c as CanvasRenderingContext2D;
ctx.save();
Expand Down Expand Up @@ -112,10 +118,17 @@ export class LogarithmicAxis extends LogarithmicScale<ILogarithmicAxisOptions> {

static readonly defaults: any = /* #__PURE__ */ merge({}, [defaults.scale, LogarithmicScale.defaults, scaleDefaults]);

static readonly descriptors = /* #__PURE__ */ LinearAxis.descriptors;

constructor() {
super({});
}

// eslint-disable-next-line class-methods-use-this
_computeLabelArea(): void {
return undefined;
}

update(): number {
return LinearAxis.prototype.update.call(this);
}
Expand Down

0 comments on commit 8110414

Please sign in to comment.