Skip to content

Commit 3d9a21c

Browse files
committed
Merge branch 'dev'
2 parents 009397f + d2a3e38 commit 3d9a21c

File tree

10 files changed

+362
-422
lines changed

10 files changed

+362
-422
lines changed

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "chartjs-chart-geo",
33
"description": "Chart.js module for charting maps",
4-
"version": "3.0.1",
4+
"version": "3.0.2",
55
"author": {
66
"name": "Samuel Gratzl",
77
"email": "sam@sgratzl.com",
@@ -36,7 +36,7 @@
3636
"src/**/*.ts"
3737
],
3838
"peerDependencies": {
39-
"chart.js": "^3.1.0"
39+
"chart.js": "^3.2.1"
4040
},
4141
"dependencies": {
4242
"@types/d3-geo": "^2.0.0",
@@ -47,43 +47,43 @@
4747
"topojson-client": "^3.1.0"
4848
},
4949
"devDependencies": {
50-
"@rollup/plugin-commonjs": "^18.0.0",
51-
"@rollup/plugin-node-resolve": "^11.2.1",
50+
"@rollup/plugin-commonjs": "^19.0.0",
51+
"@rollup/plugin-node-resolve": "^13.0.0",
5252
"@rollup/plugin-replace": "^2.4.2",
5353
"@rollup/plugin-typescript": "^8.2.1",
54-
"@types/jest": "^26.0.22",
54+
"@types/jest": "^26.0.23",
5555
"@types/jest-image-snapshot": "^4.3.0",
56-
"@types/node": "^14.14.41",
56+
"@types/node": "^15.0.2",
5757
"@types/seedrandom": "^3.0.0",
58-
"@typescript-eslint/eslint-plugin": "^4.22.0",
59-
"@typescript-eslint/parser": "^4.22.0",
58+
"@typescript-eslint/eslint-plugin": "^4.22.1",
59+
"@typescript-eslint/parser": "^4.22.1",
6060
"@yarnpkg/pnpify": "^2.4.0",
6161
"canvas": "^2.7.0",
6262
"canvas-5-polyfill": "^0.1.5",
6363
"chart.js": "3.0.0-rc.3",
64-
"eslint": "^7.24.0",
64+
"eslint": "^7.26.0",
6565
"eslint-config-airbnb-typescript": "^12.3.1",
66-
"eslint-config-prettier": "^8.2.0",
66+
"eslint-config-prettier": "^8.3.0",
6767
"eslint-config-react-app": "^6.0.0",
68-
"eslint-plugin-flowtype": "^5.7.1",
68+
"eslint-plugin-flowtype": "^5.7.2",
6969
"eslint-plugin-import": "^2.22.1",
7070
"eslint-plugin-jsx-a11y": "^6.4.1",
7171
"eslint-plugin-prettier": "^3.4.0",
7272
"eslint-plugin-react": "^7.23.2",
7373
"eslint-plugin-react-hooks": "^4.2.0",
7474
"jest": "^26.6.3",
75-
"jest-image-snapshot": "^4.4.1",
76-
"prettier": "^2.2.1",
77-
"release-it": "^14.6.1",
75+
"jest-image-snapshot": "^4.5.0",
76+
"prettier": "^2.3.0",
77+
"release-it": "^14.6.2",
7878
"rimraf": "^3.0.2",
79-
"rollup": "^2.45.2",
79+
"rollup": "^2.47.0",
8080
"rollup-plugin-cleanup": "^3.2.1",
8181
"rollup-plugin-dts": "^3.0.1",
8282
"rollup-plugin-terser": "^7.0.2",
8383
"seedrandom": "^3.0.5",
84-
"ts-jest": "^26.5.5",
84+
"ts-jest": "^26.5.6",
8585
"tslib": "^2.2.0",
86-
"typedoc": "^0.20.35",
86+
"typedoc": "^0.20.36",
8787
"typescript": "^4.2.4",
8888
"us-atlas": "^3.0.0",
8989
"world-atlas": "^2.0.2"

samples/albers.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
outline: nation,
2727
data: states.map((d) => ({
2828
feature: d,
29-
value: Math.random() * 10,
29+
value: Math.random() * 11,
3030
})),
3131
},
3232
],

