Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Statistics-Framework-SMP (Read 2809 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Statistics-Framework-SMP


A helper script for Spider Monkey Panel and foobar2000 which allows to easily create customizable charts on demand, applying basic filtering, sorting and distribution settings.

Helper meant mostly for coders not for final users, although it may be easily included on any script (don't expect how to's by my side apart from these instructions).


Features
  • Create charts: bars, scatter, line.
  • Colors, axis, background, margins, labels and points are customizable.
  • Data may be filtered, sorted or sliced on the fly.
  • Data may be fit to a distribution or shown 'as is' (with selected sorting).
  • Multiple series can be drawn on the same chart.

X

Usage
First create the chart object. In this case 2 series are added:
Code: [Select]
const chart = new _chart({
data: [
[{x:'A', y: 10},{x:'B', y: 4},{x:'C', y: 6},{x:'D', y: 7},{x:'E', y: 3}],
[{x:'A', y: 3},{x:'B', y: 7},{x:'C', y: 4},{x:'D', y: 2},{x:'E', y: 5}]
],
dataManipulation: {sort: null, filter: null, slice: null, distribution: null},
background: {color: RGB(200,200,200)},
margin: {left: _scale(20), right: _scale(10), top: _scale(10), bottom: _scale(15)},
axis: {
x: {show: true, color: RGB(0,0,0), width: _scale(2), ticks: 'auto', labels: true, key: 'Cities'},
y: {show: true, color: RGB(0,0,0), width: _scale(2), ticks: 5, labels: true, key: 'Population'}
},
x: 0,
w: window.Width,
y: 0,
h: window.Height,
tooltipText: '\n\n(This is additional info)'
});

Then, you may want to associate it to the panel callbacks for painting, resizing, mouse...:
Code: [Select]
function on_paint(gr) {
if (!window.Width || !window.Height) {return;}
chart.paint(gr);
}

function on_size() {
const w = window.Width;
const h = window.Height;
const x = 0;
const y = 0;
if (!w || !h) {return;}
chart.changeConfig({x, y, w, h});
}

function on_mouse_move(x, y, mask) {
chart.move(x,y);
}

function on_mouse_leave(x, y, mask) {
chart.leave();
};

A menu can also be added:
Code: [Select]
include('helpers\\statistics_xxx_menu.js'); // menu_xxx.js must also be present!
bindMenu(chart);
function on_mouse_rbtn_up(x, y) {
chart.rbtn_up(x,y);
return true; // left shift + left windows key will bypass this callback and will open default context menu.
}

X

There are more usage examples on the 'examples' folder.

Installation
Since the framework only requires 1 file, i.e. the main one, you can simply include it along any other script where you will use the charts. The helpers will be loaded automatically.

When using the extra menus, the menu framework file must be present too.

Download latest release (or nightly releases) at github:
https://github.com/regorxxx/Statistics-Framework-SMP

Re: Statistics-Framework-SMP

Reply #1
Plan to continue work on it with more chart types and distributions, anyway 'as is' should be handy for people who want to compute Last.FM , playback or library tag stats, etc.

The examples folder contains some scripts to compute graphs for genre (first chart) or style (second) tags for ex, while there is another one to show the most played artists (third chart). See first gif.

Obviously chart config should be saved somewhere (properties or json) to reload it between sessions.

Re: Statistics-Framework-SMP

Reply #2
Plan to continue work on it with more chart types and distributions, anyway 'as is' should be handy for people who want to compute Last.FM , playback or library tag stats, etc.


Wow, I've been hoping for something like this for years! Will take some time before I can dig in, but will share whatever I come up with if it's useful.

btw, not sure if you're aware of this?
https://github.com/apexcharts

Re: Statistics-Framework-SMP

Reply #3
Thing is we can't use standard js libraries within foobar since UI methods to draw things (strings, etc.) are restricted to those provided by SMP. So most fancy libraries out there need to be manually re-coded.

But the code logic for the data may be used, yep. And I may implement some of those charts styles/types, they look good.

I plan to do "something" with the framework, right now there are a few examples which use actual data from user's library; but my idea is implementing interactive charts which may be associated to customizable TitleFormat expressions. Also providing yearly reports like Spotify or MusicBrainz do.

Btw right now the colors are randomly set if they are not set manually (in case some color is too dark or light, just reload the panel).

Re: Statistics-Framework-SMP

Reply #4

The examples folder contains some scripts to compute graphs for genre (first chart) or style (second) tags for ex, while there is another one to show the most played artists (third chart).

FYI, example 1 loaded fine, but ex. 2+3 gave same error:

Code: [Select]
Error: Spider Monkey Panel v1.6.1 (Statistics example 2: Statistics example 2 v1.0.0 by XXX)
DrawLine failed:
GdiPlus error: DrawLine failed with error (0xb): ValueOverflow

File: statistics_xxx.js
Line: 202, Column: 8
Stack trace:
  _chart/this.paintGraph/<@statistics_xxx.js:202:8
  _chart/this.paintGraph@statistics_xxx.js:200:10
  _chart/this.paint@statistics_xxx.js:254:8
  on_paint/<@02_statistics.js:159:35
  on_paint@02_statistics.js:159:9

Re: Statistics-Framework-SMP

Reply #5
Re download the files, I updated them with some fixes just after posting here. My bad  ::)
(I think you are seeing the same bug than I saw, when passing data with missing values)

