@@ -1203,18 +1203,100 @@ export default {
1203
1203
this .drawCanvasPlots ();
1204
1204
}
1205
1205
1206
+ if (this .chartConfig .chart .highlightArea .show ) {
1207
+ this .drawHighlightArea ();
1208
+ }
1209
+
1206
1210
if (this .chartConfig .chart .title .show && this .mutableConfig .titleInside ) {
1207
1211
this .drawCanvasTitle ();
1208
1212
if (this .chartConfig .chart .title .subtitle .text ) {
1209
1213
this .drawCanvasSubtitle ();
1210
1214
}
1211
1215
}
1216
+
1217
+ if (this .chartConfig .chart .highlightArea .show ) {
1218
+ this .CTX .save ();
1219
+ this .CTX .beginPath ();
1220
+ this .CTX .fillStyle = this .chartConfig .chart .backgroundColor ;
1221
+ this .CTX .rect (
1222
+ 0 ,
1223
+ this .drawingArea .top ,
1224
+ this .drawingArea .left - 1 ,
1225
+ this .drawingArea .height
1226
+ );
1227
+ this .CTX .fill ();
1228
+ this .CTX .rect (
1229
+ this .drawingArea .right + 1 ,
1230
+ this .drawingArea .top ,
1231
+ this .chartConfig .chart .width - this .drawingArea .left - 1 ,
1232
+ this .drawingArea .height
1233
+ );
1234
+ this .CTX .fill ();
1235
+ this .CTX .closePath ();
1236
+ this .CTX .fillStyle = this .chartConfig .chart .grid .labels .color ;
1237
+ this .CTX .restore ()
1238
+ this .drawCanvasAxisYLabel ();
1239
+ this .drawCanvasYLabels ();
1240
+ }
1212
1241
1213
1242
if (this .isInsideCanvas ) {
1214
1243
this .drawCanvasTooltip ();
1215
1244
this .drawCanvasSelector ();
1216
1245
}
1217
1246
},
1247
+ wrapText (text , x , y , maxWidth , lineHeight ) {
1248
+ let words = text .split (' ' );
1249
+ let line = ' ' ;
1250
+ let testLine = ' ' ;
1251
+ let lineArray = [];
1252
+
1253
+ for (let n = 0 ; n < words .length ; n++ ) {
1254
+ testLine += ` ${ words[n]} ` ;
1255
+ let metrics = this .CTX .measureText (testLine);
1256
+ let testWidth = metrics .width ;
1257
+ if (testWidth > maxWidth && n > 0 ) {
1258
+ lineArray .push ([line, x, y]);
1259
+ y += lineHeight
1260
+ line = ` ${ words[n]} ` ;
1261
+ testLine = ` ${ words[n]} ` ;
1262
+ }
1263
+ else {
1264
+ line += ` ${ words[n]} ` ;
1265
+ }
1266
+ if (n === words .length - 1 ) {
1267
+ lineArray .push ([line, x, y]);
1268
+ }
1269
+ }
1270
+ return lineArray;
1271
+ },
1272
+ drawHighlightArea () {
1273
+ this .CTX .fillStyle = ` ${ this .chartConfig .chart .highlightArea .color }${ opacity[this .chartConfig .chart .highlightArea .opacity ]} ` ;
1274
+ const x = this .drawingArea .left + (this .drawingArea .width / this .maxSeries ) * (this .chartConfig .chart .highlightArea .from - (this .slicer .start ));
1275
+ const y = this .drawingArea .top ;
1276
+ const height = this .drawingArea .height ;
1277
+ const width = (this .drawingArea .width / this .maxSeries ) * this .highlightAreaSpan ;
1278
+ this .CTX .rect (x, y, width, height);
1279
+ this .CTX .fill ();
1280
+
1281
+ this .CTX .font = ` ${ this .chartConfig .chart .highlightArea .caption .bold ? ' bold' : ' ' } ${ this .chartConfig .chart .highlightArea .caption .fontSize } px ${ this .chartFont } ` ;
1282
+ this .CTX .fillStyle = this .chartConfig .chart .highlightArea .caption .color ;
1283
+ this .CTX .textAlign = ' center' ;
1284
+
1285
+ const textWidth = this .chartConfig .chart .highlightArea .caption .width === ' auto' ? (this .drawingArea .width / this .maxSeries ) * this .highlightAreaSpan : this .chartConfig .chart .highlightArea .caption .width ;
1286
+
1287
+ const wrappedText = this .wrapText (
1288
+ this .chartConfig .chart .highlightArea .caption .text ,
1289
+ x + width / 2 ,
1290
+ this .drawingArea .top + this .chartConfig .chart .highlightArea .caption .offsetY + this .chartConfig .chart .highlightArea .caption .fontSize + this .chartConfig .chart .highlightArea .caption .padding ,
1291
+ textWidth - this .chartConfig .chart .highlightArea .caption .padding * 2 ,
1292
+ this .chartConfig .chart .highlightArea .caption .fontSize * 1.3
1293
+ );
1294
+
1295
+
1296
+ wrappedText .forEach (line => {
1297
+ this .CTX .fillText (line[0 ], line[1 ], line[2 ]);
1298
+ });
1299
+ },
1218
1300
drawCanvasSelector () {
1219
1301
this .CTX .save ();
1220
1302
const zoneWidth = this .maxSlot ;
@@ -1534,9 +1616,8 @@ export default {
1534
1616
}
1535
1617
this .CTX .restore ();
1536
1618
},
1537
- drawCanvasAxisLabels () {
1538
- if (this .chartConfig .chart .grid .labels .axis .yLabel ) {
1539
- const x = 0 ;
1619
+ drawCanvasAxisYLabel () {
1620
+ const x = 0 ;
1540
1621
const y = this .drawingArea .height / 2 ;
1541
1622
this .CTX .save ();
1542
1623
this .CTX .translate (x,y);
@@ -1550,18 +1631,25 @@ export default {
1550
1631
15
1551
1632
)
1552
1633
this .CTX .restore ();
1634
+ },
1635
+ drawCanvasAxisXLabel () {
1636
+ this .CTX .save ();
1637
+ this .CTX .font = ` ${ this .chartConfig .chart .grid .labels .axis .fontSize } px ${ this .chartFont } ` ;
1638
+ this .CTX .fillStyle = this .chartConfig .chart .grid .labels .color ;
1639
+ this .CTX .textAlign = " center" ;
1640
+ this .CTX .fillText (
1641
+ this .chartConfig .chart .grid .labels .axis .xLabel ,
1642
+ this .chartConfig .chart .width / 2 ,
1643
+ this .drawingArea .bottom + this .chartConfig .chart .grid .labels .axis .fontSize + this .chartConfig .chart .grid .labels .xAxisLabels .fontSize * 1.3
1644
+ )
1645
+ this .CTX .restore ();
1646
+ },
1647
+ drawCanvasAxisLabels () {
1648
+ if (this .chartConfig .chart .grid .labels .axis .yLabel ) {
1649
+ this .drawCanvasAxisYLabel ();
1553
1650
}
1554
1651
if (this .chartConfig .chart .grid .labels .axis .xLabel ) {
1555
- this .CTX .save ();
1556
- this .CTX .font = ` ${ this .chartConfig .chart .grid .labels .axis .fontSize } px ${ this .chartFont } ` ;
1557
- this .CTX .fillStyle = this .chartConfig .chart .grid .labels .color ;
1558
- this .CTX .textAlign = " center" ;
1559
- this .CTX .fillText (
1560
- this .chartConfig .chart .grid .labels .axis .xLabel ,
1561
- this .chartConfig .chart .width / 2 ,
1562
- this .drawingArea .bottom + this .chartConfig .chart .grid .labels .axis .fontSize + this .chartConfig .chart .grid .labels .xAxisLabels .fontSize * 1.3
1563
- )
1564
- this .CTX .restore ();
1652
+ this .drawCanvasAxisXLabel ();
1565
1653
}
1566
1654
},
1567
1655
drawCanvasGrid () {
0 commit comments