-
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 (#6460)
Implemented RTL support for legends and tooltips
- Loading branch information
1 parent
995efa5
commit 376da21
Showing
6 changed files
with
128 additions
and
19 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
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,75 @@ | ||
'use strict'; | ||
|
||
var getRtlAdapter = function(rectX, width) { | ||
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, itemWidth) { | ||
return x - itemWidth; | ||
}, | ||
}; | ||
}; | ||
|
||
var getLtrAdapter = function() { | ||
return { | ||
x: function(x) { | ||
return x; | ||
}, | ||
setWidth: function(w) { // eslint-disable-line no-unused-vars | ||
}, | ||
textAlign: function(align) { | ||
return align; | ||
}, | ||
xPlus: function(x, value) { | ||
return x + value; | ||
}, | ||
leftForLtr: function(x, _itemWidth) { // eslint-disable-line no-unused-vars | ||
return x; | ||
}, | ||
}; | ||
}; | ||
|
||
var getAdapter = function(rtl, rectX, width) { | ||
return rtl ? getRtlAdapter(rectX, width) : getLtrAdapter(); | ||
}; | ||
|
||
var overrideTextDirection = function(ctx, direction) { | ||
var style, original; | ||
if (direction === 'ltr' || direction === 'rtl') { | ||
style = ctx.canvas.style; | ||
original = [ | ||
style.getPropertyValue('direction'), | ||
style.getPropertyPriority('direction'), | ||
]; | ||
|
||
style.setProperty('direction', direction, 'important'); | ||
ctx.prevTextDirection = original; | ||
} | ||
}; | ||
|
||
var restoreTextDirection = function(ctx) { | ||
var original = ctx.prevTextDirection; | ||
if (original !== undefined) { | ||
delete ctx.prevTextDirection; | ||
ctx.canvas.style.setProperty('direction', original[0], original[1]); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getRtlAdapter: getAdapter, | ||
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