How to invert leaflet polyline arrow auto resize on Zoom? - leaflet

I want my Leaflet polyline arrow to increases it's size on Zoom In and decreases it on Zoom Out.
But by it's pattern what happens is the opposite of that. Is the a way to reverse it?
Here a complete exemple: https://github.com/bbecquet/Leaflet.PolylineDecorator
function addLine(map, iniCoord, endCoord, desc, color, lineWeight, onClick) {
var polyline = L.polyline([coordIni, coordFim], {
color: color,
offset: 0,
weight: lineWeight
});
polyline.addTo(elements);
L.polylineDecorator(polyline, {
patterns: [{
offset: '100%',
symbol: L.Symbol.arrowHead({
offset: 20,
iconSize: 3,
polygon: false,
pathOptions: {
stroke: true,
color: color,
weight: 3
}
})
}]
}).addTo(elements);
polyline.on('click', onClick);
}

I've found the solution:
var map = L.map('map');
**var arrowSize = 30;**
L.tileLayer.provider('OpenStreetMap.Mapnik').addTo(map);
elements = L.layerGroup().addTo(map);
map.on('zoomend', function() {
var currentZoom = map.getZoom();
**arrowSize = 30/((20 - currentZoom )*2);**
elements.clearLayers();
});
function addLine(map, iniCoord, endCoord, desc, color, onClick) {
var polyline = L.polyline([coordIni, coordFim], {
color: color,
offset: 0,
weight: 1.5
});
polyline.addTo(elements);
L.polylineDecorator(polyline, {
patterns: [{
offset: '100%',
symbol: L.Symbol.arrowHead({
offset: 20,
**pixelSize: arrowSize,**
polygon: false,
pathOptions: {
stroke: true,
color: color,
}
})
}]
}).addTo(elements);
polyline.on('click', onClick);
}

Related

How to create a single progress line using Apache eCharts?

How do I create a single progress line using Apache eCharts?
Here is in an image example:
The green line should change depending on it's value, for example:
When the value is 10 there should only be a small green line.
When the value is 50 the green should fill half the line, and grey the other half.
When the value is 100 it should be all green.
The green line should also animate on load.
It should have rounded end caps.
And it should resize based on the width of the container.
Is this simple type of progress line possible in Apache eCharts?
Here you go : (my echarts sandbox)
var myChart = echarts.init(document.getElementById('main'));
var progressLineLength = 500;
var maxValue = 100;
var value = 70;
option = {
graphic: {
elements: [
{
type: 'group',
left: 'center',
top: 'center',
children: [
{
type: 'rect',
shape: {
x:0,
y:0,
width: progressLineLength,
height:10,
},
style: {
fill: '#E5E5E5'
}
},
{
type: 'rect',
shape: {
x:0,
y:0,
width: progressLineLength*value/maxValue,
height:10,
},
style: {
fill: '#3874CB'
},
keyframeAnimation: {
duration: 1000,
loop: false,
keyframes: [
{
percent: 0,
scaleX: 0,
},
{
percent: 1,
scaleX: 1,
}
]
}
}
]
}
]
}
};
myChart.setOption(option)
<html>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.3.2/echarts.min.js"></script>
<div id="main" style="width: 600px; height:200px;"></div>
</body>
</html>

Apache ECharts Gauge Gradient Style

I am trying to get something like this, where the style of the chart goes from a color on the min value to a color on the max value, and the progress value is in between.
I have this code:
option = {
tooltip: {
formatter: '{a} <br/>{b} : {c}%'
},
series: [{
name: 'Pressure',
type: 'gauge',
max: 40,
min: -10,
startAngle: 180,
endAngle: 0,
progress: {
show: true,
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 1,
x2: 1,
y2: 1,
colorStops: [{
offset: 0,
color: "blue"
}, {
offset: 0.25,
color: "blue"
}, {
offset: 0.5,
color: "green"
}, {
offset: 0.75,
color: "orange"
}, {
offset: 1,
color: "red"
}],
global: false // default is false
}
}
},
pointer: {
show: false
},
detail: {
valueAnimation: true,
formatter: '{value}'
},
data: [{
// name of date item
name: 'data1',
// value of date item is 8
value: 10,
},
// {
// name: 'data2',
// value: 40,
// // user-defined label format that only useful for this data item
// label: {},
// // user-defined special itemStyle that only useful for this data item
// itemStyle:{},
// anchor: {
// show: false
// },
// progress: {
// itemStyle: {
// color: 'black'
// }
// },
// title: {
// show: false
// },
// detail: {
// show: false
// },
// }
]
}]
};
Which gives the close to what I want but not really as you can see the range of colors apply up to the current value. To test this paste the code in here:
https://echarts.apache.org/examples/en/editor.html?c=gauge-simple
The result:
Another solution is to draw the entire axis line with this gradient color and cover the right side after the progress value but not sure how to do this.

chart.js 3.7.1 where to go with my plugins?

