How can i add a html tag "sup" and "sub" in a text shape when i use Konva.Text? - konvajs

KonvaJS is a excellent canvas plugin,it's easy to use ,a lot of demos,and detailed api document.
But i have a problem about Konva.Text, When I want to display fraction number like "7/8",it's show as a plain text <sup>7</sup>/<sub>8</sub> , how can i do?
As far as I know fabric has analogous method called setSuperscript and setSubscript, can our Konva.Text be achieved?

I suggest to draw it manually with three shapes:
function createFraction(sup, sub) {
const group = new Konva.Group();
group.add(new Konva.Text({
align: 'right',
width: 100,
x: -100,
text: sup
}));
group.add(new Konva.Text({
text: sub,
y: 13,
x: 2
}));
group.add(new Konva.Line({
stroke: 'black',
strokeWidth: 1,
points: [5, 4, -5, 20],
text: sub,
}));
return group;
}
const fraction = createFraction('7', '8');
fraction.position({ x: 50, y: 50});
layer.add(fraction);
https://jsbin.com/vahavimowa/edit?html,js,output

Related

Extract all percentages present within a text imported by IMPORTXML (Google Sheets)

As these percentages are within a function that creates the bar chart, the only way I was able to extract this data was by importing the entire function with this formula:
=IMPORTXML(
"https://int.soccerway.com/teams/spain/real-madrid-club-de-futbol/2016/statistics/",
"//div[#id='charts']//script[#type='text/javascript']")
The result is the following value:
(function(){ function drawScoringMinutesChart() { var hSize = 180, vSize =
180; var opts = { width: hSize, height: vSize, axisTitlesPosition: 'none',
legend: 'none', chartArea: { left: 0, top: 0, width: hSize, height: vSize
}, backgroundColor: '#f4f4f4', colors: ['#f85f00'], hAxis: { textPosition:
'none', viewWindowMode: 'explicit', viewWindow: { min: 0, max: 8 },
baselineColor: '#999999' }, vAxis: { textPosition: 'in' },
enableInteractivity: true }; var data_a = new
google.visualization.DataTable(); data_a.addColumn('string', 'Minute');
data_a.addColumn('number', 'Goals'); data_a.addRows(6); data_a.setValue(0,
0, '20.0%'); data_a.setValue(0, 1, 6); data_a.setValue(1, 0, '13.3%');
data_a.setValue(1, 1, 4); data_a.setValue(2, 0, '3.3%'); data_a.setValue(2,
1, 1); data_a.setValue(3, 0, '23.3%'); data_a.setValue(3, 1, 7);
data_a.setValue(4, 0, '13.3%'); data_a.setValue(4, 1, 4);
data_a.setValue(5, 0, '26.7%'); data_a.setValue(5, 1, 8); var chart_a = new
google.visualization.BarChart(document.getElementById('scoring_minutes_chart_a'));
chart_a.draw(data_a, opts); } $scru.execute(drawScoringMinutesChart,
['google:visualization']); })();
I would like to know if there is any formula that would be able to filter this text and deliver only the percentages, like this:
20.0%
13.3%
3.3%
23.3%
13.3%
26.7%
So that I can, in the end, put it like this in the spreadsheet:
0-15' 20.0%
15-30' 13.3%
30-45' 3.3%
45-60' 23.3%
60-75' 13.3%
75-90' 26.7%
try:
=QUERY(FLATTEN(SPLIT(REGEXREPLACE(IMPORTXML(A1,
"//div[#id='charts']//script[#type='text/javascript']"),
"[^(\d+.\d+%)]", " "), " ")),
"where Col1 contains '%'", 0)

Highcharts pie series label

How can i do single label for each series? something like in img.
The best option to create this labels is using renderer function:
function renderLabel(chart) {
chart.labelsGroup = chart.renderer.g("labelsGroup").attr({
zIndex: 100
}).add();
chart.series.forEach((series, i) => {
chart.labelGroup = chart.renderer.g("labelGroup").attr({
zIndex: 100
}).add(chart.labelsGroup);
chart.label = chart.renderer.label(
series.name,
chart.plotSizeX / 2 + chart.plotLeft - series.data[0].shapeArgs.r + (series.data[0].shapeArgs.r - series.data[0].shapeArgs.innerR) / 2,
(chart.plotHeight) / 2 + chart.plotTop)
.css({
color: '#FFFFFF',
zIndex: 999,
})
.attr({
align: 'center',
padding: 0,
zIndex: 999,
}).add(chart.labelGroup)
let height = chart.label.getBBox().height;
chart.labelGroup.translate(null, -height / 2)
})
}
and use render event to redraw it when the window size changes API
Check this example: DEMO

