Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-gauge-component

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-gauge-component - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

1

dist/GaugeComponent/hooks/arc.d.ts

@@ -20,1 +20,2 @@ import { Gauge } from '../types/Gauge';

export declare const clearOuterArcs: (gauge: Gauge) => void;
export declare const validateArcs: (gauge: Gauge) => void;

@@ -29,3 +29,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.clearOuterArcs = exports.clearArcs = exports.redrawArcs = exports.getCoordByValue = exports.createGradientElement = exports.getColors = exports.applyGradientColors = exports.getArcDataByValue = exports.getArcColorByValue = exports.getArcColorByPercentage = exports.applyColors = exports.setupArcs = exports.drawArc = exports.setArcData = void 0;
exports.validateArcs = exports.clearOuterArcs = exports.clearArcs = exports.redrawArcs = exports.getCoordByValue = exports.createGradientElement = exports.getColors = exports.applyGradientColors = exports.getArcDataByValue = exports.getArcColorByValue = exports.getArcColorByPercentage = exports.applyColors = exports.setupArcs = exports.drawArc = exports.setArcData = void 0;
var utils = __importStar(require("./utils"));

@@ -378,1 +378,45 @@ var d3_1 = require("d3");

exports.clearOuterArcs = clearOuterArcs;
var validateArcs = function (gauge) {
verifySubArcsLimits(gauge);
};
exports.validateArcs = validateArcs;
/**
* Reorders the subArcs within the gauge's arc property based on the limit property.
* SubArcs with undefined limits are sorted last.
*/
var reOrderSubArcs = function (gauge) {
gauge.props.arc.subArcs.sort(function (a, b) {
if (typeof a.limit === 'undefined' && typeof b.limit === 'undefined') {
return 0;
}
if (typeof a.limit === 'undefined') {
return 1;
}
if (typeof b.limit === 'undefined') {
return -1;
}
return a.limit - b.limit;
});
console.log(gauge.props.arc.subArcs);
};
var verifySubArcsLimits = function (gauge) {
var _a;
reOrderSubArcs(gauge);
var prevLimit = undefined;
for (var _i = 0, _b = gauge.props.arc.subArcs; _i < _b.length; _i++) {
var subArc = _b[_i];
var limit = subArc.limit;
if (typeof limit !== 'undefined') {
// Check if the limit is within the valid range
if (limit < gauge.props.minValue || limit > gauge.props.maxValue)
throw new Error("The limit of a subArc must be between the minValue and maxValue. The limit of the subArc is ".concat(limit));
prevLimit = limit;
}
}
// If the user has defined subArcs, make sure the last subArc has a limit equal to the maxValue
if (((_a = gauge.props.arc.subArcs) === null || _a === void 0 ? void 0 : _a.length) > 0) {
var lastSubArc = gauge.props.arc.subArcs[gauge.props.arc.subArcs.length - 1];
if (lastSubArc.limit < gauge.props.maxValue)
lastSubArc.limit = gauge.props.maxValue;
}
};

31

dist/GaugeComponent/index.js

@@ -41,2 +41,3 @@ "use strict";

var chartHooks = __importStar(require("./hooks/chart"));
var arcHooks = __importStar(require("./hooks/arc"));
var utils_1 = require("./hooks/utils");

@@ -93,32 +94,4 @@ var Dimensions_1 = require("./types/Dimensions");

mergedProps.current.marginInPercent = (0, GaugeComponentProps_1.getGaugeMarginByType)(gauge.props.type);
validateArcs(gauge);
arcHooks.validateArcs(gauge);
};
var validateArcs = function (gauge) {
var _a;
//If the user has defined subArcs, make sure the last subArc has a limit equal to the maxValue
if (((_a = gauge.props.arc.subArcs) === null || _a === void 0 ? void 0 : _a.length) > 0) {
var lastSubArc = gauge.props.arc.subArcs[gauge.props.arc.subArcs.length - 1];
if (lastSubArc.limit < gauge.props.maxValue)
lastSubArc.limit = gauge.props.maxValue;
}
verifySubArcsLimits(gauge);
};
var verifySubArcsLimits = function (gauge) {
var prevLimit = undefined;
for (var _i = 0, _a = gauge.props.arc.subArcs; _i < _a.length; _i++) {
var subArc = _a[_i];
var limit = subArc.limit;
if (typeof limit !== 'undefined') {
// Check if the limit is within the valid range
if (limit < gauge.props.minValue || limit > gauge.props.maxValue)
throw new Error("The limit of a subArc must be between the minValue and maxValue. The limit of the subArc is ".concat(limit));
// Check if the limit is greater than the previous limit
if (typeof prevLimit !== 'undefined') {
if (limit <= prevLimit)
throw new Error("The limit of a subArc must be greater than the limit of the previous subArc. The limit of the subArc is ".concat(limit));
}
prevLimit = limit;
}
}
};
var shouldInitChart = function () {

@@ -125,0 +98,0 @@ var arcsPropsChanged = (JSON.stringify(prevProps.current.arc) !== JSON.stringify(mergedProps.current.arc));

{
"name": "react-gauge-component",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "module": "dist/index.js",

@@ -39,3 +39,3 @@ # react-gauge-component

### Simple Gauge.
![Image of Simple Gauge Component for a simple data visualization](https://antoniolago.github.io/react-gauge-component/images/simpleGauge.jpg "Simple Gauge Component")
![Image of Simple Grafana Gauge Component for a simple data visualization](https://antoniolago.github.io/react-gauge-component/images/simpleGauge.jpg "Simple Grafana Gauge Component")
<details>

@@ -222,3 +222,3 @@ <summary>Show Simple Gauge code</summary>

### Gauge with blob gauge.
### Gauge with blob.
![Image of Blob Gauge Component for a simple data visualization](https://antoniolago.github.io/react-gauge-component/images/blobGauge.jpg "Blob Gauge Component")

@@ -369,3 +369,3 @@ <details>

<ul>
<li><code>limit: number</code>: The subArc limit value. When no limits are defined in the next subArcs in the list, it's optional and will auto-calculate remaining arcs limits. Example: <code>[{limit: 70}, {}, {}, {}]</code>. In a default <code>minValue/maxValue</code>, the values will be equal to <code>[{limit: 70}, {limit: 80}, {limit: 90}, {limit: 100}]</code>. But <code>[{},{limit: 100}]</code> will not work properly as the not defined subArc limit has a subArc with limit defined ahead in the array.</li>
<li><code>limit: number</code>: The subArc limit value. When no limits are defined will auto-calculate remaining arcs limits. Attention: limits are reordered in ascending order.</li>
<li><code>color: string</code>: The subArc color. When not provided, it will use default subArc's colors and interpolate first and last colors when subArcs number is greater than <code>colorArray</code>.</li>

@@ -372,0 +372,0 @@ <li><code>showMark: boolean</code>: Whether or not to show the mark. Default: <code>false</code>.</li>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc