Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c0c7ff

Browse files
Fix color values between 0 and 255 with decimal values
1 parent a7fd37b commit 2c0c7ff

11 files changed

+40
-46
lines changed

plotly/Test_plotlyfig.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function testScatterPlotData(tc)
208208
"size", 36 * ones(size(x)), ...
209209
"line", struct( ...
210210
"width", 0.7500, ...
211-
"color", 'rgb(0.000000,113.985000,188.955000)' ...
211+
"color", "rgb(0,114,189)" ...
212212
), ...
213213
"symbol", 'circle', ...
214214
"color", "rgba(0,0,0,0)", ...
@@ -244,7 +244,7 @@ function testScatter3DPlotData(tc)
244244
"size", 72 * ones(size(x)), ...
245245
"line", struct( ...
246246
"width", 0.7500, ...
247-
"color", 'rgb(0.000000,113.985000,188.955000)' ...
247+
"color", "rgb(0,114,189)" ...
248248
), ...
249249
"symbol", 'circle', ...
250250
"color", "rgba(0,0,0,0)", ...
@@ -649,7 +649,7 @@ function testContourPlotData(tc)
649649
"line", struct( ...
650650
"width", 0.75, ...
651651
"dash", 'solid', ...
652-
"color", 'rgba(0,0,0,0)', ...
652+
"color", "rgba(0,0,0,0)", ...
653653
"smoothing", 0 ...
654654
), ...
655655
"showlegend", false ...
@@ -834,7 +834,7 @@ function testErrorbarData(tc)
834834
"arrayminus", err, ...
835835
"thickness", 0.5, ...
836836
"width", 6, ...
837-
"color", 'rgb(0.000000,113.985000,188.955000)' ...
837+
"color", "rgb(0,114,189)" ...
838838
), ...
839839
"error_x", struct( ...
840840
"visible", true, ...
@@ -843,7 +843,7 @@ function testErrorbarData(tc)
843843
"arrayminus", zeros(1,0), ...
844844
"thickness", 0.5, ...
845845
"width", 6, ...
846-
"color", 'rgb(0.000000,113.985000,188.955000)' ...
846+
"color", "rgb(0,114,189)" ...
847847
) ...
848848
), AbsTol=1e-15);
849849
end

plotly/plotlyfig_aux/handlegraphics/updateContourgroup.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787

8888
%-line color-%
8989
if isnumeric(lineColor)
90-
lineColor = getStringColor( 255*lineColor );
90+
lineColor = getStringColor(round(255*lineColor));
9191
else
92-
lineColor = 'rgba(0,0,0,0)';
92+
lineColor = "rgba(0,0,0,0)";
9393
end
9494

9595
%-line dash-%
@@ -126,28 +126,28 @@
126126
%-colorscale-%
127127
if strcmp(plotData.Fill, 'on')
128128
if isBackground
129-
colorScale{1} = {0, getStringColor( 255*ones(1,3) )};
129+
colorScale{1} = {0, getStringColor(round(255*ones(1,3)))};
130130
cScaleInd = linspace(1/nContours, 1, nContours);
131131
end
132132
for n = 1:nContours
133133
m = n;
134134
if isBackground
135135
m = n+1;
136136
end
137-
stringColor = getStringColor( 255*cMap(cMapInd(n), :) );
137+
stringColor = getStringColor(round(255*cMap(cMapInd(n), :)));
138138
colorScale{m} = {cScaleInd(n), stringColor};
139139
end
140140
else
141141
cScaleInd = rescale(1:nColors, 0, 1);
142142
for n = 1:nColors
143-
stringColor = getStringColor( 255*cMap(n,:) );
143+
stringColor = getStringColor(round(255*cMap(n,:)));
144144
colorScale{n} = {cScaleInd(n), stringColor};
145145
end
146146
end
147147
end
148148

149149
function labelFont = getLabelFont(axisData)
150-
labelColor = getStringColor(255*axisData.XAxis.Color);
150+
labelColor = getStringColor(round(255*axisData.XAxis.Color));
151151
labelSize = axisData.XAxis.FontSize;
152152
labelFamily = matlab2plotlyfont(axisData.XAxis.FontName);
153153

plotly/plotlyfig_aux/handlegraphics/updateErrorbar.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
obj.data{plotIndex}.error_x.width = obj.PlotlyDefaults.ErrorbarWidth;
3434

3535
%-errorbar color-%
36-
errorColor = getStringColor(255*plotData.Color);
36+
errorColor = getStringColor(round(255*plotData.Color));
3737
obj.data{plotIndex}.error_y.color = errorColor;
3838
obj.data{plotIndex}.error_x.color = errorColor;
3939
end

plotly/plotlyfig_aux/handlegraphics/updateGeobubble.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ function updateGeobubble(obj,geoIndex)
8282
%-set trace marker-%
8383
marker = struct();
8484
marker.size = sData{g}*1.25;
85-
marker.color = getStringColor(255*colorMap(mod(g-1, nColors)+1, :));
86-
marker.line.color = 'rgb(255, 255, 255)';
85+
marker.color = getStringColor(round(255*colorMap(mod(g-1, nColors)+1, :)));
86+
marker.line.color = "rgb(255, 255, 255)";
8787