Can I lay two Highcharts series side-by-side?

Looking at this example: http://www.highcharts.com/stock/demo/candlestick-and-volume
Is there a way that I can lay these two series side-by-side rather than stacked on top?
You can use axis.width and axis.left. You will not find them in axis official API, so you may encounter some issues with it, e.g. problem with a tooltip - issue on github.
The basic config for using two x axis next to each other:
xAxis: [{
width: 200,
left: 50
}, {
width: 200,
left: 300,
linkedTo: 0,
offset: 0
}],
Workaround for a tooltip position (shared tooltip does not seem to work correctly)
tooltip: {
shared: false,
shape: 'rect',
positioner: function(w, h, p) {
return {
x: p.plotX + this.chart.hoverSeries.xAxis.left - w / 2,
y: p.plotY
}
}
},
example: http://jsfiddle.net/fqc5np5g/

Lines, circles and other shapes?

Is it possible to draw lines, circles and other shapes with pdfmake? If yes, is there a documentation or are there any samples? I would like to replace jsPDF with pdfmake.
Yes, its possible. pdfmake calls them vectors. See
pdfMake Vector examples for more possibilities.
An example for drawing a line followed by a polygon:
{
canvas:
[
{
type: 'line',
x1: 40, y1: 60,
x2: 260, y2: 60,
lineWidth: 3
},
{
type: 'polyline',
lineWidth: 3,
closePath: true,
points: [{ x: 10, y: 10}, { x: 35, y: 40 }, { x: 100, y: 40 }, { x: 125, y:10 }]
}
]
}
I answered an issue in pdfMake at GitHub like this:
Create a table with layout headeronly you must define an empty body, otherwise the line would not appear:
var dd = {
content: [
{
table : {
headerRows : 1,
widths: [200],
body : [
[''],
['']
]
},
layout : 'headerLineOnly'
}
] }
The width defines the length of the line
canvas: [
{
type: 'rect',
x: 198,
y: -186,
w: 198,
h: 188,
r: 8,
lineWidth: 4,
lineColor: '#276fb8',
},
]
As far as I know, pdfmake does not provide an drawing API. Despite this, pdfmake provides you some methods to insert images at your pdf.
Best regards!

Highcharts bubble chart dataLabels overlapping

As shown in the picture (which is not the same code as the fiddle, but exhibits the problem), with Highcharts new bubble charts it seems like dataLabels like to sit on top of each other. Is there an easy workaround for this? I'd be happy to manually change the z-index on a per label basis, but this doesn't seem to work for bubble charts. Here's some sample code that fails to work as expected (try it in a fiddle):
series: [{
data: [{
x: 99,
y: 36,
z: 50
}, {
x: 99,
y: 74,
z: 55,
dataLabels: {
zIndex:15,
enabled: true,
}
}, {
x: 99,
y: 76,
z: 55,
dataLabels: {
zIndex: 1,
enabled: true
}
}
]
}],
You can set useHTML: true flag, and then set z-index: x property for dataLabels, see: http://jsfiddle.net/ZLmU8/4/
Apparently there is a labelrank property on the Highcharts point objects that can be used to dictate which point labels are on top. It can be used when you're creating your data like this:
data: [{
x: 1, y: 1, labelrank: 1, name: 'A'
},{
x: 1, y: 1, labelrank: 2, name: 'B'
}]
Or it can be updated on an individual point to bring that point's dataLabel to the front by doing something like this: chart.series[0].points[0].update({labelrank: 3});
I had a similar issue and created this question on SO that just was answered.
Edit
They have added info regarding series.data.labelrank to their docs as well: http://api.highcharts.com/highcharts#series.data.labelrank

Resources