I designed it to crash when passing bad data, but probably I should simply display a message instead of crashing. The examples use arbitrary data from the library so... it works in my case but it may not works in other's library. I think I covered all cases in my latest commits, but let me know otherwise.

Re: Statistics-Framework-SMP

Reply #6
https://github.com/regorxxx/Statistics-Framework-SMP/releases/tag/v0.2.0
Quote
[0.2.0] - 2022-08-04
Added

    '04_statistics.js' new example showing Chroma Palettes usage.
    Color palette entries added to built-in menu.
    New method to set default configuration 'setDefaults()'.
    New method to export current configuration as object 'exportConfig()' (to be saved on panel properties, etc.).

Changed

    Missing colors are now set using Chroma Palettes. 'chroma.scheme' variable may be set to use 'diverging, qualitative, sequential or random'; schemes randomly use a palette found at [colorbrewer)(https://colorbrewer2.org/) for the matching type. An specific palette may also be set like 'OrRd' (sequential scheme). When setting it to 'random' the colors are randomly set without any consideration about color contrast.
    Qualitative scheme now replaces the previous default behavior for missing colors (random).
    Specific colors may be set for some series while leaving others to be randomly set. _chart({data, colors: [,RGB(255 , 255, 255),], ...}) will set the color for the second serie and fill the holes with the scheme used (see above). Previously holes were not allowed, so colors set were always applied to first series.
    Minor improvements on examples.

Removed
Fixed

    Variables not set at init for nested objects now also use default values (which was the intended behavior).
    Setting colors variable to null broke the chart generation, now forces an empty array by default (which is latter filled with colors according to the palette schemes).
    Fixed colors configuration on '03_statistics.js' example due to a wrong usage of default data variable.
    Fixed position configuration on '03_statistics.js' example. No visual changes, just in case it gets reused or expanded.


Spoiler (click to show/hide)

Re: Statistics-Framework-SMP

Reply #7
I am very grateful for your efforts. It would be great if you could add the pie chart implementation to the frame.

Re: Statistics-Framework-SMP

Reply #8
I am very grateful for your efforts. It would be great if you could add the pie chart implementation to the frame.

SMP doesn't support SVG format, so it's not trivial to create a pie chart, unless I use a polygon instead of a circle. @TheQwertiest

I could try drawing a triangle plues a ellipse which somewhat would be the same, but that's not really the way to do it (and I would have to calculate the coordinates for it). Maybe I'm missing other way to do it, filling the polygon with a tons of points to simulate a circle slice doesn't seem a good idea.

Re: Statistics-Framework-SMP

Reply #9
Nevermind, it seems drawing polygons does not harm performance too much and rendering is good enough. It's suboptimal, but works.

X X X

Have to add labels and mouse effects, but works. Will update it on a few days.



Re: Statistics-Framework-SMP

Reply #12
I think it's done, unless I missed some minor thing/error. Also added doughnut charts. Both work the same than the other chart types, so can be sorted, filtered, applied a normal distribution, etc.

X

Will upload it this evening.

Re: Statistics-Framework-SMP

Reply #13
https://github.com/regorxxx/Statistics-Framework-SMP/releases/tag/v0.3.0

Quote
[0.3.0] - 2023-08-24
Added

    'pie' graph type. Colors are set per data point, not only per serie. i.e. A serie with 4 values, requires at least 4 colors. Not setting one will fallback to a random Chroma Palette (per serie). In case of using multiple series to showcase the same categories, it's recommended to set a specific Chroma scheme (like 'BuGn'), so all series use the same palette.
    'doughnut' graph type. Colors are set per data point, not only per serie. Read comments above about 'pie' graph type.
    'singleLabels' axis variable to not draw multiple times the X labels per serie (only applicable to 'pie' graph type). This is the default behavior.
    'dataAsync' variable to pass function returning a promise or a promise, resolving to data, to initialize a graph while calculating data without blocking the panel. Once the promise is resolved the chart is repaint with the data.
    'configuration' variable to pass some chart exotic configurations. Currently allows 'bLoadAsyncData' key, which is set to true by default. i.e. when passing asynchronous data, it will be refreshed once available. Setting it to false will not try to repaint the chart with the data automatically.
    '05_statistics.js' and '06_statistics.js' new examples showing asynchronous loading.
    '07_statistics.js' and '08_statistics.js' new examples showing pie and doughnut graphs.
    Animation while loading asynchronous data.

Changed

    Minor performance improvement (usually on subsequent calls) caching all TitleFormat expressions.
    Improvements to vertical text using image rotation instead of chars flipped. Old behavior may be used setting 'configuration.bAltVerticalText' to true.
    Minor fix to vertical text.

Removed
Fixed

    Crash when no data is available painting ticks on Y axis.
    Crash when no data is available.


 

Re: Statistics-Framework-SMP

Reply #14
Minor fix
https://github.com/regorxxx/Statistics-Framework-SMP/releases/tag/v0.3.1
Quote
## [0.3.1] - 2023-08-24
### Added
### Changed
### Removed
### Fixed
- Vertical text clear type fixing.