-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented RTL support for legends and tooltips
* Specify *rtl=true* to set legend/tooltip direction to rtl * Specify *textDirection='ltr'|'rtl'* to force text direction
- Loading branch information
1 parent
053729a
commit 7045059
Showing
4 changed files
with
122 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
var getRtlAdapter = function (rtl, rectX, width) { | ||
if (rtl) { | ||
return { | ||
x: function (x) { | ||
return rectX + rectX + width - x; | ||
}, | ||
setWidth: function (w) { | ||
width = w; | ||
}, | ||
textAlign: function(align) { | ||
if (align === 'center') return align; | ||
return align === 'right' ? 'left' : 'right'; | ||
}, | ||
xPlus: function(x, value) { | ||
return x - value; | ||
}, | ||
leftForLtr: function(x, width) { | ||
return x - width; | ||
}, | ||
}; | ||
} else { | ||
return { | ||
x: function (x) { | ||
return x; | ||
}, | ||
setWidth: function (w) { | ||
width = w; | ||
}, | ||
textAlign: function(align) { | ||
return align; | ||
}, | ||
xPlus: function(x, value) { | ||
return x + value; | ||
}, | ||
leftForLtr: function(x, width) { | ||
return x; | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
var overrideTextDirection = function(ctx, direction) { | ||
delete ctx.prevTextDirection; | ||
|
||
if (direction === 'ltr' || direction === 'rtl') { | ||
var original = [ | ||
ctx.canvas.style.getPropertyValue('direction'), | ||
ctx.canvas.style.getPropertyPriority('direction'), | ||
]; | ||
|
||
ctx.canvas.style.setProperty('direction', direction, 'important'); | ||
ctx.prevTextDirection = original; | ||
} | ||
}; | ||
|
||
var restoreTextDirection = function(ctx) { | ||
if (ctx.prevTextDirection === undefined) | ||
return; | ||
|
||
var original = ctx.prevTextDirection; | ||
delete ctx.prevTextDirection; | ||
|
||
ctx.canvas.style.setProperty('direction', original[0], original[1]); | ||
}; | ||
|
||
module.exports = { | ||
getRtlAdapter: getRtlAdapter, | ||
overrideTextDirection: overrideTextDirection, | ||
restoreTextDirection: restoreTextDirection, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters