Having trouble with moving and scaling svg elements with jQuery UI sliders? - jquery-ui

I have an SVG element with defined text and a path. Please see my example code.
The text works as desired, scales from the center and can be positioned accurately but I have I am having terrible trouble with the path.
When I touch the slider to move x or y the scale gets thrown off and it always scales from the top left corner. I've tried numerous examples online but I have had no luck so I cleaned up the example code.
I would like to be able scale the path from it's center and when I change it's position it doesn't affect the scale.
$( ".slider-x" ).slider({
min: -530,
max: 530,
value: 165,
slide: function(){
var x = $( ".slider-x" ).slider( "value" ),
y = $( ".slider-y" ).slider( "value" );
$('.svg-size').attr("transform","translate("+x+","+y+")");
}
});
$( ".slider-y" ).slider({
min: -250,
max: 250,
value: -50,
slide: function(){
var x = $( ".slider-x" ).slider( "value" ),
y = $( ".slider-y" ).slider( "value" );
$('.svg-size').attr("transform","translate("+x+","+y+")");
}
});
$( ".slider-scale" ).slider({
min: 1,
max: 100,
value: 40,
slide: function(){
var x = $( ".slider-x" ).slider( "value" ),
y = $( ".slider-y" ).slider( "value" );
var scale = $( ".slider-scale" ).slider( "value" );
$('.svg-size ').attr("transform","translate("+x+","+y+") scale(" + scale/100 + ")");
}
});
$( ".slider-scale-title-text" ).slider({
min: 1,
max: 100,
value: 40,
slide: function(){
var scale = $( ".slider-scale-title-text" ).slider( "value" );
$('.svg-business-title').css("font-size", scale+ "px");
}
});
$( ".slider-text-x" ).slider({
min: -100,
max: 635,
value: 250,
slide: function(){
var x = $( ".slider-text-x" ).slider( "value" ),
y = $( ".slider-text-y" ).slider( "value" );
$('.title-text').attr("x",x);
}
});
$( ".slider-text-y" ).slider({
min: 0,
max: 210,
value: 150,
slide: function(){
var x = $( ".slider-text-x" ).slider( "value" ),
y = $( ".slider-text-y" ).slider( "value" );
$('.title-text').attr("y",y);
}
});
h3 {
font-family: verdana;
}
.svg-business-title {
fill: brown;
stroke-width: 4;
}
.svg-strap-line {
fill: red;
stroke-width: 4;
}
.svg-custom-logo-wrapper {
fill: #94d31b;
position:absolute;
left:0; top:0; width:100%; height:100%;
}
.svg-wrapper {
width: 100%;
position:relative;
height:180px;
}
.svg-container {
max-width: 535px;
margin: 0 auto;
}
.accent-colour-1 {
fill: red;
}
.accent-colour-2 {
fill: green;
}
.svg-size{
/* transform: scale(0.2);
-ms-transform: scale(0.2);
-webkit-transform: scale(0.2); */
/* transform-origin: 270px 5px; */
}
.slider-controls, .slider-scale-title-text {
max-width: 540px;
}
.slider, input {
margin: 10px 0 10px 10px;
}
button {
margin: 5px 0 0 0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="svg-container">
<div class="svg-wrapper">
<svg data-logoid="123" width="535" height="180" viewBox="0 0 535 180" class="svg-custom-logo-wrapper" xmlns:xlink="http://www.w3.org/1999/xlink"> <rect width="535" height="180" style="fill:none;stroke-width:1;stroke:rgb(0,0,0)"/>
<g class="svg-size" transform="translate (165,-50) scale(0.4)"><path class="accent-colour-1 path-1" d="m 255,108 -97,97 -27,-27 -73,72 19,21 54,-54 106,107 -25,25 66,-26 105,-106 46,46 29,-11 -75,-74 -29,29 z m 0,40 79,79 -77,77 -79,-79 z m -16,63 h 14 v 14 h -14 z m 22,-22 h 14 v 14 h -14 z m 109,80 h 11 v 11 h -11 z m 18,-18 h 11 v 11 h -11 z m -278,43 h 16 v 15 h -16 z m 25,-25 h 16 v 15 h -16 z"></path></g>
<g class="svg-size" transform="translate (165,-50) scale(0.4)"><path class="accent-colour-2 path-2" d="M 164,381 48,259 27,281 160,404 485,254 Z M 388,269 h 11 v 11 h -11 z m -18,-18 h 11 v 11 h -11 z m -235,43 h 16 v 15 h -16 z m -25,-25 h 16 v 15 h -16 z m 151,-58 h 14 v 14 h -14 z m -22,-22 h 14 v 14 h -14 z"></path></g>
<text text-anchor="middle" class="title-text svg-business-title" transform="scale(1)" x="250" y="150" font-size="40">Title Text Here</text>
</svg>
</div>
</div>
<div class="slider-controls">
<p>LOGO</p>
X<div class="slider slider-x"></div>
Y<div class="slider slider-y"></div>
Scale<div class="slider slider-scale"></div>
</div>
<div class="slider-controls">
<p>Text</p>
X<div class="slider slider-text-x"></div>
Y<div class="slider slider-text-y"></div>
Scale<div class="slider slider-scale-title-text">
</div>
</div>

You were using one transform attribute for three independent operations, in fact overwriting values that you would need to maintain. In addition, transform="scale()" always scales around the origin of the local coordinate system. So to scale the paths in place, they must be centered at x = y = 0.
The steps to take to rectify the situations in a maintainable way:
Distribute translating and scaling the paths to two enclosing groups, the outer one being the translation (.svg-position), the inner one the scale (.svg-size).
Determine the center of the paths:
document.querySelector('.svg-size').getBBox()
// returns { x: 27, y: 108, width: 458, height: 296 }
// => center at 256, 256
introduce a inner group that moves the paths to the origin: translate(-256, -256)
Add 256 * 0.4 = 102 (rounded) to the starting translation to get the paths back to their initial position.
adjust the scale values accordingly.
$( ".slider-x" ).slider({
min: -430,
max: 630,
value: 267,
slide: function(){
var x = $( ".slider-x" ).slider( "value" ),
y = $( ".slider-y" ).slider( "value" );
$('.svg-position').attr("transform","translate("+x+","+y+")");
}
});
$( ".slider-y" ).slider({
min: -150,
max: 350,
value: 52,
slide: function(){
var x = $( ".slider-x" ).slider( "value" ),
y = $( ".slider-y" ).slider( "value" );
$('.svg-position').attr("transform","translate("+x+","+y+")");
}
});
$( ".slider-scale" ).slider({
min: 1,
max: 100,
value: 40,
slide: function(){
var x = $( ".slider-x" ).slider( "value" ),
y = $( ".slider-y" ).slider( "value" );
var scale = $( ".slider-scale" ).slider( "value" );
$('.svg-size ').attr("transform","scale(" + scale/100 + ")");
}
});
$( ".slider-scale-title-text" ).slider({
min: 1,
max: 100,
value: 40,
slide: function(){
var scale = $( ".slider-scale-title-text" ).slider( "value" );
$('.svg-business-title').css("font-size", scale+ "px");
}
});
$( ".slider-text-x" ).slider({
min: -100,
max: 635,
value: 250,
slide: function(){
var x = $( ".slider-text-x" ).slider( "value" ),
y = $( ".slider-text-y" ).slider( "value" );
$('.title-text').attr("x",x);
}
});
$( ".slider-text-y" ).slider({
min: 0,
max: 210,
value: 150,
slide: function(){
var x = $( ".slider-text-x" ).slider( "value" ),
y = $( ".slider-text-y" ).slider( "value" );
$('.title-text').attr("y",y);
}
});
h3 {
font-family: verdana;
}
.svg-business-title {
fill: brown;
stroke-width: 4;
}
.svg-strap-line {
fill: red;
stroke-width: 4;
}
.svg-custom-logo-wrapper {
fill: #94d31b;
position:absolute;
left:0; top:0; width:100%; height:100%;
}
.svg-wrapper {
width: 100%;
position:relative;
height:180px;
}
.svg-container {
max-width: 535px;
margin: 0 auto;
}
.accent-colour-1 {
fill: red;
}
.accent-colour-2 {
fill: green;
}
.svg-size{
/* transform: scale(0.2);
-ms-transform: scale(0.2);
-webkit-transform: scale(0.2); */
/* transform-origin: 270px 5px; */
}
.slider-controls, .slider-scale-title-text {
max-width: 540px;
}
.slider, input {
margin: 10px 0 10px 10px;
}
button {
margin: 5px 0 0 0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="svg-container">
<div class="svg-wrapper">
<svg data-logoid="123" width="535" height="180" viewBox="0 0 535 180" class="svg-custom-logo-wrapper" xmlns:xlink="http://www.w3.org/1999/xlink"> <rect width="535" height="180" style="fill:none;stroke-width:1;stroke:rgb(0,0,0)"/>
<g class="svg-position" transform="translate(267,52)">
<g class="svg-size" transform="scale(0.4)">
<g transform="translate(-256 -256)">
<path class="accent-colour-1 path-1" d="m 255,108 -97,97 -27,-27 -73,72 19,21 54,-54 106,107 -25,25 66,-26 105,-106 46,46 29,-11 -75,-74 -29,29 z m 0,40 79,79 -77,77 -79,-79 z m -16,63 h 14 v 14 h -14 z m 22,-22 h 14 v 14 h -14 z m 109,80 h 11 v 11 h -11 z m 18,-18 h 11 v 11 h -11 z m -278,43 h 16 v 15 h -16 z m 25,-25 h 16 v 15 h -16 z"></path>
<path class="accent-colour-2 path-2" d="M 164,381 48,259 27,281 160,404 485,254 Z M 388,269 h 11 v 11 h -11 z m -18,-18 h 11 v 11 h -11 z m -235,43 h 16 v 15 h -16 z m -25,-25 h 16 v 15 h -16 z m 151,-58 h 14 v 14 h -14 z m -22,-22 h 14 v 14 h -14 z"></path>
</g>
</g>
</g>
<text text-anchor="middle" class="title-text svg-business-title" transform="scale(1)" x="250" y="150" font-size="40">Title Text Here</text>
</svg>
</div>
</div>
<div class="slider-controls">
<p>LOGO</p>
X<div class="slider slider-x"></div>
Y<div class="slider slider-y"></div>
Scale<div class="slider slider-scale"></div>
</div>
<div class="slider-controls">
<p>Text</p>
X<div class="slider slider-text-x"></div>
Y<div class="slider slider-text-y"></div>
Scale<div class="slider slider-scale-title-text">
</div>
</div>

Related

Trouble with jspdf script

I have added this jspdf script on my website to download pdf. However I get this error.
Uncaught TypeError: Cannot read property '1' of undefined
at f.renderParagraph (jspdf.min.js:202)
at f.setBlockBoundary (jspdf.min.js:202)
at k (jspdf.min.js:202)
at k (jspdf.min.js:202)
at k (jspdf.min.js:202)
at jspdf.min.js:202
at l (jspdf.min.js:202)
at Image.i.onerror.i.onload (jspdf.min.js:202)
This happens on certain pages while others work fine.I have added the code I am using below. I am not sure if it is anything to do with my code or the jspdf.
//Code I am using:
<script type="text/javascript">
function HTMLtoPDF(){
var pdf = new jsPDF('p', 'pt', 'letter');
source = $('#HTMLtoPDF')[0];
specialElementHandlers = {
'#bypassme': function(element, renderer){
return true
}
}
margins = {
top: 50,
left: 60,
right:60,
width: 545
};
pdf.fromHTML(
source // HTML string or DOM elem ref.
, margins.left // x coord
, margins.top // y coord
, {
'width': margins.width // max width of content on PDF
, 'elementHandlers': specialElementHandlers
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('Download.pdf');
}
)
}
</script>
<button type="button" onclick="HTMLtoPDF()" style=" height: 40px; width: 154px; background-color: #008800; color: #ffffff; font-size: 150%;">Download PDF </button>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"> </script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var str_pdf = $("#HTMLtoPDF").html();
var regex = /<br\s*[\/]?>/gi;
$("#HTMLtoPDF").html(str_pdf.replace(regex, '<p data-empty="true"><br></p>'));
});
function HTMLtoPDF(){
var pdf = new jsPDF('p', 'pt', 'a4');
source = $('#HTMLtoPDF')[0];
specialElementHandlers = {
'#bypassme': function (element, renderer) {
return true
}
};
margins = {
top: 30,
bottom: 30,
left: 40,
width: 522
};
pdf.fromHTML(
source,
margins.left,
margins.top, {
'width': margins.width,
'elementHandlers': specialElementHandlers
},
function (dispose) {
pdf.save('Download.pdf');
}, margins);
}
</script>
<!-- these js files are used for making PDF -->

