let initState = null; // Used later to store the chart state before changing the datalet store = { // Data store mathworks: [ ['matlab', 1.71], ['matlab plot', 0.33], ['matlab download', 0.25], ['plot matlab', 0.22], ['matlab online', 0.2], ], ansys: [ ['ansys', 12.06], ['ansys student', 3], ['ansys fluent', 2.79], ['fluent', 2.66], ['ansys customer portal', 1.73], ], arenasimulation: [ ['arena software', 20.01], ['arena simulation', 15.43], ['arena', 6.88], ['rockwell arena', 3.38], ['arena download', 2.55], ], omnetpp: [ ['omnet', 19.29], ['inet', 11.04], ['omnet tutorial', 5.3], ['omnet download', 3.64], ['omnet tutorial for beginners ...', 2.69], ], promodel: [ ['promodel', 12.63], ['gsa ebuy', 9.83], ['process simulator', 4.9], ['promodel corporation', 4.47, ['promodel download', 2.54]], ],};let bgColors = ['#1976d2', '#424242', '#388e3c', '#ffa000', '#7b1fa2']; // mathworks, ansys, arenasimulation, omnetpp, promodellet chartConfig = { type: 'bar', theme: 'classic', globals: { fontFamily: 'Helvetica', }, backgroundColor: 'white', title: { text: 'Alexa: Top Software Sites - Traffic from Search, 7/23/19', backgroundColor: 'white', color: '#606060', }, subtitle: { text: 'Click the columns to view top search keywords. Source: alexa.com.', color: '#606060', }, plot: { tooltip: { visible: false, }, valueBox: { text: '%v%', color: '#606060', textDecoration: 'underline', }, animation: { effect: 'ANIMATION_EXPAND_HORIZONTAL', }, cursor: 'hand', dataBrowser: [ "<span style='font-weight:bold;color:#1976d2;'>Mathworks.com</span>", "<span style='font-weight:bold;color:#424242;'>Ansys.com</span>", "<span style='font-weight:bold;color:#388e3c;'>Arenasimulation.com</span>", "<span style='font-weight:bold;color:#ffa000;'>Omnetpp.org</span>", "<span style='font-weight:bold;color:#7b1fa2;'>Promodel.com</span>", ], hoverState: { border: '2px solid #ffff00', }, rules: [ { backgroundColor: '#1976d2', rule: '%i==0', }, { backgroundColor: '#424242', rule: '%i==1', }, { backgroundColor: '#388e3c', rule: '%i==2', }, { backgroundColor: '#ffa000', rule: '%i==3', }, { backgroundColor: '#7b1fa2', rule: '%i==4', }, { backgroundColor: '#c2185b', rule: '%i==5', }, ], }, scaleX: { values: [ 'Mathworks.com', 'Ansys.com', 'Arenasimulation.com', 'Omnetpp.org', 'Promodel.com', ], guide: { visible: false, }, item: { color: '#606060', }, lineColor: '#C0D0E0', lineWidth: '1px', tick: { lineColor: '#C0D0E0', lineWidth: '1px', }, }, scaleY: { guide: { lineStyle: 'solid', }, item: { color: '#606060', }, lineColor: 'none', tick: { lineColor: 'none', }, }, crosshairX: { lineColor: 'none', lineWidth: '0px', marker: { visible: false, }, plotLabel: { text: '%data-browser: %v% of total', alpha: 0.9, backgroundColor: 'white', borderRadius: '4px', borderWidth: '3px', callout: true, calloutPosition: 'bottom', color: '#606060', fontSize: '12px', multiple: true, offsetY: '-20px', padding: '8px', placement: 'node-top', rules: [ { borderColor: '#1976d2', rule: '%i==0', }, { borderColor: '#424242', rule: '%i==1', }, { borderColor: '#388e3c', rule: '%i==2', }, { borderColor: '#ffa000', rule: '%i==3', }, { borderColor: '#7b1fa2', rule: '%i==4', }, { borderColor: '#c2185b', rule: '%i==5', }, ], shadow: false, }, scaleLabel: { visible: false, }, }, series: [ { values: [59.9, 41.3, 51.2, 48.4, 23.5], }, ],};let updateChart = (p) => { initState = zingchart.exec(p.id, 'getdata'); // Gets the state of the chart when the node was clicked let newValues = null; let update = null; switch (p.nodeindex) { case 0: newValues = store['mathworks']; update = true; break; case 1: newValues = store['ansys']; update = true; break; case 2: newValues = store['arenasimulation']; update = true; break; case 3: newValues = store['omnetpp']; update = true; break; case 4: newValues = store['promodel']; update = true; break; case 5: update = false; // We don't want to allow drilldown for unknown break; } if (update) { zingchart.unbind(p.id, 'node_click'); // Disable node_click for second level zingchart.exec(p.id, 'modify', { update: false, // Making multiple changes, queue these changes data: { crosshairX: { plotLabel: { text: '%v% of total', borderColor: bgColors[p.nodeindex], rules: [], }, }, plot: { backgroundColor: bgColors[p.nodeindex], cursor: null, rules: [], }, scaleX: { values: [], }, }, }); zingchart.exec(p.id, 'setseriesvalues', { // Replaces all values at plotindex 0 update: false, // Queue these, too plotindex: 0, values: newValues, }); zingchart.exec(p.id, 'update'); // Push queued changes zingchart.bind(p.id, 'animation_end', () => { // When the animation ends... zingchart.exec(p.id, 'addobject', { // ...add a back button type: 'shape', data: { type: 'rectangle', id: 'back_btn', backgroundColor: '#ffffff #f6f6f6', borderColor: '#888', borderWidth: '1px', cursor: 'hand', hoverState: { backgroundColor: '#1976D2 #ffffff', borderColor: '#57a2ff', fillAngle: -180, }, label: { text: '< Back', color: '#606060', }, width: '70px', height: '20px', x: '80%', y: '16%', }, }); }); }};zingchart.render({ id: 'myChart', data: chartConfig, height: '100%', width: '100%',});zingchart.bind('myChart', 'node_click', updateChart);// Listen for back button clickzingchart.bind('myChart', 'shape_click', (p) => { zingchart.unbind(p.id, 'animation_end'); if (p.shapeid == 'back_btn') { // Set the data back to the state it was in when the node was clicked zingchart.exec(p.id, 'setdata', { data: initState, }); zingchart.bind(p.id, 'node_click', updateChart); }});
Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.
Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log("Hello, " + line);
});
Keyword | Description | Scope |
---|---|---|
var | Var is used to declare variables(old way of declaring variables) | Function or global scope |
let | let is also used to declare variables(new way) | Global or block Scope |
const | const is used to declare const values. Once the value is assigned, it can not be modified | Global or block Scope |
let greetings = `Hello ${name}`
const msg = `
hello
world!
`
An array is a collection of items or values.
let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);
let mobiles = ["iPhone", "Samsung", "Pixel"];
// accessing an array
console.log(mobiles[0]);
// changing an array element
mobiles[3] = "Nokia";
Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.
() => expression
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
.map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);
let [firstName, lastName] = ['Foo', 'Bar']
let {firstName, lastName} = {
firstName: 'Foo',
lastName: 'Bar'
}
const {
title,
firstName,
lastName,
...rest
} = record;
//Object spread
const post = {
...options,
type: "new"
}
//array spread
const users = [
...adminUsers,
...normalUsers
]
function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
console.log(`Hello ${name}!`);
}
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar
IF is used to execute a block of code based on a condition.
if(condition){
// code
}
Else part is used to execute the block of code when the condition fails.
if(condition){
// code
} else {
// code
}
Switch is used to replace nested If-Else statements.
switch(condition){
case 'value1' :
//code
[break;]
case 'value2' :
//code
[break;]
.......
default :
//code
[break;]
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.
class className {
constructor() { ... } //Mandatory Class method
method1() { ... }
method2() { ... }
...
}
class Mobile {
constructor(model) {
this.name = model;
}
}
mbl = new Mobile("iPhone");