Skip to content

Commit 6f926bb

Browse files
Fix for the rendering of smooth gradients. Some example pre-rendered heat maps.
1 parent e6f3f9e commit 6f926bb

18 files changed

+11
-7
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ HeatMap.builder()
3131
```
3232
The output will be a PNG file at the output path of `myOutPutFile`.
3333

34-
The builder pattern makes it easy to customize your heat map. For example, the following will render a heatmap with no titles, no labels, no legend no border, just the core heat map with blending enabled:
34+
The builder pattern makes it easy to customize your heat map. For example, the following will render a heat map with no titles, no labels, no legend no border, just the core heat map with blending enabled:
3535

3636
```java
3737
HeatMap.builder()
@@ -63,7 +63,7 @@ public interface DataRecord {
6363
}
6464
```
6565

66-
Two options are provided for defining the chart axes: `IntegerAxis` which is useful integer values (such as 1-31 for days of the month) and `StringAxis` which is useful for string values (such as Monday-Sunday for days of the week). In both cases, the axis entries are always treated as discrete values and rendered in the same order that each entry is added to the axis. For the `IntegerAxis`, a convenience method is provided to automatically populate the values between a given minimum and maxmimum. For example:
66+
Two options are provided for defining the chart axes: `IntegerAxis` which is useful integer values (such as 1-31 for days of the month) and `StringAxis` which is useful for string values (such as Monday-Sunday for days of the week). In both cases, the axis entries are always treated as discrete values and rendered in the same order that each entry is added to the axis. For the `IntegerAxis`, a convenience method is provided to automatically populate the values between a given minimum and maximum. For example:
6767

6868
```java
6969
IntegerAxis xAxis = new IntegerAxis("Days of the Year", 1, 366);
@@ -96,7 +96,7 @@ The heat maps are highly customizable, down to colours, fonts, gradients, titles
9696
**Heat Map Rendering**
9797
- Custom colour gradients using either pre-defined steps with linear interpolation, or smooth a smooth gradient based on the HSB model colour wheel
9898
- 9 pre-defined gradients to choose from if you don't want to define your own
99-
- Option to blend the colours of each cell using a custome scale factor for applying the linear colour interpolation
99+
- Option to blend the colours of each cell using a custom scale factor for applying the linear colour interpolation
100100
- Custom background colour
101101
- Option to render of grid lines, including thickness and colour
102102
- Cell width and height
@@ -129,7 +129,8 @@ The default colour palette, if not specified, is set to number 3. Here are examp
129129

130130
## Colour Blending
131131

132-
Enabling the `blendColours` option will result in a linear colour interpolation being applied to the cells of the heat map in order to "smooth" out the values. This effect works by first rendering each cell as a single pixel, then applying a bilinear upscaler (with a variable scaling factor), followed by applying an alpha mask to avoid blending with empty cells, and finally applying a nearest-neighbour up or down scaling to the final output resolution. The strength of this effect can be controlled via the `blendColoursScale` option, which supports values between 2 and 20, inclusive. Here is an example of what colour blending looks like, starting with no effect, then a strength of 2, 3, 5,and 10, respectively.
132+
Enabling the `blendColours` option will result in a linear colour interpolation being applied to the cells of the heat map in order to "smooth out" the values. This effect works by first rendering each cell as a single pixel, then applying a bilinear upscaler (with a variable scaling factor), followed by applying an alpha mask to avoid blending with empty cells, and finally applying a nearest-neighbour up or down scaling to the final output resolution. The strength of this effect can be controlled via the `blendColoursScale` option, which supports values between 2 and 20, inclusive. Here is an example of what colour blending looks like, starting with no effect, then a strength of 2, 3, 5,and 10, respectively.
133+
133134
<p align="center">
134135
<img src="https://github.com/user-attachments/assets/f64e9520-7f8b-4473-be04-34be30771b69" width="200" />
135136
<img src="https://github.com/user-attachments/assets/1b3cdab1-97a9-4e4a-9f47-670644505911" width="200" />

examples/Blend Scale 10.png

22 KB
Loading

examples/Blend Scale 2.png

16.5 KB
Loading

examples/Blend Scale 3.png

23 KB
Loading

examples/Blend Scale 5.png

13.8 KB
Loading

examples/Gradient_1.png

25 KB
Loading

examples/Gradient_2.png

27.8 KB
Loading

examples/Gradient_3.png

25.9 KB
Loading

examples/Gradient_4.png

22.9 KB
Loading

examples/Gradient_5.png

25 KB
Loading

examples/Gradient_6.png

22.8 KB
Loading

examples/Gradient_7.png

27.2 KB
Loading

examples/Gradient_8.png

28.5 KB
Loading

examples/Gradient_9.png

22.6 KB
Loading

examples/No Blending.png

9.24 KB
Loading

src/main/java/com/dbf/heatmaps/HeatMapGradient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ public HeatMapGradient(int hueStart, int hueEnd, float saturation, float brightn
218218
this.saturation = saturation;
219219
this.brightness = brightness;
220220
this.clockwise = clockwise;
221-
this.hueStart = hueStart/360;
222-
this.hueRange = Math.abs(this.hueStart - (hueEnd/360));
221+
this.hueStart = hueStart/360f;
222+
this.hueRange = Math.abs(this.hueStart - (hueEnd/360f));
223223
}
224224

225225
/**

src/main/java/com/dbf/heatmaps/axis/StringAxis.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public StringAxis(String title, String... strings) {
2525
}
2626
}
2727

28+
public void addEntry(String entry) {
29+
super.addEntry(entry, entry);
30+
}
31+
2832
@Override
2933
public String getLabel(String entry) {
3034
return entry;

src/main/java/com/dbf/heatmaps/data/DataRecord.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.dbf.heatmaps.data;
22

33
public interface DataRecord {
4-
54
public Double getValue();
65
public Object getX();
76
public Object getY();

0 commit comments

Comments
 (0)