Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function Chart(req, res) {
try {
const routeParams = req.params
const type = routeParams.type
const body = req.query || {}
const chartData = (body.data || '').split(',')
const chartColor = (body.hexcolor) ? `#${body.hexcolor}` : null
const height = (body.height) ? parseInt(body.height) : null
const width = (body.width) ? parseInt(body.width) : null
const fillOpacity = (body.opacity) ? parseFloat(body.opacity) : null
if (chartData.length <= 1)
return res.status(400).json({ error: 'Please pass valid data.' })
exporter.export({ type: 'png', options: ChartConfig.getChartConfig(chartData, {
type: type,
color: chartColor,
opacity: fillOpacity,
height: height,
width: width
})}, function(err, response) {
//The export result is now in res.
//If the output is not PDF or SVG, it will be base64 encoded (res.data).
//If the output is a PDF or SVG, it will contain a filename (res.filename).
//Kill the pool when we're done with it, and exit the application
// exporter.killPool()
// process.exit(1)
const imageBase64 = response.data
const imageBuffer = Buffer.from(imageBase64, 'base64')
const dataManager = require('./dataManager');
const exporter = require('highcharts-export-server');
const uuidv4 = require('uuid/v4');
const path = require('path');
const fs = require('fs');
exporter.initPool();
function renderPluginImage(pluginId, options, callback) {
// TODO use waterfall
dataManager.getChartByPluginIdAndChartId(pluginId, 'players', ['type', 'title', 'data'], function (err, players) {
if (err) {
console.log(err)
return callback(err);
}
dataManager.getChartByPluginIdAndChartId(pluginId, 'servers', ['type', 'title', 'data'], function (err, servers) {
if (err) {
console.log(err)
return callback(err);
}
if (players === null || servers === null) {
return callback(null, {error: 'Unknown plugin or plugin without servers/players charts'});
}
colors: options.colors || ["#F44336", "#2196F3", "#4CAF50", "#FF9800", "#FFEB3B", "#009688",
"#E91E63", "#795548", "#607D8B", "#3F51B5", "#9C27B0"]
})
};
for (let i = 0; i < data.length; i++) {
exportSettings.options.series.push({
name : options.lineName[i] || '',
data : data[i],
type: 'area',
tooltip: {
valueDecimals: 0
}
});
}
exporter.export(exportSettings, function (err) {
if (err) {
return callback(err);
}
fs.readFile(path.resolve(__dirname + '/../' + fileName), 'utf8', function(err, contents) {
if (err) {
return callback(err);
}
fs.unlink(path.resolve(__dirname + '/../' + fileName), function(err) {
if (err) {
console.log(err);
}
});
contents = contents.replace(fileName, '<a xlink:title="bStats.org" xlink:href="https://bStats.org/">View full stats at bStats.org</a>');
callback(null, { result: contents });
});
});
series : [{
name : options.lineName || '',
data : data,
type: 'area',
tooltip: {
valueDecimals: 0
}
}]
},
globalOptions: JSON.stringify({
colors: options.colors || ["#F44336", "#2196F3", "#4CAF50", "#FF9800", "#FFEB3B", "#009688",
"#E91E63", "#795548", "#607D8B", "#3F51B5", "#9C27B0"]
})
};
exporter.export(exportSettings, function (err) {
if (err) {
return callback(err);
}
fs.readFile(path.resolve(__dirname + '/../' + fileName), 'utf8', function(err, contents) {
if (err) {
return callback(err);
}
fs.unlink(path.resolve(__dirname + '/../' + fileName), function(err) {
if (err) {
console.log(err);
}
});
contents = contents.replace(fileName, '<a xlink:title="bStats.org" xlink:href="https://bStats.org/">View full stats at bStats.org</a>');
callback(null, { result: contents });
});
});
return new Promise((resolve, reject) => {
try {
const routeParams = req.params
const body = req.query || req.body || {}
const chartType = routeParams.type || body.type
const rawConfig = jsonParseFallback(body.raw || {}, {})
const chartData = (body.data || '').split(',')
delete(body.data)
if (chartData.length <= 1 && !rawConfig.series)
return res.status(400).json({ status: 400, error: `Please pass valid data. If you passed a 'raw' param with data populated in the 'series' key, there is likely something wrong with the JSON config you passed.` })
const finalConfig = ChartHelpers.getConfig(chartData, Object.assign(body, { type: chartType }), rawConfig)
exporter.export({ type: 'png', options: finalConfig}, function(err, response) {
if (err) {
res.status(500).json({ status: 500, error: err })
return reject(err)
}
const imageBase64 = response.data
const imageBuffer = Buffer.from(imageBase64, 'base64')
res.setHeader('Content-Type', 'image/png')
res.send(imageBuffer)
resolve(imageBuffer)
})
} catch(err) {
res.status(500).json({ status: 500, error: err })
reject(err)
import fs from 'fs'
import exporter from 'highcharts-export-server'
import ChartHelpers, { jsonParseFallback } from '../libs/ChartHelpers'
//Set up a pool of PhantomJS workers
exporter.initPool()
export default function Chart(req, res) {
return new Promise((resolve, reject) => {
try {
const routeParams = req.params
const body = req.query || req.body || {}
const chartType = routeParams.type || body.type
const rawConfig = jsonParseFallback(body.raw || {}, {})
const chartData = (body.data || '').split(',')
delete(body.data)
if (chartData.length <= 1 && !rawConfig.series)
return res.status(400).json({ status: 400, error: `Please pass valid data. If you passed a 'raw' param with data populated in the 'series' key, there is likely something wrong with the JSON config you passed.` })
const finalConfig = ChartHelpers.getConfig(chartData, Object.assign(body, { type: chartType }), rawConfig)
import fs from 'fs'
import exporter from 'highcharts-export-server'
import ChartConfig from '../libs/ChartConfig'
//Set up a pool of PhantomJS workers
exporter.initPool()
export default async function Chart(req, res) {
try {
const routeParams = req.params
const type = routeParams.type
const body = req.query || {}
const chartData = (body.data || '').split(',')
const chartColor = (body.hexcolor) ? `#${body.hexcolor}` : null
const height = (body.height) ? parseInt(body.height) : null
const width = (body.width) ? parseInt(body.width) : null
const fillOpacity = (body.opacity) ? parseFloat(body.opacity) : null
if (chartData.length <= 1)
return res.status(400).json({ error: 'Please pass valid data.' })
type: 'datetime',
dateTimeLabelFormats: {
month: '%M:%S',
year: '%M:%S',
day: '%M:%S',
minute: '%M:%S',
second: '%M:%S',
millisecond: '%M:%S'
}
},
series: [{ showInLegend: false, data: bpms }]
},
themeOptions: CHART_THEME
};
highcharts.export(highcharts_settings, (err, res) => {
if(err) cb('An error occured creating the graph')
else cb(null, res.data);
});
}catch(e){
cb('An error occured creating the graph');
helper.error(e);
return;
}
},
const ur_calc = require('./renderer/ur.js');
const frame = require('./renderer/render_frame.js');
const helper = require('./helper.js');
const highcharts = require('highcharts-export-server');
const {execFileSync} = require('child_process');
const Jimp = require('jimp');
const MINUTE = 60 * 1000;
const STRAIN_STEP = 400.0;
const DECAY_BASE = [ 0.3, 0.15 ];
const STAR_SCALING_FACTOR = 0.0675;
const EXTREME_SCALING_FACTOR = 0.5;
const DECAY_WEIGHT = 0.9;
highcharts.initPool();
const config = require('./config.json');
let tracked_users = {};
if(helper.getItem('tracked_users')){
tracked_users = JSON.parse(helper.getItem('tracked_users'));
}else{
helper.setItem('tracked_users', JSON.stringify(tracked_users));
}
let top_plays = {};
if(helper.getItem('top_plays')){
top_plays = JSON.parse(helper.getItem('top_plays'));
}else{