npm package: @icgcat/thematic-stats
Description: Thematic-stats is a library to generate thematic styles for geospatial data visualization
Author: Institut Cartogràfic i Geològic de Catalunya
Latest version: 0.0.8-c

<div style="text-align:center">
<p>
  <img src="https://eines.icgc.cat/recursos/logos/icgc_logo_color.png"  alt="ICGC Logo" width="250px">
</p>
</div>

<div style="text-align:center">

  [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg?style=flat)](LICENSE.txt) 
  [![Version](https://img.shields.io/npm/v/@icgcat/thematic-stats?style=flat)](https://www.npmjs.com/package/@icgcat/thematic-stats) 
  [![LinkedIn](https://img.shields.io/badge/LinkedIn-icgcat-blue?style=flat)](https://www.linkedin.com/company/icgcat)
  <img src="https://eines.icgc.cat/recursos//images/JS-logo.svg" width="20px"/>
</div>


# @icgcat/thematic-stats

## Introduction
`@icgcat/thematic-stats` is a Node.js package designed for statistical analysis, geospatial data processing, and thematic mapping. It provides utility functions for generating map styles, defining numeric data classifications, and visualizing data for mapping tools. This package is useful for developers, analysts, and GIS professionals handling geospatial datasets and creating thematic visualizations.

---

## Installation

To install the package, use npm or yarn:

```bash
npm install @icgcat/thematic-stats
```

---

## Usage

### Import and Basic Example
Here's how to use the stats functions in your application:

```svelte
<script>

import { generateStyleJSTAT, generateStyle } from '@icgcat/thematic-stats';

// Example 1: Generate a style for thematic mapping
const styleJSTAT = generateStyleJSTAT('population', [10, 20, 30], ['A', 'B', 'C'], false);
console.log(styleJSTAT);

// Example 2: Generate a step-based style
const style = generateStyle('density', [0, 100, 200, 300], ['#FFEDA0', '#FEB24C', '#F03B20']);
console.log(style);


let activeLayer = 'polygonLayerID'
map.setPaintProperty(activeLayer + "-pol", "fill-color", style); 

// or you can import stats from @icgc/stats and: 
// stats.setStyle(capaActiva, currentStyle)


</script>
```

## Component Functions

### generateStyleJSTAT(fieldName, arrayData, arrayKeys, geostatObj, forceInt) ⇒ <code>Array</code>
Generates a style configuration for thematic mapping based on GeoStats data.

**Kind**: global function  
**Returns**: <code>Array</code> - A style configuration array for mapping tools.  

| Param | Type | Description |
| --- | --- | --- |
| fieldName | <code>String</code> | The field name used for matching values. |
| arrayData | <code>Array</code> | An array of data values. |
| arrayKeys | <code>Array</code> | An array of keys corresponding to the data values. |
| geostatObj | <code>Object</code> | The GeoStats object containing data and color mapping. |
| forceInt | <code>Boolean</code> | Whether to parse keys as integers. |

**Example**  
```js
const style = generateStyleJSTAT('field', [10, 20], [1, 2], geoStatsObj, true);
console.log(style);
```
---

### generateStyle(fieldName, arrayValues, arrayColors) ⇒ <code>Array</code>
Generates a step-based style configuration for mapping numeric ranges.

**Kind**: global function  
**Returns**: <code>Array</code> - A style configuration array for mapping tools.  

| Param | Type | Description |
| --- | --- | --- |
| fieldName | <code>String</code> | The field name used for styling. |
| arrayValues | <code>Array</code> | An array of numeric values defining range boundaries. |
| arrayColors | <code>Array</code> | An array of colors corresponding to each range. |

**Example**  
```js
const style = generateStyle('field', [10, 20, 30], ['#FF0000', '#00FF00']);
console.log(style);
```



---

<!-- ## Dependencies 
`@icgc/stats` integrates the following libraries: 
- <a href="https://www.npmjs.com/package/geostats" target="_blank"> geostats </a>
- <a href="https://www.npmjs.com/package/simple-statistics" target="_blank"> simple-statistics </a>
- <a href="https://www.npmjs.com/package/percentile" target="_blank"> percentile </a>
- <a href="https://www.npmjs.com/package/chroma-js" target="_blank"> chroma-js </a>
-->



## Developed by:

 <a href="https://www.icgc.cat/" target="_blank"><img src="https://eines.icgc.cat/recursos/logos/ICGC_color_norma.svg"  alt="ICGC Logo" width="150"></img></a>      

  <a href="https://web.gencat.cat/" target="_blank"><img src="https://eines.icgc.cat/recursos/logos/gencat_logo_color.png"  alt="Gencat Logo" width="190"></img></a>


## License
This project is licensed under the MIT License.