File tree Expand file tree Collapse file tree 4 files changed +160
-83
lines changed Expand file tree Collapse file tree 4 files changed +160
-83
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " chartjs-chart-geo" ,
3
3
"description" : " Chart.js module for charting maps" ,
4
- "version" : " 3.8.0 " ,
4
+ "version" : " 3.8.1 " ,
5
5
"author" : {
6
6
"name" : " Samuel Gratzl" ,
7
7
"email" : " sam@sgratzl.com" ,
55
55
"@rollup/plugin-typescript" : " ^8.3.3" ,
56
56
"@types/jest" : " ^28.1.4" ,
57
57
"@types/jest-image-snapshot" : " ^5.1.0" ,
58
- "@types/node" : " ^18.0.1 " ,
58
+ "@types/node" : " ^18.0.3 " ,
59
59
"@types/seedrandom" : " ^3.0.2" ,
60
- "@typescript-eslint/eslint-plugin" : " ^5.30.4 " ,
61
- "@typescript-eslint/parser" : " ^5.30.4 " ,
60
+ "@typescript-eslint/eslint-plugin" : " ^5.30.5 " ,
61
+ "@typescript-eslint/parser" : " ^5.30.5 " ,
62
62
"@yarnpkg/pnpify" : " ^3.1.3" ,
63
63
"@yarnpkg/sdks" : " ^2.6.2" ,
64
64
"canvas" : " ^2.9.3" ,
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < script src ="https://unpkg.com/chart.js@3.8.0/dist/chart.js "> </ script >
5
+ < script src ="../build/index.umd.js "> </ script >
6
+ </ head >
7
+
8
+ < body >
9
+ < div style ="width: 75% ">
10
+ < canvas id ="canvas " style ="border: 1px solid black "> </ canvas >
11
+ </ div >
12
+ < script >
13
+ fetch ( 'https://unpkg.com/us-atlas/states-10m.json' )
14
+ . then ( ( r ) => r . json ( ) )
15
+ . then ( ( us ) => {
16
+ const nation = ChartGeo . topojson . feature ( us , us . objects . nation ) . features [ 0 ] ;
17
+ const states = ChartGeo . topojson . feature ( us , us . objects . states ) . features ;
18
+
19
+ const chart = new Chart ( document . getElementById ( 'canvas' ) . getContext ( '2d' ) , {
20
+ type : 'choropleth' ,
21
+ data : {
22
+ labels : states . map ( ( d ) => d . properties . name ) ,
23
+ datasets : [
24
+ {
25
+ label : 'States' ,
26
+ outline : nation ,
27
+ data : states . map ( ( d ) => ( {
28
+ feature : d ,
29
+ value : Math . random ( ) * 11 ,
30
+ } ) ) ,
31
+ } ,
32
+ ] ,
33
+ } ,
34
+ options : {
35
+ plugins : {
36
+ legend : {
37
+ display : false ,
38
+ } ,
39
+ } ,
40
+ scales : {
41
+ xy : {
42
+ projection : 'albersUsa' ,
43
+ } ,
44
+ color : {
45
+ quantize : 5 ,
46
+ legend : {
47
+ position : 'bottom-right' ,
48
+ align : 'right' ,
49
+ } ,
50
+ } ,
51
+ } ,
52
+ } ,
53
+ } ) ;
54
+
55
+ setTimeout ( ( ) => {
56
+ chart . options . scales . xy = {
57
+ projection : 'equalEarth' ,
58
+ projectionOffset : [ 100 , 0 ] ,
59
+ } ;
60
+ chart . update ( ) ;
61
+
62
+ setTimeout ( ( ) => {
63
+ chart . options . scales . xy = {
64
+ projection : 'albersUsa' ,
65
+ projectionOffset : [ - 100 , 0 ] ,
66
+ } ;
67
+ chart . update ( ) ;
68
+ } , 1000 ) ;
69
+ } , 1000 ) ;
70
+ } ) ;
71
+ </ script >
72
+ </ body >
73
+ </ html >
Original file line number Diff line number Diff line change @@ -116,6 +116,9 @@ export class ProjectionScale extends Scale<IProjectionScaleOptions> {
116
116
this . projection = ( lookup [ options . projection ] || lookup . albersUsa ) ( ) ;
117
117
}
118
118
this . geoPath . projection ( this . projection ) ;
119
+
120
+ this . outlineBounds = null ;
121
+ this . oldChartBounds = null ;
119
122
}
120
123
121
124
computeBounds ( outline : ExtendedFeature ) : void ;
@@ -141,6 +144,7 @@ export class ProjectionScale extends Scale<IProjectionScaleOptions> {
141
144
142
145
updateBounds ( ) : boolean {
143
146
const area = this . chart . chartArea ;
147
+
144
148
const bb = this . outlineBounds ;
145
149
146
150
if ( ! bb ) {
You can’t perform that action at this time.
0 commit comments