How can I show fraction number use Konva.Text - konvajs

I want to show a fraction number (e.g. 2ΒΌ) in canvas using Konva.Text?

You can use just that Unicode as text:
const shape = new Konva.Text({
x: 10,
y: 10,
text: '2ΒΌ',
});
layer.add(shape);
Or you can make your own solution. Basically, it is just two numbers with a line.

Related

Konva Text : While using emoji in text, it renders as a line text instead of a filled emoji

let complexText = new Konva.Text({
x: 0,
y: 0,
text: "πŸ”‘ hello World πŸ€—",
fontSize: 12,
fill: "#003049",
width: stage.width() - 10,
padding: 5,
align: "center",Received output
});
Expected Output:πŸ”‘ hello World πŸ€—
Emoji's are not available in all fonts. Look on the web for lists of emoji fonts such as: https://typography.guru/list/topic/emoji-fonts/.
But be aware that the emoji font maybe will not also provide letter characters - it might just be smileys only. You will have to create text nodes for each of the emojis and the text segments.

Disable spiral in word cloud and display all the words in highcharts

Highcharts introduced word cloud in version 6.
I was trying out and I faced few problems which were not documented
How to disable the spiral nature and layout it horizontally?
All the words are not being displayed. In the below screenshot, there are exactly 500 words. But I cannot see them.
Lot's of empty space on either side.
I have exactly 500 words in this word cloud. With minimum weight as 5 and adding one to each additional word. So weights ranges from 5 to 505.
I have tried doing this, but no use.
Highcharts.seriesTypes.wordcloud.prototype.deriveFontSize = function(relativeWeight) {
var maxFontSize = 48;
// Will return a fontSize between 0px and 25px.
let size = Math.floor(maxFontSize * relativeWeight);
return size < 8 ? 8 : size;
};
I have set the width to 100% but it is still not occupying the whole area
Updated Fiddle link
UPDATE
I disabled the spiral nature by writing my own placement strategy like below. Just a copy paste of Highcharts original example and disabling rotation
var getRandomPosition = function getRandomPosition(size) {
return Math.round((size * (Math.random() + 0.5)) / 2);
};
var randomPlacement = function randomPlacement(point, options) {
var field = options.field,
r = options.rotation;
return {
x: getRandomPosition(field.width) - (field.width / 2),
y: getRandomPosition(field.height) - (field.height / 2),
rotation: 0
};
}
Highcharts.seriesTypes.wordcloud.prototype.placementStrategy.randomHorizontal = randomPlacement;
I also set the margins. But it did not help
marginRight: 0,
marginLeft: 0
marginBottom: 0
Addressing to second and third
Second there are all words in the chart but some are in very small size difficult to see. Here I use deriveFont
Third you can use chart.margin to reduce space outer edge of the chart and the plot area
This demo shows how to deal with second and third
/*Object.keys(data).map(function(key) {
data[key].name=key
});// just for demo to show 500 words populating*/
Highcharts.seriesTypes.wordcloud.prototype.deriveFontSize = function(relativeWeight) {
var maxFontSize =10;
// Will return a fontSize between 0px and 25px.
let size = Math.floor(maxFontSize * relativeWeight);
return size < 8 ? 15 : size; //sets min size to be 15 if less than 8
};
Highcharts.chart('container', {
chart: {
"type": "wordcloud",
margin: [20, 0, 0, 0]
},
"series": [{
"data": data,
"placementStrategy": 'random'
}],
"title": {
"text": "WORD CLOUD"
}
});
Fiddle demo
Update
It is not showing all 500 words. It will show all words only when font size is very small.
Workaround for reducing the spaces on both sides of the plot (in this particular case):
You can use negative margins:
marginRight: -300,
marginLeft: -300
Live demo: http://jsfiddle.net/kkulig/eyuvcpLe/
The latest release from highcharts has fixed my issue. But there are still other issues in the issue tracker opened by me in the highcharts.
Track it here
https://github.com/highcharts/highcharts/issues/7241

