what is the problem with my left alignment? - konvajs

I use konva.js and I try to align texts with the align function but I can't do it with the left alignment (right and center works on the other hand)
my code
var text1 = new Konva.Text({
y: 26,
fontSize: 40,
text: 'ligne1',
draggable: true,
width : 550,
align: 'center',
});
layer.add(text1);
layer.draw();
Thank you

The text.align() method sets the alignment. In the snippet below I have drawn a rect around the text shape to give a visualisation of the effect.
let
// Set up a stage
stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
}),
layer = new Konva.Layer(),
rect = new Konva.Rect({
x: 0,
y: 26,
width: 550,
height: 40,
stroke: 'magenta'
}),
text1 = new Konva.Text({
y: 26,
fontSize: 40,
text: 'ligne1',
draggable: true,
width: 550,
align: 'center',
fill: 'cyan'
});
stage.add(layer);
layer.add(rect, text1);
layer.draw();
$('#left').on('click', function() {
text1.align('left');
layer.draw();
})
$('#center').on('click', function() {
text1.align('center');
layer.draw();
})
$('#right').on('click', function() {
text1.align('right');
layer.draw();
})
body {
margin: 10;
padding: 10;
overflow: hidden;
background-color: #f0f0f0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/konva#^3/konva.min.js"></script>
<p>Click a button to change alignment of the text.</p>
<button id='left'>Left</button>
<button id='center'>Center</button>
<button id='right'>Right</button>
<div id="container"></div>

Related

How to aligned symbol in highcharts js?

Now it looks like this:
should be:
legend: {
floating: true,
align: 'left',
verticalAlign: 'top',
y: 0,
x: -20,
width: 150,
itemMarginTop: 12,
itemMarginBottom: 12,
alignItem: 'center',
textAlign: '40px',
itemStyle: {
fontFamily: 'Inter',
display: 'inline-block',
verticalAlign: 'middle'
},
labelFormatter() {
return `<span style="font-size: 14px;color: #595959;font-weight: 400;">${this.name}</span><br><span style="font-size: 18px;color: #1C1C1E;font-weight: 600;">${this.y}</span>`
} }
In style options for legend .highcharts-legend-item you can change position of item, there is no directly options in Highcharts for adjust symbol position related to label. In this solution, you need to use legend.useHTML to render legend items.
.highcharts-legend-item {
top: -10px !important;
}
Demo: https://jsfiddle.net/BlackLabel/6479m1y0/

Highcharts: stacked bar charts tooltip enable shared and keep display arrow

When I enable tooltip.shared = true, The arrow will disappear like screen shot.
tooltip: {
shared: true
},
I want to keep arrow just like tooltip.shared = false
tooltip: {
shared: false
},
DEMO in here http://jsfiddle.net/puff0211/5sbfztur/
Does anyone know to accomplish this?
Thank you!
You can prevent from skipping the tooltip anchor in case tooltip is shared by wrapping move function. More about wrapping can be here: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts. Take a look at the example below.
DOCS Reference:
https://www.highcharts.com/docs/extending-highcharts/extending-highcharts
Example:
http://jsfiddle.net/u6d2bode/
You can use tooltip.formatter with some css to achieve nearly required behavior but not exactly same when shared: false .
$(document).ready(function() {
$('#container').highcharts({
chart: {
//type: 'column'
type: 'bar'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -100,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
shared: true,
useHTML: true,
backgroundColor: null,
borderWidth: 0,
formatter: function() {
//console.log(this.points)
var points = this.points;
var pointsLength = points.length;
var tooltipMarkup = pointsLength ? '<div class="callout right" >' + points[0].key + '<br/>' : '';
var index;
var y_value;
for (index = 0; index < pointsLength; index += 1) {
y_value = (points[index].y);
tooltipMarkup += '<span style="color:' + points[index].series.color + '">\u25CF</span> ' + points[index].series.name + ': <b>' + y_value + ' </b><br/>';
}
return tooltipMarkup + '</div>';
},
/*//you can use bellow code to adjust position
positioner: function(boxWidth, boxHeight, point) {
return {x:point.plotX,y:point.plotY};
}*/
},
plotOptions: {
series: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
});
div.callout {
background-color: rgba(247, 247, 247, 0.85);
background-image: -moz-linear-gradient(top, rgba(247, 247, 247, 0.85), rgba(247, 247, 247, 0.85));
position: relative;
color: #000;
padding: 5px;
border-radius: 3px;
box-shadow: 0px 0px 20px #444;
}
.callout::before {
content: "";
width: 0px;
height: 0px;
border: 0.8em solid transparent;
position: absolute;
}
.callout.right::before {
left: -20px;
top: 35%;
border-right: 10px solid rgba(247, 247, 247, 0.85);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
Fiddle demo
tooltip formatter
tooltip: {
shared: true,
useHTML: true,
backgroundColor: null,
borderWidth: 0,
formatter: function() {
var points = this.points;
var pointsLength = points.length;
var tooltipMarkup = pointsLength ? '<div class="callout right" >' + points[0].key + '<br/>' : '';
var index;
var y_value;
for (index = 0; index < pointsLength; index += 1) {
y_value = (points[index].y);
tooltipMarkup += '<span style="color:' + points[index].series.color + '">\u25CF</span> ' + points[index].series.name + ': <b>' + y_value + ' </b><br/>';
}
return tooltipMarkup + '</div>';
},
css
div.callout {
background-color: rgba(247, 247, 247, 0.85);
background-image: -moz-linear-gradient(top, rgba(247, 247, 247, 0.85), rgba(247, 247, 247, 0.85));
position: relative;
color: #000;
padding: 5px;
border-radius: 3px;
box-shadow: 0px 0px 20px #444;
}
.callout::before {
content: "";
width: 0px;
height: 0px;
border: 0.8em solid transparent;
position: absolute;
}
.callout.right::before {
left: -20px;
top: 35%;
border-right: 10px solid rgba(247, 247, 247, 0.85);
}

React Native - ios - circle with border - circle background color spilling out of circle

I'm trying to create a circle with a white background in react native and i'm having an issue where the background color of the circle is seen on the outline of the border.
Check out this playground app:
https://rnplay.org/apps/TsQ-CA
If you look closely you can see that around the circle there's a thin black line. It's like the border isn't covering the entire background.
Here's the circle style:
circle: {
borderRadius: 40,
width: 80,
height: 80,
borderWidth: 5,
borderColor: 'white',
backgroundColor: 'black'
}
P.S. this only happens on iOS
Any ideas??
Thanks!
You can add different border color to a circle. try this
container: {
width: 60,
height: 60,
borderRadius: 60 / 2,
backgroundColor: 'red',
borderColor: 'black',
borderWidth: 3
}
This looks like a bug in React Native. You can work around it by using 2 circles:
class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.outerCircle}>
<View style={styles.innerCircle} />
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
outerCircle: {
borderRadius: 40,
width: 80,
height: 80,
backgroundColor: 'white',
},
innerCircle: {
borderRadius: 35,
width: 70,
height: 70,
margin: 5,
backgroundColor: 'black'
},
});
Try setting style props as
{
overflow: 'hidden'
}
with your styling on View style.

In react native how to arrange image button

I'm new to react native.
I need to arrange 8 image button in 4 rows and 2 columns.I tried with flexDirection, but it's not work(confuse).
Actually i need to arrange my 8 image like below image in react native.(I need only 4 -rows,2 columns)
Please help me..
my code
`
container:{
backgroundColor: '#ccffcc',
flex:1,
flexDirection: ('row'),
//paddingTop: 40,
//alignItems :'center',
padding:10
},
button1:{
flex:1,
// width : 100,
// height: 100,
flexDirection:'row',
backgroundColor : '#ff9933',
//alignSelf:'flex-start',
marginTop: 70,
margin: 20,
//justifyContent:'center'
},
button2:{
//flex:1,
//flexDirection:'column',
alignSelf:'center',
//height :50,
//backgroundColor : '#ff9933',
//alignSelf:'flex-start',
margin: 20,
marginTop:-30,
//justifyContent:'center'
},
button3:{
//flex:1,
flexDirection: 'column',
// width : 100,
// height: 100,
backgroundColor : '#ff9933',
alignSelf:'flex-start',
// marginTop:100,
margin: 20,
justifyContent:'center'
},
button4:{
//flex:1,
// flexDirection: 'row',
//height :50,
//backgroundColor : '#ff9933',
alignSelf:'flex-start',
margin: 20,
// marginTop:30,
justifyContent:'center'
},
button5:{
flex:1,
flexDirection:'column',
// width : 100,
// height: 100,
backgroundColor : '#ff9933',
alignSelf:'flex-end',
//marginTop:50,
margin: 20,
justifyContent:'center'
},
button6:{
flexDirection:'column',
flex:1,
//height :50,
//backgroundColor : '#ff9933',
alignSelf:'flex-end',
margin: 20,
// marginTop:30,
justifyContent:'center'
},
button7:{
flexDirection:'column',
flex:1,
// width : 100,
// height: 100,
backgroundColor : '#ff9933',
alignSelf:'flex-end',
// marginTop:100,
margin: 20,
justifyContent:'center'
},
button8:{
flexDirection:'column',
flex:1, //height :50,
//backgroundColor : '#ff9933',
alignSelf:'flex-end',
margin: 20,
// marginTop:30,
justifyContent:'center'
},`
You can do this by calculating the width of the container, then simply dividing the width by the number of items you need per row:
Check out this example I set up, also pasted the code below.
"use strict";
var React = require("react-native");
var { AppRegistry, StyleSheet, Text, View, Dimensions, ScrollView } = React;
var width = Dimensions.get("window").width - 20;
var images = [1, 2, 3, 4, 5, 6, 7, 8];
var SampleApp = React.createClass({
render: function() {
var icons = images.map((image, i) => {
return (
<View key={i} style={styles.listItemContainer}>
<View style={styles.listItem}>
<Text style={{ backgroundColor: "transparent" }}>
Image {image}
</Text>
</View>
</View>
);
});
return (
<ScrollView style={{ flex: 1, paddingLeft: 10, paddingRight: 10 }}>
<View style={styles.container}>
<View style={styles.list}>{icons}</View>
</View>
</ScrollView>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1
},
list: {
flexDirection: "row",
flexWrap: "wrap",
flex: 1,
marginTop: 50
},
listItemContainer: {
width: width / 4,
height: width / 4
},
listItem: {
backgroundColor: "#ededed",
borderRadius: 15,
margin: 10,
flex: 1
}
});
AppRegistry.registerComponent("SampleApp", () => SampleApp);
you can use react native grid view here :
https://github.com/lucholaf/react-native-grid-view

How to draw only LAC countries map with interaction using open layers

I am trying to plot the map of Latin American countries using openlayers 3 in my asp.net mvc app.
I have geojsonobject of the countries and I tried the below code but map is not displayed..
My requirements is to only show LAC with interaction and different color filling of the different countries.
<html>
<head>
<title>Modify features test</title>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"> </script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.7.0/ol.css" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.7.0/ol.js"> </script>
<style>
.map {
background: grey;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
</div>
<script>
var styleFunction = (function() {
var styles = {};
var image = new ol.style.Circle({
radius: 5,
fill: null,
stroke: new ol.style.Stroke({color: 'orange', width: 2})
});
styles['Point'] = [new ol.style.Style({image: image})];
styles['Polygon'] = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 3
}),
fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
})
})];
styles['MultiLinestring'] = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'green',
width: 3
})
})];
styles['MultiPolygon'] = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'yellow',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(255, 255, 0, 0.1)'
})
})];
styles['default'] = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'red',
width: 3
}),
fill: new ol.style.Fill({
color: 'rgba(255, 0, 0, 0.1)'
}),
image: image
})];
return function(feature, resolution) {
return styles[feature.getGeometry().getType()];
};
})();
var source = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)
});
var layer = new ol.layer.Vector({
source: source,
style: styleFunction
});
var overlayStyle = (function() {
var styles = {};
styles['Polygon'] = [
new ol.style.Style({
fill: new ol.style.Fill({
color: [255, 255, 255, 0.5]
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: [255, 255, 255, 1],
width: 5
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: [0, 153, 255, 1],
width: 3
})
})
];
styles['MultiPolygon'] = styles['Polygon'];
styles['LineString'] = [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: [255, 255, 255, 1],
width: 5
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: [0, 153, 255, 1],
width: 3
})
})
];
styles['MultiLineString'] = styles['LineString'];
styles['Point'] = [
new ol.style.Style({
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: [0, 153, 255, 1]
}),
stroke: new ol.style.Stroke({
color: [255, 255, 255, 0.75],
width: 1.5
})
}),
zIndex: 100000
})
];
styles['MultiPoint'] = styles['Point'];
styles['GeometryCollection'] = styles['Polygon'].concat(styles['Point']);
return function(feature, resolution) {
return styles[feature.getGeometry().getType()];
};
})();
var select = new ol.interaction.Select({
style: overlayStyle
});
var modify = new ol.interaction.Modify({
features: select.getFeatures(),
style: overlayStyle
});
var map = new ol.Map({
interactions: ol.interaction.defaults().extend([select, modify]),
layers: [layer],
target: 'map',
view: new ol.View({
center: [0, 1000000],
zoom: 2
})
});
</script>
</body>
</html>
and my geojsonObject is given below only one now..
var geojsonObject = {'type':'FeatureCollection','crs': {'type':'name','properties':{'name':'EPSG:3857'}},"features":[{"type":"Feature","id":"BOL","properties":{"name":"Bolivia"},"geometry":{"type":"Polygon","coordinates":[[[-62.846468,-22.034985],[-63.986838,-21.993644],[-64.377021,-22.798091],[-64.964892,-22.075862],[-66.273339,-21.83231],[-67.106674,-22.735925],[-67.82818,-22.872919],[-68.219913,-21.494347],[-68.757167,-20.372658],[-68.442225,-19.405068],[-68.966818,-18.981683],[-69.100247,-18.260125],[-69.590424,-17.580012],[-68.959635,-16.500698],[-69.389764,-15.660129],[-69.160347,-15.323974],[-69.339535,-14.953195],[-68.948887,-14.453639],[-68.929224,-13.602684],[-68.88008,-12.899729],[-68.66508,-12.5613],[-69.529678,-10.951734],[-68.786158,-11.03638],[-68.271254,-11.014521],[-68.048192,-10.712059],[-67.173801,-10.306812],[-66.646908,-9.931331],[-65.338435,-9.761988],[-65.444837,-10.511451],[-65.321899,-10.895872],[-65.402281,-11.56627],[-64.316353,-12.461978],[-63.196499,-12.627033],[-62.80306,-13.000653],[-62.127081,-13.198781],[-61.713204,-13.489202],[-61.084121,-13.479384],[-60.503304,-13.775955],[-60.459198,-14.354007],[-60.264326,-14.645979],[-60.251149,-15.077219],[-60.542966,-15.09391],[-60.15839,-16.258284],[-58.24122,-16.299573],[-58.388058,-16.877109],[-58.280804,-17.27171],[-57.734558,-17.552468],[-57.498371,-18.174188],[-57.676009,-18.96184],[-57.949997,-19.400004],[-57.853802,-19.969995],[-58.166392,-20.176701],[-58.183471,-19.868399],[-59.115042,-19.356906],[-60.043565,-19.342747],[-61.786326,-19.633737],[-62.265961,-20.513735],[-62.291179,-21.051635], [-62.685057,-22.249029],[-62.846468,-22.034985]]]}}]};
Polygon not plotted for bolivia please help...
Projection/CRS
Your GeoJSON specifies using EPSG:3857 (crs: {'type':'name','properties':{'name':'EPSG:3857'}}), but your coordinates does not seem to be in EPSG:3857. EPSG:3857's units is meters, and coordinates such as [-62.846468,-22.034985] are less than 100 meters from the equator and the Greenwich meridian.
Your coordinates are probably in EPSG:4326 (latitude and longitude in degrees). If that's true, change the GeoJSON to reflect that (set crs: {'type':'name','properties':{'name':'EPSG:4326'}}.
With features in EPSG:4326, you also have to change the view projection to EPSG:4326 or reproject the features to EPSG:3857. EPSG:3857 is normally used for global web mapping applications.
In order to read GeoJSON in EPSG:4326 and get features in EPSG:3857, change
(new ol.format.GeoJSON()).readFeatures(geojsonObject)
to
(new ol.format.GeoJSON()).readFeatures(geojsonObject,
{'featureProjection': ol.proj.get('EPSG:3857')})
Initial center
The inital center of the map does not seem to be focused on your data. You could insert this after the map is initialized:
map.getView().fit(source.getExtent(), map.getSize())

Resources