How to retrieval name data for a tooltip

I can not find how to retrieve the name of the data in the series to display it in the tooltip, with this.x it works but not this.series.data.name
at the hover over the line, the name remains always 'undefined'
I looked in the documentation but I did not find the solution, that's why I post for the first time a message here, I'm a regular reader and for the first time I can not find .. thank you very much to all
Highcharts.chart('container', {
chart: {
type: 'xrange'
},
title: {
text: 'Affectation des véhicules'
},
xAxis: {
type: 'datetime',
min: Date.UTC(2019, 7, 15),
max: Date.UTC(2019, 7, 30)
},
yAxis: {
title: {
text: ''
},
categories: ['VITO 5 places blanc','VITO 5 places bleu','VITO 9 places gris','VITO 5 places gris','20 M3','SPRINTER'],
reversed: true
},
tooltip: {
formatter () {
const x1 = Highcharts.dateFormat('%d/%m/%Y', this.x)
const x2 = Highcharts.dateFormat('%d/%m/%Y', this.x2)
const chantier = this.series.data.name
const header = `<span style="font-size:10px">du ${x1} au ${x2}</span><table>`
const body = `<tr>
<td style="color:${this.series.color};padding:0">Chantier: </td>
<td style="padding:0"><b>${chantier}</b></td>
</tr>`
const footer = '</table>'
return header + body + footer
},
useHTML: true
},
series: [{
data: [{
name: 'aze',
x: Date.UTC(2019, 7, 20),
x2: Date.UTC(2019, 7, 22),
y: 5
},
{
name: 'azer',
x: Date.UTC(2019, 7, 24),
x2: Date.UTC(2019, 7, 25),
y: 2
}]
}]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/xrange.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Can you help me please ?
For series name, use: this.series.name, but for point name use: this.point.name:
tooltip: {
formatter() {
const x1 = Highcharts.dateFormat('%d/%m/%Y', this.x)
const x2 = Highcharts.dateFormat('%d/%m/%Y', this.x2)
const chantier = this.point.name
const header = `<span style="font-size:10px">du ${x1} au ${x2}</span><table>`
const body = `<tr>
<td style="color:${this.series.color};padding:0">Chantier: </td>
<td style="padding:0"><b>${chantier}</b></td>
</tr>`
const footer = '</table>'
return header + body + footer
},
useHTML: true
}
Live demo: http://jsfiddle.net/BlackLabel/u2ekp4wz/

How to set zindex in konva.js?

I have a problem with the Zindex in konva.js. After I added everything to the layer
I am trying to assign a property to a node for each element separately. But it does not work. For example
for(let i = 0; i<=this.layer['children']; i++){
this.layer['children'][i].setZIndex(someInt);
}
How can i set zindex for all elements in layer?
zIndex in Konva is just index of the element in an array of children of the parent element. So you can't set any number to it and it can not be bigger than children.length - 1.
Working snippet illustrating the getZIndex(), setZIndex(), moveUp() and moveDown() methods of the Kovajs.Shape object. See also example at Konvajs site.
Buttons allow use to move green circle up and down the z-index list by increments of 1, then also to try to move up +10 and down -100. Resulting z-index is shown in text below circles.
// Create the stage
var stage = new Konva.Stage({
container: 'container',
width: $('#container').width(),
height: $('#container').height()
});
// create the layer
var layer = new Konva.Layer();
var data = [ {x: 60, color: 'red'}, {x: 90, color: 'limegreen'}, {x: 120, color: 'gold'}]
var circles = [];
for (var i = 0; i < data.length; i = i + 1){
// create some circles
var circle = new Konva.Circle({
x: data[i].x,
y: 60,
radius: 50,
fill: data[i].color,
stroke: 'black',
strokeWidth: 2
});
layer.add(circle);
circles.push(circle);
}
stage.add(layer);
var green = circles[1];
function sayIndex(){
$('#info').html("Green zIndex=" + circles[1].getZIndex());
}
$('#greenup').on('click', function(){
green.moveUp();
sayIndex();
layer.draw();
})
$('#greendn').on('click', function(){
green.moveDown();
sayIndex();
layer.draw();
})
$('#greenup10').on('click', function(){
var ind = circles[1].getZIndex();
green.setZIndex(ind + 10);
sayIndex();
layer.draw();
})
$('#greendn100').on('click', function(){
var ind = circles[1].getZIndex();
green.setZIndex(ind - 100);
sayIndex();
layer.draw();
})
#container
{
width: 200px;
height: 150px;
border: 1px solid #666;
float: left;
}
#buttons
{
width: 200px;
height: 150px;
border: 1px solid #666;
float: left;
}
#info
{
position: absolute;
left: 20px;
top: 135px;
}
p
{
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdn.rawgit.com/konvajs/konva/1.6.5/konva.min.js"></script>
<div id="container"></div>
<div id="buttons">
<p><button id='greenup'>Move Green + 1</button></p>
<p><button id='greendn'>Move Green -1</button></p>
<p><button id='greenup10'>Move Green +10</button></p>
<p><button id='greendn100'>Move Green -100</button></p>
<span id='info'></span>
</div>
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva#2.4.2/konva.min.js"></script>
<meta charset="utf-8">
<title>Konva Shape Layering Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #F0F0F0;
}
#buttons {
position: absolute;
left: 10px;
top: 0px;
}
button {
margin-top: 10px;
display: block;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<button id="toTop">
yellow z-index -2
</button>
<button id="toBottom">
yellow -9
</button>
<button id="up">
yellow z-index 1
</button>
<button id="down">
yellow z-index -5
</button>
<button id="zIndex">
Set yellow box zIndex to 3
</button>
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height
});
var layer = new Konva.Layer();
var offsetX = 0;
var offsetY = 0;
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
var yellowBox = null;
for(var n = 0; n < 6; n++) {
// anonymous function to induce scope
(function() {
var i = n;
var box = new Konva.Rect({
x: i * 30 + 210,
y: i * 18 + 40,
width: 100,
height: 50,
fill: colors[i],
stroke: 'black',
strokeWidth: 4,
draggable: true,
name: colors[i]
});
box.on('mouseover', function() {
document.body.style.cursor = 'pointer';
});
box.on('mouseout', function() {
document.body.style.cursor = 'default';
});
if(colors[i] === 'yellow') {
yellowBox = box;
}
layer.add(box);
})();
}
stage.add(layer);
// add button event bindings
document.getElementById('toTop').addEventListener('click', function() {
yellowBox.setZIndex(-2);
layer.draw();
}, false);
document.getElementById('toBottom').addEventListener('click', function() {
yellowBox.setZIndex(-9);
layer.draw();
}, false);
document.getElementById('up').addEventListener('click', function() {
yellowBox.setZIndex(1);
layer.draw();
}, false);
document.getElementById('down').addEventListener('click', function() {
yellowBox.setZIndex(-5);
layer.draw();
}, false);
document.getElementById('zIndex').addEventListener('click', function() {
yellowBox.setZIndex(3);
layer.draw();
}, false);
</script>
</body>
</html>
Last
Fun messing with ZIndex code,
the setZIndex is all you need; It will vain the z-index inside Konva.JS
If you would prefer to be able to set the render order of nodes using arbitrary numbers (like CSS, or how it works in most game engines, etc), you can use this fork of Konva. Alternatively, you could also grab & apply just the rejected pull request for this feature if you already have a customized Konva version.
The new feature works by adding a zOrder property to all Nodes, and a special kind of group AbsoluteRenderOrderGroup that reads and understands this property for all children.