8888
obj.data{p}.marker = marker;
8989

plotly/plotlyfig_aux/handlegraphics/updateHistogram2.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
faceColor = plotData.FaceColor;
6969

7070
if isnumeric(faceColor)
71-
obj.data{dataIndex}.color = getStringColor(255*faceColor);
71+
obj.data{dataIndex}.color = getStringColor(round(255*faceColor));
7272
elseif strcmp(faceColor, 'none')
73-
obj.data{dataIndex}.color = getStringColor(255*zeros(1,3), 0.1);
73+
obj.data{dataIndex}.color = getStringColor(round(255*zeros(1,3), 0.1));
7474
elseif strcmp(faceColor, 'flat')
7575
obj.data{dataIndex}.intensity = cData;
7676
obj.data{dataIndex}.colorscale = getColorScale(colorMap);
@@ -158,7 +158,7 @@ function updateScene(obj, dataIndex)
158158
ax.zeroline = false;
159159
ax.showline = true;
160160
ax.showspikes = true;
161-
ax.linecolor = getStringColor(255*axx.Color);
161+
ax.linecolor = getStringColor(round(255*axx.Color));
162162
ax.range = axisData.(axName + "Lim");
163163

164164
%-label-%
@@ -168,14 +168,14 @@ function updateScene(obj, dataIndex)
168168
ax.title = parseString(ax.title);
169169
end
170170
ax.titlefont.size = label.FontSize;
171-
ax.titlefont.color = getStringColor(255*label.Color);
171+
ax.titlefont.color = getStringColor(round(255*label.Color));
172172
ax.titlefont.family = matlab2plotlyfont(label.FontName);
173173

174174
%-ticks-%
175175
ax.tickvals = axx.TickValues;
176176
ax.ticktext = axx.TickLabels;
177177

178-
ax.tickcolor = getStringColor(255*axx.Color);
178+
ax.tickcolor = getStringColor(round(255*axx.Color));
179179
ax.tickfont.size = axx.FontSize;
180180
ax.tickfont.family = matlab2plotlyfont(axx.FontName);
181181

@@ -303,6 +303,6 @@ function updateScene(obj, dataIndex)
303303
colorScale = cell(nColors, 1);
304304

305305
for n = 1:nColors
306-
colorScale{n} = {normInd(n), getStringColor(255*colorMap(n, :))};
306+
colorScale{n} = {normInd(n), getStringColor(round(255*colorMap(n, :)))};
307307
end
308308
end

plotly/plotlyfig_aux/handlegraphics/updateLineseries.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ function updateDefaultPolaraxes(obj, plotIndex)
268268
polarAxis.angularaxis.nticks = 16;
269269
polarAxis.angularaxis.tickfont.size = thetaAxis.FontSize;
270270
polarAxis.angularaxis.tickfont.color = getStringColor(...
271-
255*thetaAxis.Color);
271+
round(255*thetaAxis.Color));
272272
polarAxis.angularaxis.tickfont.family = matlab2plotlyfont(...
273273
thetaAxis.FontName);
274274

@@ -278,7 +278,7 @@ function updateDefaultPolaraxes(obj, plotIndex)
278278
polarAxis.angularaxis.title.text = thetaLabel.String;
279279
polarAxis.radialaxis.title.font.size = thetaLabel.FontSize;
280280
polarAxis.radialaxis.title.font.color = getStringColor(...
281-
255*thetaLabel.Color);
281+
round(255*thetaLabel.Color));
282282
polarAxis.radialaxis.title.font.family = matlab2plotlyfont(...
283283
thetaLabel.FontName);
284284

@@ -298,14 +298,16 @@ function updateDefaultPolaraxes(obj, plotIndex)
298298
polarAxis.radialaxis.showticklabels = true;
299299
polarAxis.radialaxis.tickvals = tickValues;
300300
polarAxis.radialaxis.tickfont.size = rAxis.FontSize;
301-
polarAxis.radialaxis.tickfont.color = getStringColor(255*rAxis.Color);
301+
polarAxis.radialaxis.tickfont.color = getStringColor(round(...
302+
255*rAxis.Color));
302303
polarAxis.radialaxis.tickfont.family = matlab2plotlyfont(...
303304
rAxis.FontName);
304305

305306
rLabel = rAxis.Label;
306307
polarAxis.radialaxis.title.text = rLabel.String;
307308
polarAxis.radialaxis.title.font.size = rLabel.FontSize;
308-
polarAxis.radialaxis.title.font.color = getStringColor(255*rLabel.Color);
309+
polarAxis.radialaxis.title.font.color = getStringColor(round(...
310+
255*rLabel.Color));
309311
polarAxis.radialaxis.title.font.family = matlab2plotlyfont(...
310312
rLabel.FontName);
311313