src/controllers/BubbleMapController.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class BubbleMapController extends GeoController<'bubbleMap', PointElement
5151
parse(start: number, count: number): void {
5252
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
5353
const rScale = this.getMeta().rScale!;
54-
const data = (this.getDataset().data as unknown) as IBubbleMapDataPoint[];
54+
const data = this.getDataset().data as unknown as IBubbleMapDataPoint[];
5555
const meta = this._cachedMeta;
5656
for (let i = start; i < start + count; i += 1) {
5757
const d = data[i];
@@ -71,7 +71,7 @@ export class BubbleMapController extends GeoController<'bubbleMap', PointElement
7171
const includeOptions = this.includeOptions(mode, sharedOptions);
7272
const scale = this.getProjectionScale();
7373

74-
((this.getMeta().rScale as unknown) as SizeScale)._model = (firstOpts as unknown) as PointOptions; // for legend rendering styling
74+
(this.getMeta().rScale as unknown as SizeScale)._model = firstOpts as unknown as PointOptions; // for legend rendering styling
7575

7676
this.updateSharedOptions(sharedOptions, mode, firstOpts);
7777

@@ -85,12 +85,12 @@ export class BubbleMapController extends GeoController<'bubbleMap', PointElement
8585
skip: Number.isNaN(parsed.x) || Number.isNaN(parsed.y),
8686
};
8787
if (includeOptions) {
88-
properties.options = ((sharedOptions || this.resolveDataElementOptions(i, mode)) as unknown) as PointOptions;
88+
properties.options = (sharedOptions || this.resolveDataElementOptions(i, mode)) as unknown as PointOptions;
8989
if (reset) {
9090
properties.options.radius = 0;
9191
}
9292
}
93-
this.updateElement(elem, i, (properties as unknown) as Record<string, unknown>, mode);
93+
this.updateElement(elem, i, properties as unknown as Record<string, unknown>, mode);
9494
}
9595
}
9696

src/controllers/ChoroplethController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ export class ChoroplethController extends GeoController<'choropleth', GeoFeature
7777
y: center.y,
7878
};
7979
if (includeOptions) {
80-
properties.options = ((sharedOptions || this.resolveDataElementOptions(i, mode)) as unknown) as PointOptions;
80+
properties.options = (sharedOptions || this.resolveDataElementOptions(i, mode)) as unknown as PointOptions;
8181
}
82-
this.updateElement(elem, i, (properties as unknown) as Record<string, unknown>, mode);
82+
this.updateElement(elem, i, properties as unknown as Record<string, unknown>, mode);
8383
}
8484
}
8585

8686
indexToColor(index: number): string {
87-
const rScale = (this.getMeta().rScale as unknown) as ColorScale;
87+
const rScale = this.getMeta().rScale as unknown as ColorScale;
8888
return rScale.getColorForValue(this.getParsed(index)[rScale.axis as 'r']);
8989
}
9090