Slider on barchart

With Highcharts I realized a barchart. This one show the number of documents per year.
To select one or more dates, use the slider located below the graph.
I managed to put it in place.
However, I can not link it to the chart.
Here, if you put the first cursor on 2000 and the second on 2003, he would have the graph should shows only the dates 2000, 2001, 2002, and 2003.
Can you help me to do this please ?
Here is my HTML/PHP code :
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<div id="container"></div>
<div style="margin: 20px 0px 0px 60px">
<!--
The "oninput" attribute is automatically showing the value of the slider on load and whenever the user changes the value.
Since we are using a category x-axis, the values are between 0 and 12. For this example, I'm adding your base year (2004)
to the output value so it shows a label that's meaningful to the user. To expand this example to more years, set your max value
to the appropriate value and the base year to wherever you plan to start your chart's data.
-->
<script>
$( function() {
$( "#slider-range" ).slider({
range: true,
min: 1960,
max: 2016,
values: [ 1960, 2016 ],
slide: function( event, ui ) {
$( "#amount" ).val( ui.values[ 0 ] + " - " + ui.values[ 1 ] );
}
});
$( "#amount" ).val( $( "#slider-range" ).slider( "values", 0 ) +
" - " + $( "#slider-range" ).slider( "values", 1 ) );
} );
</script>
<p>
<label for="amount">Year(s):</label>
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-range"></div>
</div>
And here is my JS code :
$(function () {
$('#container').highcharts({
chart: {
type: 'column',
zoomType: 'x'
},
colors:[
'#d8d826'
],
legend:{
enabled:false
},
title:{
style:{
fontSize:'0px'
}
},
subtitle:{
style:{
fontSize:'0px'
}
},
xAxis: {
// NOTE: There is an interesting bug here where not all labels will be shown when the chart is redrawn.
// I'm not certain why this is occuring, and I've tried different methods to no avail. I'll check with Highcharts.
categories: ['1960','1961','1962','1963','1964','1965','1966','1967','1968','1969','1970','1971','1972','1973','1974','1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016'],
tickmarkPlacement: 'on', tickInterval: 1,
minRange: 1 // set this to allow up to one year to be viewed
},
yAxis: {
min: 15,
title: {
text: 'Number',
style:{
fontSize:'0px'
}
}
},
tooltip: {
shared: false,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'data by year',
data: [49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,83.6,40.9,69.9,83,28.9,40.9,81.6,24.9,46.4,49.9,83.6,48.9,69.1,50]
}]
});
});
You could see the result on : https://jsfiddle.net/uvat8u05/20/
The simple solution for your problem is to add jQuery responsible for your slider inside load event callback function of your chart, and use setExtremes for setting new extremes on slide:
http://api.highcharts.com/highcharts#Axis.setExtremes
function(chart) {
$("#slider-range").slider({
range: true,
min: 1960,
max: 2016,
values: [1960, 2016],
slide: function(event, ui) {
$("#amount").val(ui.values[0] + " - " + ui.values[1]);
chart.xAxis[0].setExtremes(ui.values[0] - 1960, ui.values[1] - 1960)
}
});
$("#amount").val($("#slider-range").slider("values", 0) +
" - " + $("#slider-range").slider("values", 1));
}
Here you can find live example how it can work: https://jsfiddle.net/uvat8u05/22/
Regards,

jquery draggable() in FF and Opera not working properly

I have in iframe table trs which draggable and droppable(jquery). Its work in chrome and ie normally, but when I want to drag and drop in FF, i must do 2 clicks to change trs.
$(this).draggable({ helper: 'clone', iframeFix: true, cursor: "move", cursorAt: { top: 600, left: 155 } });
$(childrensDraggableZone).droppable({
accept: '.dragdrop',
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
drop: function(event, ui) {
var draggable = ui.draggable, droppable = $(this),
dragPos = draggable.position(), dropPos = droppable.position();
draggable.css({
left: dropPos.left + 'px',
top: dropPos.top + 'px'
});
droppable.css({
left: dragPos.left + 'px',
top: dragPos.top + 'px'
});
draggable.swap(droppable);
}
});

Resources