plotly/plotlyfig_aux/handlegraphics/updateQuiver.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
obj.data{dataIndex}.name = plotData.DisplayName;
4949

5050
%-quiver line color-%
51-
lineColor = 255 * plotData.Color;
51+
lineColor = round(255*plotData.Color);
5252
obj.data{dataIndex}.line.color = getStringColor(lineColor);
5353

5454
%-quiver line width-%
@@ -381,7 +381,3 @@ function updateScene(obj, dataIndex)
381381

382382
scaleFactor = 0.8 * xStep/uStep;
383383
end
384-
385-
function stringColor = getStringColor(numColor)
386-
stringColor = sprintf('rgb(%f,%f,%f)', numColor);
387-
end

plotly/plotlyfig_aux/handlegraphics/updateSlice.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function updateSurfaceEdgeColor(obj, dataIndex)
193193
end
194194

195195
%-coloring-%
196-
numColor = 255 * edgeColor;
196+
numColor = round(255*edgeColor);
197197
stringColor = getStringColor(numColor);
198198

199199
obj.data{dataIndex}.contours.x.color = stringColor;
@@ -215,7 +215,7 @@ function updateSurfaceFaceColor(obj, dataIndex, surfaceColor)
215215
obj.data{dataIndex}.autocolorscale = false;
216216

217217
if isnumeric(faceColor)
218-
numColor = 255 * faceColor;
218+
numColor = round(255*faceColor);
219219
stringColor = getStringColor(numColor);
220220

221221
colorScale{1} = {0, stringColor};
@@ -225,7 +225,7 @@ function updateSurfaceFaceColor(obj, dataIndex, surfaceColor)
225225
nColors = size(colorMap, 1);
226226

227227
for c = 1:nColors
228-
stringColor = getStringColor(255*colorMap(c,:));
228+
stringColor = getStringColor(round(255*colorMap(c,:)));
229229
colorScale{c} = {(c-1)/(nColors-1), stringColor};
230230
end
231231

@@ -236,7 +236,3 @@ function updateSurfaceFaceColor(obj, dataIndex, surfaceColor)
236236
obj.data{dataIndex}.surfacecolor = surfaceColor;
237237
obj.data{dataIndex}.colorscale = colorScale;
238238
end
239-
240-
function stringColor = getStringColor(numColor)
241-
stringColor = sprintf('rgb(%f,%f,%f)', numColor);
242-
end

plotly/plotlyfig_aux/handlegraphics/updateStackedplot.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function updateStackedplotAxis(obj, plotIndex)
160160
if strcmp(plotData.GridVisible, 'on')
161161
ax{a}.showgrid = true;
162162
ax{a}.gridwidth = lineWidth;
163-
ax{a}.gridcolor = getStringColor(0.15*ones(1,3), 0.15);
163+
ax{a}.gridcolor = getStringColor(round(255*0.15*ones(1,3)), 0.15);
164164
else
165165
ax{a}.showgrid = false;
166166
end

plotly/plotlyfig_aux/helpers/extractScatterMarker.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
faceColor = "rgba(0,0,0,0)";
7373
case 'auto'
7474
if ~strcmp(axisData.Color,'none')
75-
faceColor = 255*axisData.Color;
75+
faceColor = round(255*axisData.Color);
7676
else
77-
faceColor = 255*figureData.Color;
77+
faceColor = round(255*figureData.Color);
7878
end
7979
faceColor = getStringColor(faceColor);
8080
case 'flat'
@@ -112,9 +112,9 @@
112112
lineColor = "rgba(0,0,0,0)";
113113
case 'auto'
114114
if ~strcmp(axisData.Color,'none')
115-
lineColor = 255*axisData.Color;
115+
lineColor = round(255*axisData.Color);
116116
else
117-
lineColor = 255*figureData.Color;
117+
lineColor = round(255*figureData.Color);
118118
end
119119
lineColor = getStringColor(lineColor, markerEdgeAlpha);
120120
case 'flat'
@@ -147,9 +147,9 @@
147147

148148
if cDataByIndex
149149
cMapInd = getcMapInd(cData, cLim, nColors);
150-
numColor = 255 * colorMap(cMapInd, :);
150+
numColor = round(255 * colorMap(cMapInd, :));
151151
else
152-
numColor = 255*cData;
152+
numColor = round(255*cData);
153153
end
154154

155155
if size(numColor, 1) == 1
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function stringColor = getStringColor(numColor, opacity)
22
if nargin == 1
3-
stringColor = sprintf('rgb(%f,%f,%f)', numColor);
3+
stringColor = sprintf("rgb(%d,%d,%d)", numColor);
44
elseif nargin == 2
5-
stringColor = sprintf('rgba(%f,%f,%f,%f)', numColor, opacity);
5+
stringColor = sprintf("rgba(%d,%d,%d,%f)", numColor, opacity);
66
else
7-
disp('Too many input arguments for getStringColor function.')
7+
disp("Too many input arguments for getStringColor function.")
88
end
99
end

0 commit comments

Comments
 (0)