Highchart is a common javascript library which use to display graph with many
beautiful features, however, there is a small need in use of highchart.js. It’s
about having dual yAxis, and how to balance common zero between two yAxis.
There is no built-in feature that can help you deal with this solution but
changing the min, max value via setExtremes() method.
I did write a small method which can help solve this problem, small but
achievable.
github
How to use
Given that, on the html there is a div which is used for highcharts, this div
is only for rendering graph for example $("#graph")
After include the balancezero.js, you can test by running the command on the
web console balanceZeroRoot(dom_element) or for example balanceZeroRoot($("#graph"))
By default, there is exist behavior for show and hide plots, you need to
modify those default behavior to work with balancezero.js. For each kind of
graph, there is exist option name legendItemClick for example
link
plotOptions:{// shared option on plottin the graphseries:{borderColor:'#000000',pointStart:Date.parse(data.start_date),pointEnd:Date.parse(data.end_date),pointInterval:24*3600*1000,groupPadding:0,// group for each point on the x-axisshadow:false,animation:false,events:{legendItemClick:function(){if(this.visible==true){this.setVisible(false,false);}else{this.setVisible(true,false);}balanceZeroRoot(YOUR_GRAPH_DOM_ELEMENT);returnfalse;}}}}
In addition, there is also a need to load balanceZeroRoot() right after
data loaded. There are many kind of graph, the code below is an example about
charttype
The demand to have common zero for dual yAxis has been there for 2 years
link
, however there is no good solution which fit for me even the one from the admin
of highcharts, the plugin does not work perfectly.
There is a small function you have to write to delete your history instantly. source
functionhistory_clear(){varhistory=Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsIBrowserHistory);history.removeAllPages();}interactive("history-clear","Clear the history.",history_clear);
private variables are declared with the var keyword inside the object, and
can only be accessed by private functions and privileged methods.
private functions are declared inline inside the object’s constructor (or
alternatively may be defined via var functionName=function(){...}) and may
only be called by privileged methods (including the object’s constructor).
privileged methods are declared with this.methodName=function(){...} and
may invoked by code external to the object.
public properties are declared with this.variableName and may be
read/written from outside the object.
public methods are defined by Classname.prototype.methodName =
function(){...} and may be called from outside the object.
prototype properties are defined by Classname.prototype.propertyName = someValue
static properties are defined by Classname.propertyName = someValue
varPerson=function(job,age){//job and age are public variablesthis.job=job;this.age=age;//sex is private variablevarsex='male';//printJob() is a public functionthis.printJob(){Console.log(this.job);}//sayHello() is private functionvarsayHello=function(){Console.log('Hello');}}Person.variable=123;//variable is pointing to object named PersonPerson.prototype.variable=345;//variable is pointing to the function of object named Person
#3. Inheritance
a.Inheritance object
vara={a:1};// a ---> Object.prototype ---> nullvarb=Object.create(a);// b ---> a ---> Object.prototype ---> nullconsole.log(b.a);// 1 (inherited)varc=Object.create(b);// c ---> b ---> a ---> Object.prototype ---> nullvard=Object.create(null);// d ---> nullconsole.log(d.hasOwnProperty);// undefined, because d doesn't inherit from Object.prototype
#4. Notes
Keyword this, within a function, this refers to object which call the
function.
3. Declare function to make a click action to DOM node
haivl.doClick=function(I,index){vardocument=I.buffer.document;varbutton_array=document.querySelectorAll(haivl.selector.nav);if(button_array[index]!=null){dom_node_click(button_array[index]);}else{I.minibuffer.message("Button: "+haivl.name[index]+" not found."+"length: "+button_array.length);}I.minibuffer.message(I);}haivl.doClickSeeMore=function(I){vardocument=I.buffer.document;varbutton=document.querySelector(haivl.selector.seemore);if(button!=null){dom_node_click(button);}else{I.minibuffer.message("Button: "+haivl.name[5]+" not found.");}}
4. Make those function become interactive
interactive("haivl-1","new feeds",function(I){haivl.doClick(I,0);});interactive("haivl-2","unread feeds",function(I){haivl.doClick(I,1);});interactive("haivl-3","vote feeds",function(I){haivl.doClick(I,2);});interactive("haivl-4","video feeds",function(I){haivl.doClick(I,3);});interactive("haivl-5","hot feeds",function(I){haivl.doClick(I,4);});interactive("haivl-seemore","see more feeds",function(I){haivl.doClickSeeMore(I);})
5. Reference
I must say thank to Tran Xuan Truong, Quan Bao Thien To. When I write this bunch
of code I don’t know much about javascript. In addition, regarding Conkeror
technical issues, I gained help from Tran Xuan Truong who is a master in Conkeror
Web browser and he is one who has a big love in programming. Thank you, I will
remember the hackday.
Right now, It’s April 14, 2015. I note this memory to remember a day of doing new
things, learning new things and of course, because it’s a memorial hackday.
Even though, currently, the haivl.com has been collapsed,but this project still
work with haivainoi.com
Problem: Apache Web Server announces that Forbidden Error, given that developers configure Allow and Deny directory with no mistake
Reason: A lack of Indexes for files in directory.
Solution: Add option Indexes in directory tag <Directory>
Example: The following configuration causes forbidden error
<Directory "/home/pvt/apache2/htdocs">
AllowOverride None
Order allow,deny
Allow from all
</Directory>
The following configuration solve the problem
<Directory "/home/pvt/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Problems: Cannot load the fonts of bootstrap
Reason: In Rails, all assets are loaded from host:port/assets not
host:port/fontsSolution: Replace the source url in @font-face, from ../fonts/ to
/assets
There is no need to descript more about the project, the main role of this
project named music-api is to provide a web service for developers to exploit
indirectly the song’s information coming from any online source such as ZingMp3,
Nhaccuatui.
This project is an open source software, developers contribute and developer my
project. This time, this is only two online source ZingMp3 and Nhaccuatui,
however, the number source will be increased regarding developers’ demand.
The song information includes name, singers, lyrics, song's page and
inparticular song's source for downloading.
Why does it work ?
Fundamentally, this service send a request to music oridinary servers, after receiving responses, it analyze the response (inspect elements selectively). After finished analysis, it send json object which inlcluding all song’s information. Currently, the web service is deployed at USA by heroku, Because of IP filter applying by VNG(ZingMp3), there are some songs which you cannot search. I have tested by using VPN locating in the USA, the result is limited.
Good news is that Nhaccuatui is very generous, they allow foreign IP to access all song, meanwhile, you can exploit from more songs.
Request should be sent to http://silverlink.herokuapp.com/api, and server
will return a result in JSON object
there are three parameters to query:
– source: the source of music (zing mp3 = 1, nhaccuatui = 2) - this is compulsory
– keyword: the keyword - this is compulsory
– number: the expect number of song - this is optional. The maximum number of
song user can query from ZingMP3 is 60, and 111 for Nhaccuatui
Local variable: defined inside a method, the usage of local variable in only
inside a method. Prefix of local variable is _ or [a-z].
Instance variable: instance variable is available accross methods and object,
meanwhile, instance variable change from object to object. Prefix of instance
variable is @. Instance variable is not shared among its descedants.
Class variable: it belongs to a class and is a characteristic of this class.
Prefix is @@. Class variable is share among its descedants(childs).
Global variable: class varaible is not across class, however, global variable
does. The prefix of global variable is $.
Constant variable: it’s similar to class variable but it’s constant. Constant
varaibles should be in upper case for all letters.
#2. Commenting
Using =begin and =end
=begin
This is a multiline comment and con spwan as many lines as you
like. But =begin and =end should come in the first line only.
=end
Block must be named after a name of a method (or a function), other while,
it does not work. Usage: In a method, there might be an chunk of code which is
used many time within the method, the point is that, this chunk of code is not
worth making a new function or maybe programmers don’t want to make a function
on that chunk (they cannot think a name for that).
deffunction_nameputs"In a function"yieldputs"Come back to function"endfunction_name{puts"In a block"}
It’s also possible to insert parameters into a block. However, if a function has parameters, I don’t know but there is a error and
cannot use block with function which have parameters.
classBox#`@` is a declare of instance varaiblesdefinitialize(w,h)@width=w@height=hendend
Getters and setters
classBox@@number_of_box=0definitialize(w,h)@width=w@height=hend# These are gettersdefprintWidth@widthenddefprintHeight@heightend#These are settersdefsetWidth=(new_value)@width=new_valueenddefsetHeight=(new_value)@height=new_valueend#usage of @@class variablesdefprintNumberOfBoxputs@@number_of_boxendend
#6. Access control: Public, Private, Protected
Public method: is called by anyone. By default, all methods excepting
initialize method are public methods.
Private method: only class methods can access private methods
Protected method: is called by class method and its subclass method.
Method overloading: Unlike java, ruby is using dynamic typed language, as a
results, it’s impossible to using overriding if depending on variable types. On
the other hand, it uses number of parameters to differentiate methods.
deffunction_name(a,b)#there is no type declaring, compiler does not knowend#how to overridedeffunction_name(a,b)#As a consequence, compiler uses number of parameters toend#differentiate two methodsdeffunction_name(a)end
# range is [0-5]forcounterin0..5putscounterend# range is [0-5)forcounterin0...5putscounterend
#9. Symbols
a. What is this
Symbols in ruby are immutable. Besides this point, it’s a string. It’s able to print put the value of a symbol in term of string or integer
:age#this is a symbol named ageputs:age# print out age's value in stringputs:age.object_id# print out age's object id
b. Implementation
Automatic make new method based on the symbols
defmake_me_a_setter(thename)eval<<-SETTERDONE
def #{thename}(myarg)
@#{thename} = myarg
end
SETTERDONEendclassExamplemake_me_a_setter:symbollmake_me_a_setter"stringg"defshow_symbollputs@symbollenddefshow_stringgputs@stringgendendexample=Example.newexample.symboll("ITS A SYMBOL")example.stringg("ITS A STRING")example.show_symbollexample.show_stringg# reference: http://www.troubleshooters.com/codecorn/ruby/symbols.htm