@@ -1203,18 +1203,100 @@ export default {
12031203 this .drawCanvasPlots ();
12041204 }
12051205
1206+ if (this .chartConfig .chart .highlightArea .show ) {
1207+ this .drawHighlightArea ();
1208+ }
1209+
12061210 if (this .chartConfig .chart .title .show && this .mutableConfig .titleInside ) {
12071211 this .drawCanvasTitle ();
12081212 if (this .chartConfig .chart .title .subtitle .text ) {
12091213 this .drawCanvasSubtitle ();
12101214 }
12111215 }
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+ }
12121241
12131242 if (this .isInsideCanvas ) {
12141243 this .drawCanvasTooltip ();
12151244 this .drawCanvasSelector ();
12161245 }
12171246 },
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+ },
12181300 drawCanvasSelector () {
12191301 this .CTX .save ();
12201302 const zoneWidth = this .maxSlot ;
@@ -1534,9 +1616,8 @@ export default {
15341616 }
15351617 this .CTX .restore ();
15361618 },
1537- drawCanvasAxisLabels () {
1538- if (this .chartConfig .chart .grid .labels .axis .yLabel ) {
1539- const x = 0 ;
1619+ drawCanvasAxisYLabel () {
1620+ const x = 0 ;
15401621 const y = this .drawingArea .height / 2 ;
15411622 this .CTX .save ();
15421623 this .CTX .translate (x,y);
@@ -1550,18 +1631,25 @@ export default {
15501631 15
15511632 )
15521633 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 ();
15531650 }
15541651 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 ();
15651653 }
15661654 },
15671655 drawCanvasGrid () {
0 commit comments