-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add functionality for load and save button in color widget
- Loading branch information
1 parent
e0a1722
commit f83bf8d
Showing
3 changed files
with
167 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from PyQt5.QtGui import QColor | ||
|
||
from qgis.core import ( | ||
QgsGradientStop, | ||
QgsGradientColorRamp | ||
) | ||
import numpy as np | ||
|
||
from typing import List | ||
|
||
|
||
def create_colorramp( | ||
boundaries: List[float], | ||
colors: List[QColor], | ||
discrete: bool = False, | ||
): | ||
""" | ||
Manually construct colorramp from boundaries and colors. The stops | ||
determined by the createColorRamp method appear to be broken. | ||
""" | ||
|
||
# For some reason discrete colormaps require the last color also added as | ||
# stop | ||
if discrete: | ||
indices_stops = slice(1, None) | ||
else: | ||
indices_stops = slice(1, -1) | ||
|
||
bound_arr = np.array(boundaries) | ||
boundaries_norm = (bound_arr-bound_arr[0])/(bound_arr[-1]-bound_arr[0]) | ||
stops = [ | ||
QgsGradientStop(stop, color) for stop, color in zip( | ||
boundaries_norm[indices_stops], colors[indices_stops] | ||
) | ||
] | ||
return QgsGradientColorRamp(colors[0], colors[-1], discrete, stops) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters