Skip to content

Commit

Permalink
feat: upgrade to beta.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Nov 10, 2020
1 parent e5c0ff5 commit 0bfb83c
Show file tree
Hide file tree
Showing 22 changed files with 697 additions and 626 deletions.
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,42 @@
"topojson-client": "^3.1.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.3",
"@rollup/plugin-typescript": "^6.0.0",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@rollup/plugin-replace": "^2.3.4",
"@rollup/plugin-typescript": "^6.1.0",
"@types/jest": "^26.0.15",
"@types/jest-image-snapshot": "^4.1.2",
"@types/node": "^14.14.0",
"@types/jest-image-snapshot": "^4.1.3",
"@types/node": "^14.14.7",
"@types/seedrandom": "^2.4.28",
"@typescript-eslint/eslint-plugin": "^4.5.0",
"@typescript-eslint/parser": "^4.5.0",
"@typescript-eslint/eslint-plugin": "^4.7.0",
"@typescript-eslint/parser": "^4.7.0",
"@yarnpkg/pnpify": "^2.3.3",
"canvas": "^2.6.1",
"chart.js": "^3.0.0-beta.4",
"eslint": "^7.11.0",
"eslint-config-prettier": "^6.13.0",
"eslint-config-react-app": "^5.2.1",
"chart.js": "^3.0.0-beta.6",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"jest": "^26.6.0",
"jest": "^26.6.3",
"jest-image-snapshot": "^4.2.0",
"prettier": "^2.1.2",
"release-it": "^14.2.0",
"release-it": "^14.2.1",
"rimraf": "^3.0.2",
"rollup": "^2.32.1",
"rollup": "^2.33.1",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-dts": "^1.4.13",
"rollup-plugin-terser": "^7.0.2",
"seedrandom": "^3.0.5",
"ts-jest": "^26.4.1",
"ts-jest": "^26.4.4",
"tslib": "^2.0.3",
"typedoc": "^0.19.2",
"typescript": "^4.0.3",
"typescript": "^4.0.5",
"us-atlas": "^3.0.0",
"world-atlas": "^2.0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion samples/albers.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.0.0-beta.4/dist/chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-beta.6/dist/chart.js"></script>
<script src="../build/index.umd.js"></script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion samples/albersLog.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.0.0-beta.4/dist/chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-beta.6/dist/chart.js"></script>
<script src="../build/index.umd.js"></script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion samples/bubbleMap.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.0.0-beta.4/dist/chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-beta.6/dist/chart.js"></script>
<!-- <script src="https://unpkg.com/chartjs-plugin-datalabels"></script> -->
<script src="../build/index.umd.js"></script>
<script src="https://unpkg.com/papaparse"></script>
Expand Down
2 changes: 1 addition & 1 deletion samples/bubbleMapArea.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.0.0-beta.4/dist/chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-beta.6/dist/chart.js"></script>
<!-- <script src="https://unpkg.com/chartjs-plugin-datalabels"></script> -->
<script src="../build/index.umd.js"></script>
<script src="https://unpkg.com/papaparse"></script>
Expand Down
2 changes: 1 addition & 1 deletion samples/bubbleMapLog.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.0.0-beta.4/dist/chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-beta.6/dist/chart.js"></script>
<!-- <script src="https://unpkg.com/chartjs-plugin-datalabels"></script> -->
<script src="../build/index.umd.js"></script>
<script src="https://unpkg.com/papaparse"></script>
Expand Down
4 changes: 2 additions & 2 deletions samples/default_esm.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<script type="importmap-shim">
{
"imports": {
"chart.js": "https://unpkg.com/chart.js@3.0.0-beta.4?module",
"chart.js/helpers": "https://unpkg.com/chart.js@3.0.0-beta.4/helpers/helpers.esm.js?module",
"chart.js": "https://unpkg.com/chart.js@3.0.0-beta.6?module",
"chart.js/helpers": "https://unpkg.com/chart.js@3.0.0-beta.6/helpers/helpers.esm.js?module",
"chartjs-chart-geo": "../build/index.esm.js",
"d3-geo": "https://unpkg.com/d3-geo?module",
"d3-scale-chromatic": "https://unpkg.com/d3-scale-chromatic?module",
Expand Down
2 changes: 1 addition & 1 deletion samples/earth.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.0.0-beta.4/dist/chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-beta.6/dist/chart.js"></script>
<script src="../build/index.umd.js"></script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion samples/earth_click.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.0.0-beta.4/dist/chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-beta.6/dist/chart.js"></script>
<script src="../build/index.umd.js"></script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion samples/germany.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.0.0-beta.4/dist/chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-beta.6/dist/chart.js"></script>
<script src="../build/index.umd.js"></script>
</head>

Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/createChart.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="jest" />
/// <reference types="node" />

import { Chart, IChartConfiguration, defaults, IChartType, DefaultDataPoint } from 'chart.js';
import { Chart, ChartConfiguration, defaults, ChartType, DefaultDataPoint } from 'chart.js';
import { toMatchImageSnapshot, MatchImageSnapshotOptions } from 'jest-image-snapshot';

expect.extend({ toMatchImageSnapshot });
Expand All @@ -22,10 +22,10 @@ export async function expectMatchSnapshot(canvas: HTMLCanvasElement) {
}

export default function createChart<
TYPE extends IChartType,
TYPE extends ChartType,
DATA extends unknown[] = DefaultDataPoint<TYPE>,
LABEL = string
>(config: IChartConfiguration<TYPE, DATA, LABEL>, width = 800, height = 600) {
>(config: ChartConfiguration<TYPE, DATA, LABEL>, width = 800, height = 600) {
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
Expand Down
40 changes: 18 additions & 22 deletions src/controllers/bubbleMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {
BubbleController,
Chart,
ChartItem,
IChartConfiguration,
ICommonHoverOptions,
IControllerDatasetOptions,
IPointOptions,
IPointProps,
IScriptableContext,
ITooltipItem,
Point,
ChartConfiguration,
CommonHoverOptions,
ControllerDatasetOptions,
PointOptions,
PointProps,
ScriptableContext,
TooltipItem,
PointElement,
Scale,
ScriptableAndArrayOptions,
UpdateMode,
Expand All @@ -20,7 +20,7 @@ import { ProjectionScale, SizeScale } from '../scales';
import { GeoController, geoDefaults, IGeoChartOptions } from './geo';
import patchController from './patchController';

export class BubbleMapController extends GeoController<Point> {
export class BubbleMapController extends GeoController<PointElement> {
initialize() {
super.initialize();
this.enableOptionSharing = true;
Expand Down Expand Up @@ -56,7 +56,7 @@ export class BubbleMapController extends GeoController<Point> {
}
}

updateElements(elems: Point[], start: number, count: number, mode: UpdateMode) {
updateElements(elems: PointElement[], start: number, count: number, mode: UpdateMode) {
const reset = mode === 'reset';
const firstOpts = this.resolveDataElementOptions(start, mode);
const sharedOptions = this.getSharedOptions(firstOpts);
Expand All @@ -71,7 +71,7 @@ export class BubbleMapController extends GeoController<Point> {
const elem = elems[i];
const parsed = this.getParsed(i);
const xy = scale.projection!([parsed.x, parsed.y]);
const properties: IPointProps & { options?: IPointOptions; skip: boolean } = {
const properties: PointProps & { options?: PointOptions; skip: boolean } = {
x: xy ? xy[0] : 0,
y: xy ? xy[1] : 0,
skip: Number.isNaN(parsed.x) || Number.isNaN(parsed.y),
Expand All @@ -96,7 +96,7 @@ export class BubbleMapController extends GeoController<Point> {
static readonly defaults: any = merge({}, [
geoDefaults,
{
dataElementType: Point.id,
dataElementType: PointElement.id,
dataElementOptions: BubbleController.defaults.dataElementOptions,
datasetElementType: GeoFeature.id,
showOutline: true,
Expand All @@ -107,7 +107,7 @@ export class BubbleMapController extends GeoController<Point> {
// Title doesn't make sense for scatter since we format the data as a point
return '';
},
label(item: ITooltipItem) {
label(item: TooltipItem) {
if (item.formattedValue == null) {
return item.chart.data.labels[item.dataIndex];
}
Expand All @@ -122,7 +122,7 @@ export class BubbleMapController extends GeoController<Point> {
},
elements: {
point: {
radius(context: IScriptableContext) {
radius(context: ScriptableContext) {
if (context.dataIndex == null) {
return null;
}
Expand All @@ -145,17 +145,13 @@ export interface IBubbleMapDataPoint {
}

export interface IBubbleMapControllerDatasetOptions
extends IControllerDatasetOptions,
extends ControllerDatasetOptions,
IGeoChartOptions,
ScriptableAndArrayOptions<IGeoFeatureOptions>,
ScriptableAndArrayOptions<ICommonHoverOptions> {}
ScriptableAndArrayOptions<CommonHoverOptions> {}

declare module 'chart.js' {
export enum ChartTypeEnum {
bubbleMap = 'bubbleMap',
}

export interface IChartTypeRegistry {
export interface ChartTypeRegistry {
bubbleMap: {
chartOptions: IGeoChartOptions;
datasetOptions: IBubbleMapControllerDatasetOptions;
Expand All @@ -172,7 +168,7 @@ export class BubbleMapChart<DATA extends unknown[] = IBubbleMapDataPoint[], LABE
> {
static id = BubbleMapController.id;

constructor(item: ChartItem, config: Omit<IChartConfiguration<'bubbleMap', DATA, LABEL>, 'type'>) {
constructor(item: ChartItem, config: Omit<ChartConfiguration<'bubbleMap', DATA, LABEL>, 'type'>) {
super(item, patchController('bubbleMap', config, BubbleMapController, GeoFeature, [SizeScale, ProjectionScale]));
}
}
30 changes: 13 additions & 17 deletions src/controllers/choropleth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
Chart,
UpdateMode,
IScriptableContext,
ITooltipItem,
ICommonHoverOptions,
ScriptableContext,
TooltipItem,
CommonHoverOptions,
ScriptableAndArrayOptions,
IControllerDatasetOptions,
IChartConfiguration,
ControllerDatasetOptions,
ChartConfiguration,
ChartItem,
IPointOptions,
PointOptions,
Scale,
} from 'chart.js';
import { merge } from 'chart.js/helpers';
Expand Down Expand Up @@ -63,7 +63,7 @@ export class ChoroplethController extends GeoController<GeoFeature> {
elem.feature = (this as any)._data[i].feature;
const center = elem.getCenterPoint();

const properties: IGeoFeatureProps & { options?: IPointOptions } = {
const properties: IGeoFeatureProps & { options?: PointOptions } = {
x: center.x,
y: center.y,
};
Expand Down Expand Up @@ -92,7 +92,7 @@ export class ChoroplethController extends GeoController<GeoFeature> {
// Title doesn't make sense for scatter since we format the data as a point
return '';
},
label(item: ITooltipItem) {
label(item: TooltipItem) {
if (item.formattedValue == null) {
return item.chart.data.labels[item.dataIndex];
}
Expand All @@ -107,7 +107,7 @@ export class ChoroplethController extends GeoController<GeoFeature> {
},
elements: {
geoFeature: {
backgroundColor(context: IScriptableContext) {
backgroundColor(context: ScriptableContext) {
if (context.dataIndex == null) {
return null;
}
Expand All @@ -121,17 +121,13 @@ export class ChoroplethController extends GeoController<GeoFeature> {
}

export interface IChoroplethControllerDatasetOptions
extends IControllerDatasetOptions,
extends ControllerDatasetOptions,
IGeoChartOptions,
ScriptableAndArrayOptions<IGeoFeatureOptions>,
ScriptableAndArrayOptions<ICommonHoverOptions> {}
ScriptableAndArrayOptions<CommonHoverOptions> {}

declare module 'chart.js' {
export enum ChartTypeEnum {
choropleth = 'choropleth',
}

export interface IChartTypeRegistry {
export interface ChartTypeRegistry {
choropleth: {
chartOptions: IGeoChartOptions;
datasetOptions: IChoroplethControllerDatasetOptions;
Expand All @@ -148,7 +144,7 @@ export class ChoroplethChart<DATA extends unknown[] = IGeoDataPoint[], LABEL = s
> {
static id = ChoroplethController.id;

constructor(item: ChartItem, config: Omit<IChartConfiguration<'choropleth', DATA, LABEL>, 'type'>) {
constructor(item: ChartItem, config: Omit<ChartConfiguration<'choropleth', DATA, LABEL>, 'type'>) {
super(item, patchController('choropleth', config, ChoroplethController, GeoFeature, [ColorScale, ProjectionScale]));
}
}
8 changes: 4 additions & 4 deletions src/controllers/geo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
DatasetController,
IChartDataset,
ChartDataset,
ScriptableAndArrayOptions,
UpdateMode,
Element,
IVisualElement,
VisualElement,
} from 'chart.js';
import { clipArea, unclipArea, valueOrDefault } from 'chart.js/helpers';
import { geoGraticule, geoGraticule10, ExtendedFeature } from 'd3-geo';
Expand Down Expand Up @@ -48,9 +48,9 @@ function patchDatasetElementOptions(options: any) {
return r;
}

export class GeoController<E extends Element & IVisualElement> extends DatasetController<E, GeoFeature> {
export class GeoController<E extends Element & VisualElement> extends DatasetController<E, GeoFeature> {
getGeoDataset() {
return (super.getDataset() as unknown) as IChartDataset<'choropleth' | 'bubbleMap'> & IGeoControllerDatasetOptions;
return (super.getDataset() as unknown) as ChartDataset<'choropleth' | 'bubbleMap'> & IGeoControllerDatasetOptions;
}
getGeoOptions() {
return (this.chart.options as unknown) as IGeoChartOptions;
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/patchController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { registry, IDatasetControllerChartComponent, IChartComponent } from 'chart.js';
import { registry, DatasetControllerChartComponent, ChartComponent } from 'chart.js';

export default function patchController<T, TYPE>(
type: TYPE,
config: T,
controller: IDatasetControllerChartComponent,
elements: IChartComponent | IChartComponent[] = [],
scales: IChartComponent | IChartComponent[] = []
controller: DatasetControllerChartComponent,
elements: ChartComponent | ChartComponent[] = [],
scales: ChartComponent | ChartComponent[] = []
): T & { type: TYPE } {
registry.addControllers(controller);
if (Array.isArray(elements)) {
Expand Down
Loading

0 comments on commit 0bfb83c

Please sign in to comment.