@guardian/interactive-component-library 0.3.2-rc1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.js +1 -1
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.js +1 -1
- package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.js +1 -1
- package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.js +1 -2
- package/dist/components/molecules/canvas-map/lib/styles/Fill.d.ts +29 -3
- package/dist/components/molecules/canvas-map/lib/styles/Fill.js +22 -0
- package/dist/components/molecules/canvas-map/lib/styles/HashPattern.d.ts +38 -0
- package/dist/components/molecules/canvas-map/lib/styles/HashPattern.js +72 -0
- package/dist/components/molecules/canvas-map/lib/styles/Style.d.ts +1 -1
- package/dist/components/molecules/canvas-map/lib/styles/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/style.css +96 -8
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Style } from "../styles/Style.js";
|
|
2
1
|
import { Stroke } from "../styles/Stroke.js";
|
|
3
2
|
import { Fill } from "../styles/Fill.js";
|
|
3
|
+
import { Style } from "../styles/Style.js";
|
|
4
4
|
function interpolateStyles(firstStyle, secondStyle, interpolateColors, interpolateNumbers) {
|
|
5
5
|
const fillInterpolator = interpolateFill(
|
|
6
6
|
firstStyle.fill,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TextLayerRenderer } from "../renderers/TextLayerRenderer.js";
|
|
2
|
-
import { Style } from "../styles/Style.js";
|
|
3
2
|
import { Text } from "../styles/Text.js";
|
|
3
|
+
import { Style } from "../styles/Style.js";
|
|
4
4
|
import { Dispatcher } from "../events/Dispatcher.js";
|
|
5
5
|
import { combineExtents } from "../util/extent.js";
|
|
6
6
|
import { MapEvent } from "../events/MapEvent.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VectorLayerRenderer } from "../renderers/VectorLayerRenderer.js";
|
|
2
|
-
import { Style } from "../styles/Style.js";
|
|
3
2
|
import { Stroke } from "../styles/Stroke.js";
|
|
3
|
+
import { Style } from "../styles/Style.js";
|
|
4
4
|
import { combineExtents } from "../util/extent.js";
|
|
5
5
|
import { Dispatcher } from "../events/Dispatcher.js";
|
|
6
6
|
import { MapEvent } from "../events/MapEvent.js";
|
|
@@ -1,7 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class Fill
|
|
3
|
+
* @description Represents a fill style for a feature
|
|
4
|
+
* @property {string} color - The color of the fill
|
|
5
|
+
* @property {number} opacity - The opacity of the fill
|
|
6
|
+
* @property {HashPattern} pattern - The pattern of the fill
|
|
7
|
+
*/
|
|
1
8
|
export class Fill {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @constructor
|
|
11
|
+
* @description Creates a new instance of the Fill class
|
|
12
|
+
* @param {Object} [options] - The options for the fill
|
|
13
|
+
* @param {string} [options.color="#CCC"] - The color of the fill
|
|
14
|
+
* @param {number} [options.opacity=1] - The opacity of the fill
|
|
15
|
+
* @param {Object} [options.pattern=null] - The pattern of the fill
|
|
16
|
+
*/
|
|
17
|
+
constructor(options?: {
|
|
18
|
+
color?: string;
|
|
19
|
+
opacity?: number;
|
|
20
|
+
pattern?: any;
|
|
21
|
+
});
|
|
22
|
+
color: string;
|
|
23
|
+
opacity: number;
|
|
24
|
+
pattern: any;
|
|
5
25
|
_getRgba: (...arg0: any[]) => string;
|
|
26
|
+
/**
|
|
27
|
+
* @function getRgba
|
|
28
|
+
* @description Returns the fill color as an RGBA string
|
|
29
|
+
* @returns {string} The fill color with opacity applied
|
|
30
|
+
*/
|
|
6
31
|
getRgba(): string;
|
|
32
|
+
drawInContext(context: any, scale: any): void;
|
|
7
33
|
}
|
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
import { memoise } from "../util/memoise.js";
|
|
2
2
|
import { toRgba } from "../util/toRgba.js";
|
|
3
3
|
class Fill {
|
|
4
|
+
/**
|
|
5
|
+
* @constructor
|
|
6
|
+
* @description Creates a new instance of the Fill class
|
|
7
|
+
* @param {Object} [options] - The options for the fill
|
|
8
|
+
* @param {string} [options.color="#CCC"] - The color of the fill
|
|
9
|
+
* @param {number} [options.opacity=1] - The opacity of the fill
|
|
10
|
+
* @param {Object} [options.pattern=null] - The pattern of the fill
|
|
11
|
+
*/
|
|
4
12
|
constructor(options) {
|
|
5
13
|
this.color = (options == null ? void 0 : options.color) || "#CCC";
|
|
6
14
|
this.opacity = (options == null ? void 0 : options.opacity) || 1;
|
|
15
|
+
this.pattern = (options == null ? void 0 : options.pattern) || null;
|
|
7
16
|
this._getRgba = memoise(toRgba);
|
|
8
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* @function getRgba
|
|
20
|
+
* @description Returns the fill color as an RGBA string
|
|
21
|
+
* @returns {string} The fill color with opacity applied
|
|
22
|
+
*/
|
|
9
23
|
getRgba() {
|
|
10
24
|
return this._getRgba(this.color, this.opacity);
|
|
11
25
|
}
|
|
26
|
+
drawInContext(context, scale) {
|
|
27
|
+
if (this.pattern) {
|
|
28
|
+
context.fillStyle = this.pattern.createPatternInContext(context, scale);
|
|
29
|
+
} else {
|
|
30
|
+
context.fillStyle = this.getRgba();
|
|
31
|
+
}
|
|
32
|
+
context.fill();
|
|
33
|
+
}
|
|
12
34
|
}
|
|
13
35
|
export {
|
|
14
36
|
Fill
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HashPattern creates a diagonally-striped pattern used to fill a canvas element.
|
|
3
|
+
*
|
|
4
|
+
* Use `createPatternInContext` to create a pattern that can be used as a `fillStyle`.
|
|
5
|
+
*/
|
|
6
|
+
export class HashPattern {
|
|
7
|
+
/**
|
|
8
|
+
* @param {Object} options
|
|
9
|
+
* @param {number} [options.stripeWidth=4] - width of the pattern's stripes
|
|
10
|
+
* @param {number} [options.gapWidth =10] - width of the gap between the stripes
|
|
11
|
+
* @param {string} [options.stripeColor="#eee"]
|
|
12
|
+
* @param {string} [options.gapColor="#777"]
|
|
13
|
+
*/
|
|
14
|
+
constructor({ stripeWidth, gapWidth, gapColor, stripeColor, }: {
|
|
15
|
+
stripeWidth?: number;
|
|
16
|
+
gapWidth?: number;
|
|
17
|
+
stripeColor?: string;
|
|
18
|
+
gapColor?: string;
|
|
19
|
+
});
|
|
20
|
+
stripeWidth: number;
|
|
21
|
+
stripeColor: string;
|
|
22
|
+
gapwidth: number;
|
|
23
|
+
gapColor: string;
|
|
24
|
+
tileSize: number;
|
|
25
|
+
offscreenCanvas: HTMLCanvasElement;
|
|
26
|
+
lastDrawnScale: any;
|
|
27
|
+
lastDrawnPattern: CanvasPattern;
|
|
28
|
+
/**
|
|
29
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
30
|
+
* @param {number} scale
|
|
31
|
+
*/
|
|
32
|
+
createPatternInContext(ctx: CanvasRenderingContext2D, scale: number): CanvasPattern;
|
|
33
|
+
/**
|
|
34
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
35
|
+
* @param {number} scale
|
|
36
|
+
*/
|
|
37
|
+
_createPattern(ctx: CanvasRenderingContext2D, scale: number): CanvasPattern;
|
|
38
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
class HashPattern {
|
|
2
|
+
/**
|
|
3
|
+
* @param {Object} options
|
|
4
|
+
* @param {number} [options.stripeWidth=4] - width of the pattern's stripes
|
|
5
|
+
* @param {number} [options.gapWidth =10] - width of the gap between the stripes
|
|
6
|
+
* @param {string} [options.stripeColor="#eee"]
|
|
7
|
+
* @param {string} [options.gapColor="#777"]
|
|
8
|
+
*/
|
|
9
|
+
constructor({
|
|
10
|
+
stripeWidth = 4,
|
|
11
|
+
gapWidth = 8,
|
|
12
|
+
gapColor = "#eee",
|
|
13
|
+
stripeColor = "#777"
|
|
14
|
+
}) {
|
|
15
|
+
this.stripeWidth = stripeWidth;
|
|
16
|
+
this.stripeColor = stripeColor;
|
|
17
|
+
this.gapwidth = gapWidth;
|
|
18
|
+
this.gapColor = gapColor;
|
|
19
|
+
const hypot = stripeWidth * 2 + gapWidth * 2;
|
|
20
|
+
this.tileSize = Math.round(hypot / Math.SQRT2);
|
|
21
|
+
this.offscreenCanvas = document.createElement("canvas");
|
|
22
|
+
this.lastDrawnScale = null;
|
|
23
|
+
this.lastDrawnPattern = null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
27
|
+
* @param {number} scale
|
|
28
|
+
*/
|
|
29
|
+
createPatternInContext(ctx, scale) {
|
|
30
|
+
const roundedScale = Math.round(scale);
|
|
31
|
+
if (roundedScale === this.lastDrawnScale) {
|
|
32
|
+
return this.lastDrawnPattern;
|
|
33
|
+
}
|
|
34
|
+
this.lastDrawnPattern = this._createPattern(ctx, roundedScale);
|
|
35
|
+
this.lastDrawnScale = roundedScale;
|
|
36
|
+
return this.lastDrawnPattern;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
40
|
+
* @param {number} scale
|
|
41
|
+
*/
|
|
42
|
+
_createPattern(ctx, scale) {
|
|
43
|
+
const size = this.tileSize * scale;
|
|
44
|
+
this.offscreenCanvas.width = size;
|
|
45
|
+
this.offscreenCanvas.height = size;
|
|
46
|
+
const offCtx = this.offscreenCanvas.getContext("2d");
|
|
47
|
+
if (this.gapColor) {
|
|
48
|
+
offCtx.fillStyle = this.gapColor;
|
|
49
|
+
offCtx.fillRect(0, 0, size, size);
|
|
50
|
+
}
|
|
51
|
+
const lineWidth = this.stripeWidth * scale;
|
|
52
|
+
offCtx.strokeStyle = this.stripeColor;
|
|
53
|
+
offCtx.lineWidth = lineWidth;
|
|
54
|
+
offCtx.lineCap = "square";
|
|
55
|
+
offCtx.beginPath();
|
|
56
|
+
offCtx.moveTo(-1, 1);
|
|
57
|
+
offCtx.lineTo(1, -1);
|
|
58
|
+
offCtx.moveTo(0, size);
|
|
59
|
+
offCtx.lineTo(size, 0);
|
|
60
|
+
offCtx.moveTo(size - 1, size + 1);
|
|
61
|
+
offCtx.lineTo(size + 1, size - 1);
|
|
62
|
+
offCtx.stroke();
|
|
63
|
+
const pattern = ctx.createPattern(this.offscreenCanvas, "repeat");
|
|
64
|
+
pattern.setTransform(
|
|
65
|
+
new DOMMatrix().scale(1 / Math.round(scale), 1 / Math.round(scale))
|
|
66
|
+
);
|
|
67
|
+
return pattern;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
HashPattern
|
|
72
|
+
};
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @class
|
|
9
9
|
* @property {Object} properties - The properties of the style
|
|
10
10
|
* @property {Object} properties.stroke - The stroke color of the style
|
|
11
|
-
* @property {
|
|
11
|
+
* @property {Fill} properties.fill - The fill color of the style
|
|
12
12
|
* @property {Object} properties.text - The text color of the style
|
|
13
13
|
*/
|
|
14
14
|
export class Style {
|
package/dist/index.js
CHANGED
|
@@ -42,10 +42,11 @@ import { MapEvent } from "./components/molecules/canvas-map/lib/events/MapEvent.
|
|
|
42
42
|
import { Projection } from "./components/molecules/canvas-map/lib/projection/index.js";
|
|
43
43
|
import { TextLayer } from "./components/molecules/canvas-map/lib/layers/TextLayer.js";
|
|
44
44
|
import { VectorLayer } from "./components/molecules/canvas-map/lib/layers/VectorLayer.js";
|
|
45
|
-
import { Style } from "./components/molecules/canvas-map/lib/styles/Style.js";
|
|
46
45
|
import { Stroke, StrokePosition } from "./components/molecules/canvas-map/lib/styles/Stroke.js";
|
|
46
|
+
import { HashPattern } from "./components/molecules/canvas-map/lib/styles/HashPattern.js";
|
|
47
47
|
import { Fill } from "./components/molecules/canvas-map/lib/styles/Fill.js";
|
|
48
48
|
import { Text } from "./components/molecules/canvas-map/lib/styles/Text.js";
|
|
49
|
+
import { Style } from "./components/molecules/canvas-map/lib/styles/Style.js";
|
|
49
50
|
import { GeoCoordinate } from "./components/molecules/canvas-map/lib/util/coordinate.js";
|
|
50
51
|
import { GeoBounds } from "./components/molecules/canvas-map/lib/util/bounds.js";
|
|
51
52
|
import { Extent, combineExtents, containsCoordinate, containsXY, extentForCoordinates } from "./components/molecules/canvas-map/lib/util/extent.js";
|
|
@@ -89,6 +90,7 @@ export {
|
|
|
89
90
|
GeoJSON,
|
|
90
91
|
GradientIcon,
|
|
91
92
|
GridType,
|
|
93
|
+
HashPattern,
|
|
92
94
|
InfoButton,
|
|
93
95
|
LabelOverlapConfig,
|
|
94
96
|
LabelType,
|
package/dist/style.css
CHANGED
|
@@ -1078,6 +1078,18 @@ button {
|
|
|
1078
1078
|
.bg-color--oth {
|
|
1079
1079
|
background-color: var(--oth) !important;
|
|
1080
1080
|
}
|
|
1081
|
+
.bg-color--ind-dem {
|
|
1082
|
+
background-color: var(--ind-dem) !important;
|
|
1083
|
+
}
|
|
1084
|
+
.bg-color--lib {
|
|
1085
|
+
background-color: var(--lib) !important;
|
|
1086
|
+
}
|
|
1087
|
+
.bg-color--grn {
|
|
1088
|
+
background-color: var(--grn) !important;
|
|
1089
|
+
}
|
|
1090
|
+
.bg-color--ken {
|
|
1091
|
+
background-color: var(--ken) !important;
|
|
1092
|
+
}
|
|
1081
1093
|
.bg-color--dem-2 {
|
|
1082
1094
|
background-color: var(--dem-2) !important;
|
|
1083
1095
|
}
|
|
@@ -1087,6 +1099,18 @@ button {
|
|
|
1087
1099
|
.bg-color--oth-2 {
|
|
1088
1100
|
background-color: var(--oth-2) !important;
|
|
1089
1101
|
}
|
|
1102
|
+
.bg-color--ind-dem-2 {
|
|
1103
|
+
background-color: var(--ind-dem-2) !important;
|
|
1104
|
+
}
|
|
1105
|
+
.bg-color--lib-2 {
|
|
1106
|
+
background-color: var(--lib-2) !important;
|
|
1107
|
+
}
|
|
1108
|
+
.bg-color--grn-2 {
|
|
1109
|
+
background-color: var(--grn-2) !important;
|
|
1110
|
+
}
|
|
1111
|
+
.bg-color--ken-2 {
|
|
1112
|
+
background-color: var(--ken-2) !important;
|
|
1113
|
+
}
|
|
1090
1114
|
.bg-color--undeclared {
|
|
1091
1115
|
background-color: var(--undeclared) !important;
|
|
1092
1116
|
}
|
|
@@ -1101,6 +1125,18 @@ button {
|
|
|
1101
1125
|
.fill-color--oth {
|
|
1102
1126
|
fill: var(--oth) !important;
|
|
1103
1127
|
}
|
|
1128
|
+
.fill-color--ind-dem {
|
|
1129
|
+
fill: var(--ind-dem) !important;
|
|
1130
|
+
}
|
|
1131
|
+
.fill-color--lib {
|
|
1132
|
+
fill: var(--lib) !important;
|
|
1133
|
+
}
|
|
1134
|
+
.fill-color--grn {
|
|
1135
|
+
fill: var(--grn) !important;
|
|
1136
|
+
}
|
|
1137
|
+
.fill-color--ken {
|
|
1138
|
+
fill: var(--ken) !important;
|
|
1139
|
+
}
|
|
1104
1140
|
.fill-color--dem-2 {
|
|
1105
1141
|
fill: var(--dem-2) !important;
|
|
1106
1142
|
}
|
|
@@ -1110,6 +1146,18 @@ button {
|
|
|
1110
1146
|
.fill-color--oth-2 {
|
|
1111
1147
|
fill: var(--oth-2) !important;
|
|
1112
1148
|
}
|
|
1149
|
+
.fill-color--ind-dem-2 {
|
|
1150
|
+
fill: var(--ind-dem-2) !important;
|
|
1151
|
+
}
|
|
1152
|
+
.fill-color--lib-2 {
|
|
1153
|
+
fill: var(--lib-2) !important;
|
|
1154
|
+
}
|
|
1155
|
+
.fill-color--grn-2 {
|
|
1156
|
+
fill: var(--grn-2) !important;
|
|
1157
|
+
}
|
|
1158
|
+
.fill-color--ken-2 {
|
|
1159
|
+
fill: var(--ken-2) !important;
|
|
1160
|
+
}
|
|
1113
1161
|
.fill-color--undeclared {
|
|
1114
1162
|
fill: var(--undeclared) !important;
|
|
1115
1163
|
}
|
|
@@ -1123,6 +1171,18 @@ button {
|
|
|
1123
1171
|
.stop-color--oth {
|
|
1124
1172
|
stop-color: var(--oth) !important;
|
|
1125
1173
|
}
|
|
1174
|
+
.stop-color--ind-dem {
|
|
1175
|
+
stop-color: var(--ind-dem) !important;
|
|
1176
|
+
}
|
|
1177
|
+
.stop-color--lib {
|
|
1178
|
+
stop-color: var(--lib) !important;
|
|
1179
|
+
}
|
|
1180
|
+
.stop-color--grn {
|
|
1181
|
+
stop-color: var(--grn) !important;
|
|
1182
|
+
}
|
|
1183
|
+
.stop-color--ken {
|
|
1184
|
+
stop-color: var(--ken) !important;
|
|
1185
|
+
}
|
|
1126
1186
|
.stop-color--undeclared {
|
|
1127
1187
|
stop-color: var(--undeclared) !important;
|
|
1128
1188
|
}
|
|
@@ -1136,6 +1196,18 @@ button {
|
|
|
1136
1196
|
.stroke-color--oth {
|
|
1137
1197
|
stroke: var(--oth) !important;
|
|
1138
1198
|
}
|
|
1199
|
+
.stroke-color--ind-dem {
|
|
1200
|
+
stroke: var(--ind-dem) !important;
|
|
1201
|
+
}
|
|
1202
|
+
.stroke-color--lib {
|
|
1203
|
+
stroke: var(--lib) !important;
|
|
1204
|
+
}
|
|
1205
|
+
.stroke-color--grn {
|
|
1206
|
+
stroke: var(--grn) !important;
|
|
1207
|
+
}
|
|
1208
|
+
.stroke-color--ken {
|
|
1209
|
+
stroke: var(--ken) !important;
|
|
1210
|
+
}
|
|
1139
1211
|
.stroke-color--undeclared {
|
|
1140
1212
|
stroke: var(--undeclared) !important;
|
|
1141
1213
|
}
|
|
@@ -1273,12 +1345,20 @@ body {
|
|
|
1273
1345
|
--undeclared: #ededed;
|
|
1274
1346
|
--declared: #fff;
|
|
1275
1347
|
--new-group-01: #333333;
|
|
1276
|
-
--dem: #
|
|
1348
|
+
--dem: #093ca3;
|
|
1277
1349
|
--gop: #c70000;
|
|
1278
|
-
--oth: #
|
|
1279
|
-
--dem
|
|
1350
|
+
--oth: #707070;
|
|
1351
|
+
--ind-dem: #7378d8;
|
|
1352
|
+
--lib: #c6b716;
|
|
1353
|
+
--grn: #0da498;
|
|
1354
|
+
--ken: #ef6f07;
|
|
1355
|
+
--dem-2: #dad7f5;
|
|
1280
1356
|
--gop-2: #ffdbd4;
|
|
1281
|
-
--oth-2: #
|
|
1357
|
+
--oth-2: #e7e7e7;
|
|
1358
|
+
--ind-dem-2: #dad7f5;
|
|
1359
|
+
--lib-2: #f4eac2;
|
|
1360
|
+
--grn-2: #cfedea;
|
|
1361
|
+
--ken-2: #ffe2cd;
|
|
1282
1362
|
--undeclared: #e7e7e7;
|
|
1283
1363
|
}
|
|
1284
1364
|
@media (prefers-color-scheme: dark) {
|
|
@@ -1377,12 +1457,20 @@ body {
|
|
|
1377
1457
|
--undeclared: #ededed;
|
|
1378
1458
|
--declared: #bababa;
|
|
1379
1459
|
--new-group-01: #cccccc;
|
|
1380
|
-
--dem: #
|
|
1381
|
-
--gop: #
|
|
1460
|
+
--dem: #3261db;
|
|
1461
|
+
--gop: #c70000;
|
|
1382
1462
|
--oth: #707070;
|
|
1383
|
-
--dem
|
|
1384
|
-
--
|
|
1463
|
+
--ind-dem: #7389d8;
|
|
1464
|
+
--lib: #c6b716;
|
|
1465
|
+
--grn: #23b4a9;
|
|
1466
|
+
--ken: #ef6f07;
|
|
1467
|
+
--dem-2: #20366d;
|
|
1468
|
+
--gop-2: #5a0b0b;
|
|
1385
1469
|
--oth-2: #333333;
|
|
1470
|
+
--ind-dem-2: #394261;
|
|
1471
|
+
--lib-2: #524d13;
|
|
1472
|
+
--grn-2: #19524e;
|
|
1473
|
+
--ken-2: #6a370e;
|
|
1386
1474
|
--undeclared: #494949;
|
|
1387
1475
|
}
|
|
1388
1476
|
}._svg_b5io0_1 {
|