Skip to content

Commit

Permalink
#1 Next version of Floria, starting to remove Dojo dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhasson-hmhn committed May 3, 2023
1 parent 069b03f commit a7704cd
Show file tree
Hide file tree
Showing 15 changed files with 1,189 additions and 871 deletions.
6 changes: 2 additions & 4 deletions WebContent/static/floria.v2.0/minitours.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"use strict";

// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Date extensions
// Mini Tours
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

define(["floria/textutil", "floria/superdom", "jslibs/popper", "floria/collections"], function(FloriaText, SuperDOM, Popper, FloriaCollections)
{

var dojoSimple = require(CapsicoDojoSimpleLibJS)

var x = {};


Expand Down Expand Up @@ -57,7 +55,7 @@ function start(data)

x.startTour = function(tourName, jsonUrl)
{
dojoSimple.ajaxUrl(jsonUrl, "GET", null,
FloriaAjax.ajaxUrl(jsonUrl, "GET", null,
function(data) {
start(data);
},
Expand Down
6 changes: 3 additions & 3 deletions WebContent/static/floria.v2.0/module-ajax.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import { FloriaDOM } from "./module-dom.js";
import { DojoSimple } from "./module-dojosimple.js";
import { FloriaLogin } from "./module-login.js";

export var FloriaAjax = {

Expand Down Expand Up @@ -60,10 +60,10 @@ ajaxUrl: function(url, method, errorMsg, successFunc, errorFunc, postContents, t
console.error("ajaxUrl error: ", error);
try
{
if (error != null && error.status||error.code == 401 && DojoSimple.PopupLogin.isAuthPassthrough(url) == false)
if (error != null && error.status||error.code == 401 && FloriaLogin.PopupLogin.isAuthPassthrough(url) == false)
{
// return alert("NO ACL!");
return DojoSimple.PopupLogin.show(true, function() { FloriaAjax.ajaxUrl(url, method, errorMsg, successFunc, errorFunc, postContents, timeout, handleAs) });
return FloriaLogin.PopupLogin.show(true, function() { FloriaAjax.ajaxUrl(url, method, errorMsg, successFunc, errorFunc, postContents, timeout, handleAs) });
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions WebContent/static/floria.v2.0/module-charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ FloriaCharts.ChartBase.prototype.drawBar = function(horizontal)
chart.x1.domain(d3.range(chart.seriesbarData.length)).rangeRound([0, (chart.x.bandwidth()-5)]);
chart.rect = chart.svg.append("g").selectAll("g")
.data(chart.seriesbarData).enter().append("g")
.style("fill", function(d, i) { return chart.colorOvr(i); /*ChartTheme.colors[i];*/ })
.style("fill", function(d, i) { return /*d[i].color || */ chart.colorOvr(i); /*ChartTheme.colors[i];*/ })
.style("stroke-width", 0.5)
.attr("transform", function(d, i) {
return (horizontal) ? "translate(0, " + chart.y1(i) + ")"
Expand Down Expand Up @@ -1051,7 +1051,7 @@ FloriaCharts.ChartBase.prototype.addBarClickHandler = function(handlerFunc) {
if(overrideColor != "undefined" && overrideColor != null && overrideColor != []){
chart.overrideTheColor = true;
chart.overridecolor = overrideColor;
chart.colorOvr = d3.scaleOrdinal().range(chart.overridecolor);
chart.colorOvr = d3.scaleOrdinal().range(chart.overridecolor);
}else{
chart.colorOvr = d3.scaleOrdinal().range(ChartTheme.colors);
}
Expand Down
98 changes: 98 additions & 0 deletions WebContent/static/floria.v2.0/module-charts2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"use strict";

import { FloriaDOM } from "./module-dom.js";
import { ChartTheme } from "./module-charttheme.js";

import { Chart, Tooltip , registerables } from "/static/jslibs/chartjs/chart.js";


export var FloriaCharts2 = { ColorSchemes : ChartTheme.colorSchemes };


Chart.register(...registerables);
Tooltip.positioners.cursor = function(chartElements, coordinates) {
return { x: coordinates.x+(this.xAlign=="left"?12:-12), y: coordinates.y };
};


FloriaCharts2.chart = function(containerDivId, title, titleFontSize, titleFontWeight, titleFontColor)
{
this._containerDivId = containerDivId;
FloriaDOM.addCSS(this._containerDivId, "chart-container");
document.getElementById(containerDivId).innerHTML = '<CANVAS id="'+this._containerDivId+'_CNVS" style=""></CANVAS>';
this._options = {
responsive: true
,maintainAspectRatio: false
,plugins: { }
};
if (title != null)
this._options.plugins.title = { display: true, text:title, color:titleFontColor, font: { size: titleFontSize||28, weight: titleFontWeight } }
this._datasets = [ ];

this.setVerticalBarLine = function(vertical)
{
this._options.indexAxis = vertical == true ? 'y' : 'x';
this._options.interaction = { mode: 'index', axis: this._options.indexAxis };
return this;
};

this.setAxisLabels = function(xAxisLabel, yAxisLabel, fontSize, fontWeight, fontColor)
{
this._options.scales = {
x: { title:{ display: true, text:xAxisLabel, color:fontColor, font:{ size: fontSize||16, weight: fontWeight } } }
,y: { title:{ display: true, text:yAxisLabel, color:fontColor, font:{ size: fontSize||16, weight: fontWeight } } }
};
return this;
};

this.setLegend = function(display, fontSize)
{
this._options.plugins.legend = { display: display, labels: { font: { size: fontSize||18 } } };
return this;
};

this.setTooltips = function(titleFontSize, bodyFontSize, footerFontSize)
{
this._options.plugins.tooltip = { mode: 'index'
, position: 'cursor'
, boxPadding: 5
, titleFont : { size: titleFontSize ||20 }
, bodyFont : { size: bodyFontSize ||(titleFontSize-4)||18 }
, footerFont: { size: footerFontSize||(titleFontSize-8)||14, weight: 'normal' }
, callbacks: {
footer: function (context) {
let d = context[0].dataset.dataSrc[context[0].dataIndex];
return d.tooltip;
}
}
};
return this;
};

this.addDataset = function(data, label, colorScheme, borderColor)
{
this._datasets.push({ label: label
,axis: this._options.indexAxis
,dataSrc: data
,data: data.map(row => row.y)
,borderWidth: 2
,borderColor: borderColor||'rgb(192, 192, 192)'
,backgroundColor: colorScheme||ChartTheme.colorSchemes.ClassicCyclic13
});
return this;
};

this.draw = function(chartType)
{
this._chartType = chartType;

this._chart = new Chart(document.getElementById(this._containerDivId+'_CNVS'), {
type: this._chartType
,options: this._options
,data: {
labels: this._datasets[0].dataSrc.map(row => row.x)
,datasets: this._datasets
}
});
};
};
18 changes: 16 additions & 2 deletions WebContent/static/floria.v2.0/module-charttheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@
// var colors = ["#AEC7E8", "#C5B0D5", "#D62728", "#98DF8A", "#9467BD", "#2CA02C", "#FF7F0E", "#8C564B", "#C49C94", "#1F77B4"];
// var colors = ["#1395ba", "#a2b86c", "#0d3c55", "#c02e1d", "#f16c20", "#ebc844"];

var colors = ["#6facc8", "#95b594", "#f0bea6", "#b7bebd", "#e7bdd1", "#b8d9e5", "#b8d9e5", "#c7fffb", "#c9d9fd", "#c4e8c4"]
var colorSchemes = {
ClassicBlue7: ['#b4d4da', '#7bc8e2', '#67add4', '#3a87b7', '#1c73b1', '#1c5998', '#26456e']
,ColorBlind10: ['#1170aa', '#fc7d0b', '#a3acb9', '#57606c', '#5fa2ce', '#c85200', '#7b848f', '#a3cce9', '#ffbc79', '#c8d0d9']
,ClassicColorBlind10: ['#006ba4', '#ff800e', '#ababab', '#595959', '#5f9ed1', '#c85200', '#898989', '#a2c8ec', '#ffbc79', '#cfcfcf']
,ClassicGreenBlue11: ['#09622a', '#1e7735', '#2f8e41', '#69a761', '#a2c18f', '#cacaca', '#67add4', '#3a87b7', '#1c73b1', '#1c5998', '#26456e']
,ClassicCyclic13: ['#1f83b4', '#12a2a8', '#2ca030', '#78a641', '#bcbd22', '#ffbf50', '#ffaa0e', '#ff7f0e', '#d63a3a', '#c7519c', '#ba43b4', '#8a60b0', '#6f63bb']
,Capsico: ["#6facc8", "#95b594", "#f0bea6", "#b7bebd", "#e7bdd1", "#b8d9e5", "#b8d9e5", "#c7fffb", "#c9d9fd", "#c4e8c4"]
,Capsico2: ['rgba(255, 99, 132, 0.8)' , 'rgba(255, 159, 64, 0.8)' , 'rgba(255, 205, 86, 0.8)', 'rgba(75, 192, 192, 0.8)' , 'rgba(54, 162, 235, 0.8)'
,'rgba(153, 102, 255, 0.8)', 'rgba(201, 203, 207, 0.8)', 'rgba(255, 99, 172, 0.8)', 'rgba(255, 159, 104, 0.8)', 'rgba(255, 205, 126, 0.8)'
,'rgba(75, 192, 232, 0.8)', 'rgba(54, 182, 255, 0.8)', 'rgba(153, 142, 255, 0.8)', 'rgba(201, 203, 247, 0.8)'
]
};


// var defaultFill = {type: "linear", space: "shape", x1: 0, y1: 0, x2: 0, y2: 100};
// var t = new Theme({ chart: { fill: "transparent" }
// ,plotarea: { fill: "transparent" }
// ,seriesThemes: colors //gradientGenerator.generateMiniTheme(colors, defaultFill, 90, 50, 30)
// });

export var ChartTheme = {colors: colors};
export var ChartTheme = {colorSchemes: colorSchemes
,colors: colorSchemes.Capsico
};
26 changes: 26 additions & 0 deletions WebContent/static/floria.v2.0/module-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,32 @@ if (!Array.prototype.fill)
return this;
}

/** Works like substring, i.e., n -> m+1 non inclusive
*/
if (!Array.prototype.subarray)
Array.prototype.subarray = function(start, end)
{
if (end == null)
end = this.length;
return this.slice(start, end);
}

if (!Array.prototype.createTotalRow)
Array.prototype.createTotalRow = function(fields)
{
var totalRow = {};
for (let i = 0; i < this.length; ++i)
for (let j = 0; j < fields.length; ++j)
{
var f = fields[j];
if (totalRow[f] == null)
totalRow[f] = 0;
totalRow[f]+=this[i][f];
}
return totalRow;
}



/**
* A wrapper to a sorted String array. If an array is passed into the
Expand Down
18 changes: 9 additions & 9 deletions WebContent/static/floria.v2.0/module-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ import { FloriaText } from "./module-text.js";
Date.prototype.DATE_MONTHS = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
Date.prototype.DATE_DAYS = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');

Date.prototype.printDayWithTH = function()
Date.prototype.printDayWithTH = function(printTh)
{
var d = this.getDate();
return d + "<SUP style='font-size:60%;'>" + (d == 1 || d == 21 ? "st" : d == 2 || d == 22 ? "nd" : d == 3 || d == 23 ? "rd" : "th")
+ "</SUP>";
return d +( printTh==false?"":"<SUP style='font-size:60%;'>" + (d == 1 || d == 21 ? "st" : d == 2 || d == 22 ? "nd" : d == 3 || d == 23 ? "rd" : "th")
+ "</SUP>");
};

Date.prototype.print24hTime = function(Timezone)
Expand Down Expand Up @@ -241,19 +241,19 @@ import { FloriaText } from "./module-text.js";
+ (PrintTime == true ? " " + this.print24hTime(PrintTimezone) : "");
};

Date.prototype.printFriendly = function(PrintYear, PrintTime)
Date.prototype.printFriendly = function(PrintYear, PrintTime, th)
{
return this.__printFriendly(PrintYear, PrintTime, false);
return this.__printFriendly(PrintYear, PrintTime, false, th);
};

Date.prototype.printFriendlyInTZ = function(PrintYear, PrintTime)
Date.prototype.printFriendlyInTZ = function(PrintYear, PrintTime, th)
{
return this.adjustFromLocalTime().__printFriendly(PrintYear, PrintTime, true);
return this.adjustFromLocalTime().__printFriendly(PrintYear, PrintTime, true, th);
};

Date.prototype.__printFriendly = function(PrintYear, PrintTime, Timezone)
Date.prototype.__printFriendly = function(PrintYear, PrintTime, Timezone, th)
{
return this.DATE_DAYS[this.getDay()] + ", " + this.DATE_MONTHS[this.getMonth()] + " " + this.printDayWithTH()
return this.DATE_DAYS[this.getDay()] + ", " + this.DATE_MONTHS[this.getMonth()] + " " + this.printDayWithTH(th)
+ (PrintYear == true ? " " + this.getFullYear() : "") + (PrintTime == true ? ", at " + this.print24hTime(Timezone) : "");
};

Expand Down
Loading

0 comments on commit a7704cd

Please sign in to comment.