0.0.15 • Published 10 months ago

vue-histogram-dual-range v0.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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

PropertyTypeDefaultDescription
minnumber0Set slider minimum value
maxnumber100Set slider maximum value
histogramDataarray[]Data to display in a histogram
histogramColumnAveragesnumber[] or {avg: number ... }[]nullYou 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
histogramColumnCountnumber17Number of bars in a histogram
histogramHeightnumber83Histogram height
histogramColumnColorstring#a3bbffHistogram column colors
histogramColumnOffsetnumber5Distance between histogram columns
histogramNoZeroColumnMinHeightPercentnumber0Since 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
sliderColorstring#3264feSlider dot color
sliderBorderColorstring#577cecDeprecated since version 0.0.14 Stroke color of slider points
sliderHoverColorstring#577cecDeprecated since version 0.0.14 Slider hover dot color
sliderSizenumber20Slider dot size in pixels
rangeColorstring#dadae5Slider line color that is not included in the active range
rangeActiveColorstring#3264feThe color of the slider line that is INCLUDED in the active range
rangeHeightstring5pxSince version 0.0.14 Slider line height

🔧 Event

NameDescription
update:modelValueCalled when the value of the sliders changes

📦 Slots

NamePropsDescription
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
        }
    }
}
0.0.15

10 months ago

0.0.14

10 months ago

0.0.13

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago