Skip to content

Commit

Permalink
Added pull request Freeboard#278
Browse files Browse the repository at this point in the history
Added pull request Freeboard#227
Added highchart plugin from https://github.com/onlinux/freeboard-dynamic-highcharts-plugin, and added object-support
  • Loading branch information
joed74 committed Aug 20, 2022
1 parent 321d573 commit bbcba28
Show file tree
Hide file tree
Showing 18 changed files with 1,095 additions and 76 deletions.
1 change: 1 addition & 0 deletions css/freeboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ header h1 {
position: relative;
-webkit-box-shadow: 0 0 5px #000;
box-shadow: 0 0 5px #000;
overflow:scroll;
}

#toggle-header {
Expand Down
2 changes: 1 addition & 1 deletion css/freeboard.min.css

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"plugins/thirdparty/paho.mqtt.plugin.js",
"plugins/thirdparty/randomdatasource.plugin.js",
"plugins/thirdparty/interactive_indicator.js",
"examples/plugin_example.js",
"plugins/thirdparty/plugin_highcharts.js",
"examples/plugin_example.js",

// *** Load more plugins here ***
function(){
Expand Down
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<script type="text/javascript">
head.js("js/freeboard_plugins.min.js",
"plugins/thirdparty/paho.mqtt.plugin.js",
"plugins/thirdparty/interactive_indicator.js",
"plugins/thirdparty/plugin_highcharts.js",
"plugins/thirdparty/interactive_indicator.js",
// *** Load more plugins here ***
function(){
$(function()
Expand Down
45 changes: 23 additions & 22 deletions js/freeboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DatasourceModel = function(theFreeboardModel, datasourcePlugins) {
}

// Do we need to load any external scripts?
if(datasourceType.external_scripts)
if(datasourceType.external_scripts && datasourceType.external_scripts.length>0)
{
head.js(datasourceType.external_scripts.slice(0), finishLoad); // Need to clone the array because head.js adds some weird functions to it
}
Expand Down Expand Up @@ -704,14 +704,12 @@ function FreeboardModel(datasourcePlugins, widgetPlugins, freeboardUI)
}
}

function FreeboardUI()
function FreeboardUI(pane_margin, pane_width, min_columns)
{
var PANE_MARGIN = 10;
var PANE_WIDTH = 300;
var MIN_COLUMNS = 3;
var COLUMN_WIDTH = PANE_MARGIN + PANE_WIDTH + PANE_MARGIN;

var userColumns = MIN_COLUMNS;
var column_width = pane_margin + pane_width + pane_margin;

var userColumns = min_columns;

var loadingIndicator = $('<div class="wrapperloading"><div class="loading up" ></div><div class="loading down"></div></div>');
var grid;
Expand Down Expand Up @@ -812,9 +810,9 @@ function FreeboardUI()
{
var col_controls = $(".column-tool");
var available_width = $("#board-content").width();
var max_columns = Math.floor(available_width / COLUMN_WIDTH);
var max_columns = Math.floor(available_width / column_width);

if(grid.cols <= MIN_COLUMNS)
if(grid.cols <= min_columns)
{
col_controls.addClass("min");
}
Expand All @@ -836,14 +834,14 @@ function FreeboardUI()
function getMaxDisplayableColumnCount()
{
var available_width = $("#board-content").width();
return Math.floor(available_width / COLUMN_WIDTH);
return Math.floor(available_width / column_width);
}

function updateGridWidth(newCols)
{
if(newCols === undefined || newCols < MIN_COLUMNS)
if(newCols === undefined || newCols < min_columns)
{
newCols = MIN_COLUMNS;
newCols = min_columns;
}

var max_columns = getMaxDisplayableColumnCount();
Expand All @@ -853,7 +851,7 @@ function FreeboardUI()
}

// +newCols to account for scaling on zoomed browsers
var new_width = (COLUMN_WIDTH * newCols) + newCols;
var new_width = (column_width * newCols) + newCols;
$(".responsive-column-width").css("max-width", new_width);

if(newCols === grid.cols)
Expand All @@ -877,7 +875,7 @@ function FreeboardUI()
rootElement.find("> li").each(repositionFunction);

grid.init();
$(".responsive-column-width").css("width", grid.cols * PANE_WIDTH + (grid.cols * PANE_MARGIN * 2));
$(".responsive-column-width").css("width", grid.cols * pane_width + (grid.cols * pane_margin * 2));
}

function getUserColumns()
Expand All @@ -887,16 +885,16 @@ function FreeboardUI()

function setUserColumns(numCols)
{
userColumns = Math.max(MIN_COLUMNS, numCols);
userColumns = Math.max(min_columns, numCols);
}

ko.bindingHandlers.grid = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
{
// Initialize our grid
grid = $(element).gridster({
widget_margins : [PANE_MARGIN, PANE_MARGIN],
widget_base_dimensions: [PANE_WIDTH, 10],
widget_margins : [pane_margin, pane_margin],
widget_base_dimensions: [pane_width, 10],
resize: {
enabled : false,
axes : "x"
Expand Down Expand Up @@ -1145,6 +1143,7 @@ function FreeboardUI()
}
}


JSEditor = function () {
var assetRoot = ""

Expand Down Expand Up @@ -1257,6 +1256,7 @@ function PaneModel(theFreeboardModel, widgetPlugins) {

this.processSizeChange = function()
{
console.log("processSizeChange");
// Give the animation a moment to complete. Really hacky.
// TODO: Make less hacky. Also, doesn't work when screen resizes.
setTimeout(function(){
Expand Down Expand Up @@ -2306,16 +2306,17 @@ function WidgetModel(theFreeboardModel, widgetPlugins) {

this.processDatasourceUpdate = function (datasourceName, newDataNames) {
var refreshSettingNames = self.datasourceRefreshNotifications[datasourceName];

if (_.isArray(refreshSettingNames)) {
var updates=[];
_.each(refreshSettingNames, function (setting) {
_.each(setting.value, function (valuename) {
if (newDataNames.includes(valuename)) {
if (updates.findIndex(updates => updates === setting.name)===-1) {
_.each(newDataNames, function (newdataname) {
if (newdataname.startsWith(valuename)) {
if (updates.findIndex(updates => updates === setting.name)===-1) {
updates.push(setting.name);
}
}
}
});
});
});
_.each(updates, function (name) {
Expand Down Expand Up @@ -2676,7 +2677,7 @@ var freeboard = (function()
var datasourcePlugins = {};
var widgetPlugins = {};

var freeboardUI = new FreeboardUI();
var freeboardUI = new FreeboardUI(10, 300, 3);
var theFreeboardModel = new FreeboardModel(datasourcePlugins, widgetPlugins, freeboardUI);

var jsEditor = new JSEditor();
Expand Down
2 changes: 1 addition & 1 deletion js/freeboard.min.js

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions js/freeboard_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DatasourceModel = function(theFreeboardModel, datasourcePlugins) {
}

// Do we need to load any external scripts?
if(datasourceType.external_scripts)
if(datasourceType.external_scripts && datasourceType.external_scripts.length>0)
{
head.js(datasourceType.external_scripts.slice(0), finishLoad); // Need to clone the array because head.js adds some weird functions to it
}
Expand Down Expand Up @@ -704,14 +704,12 @@ function FreeboardModel(datasourcePlugins, widgetPlugins, freeboardUI)
}
}

function FreeboardUI()
function FreeboardUI(pane_margin, pane_width, min_columns)
{
var PANE_MARGIN = 10;
var PANE_WIDTH = 300;
var MIN_COLUMNS = 3;
var COLUMN_WIDTH = PANE_MARGIN + PANE_WIDTH + PANE_MARGIN;

var userColumns = MIN_COLUMNS;
var column_width = pane_margin + pane_width + pane_margin;

var userColumns = min_columns;

var loadingIndicator = $('<div class="wrapperloading"><div class="loading up" ></div><div class="loading down"></div></div>');
var grid;
Expand Down Expand Up @@ -812,9 +810,9 @@ function FreeboardUI()
{
var col_controls = $(".column-tool");
var available_width = $("#board-content").width();
var max_columns = Math.floor(available_width / COLUMN_WIDTH);
var max_columns = Math.floor(available_width / column_width);

if(grid.cols <= MIN_COLUMNS)
if(grid.cols <= min_columns)
{
col_controls.addClass("min");
}
Expand All @@ -836,14 +834,14 @@ function FreeboardUI()
function getMaxDisplayableColumnCount()
{
var available_width = $("#board-content").width();
return Math.floor(available_width / COLUMN_WIDTH);
return Math.floor(available_width / column_width);
}

function updateGridWidth(newCols)
{
if(newCols === undefined || newCols < MIN_COLUMNS)
if(newCols === undefined || newCols < min_columns)
{
newCols = MIN_COLUMNS;
newCols = min_columns;
}

var max_columns = getMaxDisplayableColumnCount();
Expand All @@ -853,7 +851,7 @@ function FreeboardUI()
}

// +newCols to account for scaling on zoomed browsers
var new_width = (COLUMN_WIDTH * newCols) + newCols;
var new_width = (column_width * newCols) + newCols;
$(".responsive-column-width").css("max-width", new_width);

if(newCols === grid.cols)
Expand All @@ -877,7 +875,7 @@ function FreeboardUI()
rootElement.find("> li").each(repositionFunction);

grid.init();
$(".responsive-column-width").css("width", grid.cols * PANE_WIDTH + (grid.cols * PANE_MARGIN * 2));
$(".responsive-column-width").css("width", grid.cols * pane_width + (grid.cols * pane_margin * 2));
}

function getUserColumns()
Expand All @@ -887,16 +885,16 @@ function FreeboardUI()

function setUserColumns(numCols)
{
userColumns = Math.max(MIN_COLUMNS, numCols);
userColumns = Math.max(min_columns, numCols);
}

ko.bindingHandlers.grid = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
{
// Initialize our grid
grid = $(element).gridster({
widget_margins : [PANE_MARGIN, PANE_MARGIN],
widget_base_dimensions: [PANE_WIDTH, 10],
widget_margins : [pane_margin, pane_margin],
widget_base_dimensions: [pane_width, 10],
resize: {
enabled : false,
axes : "x"
Expand Down Expand Up @@ -1145,6 +1143,7 @@ function FreeboardUI()
}
}


JSEditor = function () {
var assetRoot = ""

Expand Down Expand Up @@ -1257,6 +1256,7 @@ function PaneModel(theFreeboardModel, widgetPlugins) {

this.processSizeChange = function()
{
console.log("processSizeChange");
// Give the animation a moment to complete. Really hacky.
// TODO: Make less hacky. Also, doesn't work when screen resizes.
setTimeout(function(){
Expand Down Expand Up @@ -2306,16 +2306,17 @@ function WidgetModel(theFreeboardModel, widgetPlugins) {

this.processDatasourceUpdate = function (datasourceName, newDataNames) {
var refreshSettingNames = self.datasourceRefreshNotifications[datasourceName];

if (_.isArray(refreshSettingNames)) {
var updates=[];
_.each(refreshSettingNames, function (setting) {
_.each(setting.value, function (valuename) {
if (newDataNames.includes(valuename)) {
if (updates.findIndex(updates => updates === setting.name)===-1) {
_.each(newDataNames, function (newdataname) {
if (newdataname.startsWith(valuename)) {
if (updates.findIndex(updates => updates === setting.name)===-1) {
updates.push(setting.name);
}
}
}
});
});
});
_.each(updates, function (name) {
Expand Down Expand Up @@ -2676,7 +2677,7 @@ var freeboard = (function()
var datasourcePlugins = {};
var widgetPlugins = {};

var freeboardUI = new FreeboardUI();
var freeboardUI = new FreeboardUI(10, 300, 3);
var theFreeboardModel = new FreeboardModel(datasourcePlugins, widgetPlugins, freeboardUI);

var jsEditor = new JSEditor();
Expand Down
2 changes: 1 addition & 1 deletion js/freeboard_plugins.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/css/freeboard/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ header h1 {
position: relative;
-webkit-box-shadow: 0 0 5px #000;
box-shadow: 0 0 5px #000;
overflow:scroll;
}

#toggle-header {
Expand Down
2 changes: 1 addition & 1 deletion lib/js/freeboard/DatasourceModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DatasourceModel = function(theFreeboardModel, datasourcePlugins) {
}

// Do we need to load any external scripts?
if(datasourceType.external_scripts)
if(datasourceType.external_scripts && datasourceType.external_scripts.length>0)
{
head.js(datasourceType.external_scripts.slice(0), finishLoad); // Need to clone the array because head.js adds some weird functions to it
}
Expand Down
Loading

0 comments on commit bbcba28

Please sign in to comment.