How to plot the X axis data point for uneven tick interval at in Highcharts

I am having a unequal data values in X axis the data point is plotted in the center of the tick interval, kindly see the fiddle link http://jsfiddle.net/mailsakthi/w4oyx8Ln/3/. Please see the 3rd point of the black line (9.4, 1.879) inspite of using the x-axis unequal interval code
tickPositioner: function() {
var tickPositions = [];
Highcharts.each(this.series[0].options.data, function(p) {
tickPositions.push(p[0]);
});
return tickPositions;
}
Just because you are using numbers in your xAxis.categories array does not mean that they are treated as numbers. They are treated as literals that are separated by 1 index value from each other. From the documentation:
If categories are present for the xAxis, names are used instead of
numbers for that axis
If you want the xAxis to be numeric then you need to set your x values to be numbers in your data points.
Setting up x/y values in your points:
data: [{
x: 0,
y: 7.7918348462852,
color: 'RGBA(128,128,128,0)',
segmentcolor: 'RGBA(128,128,128,0)'
}, {
x: 0.5,
y: null,
color: 'RGBA(128,128,128,0)',
segmentcolor: 'RGBA(128,128,128,0)'
}, {
x: 1.8790271054655,
y: 7.6224396161563,
color: 'RGBA(128,128,128,0)',
segmentcolor: 'RGBA(128,128,128,0)'
}]
Remove categories from you xAxis properties.
Live sample of a smaller set of your data.

Highstock/Highcharts - yAxis Label top

Using Highstock or Highcharts, I want my yAxis label on the top. What I don't want, is a varying margin between the left border of the chart and the beginning of the grid lines.
If you take a look at the following fiddle:
JSFiddle
Relevant part is:
yAxis: {
title: {
align: 'high',
offset: 0,
text: 'Rainfall (mm)',
rotation: 0,
y: -10
}
}
This is almost correct, but the offset margin is taken from the label width. If I set offset: -41 instead, it looks exactly right. The problem is, that the -41 is due to the rendered length of the text. If I change the text to something of a different length, the label is positioned wrongly again.
Is there any possibility to make sure, that the positions are always "correct" in my above definition of correct, regardless of the text length?
Screenshot, left part is wrong, right part is correct:
I think that you can use text-anchor property to style your title. Here you can find more information about text-anchor property: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor
title: {
align: 'high',
text: 'Rainfall (mm)',
style: {
'text-anchor': 'start'
},
rotation: 0,
y: -10,
x: -25
},
I think that you need to use chart.marginLeft parameter as well. It will give you a chance to set specific left margin for your chart. Here you can find information about it.
http://api.highcharts.com/highcharts#chart.marginLeft
You may also use xAxis.labels.reserveSpace parameter to turn off reserving space for labels: http://api.highcharts.com/highcharts#xAxis.labels.reserveSpace
Here you can find live example how your chart can work with this options:
http://jsfiddle.net/Ljwp7694/
Kind regards,

Set position for each flag in highstock

I'm trying to change the position of each flag in a chart and I'm using highstock.
I add each flag like this:
{
x: time,
shape: 'url(images/indicators/down_fractal.png)',
y:value,
title: ' ',
text: 'Fractal: ' + value
};
And there is my serie config:
seriesConf : {
id: this.uniqueID,
name: this.toString(),
data: this.indicatorData,
type: 'flags',
onSeries: this.options.onSeriesID, //Series ID on which this flags will be rendered
height: 10,
width: 10,
//y: 100,
//turboThreshold: 0
}
The y value is suppose to set the position of flag but its not working?is it even possible to define each flag position?
In this sample you change the y value and nothing happens.
The main i idea is to create a chart like this:
Flag series is rendered directly above the series, there is no y option for point (see API).
I think you want to use simple scatter series with markers, take a look: http://jsfiddle.net/ujgLzkq9/1/
Or use two flag series (one above, and second one below the line), using series.y option.

Resources