npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gapit/sld-component

v0.0.6

Published

A component for controlling a sld component.

Downloads

2

Readme

SLD-component

This component handles SVG drawings of SLD components.

This component is created based around the sldHandler function and works best if all elements are included. Running the sldHandler with all elements included will run the other functions as well, the other functions can be used for more specific purposes.

Usage

sldHandler

This is the main function and depending on the variables sent the others will be as well. Having a valueElt will trigger the valueHandler function, having a breakerElt will trigger the breakerHandler and having a trippedElt wil trigger the trippedHandler.

import { sldHandler } from "@gapit/sld-component";

function getElements() {
  //loop json for multiple components.
  for (const sldItem of Object.values(customProperties.component)) {
    const showcase = true; // true = random data, false = true data.
    const { id, metric, metricVar, baseUnit, invertBreaker } = sldItem; // get from json.
    const GroupElt = htmlNode.getElementById("component-" + id); // get component group
    const [
      trippedElt, // Displays when breaker is tripped.
      signalElt, // Displays when communication disruption.
      breakerStateElt, // Excess element to determine open / closed state.
      textElt, // Breaker name.
      descriptionElt, // Breaker description.
      valueElt, // Value Element.
      breakerElt, // Group of lines. Last = closed, 2nd last = open.
    ] = GroupElt.children as HTMLCollectionOf<HTMLElement & SVGElement>;
    const decimals = 1; // Decimals on value element.
    //create custom colors for different states.
    const customColors = {
      active: "#aa453f",
      inactive: "#49b755",
      noCommunication: "#6d6f73",
      tripped: "#001a2b",
    };
    //perform function call.
    sldHandler({
      metric,
      metricVar,
      showcase,
      baseUnit,
      decimal,
      breakerElt,
      breakerStateElt,
      customColors,
      trippedElt,
      signalElt,
      textElt,
      valueElt,
      descriptionElt,
      invertBreaker,
    });
  }
}

Create custom json (non essential)

Declare global json

import customPropertiesJSON from "../../src/json.json";

declare global {
  const customProperties: typeof customPropertiesJSON;
}

Json structure

{
  "component": {
    "xq014": {
      "id": "xq014",
      "metric": "xq014",
      "metricVar": {
        "breakerMetric": "-breaker",
        "valueMetric": "-data",
        "trippedMetric": "-status"
      },
      "invertBreaker": false,
      "baseUnit": "kW"
    },
    ...
  }
}

getBreakerElements

This function finds the last 2 objects of the breaker group and returns them as activeElt and inactiveElt, where activeElt is the last element and inactiveElt is the second last.

getBreakerElements(breakerElt);

valueHandler

Gives value to the value element.

valueHandler({
  valueMetric,
  showcase,
  valueElt,
  communicationCounter,
  decimal,
  baseUnit,
});

breakerHandler

Flips the breaker switch and colors elements.

breakerHandler({
  breakerMetric,
  showcase,
  breakerElt,
  communicationCounter,
  activeColor,
  inactiveColor,
  breakerStateElt,
  invertBreaker,
  textElt,
  valueElt,
  descriptionElt,
});

trippedHandler

Activates tripped element, opens breaker and colors elements.

trippedHandler({
  trippedMetric,
  showcase,
  trippedElt,
  communicationCounter,
  trippedColor,
  breakerStateElt,
  breakerElt,
  textElt,
  valueElt,
  descriptionElt,
});

communicationHandler

If either of the other functions (valueHandler, breakerHandler & trippedHandler) retruns a value of 1 this function should be triggered. This function activates the signal element, both breaker states and colors the elements.

communicationHandler({
  signalElt,
  noCommunicationColor,
  breakerStateElt,
  trippedElt,
  breakerElt,
  textElt,
  valueElt,
  descriptionElt,
});