JQuery UI nonlinear slider - jquery-ui

I need a slider to let the user select a weight.
$( "#slider" ).slider({
value: 15,
slide: function( event, ui ) {
$('#weight').text(ui.value);
}
});
But the values should be nonlinear: That means a 'normal' behaviour for values from 10 to 50 (increasing steps of 1).
Then for example: If the values are getting bigger they should increase in steps of 10. If the user selects lower values it should be more precise: values 3 to 10 (increasing steps of 0.5), below 3 -> increasing steps 0.1.
My attempt would be to use an own array for the data:
myData = [ 0.4, 0.45, 0.5, 0.55, 0.65, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 6, 7, 8, 9, 10,11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 40, 50, 60, 70 ];
$( "#slider" ).slider({
min: 0,
max: myData.length - 1,
step: 1,
slide: function( event, ui ) {
$('#weight').text(ui.value);
},
create: function() {
$(this).slider('values',0,0);
$(this).slider('values',1,myData.length - 1);
}
});
But this doesn't work. Is there a smarter solution?

myData = [ 0.4, 0.45, 0.5, 0.55, 0.65, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 6, 7, 8, 9, 10,11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 40, 50, 60, 70 ];
$( "#slider" ).slider({
min: 0,
max: myData.length - 1,
step: 1,
slide: function( event, ui ) {
$('#weight).text(myData[ui.value]);
}
});

Related

Logitech Lua help needed

software = Logitech G hub
UPDATE
Okay! Thanks to some help this is where I'm at, Everything's working very nicely and as it should but now I face a new task and that is adding variations of each table for the slight changes to recoil when using scopes.
I could simple add more gun modes and make the changes required but I'd really like to make a way of using a key to toggle whether they are used or not, An idea I have floating around my head is for F9 and F10 to toggle between the scopes and when the toggle is off it will work with the code I already have. however I'm not sure this is possible, to my understanding I could use the lock keys (capslock, scrolllock, numlock) to make this work. initially I had the idea to have a toggle key that modifies the timing of the recoil sequence but unfortunately this is not an accurate solution.
What I'd like to do now is create 2/3 toggles that allow gun modes to switch between variable tables without having to add more guns
any help is greatly appreciated and that goes for any help I've received so far too
thanks
---GUN MODES---
local GUN1_Mouse = 8
local GUN1_Keyboard = nil
local GUN2_Mouse = 7
local GUN2_Keyboard = nil
local GUN3_Mouse = 9
local GUN3_Keyboard = nil
local GUN4_Mouse = nil
local GUN4_Keyboard = nil
local GUN5_Mouse = 5
local GUN5_Keyboard = nil
local GUN6_Mouse = nil
local CUSTOM_Keyboard = nil
local GUN7_Mouse = 4
local GUN7_Keyboard = nil
---RECOIL TABLES---
local recoil_table = {}
-------------------------------------
recoil_table["GUN1"] = {
0, 6, 133,
-1, 6, 133,
-1, 6, 133,
-4, 6, 133,
-3, 6, 133,
-3, 6, 133,
-3, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
}
recoil_table["GUN1_crouch"] = {
0, 3, 133,
-1, 3, 133,
-1, 3, 133,
-1, 3, 133,
-1, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-3, 3, 133,
-3, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
}
-------------------------------------
recoil_table["GUN2"] = {
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
}
recoil_table["GUN2_crouch"] = {
0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
}
-------------------------------------
recoil_table["GUN3"] = {
0, 3, 133,
-1, 3, 133,
-1, 3, 133,
-1, 3, 133,
-1, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-3, 3, 133,
-3, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
}
recoil_table["GUN3_crouch"] = {
0, 2.5, 125,
0, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
0.7, 2.5, 125,
0.7, 2.5, 125,
0.7, 2.5, 125,
0.8, 2.5, 125,
0.9, 2.5, 125,
1, 2.5, 125,
0.7, 2.5, 125,
0.7, 2.5, 125,
0.7, 2.5, 125,
0.8, 2.5, 125,
0.9, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
}
-------------------------------------
recoil_table["GUN4"] = {
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
}
recoil_table["GUN4_crouch"] = {
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
}
-------------------------------------
recoil_table["GUN5"] = {
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
}
recoil_table["GUN5_crouch"] = {
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
}
-------------------------------------
recoil_table["GUN6"] = {
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
}
recoil_table["GUN6_crouch"] = {
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
}
-------------------------------------
recoil_table["GUN7"] = {
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
}
-------------------------------------
recoil_table["GUN7_crouch"] = {
0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
}
---------------------------------------------------
local weapon
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN1_Mouse) or (event == "G_PRESSED" and arg == GUN1_Keyboard) then
weapon = weapon ~= "GUN1" and "GUN1"
if not weapon then
OutputLogMessage("OFF-GUN1\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN1\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN2_Mouse) or (event == "G_PRESSED" and arg == GUN2_Keyboard) then
weapon = weapon ~= "GUN2" and "GUN2"
if not weapon then
OutputLogMessage("OFF-GUN2\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN2\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN3_Mouse) or (event == "G_PRESSED" and arg == GUN3_Keyboard) then
weapon = weapon ~= "GUN3" and "GUN3"
if not weapon then
OutputLogMessage("OFF-GUN3\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN3\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN4_Mouse) or (event == "G_PRESSED" and arg == GUN4_Keyboard) then
weapon = weapon ~= "GUN4" and "GUN4"
if not weapon then
OutputLogMessage("OFF-GUN4\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN4\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN5_Mouse) or (event == "G_PRESSED" and arg == GUN5_Keyboard) then
weapon = weapon ~= "GUN5" and "GUN5"
if not weapon then
OutputLogMessage("OFF-GUN5\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN5\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN6_Mouse) or (event == "G_PRESSED" and arg == GUN6_Keyboard) then
weapon = weapon ~= "GUN6" and "GUN6"
if not weapon then
OutputLogMessage("OFF-GUN6\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN6\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN7_Mouse) or (event == "G_PRESSED" and arg == GUN7_Keyboard) then
weapon = weapon ~= "GUN7" and "GUN7"
if not weapon then
OutputLogMessage("OFF-GUN7\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN7\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
---------------------------------------------------
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and weapon and IsMouseButtonPressed(3) then
local recoil_sequence = recoil_table[weapon..(IsModifierPressed("lctrl") and "_crouch" or "")] or {}
local x, y, tm = 0, 0, GetRunningTime()
for j = 3, #recoil_sequence, 3 do
local dx_10ms = recoil_sequence[j-2]
local dy_10ms = recoil_sequence[j-1]
local duration = recoil_sequence[j]
repeat
Sleep(10)
if not IsMouseButtonPressed(1) then break end
local dt = math.min(GetRunningTime() - tm, duration)
duration, tm = duration - dt, tm + dt
x, y = x + dt/10 * dx_10ms, y + dt/10 * dy_10ms
local int_x, int_y = math.floor(x), math.floor(y)
x, y = x - int_x, y - int_y
MoveMouseRelative(int_x, int_y)
until duration == 0
if not IsMouseButtonPressed(1) then break end
end
end
end
You should use function GetRunningTime() to check if it is time to change recoil direction.
---GUN MODES---
local AK47_Mouse = 8
local AK47_Keyboard = nil
------------- for adding another weapon -----------
local AnotherWeapon_Mouse = 7
local AnotherWeapon_Keyboard = nil
---------------------------------------------------
local SpeedX2Modifier_Mouse = nil
local SpeedX2Modifier_Keyboard = 1 -- key G1
local SpeedX2 = false
---RECOIL TABLES---
local recoil_table = {}
recoil_table["AK47"] = {
-- down for 1 second
0, 0.5, 1000, -- delta_x_per_10ms, delta_y_per_10ms, duration_in_ms
-- diagonal for 1 second
-2, 4, 1000,
-- it stops moving after 2 seconds (even if LMB is still pressed)
}
recoil_table["AK47_crouch"] = {
-- down forever (until LMB is released)
0, 2, math.huge, -- math.huge means "very big number of ms"
}
recoil_table["AK47_reddot"] = {
-- down forever (until LMB is released)
0, 2, math.huge, -- math.huge means "very big number of ms"
}
------------- for adding another weapon -----------
recoil_table["AnotherWeapon"] = {
-- down for 1 second
0, 0.5, 1000, -- delta_x_per_10ms, delta_y_per_10ms, duration_in_ms
-- diagonal for 1 second
-2, 4, 1000,
-- it stops moving after 2 seconds (even if LMB is still pressed)
}
recoil_table["AnotherWeapon_crouch"] = {
-- down forever (until LMB is released)
0, 2, math.huge, -- math.huge means "very big number of ms"
}
recoil_table["AnotherWeapon_reddot"] = {
-- down forever (until LMB is released)
0, 2, math.huge, -- math.huge means "very big number of ms"
}
---------------------------------------------------
local weapon
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == AK47_Mouse) or (event == "G_PRESSED" and arg == AK47_Keyboard) then
weapon = weapon ~= "AK47" and "AK47"
if not weapon then
OutputLogMessage("OFF-Macro-AK47\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-NoRecoil-AK47\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == AnotherWeapon_Mouse) or (event == "G_PRESSED" and arg == AnotherWeapon_Keyboard) then
weapon = weapon ~= "AnotherWeapon" and "AnotherWeapon"
if not weapon then
OutputLogMessage("OFF-Macro-AnotherWeapon\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-NoRecoil-AnotherWeapon\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
---------------------------------------------------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == SpeedX2Modifier_Mouse) or (event == "G_PRESSED" and arg == SpeedX2Modifier_Keyboard) then
SpeedX2 = not SpeedX2
if not SpeedX2 then
OutputLogMessage("OFF-SpeedX2\n")
else
OutputLogMessage("ON-SpeedX2\n")
end
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and weapon and IsMouseButtonPressed(3) then
local recoil_sequence = recoil_table[weapon..(
IsKeyLockOn("capslock") and "_crouch" or
IsKeyLockOn("scrolllock") and "_reddot" or "")] or {}
local x, y, tm = 0, 0, GetRunningTime()
for j = 3, #recoil_sequence, 3 do
local dx_10ms = recoil_sequence[j-2]
local dy_10ms = recoil_sequence[j-1]
if SpeedX2 then
dx_10ms = dx_10ms * 2
dy_10ms = dy_10ms * 2
end
local duration = recoil_sequence[j]
repeat
Sleep(10)
if not IsMouseButtonPressed(1) then break end
local dt = math.min(GetRunningTime() - tm, duration)
duration, tm = duration - dt, tm + dt
x, y = x + dt/10 * dx_10ms, y + dt/10 * dy_10ms
local int_x, int_y = math.floor(x), math.floor(y)
x, y = x - int_x, y - int_y
MoveMouseRelative(int_x, int_y)
until duration == 0
if not IsMouseButtonPressed(1) then break end
end
end
end

Show Series and colorAxis both in Legend

Is it possible to have both colorAxis and series in the legend? http://jsfiddle.net/6k17dojn/ i see i can only show one at a time when I toggle this setting
colorAxis: {
showInLegend: true,
}
Currently to show a basic legend with colorAxis, you need to add some code to Highcharts core. This plugin below allows you to add colorAxis to a legend if showInLegend property is set to false:
(function(H) {
H.addEvent(H.Legend, 'afterGetAllItems', function(e) {
var colorAxisItems = [],
colorAxis = this.chart.colorAxis[0],
i;
if (colorAxis && colorAxis.options) {
if (colorAxis.options.dataClasses) {
colorAxisItems = colorAxis.getDataClassLegendSymbols();
} else {
colorAxisItems.push(colorAxis);
}
}
i = colorAxisItems.length;
while (i--) {
e.allItems.unshift(colorAxisItems[i]);
}
});
}(Highcharts))
Live demo: http://jsfiddle.net/BlackLabel/hs1zeruy/
API Reference: https://api.highcharts.com/highcharts/colorAxis.showInLegend
Docs: https://www.highcharts.com/docs/extending-highcharts
It's possible, but not with the data you currently work with. A heatmap's data is a set of coordinates, but here, your two series overlap.
Your raw data is :
[
[0,0,0.2, 0.4],
[0,1,0.1, 0.5],
[0,2,0.4, 0.9],
[0,3,0.7, 0.1],
[0,4,0.3, 0.6]
]
From there, you're mapping two series: 2018, and 2019 via the seriesMapping: [{x: 0, y: 1, value: 2}, {x: 0, y: 1, value: 3}] option.
You thus end up with the following two series:
2018 2019 2019 should be
[ [ [
[0, 0, 0.2], [0, 0, 0.4], [1, 0, 0.4],
[0, 1, 0.1], [0, 1, 0.5], [1, 1, 0.5],
[0, 2, 0.4], [0, 2, 0.9], [1, 2, 0.9],
[0, 3, 0.7], [0, 3, 0.1], [1, 3, 0.1],
[0, 4, 0.3] [0, 4, 0.6] [1, 4, 0.6]
] ] ]
Notice that in both cases, the coordinates are the same, but for 2019, the x value should be 1. Since you have 0 as x coordinate for both series, they overlap.
To fix you issue, you need to change your data (or pre-process it, whatever is easier). For example:
var data = '[[0,0,0.2, 0.4],[0,1,0.1, 0.5],[0,2,0.4, 0.9],[0,3,0.7, 0.1],[0,4,0.3, 0.6]]';
var rows = JSON.parse(data);
rows = $.map(rows, function(arr){
return [[
arr[0], arr[1], arr[2], // 2018
arr[0] + 1, arr[1], arr[3], // 2019
]];
});
// and the seriesMapping changes to
data: {
rows: rows,
firstRowAsNames: false,
seriesMapping: [{x: 0, y: 1, value: 2}, {x: 3, y: 4, value: 5}]
},
You can see it in action here: http://jsfiddle.net/Metoule/qgd2ca6p/6/

How to set tooltip background as point color for split chart in Highcharts?

I am going to set tooltip background as its point color when tooltip.split is set in Highcharts.
// Create the chart
Highcharts.chart('container', {
chart: {
type: 'spline',
},
title: {
text: 'Mountain house indoor temperatures'
},
subtitle: {
text: 'Split tooltips in Highcharts makes it easier to read overlapping line series'
},
tooltip: {
split: true,
},
xAxis: {
crosshair: {
enabled: true
}
},
yAxis: {
title: {
text: 'Temperatur'
}
},
plotOptions: {
series: {
lineWidth: 1.5,
marker: {
radius: 2
},
events: {
afterAnimate() {
console.log("secondthis", this);
this.tooltipOptions.backgroundColor = this.color
}
}
}
},
data: {
columns: [
["Time", 1451616120000, 1451865660000, 1451952060000, 1452038400000, 1452124800000, 1452211200000, 1452297600000, 1452384000000, 1452470400000, 1452556800000, 1452643200000, 1452729600000, 1452816000000, 1452902400000, 1452988800000, 1453075200000, 1453161600000, 1453248000000, 1453334400000, 1453420800000, 1453507200000, 1453593600000, 1453680000000, 1453766400000, 1453852800000, 1453939200000, 1454025600000],
["Kitchen", 5, 4, 5, 9, 6, 15, 19, 14, 6, 5, 6, 6, 15, 18, 15, 6, 6, 6, 6, 6, 6, 6, 16, 10, 6, 6, 6],
["Living room", 9, 10, 16, 13, 6, 20, 24, 16, 7, 7, 6, 6, 20, 23, 18, 9, 7, 6, 6, 7, 6, 21, 20, 16, 6, 6, 6],
["Hall", 7, 7, 13, 12, 5, 17, 22, 14, 4, 5, 5, 6, 18, 21, 17, 9, 5, 6, 5, 6, 6, 18, 20, 14, 5, 5, 5],
["Bathroom", 7, 7, 13, 12, 5, 17, 22, 14, 4, 5, 5, 6, 18, 21, 17, 9, 5, 6, 5, 6, 6, 18, 20, 14, 5, 5, 5],
["Bedroom 1", 6, 19, 19, 10, 5, 15, 21, 14, 6, 6, 5, 5, 17, 21, 16, 6, 5, 5, 5, 5, 5, 17, 18, 13, 5, 5, 5],
["Bedroom 2", 7, 19, 19, 9, 5, 11, 19, 15, 6, 5, 6, 6, 16, 19, 17, 8, 9, 6, 5, 6, 5, 17, 19, 14, 6, 6, 6],
["Shed", 6, 6, 5, 5, 6, 6, 6, 5, 5, 6, 6, 5, 6, 6, 6, 6, 6, 6, null, null, 6, 6, 6, 6, 6, 6, 6]
]
}
});
#container {
max-width: 800px;
height: 400px;
margin: 1em auto;
}
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<div id="container"></div>
I tried to set on events but its not working.
How can I do that?
tooltip: {
split: true,
},
You can achieve it by wrapping Highcharts.Tooltip.prototype.renderSplit method and adding this lines of code there:
pointColor = H.charts[0].options.colors[pick(
point.colorIndex,
series.colorIndex,
'none'
)];
pointColor = pointColor ? pointColor : '#efefef';
pointColor = H.Color(pointColor);
pointColor.rgba[3] = 0.8; // opacity
And then use pointColor to set fill property for particular tooltip element:
if (!chart.styledMode) {
attribs.fill = pointColor.get('rgba');
attribs.stroke = (
options.borderColor ||
point.color ||
series.color ||
'#333333'
);
attribs['stroke-width'] = options.borderWidth;
}
Whole wrapper code:
(function(H) {
H.Tooltip.prototype.renderSplit = function(labels, points) {
var tooltip = this,
pick = H.pick,
boxes = [],
chart = this.chart,
ren = chart.renderer,
rightAligned = true,
options = this.options,
headerHeight = 0,
headerTop,
tooltipLabel = this.getLabel(),
distributionBoxTop = chart.plotTop;
// Graceful degradation for legacy formatters
if (H.isString(labels)) {
labels = [false, labels];
}
// Create the individual labels for header and points, ignore footer
labels.slice(0, points.length + 1).forEach(function(str, i) {
if (str !== false && str !== '') {
var point = points[i - 1] || {
// Item 0 is the header. Instead of this, we could also
// use the crosshair label
isHeader: true,
plotX: points[0].plotX,
plotY: chart.plotHeight
},
owner = point.series || tooltip,
tt = owner.tt,
series = point.series || {},
colorClass = 'highcharts-color-' + pick(
point.colorIndex,
series.colorIndex,
'none'
),
target,
x,
bBox,
boxWidth,
pointColor,
attribs;
// Store the tooltip referance on the series
if (!tt) {
attribs = {
padding: options.padding,
r: options.borderRadius
};
// CUSTOM COLORS //
pointColor = H.charts[0].options.colors[pick(
point.colorIndex,
series.colorIndex,
'none'
)];
pointColor = pointColor ? pointColor : '#efefef';
pointColor = H.Color(pointColor);
pointColor.rgba[3] = 0.8;
// CUSTOM COLORS //
if (!chart.styledMode) {
attribs.fill = pointColor.get('rgba');
attribs.stroke = (
options.borderColor ||
point.color ||
series.color ||
'#333333'
);
attribs['stroke-width'] = options.borderWidth;
}
owner.tt = tt = ren
.label(
null,
null,
null,
(
point.isHeader ? options.headerShape :
options.shape
) || 'callout',
null,
null,
options.useHTML
)
.addClass('highcharts-tooltip-box ' + colorClass)
.attr(attribs)
.add(tooltipLabel);
}
tt.isActive = true;
tt.attr({
text: str
});
if (!chart.styledMode) {
tt.css(options.style)
.shadow(options.shadow);
}
// Get X position now, so we can move all to the other side in
// case of overflow
bBox = tt.getBBox();
boxWidth = bBox.width + tt.strokeWidth();
if (point.isHeader) {
headerHeight = bBox.height;
if (chart.xAxis[0].opposite) {
headerTop = true;
distributionBoxTop -= headerHeight;
}
x = Math.max(
0, // No left overflow
Math.min(
point.plotX + chart.plotLeft - boxWidth / 2,
// No right overflow (#5794)
chart.chartWidth +
(
// Scrollable plot area
chart.scrollablePixels ?
chart.scrollablePixels - chart.marginRight :
0
) -
boxWidth
)
);
} else {
x = point.plotX + chart.plotLeft -
pick(options.distance, 16) - boxWidth;
}
// If overflow left, we don't use this x in the next loop
if (x < 0) {
rightAligned = false;
}
// Prepare for distribution
target = (point.series && point.series.yAxis &&
point.series.yAxis.pos) + (point.plotY || 0);
target -= distributionBoxTop;
if (point.isHeader) {
target = headerTop ?
-headerHeight :
chart.plotHeight + headerHeight;
}
boxes.push({
target: target,
rank: point.isHeader ? 1 : 0,
size: owner.tt.getBBox().height + 1,
point: point,
x: x,
tt: tt
});
}
});
// Clean previous run (for missing points)
this.cleanSplit();
if (options.positioner) {
boxes.forEach(function(box) {
var boxPosition = options.positioner.call(
tooltip,
box.tt.getBBox().width,
box.size,
box.point
);
box.x = boxPosition.x;
box.align = 0; // 0-align to the top, 1-align to the bottom
box.target = boxPosition.y;
box.rank = pick(boxPosition.rank, box.rank);
});
}
// Distribute and put in place
H.distribute(boxes, chart.plotHeight + headerHeight);
boxes.forEach(function(box) {
var point = box.point,
series = point.series;
// Put the label in place
box.tt.attr({
visibility: box.pos === undefined ? 'hidden' : 'inherit',
x: (rightAligned || point.isHeader || options.positioner ?
box.x :
point.plotX + chart.plotLeft + tooltip.distance),
y: box.pos + distributionBoxTop,
anchorX: point.isHeader ?
point.plotX + chart.plotLeft : point.plotX + series.xAxis.pos,
anchorY: point.isHeader ?
chart.plotTop + chart.plotHeight / 2 : point.plotY + series.yAxis.pos
});
});
}
})(Highcharts);
Demo:
https://jsfiddle.net/BlackLabel/rdnoq0fs/

Fill different colors in boxplot chart Highcharts

Can we fill colors like this in boxplot chart of Highcharts?
Please refer the image below:
You can calculate point color based on some algorithm, for example:
chart: {
type: 'boxplot',
events: {
load: function(){
var points = this.series[0].points,
color,
length = points.length;
Highcharts.each(points, function(point, i){
color = 'rgb(255,' + Math.floor(i * 255 / length) + ', 0)'
point.update({ fillColor: color }, false)
});
this.redraw();
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/5k8wfrgc/
Yes, its possible to control the fillColor for a boxplot.
This is a demonstration to show you:
http://jsfiddle.net/mqunbjrs/
If you take a look at the highcharts API you will see that instead of using an array with the 6 plot values, you can use an object with named values: https://api.highcharts.com/highcharts/series.boxplot.data
instead of this:
data: [
[0, 3, 0, 10, 3, 5],
[1, 7, 8, 7, 2, 9],
[2, 6, 9, 5, 1, 3]
]
You would use this:
data: [{
x: 1,
low: 4,
q1: 9,
median: 9,
q3: 1,
high: 10,
name: "Point2",
fillColor: "#00FF00"
}, {
x: 2,
low: 5,
q1: 7,
median: 3,
q3: 6,
high: 2,
name: "Point1",
fillColor: "#FF00FF"
}]

Naming a point on highcharts

I want to name a few points on my time data with irregular intervals. I am trying this as shown on fiddle by appending as
{ [Date.UTC(1970, 9, 27), 0 ] , name: 'point 1'},
but it is not working, any inputs ? I also want to have color for those points.
DEMO
You will have to pass data like:
data: [
{x:Date.UTC(1970, 11, 2), y:2,color:'red', name:'point 1'},
{x:Date.UTC(1970, 11, 3), y:3,color:'blue', name:'point 2'},
{x:Date.UTC(1970, 11, 4), y:4,color:'orange', name:'point 3'},
[Date.UTC(1970, 11, 2), 0.8 ],
[Date.UTC(1970, 11, 9), 0.6 ],
.......
...
Change from:
{ [Date.UTC(1970, 9, 27), 0 ] , name: 'point 1'},
To:
{ x: Date.UTC(1970, 9, 27), y: 0, name: 'point 1'},

Resources