file_path
stringlengths 3
280
| file_language
stringclasses 66
values | content
stringlengths 1
1.04M
| repo_name
stringlengths 5
92
| repo_stars
int64 0
154k
| repo_description
stringlengths 0
402
| repo_primary_language
stringclasses 108
values | developer_username
stringlengths 1
25
| developer_name
stringlengths 0
30
| developer_company
stringlengths 0
82
|
|---|---|---|---|---|---|---|---|---|---|
public/index.html
|
HTML
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/img/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<meta name="theme-color" content="#000000" />
<title>Deployer</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script>
window.electron = require('electron');
</script>
</body>
</html>
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
public/menu.js
|
JavaScript
|
const { app, dialog, Menu, shell } = require('electron');
const isWindows = process.platform === 'win32';
const appVersion = app.getVersion();
/**
* Sets the main menu
* @param mainWindow
*/
function setMainMenu(mainWindow) {
const template = [
{
label: isWindows ? 'File' : app.getName(),
submenu: [
{
label: 'Open',
accelerator: 'CmdOrCtrl+O',
click() {
dialog.showOpenDialog(function (fileNames) {
if (!fileNames || !fileNames[0]) {
return;
}
// For the file URLs, load them directly
// Append the `file://` prefix otherwise
const url = /^file:\/\/\//.test(fileNames[0]) ? fileNames[0] : `file://${fileNames[0]}`;
mainWindow.loadURL(url);
});
}
},
{ role: 'close' },
{ type: 'separator' },
{ role: 'quit' },
]
},
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'selectall' }
]
},
{
label: 'View',
submenu: [
{
label: 'Detached Mode',
accelerator: 'CmdOrCtrl+Shift+D',
click() {
app.dock && app.dock.setBadge('Detached');
mainWindow.setIgnoreMouseEvents(true);
}
},
{
type: 'separator'
},
{
label: 'Developer Tools',
accelerator: 'CmdOrCtrl+Alt+I',
click() {
mainWindow.webContents.openDevTools();
}
},
{ type: 'separator' },
{ role: 'resetzoom' },
{ role: 'zoomin', accelerator: 'CmdOrCtrl+=' },
{ role: 'zoomout' },
{ type: 'separator' },
]
},
{
label: 'Help',
submenu: [
{
label: 'Found a Bug',
click() {
shell.openExternal('https://github.com/ziishaned/deployer/issues/new');
}
},
{
label: 'Suggestions',
click() {
shell.openExternal('https://github.com/ziishaned/deployer/issues/new');
}
},
{
label: 'Learn More',
click() {
shell.openExternal('https://github.com/ziishaned');
}
},
{
label: `About Version`,
click() {
shell.openExternal(`https://github.com/ziishaned/deployer/releases/tag/v${appVersion}`);
}
},
]
}
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}
module.exports = {
setMainMenu
};
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/components/App.js
|
JavaScript
|
import React, {Component} from 'react';
import {Redirect, Route, Switch, BrowserRouter as Router} from 'react-router-dom';
import Home from './Home';
import JobBuild from './JobBuild';
import Setting from './Setting';
import PageNotFound from './PageNotFound';
const PrivateRoute = ({component: Component, ...rest}) => (
<Route
{...rest}
render={(props) =>
localStorage.getItem('setting') ? <Component {...props} /> : <Redirect to={{pathname: '/setting'}} />
}
/>
);
class App extends Component {
render() {
return (
<Router>
<Switch>
<PrivateRoute path="/" exact component={Home} />
<Route path="/setting" component={Setting} />
<PrivateRoute path="/job/:name/build" component={JobBuild} />
<Route component={PageNotFound} />
</Switch>
</Router>
);
}
}
export default App;
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/components/Home.js
|
JavaScript
|
import {Link} from 'react-router-dom';
import React, {Component} from 'react';
import Header from './partials/Header';
import {getJobs} from '../services/jenkins';
class Home extends Component {
constructor(props) {
super(props);
this.state = {
jobs: [],
filteredJobs: [],
loadingJobs: true,
};
}
async componentWillMount() {
const {jobs} = await getJobs();
this.setState({
jobs,
filteredJobs: jobs,
loadingJobs: false,
});
}
filterJobs = (e) => {
let {jobs: updatedList} = this.state;
updatedList = updatedList.filter(({name}) => name.toLowerCase().search(e.target.value.toLowerCase()) !== -1);
this.setState({
filteredJobs: updatedList,
});
};
render() {
const {shell} = window.electron;
const {filteredJobs, loadingJobs} = this.state;
return (
<div>
<Header />
<div className="container">
<div className="d-flex align-items-center small mt-3">
<i className="fa fa-search fa-fw text-muted position-absolute pl-3" />
<input
type="text"
className="form-control py-4"
placeholder="Search jobs..."
style={{paddingLeft: 38}}
onChange={this.filterJobs}
/>
</div>
{loadingJobs && <p className="text-center py-5">Loading...</p>}
{!loadingJobs && !filteredJobs.length && <p className="text-center py-5">Nothing found!</p>}
{!loadingJobs && (
<ul className="list-unstyled mb-4">
{filteredJobs.map((job, index) => (
<li className="border rounded px-3 py-3 mt-3 shadow-sm bg-white" key={index.toString()}>
<div className="d-flex justify-content-between align-items-center">
<div className="d-flex align-items-center">
{job.color === 'blue' ? (
<i className="fa fa-check-circle fa-fw mr-2 text-success" />
) : (
<i className="fa fa-times-circle fa-fw mr-2 text-danger" />
)}
<div
onClick={(e) => {
e.preventDefault();
shell.openExternal(job.url);
}}
className="btn btn-link text-dark p-0"
title="Open link in browser."
style={{cursor: 'pointer'}}
>
{job.name}
</div>
</div>
<ul className="list-inline mb-0">
<li className="list-inline-item">
<Link to={`/job/${job.name}/build`} className="btn btn-dark btn-sm shadow-sm">
<i className="fa fa-wrench fa-fw" /> Build
</Link>
</li>
</ul>
</div>
</li>
))}
</ul>
)}
</div>
</div>
);
}
}
export default Home;
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/components/JobBuild.js
|
JavaScript
|
import React, {Component} from 'react';
import {Redirect} from 'react-router-dom';
import Header from './partials/Header';
import {getJobParameter} from '../services/jenkins';
export default class JobBuild extends Component {
constructor(props) {
super(props);
const {match} = props;
this.state = {
redirectToHome: false,
jobParametersList: {},
loadingJobParameter: true,
jobName: match.params.name,
};
}
async componentWillMount() {
const {match} = this.props;
const jobName = match.params.name;
const jobParametersList = await getJobParameter(jobName);
this.setState({
jobParametersList,
loadingJobParameter: false,
});
}
handleSubmit = async (e) => {
e.preventDefault();
const {elements: parameters} = document.getElementById('build-form');
const formData = {};
for (let i = 0; i < parameters.length - 1; i += 1) {
const item = parameters.item(i);
formData[item.name] = item.value;
}
await this.jenkins.job.build({
name: 'dev-api-config-web',
parameters: formData,
});
this.setState({
redirectToHome: true,
});
};
render() {
const {jobParametersList, jobName, loadingJobParameter, redirectToHome} = this.state;
if (redirectToHome) {
return <Redirect to="/" />;
}
return (
<div>
<Header />
<div className="container">
<h6 className="text-uppercase py-4 mb-0 font-weight-bold d-flex align-items-center">
<div className="mr-2">
<i className="fa fa-briefcase-medical fa-fw" />
</div>
<div>{jobName}</div>
</h6>
{loadingJobParameter && <p className="text-center py-5">Loading...</p>}
{!loadingJobParameter && (
<div className="card shadow-sm mb-4">
<div className="card-header bg-white font-weight-bold">Parameter</div>
<div className="card-body">
<form onSubmit={this.handleSubmit} id="build-form">
{jobParametersList.map((parameter, index) => (
<div className="form-group" key={index.toString()}>
<label htmlFor={parameter.name}>{parameter.name}</label>
<input
type="text"
name={parameter.name}
id={parameter.name}
className="form-control"
defaultValue={parameter.defaultParameterValue ? parameter.defaultParameterValue.value : ''}
/>
</div>
))}
<div className="mt-4">
<button type="submit" className="btn btn-dark shadow-sm btn-block">
Build
</button>
</div>
</form>
</div>
</div>
)}
</div>
</div>
);
}
}
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/components/PageNotFound.js
|
JavaScript
|
import React from 'react';
import {Link} from 'react-router-dom';
export default function PageNotFound({location}) {
return (
<div className="container my-5">
<div className="card shadow-sm text-center">
<div className="card-body">
<p>Something went wrong!</p>
<p className="mb-0">
Go back to <Link to="/">Home</Link>
</p>
</div>
</div>
</div>
);
}
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/components/Setting.js
|
JavaScript
|
import * as Yup from 'yup';
import React, {Component} from 'react';
import {Redirect} from 'react-router-dom';
import {ErrorMessage, Field, Form, Formik} from 'formik';
import logo from '../icons/logo.svg';
const SETTING_SCHEMA = Yup.object().shape({
name: Yup.string().required('Name is required field.'),
url: Yup.string().required('URL is required field.'),
username: Yup.string().required('Username is required field.'),
key: Yup.string().required('API token is required field.'),
});
export default class Setting extends Component {
state = {
setting: {name: '', url: '', username: '', key: ''},
toDashboard: false,
};
componentWillMount() {
const setting = JSON.parse(localStorage.getItem('setting'));
this.setState({
setting,
});
}
handleSubmit = (values, {setSubmitting}) => {
setSubmitting(false);
localStorage.setItem('setting', JSON.stringify(values));
this.setState({
toDashboard: true,
});
};
render() {
const {toDashboard, setting} = this.state;
if (toDashboard) {
return <Redirect to="/" />;
}
return (
<div className="container mb-5">
<div className="card shadow-sm" style={{marginTop: '3.6rem'}}>
<div className="card-body">
<div className="text-center mb-3">
<img src={logo} alt="Deployer" width="98" />
</div>
<Formik
initialValues={setting}
validationSchema={SETTING_SCHEMA}
onSubmit={this.handleSubmit}
render={({errors, touched, isSubmitting}) => (
<Form>
<div className="form-group">
<label htmlFor="name">
<i className="fa fa-lock fa-fw" /> Name
</label>
<Field
type="text"
className={`form-control ${errors.name && touched.name ? 'is-invalid' : ''}`}
name="name"
id="name"
/>
<ErrorMessage name="name" component="div" className="invalid-feedback" />
</div>
<div className="form-group">
<label htmlFor="url">
<i className="fa fa-link fa-fw" /> URL
</label>
<Field
type="text"
className={`form-control ${errors.url && touched.url ? 'is-invalid' : ''}`}
name="url"
id="url"
/>
<ErrorMessage name="url" component="div" className="invalid-feedback" />
</div>
<div className="form-group">
<label htmlFor="username">
<i className="fa fa-user fa-fw" /> Username
</label>
<Field
type="text"
className={`form-control ${errors.username && touched.username ? 'is-invalid' : ''}`}
name="username"
id="username"
/>
<ErrorMessage name="username" component="div" className="invalid-feedback" />
</div>
<div className="form-group">
<label htmlFor="key">
<i className="fa fa-key fa-fw" /> API token
</label>
<Field
type="text"
className={`form-control ${errors.key && touched.key ? 'is-invalid' : ''}`}
name="key"
id="key"
/>
<ErrorMessage name="key" component="div" className="invalid-feedback" />
</div>
<div className="text-center mb-2 mt-4">
<button type="submit" className="btn btn-dark shadow-sm btn-block" disabled={isSubmitting}>
Update
</button>
</div>
</Form>
)}
/>
</div>
</div>
</div>
);
}
}
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/components/partials/Header.js
|
JavaScript
|
import { Link } from 'react-router-dom';
import React, { Component } from 'react';
class Header extends Component {
render() {
const { name: accountName } = JSON.parse(localStorage.getItem('setting'));
return (
<div>
<div className="py-4 bg-white">
<div className="container">
<div className="d-flex justify-content-between align-items-center">
<Link to="/" className="font-weight-bold text-dark">
{ accountName }
</Link>
<Link to="/setting" className="text-dark small">
<i className="fa fa-cog fa-fw" /> Setting
</Link>
</div>
</div>
</div>
<hr className="m-0" />
</div>
);
}
}
export default Header;
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/global.scss
|
SCSS
|
@import "~bootstrap/dist/css/bootstrap.min.css";
@import '~@fortawesome/fontawesome-free/css/all.css';
body {
font-family: "Consolas";
background-color: #f8f9fa !important;
}
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/index.js
|
JavaScript
|
import React from 'react';
import ReactDOM from 'react-dom';
import './global.scss';
import App from './components/App';
ReactDOM.render(
<App />,
document.getElementById('root'),
);
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/services/jenkins.js
|
JavaScript
|
import Jenkins from 'jenkins';
const getJenkinsUrl = () => {
const setting = JSON.parse(localStorage.getItem('setting'));
const url = setting.url.replace(/https?:\/\//, '');
return `https://${setting.username}:${setting.key}@${url}`;
};
export const getJobs = async () => {
const url = getJenkinsUrl();
const jenkins = Jenkins({
baseUrl: url,
promisify: true,
});
return jenkins.info();
};
export const getJobParameter = async (jobName) => {
const url = getJenkinsUrl();
const jenkins = Jenkins({
baseUrl: url,
promisify: true,
});
const jobInfo = await jenkins.job.get(jobName);
const {parameterDefinitions: jobParametersList} = jobInfo.actions.find(
({_class}) => _class === 'hudson.model.ParametersDefinitionProperty'
);
return jobParametersList;
};
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
test/spec.js
|
JavaScript
|
const path = require('path');
const assert = require('assert');
const electron = require('electron');
const Application = require('spectron').Application;
describe('Application launch', function() {
this.timeout(10000);
beforeEach(() => {
this.app = new Application({
path: electron,
args: [path.join(__dirname, '..')]
});
return this.app.start();
});
afterEach(() => {
if (this.app && this.app.isRunning()) {
return this.app.stop();
}
});
it('shows an initial window', async () => {
const windowCount = await this.app.client.getWindowCount();
assert.strictEqual(windowCount, 2)
});
it('shows the empty page on load', async () => {
const text = await this.app.client.getText('.card-body p:first-child');
assert.strictEqual(text, 'Something went wrong!');
});
});
|
ziishaned/deployer
| 66
|
Cross-platform application to deploy your applications through Jenkins.
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
__test__/dumper.test.js
|
JavaScript
|
const Dumper = require('../src/dumper');
describe('Dump class tests', () => {
generateDump = (item) => {
const dumper = new Dumper();
return dumper.generateDump(item).replace(/\u001b\[.*?m/g, '');
};
it('can dump strings', () => {
const stringsToTest = ['list of strings', '', ' '];
stringsToTest.forEach((toTest) => {
const actualDump = generateDump(toTest);
const expectedDump = `string "${toTest}" (length=${toTest.length})`;
expect(actualDump).toStrictEqual(expectedDump);
});
});
it('can dump boolean values', () => {
expect(generateDump(true)).toStrictEqual('boolean true');
expect(generateDump(false)).toStrictEqual('boolean false');
});
it('can dump numeric values', () => {
const numbers = [23, 2, 0, 11.1, -1, -12.2, -9.22, -0.9];
numbers.forEach((number) => {
const type = Number.isInteger(number) ? 'int' : 'float';
expect(generateDump(number)).toStrictEqual(`${type} ${number}`);
});
});
it('can dump regex values', () => {
expect(generateDump(/[0-9]+/)).toStrictEqual('/[0-9]+/');
});
it('can dump function values inside object', () => {
const users = [
{user: 'barney', age: 36, active: true, getAge: () => this.age},
{user: 'fred', age: 40, active: false, getAge: () => this.age},
{user: 'pebbles', age: 1, active: true, getAge: () => this.age},
];
const expectedOutput = `array (size=3) [
[0] => object (size=4) {
'user' => string "barney" (length=6),
'age' => int 36,
'active' => boolean true,
'getAge' => () => this.age,
},
[1] => object (size=4) {
'user' => string "fred" (length=4),
'age' => int 40,
'active' => boolean false,
'getAge' => () => this.age,
},
[2] => object (size=4) {
'user' => string "pebbles" (length=7),
'age' => int 1,
'active' => boolean true,
'getAge' => () => this.age,
},
]`;
expect(generateDump(users)).toStrictEqual(expectedOutput);
});
it('can dump null values', () => {
expect(generateDump(null)).toStrictEqual('null');
});
it('can dump undefined values', () => {
expect(generateDump(undefined)).toStrictEqual('undefined');
});
it('can dump array values', () => {
const weekdays = [
'sunday',
'monday',
1,
true,
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
null,
false,
];
const expectedOutput = `array (size=11) [
[0] => string "sunday" (length=6),
[1] => string "monday" (length=6),
[2] => int 1,
[3] => boolean true,
[4] => string "tuesday" (length=7),
[5] => string "wednesday" (length=9),
[6] => string "thursday" (length=8),
[7] => string "friday" (length=6),
[8] => string "saturday" (length=8),
[9] => null,
[10] => boolean false,
]`;
expect(generateDump(weekdays)).toStrictEqual(expectedOutput);
});
it('can dump object values', () => {
const carDetails = {
color: 'red',
wheels: 4,
engine: {
cylinders: 4,
size: 2.2,
},
};
const expectedOutput = `object (size=3) {
'color' => string "red" (length=3),
'wheels' => int 4,
'engine' => object (size=2) {
'cylinders' => int 4,
'size' => float 2.2,
},
}`;
expect(generateDump(carDetails)).toStrictEqual(expectedOutput);
});
it('can dump cycled object', () => {
const mainNode = {};
const rightNode = {
left: mainNode,
right: null,
};
mainNode.left = mainNode;
mainNode.right = rightNode;
const expectedOutput = `object (size=2) {
'left' => object (size=1) {
'$ref' => string "$" (length=1),
},
'right' => object (size=2) {
'left' => object (size=1) {
'$ref' => string "$" (length=1),
},
'right' => null,
},
}`;
expect(generateDump(mainNode)).toStrictEqual(expectedOutput);
});
it('can dump object without hasOwnProperty', () => {
const weirdObject = {
hasOwnProperty: null,
};
const expectedOutput = `object (size=1) {
'hasOwnProperty' => null,
}`;
expect(generateDump(weirdObject)).toStrictEqual(expectedOutput);
});
});
|
ziishaned/dumper.js
| 2,754
|
A better and pretty variable inspector for your Node.js applications
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
__test__/index.test.js
|
JavaScript
|
const {dd} = require('../index');
const {dump} = require('../index');
describe('dump helpers', () => {
it('should be variadic', () => {
const log = jest.spyOn(console, 'log').mockImplementation((any) => any);
dump(1, 'a', {b: 2});
expect(log).toHaveBeenCalled();
expect(log.mock.calls.length).toBe(2);
});
it('should not exit the process when dump method called', () => {
const exit = jest.spyOn(process, 'exit').mockImplementation((number) => number);
dump(1);
expect(exit).not.toHaveBeenCalled();
});
it('should kill the process when dd method called', () => {
const exit = jest.spyOn(process, 'exit').mockImplementation((number) => number);
dd(1);
expect(exit).toHaveBeenCalled();
});
});
|
ziishaned/dumper.js
| 2,754
|
A better and pretty variable inspector for your Node.js applications
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
index.js
|
JavaScript
|
const dd = require('./src/dd');
const dump = require('./src/dump');
module.exports = {dd, dump};
|
ziishaned/dumper.js
| 2,754
|
A better and pretty variable inspector for your Node.js applications
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/dd.js
|
JavaScript
|
/* eslint-disable no-console */
const callerId = require('caller-id');
const Dumper = require('./dumper');
function dd(obj) {
const dumper = new Dumper();
const caller = callerId.getData();
// Print the file path, line number and generated dump
console.log(`${caller.filePath}:${caller.lineNumber}:`);
console.log(dumper.generateDump(obj));
process.exit(0);
}
module.exports = dd;
|
ziishaned/dumper.js
| 2,754
|
A better and pretty variable inspector for your Node.js applications
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/dump.js
|
JavaScript
|
/* eslint-disable no-console */
const callerId = require('caller-id');
const Dumper = require('./dumper');
function dump(obj) {
const dumper = new Dumper();
const caller = callerId.getData();
// Print the file path, line number and generated dump
console.log(`${caller.filePath}:${caller.lineNumber}:`);
console.log(dumper.generateDump(obj));
}
module.exports = dump;
|
ziishaned/dumper.js
| 2,754
|
A better and pretty variable inspector for your Node.js applications
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/dumper.js
|
JavaScript
|
const kindOf = require('kind-of');
const {decycle} = require('cycle');
const {red, cyan, blue, green, magenta, bold} = require('kleur');
/**
* Generate structured information about one or more objects that
* includes each item type and value.
*
* @author Zeeshan Ahmad <ziishaned@gmail.com>
*/
class Dumper {
/**
* @param {int} indentCount Number of spaces to indent the object with
*/
constructor(indentCount = 4) {
this.spaces = ' '.repeat(indentCount);
}
/**
* Iterates over each property of the provided object and make the output.
*
* @param {*} toDump
* @param {string|null} indent
* @return {string}
*/
generateDump(toDump, indent = '') {
let dump = '';
let startWith = '';
let endWith = '';
switch (kindOf(toDump)) {
case 'array':
startWith = `${bold().black('array')} (size=${toDump.length}) [\n`;
endWith = `${indent}]`;
break;
case 'object':
toDump = decycle(toDump);
startWith = `${bold().black('object')} (size=${Object.keys(toDump).length}) {\n`;
endWith = `${indent}}`;
break;
default:
return this.prepareValueDump(indent, toDump);
}
// For each key of the object, keep
// preparing the inspection output
for (const itemKey in toDump) {
if (!Object.prototype.hasOwnProperty.call(toDump, itemKey)) {
continue;
}
const originalValue = toDump[itemKey];
const originalParamType = kindOf(originalValue);
const valueDump = this.prepareValueDump(indent, originalValue);
dump += this.makeArrowString(originalParamType, indent, itemKey, valueDump);
}
return startWith + dump + endWith;
}
/**
* Prepare the dump output for the given value
*
* @param indent
* @param originalValue
* @return {*|string}
*/
prepareValueDump(indent, originalValue) {
let displayValue = '';
let displayType = kindOf(originalValue);
switch (displayType) {
case 'array':
case 'object':
displayType = '';
displayValue = this.generateDump(originalValue, `${indent}${this.spaces}`);
break;
case 'boolean':
displayType = 'boolean';
displayValue = magenta(`${originalValue}`);
break;
case 'string':
displayType = 'string';
displayValue = `${red(`"${originalValue}"`)} (length=${originalValue.length})`;
break;
case 'null':
displayType = '';
displayValue = blue('null');
break;
case 'undefined':
displayType = '';
displayValue = blue('undefined');
break;
case 'number':
displayType = Number.isInteger(originalValue) ? 'int' : 'float';
displayValue = green(originalValue);
break;
case 'function':
case 'generatorfunction':
displayType = '';
displayValue = this.formatFunction(originalValue);
break;
case 'regexp':
displayType = '';
displayValue = blue(originalValue);
break;
default:
displayType = '';
displayValue = originalValue;
break;
}
let spacer = displayType.length ? ' ' : '';
return `${cyan(displayType)}${spacer}${displayValue}`;
}
/**
* Format function to log it inside the console.
*
* @param {*} originalValue
* @return {string}
*/
formatFunction(originalValue) {
return originalValue
.toString()
.slice(0, 50)
.replace(/\n/g, '')
.replace(/\s+/g, ' ');
}
/**
* Make the arrow string.
*
* @param {string} paramType
* @param {string} indent
* @param {string|number} key
* @param {*} valueDump
* @return {string}
*/
makeArrowString(paramType, indent, key, valueDump) {
const startWith = `${indent}${this.spaces}`;
const valuePart = `${valueDump},\n`;
let keyPart;
if (Number.isInteger(parseInt(key)) || (paramType === 'array' && typeof key !== 'string')) {
keyPart = `[${key}]`;
} else {
keyPart = `'${key}'`;
}
return `${startWith + keyPart} => ${valuePart}`;
}
}
module.exports = Dumper;
|
ziishaned/dumper.js
| 2,754
|
A better and pretty variable inspector for your Node.js applications
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
emoji_clock.go
|
Go
|
package emojiclock
import (
"time"
)
var clocks = []rune("🕛🕧🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕖🕡🕗🕣🕢🕘🕤🕙🕥🕚🕦")
// TimeToEmoji pass the time string of which you want the clock emoji.
func TimeToEmoji(timeString string) (string, error) {
timestamp, err := time.Parse(time.RFC3339, timeString)
if err != nil {
return "", err
}
// New emoji every 30 minutes
t := (60*timestamp.Hour() + timestamp.Minute() + 15) / 30
emoji := clocks[t%24]
return string(emoji), nil
}
|
ziishaned/emoji-clock
| 28
|
Get the emoji clock face for a given time.
|
Go
|
ziishaned
|
Zeeshan Ahmad
| |
emoji_clock_test.go
|
Go
|
package emojiclock
import (
"reflect"
"testing"
)
func TestItShouldReturnString(t *testing.T) {
currentTime := "2014-11-12T11:45:26.371Z"
emoji, _ := TimeToEmoji(currentTime)
if reflect.TypeOf(emoji).String() != "string" {
t.Errorf("Expected type was string but got %s", reflect.TypeOf(emoji).String())
}
}
func TestItShouldReturnTheCorrectEmoji(t *testing.T) {
var data = map[int]map[string]string{
0: {
"timestamp": "2014-11-12T11:45:26.371Z",
"expected": "🕛",
},
1: {
"timestamp": "2018-06-05T01:15:26.371Z",
"expected": "🕜",
},
2: {
"timestamp": "2018-06-05T20:45:26.371Z",
"expected": "🕘",
},
3: {
"timestamp": "2018-06-05T21:45:26.371Z",
"expected": "🕙",
},
4: {
"timestamp": "2018-06-05T22:45:26.371Z",
"expected": "🕚",
},
5: {
"timestamp": "2018-06-05T23:45:26.371Z",
"expected": "🕛",
},
6: {
"timestamp": "2018-06-05T23:11:26.371Z",
"expected": "🕚",
},
}
for key, val := range data {
emoji, _ := TimeToEmoji(val["timestamp"])
if emoji != val["expected"] {
t.Errorf("%b: Expected emoji is %s but received %s", key, val["expected"], emoji)
}
}
}
func TestItThrowsErrorFroWrongTimeString(t *testing.T) {
timestampString := "wrong_timestamp"
_, err := TimeToEmoji(timestampString)
if err.Error() != "parsing time \"wrong_timestamp\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"wrong_timestamp\" as \"2006\"" {
t.Errorf("Please provide a valid timestamp")
}
}
|
ziishaned/emoji-clock
| 28
|
Get the emoji clock face for a given time.
|
Go
|
ziishaned
|
Zeeshan Ahmad
| |
installer.sh
|
Shell
|
#!/usr/bin/env bash
## Clone the repo
git clone https://github.com/ziishaned/git-collab.git --depth=1 || { echo >&2 "Clone failed with $?"; exit 1; }
cd git-collab
make install || { echo >&2 "Clone failed with $?"; exit 1; }
cd ..
rm -rf git-collab
|
ziishaned/git-collab
| 26
|
Make co-authored commits on github
|
Shell
|
ziishaned
|
Zeeshan Ahmad
| |
src/downloader.ts
|
TypeScript
|
import mkdirp from 'mkdirp';
import {spinner} from './index';
import {existsSync, writeFileSync} from 'fs';
import fetch, {Headers, Response} from 'node-fetch';
import {parse as parsePath, ParsedPath, resolve as resolvePath} from 'path';
export const githubApiBaseUrl: string = 'https://api.github.com';
export const githubContentsEndpoint: string = `${githubApiBaseUrl}/repos/%s/%s/contents`;
interface GitHubRequestHeaders extends Headers {
Authorization?: string;
}
export async function getBlobs(url: string, token?: string): Promise<Blob> {
const headers: Partial<GitHubRequestHeaders> = {};
if (token) {
headers.Authorization = `Bearer ${token}`;
}
const res: Response = await fetch(url, {
headers: <GitHubRequestHeaders>headers,
});
if (!res.ok) {
spinner.stop();
console.error('Something went wrong!');
process.exit(1);
}
return res.json();
}
export async function getContents(url: string, token?: string): Promise<GithubContent[]> {
const headers: Partial<GitHubRequestHeaders> = {};
if (token) {
headers.Authorization = `Bearer ${token}`;
}
const res: Response = await fetch(url, {
headers: <GitHubRequestHeaders>headers,
});
if (!res.ok) {
const error = await res.json();
spinner.stop();
if (error.message === 'Bad credentials') {
console.error('Provided token is invalid');
} else {
console.error('Something went wrong!');
}
process.exit(1);
}
const contents: GithubContent[] | GithubContent = await res.json();
if (Array.isArray(contents)) {
return contents;
}
return [contents];
}
export async function download(baseUrl: string, path: string, branch: string, token?: string): Promise<void> {
const url: string = `${baseUrl}/${path}?ref=${branch}`;
const contents: GithubContent[] = await getContents(url, token);
for (const content of contents) {
if (content.type === 'dir') {
await download(baseUrl, content.path, branch, token);
} else {
spinner.text = `Downloading ${content.path}`;
const blob: GithubBlob = await getBlobs(content.git_url, token);
const parsedPath: ParsedPath = parsePath(content.path);
const directoryPath: string = resolvePath(`${process.cwd()}/${parsedPath.dir}`);
const filePath: string = resolvePath(`${process.cwd()}/${content.path}`);
if (!existsSync(directoryPath)) {
mkdirp.sync(directoryPath);
}
const buffer: Buffer = Buffer.from(<string>blob.content, 'base64');
writeFileSync(filePath, buffer);
}
}
}
|
ziishaned/git-dld
| 40
|
Download files or folders from GitHub
|
TypeScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/index.ts
|
TypeScript
|
#!/usr/bin/env node
/// <reference path="./types/index.d.ts" />
/// <reference path="./types/is-github-url.d.ts" />
/// <reference path="./types/github-url-parse.d.ts" />
import ora from 'ora';
import yargs from 'yargs';
import {format} from 'util';
import isGithubUrl from 'is-github-url';
import {download, githubContentsEndpoint} from './downloader';
import parseGithubUrl, {ParsedGithubUrl} from 'github-url-parse';
export const spinner: ora.Ora = ora('Fetching information');
yargs
.scriptName('git dld')
.command({
command: '* [url]',
describe: 'Download the directory or file from GitHub',
builder: {
token: {
alias: 't',
type: 'string',
describe: 'GitHub access token if you want download from private repository',
},
},
handler: async (args: DownloadCommandArgs): Promise<void> => {
const isValid = isGithubUrl(args?.url);
if (!isValid) {
console.error('Provided URL is not a valid GitHub URL');
process.exit(1);
}
const {user, repo, path, branch} = <ParsedGithubUrl>parseGithubUrl(args.url);
const url: string = format(githubContentsEndpoint, user, repo);
console.log(`Downloading into '${path}'`);
spinner.start();
await download(url, path, branch, args.token);
spinner.stop();
console.log(`✓ Done`);
process.exit(0);
},
})
.version()
.help('help')
.showHelpOnFail(false).argv;
|
ziishaned/git-dld
| 40
|
Download files or folders from GitHub
|
TypeScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/types/github-url-parse.d.ts
|
TypeScript
|
declare module 'github-url-parse' {
type ParsedGithubUrl = {
user: string;
repo: string;
type: string;
path: string;
branch: string;
};
export default function parseGithubUrl(url: string): ParsedGithubUrl;
}
|
ziishaned/git-dld
| 40
|
Download files or folders from GitHub
|
TypeScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/types/index.d.ts
|
TypeScript
|
type GithubBlob = {
sha?: string;
node_id?: string;
size?: number;
url?: string;
content?: string;
encoding?: string;
};
type GithubContent = {
name: string;
path: string;
sha: string;
size: number;
url: string;
html_url: string;
git_url: string;
download_url: string;
type: 'dir' | 'file';
_links: GithubContentLinks;
};
type GithubContentLinks = {
self: string;
git: string;
html: string;
};
type DownloadCommandArgs = {
url: string;
t: string;
token: string;
};
|
ziishaned/git-dld
| 40
|
Download files or folders from GitHub
|
TypeScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/types/is-github-url.d.ts
|
TypeScript
|
declare module 'is-github-url' {
export default function (url: string): boolean;
}
|
ziishaned/git-dld
| 40
|
Download files or folders from GitHub
|
TypeScript
|
ziishaned
|
Zeeshan Ahmad
| |
index.js
|
JavaScript
|
const core = require("@actions/core");
const { execSync } = require("child_process");
const { GitHub, context } = require("@actions/github");
const main = async () => {
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
const githubToken = core.getInput("github-token");
const testCommand = core.getInput("test-command") || "npx jest";
const prNumber = context.payload.number;
const githubClient = new GitHub(githubToken);
const codeCoverage = execSync(testCommand).toString();
let coveragePercentage = execSync(
"npx coverage-percentage ./coverage/lcov.info --lcov"
).toString();
coveragePercentage = parseFloat(coveragePercentage).toFixed(2);
const commentBody = `<p>Total Coverage: <code>${coveragePercentage}</code></p>
<details><summary>Coverage report</summary>
<p>
<pre>${codeCoverage}</pre>
</p>
</details>`;
await githubClient.issues.createComment({
repo: repoName,
owner: repoOwner,
body: commentBody,
issue_number: prNumber,
});
};
main().catch(err => core.setFailed(err.message));
|
ziishaned/jest-reporter-action
| 49
|
Comments a pull request with the jest code coverage
|
JavaScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/Exception/BaseException.php
|
PHP
|
<?php
namespace Ziishaned\PhpLicense\Exception;
use Exception;
class BaseException extends Exception
{
public function __construct($message, $code = 0, Exception $previous = null)
{
parent::__construct($message, $code, $previous);
if ($openSSlErrorMessage = openssl_error_string()) {
$this->message = sprintf(
'%s%sUnderlying OpenSSL message : %s',
parent::getMessage(),
PHP_EOL,
$openSSlErrorMessage
);
}
}
}
|
ziishaned/php-license
| 82
|
PHP library for generating and parsing license
|
PHP
|
ziishaned
|
Zeeshan Ahmad
| |
src/PhpLicense.php
|
PHP
|
<?php
namespace Ziishaned\PhpLicense;
use Ziishaned\PhpLicense\Exception\BaseException;
class PhpLicense
{
/**
* Generate license file.
*
* @param array $data
* @param string $privateKey
*
* @return string
* @throws \Ziishaned\PhpLicense\Exception\BaseException
*/
public static function generate($data, $privateKey)
{
$key = openssl_pkey_get_private($privateKey);
if (!$key) {
throw new BaseException("OpenSSL: Unable to get private key");
}
$success = openssl_private_encrypt(json_encode($data), $signature, $key);
openssl_free_key($key);
if (!$success) {
throw new BaseException("OpenSSL: Unable to generate signature");
}
$sign_b64 = base64_encode($signature);
return $sign_b64;
}
/**
* Parse license file.
*
* @param string $licenseKey
* @param string $publicKey
*
* @return string
* @throws \Ziishaned\PhpLicense\Exception\BaseException
*/
public static function parse($licenseKey, $publicKey)
{
$sign = base64_decode($licenseKey);
$key = openssl_pkey_get_public($publicKey);
if (!$key) {
throw new BaseException("OpenSSL: Unable to get public key");
}
$success = openssl_public_decrypt($sign, $decryptedData, $publicKey);
openssl_free_key($key);
if (!$success) {
throw new BaseException("OpenSSL: Unable to generate signature");
}
return json_decode($decryptedData, true);
}
}
|
ziishaned/php-license
| 82
|
PHP library for generating and parsing license
|
PHP
|
ziishaned
|
Zeeshan Ahmad
| |
tests/PhpLicenseTest.php
|
PHP
|
<?php
namespace Tests;
use PHPUnit\Framework\TestCase;
use Ziishaned\PhpLicense\PhpLicense;
use Ziishaned\PhpLicense\Exception\BaseException;
/**
* Class PhpLicenseTest
*
* @package Tests
* @author Zeeshan Ahmad <ziishaned@gmail.com>
*/
class PhpLicenseTest extends TestCase
{
/**
* @throws \Ziishaned\PhpLicense\Exception\BaseException
*/
public function testCanGenerateLicenseKey()
{
$data = [
"email" => "ziishaned@gmail.com",
];
$privateKey = file_get_contents(__DIR__ . '/keys/private_key.pem');
$license = PhpLicense::generate($data, $privateKey);
$this->assertIsString($license);
}
public function testCanThrowExceptionForWrongPublicKey()
{
$data = [
"email" => "ziishaned@gmail.com",
];
$privateKey = '';
try {
PhpLicense::generate($data, $privateKey);
} catch (BaseException $e) {
$this->assertIsString($e->getMessage());
$this->assertStringContainsString('OpenSSL: Unable to get private key', $e->getMessage());
}
}
/**
* @throws \Ziishaned\PhpLicense\Exception\BaseException
*/
public function testCanParseLicenseKey()
{
$data = [
"email" => "ziishaned@gmail.com",
];
$publicKey = file_get_contents(__DIR__ . '/keys/public_key.pem');
$privateKey = file_get_contents(__DIR__ . '/keys/private_key.pem');
$license = PhpLicense::generate($data, $privateKey);
$parsedLicense = PhpLicense::parse($license, $publicKey);
$this->assertIsString($license);
$this->assertIsArray($parsedLicense);
}
public function testCanThrowExceptionForWrongPrivateKey()
{
$licenseKey = 'license-key';
$privateKey = '';
try {
PhpLicense::parse($licenseKey, $privateKey);
} catch (BaseException $e) {
$this->assertIsString($e->getMessage());
$this->assertStringContainsString('OpenSSL: Unable to get public key', $e->getMessage());
}
}
}
|
ziishaned/php-license
| 82
|
PHP library for generating and parsing license
|
PHP
|
ziishaned
|
Zeeshan Ahmad
| |
src/extension.ts
|
TypeScript
|
import {ExtensionContext, commands} from 'vscode';
import {SnippetMaker} from './snippet-maker';
export const activate = (context: ExtensionContext) => {
let disposable = commands.registerCommand('snippetmaker.make_snippet', async () => {
let snippetMaker = new SnippetMaker();
await snippetMaker.createSnippet();
});
context.subscriptions.push(disposable);
};
export const deactivate = () => {};
|
ziishaned/snippetmaker-vscode
| 92
|
Easily make code snippets in VS Code
|
TypeScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/helpers.ts
|
TypeScript
|
import * as os from 'os';
import {join} from 'path';
import {env} from 'vscode';
export const getVSCodeUserPath = (): string => {
const appName = env.appName || '';
const isDev = /dev/i.test(appName);
const isOSS = isDev && /oss/i.test(appName);
const isInsiders = /insiders/i.test(appName);
const vscodePath = getVSCodePath();
const vscodeAppName = getVSCodeAppName(isInsiders, isOSS, isDev);
const vscodeAppUserPath = join(vscodePath, vscodeAppName, 'User');
return vscodeAppUserPath;
};
const getVSCodeAppName = (isInsiders: boolean, isOSS: boolean, isDev: boolean): string => {
return process.env.VSCODE_PORTABLE
? 'user-data'
: isInsiders
? 'Code - Insiders'
: isOSS
? 'Code - OSS'
: isDev
? 'code-oss-dev'
: 'Code';
};
const getVSCodePath = (): string => {
switch (process.platform) {
case 'darwin':
return `${os.homedir()}/Library/Application Support`;
case 'linux':
return `${os.homedir()}/.config`;
case 'win32':
return process.env.APPDATA as string;
default:
return '/var/local';
}
};
|
ziishaned/snippetmaker-vscode
| 92
|
Easily make code snippets in VS Code
|
TypeScript
|
ziishaned
|
Zeeshan Ahmad
| |
src/snippet-maker.ts
|
TypeScript
|
import {promisify} from 'util';
import {readFile, writeFile} from 'fs';
import * as stripJsonComments from 'strip-json-comments';
import {TextEditor, window, languages, Selection} from 'vscode';
import {getVSCodeUserPath} from './helpers';
const readFileSync = promisify(readFile);
const writeFileSync = promisify(writeFile);
interface SnippetInfoInterface {
lang: string;
name: string;
body: Array<string>;
prefix: string;
description: string;
}
export class SnippetMaker {
private editor: TextEditor;
private snippetInfo: SnippetInfoInterface;
public constructor() {
this.snippetInfo = <SnippetInfoInterface>{};
this.editor = <TextEditor>window.activeTextEditor;
}
public createSnippet = async () => {
await this.setSnippetInfo();
let snippetsPath = this.getSnippetsPath();
let snippetFilePath = `${snippetsPath}/${this.snippetInfo.lang}.json`;
let text = '{}';
try {
text = await readFileSync(snippetFilePath, {
encoding: 'utf8',
});
} catch (e) {
if (e.code !== 'ENOENT') {
window.showErrorMessage('Something went wrong while retrieving snippets.');
return;
}
await writeFileSync(snippetFilePath, '{}');
}
let snippetFileText = JSON.parse(stripJsonComments(text));
snippetFileText[this.snippetInfo.name] = {
body: this.snippetInfo.body,
prefix: this.snippetInfo.prefix,
description: this.snippetInfo.description,
};
await writeFileSync(snippetFilePath, JSON.stringify(snippetFileText));
};
/**
* Get snippet information from user.
*
* @returns void
*/
private setSnippetInfo = async (): Promise<void> => {
let snippetBody = this.selectedText();
this.snippetInfo.body = snippetBody.split('\n');
let listOfLanguages = await languages.getLanguages();
this.snippetInfo.lang = <string>await window.showQuickPick(listOfLanguages, {
placeHolder: this.editor.document.languageId,
});
this.snippetInfo.name = <string>await window.showInputBox({
prompt: 'Name',
});
this.snippetInfo.prefix = <string>await window.showInputBox({
prompt: 'Trigger',
});
this.snippetInfo.description = <string>await window.showInputBox({
prompt: 'Description',
});
};
/**
* Get the user defined snippets path.
*
* @returns string
*/
private getSnippetsPath = (): string => {
let vscodeUserPath = getVSCodeUserPath();
return `${vscodeUserPath}/snippets`;
};
/**
* Get selected text from active editor.
*
* @returns string
*/
private selectedText = (): string => {
let selectedRegion = <Selection>this.editor.selection;
return this.editor.document.getText(selectedRegion);
};
}
|
ziishaned/snippetmaker-vscode
| 92
|
Easily make code snippets in VS Code
|
TypeScript
|
ziishaned
|
Zeeshan Ahmad
| |
sample/main.go
|
Go
|
package main
import (
"os"
"context"
"github.com/urfave/cli/v3"
)
func main() {
(&cli.Command{}).Run(context.Background(), os.Args)
}
|
zimbatm/heretic-nix
| 4
|
Using __noChroot for good
|
Nix
|
zimbatm
|
Jonas Chevalier
|
numtide
|
index.js
|
JavaScript
|
require('./src/zingchart-angularjs');
module.exports = 'zingchart-angularjs';
|
zingchart/ZingChart-AngularJS
| 78
|
ZingChart AngularJS Directive
|
JavaScript
|
zingchart
|
ZingChart
| |
karma.conf.js
|
JavaScript
|
// Karma configuration
// Generated on Thu Feb 26 2015 13:16:16 GMT-0800 (PST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'],
// list of files / patterns to load in the browser
files: [
'./node_modules/zingchart/zingchart.min.js',
'./node_modules/angular/angular.js',
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/angular-mocks/angular-mocks.js',
'./test/*.js',
'./src/*.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
|
zingchart/ZingChart-AngularJS
| 78
|
ZingChart AngularJS Directive
|
JavaScript
|
zingchart
|
ZingChart
| |
src/zingchart-angularjs.js
|
JavaScript
|
/**
* File: zingchart-angularjs.js
* Version: v1.1.0
*/
(function(){
'use strict';
angular.module('zingchart-angularjs', [] )
.directive('zingchart', [function(){
var currentAutoId = 1;
return {
restrict : 'EA',
scope : {
id : '@',
zcValues : '=',
zcJson : '=',
zcRender : '=',
zcLicense : '='
},
controller : ['$scope', '$element', '$attrs', function($scope, $element, $attrs){
var id;
// Get or generate id
if(!$attrs.id){
id = 'zingchart-auto-' + currentAutoId;
currentAutoId++;
$attrs.id = id;
// newly generated id has to be put back on the element too to meet
// zingcharts requirements
$element.attr('id', id);
}
else{
if($attrs.id.indexOf('{{') > -1){
id=$scope.id;
$element.attr('id', id);
}
else{
id = $attrs.id;
}
}
var initializing = {
json : true,
values : true,
render : true
};
$scope.$watchCollection('zcValues', function(){
if(initializing.values){
initializing.values = !initializing.values;
return;
}
if($scope.zcValues){
if(isMultiArray($scope.zcValues)){
zingchart.exec(id, 'setseriesvalues', {
values : $scope.zcValues
});
}
else{
zingchart.exec(id, 'setseriesvalues', {
values : [$scope.zcValues]
});
}
}
});
$scope.$watch('zcLicense', function(newValue, oldValue, scope) {
if(initializing.license){
initializing.license = !initializing.license;
return;
}
ZC.LICENSE = scope.zcLicense;
scope.zcLicense = newValue;
},true);
$scope.$watch('zcJson', function(){
if(initializing.json){
initializing.json = !initializing.json;
return;
}
if($attrs.zcJson){
var _json = $scope.zcJson;
//Inject values
if($scope.zcValues){
injectValues($scope.zcValues, _json);
}
//Inject type
if(JSON.stringify(_json).indexOf('type') === -1){
_json.type = 'line';
}
else{
_json.type = ($attrs.zcType) ? $attrs.zcType : _json.type
}
zingchart.exec(id, 'setdata', {
data : _json
});
}
},true);
$scope.$watch('zcRender', function(newValue, oldValue, scope) {
if(initializing.render){
initializing.render = !initializing.render;
return;
}
// Destroy the chart and re-render it with changed attributes
zingchart.exec(scope.id, 'destroy');
scope.zcRender = newValue;
scope.renderChart();
},true);
$scope.renderChart = function (){
var id = $element.attr('id');
//Defaults
var _json = {
data : {
type : 'line',
series : []
},
width : 600,
height: 400
};
//Add render object.
if($scope.zcRender){
mergeObject($scope.zcRender, _json);
}
//Add JSON object
if($scope.zcJson){
mergeObject($scope.zcJson, _json.data);
}
//Add Values
if($scope.zcValues){
injectValues($scope.zcValues, _json.data);
}
//Add other properties
_json.data.type = ($attrs.zcType) ? $attrs.zcType : _json.data.type;
_json.height = ($attrs.zcHeight) ? $attrs.zcHeight : _json.height;
_json.width = ($attrs.zcWidth) ? $attrs.zcWidth : _json.width;
_json.id = id;
//Set the box-model of the container element if the height or width are defined as 100%.
if(_json.width === "100%" && !$element.css('width')){
$element.css('width', '100%');
}
if(_json.height === "100%" && !$element.css('height')){
$element.css('height', '100%');
}
ZC.LICENSE = $scope.zcLicense;
zingchart.render(_json);
}
$scope.$on('$destroy', function() {
zingchart.exec($scope.id,'destroy');
});
}],
link : function($scope){
$scope.renderChart();
}
};
}]);
/**
* Injects values into each series, and handles multi series cases.
* @param the values to inject into the config object
* @param the configuration object itself.
*/
function injectValues(values, config) {
if(typeof config.series === 'undefined'){
config.series = [];
}
//Single Series
if(!isMultiArray(values)){
if(config.series[0]){
config.series[0].values = values;
}
else{
config.series.push({'values' : values});
}
}
//Multi Series
else{
for(var i = 0; i < values.length; i++){
if(config.series[i]){
config.series[i].values = values[i];
}
else{
config.series.push({'values' : values[i]});
}
}
}
return config;
}
/**
* Helper function to merge an object into another, overwriting properties.
* A shallow, not a recursive merge
* @param {object} fromObj - The object that has properties to be merged
* @param {object} intoObj - The object being merged into (Result)
*/
function mergeObject(fromObj, intoObj){
for(var property in fromObj){
if (fromObj.hasOwnProperty(property)) {
intoObj[property] = fromObj[property];
}
}
}
/**
* Determines whether an array is multidimensional or not.
* @param {array} _array - The array to test
* @returns {boolean} - true if the array is multidimensional, false otherwise
*/
function isMultiArray(_array){
return Array.isArray(_array[0]);
}
})();
|
zingchart/ZingChart-AngularJS
| 78
|
ZingChart AngularJS Directive
|
JavaScript
|
zingchart
|
ZingChart
| |
test/defaults.js
|
JavaScript
|
describe('ZingChart Directive', function(){
this.timeout(5000);
beforeEach(module('zingchart-angularjs'));
var _$scope;
var _$compile;
beforeEach(function(done){
inject(function ($compile, $rootScope) {
_$scope = $rootScope.$new();
_$compile = $compile;
var completed = 0;
zingchart.complete=function(p){
completed++;
if(completed == 8){
done();
}
}
$('<div id="container"></div>').appendTo('body');
//Cases 1+2
$('<zingchart id="chart-1"></zingchart>').appendTo("#container");
//Case 3
_$scope.myValues2 = [[3,2,3,3,9] , [1,2,3,4,5]];
$('<zingchart id="chart-2" zc-values="myValues2"></zingchart>').appendTo("#container");
//Case 4
_$scope.myValues3 = [1,2,3,4,5];
$('<zingchart id="chart-3" zc-values="myValues3"></zingchart>').appendTo("#container");
//Case 5
_$scope.myValues4 = [1,2,3,4,5];
_$scope.myJson4 = {
"series":[
{
"line-color":"#ff653f",
"marker":{
"background-color":"#900000",
"border-width":1,
"shadow":0,
"border-color":"#f56b6b"
}
}
]
};
$('<zingchart id="chart-4" zc-values="myValues4" zc-json="myJson4"></zingchart>').appendTo("#container");
//Case 6
_$scope.myValues5 = [5,5,6,7,10];
_$scope.myJson5 = {
"series":[
{
"line-color":"#007790",
"marker":{
"background-color":"#007790",
"border-width":1,
"shadow":0,
"border-color":"#69dbf1"
},
"values": [0,0,0,2,3]
},
{
"line-color":"#007790",
"marker":{
"background-color":"#007790",
"border-width":1,
"shadow":0,
"border-color":"#69dbf1"
},
"values" : [1,2,3,4,5]
}
]
};
$('<zingchart id="chart-5" zc-values="myValues5" zc-json="myJson5"></zingchart>').appendTo("#container");
//Case 7
_$scope.myValues6 = [[10,20,30,44,99],[20,30,50,20,50]];
_$scope.myJson6 = {
"series":[
{
"line-color":"#33d911",
"marker":{
"background-color":"#90e496",
"border-width":1,
"shadow":0,
"border-color":"#6bf56e"
},
"values": [0,0,0,2,3]
},
{
"line-color":"#90005b",
"marker":{
"background-color":"#8b0090",
"border-width":1,
"shadow":0,
"border-color":"#d6aee7"
},
"values" : [1,2,3,4,5]
}
]
};
_$scope.myRender6 = {
"output" : "canvas",
"data" : {
"series" : [{
"values" : [1,1,1]
}]
}
};
$('<zingchart id="chart-6" zc-values="myValues6" zc-json="myJson6" zc-render="myRender6"></zingchart>').appendTo("#container");
//Case 8
_$scope.myValues7 = [[3,2,3,3,9] , [1,2,3,4,5]];
$('<zingchart id="chart-7" zc-values="myValues7" zc-type="bar"></zingchart>').appendTo("#container");
//Case 9
_$scope.myValues8 = [3,2,3,3,9];
_$scope.myJson8 = {
"type": "bar"
};
$('<zingchart id="chart-8" zc-values="myValues8" zc-json="myJson8" zc-type="line"></zingchart>').appendTo("#container");
var $element = _$compile(document.getElementById('container'))(_$scope);
});
});
//Case 1
it("should create chart-1 : render an empty zingchart", function(){
var output = zingchart.exec('chart-1', 'getdata');
var expected = {
"graphset": [{
"type":"line",
"series":[]
}]
};
expect(JSON.stringify(output)).to.equal(JSON.stringify(expected));
});
//Case 2
it("should render chart-1 with default width and height", function(){
var output = zingchart.exec('chart-1', 'getobjectinfo', {
object : 'graph'
});
expect(output.width).to.equal(600);
expect(output.height).to.equal(400);
});
//Case 3
it("should render chart-2, a line chart with 2 series", function(){
var output = zingchart.exec('chart-2', 'getdata');
var expected = {
"graphset": [{
"type":"line",
"series":[
{"values" : [3,2,3,3,9]},
{"values" : [1,2,3,4,5]},
]
}]
};
expect(JSON.stringify(output)).to.equal(JSON.stringify(expected));
});
//Case 4
it("should render chart-3; a line chart with 1 series", function(){
var output = zingchart.exec('chart-3', 'getdata');
var expected = {
"graphset": [{
"type":"line",
"series":[
{"values" : [1,2,3,4,5]},
]
}]
};
expect(JSON.stringify(output)).to.equal(JSON.stringify(expected));
});
//Case 5
it("should render chart-4; a line chart with 1 series, and a data object", function(){
var output = zingchart.exec('chart-4', 'getdata');
var expected = {
"graphset":[{
"type":"line",
"series":[{
"line-color":"#ff653f",
"marker":{
"background-color":"#900000",
"border-width":1,
"shadow":0,
"border-color":"#f56b6b"
},
"values":[1,2,3,4,5]}
]}
]
};
expect(JSON.stringify(output)).to.equal(JSON.stringify(expected));
});
//Case 6
it("should render chart-5; a line chart with 1 series, and a data object with 2 series", function(){
var output = zingchart.exec('chart-5', 'getdata');
var expected = {
"graphset":[{
"type":"line",
"series":[
{
"line-color":"#007790",
"marker":{
"background-color":"#007790",
"border-width":1,
"shadow":0,
"border-color":"#69dbf1"
},
"values":[5,5,6,7,10]
},
{
"line-color":"#007790",
"marker":{
"background-color":"#007790",
"border-width":1,
"shadow":0,
"border-color":"#69dbf1"
},
"values":[1,2,3,4,5]
}
]}
]
};
expect(JSON.stringify(output)).to.equal(JSON.stringify(expected));
});
//Case 7
it("should render chart-6; a line chart with 2 series, and a data object with 2 series, and a render object with 1 series in canvas", function(){
var output = zingchart.exec('chart-6', 'getdata');
var expected = {
"graphset": [{
"series": [{
"line-color": "#33d911",
"marker": {
"background-color": "#90e496",
"border-width": 1,
"shadow": 0,
"border-color": "#6bf56e"
},
"values": [10, 20, 30, 44, 99]
}, {
"line-color": "#90005b",
"marker": {
"background-color": "#8b0090",
"border-width": 1,
"shadow": 0,
"border-color": "#d6aee7"
},
"values": [20, 30, 50, 20, 50]
}]
}]
};
expect(JSON.stringify(output)).to.equal(JSON.stringify(expected));
});
//Case 8
it("should render chart-7 a 1 series bar chart", function(){
var output = zingchart.exec('chart-7', 'getdata');
var expected = {
"graphset": [{
"type": "bar",
"series": [{
"values": [3, 2, 3, 3, 9]
}, {
"values": [1, 2, 3, 4, 5]
}]
}]
};
expect(JSON.stringify(output)).to.equal(JSON.stringify(expected));
});
//Case 9
it("should render chart-8; a line chart with a json that specifies bar, but is overwritten", function(){
var output = zingchart.exec('chart-8', 'getdata');
var expected = {
"graphset":[{
"type":"line",
"series":[{
"values":[3,2,3,3,9]
}]
}]
};
expect(JSON.stringify(output)).to.equal(JSON.stringify(expected));
});
});
|
zingchart/ZingChart-AngularJS
| 78
|
ZingChart AngularJS Directive
|
JavaScript
|
zingchart
|
ZingChart
| |
Gruntfile.js
|
JavaScript
|
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
clean: {
default: ["lib/*.js"]
},
concat: {
options: {
banner: '/*!\n <%= pkg.name %> <%= pkg.version %>\n' +
//' <%= pkg.repository.url %>\n\n' +
' Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' Licensed under the MIT license.\n' +
'*/\n\n' +
'(function (root, factory) {\n' +
' if (typeof define === "function" && define.amd) {\n' +
' define(["underscore", "backbone"], function (_, Backbone) {\n' +
' return (root.ZingChart = factory(_, Backbone));\n' +
' });\n' +
' } else if (typeof exports === "object") {\n' +
' module.exports = factory(require("underscore"), require("backbone"));\n' +
' } else {\n' +
' root.ZingChart = factory(root._, root.Backbone);\n' +
' }}(this, function (_, Backbone) {\n\n' +
' var ZingChart = {};\n',
footer: '\n return ZingChart;\n\n' +
'}));'
},
default:{
files: {
'lib/backbone.zingchart.js': ['src/ZingChartModel.js', 'src/ZingChartView.js'],
'lib/backbone.zingchart.extended.js': ['src/ZingChartModel.js', 'src/ZingChartView.js', 'src/ZingChartViewExtended.js']
}
}
},
uglify: {
options: {
mangle: true,
compress: true
},
default: {
files: {
'lib/backbone.zingchart.min.js': ['lib/backbone.zingchart.js'],
'lib/backbone.zingchart.extended.min.js': ['lib/backbone.zingchart.extended.js']
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.registerTask("default", ["clean", "concat", "uglify"]);
};
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
examples/chart_demo.html
|
HTML
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>ZingChart Backbone Plugin - Simple Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
<script src="../lib/backbone.zingchart.min.js"></script>
<script type="text/template" id="chart-template">
<div>
<button class="add-plot">Add Plot</button>
<button class="reset-json">Change JSON</button>
<button class="reset-data">Change Data</button>
<button class="toggle-legend">Toggle Legend</button>
<div id="chartDiv"></div>
</div>
</script>
<body>
<div id="demo"></div>
<script>
var DemoView = Backbone.View.extend({
el: '#demo',
template: _.template($('#chart-template').html()),
initialize: function() {
this.$el.empty();
this.zc = new ZingChart.ZingChartModel({data: [[3,2,3,3,9] , [1,2,3,4,5]],
width: 500,
height: 400});
this.render();
},
render: function() {
this.$el.html(this.template());
this.zcView = new ZingChart.ZingChartView({model: this.zc, el: $('#chartDiv')});
this.zcView.render();
return this;
},
events: {
'click .reset-json': 'changeJSON',
'click .reset-data': 'changeData',
'click .add-plot': 'addPlot',
'click .toggle-legend': 'addLegend'
},
random: function(max){
return Math.floor((Math.random() * max));
},
changeJSON: function(){
console.log('Changing JSON');
var charttype = ["area", "line", "bar"];
var max = 100;
var plots = 3;
var points = 15;
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink'];
var data = {
type: charttype[this.random(charttype.length)]
};
var series = [];
for (var i=0;i<plots;i++){
var color = colors[this.random(colors.length)];
var plot = {
lineColor: color,
backgroundColor: color
}
var plotdata = [];
for (var j=0;j<points;j++){
plotdata.push(this.random(max) + 1);
}
plot.values = plotdata;
series.push(plot);
}
data.series = series;
this.zc.set("json", data);
},
addPlot: function(){
var values = [];
for (var j=0;j<15;j++){
values.push(this.random(100) + 1);
}
this.zcView.exec('addplot', {
data : {
values : values
}
});
},
addLegend: function(){
var graph = this.zcView.exec('getdata');
if (graph.graphset){
graph = graph.graphset[0];
}
if(!graph.legend){
graph.legend = {};
}
this.zc.set('json', graph);
this.zcView.bind('legend_item_click', this.alertClick);
},
alertClick: function(){
alert("CLICKED");
},
changeData: function(){
console.log('Change Data');
var max = 100;
var plots = 3;
var points = 15;
var series = [];
for (var i=0;i<plots;i++){
var plotdata = [];
for (var j=0;j<points;j++){
plotdata.push(this.random(max) + 1);
}
series.push(plotdata);
}
this.zc.set("data", series);
}
});
var demo = new DemoView();
demo.render();
</script>
</body>
</html>
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
examples/chart_demo_extended.html
|
HTML
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>ZingChart Backbone Plugin - Simple Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
<script src="../lib/backbone.zingchart.extras.min.js"></script>
<script type="text/template" id="chart-template">
<div>
<button class="add-plot">Add Plot</button>
<button class="reset-json">Change JSON</button>
<button class="reset-data">Change Data</button>
<button class="toggle-legend">Toggle Legend</button>
<div id="chartDiv"></div>
</div>
</script>
<body>
<div id="demo"></div>
<script>
var DemoView = Backbone.View.extend({
el: '#demo',
template: _.template($('#chart-template').html()),
initialize: function() {
this.$el.empty();
this.zc = new ZingChart.ZingChartModel({data: [[3,2,3,3,9] , [1,2,3,4,5]],
width: 500,
height: 400});
this.render();
},
render: function() {
this.$el.html(this.template());
this.zcView = new ZingChart.ZingChartView({model: this.zc, el: $('#chartDiv')});
this.zcView.render();
return this;
},
events: {
'click .reset-json': 'changeJSON',
'click .reset-data': 'changeData',
'click .add-plot': 'addPlot',
'click .toggle-legend': 'addLegend'
},
random: function(max){
return Math.floor((Math.random() * max));
},
changeJSON: function(){
console.log('Changing JSON');
var charttype = ["area", "line", "bar"];
var max = 100;
var plots = 3;
var points = 15;
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink'];
var data = {
type: charttype[this.random(charttype.length)]
};
var series = [];
for (var i=0;i<plots;i++){
var color = colors[this.random(colors.length)];
var plot = {
lineColor: color,
backgroundColor: color
}
var plotdata = [];
for (var j=0;j<points;j++){
plotdata.push(this.random(max) + 1);
}
plot.values = plotdata;
series.push(plot);
}
data.series = series;
this.zc.set("json", data);
},
addPlot: function(){
var values = [];
for (var j=0;j<15;j++){
values.push(this.random(100) + 1);
}
this.zcView.addPlot({
data:{
values: values
}
});
},
addLegend: function(){
var graph = this.zcView.getData();
if (graph.graphset){
graph = graph.graphset[0];
}
if(!graph.legend){
graph.legend = {};
}
this.zc.set('json', graph);
this.zcView.legendItemClick(this.alertClick);
},
alertClick: function(){
alert("CLICKED");
},
changeData: function(){
console.log('Change Data');
var max = 100;
var plots = 3;
var points = 15;
var series = [];
for (var i=0;i<plots;i++){
var plotdata = [];
for (var j=0;j<points;j++){
plotdata.push(this.random(max) + 1);
}
series.push(plotdata);
}
this.zc.set("data", series);
}
});
var demo = new DemoView();
demo.render();
</script>
</body>
</html>
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
examples/chart_demo_json.html
|
HTML
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>ZingChart Backbone Plugin - Example using JSON</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
<script src="../lib/backbone.zingchart.min.js"></script>
<script type="text/template" id="chart-template">
<div id="chartDiv"></div>
</script>
<body>
<div id="demo"></div>
<script>
var DemoView = Backbone.View.extend({
el: '#demo',
template: _.template($('#chart-template').html()),
initialize: function() {
this.$el.empty();
var json = {
"type":"pie",
"series":[
{
"text":"Apples",
"values":[5]
},
{
"text":"Oranges",
"values":[8]
},
{
"text":"Bananas",
"values":[22]
}
]
};
this.zc = new ZingChart.ZingChartModel({json: json});
this.render();
},
render: function() {
this.$el.html(this.template());
this.zcView = new ZingChart.ZingChartView({model: this.zc, el: $('#chartDiv')});
this.zcView.render();
return this;
}
});
var demo = new DemoView();
demo.render();
</script>
</body>
</html>
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
lib/backbone.zingchart.extended.js
|
JavaScript
|
/*!
backbone-zingchart 1.0.1
Copyright (c) 2023 ZingChart
Licensed under the MIT license.
*/
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["underscore", "backbone"], function (_, Backbone) {
return (root.ZingChart = factory(_, Backbone));
});
} else if (typeof exports === "object") {
module.exports = factory(require("underscore"), require("backbone"));
} else {
root.ZingChart = factory(root._, root.Backbone);
}}(this, function (_, Backbone) {
var ZingChart = {};
if (typeof ZingChart === 'undefined'){ZingChart = {}};
ZingChart.ZingChartModel = Backbone.Model.extend({
defaults:{
width: 640,
height: 480,
json: {},
data: [],
charttype: 'line',
defaults: {},
events: null
}
});
ZingChart.ZingChartView = Backbone.View.extend({
initialize: function() {
this.listenTo(this.model, "change:json", this.updateChartJSON);
this.listenTo(this.model, "change:data", this.updateChartData);
},
render: function() {
var data = this.mergeJSONData();
zingchart.render({
id:this.el.id,
height:this.model.get('height'),
width:this.model.get('width'),
data:data,
defaults:this.model.get('defaults')
});
return this;
},
exec: function(apimethod, apioptions){
return zingchart.exec(this.el.id, apimethod, apioptions);
},
bind: function(eventname, callback){
zingchart.bind(this.el.id,eventname,callback);
return this;
},
mergeJSONData: function(){
var json = this.model.get('json');
var data = this.model.get('data');
if (typeof(json) === 'string'){
json = JSON.parse(json);
}
if (json.graphset && json.graphset.length === 1){
json = json.graphset[0];
}
if(data && data.length !== 0){
if (!json.series){
json.series = [];
}
for(var i = 0; i < data.length; i++){
if(json.series[i]){
json.series[i].values = data[i];
}
else{
json.series.push({'values' : data[i]});
}
}
}
if (!json.type){
json.type = this.model.get('charttype');
}
return json;
},
updateChartJSON: function(){
var newjson = this.model.get('json');
zingchart.exec(this.el.id, 'setdata',{
data : newjson
});
},
updateChartData: function(){
var newdata = this.model.get('data');
zingchart.exec(this.el.id, 'setseriesvalues',{
values : newdata
});
}
});
ZingChart.SimpleView = ZingChart.ZingChartView;
ZingChart.ZingChartView = ZingChart.SimpleView.extend({
//Direct API Access ==============================================================
// DATA MANIPULATION ======================================================
addNode: function (data) {
zingchart.exec(this.el.id, "addnode", data);
return this;
},
addPlot: function (data) {
zingchart.exec(this.el.id, "addplot", data);
return this;
},
appendSeriesData: function (data) {
zingchart.exec(this.el.id, "appendseriesdata", data);
return this;
},
appendSeriesValues: function (data) {
zingchart.exec(this.el.id, "appendseriesvalues", data);
return this;
},
getSeriesData: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getseriesdata", opts);
}
else {
return zingchart.exec(this.el.id, "getseriesdata", {});
}
},
getSeriesValues: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getseriesvalues", opts);
}
else {
return zingchart.exec(this.el.id, "getseriesvalues", {});
}
},
modifyPlot: function (data) {
zingchart.exec(this.el.id, "modifyplot", data);
return this;
},
removeNode: function (data) {
zingchart.exec(this.el.id, "removenode", data);
return this;
},
removePlot: function (data) {
zingchart.exec(this.el.id, "removeplot", data);
return this;
},
set3dView: function (data) {
zingchart.exec(this.el.id, "set3dview", data);
return this;
},
setNodeValue: function (data) {
zingchart.exec(this.el.id, "setnodevalue", data);
return this;
},
setSeriesData: function (data) {
zingchart.exec(this.el.id, "setseriesdata", data);
return this;
},
setSeriesValues: function (data) {
zingchart.exec(this.el.id, "setseriesvalues", data);
return this;
},
// EXPORT METHODS =========================================================
exportData: function () {
zingchart.exec(this.el.id, "exportdata");
return this;
},
getImageData: function (ftype) {
if (ftype == "png" || ftype == "jpg" || ftype == "bmp") {
zingchart.exec(this.el.id, "getimagedata", {
filetype: ftype
});
return this;
}
else {
throw("Error: Got " + ftype + ", expected 'png' or 'jpg' or 'bmp'");
}
},
print: function () {
zingchart.exec(this.el.id, "print");
return this;
},
saveAsImage: function () {
zingchart.exec(this.el.id, "saveasimage");
return this;
},
// FEED METHODS ===========================================================
clearFeed: function () {
zingchart.exec(this.el.id, "clearfeed");
return this;
},
getInterval: function () {
return zingchart.exec(this.el.id, "getinterval");
},
setInterval: function (intr) {
if (typeof(intr) == "number") {
zingchart.exec(this.el.id, "setinterval", {
interval: intr
});
return this;
}
else if (typeof(intr) == "object") {
zingchart.exec(this.el.id, "setinterval", intr);
return this;
}
else {
throw("Error: Got " + typeof(intr) + ", expected number");
}
},
startFeed: function () {
zingchart.exec(this.el.id, "startfeed");
return this;
},
stopFeed: function () {
zingchart.exec(this.el.id, "stopfeed");
return this;
},
// GRAPH INFORMATION METHODS ==============================================
getChartType: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getcharttype", opts);
}
else {
return zingchart.exec(this.el.id, "getcharttype");
}
},
getData: function () {
return zingchart.exec(this.el.id, "getdata");
},
getEditMode: function () {
return zingchart.exec(this.el.id, "geteditmode");
},
getGraphLength: function () {
return zingchart.exec(this.el.id, "getgraphlength");
},
getNodeLength: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getnodelength", opts);
}
else {
return zingchart.exec(this.el.id, "getnodelength");
}
},
getNodeValue: function (opts) {
return zingchart.exec(this.el.id, "getnodevalue", opts);
},
getObjectInfo: function (opts) {
return zingchart.exec(this.el.id, "getobjectinfo", opts);
},
getPlotLength: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getplotlength", opts);
}
else {
return zingchart.exec(this.el.id, "getplotlength");
}
},
getPlotValues: function (opts) {
return zingchart.exec(this.el.id, "getplotvalues", opts);
},
getRender: function () {
return zingchart.exec(this.el.id, "getrender");
},
getRules: function (opts) {
return zingchart.exec(this.el.id, "getrules", opts);
},
getScales: function (opts) {
return zingchart.exec(this.el.id, "getscales", opts);
},
getVersion: function () {
return zingchart.exec(this.el.id, "getversion");
},
getXYInfo: function (opts) {
return zingchart.exec(this.el.id, "getxyinfo", opts);
},
// GRAPH MANIPULATION =====================================================
addScaleValue: function (url) {
zingchart.exec(this.el.id, "addscalevalue", {
dataurl: url
});
return this;
},
destroy: function (opts) {
if (opts) {
if (opts.hasOwnProperty("")) {
}
}
else {
zingchart.exec(this.el.id, "destroy");
}
return this;
},
loadNewData: function (opts) {
zingchart.exec(this.el.id, "load", opts);
return this;
},
modify: function (opts) {
zingchart.exec(this.el.id, "modify", opts);
return this;
},
reloadChart: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "reload", opts);
}
else {
zingchart.exec(this.el.id, "reload");
}
return this;
},
removeScaleValue: function (opts) {
zingchart.exec(this.el.id, "removescalevalue", opts);
return this;
},
resizeChart: function (opts) {
zingchart.exec(this.el.id, "resize", opts);
return this;
},
setData: function (opts) {
zingchart.exec(this.el.id, "setdata", opts);
return this;
},
update: function (opts) {
zingchart.exec(this.el.id, "update");
return this;
},
// HISTORY METHODS ========================================================
goBack: function () {
zingchart.exec(this.el.id, "goback");
return this;
},
goForward: function () {
zingchart.exec(this.el.id, "goforward");
return this;
},
// INTERACTIVE METHODS ====================================================
addNodeIA: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "addnodeia", opts);
}
else {
zingchart.exec(this.el.id, "addnodeia");
}
return this;
},
enterEditMode: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "entereditmode", opts);
}
else {
zingchart.exec(this.el.id, "entereditmode");
}
return this;
},
exitEditMode: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "exiteditmode", opts);
}
else {
zingchart.exec(this.el.id, "exiteditmode");
}
return this;
},
removeNodeIA: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "removenodeia", opts);
}
else {
zingchart.exec(this.el.id, "removenodeia");
}
return this;
},
removePlotIA: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "removeplotia", opts);
}
else {
zingchart.exec(this.el.id, "removeplotia");
}
return this;
},
// NOTES METHODS ==========================================================
addNote: function (opts) {
zingchart.exec(this.el.id, "addnote", opts);
return this;
},
removeNote: function (opts) {
zingchart.exec(this.el.id, "removenote", {
"id": opts
});
return this;
},
updateNote: function (opts) {
zingchart.exec(this.el.id, "updatenote", opts);
return this;
},
// OBJECTS METHODS ========================================================
addObject: function (opts) {
zingchart.exec(this.el.id, "addobject", opts);
return this;
},
removeObject: function (opts) {
zingchart.exec(this.el.id, "removeobject", opts);
return this;
},
repaintObjects: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "repaintobjects", opts);
}
else {
zingchart.exec(this.el.id, "repaintobjects", {});
}
return this;
},
updateObject: function (opts) {
zingchart.exec(this.el.id, "updateobject", opts);
return this;
},
// LABEL METHODS ==========================================================
addLabel: function (opts) {
zingchart.exec(this.el.id, "addobject", {
"type":"label",
"data":opts
});
return this;
},
removeLabel: function (opts) {
zingchart.exec(this.el.id, "removeobject", {
"type":"label",
"id":opts
});
return this;
},
updateLabel: function (opts) {
zingchart.exec(this.el.id, "updateobject", {
"type": "label",
"data": opts
});
return this;
},
// RULES METHODS ==========================================================
addRule: function (opts) {
zingchart.exec(this.el.id, "addrule", opts);
return this;
},
removeRule: function (opts) {
zingchart.exec(this.el.id, "removerule", opts);
return this;
},
updateRule: function (opts) {
zingchart.exec(this.el.id, "updaterule", opts);
return this;
},
// SELECTION METHODS ======================================================
clearSelection: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "clearselection", opts);
}
else {
zingchart.exec(this.el.id, "clearselection");
}
return this;
},
chartDeselect: function (opts) {
zingchart.exec(this.el.id, "deselect", opts);
return this;
},
getSelection: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "getselection", opts);
}
else {
zingchart.exec(this.el.id, "getselection");
}
return this;
},
chartSelect: function (opts) {
zingchart.exec(this.el.id, "select", opts);
return this;
},
setSelection: function (opts) {
zingchart.exec(this.el.id, "setselection", opts);
return this;
},
// TOGGLE METHODS =========================================================
disable: function (message) {
if (message) {
zingchart.exec(this.el.id, "disable", {text: message});
}
else {
zingchart.exec(this.el.id, "disable");
}
return this;
},
enable: function () {
zingchart.exec(this.el.id, "enable");
return this;
},
exitFullscreen: function () {
zingchart.exec(this.el.id, "exitfullscreen");
return this;
},
fullscreen: function () {
zingchart.exec(this.el.id, "fullscreen");
return this;
},
hideMenu: function () {
zingchart.exec(this.el.id, "hidemenu");
return this;
},
hidePlot: function (opts) {
zingchart.exec(this.el.id, "hideplot", opts);
return this;
},
hideAllPlots: function (opts) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid')) {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "hideplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
else {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "hideplot", {
"plotindex": i
});
}
}
return this;
},
hideAllPlotsBut: function (opts) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid') && opts.hasOwnProperty('plotindex')) {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "hideplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
}
else {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "hideplot", {
"plotindex": i
});
}
}
}
return this;
},
modifyAllPlotsBut: function (opts, data) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid') && opts.hasOwnProperty('plotindex')) {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "modifyplot", {
"graphid": opts.graphid,
"plotindex": i,
"data": data
});
}
}
}
else {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "modifyplot", {
"plotindex": i,
"data": data
});
}
}
}
return this;
},
modifyAllPlots: function (data, opts) {
var myId = this.el.id;
var allPlots = ( opts ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
for (var i = 0; i < allPlots; i++) {
if (opts && opts.graphid) {
zingchart.exec(myId, "modifyplot", {
"graphid": opts.graphid,
"plotindex": i,
"data": data
});
}
else {
zingchart.exec(myId, "modifyplot", {
"plotindex": i,
"data": data
});
}
}
return this;
},
showAllPlots: function (opts) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid')) {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "showplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
else {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "showplot", {
"plotindex": i
});
}
}
return this;
},
showAllPlotsBut: function (opts) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid') && opts.hasOwnProperty('plotindex')) {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "showplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
}
else {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "showplot", {
"plotindex": i
});
}
}
}
return this;
},
legendMaximize: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "legendmaximize", opts);
}
else {
zingchart.exec(this.el.id, "legendmaximize");
}
return this;
},
legendMinimize: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "legendminimize", opts);
}
else {
zingchart.exec(this.el.id, "legendminimize");
}
return this;
},
showMenu: function () {
zingchart.exec(this.el.id, "showmenu");
return this;
},
showPlot: function (opts) {
zingchart.exec(this.el.id, "showplot", opts);
return this;
},
toggleAbout: function () {
zingchart.exec(this.el.id, "toggleabout");
return this;
},
toggleBugReport: function () {
zingchart.exec(this.el.id, "togglebugreport");
return this;
},
toggleDimension: function () {
zingchart.exec(this.el.id, "toggledimension");
return this;
},
toggleLegend: function () {
zingchart.exec(this.el.id, "togglelegend");
return this;
},
toggleLens: function () {
zingchart.exec(this.el.id, "togglelens");
return this;
},
toggleSource: function () {
zingchart.exec(this.el.id, "togglesource");
return this;
},
// ZOOM METHODS ===========================================================
viewAll: function () {
zingchart.exec(this.el.id, "viewall");
return this;
},
zoomIn: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "zoomin", opts);
}
else {
zingchart.exec(this.el.id, "zoomin");
}
return this;
},
zoomOut: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "zoomout", opts);
}
else {
zingchart.exec(this.el.id, "zoomout");
}
return this;
},
zoomTo: function (opts) {
zingchart.exec(this.el.id, "zoomto", opts);
return this;
},
zoomToValues: function (opts) {
zingchart.exec(this.el.id, "zoomtovalues", opts);
return this;
},
/*********************************************************************
****************************** EVENTS *******************************
*********************************************************************/
// ANIMATION EVENTS ====================================================
animationEnd: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "animationEnd", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
animationStart: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "animation_start", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
animationStep: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "animation_step", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// DATA MANIPULATION EVENTS ===============================================
chartModify: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "modify", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeAdd: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_add", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeRemove: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_remove", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotAdd: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_add", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotModify: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_modify", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotRemove: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_remove", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
chartReload: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "reload", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
dataSet: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "setdata", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// EXPORT EVENTS ==========================================================
dataExport: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "data_export", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
imageSave: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "image_save", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
chartPrint: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "print", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// FEED EVENTS ============================================================
feedClear: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "feed_clear", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
feedIntervalModify: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "feed_interval_modify", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
feedStart: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "feed_start", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
feedStop: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "feed_stop", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// GLOBAL EVENTS
graphClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphComplete: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "complete", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphDataParse: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "dataparse", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphDataReady: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "dataready", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphGuideMouseMove: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "guide_mousemove", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphLoad: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "load", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphMenuItemClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "menu_item_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphResize: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "resize", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// HISTORY EVENTS =========================================================
historyForward: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "history_forward", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
historyBack: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "history_back", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// INTERACTIVE EVENTS =====================================================
nodeSelect: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_select", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeDeselect: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_deselect", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotSelect: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_select", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotDeselect: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_deselect", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// LEGEND EVENTS ==========================================================
legendItemClick: function (callback) {
zingchart.bind(this.el.id, "legend_item_click", callback);
/*var jq = this;
zingchart.bind(this.el.id, "legend_item_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});*/
return this;
},
legendMarkerClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_marker_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// NODE EVENTS ============================================================
nodeClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeDoubleClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_doubleclick", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeMouseOver: function (callback) {
var jq = this;
var NODEMOUSEOVER = false;
zingchart.bind(this.el.id, "node_mouseover", function(p){
if (!NODEMOUSEOVER) {
$.extend(jq,{event:p});
NODEMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "node_mouseout", function(){
NODEMOUSEOVER = false;
});
return this;
},
nodeMouseOut: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq);
});
return this;
},
nodeHover: function (mouseover, mouseout) {
var jq = this;
var NODEMOUSEOVER = false;
zingchart.bind(this.el.id, "node_mouseover", function(p){
if (!NODEMOUSEOVER) {
$.extend(jq,{event:p});
NODEMOUSEOVER = true;
mouseover.call(jq);
}
});
zingchart.bind(jq[0].id, "node_mouseout", function(){
NODEMOUSEOVER = false;
mouseout.call(jq);
});
return this;
},
// LABEL EVENTS ============================================================
labelClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "label_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
labelMouseOver: function (callback) {
var jq = this;
var LABELMOUSEOVER = false;
zingchart.bind(this.el.id, "label_mouseover", function(p){
if (!LABELMOUSEOVER) {
$.extend(jq,{event:p});
LABELMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "label_mouseout", function(){
LABELMOUSEOVER = false;
});
return this;
},
labelMouseOut: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "label_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
labelHover: function (mouseover, mouseout) {
$(this).labelMouseOver(mouseover).labelMouseOut(mouseout);
return this;
},
// SHAPE EVENTS ============================================================
shapeClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "shape_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
shapeMouseOver: function (callback) {
var jq = this;
var SHAPEMOUSEOVER = false;
zingchart.bind(this.el.id, "shape_mouseover", function(p){
if (!SHAPEMOUSEOVER) {
$.extend(jq,{event:p});
SHAPEMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "shape_mouseout", function(){
SHAPEMOUSEOVER = false;
});
return this;
},
shapeMouseOut: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "shape_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
shapeHover: function (mouseover, mouseout) {
$(this).shapeMouseOver(mouseover).shapeMouseOut(mouseout);
return this;
},
// PLOT EVENTS ============================================================
plotClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotDoubleClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_doubleclick", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotMouseOver: function (callback) {
var jq = this;
var PLOTMOUSEOVER = false;
zingchart.bind(this.el.id, "plot_mouseover", function(p){
if (!PLOTMOUSEOVER) {
$.extend(jq,{event:p});
PLOTMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "plot_mouseout", function(){
PLOTMOUSEOVER = false;
});
return this;
},
plotMouseOut: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotHover: function (mouseover, mouseout) {
$(this).plotMouseOver(mouseover).plotMouseOut(mouseout);
return this;
},
plotShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// TOGGLE EVENTS ==========================================================
aboutShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "about_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
aboutHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "about_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
bugReportShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "bugreport_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
bugReportHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "bugreport_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
dimensionChange: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "dimension_change", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
lensShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "lens_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
lensHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "lens_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
sourceShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "source_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
sourceHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "source_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
legendShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
legendHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
legendMaximize: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_maximize", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
legendMinimize: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_minimize", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
zoomEvent: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "zoom", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
/*********************************************************************
********************** HELPER METHODS *******************************
*********************************************************************/
setTitle: function (newtitle) {
if (typeof(newtitle) == 'object') {
zingchart.exec(this.el.id, "modify", {
data: {
title: newtitle
}
});
}
else {
zingchart.exec(this.el.id, "modify", {
data: {
title: {
text: newtitle
}
}
});
}
return this;
},
setSubtitle: function (newtitle) {
if (typeof(newtitle) == 'object') {
zingchart.exec(this.el.id, "modify", {
data: {
subtitle: newtitle
}
});
}
else {
zingchart.exec(this.el.id, "modify", {
data: {
subtitle: {
text: newtitle
}
}
});
}
return this;
},
setType: function (type) {
zingchart.exec(this.el.id, "modify", {
"data": {
"type": type
}
});
zingchart.exec(this.el.id,"update");
return this;
},
drawTrendline: function (opts) {
var myId = this.el.id;
calculate.call(this,0);
function calculate(pindex) {
var nodes = $(this).getSeriesValues({
plotindex:pindex
});
var sxy = 0, sx = 0, sy = 0, sx2 = 0, l = 0;
var oScaleInfo = $(this).getObjectInfo({
object : 'scale',
name : 'scale-x'
});
var aScaleValues = oScaleInfo.values;
for (var i=0;i<nodes.length;i++) {
if (nodes[i][1] != undefined && typeof(nodes[i][1]) == 'number') {
sxy += nodes[i][0]*nodes[i][1];
sx += nodes[i][0];
sy += nodes[i][1];
sx2 += nodes[i][0]*nodes[i][0];
l++;
}
else {
sxy += nodes[i]*aScaleValues[i];
sx += aScaleValues[i];
sy += nodes[i];
sx2 += Math.pow(aScaleValues[i],2);
l++;
}
}
var b = (l * sxy - sx * sy) / (l * sx2 - sx * sx);
var a = (sy - b * sx) / l;
var oScaleInfo = $(this).getObjectInfo({
object : 'scale',
name : 'scale-x'
});
var aScaleValues = oScaleInfo.values, fScaleMin = aScaleValues[0], fScaleMax = aScaleValues[aScaleValues.length-1];
var aRange = [a + b*fScaleMin, a + b*fScaleMax];
var trendline = {
type : 'line',
lineColor : '#c00',
lineWidth : 2,
alpha : 0.75,
lineStyle : 'dashed',
label : {
text : ''
}
};
if (opts) {
$.extend(trendline,opts);
}
trendline.range = aRange;
var scaleY = $(this).getObjectInfo({
object:'scale',
name: 'scale-y'
});
var markers = scaleY.markers;
if (markers) {
markers.push(trendline);
}
else {
markers = [trendline];
}
$(this).modify({
"data": {
"scale-y": {
"markers": markers
}
}
});
}
return this;
}
});
return ZingChart;
}));
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
lib/backbone.zingchart.extended.min.js
|
JavaScript
|
!function(i,n){"function"==typeof define&&define.amd?define(["underscore","backbone"],function(e,t){return i.ZingChart=n(0,t)}):"object"==typeof exports?module.exports=n(require("underscore"),require("backbone")):i.ZingChart=n(i._,i.Backbone)}(this,function(e,t){var i={};return(i=void 0===i?{}:i).ZingChartModel=t.Model.extend({defaults:{width:640,height:480,json:{},data:[],charttype:"line",defaults:{},events:null}}),i.ZingChartView=t.View.extend({initialize:function(){this.listenTo(this.model,"change:json",this.updateChartJSON),this.listenTo(this.model,"change:data",this.updateChartData)},render:function(){var e=this.mergeJSONData();return zingchart.render({id:this.el.id,height:this.model.get("height"),width:this.model.get("width"),data:e,defaults:this.model.get("defaults")}),this},exec:function(e,t){return zingchart.exec(this.el.id,e,t)},bind:function(e,t){return zingchart.bind(this.el.id,e,t),this},mergeJSONData:function(){var e=this.model.get("json"),t=this.model.get("data");if((e="string"==typeof e?JSON.parse(e):e).graphset&&1===e.graphset.length&&(e=e.graphset[0]),t&&0!==t.length){e.series||(e.series=[]);for(var i=0;i<t.length;i++)e.series[i]?e.series[i].values=t[i]:e.series.push({values:t[i]})}return e.type||(e.type=this.model.get("charttype")),e},updateChartJSON:function(){var e=this.model.get("json");zingchart.exec(this.el.id,"setdata",{data:e})},updateChartData:function(){var e=this.model.get("data");zingchart.exec(this.el.id,"setseriesvalues",{values:e})}}),i.SimpleView=i.ZingChartView,i.ZingChartView=i.SimpleView.extend({addNode:function(e){return zingchart.exec(this.el.id,"addnode",e),this},addPlot:function(e){return zingchart.exec(this.el.id,"addplot",e),this},appendSeriesData:function(e){return zingchart.exec(this.el.id,"appendseriesdata",e),this},appendSeriesValues:function(e){return zingchart.exec(this.el.id,"appendseriesvalues",e),this},getSeriesData:function(e){return e?zingchart.exec(this.el.id,"getseriesdata",e):zingchart.exec(this.el.id,"getseriesdata",{})},getSeriesValues:function(e){return e?zingchart.exec(this.el.id,"getseriesvalues",e):zingchart.exec(this.el.id,"getseriesvalues",{})},modifyPlot:function(e){return zingchart.exec(this.el.id,"modifyplot",e),this},removeNode:function(e){return zingchart.exec(this.el.id,"removenode",e),this},removePlot:function(e){return zingchart.exec(this.el.id,"removeplot",e),this},set3dView:function(e){return zingchart.exec(this.el.id,"set3dview",e),this},setNodeValue:function(e){return zingchart.exec(this.el.id,"setnodevalue",e),this},setSeriesData:function(e){return zingchart.exec(this.el.id,"setseriesdata",e),this},setSeriesValues:function(e){return zingchart.exec(this.el.id,"setseriesvalues",e),this},exportData:function(){return zingchart.exec(this.el.id,"exportdata"),this},getImageData:function(e){if("png"==e||"jpg"==e||"bmp"==e)return zingchart.exec(this.el.id,"getimagedata",{filetype:e}),this;throw"Error: Got "+e+", expected 'png' or 'jpg' or 'bmp'"},print:function(){return zingchart.exec(this.el.id,"print"),this},saveAsImage:function(){return zingchart.exec(this.el.id,"saveasimage"),this},clearFeed:function(){return zingchart.exec(this.el.id,"clearfeed"),this},getInterval:function(){return zingchart.exec(this.el.id,"getinterval")},setInterval:function(e){if("number"==typeof e)return zingchart.exec(this.el.id,"setinterval",{interval:e}),this;if("object"==typeof e)return zingchart.exec(this.el.id,"setinterval",e),this;throw"Error: Got "+typeof e+", expected number"},startFeed:function(){return zingchart.exec(this.el.id,"startfeed"),this},stopFeed:function(){return zingchart.exec(this.el.id,"stopfeed"),this},getChartType:function(e){return e?zingchart.exec(this.el.id,"getcharttype",e):zingchart.exec(this.el.id,"getcharttype")},getData:function(){return zingchart.exec(this.el.id,"getdata")},getEditMode:function(){return zingchart.exec(this.el.id,"geteditmode")},getGraphLength:function(){return zingchart.exec(this.el.id,"getgraphlength")},getNodeLength:function(e){return e?zingchart.exec(this.el.id,"getnodelength",e):zingchart.exec(this.el.id,"getnodelength")},getNodeValue:function(e){return zingchart.exec(this.el.id,"getnodevalue",e)},getObjectInfo:function(e){return zingchart.exec(this.el.id,"getobjectinfo",e)},getPlotLength:function(e){return e?zingchart.exec(this.el.id,"getplotlength",e):zingchart.exec(this.el.id,"getplotlength")},getPlotValues:function(e){return zingchart.exec(this.el.id,"getplotvalues",e)},getRender:function(){return zingchart.exec(this.el.id,"getrender")},getRules:function(e){return zingchart.exec(this.el.id,"getrules",e)},getScales:function(e){return zingchart.exec(this.el.id,"getscales",e)},getVersion:function(){return zingchart.exec(this.el.id,"getversion")},getXYInfo:function(e){return zingchart.exec(this.el.id,"getxyinfo",e)},addScaleValue:function(e){return zingchart.exec(this.el.id,"addscalevalue",{dataurl:e}),this},destroy:function(e){return e?e.hasOwnProperty(""):zingchart.exec(this.el.id,"destroy"),this},loadNewData:function(e){return zingchart.exec(this.el.id,"load",e),this},modify:function(e){return zingchart.exec(this.el.id,"modify",e),this},reloadChart:function(e){return e?zingchart.exec(this.el.id,"reload",e):zingchart.exec(this.el.id,"reload"),this},removeScaleValue:function(e){return zingchart.exec(this.el.id,"removescalevalue",e),this},resizeChart:function(e){return zingchart.exec(this.el.id,"resize",e),this},setData:function(e){return zingchart.exec(this.el.id,"setdata",e),this},update:function(e){return zingchart.exec(this.el.id,"update"),this},goBack:function(){return zingchart.exec(this.el.id,"goback"),this},goForward:function(){return zingchart.exec(this.el.id,"goforward"),this},addNodeIA:function(e){return e?zingchart.exec(this.el.id,"addnodeia",e):zingchart.exec(this.el.id,"addnodeia"),this},enterEditMode:function(e){return e?zingchart.exec(this.el.id,"entereditmode",e):zingchart.exec(this.el.id,"entereditmode"),this},exitEditMode:function(e){return e?zingchart.exec(this.el.id,"exiteditmode",e):zingchart.exec(this.el.id,"exiteditmode"),this},removeNodeIA:function(e){return e?zingchart.exec(this.el.id,"removenodeia",e):zingchart.exec(this.el.id,"removenodeia"),this},removePlotIA:function(e){return e?zingchart.exec(this.el.id,"removeplotia",e):zingchart.exec(this.el.id,"removeplotia"),this},addNote:function(e){return zingchart.exec(this.el.id,"addnote",e),this},removeNote:function(e){return zingchart.exec(this.el.id,"removenote",{id:e}),this},updateNote:function(e){return zingchart.exec(this.el.id,"updatenote",e),this},addObject:function(e){return zingchart.exec(this.el.id,"addobject",e),this},removeObject:function(e){return zingchart.exec(this.el.id,"removeobject",e),this},repaintObjects:function(e){return e?zingchart.exec(this.el.id,"repaintobjects",e):zingchart.exec(this.el.id,"repaintobjects",{}),this},updateObject:function(e){return zingchart.exec(this.el.id,"updateobject",e),this},addLabel:function(e){return zingchart.exec(this.el.id,"addobject",{type:"label",data:e}),this},removeLabel:function(e){return zingchart.exec(this.el.id,"removeobject",{type:"label",id:e}),this},updateLabel:function(e){return zingchart.exec(this.el.id,"updateobject",{type:"label",data:e}),this},addRule:function(e){return zingchart.exec(this.el.id,"addrule",e),this},removeRule:function(e){return zingchart.exec(this.el.id,"removerule",e),this},updateRule:function(e){return zingchart.exec(this.el.id,"updaterule",e),this},clearSelection:function(e){return e?zingchart.exec(this.el.id,"clearselection",e):zingchart.exec(this.el.id,"clearselection"),this},chartDeselect:function(e){return zingchart.exec(this.el.id,"deselect",e),this},getSelection:function(e){return e?zingchart.exec(this.el.id,"getselection",e):zingchart.exec(this.el.id,"getselection"),this},chartSelect:function(e){return zingchart.exec(this.el.id,"select",e),this},setSelection:function(e){return zingchart.exec(this.el.id,"setselection",e),this},disable:function(e){return e?zingchart.exec(this.el.id,"disable",{text:e}):zingchart.exec(this.el.id,"disable"),this},enable:function(){return zingchart.exec(this.el.id,"enable"),this},exitFullscreen:function(){return zingchart.exec(this.el.id,"exitfullscreen"),this},fullscreen:function(){return zingchart.exec(this.el.id,"fullscreen"),this},hideMenu:function(){return zingchart.exec(this.el.id,"hidemenu"),this},hidePlot:function(e){return zingchart.exec(this.el.id,"hideplot",e),this},hideAllPlots:function(e){var t=this.el.id,i=e&&e.hasOwnProperty("graphid")?zingchart.exec(t,"getplotlength",e):zingchart.exec(t,"getplotlength");if(e&&e.hasOwnProperty("graphid"))for(var n=0;n<i;n++)zingchart.exec(t,"hideplot",{graphid:e.graphid,plotindex:n});else for(n=0;n<i;n++)zingchart.exec(t,"hideplot",{plotindex:n});return this},hideAllPlotsBut:function(e){var t=this.el.id,i=e&&e.hasOwnProperty("graphid")?zingchart.exec(t,"getplotlength",e):zingchart.exec(t,"getplotlength");if(e&&e.hasOwnProperty("graphid")&&e.hasOwnProperty("plotindex"))for(var n=0;n<i;n++)n!=e.plotindex&&zingchart.exec(t,"hideplot",{graphid:e.graphid,plotindex:n});else for(n=0;n<i;n++)n!=e.plotindex&&zingchart.exec(t,"hideplot",{plotindex:n});return this},modifyAllPlotsBut:function(e,t){var i=this.el.id,n=e&&e.hasOwnProperty("graphid")?zingchart.exec(i,"getplotlength",e):zingchart.exec(i,"getplotlength");if(e&&e.hasOwnProperty("graphid")&&e.hasOwnProperty("plotindex"))for(var r=0;r<n;r++)r!=e.plotindex&&zingchart.exec(i,"modifyplot",{graphid:e.graphid,plotindex:r,data:t});else for(r=0;r<n;r++)r!=e.plotindex&&zingchart.exec(i,"modifyplot",{plotindex:r,data:t});return this},modifyAllPlots:function(e,t){for(var i=this.el.id,n=t?zingchart.exec(i,"getplotlength",t):zingchart.exec(i,"getplotlength"),r=0;r<n;r++)t&&t.graphid?zingchart.exec(i,"modifyplot",{graphid:t.graphid,plotindex:r,data:e}):zingchart.exec(i,"modifyplot",{plotindex:r,data:e});return this},showAllPlots:function(e){var t=this.el.id,i=e&&e.hasOwnProperty("graphid")?zingchart.exec(t,"getplotlength",e):zingchart.exec(t,"getplotlength");if(e&&e.hasOwnProperty("graphid"))for(var n=0;n<i;n++)zingchart.exec(t,"showplot",{graphid:e.graphid,plotindex:n});else for(n=0;n<i;n++)zingchart.exec(t,"showplot",{plotindex:n});return this},showAllPlotsBut:function(e){var t=this.el.id,i=e&&e.hasOwnProperty("graphid")?zingchart.exec(t,"getplotlength",e):zingchart.exec(t,"getplotlength");if(e&&e.hasOwnProperty("graphid")&&e.hasOwnProperty("plotindex"))for(var n=0;n<i;n++)n!=e.plotindex&&zingchart.exec(t,"showplot",{graphid:e.graphid,plotindex:n});else for(n=0;n<i;n++)n!=e.plotindex&&zingchart.exec(t,"showplot",{plotindex:n});return this},legendMaximize:function(t){var i=this;return zingchart.bind(this.el.id,"legend_maximize",function(e){$.extend(i,{event:e}),t.call(i)}),this},legendMinimize:function(t){var i=this;return zingchart.bind(this.el.id,"legend_minimize",function(e){$.extend(i,{event:e}),t.call(i)}),this},showMenu:function(){return zingchart.exec(this.el.id,"showmenu"),this},showPlot:function(e){return zingchart.exec(this.el.id,"showplot",e),this},toggleAbout:function(){return zingchart.exec(this.el.id,"toggleabout"),this},toggleBugReport:function(){return zingchart.exec(this.el.id,"togglebugreport"),this},toggleDimension:function(){return zingchart.exec(this.el.id,"toggledimension"),this},toggleLegend:function(){return zingchart.exec(this.el.id,"togglelegend"),this},toggleLens:function(){return zingchart.exec(this.el.id,"togglelens"),this},toggleSource:function(){return zingchart.exec(this.el.id,"togglesource"),this},viewAll:function(){return zingchart.exec(this.el.id,"viewall"),this},zoomIn:function(e){return e?zingchart.exec(this.el.id,"zoomin",e):zingchart.exec(this.el.id,"zoomin"),this},zoomOut:function(e){return e?zingchart.exec(this.el.id,"zoomout",e):zingchart.exec(this.el.id,"zoomout"),this},zoomTo:function(e){return zingchart.exec(this.el.id,"zoomto",e),this},zoomToValues:function(e){return zingchart.exec(this.el.id,"zoomtovalues",e),this},animationEnd:function(t){var i=this;return zingchart.bind(this.el.id,"animationEnd",function(e){$.extend(i,{event:e}),t.call(i)}),this},animationStart:function(t){var i=this;return zingchart.bind(this.el.id,"animation_start",function(e){$.extend(i,{event:e}),t.call(i)}),this},animationStep:function(t){var i=this;return zingchart.bind(this.el.id,"animation_step",function(e){$.extend(i,{event:e}),t.call(i)}),this},chartModify:function(t){var i=this;return zingchart.bind(this.el.id,"modify",function(e){$.extend(i,{event:e}),t.call(i)}),this},nodeAdd:function(t){var i=this;return zingchart.bind(this.el.id,"node_add",function(e){$.extend(i,{event:e}),t.call(i)}),this},nodeRemove:function(t){var i=this;return zingchart.bind(this.el.id,"node_remove",function(e){$.extend(i,{event:e}),t.call(i)}),this},plotAdd:function(t){var i=this;return zingchart.bind(this.el.id,"plot_add",function(e){$.extend(i,{event:e}),t.call(i)}),this},plotModify:function(t){var i=this;return zingchart.bind(this.el.id,"plot_modify",function(e){$.extend(i,{event:e}),t.call(i)}),this},plotRemove:function(t){var i=this;return zingchart.bind(this.el.id,"plot_remove",function(e){$.extend(i,{event:e}),t.call(i)}),this},chartReload:function(t){var i=this;return zingchart.bind(this.el.id,"reload",function(e){$.extend(i,{event:e}),t.call(i)}),this},dataSet:function(t){var i=this;return zingchart.bind(this.el.id,"setdata",function(e){$.extend(i,{event:e}),t.call(i)}),this},dataExport:function(t){var i=this;return zingchart.bind(this.el.id,"data_export",function(e){$.extend(i,{event:e}),t.call(i)}),this},imageSave:function(t){var i=this;return zingchart.bind(this.el.id,"image_save",function(e){$.extend(i,{event:e}),t.call(i)}),this},chartPrint:function(t){var i=this;return zingchart.bind(this.el.id,"print",function(e){$.extend(i,{event:e}),t.call(i)}),this},feedClear:function(t){var i=this;return zingchart.bind(this.el.id,"feed_clear",function(e){$.extend(i,{event:e}),t.call(i)}),this},feedIntervalModify:function(t){var i=this;return zingchart.bind(this.el.id,"feed_interval_modify",function(e){$.extend(i,{event:e}),t.call(i)}),this},feedStart:function(t){var i=this;return zingchart.bind(this.el.id,"feed_start",function(e){$.extend(i,{event:e}),t.call(i)}),this},feedStop:function(t){var i=this;return zingchart.bind(this.el.id,"feed_stop",function(e){$.extend(i,{event:e}),t.call(i)}),this},graphClick:function(t){var i=this;return zingchart.bind(this.el.id,"click",function(e){$.extend(i,{event:e}),t.call(i)}),this},graphComplete:function(t){var i=this;return zingchart.bind(this.el.id,"complete",function(e){$.extend(i,{event:e}),t.call(i)}),this},graphDataParse:function(t){var i=this;return zingchart.bind(this.el.id,"dataparse",function(e){$.extend(i,{event:e}),t.call(i)}),this},graphDataReady:function(t){var i=this;return zingchart.bind(this.el.id,"dataready",function(e){$.extend(i,{event:e}),t.call(i)}),this},graphGuideMouseMove:function(t){var i=this;return zingchart.bind(this.el.id,"guide_mousemove",function(e){$.extend(i,{event:e}),t.call(i)}),this},graphLoad:function(t){var i=this;return zingchart.bind(this.el.id,"load",function(e){$.extend(i,{event:e}),t.call(i)}),this},graphMenuItemClick:function(t){var i=this;return zingchart.bind(this.el.id,"menu_item_click",function(e){$.extend(i,{event:e}),t.call(i)}),this},graphResize:function(t){var i=this;return zingchart.bind(this.el.id,"resize",function(e){$.extend(i,{event:e}),t.call(i)}),this},historyForward:function(t){var i=this;return zingchart.bind(this.el.id,"history_forward",function(e){$.extend(i,{event:e}),t.call(i)}),this},historyBack:function(t){var i=this;return zingchart.bind(this.el.id,"history_back",function(e){$.extend(i,{event:e}),t.call(i)}),this},nodeSelect:function(t){var i=this;return zingchart.bind(this.el.id,"node_select",function(e){$.extend(i,{event:e}),t.call(i)}),this},nodeDeselect:function(t){var i=this;return zingchart.bind(this.el.id,"node_deselect",function(e){$.extend(i,{event:e}),t.call(i)}),this},plotSelect:function(t){var i=this;return zingchart.bind(this.el.id,"plot_select",function(e){$.extend(i,{event:e}),t.call(i)}),this},plotDeselect:function(t){var i=this;return zingchart.bind(this.el.id,"plot_deselect",function(e){$.extend(i,{event:e}),t.call(i)}),this},legendItemClick:function(e){return zingchart.bind(this.el.id,"legend_item_click",e),this},legendMarkerClick:function(t){var i=this;return zingchart.bind(this.el.id,"legend_marker_click",function(e){$.extend(i,{event:e}),t.call(i)}),this},nodeClick:function(t){var i=this;return zingchart.bind(this.el.id,"node_click",function(e){$.extend(i,{event:e}),t.call(i)}),this},nodeDoubleClick:function(t){var i=this;return zingchart.bind(this.el.id,"node_doubleclick",function(e){$.extend(i,{event:e}),t.call(i)}),this},nodeMouseOver:function(t){var i=this,n=!1;return zingchart.bind(this.el.id,"node_mouseover",function(e){n||($.extend(i,{event:e}),n=!0,t.call(i))}),zingchart.bind(i[0].id,"node_mouseout",function(){n=!1}),this},nodeMouseOut:function(t){var i=this;return zingchart.bind(this.el.id,"node_mouseout",function(e){$.extend(i,{event:e}),t.call(i)}),this},nodeHover:function(t,e){var i=this,n=!1;return zingchart.bind(this.el.id,"node_mouseover",function(e){n||($.extend(i,{event:e}),n=!0,t.call(i))}),zingchart.bind(i[0].id,"node_mouseout",function(){n=!1,e.call(i)}),this},labelClick:function(t){var i=this;return zingchart.bind(this.el.id,"label_click",function(e){$.extend(i,{event:e}),t.call(i)}),this},labelMouseOver:function(t){var i=this,n=!1;return zingchart.bind(this.el.id,"label_mouseover",function(e){n||($.extend(i,{event:e}),n=!0,t.call(i))}),zingchart.bind(i[0].id,"label_mouseout",function(){n=!1}),this},labelMouseOut:function(t){var i=this;return zingchart.bind(this.el.id,"label_mouseout",function(e){$.extend(i,{event:e}),t.call(i)}),this},labelHover:function(e,t){return $(this).labelMouseOver(e).labelMouseOut(t),this},shapeClick:function(t){var i=this;return zingchart.bind(this.el.id,"shape_click",function(e){$.extend(i,{event:e}),t.call(i)}),this},shapeMouseOver:function(t){var i=this,n=!1;return zingchart.bind(this.el.id,"shape_mouseover",function(e){n||($.extend(i,{event:e}),n=!0,t.call(i))}),zingchart.bind(i[0].id,"shape_mouseout",function(){n=!1}),this},shapeMouseOut:function(t){var i=this;return zingchart.bind(this.el.id,"shape_mouseout",function(e){$.extend(i,{event:e}),t.call(i)}),this},shapeHover:function(e,t){return $(this).shapeMouseOver(e).shapeMouseOut(t),this},plotClick:function(t){var i=this;return zingchart.bind(this.el.id,"plot_click",function(e){$.extend(i,{event:e}),t.call(i)}),this},plotDoubleClick:function(t){var i=this;return zingchart.bind(this.el.id,"plot_doubleclick",function(e){$.extend(i,{event:e}),t.call(i)}),this},plotMouseOver:function(t){var i=this,n=!1;return zingchart.bind(this.el.id,"plot_mouseover",function(e){n||($.extend(i,{event:e}),n=!0,t.call(i))}),zingchart.bind(i[0].id,"plot_mouseout",function(){n=!1}),this},plotMouseOut:function(t){var i=this;return zingchart.bind(this.el.id,"plot_mouseout",function(e){$.extend(i,{event:e}),t.call(i)}),this},plotHover:function(e,t){return $(this).plotMouseOver(e).plotMouseOut(t),this},plotShow:function(t){var i=this;return zingchart.bind(this.el.id,"plot_show",function(e){$.extend(i,{event:e}),t.call(i)}),this},plotHide:function(t){var i=this;return zingchart.bind(this.el.id,"plot_hide",function(e){$.extend(i,{event:e}),t.call(i)}),this},aboutShow:function(t){var i=this;return zingchart.bind(this.el.id,"about_show",function(e){$.extend(i,{event:e}),t.call(i)}),this},aboutHide:function(t){var i=this;return zingchart.bind(this.el.id,"about_hide",function(e){$.extend(i,{event:e}),t.call(i)}),this},bugReportShow:function(t){var i=this;return zingchart.bind(this.el.id,"bugreport_show",function(e){$.extend(i,{event:e}),t.call(i)}),this},bugReportHide:function(t){var i=this;return zingchart.bind(this.el.id,"bugreport_hide",function(e){$.extend(i,{event:e}),t.call(i)}),this},dimensionChange:function(t){var i=this;return zingchart.bind(this.el.id,"dimension_change",function(e){$.extend(i,{event:e}),t.call(i)}),this},lensShow:function(t){var i=this;return zingchart.bind(this.el.id,"lens_show",function(e){$.extend(i,{event:e}),t.call(i)}),this},lensHide:function(t){var i=this;return zingchart.bind(this.el.id,"lens_hide",function(e){$.extend(i,{event:e}),t.call(i)}),this},sourceShow:function(t){var i=this;return zingchart.bind(this.el.id,"source_show",function(e){$.extend(i,{event:e}),t.call(i)}),this},sourceHide:function(t){var i=this;return zingchart.bind(this.el.id,"source_hide",function(e){$.extend(i,{event:e}),t.call(i)}),this},legendShow:function(t){var i=this;return zingchart.bind(this.el.id,"legend_show",function(e){$.extend(i,{event:e}),t.call(i)}),this},legendHide:function(t){var i=this;return zingchart.bind(this.el.id,"legend_hide",function(e){$.extend(i,{event:e}),t.call(i)}),this},zoomEvent:function(t){var i=this;return zingchart.bind(this.el.id,"zoom",function(e){$.extend(i,{event:e}),t.call(i)}),this},setTitle:function(e){return"object"==typeof e?zingchart.exec(this.el.id,"modify",{data:{title:e}}):zingchart.exec(this.el.id,"modify",{data:{title:{text:e}}}),this},setSubtitle:function(e){return"object"==typeof e?zingchart.exec(this.el.id,"modify",{data:{subtitle:e}}):zingchart.exec(this.el.id,"modify",{data:{subtitle:{text:e}}}),this},setType:function(e){return zingchart.exec(this.el.id,"modify",{data:{type:e}}),zingchart.exec(this.el.id,"update"),this},drawTrendline:function(u){this.el.id;return function(e){for(var t=$(this).getSeriesValues({plotindex:e}),i=0,n=0,r=0,h=0,c=0,a=(e=$(this).getObjectInfo({object:"scale",name:"scale-x"})).values,o=0;o<t.length;o++)null!=t[o][1]&&"number"==typeof t[o][1]?(i+=t[o][0]*t[o][1],n+=t[o][0],r+=t[o][1],h+=t[o][0]*t[o][0]):(i+=t[o]*a[o],n+=a[o],r+=t[o],h+=Math.pow(a[o],2)),c++;var l=(c*i-n*r)/(c*h-n*n),s=(r-l*n)/c,e=$(this).getObjectInfo({object:"scale",name:"scale-x"}),e=(a=e.values)[0],d=a[a.length-1],e=[s+l*e,s+l*d],s={type:"line",lineColor:"#c00",lineWidth:2,alpha:.75,lineStyle:"dashed",label:{text:""}};u&&$.extend(s,u);s.range=e;l=$(this).getObjectInfo({object:"scale",name:"scale-y"}).markers;l?l.push(s):l=[s];$(this).modify({data:{"scale-y":{markers:l}}})}.call(this,0),this}}),i});
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
lib/backbone.zingchart.js
|
JavaScript
|
/*!
backbone-zingchart 1.0.1
Copyright (c) 2023 ZingChart
Licensed under the MIT license.
*/
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["underscore", "backbone"], function (_, Backbone) {
return (root.ZingChart = factory(_, Backbone));
});
} else if (typeof exports === "object") {
module.exports = factory(require("underscore"), require("backbone"));
} else {
root.ZingChart = factory(root._, root.Backbone);
}}(this, function (_, Backbone) {
var ZingChart = {};
if (typeof ZingChart === 'undefined'){ZingChart = {}};
ZingChart.ZingChartModel = Backbone.Model.extend({
defaults:{
width: 640,
height: 480,
json: {},
data: [],
charttype: 'line',
defaults: {},
events: null
}
});
ZingChart.ZingChartView = Backbone.View.extend({
initialize: function() {
this.listenTo(this.model, "change:json", this.updateChartJSON);
this.listenTo(this.model, "change:data", this.updateChartData);
},
render: function() {
var data = this.mergeJSONData();
zingchart.render({
id:this.el.id,
height:this.model.get('height'),
width:this.model.get('width'),
data:data,
defaults:this.model.get('defaults')
});
return this;
},
exec: function(apimethod, apioptions){
return zingchart.exec(this.el.id, apimethod, apioptions);
},
bind: function(eventname, callback){
zingchart.bind(this.el.id,eventname,callback);
return this;
},
mergeJSONData: function(){
var json = this.model.get('json');
var data = this.model.get('data');
if (typeof(json) === 'string'){
json = JSON.parse(json);
}
if (json.graphset && json.graphset.length === 1){
json = json.graphset[0];
}
if(data && data.length !== 0){
if (!json.series){
json.series = [];
}
for(var i = 0; i < data.length; i++){
if(json.series[i]){
json.series[i].values = data[i];
}
else{
json.series.push({'values' : data[i]});
}
}
}
if (!json.type){
json.type = this.model.get('charttype');
}
return json;
},
updateChartJSON: function(){
var newjson = this.model.get('json');
zingchart.exec(this.el.id, 'setdata',{
data : newjson
});
},
updateChartData: function(){
var newdata = this.model.get('data');
zingchart.exec(this.el.id, 'setseriesvalues',{
values : newdata
});
}
});
return ZingChart;
}));
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
lib/backbone.zingchart.min.js
|
JavaScript
|
!function(i,n){"function"==typeof define&&define.amd?define(["underscore","backbone"],function(e,t){return i.ZingChart=n(0,t)}):"object"==typeof exports?module.exports=n(require("underscore"),require("backbone")):i.ZingChart=n(i._,i.Backbone)}(this,function(e,t){var i={};return(i=void 0===i?{}:i).ZingChartModel=t.Model.extend({defaults:{width:640,height:480,json:{},data:[],charttype:"line",defaults:{},events:null}}),i.ZingChartView=t.View.extend({initialize:function(){this.listenTo(this.model,"change:json",this.updateChartJSON),this.listenTo(this.model,"change:data",this.updateChartData)},render:function(){var e=this.mergeJSONData();return zingchart.render({id:this.el.id,height:this.model.get("height"),width:this.model.get("width"),data:e,defaults:this.model.get("defaults")}),this},exec:function(e,t){return zingchart.exec(this.el.id,e,t)},bind:function(e,t){return zingchart.bind(this.el.id,e,t),this},mergeJSONData:function(){var e=this.model.get("json"),t=this.model.get("data");if((e="string"==typeof e?JSON.parse(e):e).graphset&&1===e.graphset.length&&(e=e.graphset[0]),t&&0!==t.length){e.series||(e.series=[]);for(var i=0;i<t.length;i++)e.series[i]?e.series[i].values=t[i]:e.series.push({values:t[i]})}return e.type||(e.type=this.model.get("charttype")),e},updateChartJSON:function(){var e=this.model.get("json");zingchart.exec(this.el.id,"setdata",{data:e})},updateChartData:function(){var e=this.model.get("data");zingchart.exec(this.el.id,"setseriesvalues",{values:e})}}),i});
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
src/ZingChartModel.js
|
JavaScript
|
if (typeof ZingChart === 'undefined'){ZingChart = {}};
ZingChart.ZingChartModel = Backbone.Model.extend({
defaults:{
width: 640,
height: 480,
json: {},
data: [],
charttype: 'line',
defaults: {},
events: null
}
});
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
src/ZingChartView.js
|
JavaScript
|
ZingChart.ZingChartView = Backbone.View.extend({
initialize: function() {
this.listenTo(this.model, "change:json", this.updateChartJSON);
this.listenTo(this.model, "change:data", this.updateChartData);
},
render: function() {
var data = this.mergeJSONData();
zingchart.render({
id:this.el.id,
height:this.model.get('height'),
width:this.model.get('width'),
data:data,
defaults:this.model.get('defaults')
});
return this;
},
exec: function(apimethod, apioptions){
return zingchart.exec(this.el.id, apimethod, apioptions);
},
bind: function(eventname, callback){
zingchart.bind(this.el.id,eventname,callback);
return this;
},
mergeJSONData: function(){
var json = this.model.get('json');
var data = this.model.get('data');
if (typeof(json) === 'string'){
json = JSON.parse(json);
}
if (json.graphset && json.graphset.length === 1){
json = json.graphset[0];
}
if(data && data.length !== 0){
if (!json.series){
json.series = [];
}
for(var i = 0; i < data.length; i++){
if(json.series[i]){
json.series[i].values = data[i];
}
else{
json.series.push({'values' : data[i]});
}
}
}
if (!json.type){
json.type = this.model.get('charttype');
}
return json;
},
updateChartJSON: function(){
var newjson = this.model.get('json');
zingchart.exec(this.el.id, 'setdata',{
data : newjson
});
},
updateChartData: function(){
var newdata = this.model.get('data');
zingchart.exec(this.el.id, 'setseriesvalues',{
values : newdata
});
}
});
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
src/ZingChartViewExtended.js
|
JavaScript
|
ZingChart.SimpleView = ZingChart.ZingChartView;
ZingChart.ZingChartView = ZingChart.SimpleView.extend({
//Direct API Access ==============================================================
// DATA MANIPULATION ======================================================
addNode: function (data) {
zingchart.exec(this.el.id, "addnode", data);
return this;
},
addPlot: function (data) {
zingchart.exec(this.el.id, "addplot", data);
return this;
},
appendSeriesData: function (data) {
zingchart.exec(this.el.id, "appendseriesdata", data);
return this;
},
appendSeriesValues: function (data) {
zingchart.exec(this.el.id, "appendseriesvalues", data);
return this;
},
getSeriesData: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getseriesdata", opts);
}
else {
return zingchart.exec(this.el.id, "getseriesdata", {});
}
},
getSeriesValues: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getseriesvalues", opts);
}
else {
return zingchart.exec(this.el.id, "getseriesvalues", {});
}
},
modifyPlot: function (data) {
zingchart.exec(this.el.id, "modifyplot", data);
return this;
},
removeNode: function (data) {
zingchart.exec(this.el.id, "removenode", data);
return this;
},
removePlot: function (data) {
zingchart.exec(this.el.id, "removeplot", data);
return this;
},
set3dView: function (data) {
zingchart.exec(this.el.id, "set3dview", data);
return this;
},
setNodeValue: function (data) {
zingchart.exec(this.el.id, "setnodevalue", data);
return this;
},
setSeriesData: function (data) {
zingchart.exec(this.el.id, "setseriesdata", data);
return this;
},
setSeriesValues: function (data) {
zingchart.exec(this.el.id, "setseriesvalues", data);
return this;
},
// EXPORT METHODS =========================================================
exportData: function () {
zingchart.exec(this.el.id, "exportdata");
return this;
},
getImageData: function (ftype) {
if (ftype == "png" || ftype == "jpg" || ftype == "bmp") {
zingchart.exec(this.el.id, "getimagedata", {
filetype: ftype
});
return this;
}
else {
throw("Error: Got " + ftype + ", expected 'png' or 'jpg' or 'bmp'");
}
},
print: function () {
zingchart.exec(this.el.id, "print");
return this;
},
saveAsImage: function () {
zingchart.exec(this.el.id, "saveasimage");
return this;
},
// FEED METHODS ===========================================================
clearFeed: function () {
zingchart.exec(this.el.id, "clearfeed");
return this;
},
getInterval: function () {
return zingchart.exec(this.el.id, "getinterval");
},
setInterval: function (intr) {
if (typeof(intr) == "number") {
zingchart.exec(this.el.id, "setinterval", {
interval: intr
});
return this;
}
else if (typeof(intr) == "object") {
zingchart.exec(this.el.id, "setinterval", intr);
return this;
}
else {
throw("Error: Got " + typeof(intr) + ", expected number");
}
},
startFeed: function () {
zingchart.exec(this.el.id, "startfeed");
return this;
},
stopFeed: function () {
zingchart.exec(this.el.id, "stopfeed");
return this;
},
// GRAPH INFORMATION METHODS ==============================================
getChartType: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getcharttype", opts);
}
else {
return zingchart.exec(this.el.id, "getcharttype");
}
},
getData: function () {
return zingchart.exec(this.el.id, "getdata");
},
getEditMode: function () {
return zingchart.exec(this.el.id, "geteditmode");
},
getGraphLength: function () {
return zingchart.exec(this.el.id, "getgraphlength");
},
getNodeLength: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getnodelength", opts);
}
else {
return zingchart.exec(this.el.id, "getnodelength");
}
},
getNodeValue: function (opts) {
return zingchart.exec(this.el.id, "getnodevalue", opts);
},
getObjectInfo: function (opts) {
return zingchart.exec(this.el.id, "getobjectinfo", opts);
},
getPlotLength: function (opts) {
if (opts) {
return zingchart.exec(this.el.id, "getplotlength", opts);
}
else {
return zingchart.exec(this.el.id, "getplotlength");
}
},
getPlotValues: function (opts) {
return zingchart.exec(this.el.id, "getplotvalues", opts);
},
getRender: function () {
return zingchart.exec(this.el.id, "getrender");
},
getRules: function (opts) {
return zingchart.exec(this.el.id, "getrules", opts);
},
getScales: function (opts) {
return zingchart.exec(this.el.id, "getscales", opts);
},
getVersion: function () {
return zingchart.exec(this.el.id, "getversion");
},
getXYInfo: function (opts) {
return zingchart.exec(this.el.id, "getxyinfo", opts);
},
// GRAPH MANIPULATION =====================================================
addScaleValue: function (url) {
zingchart.exec(this.el.id, "addscalevalue", {
dataurl: url
});
return this;
},
destroy: function (opts) {
if (opts) {
if (opts.hasOwnProperty("")) {
}
}
else {
zingchart.exec(this.el.id, "destroy");
}
return this;
},
loadNewData: function (opts) {
zingchart.exec(this.el.id, "load", opts);
return this;
},
modify: function (opts) {
zingchart.exec(this.el.id, "modify", opts);
return this;
},
reloadChart: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "reload", opts);
}
else {
zingchart.exec(this.el.id, "reload");
}
return this;
},
removeScaleValue: function (opts) {
zingchart.exec(this.el.id, "removescalevalue", opts);
return this;
},
resizeChart: function (opts) {
zingchart.exec(this.el.id, "resize", opts);
return this;
},
setData: function (opts) {
zingchart.exec(this.el.id, "setdata", opts);
return this;
},
update: function (opts) {
zingchart.exec(this.el.id, "update");
return this;
},
// HISTORY METHODS ========================================================
goBack: function () {
zingchart.exec(this.el.id, "goback");
return this;
},
goForward: function () {
zingchart.exec(this.el.id, "goforward");
return this;
},
// INTERACTIVE METHODS ====================================================
addNodeIA: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "addnodeia", opts);
}
else {
zingchart.exec(this.el.id, "addnodeia");
}
return this;
},
enterEditMode: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "entereditmode", opts);
}
else {
zingchart.exec(this.el.id, "entereditmode");
}
return this;
},
exitEditMode: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "exiteditmode", opts);
}
else {
zingchart.exec(this.el.id, "exiteditmode");
}
return this;
},
removeNodeIA: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "removenodeia", opts);
}
else {
zingchart.exec(this.el.id, "removenodeia");
}
return this;
},
removePlotIA: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "removeplotia", opts);
}
else {
zingchart.exec(this.el.id, "removeplotia");
}
return this;
},
// NOTES METHODS ==========================================================
addNote: function (opts) {
zingchart.exec(this.el.id, "addnote", opts);
return this;
},
removeNote: function (opts) {
zingchart.exec(this.el.id, "removenote", {
"id": opts
});
return this;
},
updateNote: function (opts) {
zingchart.exec(this.el.id, "updatenote", opts);
return this;
},
// OBJECTS METHODS ========================================================
addObject: function (opts) {
zingchart.exec(this.el.id, "addobject", opts);
return this;
},
removeObject: function (opts) {
zingchart.exec(this.el.id, "removeobject", opts);
return this;
},
repaintObjects: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "repaintobjects", opts);
}
else {
zingchart.exec(this.el.id, "repaintobjects", {});
}
return this;
},
updateObject: function (opts) {
zingchart.exec(this.el.id, "updateobject", opts);
return this;
},
// LABEL METHODS ==========================================================
addLabel: function (opts) {
zingchart.exec(this.el.id, "addobject", {
"type":"label",
"data":opts
});
return this;
},
removeLabel: function (opts) {
zingchart.exec(this.el.id, "removeobject", {
"type":"label",
"id":opts
});
return this;
},
updateLabel: function (opts) {
zingchart.exec(this.el.id, "updateobject", {
"type": "label",
"data": opts
});
return this;
},
// RULES METHODS ==========================================================
addRule: function (opts) {
zingchart.exec(this.el.id, "addrule", opts);
return this;
},
removeRule: function (opts) {
zingchart.exec(this.el.id, "removerule", opts);
return this;
},
updateRule: function (opts) {
zingchart.exec(this.el.id, "updaterule", opts);
return this;
},
// SELECTION METHODS ======================================================
clearSelection: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "clearselection", opts);
}
else {
zingchart.exec(this.el.id, "clearselection");
}
return this;
},
chartDeselect: function (opts) {
zingchart.exec(this.el.id, "deselect", opts);
return this;
},
getSelection: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "getselection", opts);
}
else {
zingchart.exec(this.el.id, "getselection");
}
return this;
},
chartSelect: function (opts) {
zingchart.exec(this.el.id, "select", opts);
return this;
},
setSelection: function (opts) {
zingchart.exec(this.el.id, "setselection", opts);
return this;
},
// TOGGLE METHODS =========================================================
disable: function (message) {
if (message) {
zingchart.exec(this.el.id, "disable", {text: message});
}
else {
zingchart.exec(this.el.id, "disable");
}
return this;
},
enable: function () {
zingchart.exec(this.el.id, "enable");
return this;
},
exitFullscreen: function () {
zingchart.exec(this.el.id, "exitfullscreen");
return this;
},
fullscreen: function () {
zingchart.exec(this.el.id, "fullscreen");
return this;
},
hideMenu: function () {
zingchart.exec(this.el.id, "hidemenu");
return this;
},
hidePlot: function (opts) {
zingchart.exec(this.el.id, "hideplot", opts);
return this;
},
hideAllPlots: function (opts) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid')) {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "hideplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
else {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "hideplot", {
"plotindex": i
});
}
}
return this;
},
hideAllPlotsBut: function (opts) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid') && opts.hasOwnProperty('plotindex')) {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "hideplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
}
else {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "hideplot", {
"plotindex": i
});
}
}
}
return this;
},
modifyAllPlotsBut: function (opts, data) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid') && opts.hasOwnProperty('plotindex')) {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "modifyplot", {
"graphid": opts.graphid,
"plotindex": i,
"data": data
});
}
}
}
else {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "modifyplot", {
"plotindex": i,
"data": data
});
}
}
}
return this;
},
modifyAllPlots: function (data, opts) {
var myId = this.el.id;
var allPlots = ( opts ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
for (var i = 0; i < allPlots; i++) {
if (opts && opts.graphid) {
zingchart.exec(myId, "modifyplot", {
"graphid": opts.graphid,
"plotindex": i,
"data": data
});
}
else {
zingchart.exec(myId, "modifyplot", {
"plotindex": i,
"data": data
});
}
}
return this;
},
showAllPlots: function (opts) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid')) {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "showplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
else {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "showplot", {
"plotindex": i
});
}
}
return this;
},
showAllPlotsBut: function (opts) {
var myId = this.el.id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid') && opts.hasOwnProperty('plotindex')) {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "showplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
}
else {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "showplot", {
"plotindex": i
});
}
}
}
return this;
},
legendMaximize: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "legendmaximize", opts);
}
else {
zingchart.exec(this.el.id, "legendmaximize");
}
return this;
},
legendMinimize: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "legendminimize", opts);
}
else {
zingchart.exec(this.el.id, "legendminimize");
}
return this;
},
showMenu: function () {
zingchart.exec(this.el.id, "showmenu");
return this;
},
showPlot: function (opts) {
zingchart.exec(this.el.id, "showplot", opts);
return this;
},
toggleAbout: function () {
zingchart.exec(this.el.id, "toggleabout");
return this;
},
toggleBugReport: function () {
zingchart.exec(this.el.id, "togglebugreport");
return this;
},
toggleDimension: function () {
zingchart.exec(this.el.id, "toggledimension");
return this;
},
toggleLegend: function () {
zingchart.exec(this.el.id, "togglelegend");
return this;
},
toggleLens: function () {
zingchart.exec(this.el.id, "togglelens");
return this;
},
toggleSource: function () {
zingchart.exec(this.el.id, "togglesource");
return this;
},
// ZOOM METHODS ===========================================================
viewAll: function () {
zingchart.exec(this.el.id, "viewall");
return this;
},
zoomIn: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "zoomin", opts);
}
else {
zingchart.exec(this.el.id, "zoomin");
}
return this;
},
zoomOut: function (opts) {
if (opts) {
zingchart.exec(this.el.id, "zoomout", opts);
}
else {
zingchart.exec(this.el.id, "zoomout");
}
return this;
},
zoomTo: function (opts) {
zingchart.exec(this.el.id, "zoomto", opts);
return this;
},
zoomToValues: function (opts) {
zingchart.exec(this.el.id, "zoomtovalues", opts);
return this;
},
/*********************************************************************
****************************** EVENTS *******************************
*********************************************************************/
// ANIMATION EVENTS ====================================================
animationEnd: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "animationEnd", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
animationStart: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "animation_start", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
animationStep: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "animation_step", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// DATA MANIPULATION EVENTS ===============================================
chartModify: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "modify", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeAdd: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_add", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeRemove: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_remove", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotAdd: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_add", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotModify: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_modify", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotRemove: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_remove", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
chartReload: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "reload", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
dataSet: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "setdata", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// EXPORT EVENTS ==========================================================
dataExport: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "data_export", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
imageSave: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "image_save", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
chartPrint: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "print", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// FEED EVENTS ============================================================
feedClear: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "feed_clear", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
feedIntervalModify: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "feed_interval_modify", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
feedStart: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "feed_start", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
feedStop: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "feed_stop", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// GLOBAL EVENTS
graphClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphComplete: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "complete", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphDataParse: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "dataparse", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphDataReady: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "dataready", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphGuideMouseMove: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "guide_mousemove", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphLoad: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "load", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphMenuItemClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "menu_item_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
graphResize: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "resize", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// HISTORY EVENTS =========================================================
historyForward: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "history_forward", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
historyBack: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "history_back", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// INTERACTIVE EVENTS =====================================================
nodeSelect: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_select", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeDeselect: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_deselect", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotSelect: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_select", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotDeselect: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_deselect", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// LEGEND EVENTS ==========================================================
legendItemClick: function (callback) {
zingchart.bind(this.el.id, "legend_item_click", callback);
/*var jq = this;
zingchart.bind(this.el.id, "legend_item_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});*/
return this;
},
legendMarkerClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_marker_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// NODE EVENTS ============================================================
nodeClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeDoubleClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_doubleclick", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
nodeMouseOver: function (callback) {
var jq = this;
var NODEMOUSEOVER = false;
zingchart.bind(this.el.id, "node_mouseover", function(p){
if (!NODEMOUSEOVER) {
$.extend(jq,{event:p});
NODEMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "node_mouseout", function(){
NODEMOUSEOVER = false;
});
return this;
},
nodeMouseOut: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "node_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq);
});
return this;
},
nodeHover: function (mouseover, mouseout) {
var jq = this;
var NODEMOUSEOVER = false;
zingchart.bind(this.el.id, "node_mouseover", function(p){
if (!NODEMOUSEOVER) {
$.extend(jq,{event:p});
NODEMOUSEOVER = true;
mouseover.call(jq);
}
});
zingchart.bind(jq[0].id, "node_mouseout", function(){
NODEMOUSEOVER = false;
mouseout.call(jq);
});
return this;
},
// LABEL EVENTS ============================================================
labelClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "label_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
labelMouseOver: function (callback) {
var jq = this;
var LABELMOUSEOVER = false;
zingchart.bind(this.el.id, "label_mouseover", function(p){
if (!LABELMOUSEOVER) {
$.extend(jq,{event:p});
LABELMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "label_mouseout", function(){
LABELMOUSEOVER = false;
});
return this;
},
labelMouseOut: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "label_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
labelHover: function (mouseover, mouseout) {
$(this).labelMouseOver(mouseover).labelMouseOut(mouseout);
return this;
},
// SHAPE EVENTS ============================================================
shapeClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "shape_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
shapeMouseOver: function (callback) {
var jq = this;
var SHAPEMOUSEOVER = false;
zingchart.bind(this.el.id, "shape_mouseover", function(p){
if (!SHAPEMOUSEOVER) {
$.extend(jq,{event:p});
SHAPEMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "shape_mouseout", function(){
SHAPEMOUSEOVER = false;
});
return this;
},
shapeMouseOut: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "shape_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
shapeHover: function (mouseover, mouseout) {
$(this).shapeMouseOver(mouseover).shapeMouseOut(mouseout);
return this;
},
// PLOT EVENTS ============================================================
plotClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotDoubleClick: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_doubleclick", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotMouseOver: function (callback) {
var jq = this;
var PLOTMOUSEOVER = false;
zingchart.bind(this.el.id, "plot_mouseover", function(p){
if (!PLOTMOUSEOVER) {
$.extend(jq,{event:p});
PLOTMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "plot_mouseout", function(){
PLOTMOUSEOVER = false;
});
return this;
},
plotMouseOut: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotHover: function (mouseover, mouseout) {
$(this).plotMouseOver(mouseover).plotMouseOut(mouseout);
return this;
},
plotShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
plotHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "plot_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
// TOGGLE EVENTS ==========================================================
aboutShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "about_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
aboutHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "about_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
bugReportShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "bugreport_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
bugReportHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "bugreport_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
dimensionChange: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "dimension_change", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
lensShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "lens_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
lensHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "lens_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
sourceShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "source_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
sourceHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "source_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
legendShow: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
legendHide: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
legendMaximize: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_maximize", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
legendMinimize: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "legend_minimize", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
zoomEvent: function (callback) {
var jq = this;
zingchart.bind(this.el.id, "zoom", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
},
/*********************************************************************
********************** HELPER METHODS *******************************
*********************************************************************/
setTitle: function (newtitle) {
if (typeof(newtitle) == 'object') {
zingchart.exec(this.el.id, "modify", {
data: {
title: newtitle
}
});
}
else {
zingchart.exec(this.el.id, "modify", {
data: {
title: {
text: newtitle
}
}
});
}
return this;
},
setSubtitle: function (newtitle) {
if (typeof(newtitle) == 'object') {
zingchart.exec(this.el.id, "modify", {
data: {
subtitle: newtitle
}
});
}
else {
zingchart.exec(this.el.id, "modify", {
data: {
subtitle: {
text: newtitle
}
}
});
}
return this;
},
setType: function (type) {
zingchart.exec(this.el.id, "modify", {
"data": {
"type": type
}
});
zingchart.exec(this.el.id,"update");
return this;
},
drawTrendline: function (opts) {
var myId = this.el.id;
calculate.call(this,0);
function calculate(pindex) {
var nodes = $(this).getSeriesValues({
plotindex:pindex
});
var sxy = 0, sx = 0, sy = 0, sx2 = 0, l = 0;
var oScaleInfo = $(this).getObjectInfo({
object : 'scale',
name : 'scale-x'
});
var aScaleValues = oScaleInfo.values;
for (var i=0;i<nodes.length;i++) {
if (nodes[i][1] != undefined && typeof(nodes[i][1]) == 'number') {
sxy += nodes[i][0]*nodes[i][1];
sx += nodes[i][0];
sy += nodes[i][1];
sx2 += nodes[i][0]*nodes[i][0];
l++;
}
else {
sxy += nodes[i]*aScaleValues[i];
sx += aScaleValues[i];
sy += nodes[i];
sx2 += Math.pow(aScaleValues[i],2);
l++;
}
}
var b = (l * sxy - sx * sy) / (l * sx2 - sx * sx);
var a = (sy - b * sx) / l;
var oScaleInfo = $(this).getObjectInfo({
object : 'scale',
name : 'scale-x'
});
var aScaleValues = oScaleInfo.values, fScaleMin = aScaleValues[0], fScaleMax = aScaleValues[aScaleValues.length-1];
var aRange = [a + b*fScaleMin, a + b*fScaleMax];
var trendline = {
type : 'line',
lineColor : '#c00',
lineWidth : 2,
alpha : 0.75,
lineStyle : 'dashed',
label : {
text : ''
}
};
if (opts) {
$.extend(trendline,opts);
}
trendline.range = aRange;
var scaleY = $(this).getObjectInfo({
object:'scale',
name: 'scale-y'
});
var markers = scaleY.markers;
if (markers) {
markers.push(trendline);
}
else {
markers = [trendline];
}
$(this).modify({
"data": {
"scale-y": {
"markers": markers
}
}
});
}
return this;
}
});
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
src/test/chart_test.html
|
HTML
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>ZingChart Backbone Plugin - Simple Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
<script src="../ZingChartModel.js"></script>
<script src="../ZingChartView.js"></script>
<script type="text/template" id="chart-template">
<div>
<button class="add-plot">Add Plot</button>
<button class="reset-json">Change JSON</button>
<button class="reset-data">Change Data</button>
<button class="toggle-legend">Toggle Legend</button>
<div id="chartDiv"></div>
</div>
</script>
<body>
<div id="demo"></div>
<script>
var DemoView = Backbone.View.extend({
el: '#demo',
template: _.template($('#chart-template').html()),
initialize: function() {
this.$el.empty();
this.zc = new ZingChart.ZingChartModel({data: [[3,2,3,3,9] , [1,2,3,4,5]],
width: 500,
height: 400});
this.render();
},
render: function() {
this.$el.html(this.template());
this.zcView = new ZingChart.ZingChartView({model: this.zc, el: $('#chartDiv')});
this.zcView.render();
return this;
},
events: {
'click .reset-json': 'changeJSON',
'click .reset-data': 'changeData',
'click .add-plot': 'addPlot',
'click .toggle-legend': 'addLegend'
},
random: function(max){
return Math.floor((Math.random() * max));
},
changeJSON: function(){
console.log('Changing JSON');
var charttype = ["area", "line", "bar"];
var max = 100;
var plots = 3;
var points = 15;
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink'];
var data = {
type: charttype[this.random(charttype.length)]
};
var series = [];
for (var i=0;i<plots;i++){
var color = colors[this.random(colors.length)];
var plot = {
lineColor: color,
backgroundColor: color
}
var plotdata = [];
for (var j=0;j<points;j++){
plotdata.push(this.random(max) + 1);
}
plot.values = plotdata;
series.push(plot);
}
data.series = series;
this.zc.set("json", data);
},
addPlot: function(){
var values = [];
for (var j=0;j<15;j++){
values.push(this.random(100) + 1);
}
this.zcView.exec('addplot', {
data : {
values : values
}
});
},
addLegend: function(){
var graph = this.zcView.exec('getdata');
if (graph.graphset){
graph = graph.graphset[0];
}
if(!graph.legend){
graph.legend = {};
}
this.zc.set('json', graph);
this.zcView.bind('legend_item_click', this.alertClick);
},
alertClick: function(){
alert("CLICKED");
},
changeData: function(){
console.log('Change Data');
var max = 100;
var plots = 3;
var points = 15;
var series = [];
for (var i=0;i<plots;i++){
var plotdata = [];
for (var j=0;j<points;j++){
plotdata.push(this.random(max) + 1);
}
series.push(plotdata);
}
this.zc.set("data", series);
}
});
var demo = new DemoView();
demo.render();
</script>
</body>
</html>
|
zingchart/ZingChart-Backbone
| 20
|
Turn simple Models and Views into snazzy charts with our Backbone extension for ZingChart
|
JavaScript
|
zingchart
|
ZingChart
| |
addon/components/ember-zingchart.js
|
JavaScript
|
import Ember from 'ember';
// https://www.zingchart.com/docs/api/events/
const EVENT_NAMES = [
// Animation Events
'animation_end',
'animation_start',
'animation_step',
// Data Manipulation Events
'modify',
'node_add',
'node_remove',
'plot_add',
'plot_modify',
'plot_remove',
'reload',
'setdata',
// Export Events
'data_export',
'image_save',
'print',
// Feed Events
'feed_clear',
'feed_interval_modify',
'feed_start',
'feed_stop',
// Global Events
'click',
'complete',
'dataparse',
'dataready',
'guide_mousemove',
'load',
'menu_item_click',
'resize',
// Graph Events
'gcomplete',
'gload',
// History Events
'history_back',
'history_forward',
// History Events
'node_deselect',
'node_select',
'plot_deselect',
'plot_select',
// Legend Events
'legend_item_click',
'legend_marker_click',
// Node Events
'node_click',
'node_doubleclick',
'node_mouseout',
'node_mouseover',
// Object Events
'label_click',
'label_mouseout',
'label_mouseover',
'legend_marker_click',
'shape_click',
'shape_mouseout',
'shape_mouseover',
// Plot Events
'plot_click',
'plot_doubleclick',
'plot_mouseout',
'plot_mouseover',
// Toggle Events
'about_hide',
'about_show',
'bugreport_hide',
'bugreport_show',
'dimension_change',
'legend_hide',
'legend_maximize',
'legend_minimize',
'legend_show',
'lens_hide',
'lens_show',
'plot_hide',
'plot_show',
'source_hide',
'source_show',
// Zoom Events
'zoom'
];
export default Ember.Component.extend({
classNames:['zingchart-ember'],
_eventDispatcher: function (handlerName, event, data) {
const handler = this.get(handlerName);
if (handler) {
return handler(event, data);
}
else {
return data;
}
},
_events: Ember.computed(function(){
const events = {};
const eventDispatcher = this.get('_eventDispatcher');
EVENT_NAMES.forEach(
eventName => {
const handlerName = `on_${eventName}`;
events[eventName] = eventDispatcher.bind(this, handlerName.camelize());
});
return events;
}),
renderOptions: undefined,
// http://www.zingchart.com/docs/developers/zingchart-object-and-methods/#render-method
_defaultRenderOptions: {
// minimal config
id: null,
data: null,
height: 400,
width: 600,
// optional defaults
output: 'svg',
hideprogresslogo: true,
'type': null,
'labels': [
{
'width': '10%',
'x': '45%',
'y': '50%',
'text': 'Error Loading Data!',
'background-color': 'white',
'border-width': 1,
'border-color': 'black',
'border-radius': 6,
'padding': 10,
'color': 'red',
'font-weight': 'bold',
'font-size': 12,
'wrap-text': true,
'shadow': 0
}
]
},
_overwriteDefaultRenderOptions: function(renderOptions) {
this._defaultRenderOptions.id = this.elementId;
this._defaultRenderOptions.events = this.get('_events');
// Overwrite the defaults with the passed config
for (let key of Object.keys(renderOptions)) {
this._defaultRenderOptions[key] = renderOptions[key];
}
return this._defaultRenderOptions;
},
didInsertElement: function() {
this.renderLater();
},
renderLater:function() {
Ember.run.scheduleOnce('afterRender', this, '_renderChart');
},
_renderChart: function() {
let renderOptions = this.get('renderOptions');
renderOptions = this._overwriteDefaultRenderOptions(renderOptions);
zingchart.render(renderOptions);
},
_destroyChart: Ember.on('willDestroyElement', function() {
var self=this;
zingchart.exec(self.elementId,'destroy');
})
});
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
app/components/ember-zingchart.js
|
JavaScript
|
import Ember from 'ember';
import EmberZingChartComponent from 'ember-zingchart/components/ember-zingchart';
export default EmberZingChartComponent;
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
blueprints/ember-zingchart/index.js
|
JavaScript
|
module.exports = {
normalizeEntityName: function() {},
afterInstall: function() {
return this.addBowerPackageToProject('zingchart');
}
};
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
config/ember-try.js
|
JavaScript
|
/*jshint node:true*/
module.exports = {
scenarios: [
{
name: 'ember-1.12.2',
bower: {
dependencies: {
'ember': '~1.12.2'
},
resolutions: {
'ember': '~1.12.2'
}
}
},
{
name: 'ember-1.13.13',
bower: {
dependencies: {
'ember': '~1.13.13'
},
resolutions: {
'ember': '~1.13.13'
}
}
},
{
name: 'ember-2.4.3',
bower: {
dependencies: {
'ember': '~2.4.3'
},
resolutions: {
'ember': '~2.4.3'
}
}
},
{
name: 'ember-release',
bower: {
dependencies: {
'ember': 'components/ember#release'
},
resolutions: {
'ember': 'release'
}
}
},
{
name: 'ember-beta',
bower: {
dependencies: {
'ember': 'components/ember#beta'
},
resolutions: {
'ember': 'beta'
}
}
},
{
name: 'ember-canary',
bower: {
dependencies: {
'ember': 'components/ember#canary'
},
resolutions: {
'ember': 'canary'
}
}
}
]
};
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
config/environment.js
|
JavaScript
|
/*jshint node:true*/
'use strict';
module.exports = function(/* environment, appConfig */) {
return { };
};
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
ember-cli-build.js
|
JavaScript
|
/*jshint node:true*/
/* global require, module */
var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
module.exports = function(defaults) {
var app = new EmberAddon(defaults, {
// Add options here
});
/*
This build file specifies the options for the dummy test app of this
addon, located in `/tests/dummy`
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/
app.import('bower_components/zingchart/client/zingchart.min.js');
return app.toTree();
};
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
index.js
|
JavaScript
|
/* jshint node: true */
'use strict';
module.exports = {
name: 'ember-zingchart',
included: function(app) {
this._super.included(app);
app.import(app.bowerDirectory + '/zingchart/client/zingchart.min.js');
app.import(app.bowerDirectory + '/zingchart/client/modules/*.js');
}
};
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
testem.js
|
JavaScript
|
/*jshint node:true*/
module.exports = {
"framework": "qunit",
"test_page": "tests/index.html?hidepassed",
"disable_watching": true,
"launch_in_ci": [
"PhantomJS"
],
"launch_in_dev": [
"PhantomJS",
"Chrome"
]
};
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/dummy/app/app.js
|
JavaScript
|
import Ember from 'ember';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';
let App;
Ember.MODEL_FACTORY_INJECTIONS = true;
App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver
});
loadInitializers(App, config.modulePrefix);
export default App;
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/dummy/app/controllers/application.js
|
JavaScript
|
import Ember from 'ember';
let _renderOptions = {
height: 400,
width: "100%",
events: {
node_click:function(p) {
console.log(p);
}
},
data: {
"type":"line",
"title":{
"text":"Average Metric"
},
"series":[
{
"values":[69,68,54,48,70,74,98,70,72,68,49,69]
},
{
"values":[51,53,47,60,48,52,75,52,55,47,60,48]
},
{
"values":[42,43,30,40,31,48,55,46,48,32,38,38]
},
{
"values":[25,15,26,21,24,26,33,25,15,25,22,24]
}
]
},
defaults: {
"palette" : {
"line" : [
["#ffffff", "#196eed", "#196eed", "#196eed"],
["#ffffff", "#d94530", "#d94530", "#d94530"],
["#ffffff", "#fdb82b", "#fdb82b", "#fdb82b"],
["#ffffff", "#159755", "#159755", "#159755"],
["#ffffff", "#8e8e8e", "#8e8e8e", "#8e8e8e"]
]
},
"graph" : {
"background-color":"#f9f9f9",
"border-color":"#ddd",
"border-width":"1px",
"border-style":"solid",
"border-radius":5,
"title" : {
"background-color" : "#5f9af3",
"height":"30px",
"align":"center",
"font-color" : "#fff",
"border-radius-top-left":5,
"border-radius-top-right":5
},
}
}
}; // _renderOptions
export default Ember.Controller.extend({
// improve the readability of the controller
// by keeping the actual config object outside
myRenderOptions: _renderOptions
});
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/dummy/app/index.html
|
HTML
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{content-for "head"}}
<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/dummy.css">
{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}
<script src="assets/vendor.js"></script>
<script src="assets/dummy.js"></script>
{{content-for "body-footer"}}
</body>
</html>
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/dummy/app/resolver.js
|
JavaScript
|
import Resolver from 'ember-resolver';
export default Resolver;
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/dummy/app/router.js
|
JavaScript
|
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
});
export default Router;
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/dummy/config/environment.js
|
JavaScript
|
/* jshint node: true */
module.exports = function(environment) {
var ENV = {
modulePrefix: 'dummy',
environment: environment,
baseURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
}
};
if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
}
if (environment === 'test') {
// Testem prefers this...
ENV.baseURL = '/';
ENV.locationType = 'none';
// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
}
if (environment === 'production') {
}
return ENV;
};
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/helpers/destroy-app.js
|
JavaScript
|
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/helpers/module-for-acceptance.js
|
JavaScript
|
import { module } from 'qunit';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
if (options.beforeEach) {
options.beforeEach.apply(this, arguments);
}
},
afterEach() {
if (options.afterEach) {
options.afterEach.apply(this, arguments);
}
destroyApp(this.application);
}
});
}
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/helpers/resolver.js
|
JavaScript
|
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/helpers/start-app.js
|
JavaScript
|
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
export default function startApp(attrs) {
let application;
let attributes = Ember.merge({}, config.APP);
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
Ember.run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/index.html
|
HTML
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy Tests</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{content-for "head"}}
{{content-for "test-head"}}
<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/dummy.css">
<link rel="stylesheet" href="assets/test-support.css">
{{content-for "head-footer"}}
{{content-for "test-head-footer"}}
</head>
<body>
{{content-for "body"}}
{{content-for "test-body"}}
<script src="testem.js" integrity=""></script>
<script src="assets/vendor.js"></script>
<script src="assets/test-support.js"></script>
<script src="assets/dummy.js"></script>
<script src="assets/tests.js"></script>
<script src="assets/test-loader.js"></script>
{{content-for "body-footer"}}
{{content-for "test-body-footer"}}
</body>
</html>
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/integration/components/ember-zingchart-test.js
|
JavaScript
|
import { moduleForComponent, test } from 'ember-qunit';
//import hbs from 'htmlbars-inline-precompile';
moduleForComponent('ember-zingchart', 'Integration | Component | ember zingchart', {
integration: true
});
test('it renders', function(assert) {
assert.expect(0);
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
//TODO: need a stub like this one for PhantomJS
window.zingchart = {
render: function() {},
exec: function() {}
};
this.set('myRenderOptions', {});
//this.render(hbs`{{ember-zingchart renderOptions=myRenderOptions}}`);
//assert.equal(this.$().text().trim(), '');
});
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
tests/test-helper.js
|
JavaScript
|
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
|
zingchart/ZingChart-Ember
| 19
|
A ZingChart component for Ember CLI
|
JavaScript
|
zingchart
|
ZingChart
| |
docs/index.html
|
HTML
|
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../zingchart.min.js"></script>
<script src="../zingchart.jquery.js"></script>
<script>
$(document).ready( function() {
// example one data
var ex1 = {
"type": "bar",
"legend":{},
"series": [
{
"values": [5,10,15,5,10,5]
},
{
"values": [10,5,10,10,5,10]
},
{
"values": [1,15,3,6,9,12]
},
{
"values": [4,7,9,1,2,1]
},
]
};
// render example one
$('#ex_1').zingchart({
data:ex1
});
// example two
var ex2_Data = {
"background-color":"none",
"type":"line",
"plotarea":{
"margin-top":20,
"margin-bottom":20
},
"scaleX":{
"line-width":1,
"tick":{
"line-width":1
}
},
"scaleY":{
"values":"0:20000:2000",
"line-width":1,
"tick":{
"line-width":1
}
},
"plot":{
"line-width":1
},
"series":[
{
"values":[[1156.17,1156.17],
[8783.25,7627.08],
[16128.48,7345.23],
[28812.29,12683.81],
[40495.65,11683.36],
[53333.87,12838.22],
[66805,13471.13],
[75952.64,9147.64],
[88751.12,12798.48],
[101232.14,12481.02],
[111116.5,9884.36],
[122258.86,11142.36],
[133276.59,11017.73],
[143820.55,10543.96],
[153530.83,9710.28],
[163465.26,9934.43],
[175577.26,12112],
[187311.18,11733.92],
[199613.18,12302],
[211922.78,12309.6],
[224043.47,12120.69],
[236226.84,12183.37],
[248416.11,12189.27],
[260563.17,12147.06],
[272744.07,12180.9],
[285156.89,12412.82],
[296349.84,11192.95],
[310385.61,14035.77],
[324812.43,14426.82],
[338157.73,13345.3],
[352548.68,14390.95],
[366928.67,14379.99],
[379945.48,13016.81],
[394992.46,15046.98],
[409990.19,14997.73],
[424960.02,14969.83],
[439894.22,14934.2],
[452135.57,12241.35],
[466389.35,14253.78],
[484396.06,18006.71],
[499981.06,15585],
[513354.06,13373],
[526727.06,13373],
[540063.06,13336],
[553519.06,13456],
[566975.06,13456],
[580227.06,13252],
[592737.06,12510],
[608441.06,15704],
[625005.57,16564.51],
[637818.23,12812.66],
[652867.76,15049.53],
[668146.01,15278.25],
[683469.81,15323.8],
[698773.3,15303.49],
[714257.81,15484.51],
[729603.85,15346.04],
[741997.65,12393.8],
[754165.47,12167.82],
[769161.41,14995.94],
[782726.81,13565.4],
[797655.44,14928.63],
[808720.73,11065.29],
[824101.5,15380.77],
[838214.17,14112.67],
[855129.75,16915.58],
[873883.15,18753.4],
[889377,15493.85],
[904934.22,15557.22],
[918838.6,13904.38],
[934296.95,15458.35],
[947715.25,13418.3],
[963512.22,15796.97],
[979741.8,16229.58],
[996103.29,16361.49],
[1010824.7,14721.41],
[1025576.41,14751.71],
[1038454.55,12878.14],
[1053228.96,14774.41],
[1067019.96,13791],
[1076133.28,9113.32],
[1091130.02,14996.74],
[1104879.65,13749.63],
[1118815.5,13935.85],
[1131968.5,13153],
[1146180.62,14212.12],
[1160449.55,14268.93],
[1174443.9,13994.35],
[1188392.14,13948.24],
[1202278.67,13886.53],
[1215543.17,13264.5],
[1229433.94,13890.77],
[1243404.59,13970.65],
[1257321.15,13916.56],
[1271140.72,13819.57],
[1283283.52,12142.8],
[1296109.57,12826.05],
[1308449.59,12340.02],
[1321055.09,12605.5],
[1333649.77,12594.68],
[1346052.49,12402.72],
[1361057.29,15004.8],
[1373715.89,12658.6],
[1388168.66,14452.77],
[1402313.71,14145.05],
[1416294.23,13980.52],
[1430338.18,14043.95],
[1436933.96,6595.78],
[1447258.75,10324.79],
[1448450.75,1192],
[1448450.75,0],
[1448451.75,1],
[1448451.75,0],
[1455180.75,6729],
[1464844.75,9664],
[1475658.75,10814],
[1486327.35,10668.6],
[1496931.25,10603.9],
[1507635.7,10704.45],
[1519850.9,12215.2],
[1529148.92,9298.02],
[1539730.45,10581.53],
[1550294.58,10564.13],
[1560913.33,10618.75],
[1571571.37,10658.04],
[1582551.7,10980.33],
[1593075.36,10523.66],
[1603496.2,10420.84],
[1613883.43,10387.23],
[1623982.24,10098.81],
[1634598.48,10616.24],
[1645166.22,10567.74],
[1654580.56,9414.34],
[1664732.83,10152.27],
[1674297.28,9564.45],
[1683724.08,9426.8],
[1693141.3,9417.22],
[1702534.71,9393.41],
[1711890.44,9355.73],
[1721441.95,9551.51],
[1730749.23,9307.28],
[1738910.94,8161.71],
[1746096.86,7185.92],
[1750639.09,4542.23],
[1755120.36,4481.27],
[1759523.6,4403.24],
[1763849.28,4325.68],
[1768076.3,4227.02],
[1772357.62,4281.32],
[1777158.05,4800.43],
[1781879.22,4721.17],
[1786524.19,4644.97],
[1791098.08,4573.89],
[1794968.7,3870.62],
[1799302.87,4334.17],
[1804186.52,4883.65],
[1809288.76,5102.24],
[1814399.06,5110.3],
[1819643.43,5244.37],
[1824896.62,5253.19],
[1830152.22,5255.6],
[1835394.98,5242.76],
[1840612.73,5217.75],
[1845082.13,4469.4],
[1849819.05,4736.92],
[1854519.66,4700.61],
[1859007.81,4488.15],
[1863233.04,4225.23],
[1867630.83,4397.79],
[1872523.6,4892.77],
[1877435.02,4911.42],
[1881910.5,4475.48],
[1886964.87,5054.37],
[1887595.04,630.17],
[1887595.04,0],
[1887595.04,0],
[1887595.04,0],
[1887595.04,0],
[1887595.04,0],
[1887595.04,0],
[1890431.04,2836],
[1895439.04,5008],
[1900615.04,5176],
[1905738.04,5123],
[1910034.86,4296.82],
[1914852.5,4817.64],
[1919561.23,4708.73],
[1924208.68,4647.45],
[1928822.39,4613.71],
[1933414.24,4591.85],
[1937983.69,4569.45],
[1941409.72,3426.03],
[1945815.11,4405.39],
[1948726.86,2911.75],
[1948863.45,136.59],
[1953580.61,4717.16],
[1957935.89,4355.28],
[1962178.39,4242.5],
[1966457.57,4279.18],
[1970639.61,4182.04],
[1975513.01,4873.4],
[1980332.57,4819.56],
[1985076.08,4743.51],
[1989748.54,4672.46],
[1994446.12,4697.58],
[1999630.33,5184.21],
[2004917.96,5287.63],
[2009582.41,4664.45],
[2014277.37,4694.96],
[2018070.99,3793.62],
[2022785.57,4714.58],
[2027410.57,4625],
[2031829.57,4419],
[2036186.94,4357.37],
[2040697.69,4510.75],
[2045002.28,4304.59],
[2049221.12,4218.84],
[2053896.45,4675.33],
[2058621.25,4724.8],
[2063237.75,4616.5],
[2067890.1,4652.35],
[2072457.73,4567.63],
[2076995.97,4538.24],
[2081481.96,4485.99],
[2085959.86,4477.9],
[2090388.76,4428.9],
[2095048.18,4659.42],
[2100255.3,5207.12],
[2100617.64,362.34],
[2105229.22,4611.58],
[2109769.15,4539.93],
[2114276.58,4507.43],
[2118772.33,4495.75],
[2123302.33,4530],
[2127823.87,4521.54],
[2132228.63,4404.76],
[2136674.19,4445.56],
[2140607.56,3933.37],
[2145091.64,4484.08],
[2149613.35,4521.71],
[2154199.07,4585.72],
[2158726.73,4527.66],
[2163433.64,4706.91],
[2168149.7,4716.06],
[2173002,4852.3],
[2177576.52,4574.52],
[2182128,4551.48],
[2186657.67,4529.67],
[2191215.96,4558.29],
[2195794.96,4579],
[2200312.08,4517.12],
[2204931.52,4619.44],
[2209444.09,4512.57],
[2214064.86,4620.77],
[2218657.21,4592.35],
[2222597.63,3940.42],
[2227225.46,4627.83],
[2231842.44,4616.98],
[2236530.93,4688.49],
[2241101.3,4570.37],
[2245651.6,4550.3],
[2250177.18,4525.58],
[2254694.08,4516.9],
[2259153.1,4459.02],
[2259311.91,158.81],
[2259311.91,0],
[2259318.89,6.98],
[2262403.64,3084.75],
[2268536.22,6132.58],
[2273174.47,4638.25],
[2277837.2,4662.73],
[2282408.35,4571.15],
[2286636.88,4228.53],
[2291379.59,4742.71],
[2296198.31,4818.72],
[2300955.65,4757.34],
[2305659.89,4704.24],
[2310338.9,4679.01],
[2314989.75,4650.85],
[2319391.15,4401.4],
[2323990.07,4598.92],
[2328803.82,4813.75],
[2333579.64,4775.82],
[2338373.49,4793.85],
[2343103.54,4730.05],
[2347763.32,4659.78],
[2352588.2,4824.88],
[2357385.84,4797.64],
[2362160.43,4774.59],
[2366917.65,4757.22],
[2371598.98,4681.33],
[2376271.31,4672.33],
[2380931.11,4659.8],
[2385583.89,4652.78],
[2390220.09,4636.2],
[2394328.21,4108.12],
[2399001.07,4672.86],
[2402968.71,3967.64],
[2407595.77,4627.06],
[2412194.88,4599.11],
[2416787.17,4592.29],
[2421387.55,4600.38],
[2426209.55,4822],
[2430977.12,4767.57],
[2435662.21,4685.09],
[2440500.73,4838.52],
[2445578.52,5077.79],
[2450618.75,5040.23],
[2455644.58,5025.83],
[2459843.01,4198.43],
[2464760.09,4917.08],
[2468669.2,3909.11],
[2473329.2,4660],
[2477720.13,4390.93],
[2482523.33,4803.2],
[2487561.8,5038.47],
[2492586.19,5024.39],
[2497556.33,4970.14],
[2502575.63,5019.3],
[2507240.12,4664.49],
[2511968.08,4727.96],
[2516665.16,4697.08],
[2521443.63,4778.47],
[2526213.17,4769.54],
[2530963.56,4750.39],
[2535699.27,4735.71],
[2540412.23,4712.96],
[2545175.94,4763.71],
[2549924.92,4748.98],
[2555342.42,5417.5],
[2561011.54,5669.12],
[2566637.53,5625.99],
[2572224.08,5586.55],
[2577794.28,5570.2],
[2583335.19,5540.91],
[2588855.34,5520.15],
[2592143.36,3288.02],
[2597550.09,5406.73],
[2602778.36,5228.27],
[2607076.75,4298.39],
[2612326.47,5249.72],
[2617567.53,5241.06],
[2622744.26,5176.73],
[2627899.39,5155.13],
[2633017.88,5118.49],
[2638133.92,5116.04],
[2643224.1,5090.18],
[2646383.38,3159.28],
[2651825.28,5441.9],
[2657390.82,5565.54],
[2662922.25,5531.43],
[2668428.3,5506.05],
[2673897.96,5469.66],
[2679340.07,5442.11],
[2682206.05,2865.98],
[2687239.98,5033.93],
[2692192.4,4952.42],
[2697197.45,5005.05],
[2701942.82,4745.37],
[2712536.4,10593.58],
[2717478.74,4942.34],
[2722397.14,4918.4],
[2726360.86,3963.72],
[2731347.24,4986.38],
[2736301.96,4954.72],
[2741215.12,4913.16],
[2746336.46,5121.34],
[2751200.03,4863.57],
[2755779.93,4579.9],
[2760730.66,4950.73],
[2765387.31,4656.65],
[2769456.54,4069.23],
[2774872.59,5416.05],
[2779541.35,4668.76],
[2784392.93,4851.58],
[2784844.4,451.47],
[2784844.4,0],
[2787306.03,2461.63],
[2792173.02,4866.99],
[2797703.88,5530.86],
[2803276.48,5572.6],
[2808618.67,5342.19],
[2813962.7,5344.03],
[2819249.28,5286.58],
[2824402.24,5152.96],
[2829554.14,5151.9],
[2834797.43,5243.29],
[2839924.32,5126.89],
[2845048.77,5124.45],
[2850123.29,5074.52],
[2855360.34,5237.05],
[2860415.08,5054.74],
[2865495.53,5080.45],
[2869524.41,4028.88],
[2873184.42,3660.01],
[2876324.41,3139.99],
[2879412.11,3087.7],
[2882475.39,3063.28],
[2885333.28,2857.89],
[2888595.02,3261.74],
[2891201.58,2606.56],
[2895507.16,4305.58],
[2900335.76,4828.6],
[2904798.44,4462.68],
[2909909.43,5110.99],
[2914870.87,4961.44],
[2919167.26,4296.39],
[2924168.17,5000.91],
[2929341.08,5172.91],
[2934825.39,5484.31],
[2940372.97,5547.58],
[2945887.04,5514.07],
[2951340.62,5453.58],
[2956772.68,5432.06],
[2962163.24,5390.56],
[2967674.24,5511],
[2973069.16,5394.92],
[2976725.38,3656.22],
[2980004.4,3279.02],
[2985108.04,5103.64],
[2990438.11,5330.07],
[2995691.41,5253.3],
[3000759.45,5068.04],
[3006012.65,5253.2],
[3011233.37,5220.72],
[3015993.79,4760.42],
[3020807.62,4813.83],
[3025612.91,4805.29],
[3030533.53,4920.62],
[3035333.11,4799.58],
[3040636.69,5303.58],
[3046587.19,5950.5],
[3051938.16,5350.97],
[3056787.72,4849.56],
[3061650.74,4863.02],
[3066690.26,5039.52],
[3071212.83,4522.57],
[3076082.06,4869.23],
[3080491.35,4409.29],
[3084500.62,4009.27],
[3089354.63,4854.01],
[3094293.38,4938.75],
[3097960.07,3666.69],
[3102909.37,4949.3],
[3107940.17,5030.8],
[3112919.69,4979.52],
[3117835.68,4915.99],
[3122668.21,4832.53],
[3127569.57,4901.36],
[3132455.66,4886.09],
[3137204.99,4749.33],
[3141944.86,4739.87],
[3146712.97,4768.11],
[3151546.9,4833.93],
[3156665.31,5118.41],
[3161417.31,4752],
[3166284.17,4866.86],
[3170421.37,4137.2],
[3175392.36,4970.99],
[3180463.9,5071.54],
[3185099.18,4635.28],
[3190168.55,5069.37],
[3195096.27,4927.72],
[3200191.17,5094.9],
[3205228.28,5037.11],
[3210260.54,5032.26],
[3215235.29,4974.75],
[3220193.6,4958.31],
[3225091.31,4897.71],
[3230004.34,4913.03],
[3234663.39,4659.05],
[3239321.77,4658.38],
[3244222.74,4900.97],
[3249220.85,4998.11],
[3253690.01,4469.16],
[3258392.09,4702.08],
[3263458.25,5066.16],
[3268301.6,4843.35],
[3273515.84,5214.24],
[3278672.52,5156.68],
[3283861.52,5189],
[3288997.12,5135.6],
[3294137.49,5140.37],
[3299254.41,5116.92],
[3303940.91,4686.5],
[3308857.76,4916.85],
[3314190.83,5333.07],
[3318641.64,4450.81],
[3321532.17,2890.53],
[3325445.25,3913.08],
[3328021.51,2576.26],
[3333019.35,4997.84],
[3338042.53,5023.18],
[3343655.57,5613.04],
[3349201.31,5545.74],
[3354623.21,5421.9],
[3359934.51,5311.3],
[3364896.52,4962.01],
[3370162.39,5265.87],
[3374550.67,4388.28],
[3374550.67,0],
[3374789.59,238.92],
[3379372.71,4583.12],
[3384275.34,4902.63],
[3388979.37,4704.03],
[3392195.23,3215.86],
[3396678.61,4483.38],
[3396678.61,0],
[3400954.48,4275.87],
[3405972.51,5018.03],
[3411030.91,5058.4],
[3416101.21,5070.3],
[3421332.41,5231.2],
[3426333.26,5000.85],
[3431423.7,5090.44],
[3436532.7,5109],
[3441607.86,5075.16],
[3446681.02,5073.16],
[3451084.39,4403.37],
[3452695.72,1611.33],
[3452732.24,36.52],
[3452732.24,0],
[3452732.24,0],
[3452732.24,0],
[3452732.24,0],
[3452732.24,0],
[3452732.24,0],
[3452732.24,0],
[3456712.8,3980.56],
[3461995.39,5282.59],
[3467217.14,5221.75],
[3472503.88,5286.74],
[3477942.35,5438.47],
[3483115.21,5172.86],
[3488353.54,5238.33],
[3493583.01,5229.47],
[3498852.48,5269.47],
[3504051.23,5198.75],
[3509239.26,5188.03],
[3514454.62,5215.36],
[3519932.55,5477.93],
[3525016.05,5083.5],
[3530272.31,5256.26],
[3535639.66,5367.35],
[3540837.05,5197.39],
[3544497.3,3660.25],
[3549378.3,4881],
[3554378.3,5000],
[3559378.3,5000],
[3564378.3,5000],
[3569378.3,5000],
[3576878.3,7500],
[3576878.3,0],
[3576878.3,0],
[3578701.42,1823.12],
[3583833.54,5132.12],
[3589369.84,5536.3],
[3594472.23,5102.39],
[3599238.18,4765.95],
[3605288.61,6050.43],
[3610510.95,5222.34],
[3615709.51,5198.56],
[3621856.98,6147.47],
[3627714.65,5857.67],
[3632976.57,5261.92],
[3633164.85,188.28],
[3636130.2,2965.35],
[3641618.62,5488.42],
[3647025.35,5406.73],
[3652536.41,5511.06],
[3657773.14,5236.73],
[3662707.06,4933.92],
[3668518.44,5811.38],
[3674062.37,5543.93],
[3676674.92,2612.55],
[3682223.63,5548.71],
[3687819.43,5595.8],
[3693411.8,5592.37],
[3698941.96,5530.16],
[3703358.11,4416.15],
[3708911.81,5553.7],
[3712324.22,3412.41],
[3716122.98,3798.76],
[3721568.1,5445.12],
[3727029.4,5461.3],
[3732630.34,5600.94],
[3738199.66,5569.32],
[3743546.23,5346.57],
[3747853.83,4307.6],
[3752766.99,4913.16],
[3757720.06,4953.07],
[3762739.37,5019.31],
[3767595.93,4856.56],
[3772540.02,4944.09],
[3777498.29,4958.27],
[3782579.19,5080.9],
[3787185.73,4606.54],
[3792275.49,5089.76],
[3798011.48,5735.99],
[3803762.05,5750.57],
[3809508.14,5746.09],
[3815304.39,5796.25],
[3821077.99,5773.6],
[3825782.84,4704.85],
[3831021.07,5238.23],
[3836203.8,5182.73],
[3841382.22,5178.42],
[3846505.59,5123.37],
[3851669.72,5164.13],
[3854035.89,2366.17],
[3858688.87,4652.98],
[3863375.84,4686.97],
[3868040.13,4664.29],
[3872543.86,4503.73],
[3877210.39,4666.53],
[3882078.52,4868.13],
[3887453.5,5374.98],
[3893217.55,5764.05],
[3898593.92,5376.37],
[3904827.71,6233.79],
[3911170.23,6342.52],
[3917469.01,6298.78],
[3923888.75,6419.74],
[3930311.09,6422.34],
[3933426.42,3115.33],
[3940076.3,6649.88],
[3946764.68,6688.38],
[3953427.77,6663.09],
[3960312.69,6884.92],
[3966969.58,6656.89],
[3969910.98,2941.4],
[3976426.99,6516.01],
[3982533.58,6106.59],
[3989243.27,6709.69],
[3996031.55,6788.28],
[4002047.39,6015.84],
[4008049.44,6002.05],
[4010126.7,2077.26],
[4014102.22,3975.52],
[4019377.49,5275.27],
[4024772.16,5394.67],
[4030161.45,5389.29],
[4034889.16,4727.71],
[4040807.92,5918.76],
[4044500.62,3692.7],
[4044500.62,0],
[4046712.53,2211.91],
[4049941.13,3228.6],
[4053161.63,3220.5],
[4056535.8,3374.17],
[4061123.57,4587.77],
[4066053.83,4930.26],
[4070920,4866.17],
[4074163.17,3243.17],
[4077904.19,3741.02],
[4082038.22,4134.03],
[4086728.97,4690.75],
[4091122.7,4393.73],
[4095144.75,4022.05],
[4099251.18,4106.43],
[4103190.09,3938.91],
[4108002.72,4812.63],
[4111852.58,3849.86],
[4114759.51,2906.93],
[4119550.17,4790.66],
[4124557.41,5007.24],
[4127072.72,2515.31],
[4130078.93,3006.21],
[4134950.77,4871.84],
[4141651.85,6701.08],
[4148412.68,6760.83],
[4155280.69,6868.01],
[4162131.62,6850.93],
[4168873.25,6741.63],
[4174321.35,5448.1],
[4180515.85,6194.5],
[4187742.63,7226.78],
[4195488.7,7746.07],
[4198528.56,3039.86],
[4203523.53,4994.97],
[4209371.64,5848.11],
[4216840.68,7469.04],
[4224112.91,7272.23],
[4230903.6,6790.69],
[4236833.15,5929.55],
[4242402.01,5568.86],
[4246565.4,4163.39],
[4253919.78,7354.38],
[4261417.13,7497.35],
[4268201.61,6784.48],
[4272468.2,4266.59],
[4279956.25,7488.05],
[4285968.97,6012.72],
[4285968.97,0],
[4285968.97,0],
[4285968.97,0],
[4285968.97,0],
[4290271.2,4302.23],
[4297478.06,7206.86],
[4304264.22,6786.16],
[4311800.01,7535.79],
[4318589.24,6789.23],
[4325909.89,7320.65],
[4333309.44,7399.55],
[4340727.58,7418.14],
[4348157.36,7429.78],
[4355442.38,7285.02],
[4359490.19,4047.81],
[4359490.19,0],
[4359907.33,417.14],
[4365668.36,5761.03],
[4373249.28,7580.92],
[4380630.42,7381.14],
[4387961.03,7330.61],
[4395422.26,7461.23],
[4402582.07,7159.81],
[4409392.32,6810.25],
[4416160.09,6767.77],
[4423790.63,7630.54],
[4431432.38,7641.75],
[4439073.73,7641.35],
[4446761.75,7688.02],
[4453948.62,7186.87],
[4460939.32,6990.7],
[4468340.03,7400.71],
[4474267.19,5927.16],
[4481451.44,7184.25],
[4488737.98,7286.54],
[4496473.77,7735.79],
[4503912.49,7438.72],
[4511289.99,7377.5],
[4518989.73,7699.74],
[4525761.88,6772.15],
[4528409.76,2647.88],
[4534700.73,6290.97],
[4540077.44,5376.71],
[4546954.28,6876.84],
[4553691.89,6737.61],
[4561062.32,7370.43],
[4568441.32,7379],
[4575860.16,7418.84],
[4583278.11,7417.95],
[4590729.8,7451.69],
[4598100.66,7370.86],
[4605551.48,7450.82],
[4612315.45,6763.97],
[4617561.11,5245.66],
[4624133.11,6572],
[4630747.98,6614.87],
[4638316.82,7568.84],
[4645050.14,6733.32],
[4652319.35,7269.21],
[4659640.21,7320.86],
[4666981.5,7341.29],
[4674191.72,7210.22],
[4681372.67,7180.95],
[4686097.59,4724.92],
[4693230.93,7133.34],
[4700020.22,6789.29],
[4708737.22,8717],
[4716106.26,7369.04],
[4723572.73,7466.47],
[4729980.03,6407.3],
[4736174.16,6194.13],
[4743402.55,7228.39],
[4750642.2,7239.65],
[4757761.92,7119.72],
[4763194.51,5432.59],
[4767933.24,4738.73],
[4773609.6,5676.36],
[4779259.39,5649.79],
[4784285.18,5025.79],
[4790016.78,5731.6],
[4794855.95,4839.17],
[4800464.4,5608.45],
[4805562.1,5097.7],
[4810497.46,4935.36],
[4815419.01,4921.55],
[4820304.62,4885.61],
[4825542.06,5237.44],
[4830497.69,4955.63],
[4835039.64,4541.95],
[4839727.79,4688.15],
[4844756.51,5028.72],
[4849753.15,4996.64],
[4854439.87,4686.72],
[4859623.67,5183.8],
[4864726.46,5102.79],
[4869815.83,5089.37],
[4874541.98,4726.15],
[4877257.7,2715.72],
[4882443.3,5185.6],
[4887517.43,5074.13],
[4892575.83,5058.4],
[4897585.94,5010.11],
[4902563.88,4977.94],
[4907600.75,5036.87],
[4912695.84,5095.09],
[4916093.4,3397.56],
[4919316.02,3222.62],
[4923016.91,3700.89],
[4927768.47,4751.56],
[4933846.82,6078.35],
[4938637.84,4791.02],
[4943518.83,4880.99],
[4948157.06,4638.23],
[4952922.06,4765],
[4957214.68,4292.62],
[4962331.32,5116.64],
[4967143.75,4812.43],
[4971969.74,4825.99]],
"text":"Apple"
}
]
};
$('#ex_2').zingchart({data:ex2_Data});
$("#trendline").click(function(){
$("#ex_2").drawTrendline({
lineColor: "#0FF",
lineWidth: 1,
alpha: 1,
lineStyle: "solid"
});
});
function makeLabel(x) {
return {
"visible":1,
"id":"label1",
"text":x.event.value,
"font-size":"20px",
"color":"white",
"background-color":"#444",
"callout":1,
"shadow":0,
"border-radius":5,
"width":36,
"padding":6,
"offset-y":-30,
"hook":"node:plot="+x.event.plotindex+";index="+x.event.nodeindex
}
}
$("#ex_2").nodeMouseOver(function(){
$(this).addLabel(makeLabel(this));
}).labelHover(function(){
$(this).updateLabel({
"id": "label1",
"background-color":"#FFF",
"color":"#444"
});
}, function(){
$(this).updateLabel({
"id":"label1",
"background-color":"#444",
"color":"#FFF"
});
});
/*
$("#ex_2").nodeHover(
function(){
$(this).addLabel(makeLabel(this));
},
function(){
$(this).removeLabel("label1");
}
);
*/
// example three
$('#ex_3').zingchart({data: {
type: 'line',
series: [{values: [1,2,3,4,5,6,7]}]
}
});
$('#ex_3_button').click( function(e) {
$('#ex_3').setType( 'area').setTitle( 'new title' );
});
});
</script>
</head>
<body>
<h1>Example 1: Basic Usage</h1>
<p>The jQuery plugin for ZingChart allows devs to create and manipulate charts, and generally access the ZingChart API, in familiar jQuery syntax.</p>
<p>The most basic usage of the plugin entails using jQuery to select an element to apply the chart to and calling .zingchart() on it:
<pre>$('#myDiv').zingchart();</pre>
<p>Technically this will initiate a ZingChart jQuery object on the selected element, but we want to pass in some data for ZingChart to work with.
The .zingchart() function takes one parameter, an object. This object
can contain a variety of key-value pairs. The main one you'll need in order to render a chart is 'data'. This should be another object that corresponds with
the JSON data structure passed to ZingChart's render() function as the 'data' variable, and the syntax should be as described here:
<a href="http://www.zingchart.com/docs/json-attributes-syntax/">http://www.zingchart.com/docs/json-attributes-syntax/</a>.</p>
<p>A basic example:</p>
<pre>
var data = {
type: 'line',
title: { text: 'zingchart w/ jquery' },
series: [
{ values: [5,3,1,7,7,6] },
{ values: [3,5,7,9,10,12] }
]
};
$('#myDiv').zingchart( { data: data } );
</pre>
<p>which will render something like this:</p>
<div id="ex_1" class="zingchart"></div>
<p>The data has now been rendered in the '#myDiv' element. In most cases though, you'll probably want to save the ZingChart jQuery object
you've just created to manipulate it later, e.g.:</p>
<pre>var myChart = $('#myDiv').zingchart({ data: data });</pre>
<h1>Example 2: Executing functions on the ZingChart jQuery object</h1>
<p>Once you've created a zingchart object, you can execute function on it in regular jQuery fashion.</p>
<pre>
var data = {
type: 'line',
title: { text: 'zingchart w/ jquery' },
series: [
{ values: [5,3,1,7,7,6] },
{ values: [3,5,7,9,10,12] }
]
};
var myChart = $('#myDiv').zingchart( { data: data } );
var newData = { type: "scatter" };
$('#button').click( function() {
myChart.setData( newData );
});
</pre>
<button id="trendline">Draw Trendline</button>
<div id="ex_2" class="zingchart"></div>
<h1>Example 3: Chaining on your ZingChart object</h1>
<p>The returned ZingChart object can be chained just like a regular jQuery object. This allows you to do something like:</p>
<pre>
var myChart = $('#myDiv').zingchart( { data: data } );
$('#button').click( function() {
myChart.setType('area').setTitle( 'new title' );
});
</pre>
<button id="ex_3_button">change to area and reset title</button>
<div id="ex_3" class="zingchart"></div>
<div id='one'></div>
<div id='two'></div>
</body>
</html>
|
zingchart/ZingChart-jQuery
| 45
|
Easy ZingChart manipulation and interactivity for jQuery users.
|
JavaScript
|
zingchart
|
ZingChart
| |
docs/style.css
|
CSS
|
* {
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
body {
width: 60%;
margin: 0 auto;
}
.zingchart {
width: 500px;
height: 300px;
}
pre {
padding: 15px;
background-color: #E8E8E8;
font-family: 'Monaco', Courier, monospace;
}
code {
background-color: #E8E8E8;
font-family: 'Monaco', Courier, monospace;
font-size: 14px;
font-style: normal;
padding: 2px;
margin: 2px;
display: inline-block;
}
h1 {
margin-top: 50px;
}
button {
padding: 8px 10px;
margin: 10px 2px;
font-size: 14px;
border-radius: 4px;
background-color: #00baf0; /*#359AF2;*/
border: none;
color: #FFF;
}
button:hover {
cursor: pointer;
background-color: #2BD1FF; /*#308AD9;*/
}
|
zingchart/ZingChart-jQuery
| 45
|
Easy ZingChart manipulation and interactivity for jQuery users.
|
JavaScript
|
zingchart
|
ZingChart
| |
docs/table-convert.html
|
HTML
|
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../zingchart.min.js"></script>
<script src="../zingchart.jquery.js"></script>
<script src="../zingify/zingify.jquery.js"></script>
<!-- <style type="text/css">
code {
background-color: #FFFFCC;
}
</style>-->
</head>
<body>
<h1>ZingChart jQuery Table-to-Chart Plugin</h1>
<h2>Basic Info</h2>
<p>This plugin takes the data from an HTML table and converts renders it in a ZingChart. It allows the user to submit JSON data along with the table
when rendering, or to pull data from HTML5 custom data attributes.</p>
<em>note: the JS code snippets below are assumed to be within a jQuery <code>$(document).ready()</code> block</em>
<h2>Configuration</h2>
<ul>Using the plugin requires you include the following scripts:
<li>jQuery (ex: <code><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script></code>)</li>
<li>the ZingChart core library scripts (ex: <code><script src="zingchart/html5_scripts/zingchart-html5-min.js"></script></code>)</li>
<li>the ZingChart jQuery plugin, which this plugin utilizes (ex: <code><script src="zingchart.jquery.js"></script></code>)</li>
<li>the script for this plugin, zingify.jquery.js (ex: <code><script src="zingify.jquery.js"></script></code>)</li>
</ul>
<h2>Basic usage</h2>
<p>Converts a (well-formed) HTML table into a ZingChart rendering. For an example of the most basic usage:</p>
<p>A table in the HTML that looks like this:</p>
<table id="ex_1">
<caption>Sales</caption>
<thead>
<tr>
<th>month</th>
<th>apples</th>
<th>oranges</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jan</td>
<td>42</td>
<td>48</td>
</tr>
<tr>
<td>Feb</td>
<td>37</td>
<td>52</td>
</tr>
<tr>
<td>Mar</td>
<td>48</td>
<td>59</td>
</tr>
<tr>
<td>April</td>
<td>36</td>
<td>61</td>
</tr>
<tr>
<td>May</td>
<td>35</td>
<td>38</td>
</tr>
</tbody>
</table>
<p>When zingified as follows:</p>
<pre>$('table#myTable').zingify();</pre>
<p>Will render this chart:</p>
<div id="ex_1_chart"></div>
<br><br><br>
<!-- data-zc='{ "type": "line", "title": { "text": "Quantity Sold" }, "scale-y": { "label": { "text": "quantity" } } }' -->
<!-- <table data-zc-type="line" data-zc-title_text="Quantity Sold" data-zc-scale-y_label_text="quantity" id="ex_2"> -->
<table data-zc-type="line" data-zc-title_text="Quantity Sold" data-zc-scale-y_label_text="quantity" id="ex_2">
<thead>
<tr>
<th>month</th>
<th>vacuum cleaners</th>
<th>senators</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jan</td>
<td>43</td>
<td>32</td>
</tr>
<tr>
<td>Feb</td>
<td>21</td>
<td>33</td>
</tr>
<tr>
<td>Mar</td>
<td>12</td>
<td>42</td>
</tr>
<tr>
<td>April</td>
<td>19</td>
<td>55</td>
</tr>
<tr>
<td>May</td>
<td>34</td>
<td>38</td>
</tr>
<tr>
<td>June</td>
<td>40</td>
<td>32</td>
</tr>
<tr>
<td>July</td>
<td>42</td>
<td>35</td>
</tr>
<tr>
<td>Aug</td>
<td>42</td>
<td>37</td>
</tr>
<tr>
<td>Sep</td>
<td>38</td>
<td>48</td>
</tr>
<tr>
<td>Oct</td>
<td>38</td>
<td>55</td>
</tr>
<tr>
<td>Nov</td>
<td>32</td>
<td>59</td>
</tr>
<tr>
<td>Dec</td>
<td>38</td>
<td>55</td>
</tr>
</tbody>
</table>
<div id="ex_2_chart"></div>
<script>
$(document).ready( function() {
$('#ex_1').zingify({
target: 'ex_1_chart',
data: {
"type": "line"
}
});
$('#ex_2').zingify({
target: 'ex_2_chart',
// data: {
// "type": "line",
// "title": {
// "text": "Quantity Sold"
// },
// "scale-y": {
// "label": {
// "text": "quantity"
// }
// }
// }
});
});
</script>
</body>
</html>
|
zingchart/ZingChart-jQuery
| 45
|
Easy ZingChart manipulation and interactivity for jQuery users.
|
JavaScript
|
zingchart
|
ZingChart
| |
zingchart.jquery.js
|
JavaScript
|
/* View the README.md for detailed documentation. */
/* Version 2.0.0 | Last Updated 19 Oct. 2016 */
(function ( $ ) {
/**********************************************************************
****************************** METHODS *******************************
*********************************************************************/
// MAIN METHOD ============================================================
$.fn.zingchart = function (options) {
var id = this[0].id;
var defaults = {
id: id,
height: '100%',
width: '100%'
};
$.extend(defaults, options);
zingchart.render(defaults);
return this;
};
// LOAD MODULES ===========================================================
$.fn.loadModules = function (options) {
zingchart.loadModules(options);
return this;
}
// DATA MANIPULATION ======================================================
$.fn.addNode = function (data) {
zingchart.exec(this[0].id, "addnode", data);
return this;
};
$.fn.addPlot = function (data) {
zingchart.exec(this[0].id, "addplot", data);
return this;
};
$.fn.appendSeriesData = function (data) {
zingchart.exec(this[0].id, "appendseriesdata", data);
return this;
};
$.fn.appendSeriesValues = function (data) {
zingchart.exec(this[0].id, "appendseriesvalues", data);
return this;
};
$.fn.getSeriesData = function (opts) {
if (opts) {
return zingchart.exec(this[0].id, "getseriesdata", opts);
}
else {
return zingchart.exec(this[0].id, "getseriesdata", {});
}
};
$.fn.getSeriesValues = function (opts) {
if (opts) {
return zingchart.exec(this[0].id, "getseriesvalues", opts);
}
else {
return zingchart.exec(this[0].id, "getseriesvalues", {});
}
};
$.fn.modifyPlot = function (data) {
zingchart.exec(this[0].id, "modifyplot", data);
return this;
};
$.fn.removeNode = function (data) {
zingchart.exec(this[0].id, "removenode", data);
return this;
};
$.fn.removePlot = function (data) {
zingchart.exec(this[0].id, "removeplot", data);
return this;
};
$.fn.set3dView = function (data) {
zingchart.exec(this[0].id, "set3dview", data);
return this;
};
$.fn.setNodeValue = function (data) {
zingchart.exec(this[0].id, "setnodevalue", data);
return this;
};
$.fn.setSeriesData = function (data) {
zingchart.exec(this[0].id, "setseriesdata", data);
return this;
};
$.fn.setSeriesValues = function (data) {
zingchart.exec(this[0].id, "setseriesvalues", data);
return this;
};
// EXPORT METHODS =========================================================
$.fn.exportData = function () {
zingchart.exec(this[0].id, "exportdata");
return this;
};
$.fn.getImageData = function (ftype) {
if (ftype == "png" || ftype == "jpg" || ftype == "bmp") {
zingchart.exec(this[0].id, "getimagedata", {
filetype: ftype
});
return this;
}
else {
throw("Error: Got " + ftype + ", expected 'png' or 'jpg' or 'bmp'");
}
};
$.fn.print = function () {
zingchart.exec(this[0].id, "print");
return this;
};
$.fn.saveAsImage = function () {
zingchart.exec(this[0].id, "saveasimage");
return this;
};
// FEED METHODS ===========================================================
$.fn.clearFeed = function () {
zingchart.exec(this[0].id, "clearfeed");
return this;
};
$.fn.getInterval = function () {
return zingchart.exec(this[0].id, "getinterval");
};
$.fn.setInterval = function (intr) {
if (typeof(intr) == "number") {
zingchart.exec(this[0].id, "setinterval", {
interval: intr
});
return this;
}
else if (typeof(intr) == "object") {
zingchart.exec(this[0].id, "setinterval", intr);
return this;
}
else {
throw("Error: Got " + typeof(intr) + ", expected number");
}
};
$.fn.startFeed = function () {
zingchart.exec(this[0].id, "startfeed");
return this;
};
$.fn.stopFeed = function () {
zingchart.exec(this[0].id, "stopfeed");
return this;
};
// GRAPH INFORMATION METHODS ==============================================
$.fn.getChartType = function (opts) {
if (opts) {
return zingchart.exec(this[0].id, "getcharttype", opts);
}
else {
return zingchart.exec(this[0].id, "getcharttype");
}
};
$.fn.getData = function () {
return zingchart.exec(this[0].id, "getdata");
};
$.fn.getEditMode = function () {
return zingchart.exec(this[0].id, "geteditmode");
};
$.fn.getGraphLength = function () {
return zingchart.exec(this[0].id, "getgraphlength");
};
$.fn.getNodeLength = function (opts) {
if (opts) {
return zingchart.exec(this[0].id, "getnodelength", opts);
}
else {
return zingchart.exec(this[0].id, "getnodelength");
}
};
$.fn.getNodeValue = function (opts) {
return zingchart.exec(this[0].id, "getnodevalue", opts);
};
$.fn.getObjectInfo = function (opts) {
return zingchart.exec(this[0].id, "getobjectinfo", opts);
};
$.fn.getPlotLength = function (opts) {
if (opts) {
return zingchart.exec(this[0].id, "getplotlength", opts);
}
else {
return zingchart.exec(this[0].id, "getplotlength");
}
};
$.fn.getPlotValues = function (opts) {
return zingchart.exec(this[0].id, "getplotvalues", opts);
};
$.fn.getRender = function () {
return zingchart.exec(this[0].id, "getrender");
};
$.fn.getRules = function (opts) {
return zingchart.exec(this[0].id, "getrules", opts);
};
$.fn.getScales = function (opts) {
return zingchart.exec(this[0].id, "getscales", opts);
};
$.fn.getVersion = function () {
return zingchart.exec(this[0].id, "getversion");
};
$.fn.getXYInfo = function (opts) {
return zingchart.exec(this[0].id, "getxyinfo", opts);
};
// GRAPH MANIPULATION =====================================================
$.fn.addScaleValue = function (url) {
zingchart.exec(this[0].id, "addscalevalue", {
dataurl: url
});
return this;
};
$.fn.destroy = function (opts) {
if (opts) {
if (opts.hasOwnProperty("")) {
}
}
else {
zingchart.exec(this[0].id, "destroy");
}
return this;
};
$.fn.loadNewData = function (opts) {
zingchart.exec(this[0].id, "load", opts);
return this;
};
$.fn.modify = function (opts) {
zingchart.exec(this[0].id, "modify", opts);
return this;
};
$.fn.reloadChart = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "reload", opts);
}
else {
zingchart.exec(this[0].id, "reload");
}
return this;
};
$.fn.removeScaleValue = function (opts) {
zingchart.exec(this[0].id, "removescalevalue", opts);
return this;
};
$.fn.resizeChart = function (opts) {
zingchart.exec(this[0].id, "resize", opts);
return this;
};
$.fn.setData = function (opts) {
zingchart.exec(this[0].id, "setdata", opts);
return this;
};
$.fn.update = function (opts) {
zingchart.exec(this[0].id, "update");
return this;
};
// HISTORY METHODS ========================================================
$.fn.goBack = function () {
zingchart.exec(this[0].id, "goback");
return this;
};
$.fn.goForward = function () {
zingchart.exec(this[0].id, "goforward");
return this;
};
// INTERACTIVE METHODS ====================================================
$.fn.addNodeIA = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "addnodeia", opts);
}
else {
zingchart.exec(this[0].id, "addnodeia");
}
return this;
};
$.fn.enterEditMode = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "entereditmode", opts);
}
else {
zingchart.exec(this[0].id, "entereditmode");
}
return this;
};
$.fn.exitEditMode = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "exiteditmode", opts);
}
else {
zingchart.exec(this[0].id, "exiteditmode");
}
return this;
};
$.fn.removeNodeIA = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "removenodeia", opts);
}
else {
zingchart.exec(this[0].id, "removenodeia");
}
return this;
};
$.fn.removePlotIA = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "removeplotia", opts);
}
else {
zingchart.exec(this[0].id, "removeplotia");
}
return this;
};
// NOTES METHODS ==========================================================
$.fn.addNote = function (opts) {
zingchart.exec(this[0].id, "addnote", opts);
return this;
};
$.fn.removeNote = function (opts) {
zingchart.exec(this[0].id, "removenote", {
"id": opts
});
return this;
};
$.fn.updateNote = function (opts) {
zingchart.exec(this[0].id, "updatenote", opts);
return this;
};
// OBJECTS METHODS ========================================================
$.fn.addObject = function (opts) {
zingchart.exec(this[0].id, "addobject", opts);
return this;
};
$.fn.removeObject = function (opts) {
zingchart.exec(this[0].id, "removeobject", opts);
return this;
};
$.fn.repaintObjects = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "repaintobjects", opts);
}
else {
zingchart.exec(this[0].id, "repaintobjects", {});
}
return this;
};
$.fn.updateObject = function (opts) {
zingchart.exec(this[0].id, "updateobject", opts);
return this;
};
// LABEL METHODS ==========================================================
$.fn.addLabel = function (opts) {
zingchart.exec(this[0].id, "addobject", {
"type":"label",
"data":opts
});
return this;
};
$.fn.removeLabel = function (opts) {
zingchart.exec(this[0].id, "removeobject", {
"type":"label",
"id":opts
});
return this;
};
$.fn.updateLabel = function (opts) {
zingchart.exec(this[0].id, "updateobject", {
"type": "label",
"data": opts
});
return this;
};
// RULES METHODS ==========================================================
$.fn.addRule = function (opts) {
zingchart.exec(this[0].id, "addrule", opts);
return this;
};
$.fn.removeRule = function (opts) {
zingchart.exec(this[0].id, "removerule", opts);
return this;
};
$.fn.updateRule = function (opts) {
zingchart.exec(this[0].id, "updaterule", opts);
return this;
};
// SELECTION METHODS ======================================================
$.fn.clearSelection = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "clearselection", opts);
}
else {
zingchart.exec(this[0].id, "clearselection");
}
return this;
};
$.fn.chartDeselect = function (opts) {
zingchart.exec(this[0].id, "deselect", opts);
return this;
};
$.fn.getSelection = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "getselection", opts);
}
else {
zingchart.exec(this[0].id, "getselection");
}
return this;
};
$.fn.chartSelect = function (opts) {
zingchart.exec(this[0].id, "select", opts);
return this;
};
$.fn.setSelection = function (opts) {
zingchart.exec(this[0].id, "setselection", opts);
return this;
};
// TOGGLE METHODS =========================================================
$.fn.disableChart = function (message) {
if (message) {
zingchart.exec(this[0].id, "disable", {text: message});
}
else {
zingchart.exec(this[0].id, "disable");
}
return this;
};
$.fn.enableChart = function () {
zingchart.exec(this[0].id, "enable");
return this;
};
$.fn.exitFullscreen = function () {
zingchart.exec(this[0].id, "exitfullscreen");
return this;
};
$.fn.fullscreen = function () {
zingchart.exec(this[0].id, "fullscreen");
return this;
};
$.fn.hideMenu = function () {
zingchart.exec(this[0].id, "hidemenu");
return this;
};
$.fn.hidePlot = function (opts) {
zingchart.exec(this[0].id, "hideplot", opts);
return this;
};
$.fn.hideAllPlots = function (opts) {
var myId = this[0].id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid')) {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "hideplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
else {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "hideplot", {
"plotindex": i
});
}
}
return this;
};
$.fn.hideAllPlotsBut = function (opts) {
var myId = this[0].id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid') && opts.hasOwnProperty('plotindex')) {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "hideplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
}
else {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "hideplot", {
"plotindex": i
});
}
}
}
return this;
};
$.fn.modifyAllPlotsBut = function (opts, data) {
var myId = this[0].id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid') && opts.hasOwnProperty('plotindex')) {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "modifyplot", {
"graphid": opts.graphid,
"plotindex": i,
"data": data
});
}
}
}
else {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "modifyplot", {
"plotindex": i,
"data": data
});
}
}
}
return this;
};
$.fn.modifyAllPlots = function (data, opts) {
var myId = this[0].id;
var allPlots = ( opts ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
for (var i = 0; i < allPlots; i++) {
if (opts && opts.graphid) {
zingchart.exec(myId, "modifyplot", {
"graphid": opts.graphid,
"plotindex": i,
"data": data
});
}
else {
zingchart.exec(myId, "modifyplot", {
"plotindex": i,
"data": data
});
}
};
return this;
};
$.fn.showAllPlots = function (opts) {
var myId = this[0].id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid')) {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "showplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
else {
for (var i = 0; i < allPlots; i++) {
zingchart.exec(myId, "showplot", {
"plotindex": i
});
}
}
return this;
};
$.fn.showAllPlotsBut = function (opts) {
var myId = this[0].id;
var allPlots = ( opts && opts.hasOwnProperty("graphid") ? zingchart.exec(myId,"getplotlength",opts) : zingchart.exec(myId,"getplotlength"));
if (opts && opts.hasOwnProperty('graphid') && opts.hasOwnProperty('plotindex')) {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "showplot", {
"graphid": opts.graphid,
"plotindex": i
});
}
}
}
else {
for (var i = 0; i < allPlots; i++) {
if (i != opts.plotindex) {
zingchart.exec(myId, "showplot", {
"plotindex": i
});
}
}
}
return this;
};
$.fn.legendMaximize = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "legendmaximize", opts);
}
else {
zingchart.exec(this[0].id, "legendmaximize");
}
return this;
};
$.fn.legendMinimize = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "legendminimize", opts);
}
else {
zingchart.exec(this[0].id, "legendminimize");
}
return this;
};
$.fn.showMenu = function () {
zingchart.exec(this[0].id, "showmenu");
return this;
};
$.fn.showPlot = function (opts) {
zingchart.exec(this[0].id, "showplot", opts);
return this;
};
$.fn.toggleAbout = function () {
zingchart.exec(this[0].id, "toggleabout");
return this;
};
$.fn.toggleBugReport = function () {
zingchart.exec(this[0].id, "togglebugreport");
return this;
};
$.fn.toggleDimension = function () {
zingchart.exec(this[0].id, "toggledimension");
return this;
};
$.fn.toggleLegend = function () {
zingchart.exec(this[0].id, "togglelegend");
return this;
};
$.fn.toggleSource = function () {
zingchart.exec(this[0].id, "togglesource");
return this;
};
// ZOOM METHODS ===========================================================
$.fn.viewAll = function () {
zingchart.exec(this[0].id, "viewall");
return this;
};
$.fn.zoomIn = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "zoomin", opts);
}
else {
zingchart.exec(this[0].id, "zoomin");
}
return this;
};
$.fn.zoomOut = function (opts) {
if (opts) {
zingchart.exec(this[0].id, "zoomout", opts);
}
else {
zingchart.exec(this[0].id, "zoomout");
}
return this;
};
$.fn.zoomTo = function (opts) {
zingchart.exec(this[0].id, "zoomto", opts);
return this;
};
$.fn.zoomToValues = function (opts) {
zingchart.exec(this[0].id, "zoomtovalues", opts);
return this;
};
/*********************************************************************
****************************** EVENTS *******************************
*********************************************************************/
// ANIMATION EVENTS ====================================================
$.fn.animationEnd = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "animation_end", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.animationStart = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "animation_start", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.animationStep = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "animation_step", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
// DATA MANIPULATION EVENTS ===============================================
$.fn.chartModify = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "modify", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.nodeAdd = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "node_add", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.nodeRemove = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "node_remove", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.plotAdd = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_add", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.plotModify = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_modify", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.plotRemove = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_remove", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.chartReload = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "reload", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.dataSet = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "setdata", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
// EXPORT EVENTS ==========================================================
$.fn.dataExport = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "data_export", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.imageSave = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "image_save", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.chartPrint = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "print", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
// FEED EVENTS ============================================================
$.fn.feedClear = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "feed_clear", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.feedIntervalModify = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "feed_interval_modify", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.feedStart = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "feed_start", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.feedStop = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "feed_stop", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
// GLOBAL EVENTS
$.fn.graphClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.graphComplete = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "complete", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.graphDataParse = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "dataparse", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.graphDataReady = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "dataready", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.graphGuideMouseMove = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "guide_mousemove", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.graphLoad = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "load", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.graphMenuItemClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "menu_item_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.graphResize = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "resize", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
// HISTORY EVENTS =========================================================
$.fn.historyForward = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "history_forward", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.historyBack = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "history_back", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
// INTERACTIVE EVENTS =====================================================
$.fn.nodeSelect = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "node_select", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.nodeDeselect = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "node_deselect", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.plotSelect = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_select", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.plotDeselect = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_deselect", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
// LEGEND EVENTS ==========================================================
$.fn.legendItemClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "legend_item_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.legendMarkerClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "legend_marker_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
// NODE EVENTS ============================================================
$.fn.nodeClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "node_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.nodeDoubleClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "node_doubleclick", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.nodeMouseOver = function (callback) {
var jq = this;
var NODEMOUSEOVER = false;
zingchart.bind(this[0].id, "node_mouseover", function(p){
if (!NODEMOUSEOVER) {
$.extend(jq,{event:p});
NODEMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "node_mouseout", function(){
NODEMOUSEOVER = false;
});
return this;
};
$.fn.nodeMouseOut = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "node_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq);
});
return this;
};
$.fn.nodeHover = function (mouseover, mouseout) {
var jq = this;
var NODEMOUSEOVER = false;
zingchart.bind(this[0].id, "node_mouseover", function(p){
if (!NODEMOUSEOVER) {
$.extend(jq,{event:p});
NODEMOUSEOVER = true;
mouseover.call(jq);
}
});
zingchart.bind(jq[0].id, "node_mouseout", function(){
NODEMOUSEOVER = false;
mouseout.call(jq);
});
return this;
};
// LABEL EVENTS ============================================================
$.fn.labelClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "label_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.labelMouseOver = function (callback) {
var jq = this;
var LABELMOUSEOVER = false;
zingchart.bind(this[0].id, "label_mouseover", function(p){
if (!LABELMOUSEOVER) {
$.extend(jq,{event:p});
LABELMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "label_mouseout", function(){
LABELMOUSEOVER = false;
});
return this;
};
$.fn.labelMouseOut = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "label_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.labelHover = function (mouseover, mouseout) {
$(this).labelMouseOver(mouseover).labelMouseOut(mouseout);
return this;
};
// SHAPE EVENTS ============================================================
$.fn.shapeClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "shape_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.shapeMouseOver = function (callback) {
var jq = this;
var SHAPEMOUSEOVER = false;
zingchart.bind(this[0].id, "shape_mouseover", function(p){
if (!SHAPEMOUSEOVER) {
$.extend(jq,{event:p});
SHAPEMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "shape_mouseout", function(){
SHAPEMOUSEOVER = false;
});
return this;
};
$.fn.shapeMouseOut = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "shape_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.shapeHover = function (mouseover, mouseout) {
$(this).shapeMouseOver(mouseover).shapeMouseOut(mouseout);
return this;
};
// PLOT EVENTS ============================================================
$.fn.plotClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_click", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.plotDoubleClick = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_doubleclick", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.plotMouseOver = function (callback) {
var jq = this;
var PLOTMOUSEOVER = false;
zingchart.bind(this[0].id, "plot_mouseover", function(p){
if (!PLOTMOUSEOVER) {
$.extend(jq,{event:p});
PLOTMOUSEOVER = true;
callback.call(jq);
}
});
zingchart.bind(jq[0].id, "plot_mouseout", function(){
PLOTMOUSEOVER = false;
});
return this;
};
$.fn.plotMouseOut = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_mouseout", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.plotHover = function (mouseover, mouseout) {
$(this).plotMouseOver(mouseover).plotMouseOut(mouseout);
return this;
};
$.fn.plotShow = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.plotHide = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "plot_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
// TOGGLE EVENTS ==========================================================
$.fn.aboutShow = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "about_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.aboutHide = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "about_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.bugReportShow = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "bugreport_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.bugReportHide = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "bugreport_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.dimensionChange = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "dimension_change", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.sourceShow = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "source_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.sourceHide = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "source_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.legendShow = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "legend_show", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.legendHide = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "legend_hide", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.legendMaximize = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "legend_maximize", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.legendMinimize = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "legend_minimize", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
$.fn.zoomEvent = function (callback) {
var jq = this;
zingchart.bind(this[0].id, "zoom", function(p){
$.extend(jq,{event:p});
callback.call(jq)
});
return this;
};
/*********************************************************************
********************** HELPER METHODS *******************************
*********************************************************************/
$.fn.setTitle = function (newtitle) {
if (typeof(newtitle) == 'object') {
zingchart.exec(this[0].id, "modify", {
data: {
title: newtitle
}
});
}
else {
zingchart.exec(this[0].id, "modify", {
data: {
title: {
text: newtitle
}
}
});
}
return this;
};
$.fn.setSubtitle = function (newtitle) {
if (typeof(newtitle) == 'object') {
zingchart.exec(this[0].id, "modify", {
data: {
subtitle: newtitle
}
});
}
else {
zingchart.exec(this[0].id, "modify", {
data: {
subtitle: {
text: newtitle
}
}
});
}
return this;
};
$.fn.setType = function (type) {
zingchart.exec(this[0].id, "modify", {
"data": {
"type": type
}
});
zingchart.exec(this[0].id,"update");
return this;
};
$.fn.drawTrendline = function (opts) {
var myId = this[0].id;
calculate.call(this,0);
function calculate(pindex) {
var nodes = $(this).getSeriesValues({
plotindex:pindex
});
var sxy = 0, sx = 0, sy = 0, sx2 = 0, l = 0;
var oScaleInfo = $(this).getObjectInfo({
object : 'scale',
name : 'scale-x'
});
var aScaleValues = oScaleInfo.values;
for (var i=0;i<nodes.length;i++) {
if (nodes[i] && nodes[i][1] != undefined && typeof(nodes[i][1]) == 'number') {
sxy += nodes[i][0]*nodes[i][1];
sx += nodes[i][0];
sy += nodes[i][1];
sx2 += nodes[i][0]*nodes[i][0];
l++;
}
else {
sxy += nodes[i]*aScaleValues[i];
sx += aScaleValues[i];
sy += nodes[i];
sx2 += Math.pow(aScaleValues[i],2);
l++;
}
}
var b = (l * sxy - sx * sy) / (l * sx2 - sx * sx);
var a = (sy - b * sx) / l;
var oScaleInfo = $(this).getObjectInfo({
object : 'scale',
name : 'scale-x'
});
var aScaleValues = oScaleInfo.values, fScaleMin = aScaleValues[0], fScaleMax = aScaleValues[aScaleValues.length-1];
var aRange = [a + b*fScaleMin, a + b*fScaleMax];
var trendline = {
type : 'line',
lineColor : '#c00',
lineWidth : 2,
alpha : 0.75,
lineStyle : 'dashed',
label : {
text : ''
}
};
if (opts) {
$.extend(trendline,opts);
}
trendline.range = aRange;
var scaleY = $(this).getObjectInfo({
object:'scale',
name: 'scale-y'
});
var markers = scaleY.markers;
if (markers) {
markers.push(trendline);
}
else {
markers = [trendline];
}
$(this).modify({
"data": {
"scale-y": {
"markers": markers
}
}
});
}
return this;
};
}( jQuery ));
|
zingchart/ZingChart-jQuery
| 45
|
Easy ZingChart manipulation and interactivity for jQuery users.
|
JavaScript
|
zingchart
|
ZingChart
| |
zingchart.jquery.min.js
|
JavaScript
|
!function(t){t.fn.zingchart=function(e){var n=this[0].id,i={id:n,height:"100%",width:"100%"};return t.extend(i,e),zingchart.render(i),this},t.fn.loadModules=function(t){return zingchart.loadModules(t),this},t.fn.addNode=function(t){return zingchart.exec(this[0].id,"addnode",t),this},t.fn.addPlot=function(t){return zingchart.exec(this[0].id,"addplot",t),this},t.fn.appendSeriesData=function(t){return zingchart.exec(this[0].id,"appendseriesdata",t),this},t.fn.appendSeriesValues=function(t){return zingchart.exec(this[0].id,"appendseriesvalues",t),this},t.fn.getSeriesData=function(t){return t?zingchart.exec(this[0].id,"getseriesdata",t):zingchart.exec(this[0].id,"getseriesdata",{})},t.fn.getSeriesValues=function(t){return t?zingchart.exec(this[0].id,"getseriesvalues",t):zingchart.exec(this[0].id,"getseriesvalues",{})},t.fn.modifyPlot=function(t){return zingchart.exec(this[0].id,"modifyplot",t),this},t.fn.removeNode=function(t){return zingchart.exec(this[0].id,"removenode",t),this},t.fn.removePlot=function(t){return zingchart.exec(this[0].id,"removeplot",t),this},t.fn.set3dView=function(t){return zingchart.exec(this[0].id,"set3dview",t),this},t.fn.setNodeValue=function(t){return zingchart.exec(this[0].id,"setnodevalue",t),this},t.fn.setSeriesData=function(t){return zingchart.exec(this[0].id,"setseriesdata",t),this},t.fn.setSeriesValues=function(t){return zingchart.exec(this[0].id,"setseriesvalues",t),this},t.fn.exportData=function(){return zingchart.exec(this[0].id,"exportdata"),this},t.fn.getImageData=function(t){if("png"==t||"jpg"==t||"bmp"==t)return zingchart.exec(this[0].id,"getimagedata",{filetype:t}),this;throw"Error: Got "+t+", expected 'png' or 'jpg' or 'bmp'"},t.fn.print=function(){return zingchart.exec(this[0].id,"print"),this},t.fn.saveAsImage=function(){return zingchart.exec(this[0].id,"saveasimage"),this},t.fn.clearFeed=function(){return zingchart.exec(this[0].id,"clearfeed"),this},t.fn.getInterval=function(){return zingchart.exec(this[0].id,"getinterval")},t.fn.setInterval=function(t){if("number"==typeof t)return zingchart.exec(this[0].id,"setinterval",{interval:t}),this;if("object"==typeof t)return zingchart.exec(this[0].id,"setinterval",t),this;throw"Error: Got "+typeof t+", expected number"},t.fn.startFeed=function(){return zingchart.exec(this[0].id,"startfeed"),this},t.fn.stopFeed=function(){return zingchart.exec(this[0].id,"stopfeed"),this},t.fn.getChartType=function(t){return t?zingchart.exec(this[0].id,"getcharttype",t):zingchart.exec(this[0].id,"getcharttype")},t.fn.getData=function(){return zingchart.exec(this[0].id,"getdata")},t.fn.getEditMode=function(){return zingchart.exec(this[0].id,"geteditmode")},t.fn.getGraphLength=function(){return zingchart.exec(this[0].id,"getgraphlength")},t.fn.getNodeLength=function(t){return t?zingchart.exec(this[0].id,"getnodelength",t):zingchart.exec(this[0].id,"getnodelength")},t.fn.getNodeValue=function(t){return zingchart.exec(this[0].id,"getnodevalue",t)},t.fn.getObjectInfo=function(t){return zingchart.exec(this[0].id,"getobjectinfo",t)},t.fn.getPlotLength=function(t){return t?zingchart.exec(this[0].id,"getplotlength",t):zingchart.exec(this[0].id,"getplotlength")},t.fn.getPlotValues=function(t){return zingchart.exec(this[0].id,"getplotvalues",t)},t.fn.getRender=function(){return zingchart.exec(this[0].id,"getrender")},t.fn.getRules=function(t){return zingchart.exec(this[0].id,"getrules",t)},t.fn.getScales=function(t){return zingchart.exec(this[0].id,"getscales",t)},t.fn.getVersion=function(){return zingchart.exec(this[0].id,"getversion")},t.fn.getXYInfo=function(t){return zingchart.exec(this[0].id,"getxyinfo",t)},t.fn.addScaleValue=function(t){return zingchart.exec(this[0].id,"addscalevalue",{dataurl:t}),this},t.fn.destroy=function(t){return t?t.hasOwnProperty(""):zingchart.exec(this[0].id,"destroy"),this},t.fn.loadNewData=function(t){return zingchart.exec(this[0].id,"load",t),this},t.fn.modify=function(t){return zingchart.exec(this[0].id,"modify",t),this},t.fn.reloadChart=function(t){return t?zingchart.exec(this[0].id,"reload",t):zingchart.exec(this[0].id,"reload"),this},t.fn.removeScaleValue=function(t){return zingchart.exec(this[0].id,"removescalevalue",t),this},t.fn.resizeChart=function(t){return zingchart.exec(this[0].id,"resize",t),this},t.fn.setData=function(t){return zingchart.exec(this[0].id,"setdata",t),this},t.fn.update=function(t){return zingchart.exec(this[0].id,"update"),this},t.fn.goBack=function(){return zingchart.exec(this[0].id,"goback"),this},t.fn.goForward=function(){return zingchart.exec(this[0].id,"goforward"),this},t.fn.addNodeIA=function(t){return t?zingchart.exec(this[0].id,"addnodeia",t):zingchart.exec(this[0].id,"addnodeia"),this},t.fn.enterEditMode=function(t){return t?zingchart.exec(this[0].id,"entereditmode",t):zingchart.exec(this[0].id,"entereditmode"),this},t.fn.exitEditMode=function(t){return t?zingchart.exec(this[0].id,"exiteditmode",t):zingchart.exec(this[0].id,"exiteditmode"),this},t.fn.removeNodeIA=function(t){return t?zingchart.exec(this[0].id,"removenodeia",t):zingchart.exec(this[0].id,"removenodeia"),this},t.fn.removePlotIA=function(t){return t?zingchart.exec(this[0].id,"removeplotia",t):zingchart.exec(this[0].id,"removeplotia"),this},t.fn.addNote=function(t){return zingchart.exec(this[0].id,"addnote",t),this},t.fn.removeNote=function(t){return zingchart.exec(this[0].id,"removenote",{id:t}),this},t.fn.updateNote=function(t){return zingchart.exec(this[0].id,"updatenote",t),this},t.fn.addObject=function(t){return zingchart.exec(this[0].id,"addobject",t),this},t.fn.removeObject=function(t){return zingchart.exec(this[0].id,"removeobject",t),this},t.fn.repaintObjects=function(t){return t?zingchart.exec(this[0].id,"repaintobjects",t):zingchart.exec(this[0].id,"repaintobjects",{}),this},t.fn.updateObject=function(t){return zingchart.exec(this[0].id,"updateobject",t),this},t.fn.addLabel=function(t){return zingchart.exec(this[0].id,"addobject",{type:"label",data:t}),this},t.fn.removeLabel=function(t){return zingchart.exec(this[0].id,"removeobject",{type:"label",id:t}),this},t.fn.updateLabel=function(t){return zingchart.exec(this[0].id,"updateobject",{type:"label",data:t}),this},t.fn.addRule=function(t){return zingchart.exec(this[0].id,"addrule",t),this},t.fn.removeRule=function(t){return zingchart.exec(this[0].id,"removerule",t),this},t.fn.updateRule=function(t){return zingchart.exec(this[0].id,"updaterule",t),this},t.fn.clearSelection=function(t){return t?zingchart.exec(this[0].id,"clearselection",t):zingchart.exec(this[0].id,"clearselection"),this},t.fn.chartDeselect=function(t){return zingchart.exec(this[0].id,"deselect",t),this},t.fn.getSelection=function(t){return t?zingchart.exec(this[0].id,"getselection",t):zingchart.exec(this[0].id,"getselection"),this},t.fn.chartSelect=function(t){return zingchart.exec(this[0].id,"select",t),this},t.fn.setSelection=function(t){return zingchart.exec(this[0].id,"setselection",t),this},t.fn.disableChart=function(t){return t?zingchart.exec(this[0].id,"disable",{text:t}):zingchart.exec(this[0].id,"disable"),this},t.fn.enableChart=function(){return zingchart.exec(this[0].id,"enable"),this},t.fn.exitFullscreen=function(){return zingchart.exec(this[0].id,"exitfullscreen"),this},t.fn.fullscreen=function(){return zingchart.exec(this[0].id,"fullscreen"),this},t.fn.hideMenu=function(){return zingchart.exec(this[0].id,"hidemenu"),this},t.fn.hidePlot=function(t){return zingchart.exec(this[0].id,"hideplot",t),this},t.fn.hideAllPlots=function(t){var e=this[0].id,n=t&&t.hasOwnProperty("graphid")?zingchart.exec(e,"getplotlength",t):zingchart.exec(e,"getplotlength");if(t&&t.hasOwnProperty("graphid"))for(var i=0;n>i;i++)zingchart.exec(e,"hideplot",{graphid:t.graphid,plotindex:i});else for(var i=0;n>i;i++)zingchart.exec(e,"hideplot",{plotindex:i});return this},t.fn.hideAllPlotsBut=function(t){var e=this[0].id,n=t&&t.hasOwnProperty("graphid")?zingchart.exec(e,"getplotlength",t):zingchart.exec(e,"getplotlength");if(t&&t.hasOwnProperty("graphid")&&t.hasOwnProperty("plotindex"))for(var i=0;n>i;i++)i!=t.plotindex&&zingchart.exec(e,"hideplot",{graphid:t.graphid,plotindex:i});else for(var i=0;n>i;i++)i!=t.plotindex&&zingchart.exec(e,"hideplot",{plotindex:i});return this},t.fn.modifyAllPlotsBut=function(t,e){var n=this[0].id,i=t&&t.hasOwnProperty("graphid")?zingchart.exec(n,"getplotlength",t):zingchart.exec(n,"getplotlength");if(t&&t.hasOwnProperty("graphid")&&t.hasOwnProperty("plotindex"))for(var r=0;i>r;r++)r!=t.plotindex&&zingchart.exec(n,"modifyplot",{graphid:t.graphid,plotindex:r,data:e});else for(var r=0;i>r;r++)r!=t.plotindex&&zingchart.exec(n,"modifyplot",{plotindex:r,data:e});return this},t.fn.modifyAllPlots=function(t,e){for(var n=this[0].id,i=e?zingchart.exec(n,"getplotlength",e):zingchart.exec(n,"getplotlength"),r=0;i>r;r++)e&&e.graphid?zingchart.exec(n,"modifyplot",{graphid:e.graphid,plotindex:r,data:t}):zingchart.exec(n,"modifyplot",{plotindex:r,data:t});return this},t.fn.showAllPlots=function(t){var e=this[0].id,n=t&&t.hasOwnProperty("graphid")?zingchart.exec(e,"getplotlength",t):zingchart.exec(e,"getplotlength");if(t&&t.hasOwnProperty("graphid"))for(var i=0;n>i;i++)zingchart.exec(e,"showplot",{graphid:t.graphid,plotindex:i});else for(var i=0;n>i;i++)zingchart.exec(e,"showplot",{plotindex:i});return this},t.fn.showAllPlotsBut=function(t){var e=this[0].id,n=t&&t.hasOwnProperty("graphid")?zingchart.exec(e,"getplotlength",t):zingchart.exec(e,"getplotlength");if(t&&t.hasOwnProperty("graphid")&&t.hasOwnProperty("plotindex"))for(var i=0;n>i;i++)i!=t.plotindex&&zingchart.exec(e,"showplot",{graphid:t.graphid,plotindex:i});else for(var i=0;n>i;i++)i!=t.plotindex&&zingchart.exec(e,"showplot",{plotindex:i});return this},t.fn.legendMaximize=function(t){return t?zingchart.exec(this[0].id,"legendmaximize",t):zingchart.exec(this[0].id,"legendmaximize"),this},t.fn.legendMinimize=function(t){return t?zingchart.exec(this[0].id,"legendminimize",t):zingchart.exec(this[0].id,"legendminimize"),this},t.fn.showMenu=function(){return zingchart.exec(this[0].id,"showmenu"),this},t.fn.showPlot=function(t){return zingchart.exec(this[0].id,"showplot",t),this},t.fn.toggleAbout=function(){return zingchart.exec(this[0].id,"toggleabout"),this},t.fn.toggleBugReport=function(){return zingchart.exec(this[0].id,"togglebugreport"),this},t.fn.toggleDimension=function(){return zingchart.exec(this[0].id,"toggledimension"),this},t.fn.toggleLegend=function(){return zingchart.exec(this[0].id,"togglelegend"),this},t.fn.toggleSource=function(){return zingchart.exec(this[0].id,"togglesource"),this},t.fn.viewAll=function(){return zingchart.exec(this[0].id,"viewall"),this},t.fn.zoomIn=function(t){return t?zingchart.exec(this[0].id,"zoomin",t):zingchart.exec(this[0].id,"zoomin"),this},t.fn.zoomOut=function(t){return t?zingchart.exec(this[0].id,"zoomout",t):zingchart.exec(this[0].id,"zoomout"),this},t.fn.zoomTo=function(t){return zingchart.exec(this[0].id,"zoomto",t),this},t.fn.zoomToValues=function(t){return zingchart.exec(this[0].id,"zoomtovalues",t),this},t.fn.animationEnd=function(e){var n=this;return zingchart.bind(this[0].id,"animation_end",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.animationStart=function(e){var n=this;return zingchart.bind(this[0].id,"animation_start",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.animationStep=function(e){var n=this;return zingchart.bind(this[0].id,"animation_step",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.chartModify=function(e){var n=this;return zingchart.bind(this[0].id,"modify",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.nodeAdd=function(e){var n=this;return zingchart.bind(this[0].id,"node_add",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.nodeRemove=function(e){var n=this;return zingchart.bind(this[0].id,"node_remove",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.plotAdd=function(e){var n=this;return zingchart.bind(this[0].id,"plot_add",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.plotModify=function(e){var n=this;return zingchart.bind(this[0].id,"plot_modify",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.plotRemove=function(e){var n=this;return zingchart.bind(this[0].id,"plot_remove",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.chartReload=function(e){var n=this;return zingchart.bind(this[0].id,"reload",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.dataSet=function(e){var n=this;return zingchart.bind(this[0].id,"setdata",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.dataExport=function(e){var n=this;return zingchart.bind(this[0].id,"data_export",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.imageSave=function(e){var n=this;return zingchart.bind(this[0].id,"image_save",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.chartPrint=function(e){var n=this;return zingchart.bind(this[0].id,"print",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.feedClear=function(e){var n=this;return zingchart.bind(this[0].id,"feed_clear",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.feedIntervalModify=function(e){var n=this;return zingchart.bind(this[0].id,"feed_interval_modify",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.feedStart=function(e){var n=this;return zingchart.bind(this[0].id,"feed_start",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.feedStop=function(e){var n=this;return zingchart.bind(this[0].id,"feed_stop",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.graphClick=function(e){var n=this;return zingchart.bind(this[0].id,"click",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.graphComplete=function(e){var n=this;return zingchart.bind(this[0].id,"complete",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.graphDataParse=function(e){var n=this;return zingchart.bind(this[0].id,"dataparse",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.graphDataReady=function(e){var n=this;return zingchart.bind(this[0].id,"dataready",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.graphGuideMouseMove=function(e){var n=this;return zingchart.bind(this[0].id,"guide_mousemove",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.graphLoad=function(e){var n=this;return zingchart.bind(this[0].id,"load",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.graphMenuItemClick=function(e){var n=this;return zingchart.bind(this[0].id,"menu_item_click",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.graphResize=function(e){var n=this;return zingchart.bind(this[0].id,"resize",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.historyForward=function(e){var n=this;return zingchart.bind(this[0].id,"history_forward",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.historyBack=function(e){var n=this;return zingchart.bind(this[0].id,"history_back",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.nodeSelect=function(e){var n=this;return zingchart.bind(this[0].id,"node_select",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.nodeDeselect=function(e){var n=this;return zingchart.bind(this[0].id,"node_deselect",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.plotSelect=function(e){var n=this;return zingchart.bind(this[0].id,"plot_select",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.plotDeselect=function(e){var n=this;return zingchart.bind(this[0].id,"plot_deselect",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.legendItemClick=function(e){var n=this;return zingchart.bind(this[0].id,"legend_item_click",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.legendMarkerClick=function(e){var n=this;return zingchart.bind(this[0].id,"legend_marker_click",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.nodeClick=function(e){var n=this;return zingchart.bind(this[0].id,"node_click",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.nodeDoubleClick=function(e){var n=this;return zingchart.bind(this[0].id,"node_doubleclick",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.nodeMouseOver=function(e){var n=this,i=!1;return zingchart.bind(this[0].id,"node_mouseover",function(r){i||(t.extend(n,{event:r}),i=!0,e.call(n))}),zingchart.bind(n[0].id,"node_mouseout",function(){i=!1}),this},t.fn.nodeMouseOut=function(e){var n=this;return zingchart.bind(this[0].id,"node_mouseout",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.nodeHover=function(e,n){var i=this,r=!1;return zingchart.bind(this[0].id,"node_mouseover",function(n){r||(t.extend(i,{event:n}),r=!0,e.call(i))}),zingchart.bind(i[0].id,"node_mouseout",function(){r=!1,n.call(i)}),this},t.fn.labelClick=function(e){var n=this;return zingchart.bind(this[0].id,"label_click",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.labelMouseOver=function(e){var n=this,i=!1;return zingchart.bind(this[0].id,"label_mouseover",function(r){i||(t.extend(n,{event:r}),i=!0,e.call(n))}),zingchart.bind(n[0].id,"label_mouseout",function(){i=!1}),this},t.fn.labelMouseOut=function(e){var n=this;return zingchart.bind(this[0].id,"label_mouseout",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.labelHover=function(e,n){return t(this).labelMouseOver(e).labelMouseOut(n),this},t.fn.shapeClick=function(e){var n=this;return zingchart.bind(this[0].id,"shape_click",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.shapeMouseOver=function(e){var n=this,i=!1;return zingchart.bind(this[0].id,"shape_mouseover",function(r){i||(t.extend(n,{event:r}),i=!0,e.call(n))}),zingchart.bind(n[0].id,"shape_mouseout",function(){i=!1}),this},t.fn.shapeMouseOut=function(e){var n=this;return zingchart.bind(this[0].id,"shape_mouseout",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.shapeHover=function(e,n){return t(this).shapeMouseOver(e).shapeMouseOut(n),this},t.fn.plotClick=function(e){var n=this;return zingchart.bind(this[0].id,"plot_click",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.plotDoubleClick=function(e){var n=this;return zingchart.bind(this[0].id,"plot_doubleclick",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.plotMouseOver=function(e){var n=this,i=!1;return zingchart.bind(this[0].id,"plot_mouseover",function(r){i||(t.extend(n,{event:r}),i=!0,e.call(n))}),zingchart.bind(n[0].id,"plot_mouseout",function(){i=!1}),this},t.fn.plotMouseOut=function(e){var n=this;return zingchart.bind(this[0].id,"plot_mouseout",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.plotHover=function(e,n){return t(this).plotMouseOver(e).plotMouseOut(n),this},t.fn.plotShow=function(e){var n=this;return zingchart.bind(this[0].id,"plot_show",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.plotHide=function(e){var n=this;return zingchart.bind(this[0].id,"plot_hide",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.aboutShow=function(e){var n=this;return zingchart.bind(this[0].id,"about_show",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.aboutHide=function(e){var n=this;return zingchart.bind(this[0].id,"about_hide",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.bugReportShow=function(e){var n=this;return zingchart.bind(this[0].id,"bugreport_show",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.bugReportHide=function(e){var n=this;return zingchart.bind(this[0].id,"bugreport_hide",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.dimensionChange=function(e){var n=this;return zingchart.bind(this[0].id,"dimension_change",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.sourceShow=function(e){var n=this;return zingchart.bind(this[0].id,"source_show",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.sourceHide=function(e){var n=this;return zingchart.bind(this[0].id,"source_hide",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.legendShow=function(e){var n=this;return zingchart.bind(this[0].id,"legend_show",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.legendHide=function(e){var n=this;return zingchart.bind(this[0].id,"legend_hide",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.legendMaximize=function(e){var n=this;return zingchart.bind(this[0].id,"legend_maximize",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.legendMinimize=function(e){var n=this;return zingchart.bind(this[0].id,"legend_minimize",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.zoomEvent=function(e){var n=this;return zingchart.bind(this[0].id,"zoom",function(i){t.extend(n,{event:i}),e.call(n)}),this},t.fn.setTitle=function(t){return"object"==typeof t?zingchart.exec(this[0].id,"modify",{data:{title:t}}):zingchart.exec(this[0].id,"modify",{data:{title:{text:t}}}),this},t.fn.setSubtitle=function(t){return"object"==typeof t?zingchart.exec(this[0].id,"modify",{data:{subtitle:t}}):zingchart.exec(this[0].id,"modify",{data:{subtitle:{text:t}}}),this},t.fn.setType=function(t){return zingchart.exec(this[0].id,"modify",{data:{type:t}}),zingchart.exec(this[0].id,"update"),this},t.fn.drawTrendline=function(e){function n(n){for(var i=t(this).getSeriesValues({plotindex:n}),r=0,c=0,h=0,a=0,o=0,d=t(this).getObjectInfo({object:"scale",name:"scale-x"}),s=d.values,u=0;u<i.length;u++)i[u]&&void 0!=i[u][1]&&"number"==typeof i[u][1]?(r+=i[u][0]*i[u][1],c+=i[u][0],h+=i[u][1],a+=i[u][0]*i[u][0],o++):(r+=i[u]*s[u],c+=s[u],h+=i[u],a+=Math.pow(s[u],2),o++);var f=(o*r-c*h)/(o*a-c*c),l=(h-f*c)/o,d=t(this).getObjectInfo({object:"scale",name:"scale-x"}),s=d.values,g=s[0],x=s[s.length-1],z=[l+f*g,l+f*x],v={type:"line",lineColor:"#c00",lineWidth:2,alpha:.75,lineStyle:"dashed",label:{text:""}};e&&t.extend(v,e),v.range=z;var p=t(this).getObjectInfo({object:"scale",name:"scale-y"}),b=p.markers;b?b.push(v):b=[v],t(this).modify({data:{"scale-y":{markers:b}}})}this[0].id;return n.call(this,0),this}}(jQuery);
|
zingchart/ZingChart-jQuery
| 45
|
Easy ZingChart manipulation and interactivity for jQuery users.
|
JavaScript
|
zingchart
|
ZingChart
| |
zingify/zingify.jquery.js
|
JavaScript
|
(function ( $ ) {
$.fn.zingify = function( options ) {
if (options === undefined) {
options = {};
}
if ( $(this).is('table') ) {
return convertToChart.call(this, 0, options);
} else {
var charts = [];
$(this).find('table').each( function(i) {
charts.push( convertToChart.call(this, i, options) );
});
return charts;
}
/*
* options [object]: {
* target [string]: Target to add the chart to. If undefined, a target will be created
* hideTable [boolean]: Hides table if true; default: false
* }
*/
function convertToChart(i, options) {
//console.log("convertToChart:");
//console.log("\toptions =", JSON.stringify(options));
var target = undefined;
if ( options.target !== undefined) {
target = $('#' + options.target);
} else {
target = $('<div></div>').insertAfter(this);
// we need an options.target for the ID
// Create the target from
options.target = (new Date()).valueOf().toString();
target.attr('id', options.target);
}
//console.log("\ttarget =", target);
if (options.hideTable === true) {
$(this).hide();
}
//
$(target).width( options.hasOwnProperty('width') ? options.width : '100%' );
$(target).height( options.hasOwnProperty('height') ? options.height : '500px' );
// Each chart needs a UNIQUE identifier
var zingchartID = options.target + '_zc_chart';
if (i > 0) zingchartID += i;
//console.log('zingchartID =', zingchartID);
$(target).attr('id', zingchartID);
var data = {};
// extract the columns from the table into a data object
var columns = $(this).find('thead th').map(function() {
return $(this).text();
});
// the first <th> in <thead> corresponds to the data that will be
// represented on the x-axis, so we'll use that value for the x-axis label
data['scale-x'] = { label: { text: columns[0] }, values: [] };
// the remaining <td>s are the labels for each data series the chart will support
// so we'll create each series array, and push each series object onto with with text
data.series = [];
for (var i = 1; i < columns.length; i++) {
data.series.push( { text: columns[i], values: [] } );
}
$(this).find('tbody tr').each( function() {
$(this).find('td').each( function(i) {
if (i === 0) {
data['scale-x'].values.push( $(this).html() );
} else {
data.series[i - 1].values.push( parseInt( $(this).html() ));
}
});
});
// set the title from the <caption> element if present
if ( $(this).find('caption').html() !== undefined ) {
data.title = { text: $(this).find('caption').html() }
}
data.legend = {};
// now we extract JSON structure from any custom html data attributes
// get key-value mapped object of all the <table> attributes
// these will be parsed and the custom zingchart data extracted
/*
* Alternative way to extract data. Single attribute on the HTML element
* data-zc OR data-zingchart: contains a JSON string to be parsed
*/
var attributes = undefined;
try {
var jsonString = $(this).attr('data-zc') || $(this).attr('data-zingchart');
attributes = JSON.parse(jsonString);
} catch (err) {
//console.log(err);
attributes = {};
}
$(this).each(function() {
$.each(this.attributes, function() {
if(this.specified) {
attributes[this.name] = this.value;
}
});
});
// convert 'data-zingchart_' to 'data-zc_' (so user can specify it either way)
for (var key in attributes) {
if (key.substring(0,14) === 'data-zingchart') {
newKey = key.replace('data-zingchart', 'data-zc');
attributes[newKey] = attributes[key];
delete attributes[key];
}
}
// now filter out any attributes that do not begin with 'data-zc'
for (var key in attributes) {
if (key.substring(0,8) !== 'data-zc-') {
delete attributes[key];
}
}
var attrData = {};
for (var key in attributes) {
var attributeKey = key;
// strip off 'data-zc_' section
key = key.substring(8);
// separate into each JSON specification, which are delimited by underscores.
key = key.split('_');
// create a temp variable with the JSON struct corresponding to the values specified in the data attribute
var temp = generateJSON(-1);
// recursive function that generates a multi-level JSON struct from the 'flat' data attribute array
function generateJSON(count) {
count++;
if (count === key.length) {
// the last layer is not another object, but rather the value of the deepest JSON key specified
return attributes[attributeKey];
} else {
// the keys at the outer layers specify an object as their value, so recurse the function to generate the next step
var obj = {};
obj[key[count]] = generateJSON(count);
return obj;
}
}
$.extend(attrData, temp); // for each data attribute, attrData will gain additional key-value pairs
}
$.extend(true, data, attrData); // finally, extend all the JSON data collected from attributes into the main data variable
// $.extend(true, data, attributes);
// allow user to include JSON options in the standard form while invoking the zingify function
if (options.hasOwnProperty('data')) {
$.extend(true, data, options.data);
}
// temp fix: convert data['scale-x'] into data['scaleX']
data['scaleX'] = data['scale-x'];
return $(target).zingchart( { data: data } ); // and render the chart
}; // end convertToChart() function
}; // end $.fn.extend()
}( jQuery ));
|
zingchart/ZingChart-jQuery
| 45
|
Easy ZingChart manipulation and interactivity for jQuery users.
|
JavaScript
|
zingchart
|
ZingChart
| |
zingify/zingify.jquery.min.js
|
JavaScript
|
(function(t){t.fn.zingify=function(e){if(e===undefined){e={}}if(t(this).is("table")){return a.call(this,0,e)}else{var i=[];t(this).find("table").each(function(t){i.push(a.call(this,t,e))});return i}function a(e,i){console.log("convertToChart:");console.log(" options =",JSON.stringify(i));var a=undefined;if(i.target!==undefined){a=t("#"+i.target)}else{a=t("<div></div>").insertAfter(this);i.target=(new Date).valueOf().toString();a.attr("id",i.target)}console.log(" target =",a);if(i.hideTable===true){t(this).hide()}t(a).width(i.hasOwnProperty("width")?i.width:"100%");t(a).height(i.hasOwnProperty("height")?i.height:"500px");var n=i.target+"_zc_chart";if(e>0)n+=e;console.log("zingchartID =",n);t(a).attr("id",n);var r={};var s=t(this).find("thead th").map(function(){return t(this).text()});r["scale-x"]={label:{text:s[0]},values:[]};r.series=[];for(var e=1;e<s.length;e++){r.series.push({text:s[e],values:[]})}t(this).find("tbody tr").each(function(){t(this).find("td").each(function(e){if(e===0){r["scale-x"].values.push(t(this).html())}else{r.series[e-1].values.push(parseInt(t(this).html()))}})});if(t(this).find("caption").html()!==undefined){r.title={text:t(this).find("caption").html()}}r.legend={};var h=undefined;try{var l=t(this).attr("data-zc")||t(this).attr("data-zingchart");h=JSON.parse(l)}catch(d){console.log(d);h={}}t(this).each(function(){t.each(this.attributes,function(){if(this.specified){h[this.name]=this.value}})});for(var c in h){if(c.substring(0,14)==="data-zingchart"){newKey=c.replace("data-zingchart","data-zc");h[newKey]=h[c];delete h[c]}}for(var c in h){if(c.substring(0,8)!=="data-zc-"){delete h[c]}}var f={};for(var c in h){var o=c;c=c.substring(8);c=c.split("_");var u=g(-1);function g(t){t++;if(t===c.length){return h[o]}else{var e={};e[c[t]]=g(t);return e}}t.extend(f,u)}t.extend(true,r,f);if(i.hasOwnProperty("data")){t.extend(true,r,i.data)}r["scaleX"]=r["scale-x"];return t(a).zingchart({data:r})}}})(jQuery);
|
zingchart/ZingChart-jQuery
| 45
|
Easy ZingChart manipulation and interactivity for jQuery users.
|
JavaScript
|
zingchart
|
ZingChart
| |
test/readme.js
|
JavaScript
|
var mocha = require('mocha');
var chai = require('chai');
var expect = chai.expect;
var fs = require('fs');
describe('README', function () {
var readme;
var items;
before(function () {
readme = fs.readFileSync('./README.md', 'utf8');
});
it('should be in alphabetical order within each category', function () {
var categories = (readme.split('---'));
categories.shift();
for (var i = 0; i < categories.length; i++) {
if (categories[i].indexOf('####') === -1) {
items = extractListNames(categories[i]);
expect(compareArrays(items, alphabetize(items))).to.be.true;
} else {
var subCategories = categories[i].split('####');
subCategories.shift();
for (var k = 0; k < subCategories.length; k++) {
items = extractListNames(subCategories[k]);
expect(compareArrays(items, alphabetize(items))).to.be.true;
}
}
}
})
});
function alphabetize(items) {
var _items = [];
for (var i = 0; i < items.length; i++) {
_items.push(items[i]);
}
return _items.sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
}
function extractListNames(str) {
var regexp = /\* \[(.*?)\]/g;
var items = str.match(regexp);
return items;
}
function compareArrays(arr1, arr2) {
console.log("Unsorted : \n", arr1);
console.log("Sorted : \n", arr2);
console.log('----');
arr1 = arr1.join();
arr2 = arr2.join();
return arr1 === arr2;
}
|
zingchart/awesome-charting
| 2,073
|
A curated list of the best charting and dataviz resources that developers may find useful, including the best JavaScript charting libraries
|
zingchart
|
ZingChart
| ||
assets/editor.css
|
CSS
|
html,body{
margin: 0;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
height: 100%;
width : 100%;
}
.zc-editor {
width:100%;
}
.zc-top{
white-space:nowrap;
width:100%;
height:30px;
border-bottom: 1px solid #c1c1c1;
}
.zc-top:after { content:''; display:block; clear:both; }
.zc-top.blue{
background-color: #29A2CC;
color:white;
}
.zc-top.green{
background-color: #7CA82B;
color:white;
}
.zc-top.dark{
background-color: #363132;
color:white;
}
.zc-commands{
float:left;
}
.zc-actions{
float:right;
}
.zc-content{
overflow:hidden;
height: 100%;
width : 100%;
}
.zc-btn{
position: relative;
padding:0 15px;
float:left;
height:30px;
line-height:30px;
text-align:center;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
cursor: hand;
font-size: 0.8em;
cursor : pointer;
}
.zc-btn.active:after{
top: 100%;
left : 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 10px;
margin-left: -10px;
}
.zc-top.blue .zc-btn:hover{
background-color:#1C7B97;
color:white;
}
.zc-top.blue .zc-btn.active{
background-color: #003849;
color : white;
}
.zc-top.blue .zc-btn.active:after{
border-top-color: #003849;
}
.zc-top.green .zc-btn:hover{
background-color:#648623;
color:white;
}
.zc-top.green .zc-btn.active{
background-color: #49631A;
color : white;
}
.zc-top.green .zc-btn.active:after{
border-top-color: #49631A;
}
.zc-top.dark .zc-btn:hover{
background-color:#2990AE;
color:white;
}
.zc-top.dark .zc-btn.active{
background-color: #161414;
color : white;
}
.zc-top.dark .zc-btn.active:after{
border-top-color: #161414;
}
.zc-sprite{
margin: 5px;
background-repeat: no-repeat;
height: 20px;
background-image : url('/assets/sprite.png');
}
.zc-sprite.wide {
display:inline-block;
float:left;
}
.zc-top.blue .icon:hover:after{
border-bottom-color: #003849;
}
.zc-top.blue .icon:hover:before{
color : white;
background-color: #003849;
}
.zc-top.green .icon:hover:after{
border-bottom-color: #49631A;
}
.zc-top.green .icon:hover:before{
color : white;
background-color: #49631A;
}
.zc-top.dark .icon:hover:after{
border-bottom-color: #161414;
}
.zc-top.dark .icon:hover:before{
color : white;
background-color: #161414;
}
.zc-cont {
padding: 15px 0;
height:100%;
width:100%;
overflow-y:scroll;
background-color: #fff;
border:1px solid #d0d0d0;
box-sizing: border-box;
}
.zc-cont[id*="css"],
.zc-cont[id*="html"],
.zc-cont[id*="js"] {
background-color: #ececec;
}
.zc-cont[id*="result"] {
padding:15px;
border-width:15px;
border-color:#ececec;
}
.zc-cont pre { margin-bottom:0 !important; }
.zc-cont .ace-chrome .ace_gutter {
border:1px solid #d0d0d0; border-width:1px 0;
}
.zc-cont .ace-chrome .ace_scroller {
border:1px solid #d0d0d0; border-width:1px 0;
}
.zc-cont .ace-chrome .ace_marker-layer .ace_active-line {
background: rgba(112,186,212,.15);
}
.zc-cont .ace-chrome .ace_storage, .ace-chrome .ace_keyword, .ace-chrome .ace_meta.ace_tag {
color:
}
pre{
margin: 0px;
tab-size : 2;
-moz-tab-size: 2;
-o-tab-size: 2;
-webkit-tab-size: 2;
white-space: pre-wrap;
}
/* @group Prettify */
li.L0, li.L1, li.L2, li.L3,
li.L5, li.L6, li.L7, li.L8
{ list-style-type: decimal !important }
.com { color: #93a1a1; }
.lit { color: #195f91; }
.pun, .opn, .clo { color: #93a1a1; }
.fun { color: #dc322f; }
.str, .atv { color: #D14; }
.kwd, .linenums .tag { color: #1e347b; }
.typ, .atn, .dec, .var { color: teal; }
.pln { color: #48484c; }
.prettyprint {
padding: 8px !important;
word-wrap: break-word !important;
background-color: #f7f7f9;
border: 0px !important;
}
.prettyprint.linenums {
-webkit-box-shadow: inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0;
-moz-box-shadow: inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0;
box-shadow: inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0;
}
ol.linenums li {
padding-left: 12px;
color: #bebec5;
line-height: 18px;
text-shadow: 0 1px 0 #fff;
}
/* @end group Prettify */
@media screen and (max-width: 480px) {
.zc-top #dl-btn { display:none; }
.zc-actions {
display:none;
}
.zc-top {
min-width:100%;
}
}
|
zingchart/gitbook-plugin-code-editor
| 13
|
Plugin for Gitbook that displays and runs code from external file. Code is displayed in an Ace editor.
|
JavaScript
|
zingchart
|
ZingChart
| |
assets/editor.js
|
JavaScript
|
//2. Figure out css and js
require(["gitbook"], function(gitbook) {
gitbook.events.bind("page.change", initEditors);
});
function initEditors(){
var blocks = document.getElementsByClassName('zc-editor');
for (var i=0;i<blocks.length;i++){
initEditor(blocks[i].dataset.id, blocks[i].dataset.singleTab);
}
}
function initEditor(id, singleTab) {
if (singleTab === 'false'){
singleTab = false;
}
var editor = initAce(id);
var obj = {
js: document.getElementById('init-js' + id).value,
html: editor.getValue(),
css: document.getElementById('init-css' + id).value
};
//when we do js and css in the future, we'll need to check for active tabs here.
obj.js = obj.js.replace(/>/g, '>');
obj.js = obj.js.replace(/</g, '<');
document.getElementById('css-code' + id).innerHTML = obj.css;
document.getElementById('js-code' + id).innerHTML = obj.js;
//Set default tab
toggle(document.getElementById('init-active' + id).value, id, singleTab);
}
function initAce(id){
var fullId = 'codeeditor' + id;
var block = document.getElementById(fullId);
var settings = JSON.parse(block.dataset.settings);
var editor = ace.edit(fullId);
editor.setTheme('ace/theme/' + settings.theme );
editor.getSession().setMode('ace/mode/' + settings.mode);
editor.setReadOnly(settings.readOnly);
editor.setOption('maxLines', settings.maxLines);
return editor;
}
function extractDelimited(source, start, end){
var aParts = source.split(start);
var i = 1;
var deferString = "";
var headString = aParts[0];
while(i< aParts.length){
//Defer String
deferString += aParts[i].split(end)[0];
headString += aParts[i].slice(aParts[i].indexOf(end) + 9);
i++;
}
return {
extracted : deferString,
remaining : headString
}
}
function updateIframeCode(id){
var editor = ace.edit('codeeditor' + id);
var obj = {
js: document.getElementById('init-js' + id).value,
html: editor.getValue(),
css: document.getElementById('init-css' + id).value
};
var htmlParts = extractDelimited(obj.html, "<" + "script>", "<" + "/script>");
//Get global zingchart theme
var sJS = "<" + "script> window.onload= function(){" + htmlParts.extracted + obj.js + "}<" + "/script>";
var aParts = htmlParts.remaining.split('<' + '/body>');
var index = aParts[0].indexOf('<' + 'body>');
aParts[0] = aParts[0].slice(0, index + 5) + " style='margin:0px'" + aParts[0].slice(index + 5);
var sHTML = aParts[0] + sJS + aParts[1];
//Inject CSS
aParts = sHTML.split('<' + '/head>');
sHTML = aParts[0] + "<" + "style>" + obj.css + "<" + "/style>" + "</" + "head>" + aParts[1];
createIframe(sHTML, id);
}
function createIframe(sHTML, id){
var result = document.getElementById('result' + id);
var child = document.getElementById('preview' + id);
if (child){
result.removeChild(child);
}
var height = result.dataset.height;
var iFrame = document.createElement('iframe');
iFrame.style.width="100%";
iFrame.style.height=height;
iFrame.id = "preview" + id;
iFrame.src = "";
iFrame.frameBorder = "0";
result.appendChild(iFrame);
document.getElementById('preview' + id).contentWindow.document.write(sHTML);
document.getElementById('preview' + id).contentWindow.document.close();
}
function toggle(target, id, singleTab){
if (target === 'result'){
updateIframeCode(id);
}
if (singleTab){
var container = document.getElementById(target + id);
container.style.display = "";
}
else {
var containers = ['result', 'html', 'js', 'css'];
for (var i = 0; i < containers.length; i++) {
var container = document.getElementById(containers[i] + id);
var btn = document.getElementById(containers[i] + '-btn' + id);
if (container.id === (target + id)) {
container.style.display = "";
btn.className = "zc-btn active";
}
else {
if (btn) {
btn.className = "zc-btn";
}
container.style.display = "none";
}
}
}
}
function exportToCodepen(id){
//JS Code Block
var editor = ace.edit('codeeditor' + id);
var obj = {
js : document.getElementById('init-js' + id).value,
html : editor.getValue(),
css : document.getElementById('init-css' + id).value
};
document.getElementById('codepen-data'+id).value = JSON.stringify(obj);
document.getElementById('codepen-form'+id).submit();
}
function tabSizePolyfill(){
var codeElements = document.getElementsByTagName('code');
var e = document.createElement('i');
if(e.style.tabSize !== '' && e.style.MozTabSize !== '' && e.style.oTabSize !== ''){
ele[i].innerHTML = ele[i].innerHTML.replace(/\t/g, " ");
}
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
|
zingchart/gitbook-plugin-code-editor
| 13
|
Plugin for Gitbook that displays and runs code from external file. Code is displayed in an Ace editor.
|
JavaScript
|
zingchart
|
ZingChart
| |
assets/editorLoad.js
|
JavaScript
|
function loadTemplate(options) {
var str = `
<div class="zc-editor" data-id="${options.id}" data-single-tab="${options.singleTab}">`;
if (!options.singleTab) {
str += `
<div class="zc-top blue">
<div class="zc-actions">
<div class="zc-btn" data-text="JSFiddle" onclick="exportToCodepen(${options.id});">
<div>Export</div>
</div>
</div>
<div class="zc-commands">
<div id="html-btn${options.id}" class="zc-btn" onclick="toggle('html', ${options.id})">HTML</div>
<!--<div id="js-btn${options.id}" class="zc-btn" onclick="toggle('js', ${options.id})">JavaScript</div>-->
<!--<div id="css-btn${options.id}" class="zc-btn" onclick="toggle('css', ${options.id})">CSS</div>-->
<div id="result-btn${options.id}" class="zc-btn" onclick="toggle('result', ${options.id})">Result</div>
</div>
</div>`;
}
str += `
<div class="zc-content">
<div id="html${options.id}" class="zc-cont" style="display:none; ">
<div class="editor" id="codeeditor${options.id}" data-settings='${ JSON.stringify(options.editorSettings) }'>${options.html}</div>
</div>`;
if (!options.singleTab || options.singleTab === 'result') {
str += `<div id="result${options.id}" class="zc-cont" style="overflow:hidden;" data-height="${options.height}"></div>`;
}
str += `
<div id="js${options.id}" class="zc-cont" style="display:none">
<pre id="js-code${options.id}" class="prettyprint linenums"></pre>
</div>
<div id="css${options.id}" class="zc-cont" style="display:none">
<pre id="css-code${options.id}" class="prettyprint linenums"></pre>
</div>
</div>
<input type="hidden" id="init-html${options.id}" value= "${ options.html }">
<input type="hidden" id="init-css${options.id}" value= "${ options.css }">
<input type="hidden" id="init-js${options.id}" value= "${options.js }">
<input type="hidden" id="init-active${options.id}" value= "${options.initTab }">
<div style="display:none;">
<form method="post" id="codepen-form${options.id}" action="//codepen.io/pen/define" target="check">
<input id="codepen-data${options.id}" type="hidden" name="data" />
<input type="hidden" name="wrap" value="l">
</form>
</div>
</div>
`;
return str;
}
module.exports.load = loadTemplate;
|
zingchart/gitbook-plugin-code-editor
| 13
|
Plugin for Gitbook that displays and runs code from external file. Code is displayed in an Ace editor.
|
JavaScript
|
zingchart
|
ZingChart
| |
index.js
|
JavaScript
|
var fs = require('fs');
var Q = require('q');
var htmlencode = require('htmlencode');
var path = require('path');
var editorLoad = require('./assets/editorLoad');
var _counter = 1;
var _currentPage;
module.exports = {
website: {
assets: "./assets",
js: [
"http://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js",
"https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js",
"editor.js"
],
css: [
'editor.css'
]
},
hooks: {
"page:before": function (page) {
_currentPage = page;
return page;
}
},
blocks: {
codeeditor: {
process: function (block) {
if (this.generator === 'website') {
var id = _counter++;
var config = block.kwargs;
var height = config.height || '300px';
var settings = {
readOnly: config.readOnly || false,
mode: config.language || 'html',
theme: config.theme || 'chrome',
maxLines: config.maxLines || 25
};
var options = {};
options.css = "";
options.js = "";
options.editorSettings = settings;
options.height = height;
options.id = id;
options.initTab = config.initTab || 'html';
options.singleTab = config.singleTab || false;
if (options.singleTab) {
options.initTab = options.singleTab;
}
if (config.src) {
// Read the file
var fullPath = path.resolve(path.dirname(_currentPage.rawPath), config.src);
return Q.nfcall(fs.readFile, fullPath, "utf-8")
.then(function (data) {
data = htmlencode.htmlEncode(data).replace(/ /g, ' ');
options.html = data;
return editorLoad.load(options);
});
}
else{
//var body = htmlencode.htmlEncode(block.body).replace(/ /g, ' ');
return '';
//options.html = body;
//return editorLoad.load(options);
}
}
else {
return '';
}
}
}
}
};
|
zingchart/gitbook-plugin-code-editor
| 13
|
Plugin for Gitbook that displays and runs code from external file. Code is displayed in an Ace editor.
|
JavaScript
|
zingchart
|
ZingChart
| |
.configs/.mocharc.js
|
JavaScript
|
'use strict';
// Here's a JavaScript-based config file.
// If you need conditional logic, you might want to use this type of config.
// Otherwise, JSON or YAML is recommended.
module.exports = {
diff: true,
extension: ['spec'],
opts: false,
exit: true, // end bash script when done
slow: 75,
timeout: 5000,
ui: 'bdd',
spec: ['test/*.spec.js'],
color: true,
output: 'test/test.js'
};
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
public/index.html
|
HTML
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
rollup.config.js
|
JavaScript
|
import babel from "rollup-plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import external from "rollup-plugin-peer-deps-external";
import postcss from "rollup-plugin-postcss";
import resolve from "@rollup/plugin-node-resolve";
import url from "@rollup/plugin-url";
import svgr from "@svgr/rollup";
import pkg from "./package.json";
export default {
input: "src/lib/Zingchart.js",
output: [
{
file: pkg.main,
format: "cjs",
},
{
file: pkg.module,
format: "esm",
},
],
plugins: [
external(),
postcss({
modules: true,
}),
url(),
svgr(),
babel({
exclude: "node_modules/**",
}),
resolve(),
commonjs(),
],
};
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/App.css
|
CSS
|
.App {
text-align: center;
}
.App-header {
background-color: #c3c3c5;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 120%;
color: white;
}
.App-buttonbar {
display: flex;
flex-direction: row;
padding-bottom: 2em;
}
[class*="App-button-"] {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
display: inline-block;
font-size: 16px;
border-radius: 8px;
text-decoration: none;
margin-right: 1em;
}
.App-button-plain {
color: white;
}
.App-button-active {
color: black;
}
.App-button-plain:hover {
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
.App-link {
color: #61dafb;
}
.Events-wrapper {
display: flex;
flex-direction: row;
}
.Events-output {
border: 1px;
border-style: solid;
width: 30%;
margin-top: 1em;
margin-bottom: 1em;
margin-right: 1em;
}
.Events-bound {
margin-left: 1em;
text-align: left;
}
.Events-bound ul {
margin-top: 0.5em;
}
.Events-renderState {
background-color:#c3c3c5;
color: white;
padding-top: 0.3em;
padding-bottom: 0.3em;
}
.Events-nodeInfo {
margin-left: 1em;
text-align: left;
}
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/App.js
|
JavaScript
|
import React from "react";
import { NavLink, Route, Routes } from "react-router-dom";
import Simple from "./components/Simple.js";
import ModuleChart from "./components/ModuleChart.js";
import ModuleDrag from "./components/ModuleDrag.js";
import Dynamic from "./components/Dynamic.js";
import Events from "./components/Events.js";
import Methods from "./components/Methods.js";
import License from "./components/License.js";
import "./App.css";
/**
* The main application component. This component is responsible for
* rendering the navigation bar and the content of the currently selected
* demo.
*/
function App() {
const modules = {
"/": {
label: "Hello World",
text: "Demonstrates a simple chart of static data",
file: "Simple.js",
},
"/module_chart": {
label: "US Map",
text: "Demonstrates explicitly importing ZingChart modules",
file: "ModuleChart.js",
},
"/module_drag": {
label: "Interaction",
text: "Demonstrates interacting with a chart to change data",
file: "ModuleDrag.js",
},
"/dynamic": {
label: "Reconfiguring",
text: "Demonstrates modifying the configuration of an existing chart",
file: "Dynamic.js",
},
"/events": {
label: "Events",
text: "Demonstrates responding to chart events",
file: "Events.js",
},
"/methods": {
label: "Methods",
text: "Demonstrates using a reference to a ZingChart element to invoke methods on it",
file: "Methods.js",
},
"/license": {
label: "Multiple Plots",
text: "Demonstrates setting the license key and performance flags on the ZingChart object, as well as multiple plots",
file: "License.js",
},
};
return (
<div className="App">
<header className="App-header">
<h2>ZingChart React Demo</h2>
<h6>
A simple example of binding data, mutations with methods, and
listening to events
</h6>
<div className="App-buttonbar">
{Object.entries(modules).map(([path, mod], index) => (
<NavLink
to={path}
key={index}
className={({ isActive }) =>
isActive ? "App-button-active" : "App-button-plain"
}
>
{mod.label}
</NavLink>
))}
</div>
</header>
<div className="App-demo-block">
<div className="App-demo-titlebar">
<Routes>
{Object.entries(modules).map(([path, mod], index) => (
<Route
exact
path={path}
key={index}
element={<h3>{mod.text}</h3>}
/>
))}
</Routes>
</div>
<div className="App-demo-demo">
<Routes>
<Route exact path="/" element={<Simple />} />
<Route path="/module_chart" element={<ModuleChart />} />
<Route path="/module_drag" element={<ModuleDrag />} />
<Route path="/dynamic" element={<Dynamic />} />
<Route path="/events" element={<Events />} />
<Route path="/methods" element={<Methods />} />
<Route path="/license" element={<License />} />
</Routes>
</div>
</div>
</div>
);
}
export default App;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/components/Dynamic.js
|
JavaScript
|
import React, { useState, useEffect } from "react";
import "zingchart/es6";
import ZingChart from "../lib/Zingchart";
/*
* A dynamically updating line plot. Demonstrates modifying the
* configuration of an existing ZingChart.
*/
function Dynamic() {
const nValues = 10;
const period = 1000; // milliseconds
// Return an array of `count` random values
const randomData = (count) =>
[...Array(count)].map(() => Math.floor(Math.random() * 10));
const [config, setConfig] = useState({
type: "line",
series: [{ values: randomData(nValues) }],
});
/*
* Set a new random dataset
*/
function shuffle() {
setConfig((state) => ({
...state,
series: [{ values: randomData(nValues) }],
}));
}
// Create an effect to periodically update the chart data
useEffect(() => {
const interval = setInterval(shuffle, period);
// Invoked to clean up when unmounted
return () => clearInterval(interval);
}, []);
return (
<div>
<div>{JSON.stringify(config.series[0].values)}</div>
<ZingChart data={config} />
</div>
);
}
export default Dynamic;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/components/Events.js
|
JavaScript
|
import React, { useState } from "react";
import "zingchart/es6";
import ZingChart from "../lib/Zingchart";
/*
* A line chart with events logged to a text box.
*/
function Events() {
const listOfEventListeners = ["complete", "node_mouseover"];
const events = listOfEventListeners.map((value, index) => (
<li key={index}>{value}</li>
));
const [config] = useState({
type: "line",
series: [
{
values: [4, 5, 3, 4, 5, 3, 5, 4, 11],
},
],
});
const [output, setOutput] = useState("");
const [renderState, setRenderState] = useState("pending");
/*
* Invoked when the chart has finished rendering
*/
function chartDone() {
setRenderState("rendered");
}
/*
* Handle the info relating to the node under the cursor
*/
function nodeInfo(info) {
delete info.ev; // Remove the event data
setOutput(`Node Info\n${JSON.stringify(info, null, 2)}\n`);
}
return (
<div className="Events-wrapper">
<ZingChart data={config} complete={chartDone} node_mouseover={nodeInfo} />
<div className="Events-output">
<h2>Output from events</h2>
<div className="Events-bound">
Events bound:
<ul>{events}</ul>
</div>
<div className="Events-renderState">Chart is {renderState}</div>
<pre className="Events-nodeInfo">{output}</pre>
</div>
</div>
);
}
export default Events;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/components/License.js
|
JavaScript
|
import React, { useState } from "react";
import zingchart from "zingchart/es6";
import ZingChart from "../lib/Zingchart";
/*
* Demonstrate setting the license key and performance
* flags on the ZingChart object, as well as multiple
* plots in one chart.
*/
// Set performance flags on the ZingChart object
zingchart.DEV.KEEPSOURCE = 0; // prevents lib from storing the original data package
zingchart.DEV.COPYDATA = 0; // prevents lib from creating a copy of the data package
// Set the license key on the ZingChart object
zingchart.LICENSE = ["abcdefghijklmnopqrstuvwxy"];
function License() {
const [config] = useState({
/* Graphset array */
graphset: [
{
/* Object containing chart data */ type: "line",
/* Size your chart using height/width attributes */
height: "200px",
width: "90%",
/* Position your chart using x/y attributes */
x: "5%",
y: "5%",
series: [
{
values: [76, 23, 15, 85, 13],
},
{
values: [36, 53, 65, 25, 45],
},
],
},
{
/* Object containing chart data */ type: "funnel",
height: "55%",
width: "45%",
x: "5%",
y: "200px",
series: [
{ values: [30] },
{ values: [15] },
{ values: [5] },
{ values: [3] },
],
},
{
type: "pie",
height: "55%",
width: "45%",
x: "50%",
y: "200px",
series: [{ values: [15] }, { values: [30] }, { values: [34] }],
},
],
});
return <ZingChart data={config} />;
}
export default License;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/components/Methods.js
|
JavaScript
|
import React, { useState, useRef } from "react";
import "zingchart/es6";
import ZingChart from "../lib/Zingchart";
/*
* A bar chart with a button that adds additional data. Demonstrates
* using a reference to a ZingChart element.
*/
function Methods() {
const nValues = 10;
// Return an array of `count` random values
const randomData = (count) =>
[...Array(count)].map(() => Math.floor(Math.random() * 10));
const chart = useRef(null);
const [nSets, setNSets] = useState(1);
const [config] = useState({
type: "bar",
series: [
{
values: randomData(nValues),
},
],
});
/*
* Add an additional dataset to the existing barchart
*/
function addDataset() {
chart.current.addplot({
data: {
values: randomData(nValues),
},
});
setNSets((n) => n + 1);
}
return (
<div>
<button onClick={addDataset}>Add dataset {nSets + 1}</button>
<ZingChart ref={chart} data={config} />
</div>
);
}
export default Methods;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/components/ModuleChart.js
|
JavaScript
|
import React, { useState } from "react";
import "zingchart/es6";
import ZingChart from "../lib/Zingchart";
import "zingchart/modules-es6/zingchart-maps.min.js";
import "zingchart/modules-es6/zingchart-maps-usa.min.js";
/*
* Vector map of the 48 US states. Demonstrates explicitly importing
* ZingChart modules.
*/
function ModuleChart() {
const [config] = useState({
shapes: [
{
type: "zingchart.maps",
options: {
name: "usa",
ignore: ["AK", "HI"],
},
},
],
});
return <ZingChart data={config} height="600px" />;
}
export default ModuleChart;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/components/ModuleDrag.js
|
JavaScript
|
import React, { useState, useRef } from "react";
import "zingchart/es6";
import ZingChart from "../lib/Zingchart";
import "zingchart/modules-es6/zingchart-dragging.min.js";
/*
* Demonstrate interacting with a chart to change its data
* using the dragging module. Note that the module is imported
* and then passed as a prop to the ZingChart component.
*/
function ModuleDrag() {
const startingValues = [20, 40, 14, 50, 15, 35, 5];
const goals = [25, 43, 30, 40, 21, 59, 35];
// Compare values to goals and return count of goals met
function countGoodDays(vs, gs) {
let n = 0;
for (const i in vs) if (vs[i] >= gs[i]) n++;
return n;
}
const chart = useRef(null);
const [goodDays, setGoodDays] = useState(
countGoodDays(startingValues, goals)
);
const [config] = useState({
type: "vbullet",
title: {
text: "Pushups Per Day",
},
subtitle: {
text: "Bars are draggable",
},
plot: {
valueBox: [
{
type: "all",
text: "[%node-value / %node-goal-value]",
color: "#000",
placement: "goal",
},
],
},
scaleX: {
labels: ["Mon", "Tues", "Wed", "Thur", "Fri", "Sat", "Sun"],
},
tooltip: {
borderRadius: "3px",
borderWidth: "0px",
fontSize: "14px",
shadow: true,
},
series: [
{
values: startingValues,
dataDragging: true,
goal: {
backgroundColor: "#64b5f6",
borderWidth: "0px",
},
goals: goals,
rules: [
{
backgroundColor: "#81c784",
rule: "%v >= %g",
},
{
backgroundColor: "#ef5350",
rule: "%v < %g/2",
},
{
backgroundColor: "#ffca28",
rule: "%v >= %g/2 && %v < %g",
},
],
},
],
});
/*
* Update the number of days the goals have been met
*/
function showData() {
const data = chart.current.getseriesdata();
setGoodDays(countGoodDays(data[0].values, data[0].goals));
}
return (
<div>
<div>Goals met {goodDays} days this week</div>
<ZingChart
ref={chart}
data={config}
height="600px"
modules="dragging"
zingchart_plugins_dragging_complete={showData}
/>
</div>
);
}
export default ModuleDrag;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/components/Simple.js
|
JavaScript
|
import React from "react";
import "zingchart/es6";
import ZingChart from "../lib/Zingchart";
/*
* Simplest demo, just a bar chart of static data
*/
function Simple() {
const config = {
type: "bar",
series: [
{
values: [4, 5, 3, 4, 5, 3, 5, 4, 11],
},
],
};
return <ZingChart data={config} />;
}
export default Simple;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/index.css
|
CSS
|
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/index.js
|
JavaScript
|
import React from "react";
import ReactDOM from "react-dom/client";
import reportWebVitals from "./reportWebVitals";
import { BrowserRouter } from "react-router-dom";
import "./index.css";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/lib/Zingchart.js
|
JavaScript
|
import React, { Component } from "react";
import zingchart from "zingchart";
import constants from "zingchart-constants";
const {
DEFAULT_WIDTH,
DEFAULT_HEIGHT,
DEFAULT_OUTPUT,
EVENT_NAMES,
METHOD_NAMES,
} = constants;
// One time setup globally to handle all zingchart-react objects in the app space.
if (!window.ZCReact) {
window.ZCReact = {
instances: {},
count: 0,
};
}
class ZingChart extends Component {
constructor(props) {
super(props);
this.id = this.props.id || "zingchart-react-" + window.ZCReact.count++;
// Bind all methods available to zingchart to be accessed via Refs.
METHOD_NAMES.forEach((name) => {
this[name] = (args) => {
return window.zingchart.exec(this.id, name, args);
};
});
this.state = {
style: {
height: this.props.height || DEFAULT_HEIGHT,
width: this.props.width || DEFAULT_WIDTH,
},
};
}
render() {
return <div id={this.id} style={this.state.style}></div>;
}
bindEvent(eventName, originalEventName) {
if (EVENT_NAMES.includes(eventName)) {
// Filter through the provided events list, then register it to zingchart.
window.zingchart.bind(this.id, eventName, (result) => {
this.props[originalEventName || eventName](result);
});
return true;
} else {
return false;
}
}
componentDidMount() {
// Bind all events registered.
Object.keys(this.props).forEach((eventName) => {
if (!this.bindEvent(eventName)) {
// Replace '_' with '.' and attempt again
let newEventName = eventName.replace(/\_/g, ".");
this.bindEvent(newEventName, eventName);
}
});
this.renderChart();
}
// Used to check the values being passed in to avoid unnecessary changes.
shouldComponentUpdate(nextProps) {
// Data change
if (JSON.stringify(nextProps.data) !== JSON.stringify(this.props.data)) {
zingchart.exec(this.id, "setdata", {
data: nextProps.data,
});
// Series change
} else if (
JSON.stringify(nextProps.series) !== JSON.stringify(this.props.series)
) {
zingchart.exec(this.id, "setseriesdata", {
graphid: 0,
plotindex: 0,
data: nextProps.series,
});
// Resize
} else if (
nextProps.width !== this.props.width ||
nextProps.height !== this.props.height
) {
this.setState({
style: {
width: nextProps.width || DEFAULT_WIDTH,
height: nextProps.height || DEFAULT_HEIGHT,
},
});
zingchart.exec(this.id, "resize", {
width: nextProps.width || DEFAULT_WIDTH,
height: nextProps.height || DEFAULT_HEIGHT,
});
}
// React should never re-render since ZingChart controls this component.
return false;
}
renderChart() {
const renderObject = {};
Object.keys(this.props).forEach((prop) => {
renderObject[prop] = this.props[prop];
});
// Overwrite some existing props.
renderObject.id = this.id;
renderObject.width = this.props.width || DEFAULT_WIDTH;
renderObject.height = this.props.height || DEFAULT_HEIGHT;
renderObject.data = this.props.data;
renderObject.output = this.props.output || DEFAULT_OUTPUT;
if (this.props.series) {
renderObject.data.series = this.props.series;
}
if (this.props.theme) {
renderObject.defaults = this.props.theme;
}
if (this.props.modules) {
renderObject.modules = this.props.modules;
}
zingchart.render(renderObject);
}
componentWillUnmount() {
zingchart.exec(this.id, "destroy");
}
}
// export ZingChart react class as the default
export default ZingChart;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
src/reportWebVitals.js
|
JavaScript
|
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
| |
test/build.spec.js
|
JavaScript
|
const utils = require("./utils.js");
const chai = require("chai");
chai.use(require("chai-fs"));
// server/controllers/api/card.js
describe("Build", function () {
describe("dist/zingchart-react.js", function () {
// verify the ZingChart object exists
it(`zingchart-react.esm.js file should exist`, async function () {
let zcReactFilePath = "dist/zingchart-react.esm.js";
expect(zcReactFilePath).to.be.a.path();
});
// verify exports
it(`default export exists`, async function () {
// exports.ZC = ZC$2;
let zcReactFilePath = "dist/zingchart-react.cjs.js";
expect(zcReactFilePath)
.to.be.a.file()
.with.contents.that.match(/module.exports = ZingChart;/);
});
});
});
|
zingchart/zingchart-react
| 93
|
Quickly create dynamic JavaScript charts with ZingChart & React.
|
JavaScript
|
zingchart
|
ZingChart
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.