I switched from chart.js 2.9.3 to 3.7.1 and some options do not work anymore. If I see it right the options like "Legend" and also "tooltips" went to plugin under "options"?
But it does not work for me. I want to hide the Legend and customize the tooltips.
Where do the plugins go? Any help would be great.
Thank you,
Michael
const titleTooltip_diagramm_fokus = (tooltipItems) => {return "Betroffen";};
const labelTooltip_diagramm_fokus = (tooltipItems) => {return "Tooltip";};
const data_diagramm_fokus = {
datasets: [{
label: ["Positive Value"],
backgroundColor: "rgba(255,0,0,0.2)",
borderColor: "#000",
data: [{
x: 10,
y: 9,
r: 10
}]
},{
label: ["Negative Value"],
backgroundColor: "rgba(255,0,0,0.2)",
borderColor: "#000",
data: [{
x: -5,
y: -5,
r: 5
}]
},{
label: ["Beteiligte / Rollen 3"],
backgroundColor: "rgba(255,0,0,0.2)",
borderColor: "#000",
data: [{
x: -10,
y: -9,
r: 6
}]
},
]};
const options_diagramm_fokus = {
responsive: true,
maintainAspectRatio: true,
title: {
display: false,
text: "Identifiziere die größten fokus"
},
scales: {
yAxes: [{
ticks: {
beginAtZero: false,
max: 10,
min: -10
},
scaleLabel: {
display: true,
labelString: "schwacher Einfluss / starker Einfluss"
}
}],
xAxes: [{
ticks: {
beginAtZero: false,
max: 10,
min: -10
},
scaleLabel: {
display: true,
labelString: "starke Unterstützung / starker Zweifel"
}
}]
},
plugins:{
legend: {
display: false
},
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
var rLabel = (data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].r - 2);
var label = data.datasets[tooltipItem.datasetIndex].label || "";
if (label) {
label += ": ";
}
label += "(" + tooltipItem.xLabel + " / ";
label += tooltipItem.yLabel + ") | ";
label += "Betroffenheit: " + rLabel;
return label;
}
}
}
}
};
const plugin_diagramm_fokus = {
id: "plugin_diagramm_fokus",
beforeDraw(chart, args, options) {
const {ctx, chartArea: {left, top, right, bottom}, scales: {x, y}} = chart;
const midX = x.getPixelForValue(0);
const midY = y.getPixelForValue(0);
ctx.save();
ctx.fillStyle = options.topLeft;
ctx.fillRect(left, top, midX - left, midY - top);
ctx.fillStyle = options.topRight;
ctx.fillRect(midX, top, right - midX, midY - top);
ctx.fillStyle = options.bottomRight;
ctx.fillRect(midX, midY, right - midX, bottom - midY);
ctx.fillStyle = options.bottomLeft;
ctx.fillRect(left, midY, midX - left, bottom - midY);
ctx.restore();
}
};
const config_diagramm_fokus = {
type: "bubble",
data: data_diagramm_fokus,
options: {
options_diagramm_fokus,
plugins: {
plugin_diagramm_fokus: {
topLeft: "#9DC3E6",
topRight: "#2E75B6",
bottomRight: "#BDD7EE",
bottomLeft: "#DEEBF7",
}
}
},
plugins: [plugin_diagramm_fokus]
};
const diagramm_fokus = new Chart(
document.getElementById("diagramm_fokus").getContext("2d"),
config_diagramm_fokus,
);
<h2>
Hello!
</h2>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<canvas id="diagramm_fokus"></canvas>
This is because your options where totally wrong, the options does not have an options object in it and a plugins object. The options object is an object with all the options in it. So if you have a custom plugin you also need to define it in there. Rest of your config is also still wrong with lot of V2 syntax like the title, and scales config. For all changes please read the migration guide
const titleTooltip_diagramm_fokus = (tooltipItems) => {
return "Betroffen";
};
const labelTooltip_diagramm_fokus = (tooltipItems) => {
return "Tooltip";
};
const data_diagramm_fokus = {
datasets: [{
label: ["Positive Value"],
backgroundColor: "rgba(255,0,0,0.2)",
borderColor: "#000",
data: [{
x: 10,
y: 9,
r: 10
}]
}, {
label: ["Negative Value"],
backgroundColor: "rgba(255,0,0,0.2)",
borderColor: "#000",
data: [{
x: -5,
y: -5,
r: 5
}]
}, {
label: ["Beteiligte / Rollen 3"],
backgroundColor: "rgba(255,0,0,0.2)",
borderColor: "#000",
data: [{
x: -10,
y: -9,
r: 6
}]
}, ]
};
const options_diagramm_fokus = {
responsive: true,
maintainAspectRatio: true,
title: {
display: false,
text: "Identifiziere die größten fokus"
},
scales: {
yAxes: [{
ticks: {
beginAtZero: false,
max: 10,
min: -10
},
scaleLabel: {
display: true,
labelString: "schwacher Einfluss / starker Einfluss"
}
}],
xAxes: [{
ticks: {
beginAtZero: false,
max: 10,
min: -10
},
scaleLabel: {
display: true,
labelString: "starke Unterstützung / starker Zweifel"
}
}]
},
plugins: {
legend: {
display: false
},
plugin_diagramm_fokus: {
topLeft: "#9DC3E6",
topRight: "#2E75B6",
bottomRight: "#BDD7EE",
bottomLeft: "#DEEBF7",
},
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
var rLabel = (data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].r - 2);
var label = data.datasets[tooltipItem.datasetIndex].label || "";
if (label) {
label += ": ";
}
label += "(" + tooltipItem.xLabel + " / ";
label += tooltipItem.yLabel + ") | ";
label += "Betroffenheit: " + rLabel;
return label;
}
}
}
}
};
const plugin_diagramm_fokus = {
id: "plugin_diagramm_fokus",
beforeDraw(chart, args, options) {
const {
ctx,
chartArea: {
left,
top,
right,
bottom
},
scales: {
x,
y
}
} = chart;
const midX = x.getPixelForValue(0);
const midY = y.getPixelForValue(0);
ctx.save();
ctx.fillStyle = options.topLeft;
ctx.fillRect(left, top, midX - left, midY - top);
ctx.fillStyle = options.topRight;
ctx.fillRect(midX, top, right - midX, midY - top);
ctx.fillStyle = options.bottomRight;
ctx.fillRect(midX, midY, right - midX, bottom - midY);
ctx.fillStyle = options.bottomLeft;
ctx.fillRect(left, midY, midX - left, bottom - midY);
ctx.restore();
}
};
const config_diagramm_fokus = {
type: "bubble",
data: data_diagramm_fokus,
options: options_diagramm_fokus,
plugins: [plugin_diagramm_fokus]
};
const diagramm_fokus = new Chart(
document.getElementById("diagramm_fokus").getContext("2d"),
config_diagramm_fokus,
);
<h2>
Hello!
</h2>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<canvas id="diagramm_fokus"></canvas>

