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

vue-histogram-dual-range

v0.0.15

Published

Vue3 histogram dual range package

Downloads

87

Readme

Vue Histogram Dual Range

Histogram dual range for Vue3

📦 Installation

yarn

yarn add vue-histogram-dual-range

npm

npm i vue-histogram-dual-range

🔧 Simple usage

import VueHistogramDualRange from "vue-histogram-dual-range";
import "vue-histogram-dual-range/style.css"

const value = ref([20, 70])

const histogramData: HistogramData = [
    { value: 1, count: 10 },
    { value: 2, count: 6 },
    { value: 3, count: 8 },
    //...
];
<VueHistogramDualRange
    v-model="value"
    :min="1"
    :max="100"
    :histogram-data="histogramData"
>
  <template #columnTooltip="slotProps">
    <div>{{ slotProps.column.data.range.from }} - {{ slotProps.column.data.range.to }}</div>
    <div>Total: {{ slotProps.column.data.sum }}</div>
  </template>
</VueHistogramDualRange>

📋 Props

| Property | Type | Default | Description | |---------------------------------------|:--------------------------------:|:-------:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | min | number | 0 | Set slider minimum value | | max | number | 100 | Set slider maximum value | | histogramData | array | [] | Data to display in a histogram | | histogramColumnAverages | number[] or {avg: number ... }[] | null | You can choose not to pass the histogramData property, passing instead an array of numbers histogramColumnAverages, which will determine the value for each column in order from first to last (useful for optimization if the range is a large range of numbers), or you can pass an array of objects with a numeric property avg (the behavior is identical to passing an array of numbers), in this case you can set your own properties to the object and get them in the columnsTooltip slot prop via slotProps.column.data | | histogramColumnCount | number | 17 | Number of bars in a histogram | | histogramHeight | number | 83 | Histogram height | | histogramColumnColor | string | #a3bbff | Histogram column colors | | histogramColumnOffset | number | 5 | Distance between histogram columns | | histogramNoZeroColumnMinHeightPercent | number | 0 | [Since version 0.0.10] If the column height is greater than 0 and the value of this prop is set and if the column height is less than the value of this prop then the column height will be equal to this prop in percentage | | sliderColor | string | #3264fe | Slider dot color | | ~~sliderBorderColor~~ | string | #577cec | [Deprecated since version 0.0.14] Stroke color of slider points | | ~~sliderHoverColor~~ | string | #577cec | [Deprecated since version 0.0.14] Slider hover dot color | | sliderSize | number | 20 | Slider dot size in pixels | | rangeColor | string | #dadae5 | Slider line color that is not included in the active range | | rangeActiveColor | string | #3264fe | The color of the slider line that is INCLUDED in the active range | | rangeHeight | string | 5px | [Since version 0.0.14] Slider line height |

🔧 Event

| Name | Description | |-------------------|----------------------------------------------| | update:modelValue | Called when the value of the sliders changes |

📦 Slots

| Name | Props | Description | |---------------|------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------| | columnTooltip | { column: { x: number; sum: number; data: number or { avg: number; ... } } } | The slot that will be inserted into the tooltip; slotProps has a column property with data about the displayed column |

Histogram data for large numbers

If you manipulate large numbers in ranges, for example, in a range from 1 to 20314 - the quantity value is 64, then you can pass the values exactly divided by quantity to the histogramData prop, and also pass the number of objects that are in HistogramData to histogramColumnCount

Example

const histogramData: HistogramData = [
    { value: 1, count: 64 },
    { value: 20315, count: 2 },
    { value: 40630, count: 3 },
    { value: 60944, count: 0 },
    { value: 81258, count: 4 },
    { value: 101573, count: 2 },
    { value: 121887, count: 2 },
    { value: 142201, count: 3 },
    { value: 162516, count: 0 },
];
<VueHistogramDualRange
    :min="1"
    :max="162516"
    :histogram-column-count="9"
    :histogram-data="histogramData"
/>

Optimized example with a large range

If you are dealing with large numbers and see that there are performance problems, then this is a consequence of the fact that when passing the histogramData prop (without passing histogramColumnAverages), the package tries to split the histogramData into pieces (equal to the number of histogramColumnCount) and from these pieces calculate the average value, if you you already know them, you can use the histogramColumnAverages prop and solve the performance problem

The histogramColumnAverages prop accepts an array of numbers, the number of numbers must be equal to the number of columns (from the histogramColumnCount prop), each number is the arimetic average for one column

  • In this case, if you passed the histogramColumnAverages prop, then you do not need to pass the histogramData prop

Example

const sliderValue = ref([1, 9999999999])
const histogramDataAverages = [
    30,
    20,
    50,
    40,
    10,
    0,
    90,
    70,
    30
];
<VueHistogramDualRange
    v-model="sliderValue"
    :min="1"
    :max="9999999999"
    :histogram-column-count="9"
    :histogram-column-averages="histogramDataAverages"
/>

Optimized example with a large range and tooltip

In the histogramColumnAverages prop you can also pass your own object with one required property - avg, this object will be passed to the columnTooltip slot, and you can access them in this way slotProps.column

const histogramDataAveragesObject = [
  {
    avg: 40,
    sum: 100,
    range: {
      from: 0,
      to: 1000000
    }
  },
  {
    avg: 10,
    sum: 200,
    range: {
      from: 1000000,
      to: 2000000
    }
  },
  {
    avg: 100,
    sum: 500,
    range: {
      from: 2000000,
      to: 3000000
    }
  },
    // ...
];
<VueHistogramDualRange
    v-model="sliderValue"
    :min="1"
    :max="9999999999"
    :histogram-column-count="9"
    :histogram-column-averages="histogramDataAverages"
>
    <template #columnTooltip="slotProps">
        <div>{{ slotProps.column.data.range.from }} - {{ slotProps.column.data.range.to }}</div>
        <div>Total: {{ slotProps.column.data.sum }}</div>
    </template>
</VueHistogramDualRange>

Example slotProps.column for the first column from the example above

{
    "heightPercentage": 40,
    "x": 0,
    "data": {
        "avg": 40,
        "sum": 100,
        "range": {
            "from": 0,
            "to": 1000000
        }
    }
}