src/controllers/GeoController.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export class GeoController<
5454
TElement extends Element & VisualElement
5555
> extends DatasetController<TYPE, TElement, GeoFeature> {
5656
getGeoDataset(): ChartDataset<'choropleth' | 'bubbleMap'> & IGeoControllerDatasetOptions {
57-
return (super.getDataset() as unknown) as ChartDataset<'choropleth' | 'bubbleMap'> & IGeoControllerDatasetOptions;
57+
return super.getDataset() as unknown as ChartDataset<'choropleth' | 'bubbleMap'> & IGeoControllerDatasetOptions;
5858
}
5959

6060
getGeoOptions(): IGeoChartOptions {
61-
return (this.chart.options as unknown) as IGeoChartOptions;
61+
return this.chart.options as unknown as IGeoChartOptions;
6262
}
6363

6464
getProjectionScale(): ProjectionScale {
@@ -159,10 +159,10 @@ export class GeoController<
159159
} else {
160160
const geo = geoGraticule();
161161
if (g.stepMajor) {
162-
geo.stepMajor((g.stepMajor as unknown) as [number, number]);
162+
geo.stepMajor(g.stepMajor as unknown as [number, number]);
163163
}
164164
if (g.stepMinor) {
165-
geo.stepMinor((g.stepMinor as unknown) as [number, number]);
165+
geo.stepMinor(g.stepMinor as unknown as [number, number]);
166166
}
167167
path(geo());
168168
}

src/elements/GeoFeature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class GeoFeature extends Element<IGeoFeatureProps, IGeoFeatureOptions> im
6565
(Number.isNaN(mouseX) || (mouseX >= bb.x && mouseX <= bb.x2)) &&
6666
(Number.isNaN(mouseY) || (mouseY >= bb.y && mouseY <= bb.y2));
6767

68-
const projection = (this.projectionScale.geoPath.projection() as unknown) as GeoProjection;
68+
const projection = this.projectionScale.geoPath.projection() as unknown as GeoProjection;
6969
if (r && !Number.isNaN(mouseX) && !Number.isNaN(mouseY) && typeof projection.invert === 'function') {
7070
// test for real if within the bounds
7171
const longlat = projection.invert([mouseX, mouseY]);

src/scales/ColorScale.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,11 @@ export class ColorScale extends LegendScale<IColorScaleOptions & LinearScaleOpti
206206
}
207207

208208
_drawIndicator(): void {
209-
const w = this.width;
210-
const h = this.height;
211-
const indicatorSize = this.options.legend.indicatorWidth;
209+
const { indicatorWidth: indicatorSize } = this.options.legend;
212210
const reverse = (this as any)._reversePixels;
213211

214212
if (this.isHorizontal()) {
213+
const w = this.width;
215214
if (this.options.quantize > 0) {
216215
const stepWidth = w / this.options.quantize;
217216
const offset = !reverse ? (i: number) => i : (i: number) => w - stepWidth - i;
@@ -227,19 +226,22 @@ export class ColorScale extends LegendScale<IColorScaleOptions & LinearScaleOpti
227226
this.ctx.fillRect(offset(i), 0, 1, indicatorSize);
228227
}
229228
}
230-
} else if (this.options.quantize > 0) {
231-
const stepWidth = h / this.options.quantize;
232-
const offset = !reverse ? (i: number) => i : (i: number) => h - stepWidth - i;
233-
for (let i = 0; i < h; i += stepWidth) {
234-
const v = (i + stepWidth / 2) / h;
235-
this.ctx.fillStyle = this.getColor(v);
236-
this.ctx.fillRect(0, offset(i), indicatorSize, stepWidth);
237-
}
238229
} else {
239-
const offset = !reverse ? (i: number) => i : (i: number) => h - 1 - i;
240-
for (let i = 0; i < h; i += 1) {
241-
this.ctx.fillStyle = this.getColor((i + 0.5) / h);
242-
this.ctx.fillRect(0, offset(i), indicatorSize, 1);
230+
const h = this.height;
231+
if (this.options.quantize > 0) {
232+
const stepWidth = h / this.options.quantize;
233+
const offset = !reverse ? (i: number) => i : (i: number) => h - stepWidth - i;
234+
for (let i = 0; i < h; i += stepWidth) {
235+
const v = (i + stepWidth / 2) / h;
236+
this.ctx.fillStyle = this.getColor(v);
237+
this.ctx.fillRect(0, offset(i), indicatorSize, stepWidth);
238+
}
239+
} else {
240+
const offset = !reverse ? (i: number) => i : (i: number) => h - 1 - i;
241+
for (let i = 0; i < h; i += 1) {
242+
this.ctx.fillStyle = this.getColor((i + 0.5) / h);
243+
this.ctx.fillRect(0, offset(i), indicatorSize, 1);
244+
}
243245
}
244246
}
245247
}

src/scales/LegendScale.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
export interface ILegendScaleOptions extends CartesianScaleOptions {
1111
/**
1212
* whether to render a color legend
13-
* @default false (for compatibility reasons)
13+
* @default true
1414
*/
1515
display: boolean;
1616

@@ -93,9 +93,12 @@ interface IPositionOption {
9393
position?: string;
9494
}
9595

96-
function computeLegendMargin(
97-
legend: ILegendScaleOptions['legend']
98-
): { left: number; top: number; right: number; bottom: number } {
96+
function computeLegendMargin(legend: ILegendScaleOptions['legend']): {
97+
left: number;
98+
top: number;
99+
right: number;
100+
bottom: number;
101+
} {
99102
const { indicatorWidth, align: pos, margin } = legend;
100103

101104
const left = (typeof margin === 'number' ? margin : margin.left) + (pos === 'right' ? indicatorWidth : 0);
@@ -147,7 +150,7 @@ export class LegendScale<O extends ILegendScaleOptions & LinearScaleOptions> ext
147150

148151
init(options: O): void {
149152
// eslint-disable-next-line no-param-reassign
150-
((options as unknown) as IPositionOption).position = 'chartArea';
153+
(options as unknown as IPositionOption).position = 'chartArea';
151154
super.init(options);
152155
this.axis = 'r';
153156
}
@@ -195,6 +198,11 @@ export class LegendScale<O extends ILegendScaleOptions & LinearScaleOptions> ext
195198
return r;
196199
}
197200

201+
// eslint-disable-next-line class-methods-use-this
202+
_computeLabelArea(): void {
203+
return undefined;
204+
}
205+
198206
draw(chartArea: ChartArea): void {
199207
if (!(this as any)._isVisible()) {
200208
return;
@@ -207,7 +215,7 @@ export class LegendScale<O extends ILegendScaleOptions & LinearScaleOptions> ext
207215

208216
const bak = (this.options as IPositionOption).position;
209217
(this.options as IPositionOption).position = this.options.legend.align;
210-
super.draw({ ...chartArea, bottom: this.height, right: this.width });
218+
super.draw({ ...chartArea, bottom: this.height + 10, right: this.width });
211219
(this.options as IPositionOption).position = bak;
212220
const { indicatorWidth } = this.options.legend;
213221
switch (this.options.legend.align) {

src/scales/SizeScale.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ export interface ISizeScaleOptions extends ILegendScaleOptions {
1313
// support all options from linear scale -> https://www.chartjs.org/docs/latest/axes/cartesian/linear.html#linear-cartesian-axis
1414
// e.g. for tick manipulation, ...
1515

16-
/**
17-
* whether to render a color legend
18-
* @default false (for compatibility reasons)
19-
*/
20-
display: boolean;
21-
2216
/**
2317
* radius range in pixel, the minimal data value will be mapped to the
2418
* first entry, the maximal one to the second and a linear interpolation
@@ -40,50 +34,6 @@ export interface ISizeScaleOptions extends ILegendScaleOptions {
4034
* @default 1
4135
*/
4236
missing: number;
43-
44-
/**
45-
* the property name that stores the value in the data elements
46-
* @default value
47-
*/
48-
property: string;
49-
50-
legend: {
51-
/**
52-
* location of the legend on the chart area
53-
* @default bottom-right
54-
*/
55-
position: 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'top-right' | 'bottom-right';
56-
/**
57-
* alignment of the scale, e.g., `right` means that it is a vertical scale
58-
* with the ticks on the right side
59-
* @default bottom
60-
*/
61-
align: 'left' | 'right' | 'top' | 'bottom';
62-
/**
63-
* length of the legend, i.e., for a horizontal scale the width
64-
* if a value < 1 is given, is it assume to be a ratio of the corresponding
65-
* chart area
66-
* @default 90
67-
*/
68-
length: number;
69-
/**
70-
* how wide the scale is, i.e., for a horizontal scale the height
71-
* if a value < 1 is given, is it assume to be a ratio of the corresponding
72-
* chart area
73-
* @default 70
74-
*/
75-
width: number;
76-
/**
77-
* how many pixels should be used for the color bar
78-
* @default 42
79-
*/
80-
indicatorWidth: number;
81-
/**
82-
* margin pixels such that it doesn't stick to the edge of the chart
83-
* @default 8
84-
*/
85-
margin: number;
86-
};
8737
}
8838

8939
const scaleDefaults = {

0 commit comments

Comments
 (0)