Semi donot chart with highcharts

I have been trying to achieve a chart like below using Highcharts library.
All i have been able to achieve is this http://jsfiddle.net/HpdwR/1489/ . So is there a way i could control how much the outer circle covers and its color. Also putting a title at the center of the chart.
Here is the config i have used to draw the chart
{
chart: {
renderTo: 'container',
type: 'pie'
},
title: {
text: 'Browser market share, April, 2011'
},
yAxis: {
title: {
text: 'Total percent market share'
}
},
plotOptions: {
pie: {
shadow: false
}
},
tooltip: {
formatter: function() {
return '<b>' + this.point.name + '</b>: ' + this.y + ' %';
}
},
series: [{
name: 'Browsers',
data: [
["Chrome", 70]
],
size: '60%',
innerSize: '60%',
showInLegend: true,
dataLabels: {
enabled: false
}
}]
}
I would also like to know if there are any other js libraries that could draw the same.
Tooltip Image
You can use solid-gauge type of chart with circle background (instead of default arc).
pane: {
center: ['50%', '50%'],
size: '100%',
startAngle: 0,
endAngle: 360,
background: {
backgroundColor: 'black',
innerRadius: '0%',
outerRadius: '80%',
shape: 'circle'
}
},
plotOptions: {
solidgauge: {
dataLabels: {
enabled: true,
y: -25,
borderWidth: 0,
useHTML: true,
format: '<div style="text-align:center"><span style="font-size:45px;color:#fff;">{y}</span><br/>' +
'<span style="font-size:12px;color:silver">%</span></div>'
}
}
},
Example:
http://jsfiddle.net/12kwyftq/1/
you can use start angle ,end angle to make it desired view
startAngle: -90,
endAngle: 90,
center: ['50%', '75%']
example fiddle

ExtJS 4.0.7 Ext.Draw drag and resize

I add Ext.draw.Component inside grid cell as column renderer:
renderer: function(_value){
var id = Ext.id();
Ext.Function.defer(function(){
Ext.create('Ext.draw.Component', {
minWidth: width,
id: 'timer-' + id,
width: (_value * width),
style: {
position: 'absolute',
'z-index': '10000000',
},
height: 17,
renderTo: id,
resizable: {
dynamic: true,
pinned: true,
handles: 'w e',
widthIncrement: width,
},
gradients: [{
id: 'grad1',
angle: 270,
stops: {
0: {
color: '#6594cf'
},
1: {
color: '#c6d8ed'
},
99: {
color: '#5f96db'
},
100: {
color: '#6594cf'
}
}
}],
items: [{
type: 'rect',
fill: 'url(#grad1)',
width: '100%',
height: '100%',
x: 0,
y: 0
}],
draggable: {
constrain: false,
},
listeners: {
}
});
}, 25);
return '<div id="' + id + '" style="width:1000px;" class="timers" />';
}
I need to know, how to drag this draw component only by x-axis. And I need name of listeners, whitch called on drag and on resize.
There is listner resize, but funciton return only new width and height (or I dont know some thing), I need to know, to whitch resizable handle was user pooled - left or right?