added tons of files for component functionality; manual component adding added temporarily
This commit is contained in:
parent
58830d480e
commit
45ff49bcea
121 changed files with 25883 additions and 65 deletions
88
src/utils/download.ts
Normal file
88
src/utils/download.ts
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// import * as save from "save-svg-as-png";
|
||||
// import * as jsonexport from "jsonexport";
|
||||
import { or } from "./types";
|
||||
// const jsonexport = require("jsonexport");
|
||||
// const save = require("save-svg-as-png")
|
||||
|
||||
export function saveSVG(element: string, filename: string, options: Object) {
|
||||
// save.saveSvgAsPng(document.getElementById(element), filename, options);
|
||||
}
|
||||
|
||||
export function downloadFile(response: any, filename: any) {
|
||||
if (!response || !response.data) {
|
||||
return;
|
||||
}
|
||||
var blob = new Blob([response.data], { type: "application/octet-stream" });
|
||||
var link = document.createElement("a");
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
export function downloadJSON(data: any, filename: string) {
|
||||
var link = document.createElement("a");
|
||||
link.href = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(data));
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
export function downloadURL(url: any) {
|
||||
var link = document.createElement("a");
|
||||
link.href = url;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
export function exportDataToCSV(filename: string, data: Array<any>) {
|
||||
if (!data || !data.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// jsonexport(data, function(err: any, csv: any) {
|
||||
// if (err) return console.log(err);
|
||||
// var blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
||||
// var link = document.createElement("a");
|
||||
// link.href = window.URL.createObjectURL(blob);
|
||||
// link.download = or(filename, "generated") + ".csv";
|
||||
// document.body.appendChild(link);
|
||||
// link.click();
|
||||
// setTimeout(function() {
|
||||
// document.body.removeChild(link);
|
||||
// window.URL.revokeObjectURL(link.href);
|
||||
// }, 100);
|
||||
// });
|
||||
}
|
||||
|
||||
export function exportJSON(filename: string, data: Array<any>) {
|
||||
if (!data || !data.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// jsonexport(data, function(err: any, csv: any) {
|
||||
// if (err) return console.log(err);
|
||||
// var blob = new Blob([jsonexport], { type: "application/json;charset=utf-8;" });
|
||||
// var link = document.createElement("a");
|
||||
// link.href = window.URL.createObjectURL(blob);
|
||||
// link.download = or(filename, "generated") + ".json";
|
||||
// document.body.appendChild(link);
|
||||
// link.click();
|
||||
// setTimeout(function() {
|
||||
// document.body.removeChild(link);
|
||||
// window.URL.revokeObjectURL(link.href);
|
||||
// }, 100);
|
||||
// });
|
||||
}
|
||||
6
src/utils/index.ts
Normal file
6
src/utils/index.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export * from "./download";
|
||||
export * from "./environment";
|
||||
export * from "./numbers";
|
||||
export * from "./strings";
|
||||
export * from "./types";
|
||||
export * from "./units";
|
||||
18
src/utils/numbers.ts
Normal file
18
src/utils/numbers.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
export function isPercent(value: number): boolean {
|
||||
return value >= 0 && value <= 100;
|
||||
}
|
||||
|
||||
export function avg(values: number[]): number {
|
||||
return values.reduce((a, b) => a + b, 0) / values.length;
|
||||
}
|
||||
|
||||
export function roundTo(value: number, places: number): number {
|
||||
return parseFloat(value.toFixed(places));
|
||||
}
|
||||
|
||||
export function abbreviateNum(value: number): string {
|
||||
if (isNaN(value)) return value.toString();
|
||||
if (value >= 1000000 || value <= -1000000) return Math.round(value / 1000000) + "m";
|
||||
if (value >= 1000 || value <= -1000) return Math.round(value / 1000) + "k";
|
||||
return value.toString();
|
||||
}
|
||||
66
src/utils/random.ts
Normal file
66
src/utils/random.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import {
|
||||
amber,
|
||||
blue,
|
||||
cyan,
|
||||
deepOrange,
|
||||
deepPurple,
|
||||
green,
|
||||
indigo,
|
||||
lightBlue,
|
||||
lightGreen,
|
||||
lime,
|
||||
orange,
|
||||
pink,
|
||||
purple,
|
||||
red,
|
||||
teal,
|
||||
yellow
|
||||
} from "@mui/material/colors";
|
||||
|
||||
export function randomInt(min: number, max: number) {
|
||||
return Math.floor(Math.random() * (max - min)) + min;
|
||||
}
|
||||
|
||||
export function randomFloat(min: number, max: number) {
|
||||
return Math.random() * (max - min) + min;
|
||||
}
|
||||
|
||||
export function randomMaterialColour() {
|
||||
const colours = [
|
||||
red,
|
||||
pink,
|
||||
purple,
|
||||
deepPurple,
|
||||
indigo,
|
||||
blue,
|
||||
lightBlue,
|
||||
cyan,
|
||||
teal,
|
||||
green,
|
||||
lightGreen,
|
||||
lime,
|
||||
yellow,
|
||||
amber,
|
||||
orange,
|
||||
deepOrange
|
||||
];
|
||||
const shades = [
|
||||
"50",
|
||||
"100",
|
||||
"200",
|
||||
"300",
|
||||
"400",
|
||||
"500",
|
||||
"600",
|
||||
"700",
|
||||
"800",
|
||||
"900",
|
||||
"A100",
|
||||
"A200",
|
||||
"A400",
|
||||
"A700"
|
||||
];
|
||||
const randomColour: any = colours[Math.floor(Math.random() * colours.length)];
|
||||
const randomShade: any = shades[Math.floor(Math.random() * colours.length)];
|
||||
return randomColour[randomShade];
|
||||
}
|
||||
74
src/utils/units.ts
Normal file
74
src/utils/units.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import { pond } from "protobuf-ts/pond";
|
||||
|
||||
export function getTemperatureUnit(): pond.TemperatureUnit {
|
||||
return localStorage.getItem("temperature") === "f"
|
||||
? pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
: pond.TemperatureUnit.TEMPERATURE_UNIT_CELSIUS;
|
||||
}
|
||||
|
||||
export function setTemperatureUnit(unit: pond.TemperatureUnit) {
|
||||
localStorage.setItem(
|
||||
"temperature",
|
||||
unit === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? "f" : "c"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* takes in the celsius value for temperature and returns the fahrenheit value
|
||||
* @param celsius celsius value
|
||||
* @returns temperature in fahrenheit
|
||||
*/
|
||||
export const celsiusToFahrenheit = (celsius: number) => {
|
||||
return celsius * (9 / 5) + 32;
|
||||
};
|
||||
|
||||
/**
|
||||
* takes in the fahrenheit value for temperature and returns the celsius value
|
||||
* @param fahrenheit starting value
|
||||
* @returns temperature in celsius
|
||||
*/
|
||||
export const fahrenheitToCelsius = (fahrenheit: number) => {
|
||||
return (fahrenheit - 32) * (5 / 9);
|
||||
};
|
||||
|
||||
export function getPressureUnit(): pond.PressureUnit {
|
||||
return localStorage.getItem("pressure") === "kpa"
|
||||
? pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS
|
||||
: pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER;
|
||||
}
|
||||
|
||||
export function setPressureUnit(unit: pond.PressureUnit) {
|
||||
localStorage.setItem(
|
||||
"pressure",
|
||||
unit === pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS ? "kpa" : "iwg"
|
||||
);
|
||||
}
|
||||
|
||||
export function getDistanceUnit(): pond.DistanceUnit {
|
||||
return localStorage.getItem("distance") === "m"
|
||||
? pond.DistanceUnit.DISTANCE_UNIT_METERS
|
||||
: pond.DistanceUnit.DISTANCE_UNIT_FEET;
|
||||
}
|
||||
|
||||
export function setDistanceUnit(unit: pond.DistanceUnit) {
|
||||
localStorage.setItem("distance", unit === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft");
|
||||
}
|
||||
|
||||
export function getGrainUnit(): pond.GrainUnit {
|
||||
return localStorage.getItem("grainUnit") === "mT"
|
||||
? pond.GrainUnit.GRAIN_UNIT_WEIGHT
|
||||
: pond.GrainUnit.GRAIN_UNIT_BUSHELS;
|
||||
}
|
||||
|
||||
export function setGrainUnit(unit: pond.GrainUnit) {
|
||||
localStorage.setItem("grainUnit", unit === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu");
|
||||
}
|
||||
|
||||
export const distanceConversion = (val: number) => {
|
||||
let converted = val;
|
||||
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
converted = val / 3.281;
|
||||
}
|
||||
return converted;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue