diff --git a/plotly/plotlyfig.m b/plotly/plotlyfig.m index 48357dc1..418fbe96 100644 --- a/plotly/plotlyfig.m +++ b/plotly/plotlyfig.m @@ -100,6 +100,7 @@ obj.PlotlyDefaults.CaptionMarginIncreaseFactor = 1.2; obj.PlotlyDefaults.MinCaptionMargin = 80; obj.PlotlyDefaults.IsLight = false; + obj.PlotlyDefaults.isGeoaxis = false; %-State-% obj.State.Figure = []; @@ -741,11 +742,13 @@ function validate(obj) % update annotations for n = 1:obj.State.Figure.NumTexts try - if ~obj.PlotOptions.is_headmap_axis - updateAnnotation(obj,n); - else + if obj.PlotOptions.is_headmap_axis updateHeatmapAnnotation(obj,n); obj.PlotOptions.CleanFeedTitle = false; + elseif obj.PlotlyDefaults.isGeoaxis + % TODO + else + updateAnnotation(obj,n); end catch % TODO to the future @@ -1060,6 +1063,7 @@ function delete(obj) || strcmpi(fieldname,'yaxis') || strcmpi(fieldname,'cone')... || strcmpi(fieldname,'legend') || strcmpi(fieldname,'histogram')... || strcmpi(fieldname,'scatter') || strcmpi(fieldname,'line')... + || strcmpi(fieldname,'scattergeo') ... ) fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']); end diff --git a/plotly/plotlyfig_aux/core/updateAxis.m b/plotly/plotlyfig_aux/core/updateAxis.m index 1aec4ca6..1dc0ffd0 100644 --- a/plotly/plotlyfig_aux/core/updateAxis.m +++ b/plotly/plotlyfig_aux/core/updateAxis.m @@ -61,20 +61,28 @@ is_headmap_axis = isfield(axis_data, 'XDisplayData'); obj.PlotOptions.is_headmap_axis = is_headmap_axis; +%-------------------------------------------------------------------------% + +%-check if geo-axis-% +isGeoaxis = isfield(axis_data, 'Type') && strcmpi(axis_data.Type, 'geoaxes'); +obj.PlotlyDefaults.isGeoaxis = isGeoaxis; + +%-------------------------------------------------------------------------% + %-xaxis-% -if ~is_headmap_axis - xaxis = extractAxisData(obj,axis_data,'X'); +if is_headmap_axis + xaxis = extractHeatmapAxisData(obj,axis_data, 'X'); else - xaxis = extractHeatmapAxisData(obj,axis_data,'X'); + xaxis = extractAxisData(obj,axis_data, 'X'); end %-------------------------------------------------------------------------% %-yaxis-% -if ~is_headmap_axis - yaxis = extractAxisData(obj,axis_data,'Y'); +if is_headmap_axis + yaxis = extractHeatmapAxisData(obj,axis_data, 'Y'); else - yaxis = extractHeatmapAxisData(obj,axis_data,'Y'); + yaxis = extractAxisData(obj,axis_data, 'Y'); end %-------------------------------------------------------------------------% diff --git a/plotly/plotlyfig_aux/core/updateData.m b/plotly/plotlyfig_aux/core/updateData.m index 4d8e0f0f..1c11347e 100644 --- a/plotly/plotlyfig_aux/core/updateData.m +++ b/plotly/plotlyfig_aux/core/updateData.m @@ -51,7 +51,13 @@ switch lower(obj.State.Plot(dataIndex).Class) + %--GEOAXES SPECIAL CASE--% + case 'geoaxes' + UpdateGeoAxes(obj, dataIndex); + %--CORE PLOT OBJECTS--% + case 'geobubble' + updateGeobubble(obj, dataIndex); case 'scatterhistogram' updateScatterhistogram(obj, dataIndex); case 'wordcloud' @@ -65,7 +71,11 @@ updateImage3D(obj, dataIndex); end case 'line' - updateLineseries(obj, dataIndex); + if obj.PlotlyDefaults.isGeoaxis + updateGeoPlot(obj, dataIndex); + else + updateLineseries(obj, dataIndex); + end case 'categoricalhistogram' updateCategoricalHistogram(obj, dataIndex); case 'histogram' @@ -119,7 +129,9 @@ updateQuivergroup(obj, dataIndex); case 'scatter' if strcmpi(obj.State.Axis(dataIndex).Handle.Type, 'polaraxes') - updateScatterPolar(obj, dataIndex); + updateScatterPolar(obj, dataIndex); + elseif obj.PlotlyDefaults.isGeoaxis + updateGeoScatter(obj, dataIndex); else updateScatter(obj, dataIndex); end diff --git a/plotly/plotlyfig_aux/handlegraphics/UpdateGeoAxes.m b/plotly/plotlyfig_aux/handlegraphics/UpdateGeoAxes.m new file mode 100644 index 00000000..c06e665c --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/UpdateGeoAxes.m @@ -0,0 +1,135 @@ +function UpdateGeoAxes(obj, geoIndex) + + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(geoIndex).AssociatedAxis); + + %-GET DATA STRUCTURE- % + geoData = get(obj.State.Plot(geoIndex).Handle); + + %-CHECK FOR MULTIPLE AXES-% + [xsource, ysource] = findSourceAxis(obj,axIndex); + + %-------------------------------------------------------------------------% + + %-set domain geo plot-% + xo = geoData.Position(1); + yo = geoData.Position(2); + w = geoData.Position(3); + h = geoData.Position(4); + + geo.domain.x = min([xo xo + w],1); + geo.domain.y = min([yo yo + h],1); + + %-------------------------------------------------------------------------% + + %-setting projection-% + geo.projection.type = 'mercator'; + + %-------------------------------------------------------------------------% + + %-setting basemap-% + geo.framecolor = 'rgb(120,120,120)'; + + if strcmpi(geoData.Basemap, 'streets-light') + geo.oceancolor = 'rgba(20,220,220,1)'; + geo.landcolor = 'rgba(20,220,220,0.2)'; + elseif strcmpi(geoData.Basemap, 'colorterrain') + geo.oceancolor = 'rgba(118,165,225,0.6)'; + geo.landcolor = 'rgba(190,180,170,1)'; + geo.showcountries = true; + geo.showlakes = true; + end + + geo.showocean = true; + geo.showcoastlines = false; + geo.showland = true; + + %-------------------------------------------------------------------------% + + %-setting latitude axis-% + latTick = geoData.LatitudeAxis.TickValues; + + geo.lataxis.range = geoData.LatitudeLimits; + geo.lataxis.tick0 = latTick(1); + geo.lataxis.dtick = mean(diff(latTick)); + + if strcmpi(geoData.Grid, 'on') + geo.lataxis.showgrid = true; + geo.lataxis.gridwidth = geoData.LineWidth; + geo.lataxis.gridcolor = sprintf('rgba(%f,%f,%f,%f)', 255*geoData.GridColor, geoData.GridAlpha); + end + + %-------------------------------------------------------------------------% + + %-setting longitude axis-% + lonTick = geoData.LongitudeAxis.TickValues; + + geo.lonaxis.range = geoData.LongitudeLimits; + geo.lonaxis.tick0 = lonTick(1); + geo.lonaxis.dtick = mean(diff(lonTick)); + + if strcmpi(geoData.Grid, 'on') + geo.lonaxis.showgrid = true; + geo.lonaxis.gridwidth = geoData.LineWidth; + geo.lonaxis.gridcolor = sprintf('rgba(%f,%f,%f,%f)', 255*geoData.GridColor, geoData.GridAlpha); + end + + %-------------------------------------------------------------------------% + + %-set map center-% + geo.center.lat = geoData.MapCenter(1); + geo.center.lon = geoData.MapCenter(2); + + %-------------------------------------------------------------------------% + + %-set better resolution-% + geo.resolution = '50'; + + %-------------------------------------------------------------------------% + + %-set geo axes to layout-% + obj.layout = setfield(obj.layout, sprintf('geo%d', xsource+1), geo); + + %-------------------------------------------------------------------------% + + %-TEXT STTINGS-% + isText = false; + child = geoData.Children; + t = 1; + + for n=1:length(child) + if strcmpi(child(n).Type, 'text') + isText = true; + texts{t} = child(t).String; + lats(t) = child(t).Position(1); + lons(t) = child(t).Position(2); + sizes(t) = child(t).FontSize; + families{t} = matlab2plotlyfont(child(t).FontName); + colors{t} = sprintf('rgb(%f,%f,%f)', child(t).Color); + + if strcmpi(child(t).HorizontalAlignment, 'left') + pos{t} = 'right'; + elseif strcmpi(child(t).HorizontalAlignment, 'right') + pos{t} = 'left'; + else + pos{t} = child(t).HorizontalAlignment; + end + + t = t + 1; + end + end + + if isText + obj.data{geoIndex}.type = 'scattergeo'; + obj.data{geoIndex}.mode = 'text'; + obj.data{geoIndex}.text = texts; + obj.data{geoIndex}.lat = lats; + obj.data{geoIndex}.lon = lons; + obj.data{geoIndex}.geo = obj.data{geoIndex-1}.geo; + + obj.data{geoIndex}.textfont.size = sizes; + obj.data{geoIndex}.textfont.color = colors; + obj.data{geoIndex}.textfont.family = families; + obj.data{geoIndex}.textposition = pos; + end +end \ No newline at end of file diff --git a/plotly/plotlyfig_aux/handlegraphics/updateGeoPlot.m b/plotly/plotlyfig_aux/handlegraphics/updateGeoPlot.m new file mode 100644 index 00000000..3d292dc6 --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updateGeoPlot.m @@ -0,0 +1,53 @@ +function updateGeoPlot(obj,geoIndex) + + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(geoIndex).AssociatedAxis); + + %-GET STRUCTURES-% + geoData = get(obj.State.Plot(geoIndex).Handle); + axisData = geoData.Parent; + figureData = get(obj.State.Figure.Handle); + + %-CHECK FOR MULTIPLE AXES-% + [xsource, ysource] = findSourceAxis(obj,axIndex); + + %-ASSOCIATE GEO-AXES LAYOUT-% + obj.data{geoIndex}.geo = sprintf('geo%d', xsource+1); + + %-------------------------------------------------------------------------% + + %-set scattergeo type-% + obj.data{geoIndex}.type = 'scattergeo'; + + %-------------------------------------------------------------------------% + + %-set scattergeo mode-% + obj.data{geoIndex}.mode = 'lines+markers'; + + %-------------------------------------------------------------------------% + + %-set plot data-% + obj.data{geoIndex}.lat = geoData.LatitudeData; + obj.data{geoIndex}.lon = geoData.LongitudeData; + + %-------------------------------------------------------------------------% + + %-get marker setting-% + [marker, linee] = extractGeoLinePlusMarker(geoData, axisData); + + %-------------------------------------------------------------------------% + + %-set marker field-% + obj.data{geoIndex}.marker = marker; + + if strcmpi(geoData.Marker, 'none') + obj.data{geoIndex}.mode = 'lines'; + end + + %-------------------------------------------------------------------------% + + %-set line field-% + obj.data{geoIndex}.line = linee; + + %-------------------------------------------------------------------------% +end \ No newline at end of file diff --git a/plotly/plotlyfig_aux/handlegraphics/updateGeoScatter.m b/plotly/plotlyfig_aux/handlegraphics/updateGeoScatter.m new file mode 100644 index 00000000..514555de --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updateGeoScatter.m @@ -0,0 +1,44 @@ +function updateGeoScatter(obj,geoIndex) + + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(geoIndex).AssociatedAxis); + + %-GET STRUCTURES-% + geoData = get(obj.State.Plot(geoIndex).Handle); + axisData = geoData.Parent; + figureData = get(obj.State.Figure.Handle); + + %-CHECK FOR MULTIPLE AXES-% + [xsource, ysource] = findSourceAxis(obj,axIndex); + + %-ASSOCIATE GEO-AXES LAYOUT-% + obj.data{geoIndex}.geo = sprintf('geo%d', xsource+1); + + %-------------------------------------------------------------------------% + + %-set scattergeo type-% + obj.data{geoIndex}.type = 'scattergeo'; + + %-------------------------------------------------------------------------% + + %-set scattergeo mode-% + obj.data{geoIndex}.mode = 'markers'; + + %-------------------------------------------------------------------------% + + %-set plot data-% + obj.data{geoIndex}.lat = geoData.LatitudeData; + obj.data{geoIndex}.lon = geoData.LongitudeData; + + %-------------------------------------------------------------------------% + + %-get marker setting-% + marker = extractGeoMarker(geoData, axisData); + + %-------------------------------------------------------------------------% + + %-set marker field-% + obj.data{geoIndex}.marker = marker; + + %-------------------------------------------------------------------------% +end \ No newline at end of file diff --git a/plotly/plotlyfig_aux/handlegraphics/updateGeobubble.m b/plotly/plotlyfig_aux/handlegraphics/updateGeobubble.m new file mode 100644 index 00000000..5339a239 --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updateGeobubble.m @@ -0,0 +1,249 @@ +function updateGeobubble(obj,geoIndex) + + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(geoIndex).AssociatedAxis); + + %-GET STRUCTURES-% + geoData = get(obj.State.Plot(geoIndex).Handle); + + %-CHECK FOR MULTIPLE AXES-% + [xsource, ysource] = findSourceAxis(obj,axIndex); + + %-----------------------------------------------------------------------------% + + %-PASE DATA-% + bubbleRange = geoData.BubbleWidthRange; + allLats = geoData.LatitudeData; + allLons = geoData.LongitudeData; + allSizes = rescale(geoData.SizeData, bubbleRange(1), bubbleRange(2)); + + if ~isempty(geoData.ColorData) + allNames = geoData.ColorData; + + [groupNames, ~, allNamesIdx] = unique(allNames); + nGroups = length(groupNames); + byGroups = true; + + for g=1:nGroups + + idx = g == allNamesIdx; + + group{g} = char(groupNames(g)); + lat{g} = allLats(idx); + lon{g} = allLons(idx); + sData{g} = allSizes(idx); + + if length(lat{g}) < 2 + lat{g} = [allLats(idx); NaN; NaN]; + lon{g} = [allLons(idx); NaN; NaN]; + sData{g} = [allSizes(idx); NaN; NaN]; + end + + end + + else + lat{1} = allLats; + lon{1} = allLons; + sData{1} = allSizes; + nGroups = 1; + byGroups = false; + end + + %-----------------------------------------------------------------------------% + + %=============================================================================% + % + %-SETTING GEOBBUBLE PLOT-% + % + %=============================================================================% + + for g = 1:nGroups + + %-------------------------------------------------------------------------% + + %-get current trace index-% + p = geoIndex; + + if g > 1 + obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1; + p = obj.PlotOptions.nPlots; + end + + %-------------------------------------------------------------------------% + + %-set scattergeo type-% + obj.data{p}.type = 'scattergeo'; + + %-------------------------------------------------------------------------% + + %-set scattergeo mode-% + obj.data{p}.mode = 'markers'; + + %-------------------------------------------------------------------------% + + %-set plot data-% + obj.data{p}.lat = lat{g}; + obj.data{p}.lon = lon{g}; + + %-------------------------------------------------------------------------% + + %-get marker setting-% + marker = struct(); + marker.size = sData{g}*1.25; + marker.color = sprintf('rgb(%f,%f,%f)', 255*geoData.BubbleColorList(g ,:)); + marker.line.color = 'rgb(255, 255, 255)'; + + %-------------------------------------------------------------------------% + + %-set marker field-% + obj.data{p}.marker = marker; + + %-------------------------------------------------------------------------% + + %-ASSOCIATE GEO-AXES LAYOUT-% + obj.data{p}.geo = sprintf('geo%d', xsource+1); + + %-------------------------------------------------------------------------% + + %-legend-% + if byGroups + obj.data{p}.name = group{g}; + obj.data{p}.legendgroup = obj.data{p}.name; + obj.data{p}.showlegend = true; + end + + %-------------------------------------------------------------------------% + + end + + %=============================================================================% + % + %-SETTING LAYOUT-% + % + %=============================================================================% + + %-set domain geo plot-% + xo = geoData.Position(1); + yo = geoData.Position(2); + w = geoData.Position(3); + h = geoData.Position(4); + + geo.domain.x = min([xo xo + w],1); + geo.domain.y = min([yo yo + h],1); + + %-----------------------------------------------------------------------------% + + %-setting projection-% + geo.projection.type = 'mercator'; + + %-----------------------------------------------------------------------------% + + %-setting basemap-% + geo.framecolor = 'rgb(120,120,120)'; + + if strcmpi(geoData.Basemap, 'streets-light') + geo.oceancolor = 'rgba(20,220,220,1)'; + geo.landcolor = 'rgba(20,220,220,0.2)'; + elseif strcmpi(geoData.Basemap, 'colorterrain') + geo.oceancolor = 'rgba(118,165,225,0.6)'; + geo.landcolor = 'rgba(190,180,170,1)'; + geo.showcountries = true; + geo.showlakes = true; + end + + geo.showocean = true; + geo.showcoastlines = false; + geo.showland = true; + + %-----------------------------------------------------------------------------% + + %-setting latitude axis-% + geo.lataxis.range = geoData.LatitudeLimits; + + if strcmpi(geoData.GridVisible, 'on') + geo.lataxis.showgrid = true; + geo.lataxis.gridwidth = 0.5; + geo.lataxis.gridcolor = 'rgba(38.250000,38.250000,38.250000,0.150000)'; + end + + %-----------------------------------------------------------------------------% + + %-setting longitude axis-% + geo.lonaxis.range = geoData.LongitudeLimits; + + if strcmpi(geoData.GridVisible, 'on') + geo.lonaxis.showgrid = true; + geo.lonaxis.gridwidth = 0.5; + geo.lonaxis.gridcolor = 'rgba(38.250000,38.250000,38.250000,0.150000)'; + end + + %-----------------------------------------------------------------------------% + + %-set map center-% + geo.center.lat = geoData.MapCenter(1); + geo.center.lon = geoData.MapCenter(2); + + %-----------------------------------------------------------------------------% + + %-set better resolution-% + geo.resolution = '50'; + + %-----------------------------------------------------------------------------% + + %-set geo axes to layout-% + obj.layout = setfield(obj.layout, sprintf('geo%d', xsource+1), geo); + + %-----------------------------------------------------------------------------% + + %-remove any annotation text-% + istitle = length(geoData.Title) > 0; + obj.layout.annotations{1}.text = ' '; + obj.layout.annotations{1}.showarrow = false; + + %-----------------------------------------------------------------------------% + + %-layout title-% + if istitle + obj.layout.annotations{1}.text = sprintf('%s', geoData.Title); + obj.layout.annotations{1}.xref = 'paper'; + obj.layout.annotations{1}.yref = 'paper'; + obj.layout.annotations{1}.yanchor = 'top'; + obj.layout.annotations{1}.xanchor = 'middle'; + obj.layout.annotations{1}.x = mean(geo.domain.x); + obj.layout.annotations{1}.y = 0.96; + obj.layout.annotations{1}.font.color = 'black'; + obj.layout.annotations{1}.font.family = matlab2plotlyfont(geoData.FontName); + obj.layout.annotations{1}.font.size = 1.5*geoData.FontSize; + end + + %-----------------------------------------------------------------------------% + + %-setting legend-% + if byGroups + obj.layout.showlegend = true; + obj.layout.legend.borderwidth = 1; + obj.layout.legend.bordercolor = 'rgba(0,0,0,0.2)'; + obj.layout.legend.font.family = matlab2plotlyfont(geoData.FontName); + obj.layout.legend.font.size = 1.0*geoData.FontSize; + + if length(geoData.ColorLegendTitle) > 0 + obj.layout.legend.title.text = sprintf('%s', geoData.ColorLegendTitle); + obj.layout.legend.title.side = 'top'; + obj.layout.legend.title.font.family = matlab2plotlyfont(geoData.FontName); + obj.layout.legend.title.font.size = 1.2*geoData.SizeLegendTitle; + obj.layout.legend.title.font.color = 'black'; + end + + obj.layout.legend.x = geo.domain.x(end) * 0.980; + obj.layout.legend.y = geo.domain.y(end) * 1.001; + obj.layout.legend.xanchor = 'left'; + obj.layout.legend.yanchor = 'top'; + obj.layout.legend.itemsizing = 'constant'; + obj.layout.legend.itemwidth = 30; + obj.layout.legend.tracegroupgap = 0.01; + obj.layout.legend.traceorder = 'normal'; + obj.layout.legend.valign = 'middle'; + end + + %-----------------------------------------------------------------------------% +end \ No newline at end of file diff --git a/plotly/plotlyfig_aux/handlegraphics/updateWordcloud.m b/plotly/plotlyfig_aux/handlegraphics/updateWordcloud.m index b4c01be0..7fbf105a 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateWordcloud.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateWordcloud.m @@ -123,7 +123,7 @@ function updateWordcloud(obj,scatterIndex) %-------------------------------------------------------------------------% %-det font family-% -obj.data{scatterIndex}.textfont.family = matlab2plotlyfont(scatter_data.FontName);; +obj.data{scatterIndex}.textfont.family = matlab2plotlyfont(scatter_data.FontName); %-------------------------------------------------------------------------% diff --git a/plotly/plotlyfig_aux/helpers/extractGeoLinePlusMarker.m b/plotly/plotlyfig_aux/helpers/extractGeoLinePlusMarker.m new file mode 100644 index 00000000..e67a5076 --- /dev/null +++ b/plotly/plotlyfig_aux/helpers/extractGeoLinePlusMarker.m @@ -0,0 +1,226 @@ +function [marker, linee] = extractGeoLinePlusMarker(geoData, axisData) + + %-------------------------------------------------------------------------% + + %-FIGURE STRUCTURE-% + figureData = get(ancestor(geoData.Parent,'figure')); + + %-INITIALIZE OUTPUTS-% + marker = struct(); + linee = struct(); + + %-------------------------------------------------------------------------% + + %-LINE SETTINGS-% + + % line color + lineColor = geoData.Color; + + if isnumeric(lineColor) + lineColor = sprintf('rgb(%f,%f,%f)', 255 * lineColor); + + else + switch lineColor + + case 'none' + + lineColor = 'rgba(0,0,0,0)'; + + case {'auto', 'manual'} + + lineColor = sprintf('rgb(%f,%f,%f)', 255*lineColor); + + case 'flat' + + cData = geoData.CData; + cMap = figureData.Colormap; + ncolors = size(cMap, 1); + + for m = 1:length(cData) + colorValue = max( min( cData(m), axisData.CLim(2) ), axisData.CLim(1) ); + scaleFactor = (colorValue - axisData.CLim(1)) / diff(axisData.CLim); + rgbColor = 255 * cMap( 1+floor(scaleFactor*(ncolors-1)), : ); + lineColor{m} = sprintf('rgb(%f,%f,%f)', rgbColor); + end + + end + end + + linee.color = lineColor; + + % line width + linee.width = 2*geoData.LineWidth; + + % line style + lineStyle = geoData.LineStyle; + + switch lineStyle + + case '-' + lineStyle = 'solid'; + case '--' + lineStyle = 'dash'; + case ':' + lineStyle = 'dot'; + case '.-' + lineStyle = 'dash-dot'; + end + + linee.dash = lineStyle; + + %-------------------------------------------------------------------------% + + %-MARKER SIZEREF-% + marker.sizeref = 1; + + %-------------------------------------------------------------------------% + + %-MARKER SIZEMODE-% + marker.sizemode = 'area'; + + %-------------------------------------------------------------------------% + + %-MARKER SIZE (STYLE)-% + marker.size = geoData.MarkerSize; + + %-------------------------------------------------------------------------% + + %-MARKER SYMBOL (STYLE)-% + if ~strcmp(geoData.Marker,'none') + + switch geoData.Marker + case '.' + marksymbol = 'circle'; + case 'o' + marksymbol = 'circle'; + case 'x' + marksymbol = 'x-thin-open'; + case '+' + marksymbol = 'cross-thin-open'; + case '*' + marksymbol = 'asterisk-open'; + case {'s','square'} + marksymbol = 'square'; + case {'d','diamond'} + marksymbol = 'diamond'; + case 'v' + marksymbol = 'triangle-down'; + case '^' + marksymbol = 'star-triangle-up'; + case '<' + marksymbol = 'triangle-left'; + case '>' + marksymbol = 'triangle-right'; + case {'p','pentagram'} + marksymbol = 'star'; + case {'h','hexagram'} + marksymbol = 'hexagram'; + end + + marker.symbol = marksymbol; + end + + %-------------------------------------------------------------------------% + + %-MARKER LINE WIDTH (STYLE)-% + marker.line.width = 2*geoData.LineWidth; + + %-------------------------------------------------------------------------% + + %--MARKER FILL COLOR--% + + % marker face color + faceColor = geoData.MarkerFaceColor; + + filledMarkerSet = {'o','square','s','diamond','d','v','^', '<','>','hexagram','pentagram'}; + filledMarker = ismember(geoData.Marker, filledMarkerSet); + + if filledMarker + + if isnumeric(faceColor) + markerColor = sprintf('rgb(%f,%f,%f)', 255 * faceColor); + + else + + switch faceColor + + case 'none' + + markerColor = 'rgba(0,0,0,0)'; + + case 'auto' + + if ~strcmp(axisData.Color,'none') + col = 255*axisData.Color; + else + col = 255*figureData.Color; + end + + markerColor = sprintf('rgb(%f,%f,%f)', col); + + case 'flat' + + cData = geoData.CData; + cMap = figureData.Colormap; + ncolors = size(cMap, 1); + + for m = 1:length(cData) + colorValue = max( min( cData(m), axisData.CLim(2) ), axisData.CLim(1) ); + scaleFactor = (colorValue - axisData.CLim(1)) / diff(axisData.CLim); + rgbColor = 255 * cMap( 1+floor(scaleFactor*(ncolors-1)), : ); + markerColor{m} = sprintf('rgb(%f,%f,%f)', rgbColor); + end + end + end + + %-set marker color-% + marker.color = markerColor; + + end + + %-------------------------------------------------------------------------% + + %-MARKER LINE COLOR-% + + % marker edge color + edgeColor = geoData.MarkerEdgeColor; + + if isnumeric(edgeColor) + lineColor = sprintf('rgb(%f,%f,%f)', 255 * edgeColor); + + else + switch edgeColor + + case 'none' + + lineColor = 'rgba(0,0,0,0)'; + + case 'auto' + + lineColor = sprintf('rgb(%f,%f,%f)', 255*geoData.Color); + + case 'flat' + + cData = geoData.CData; + cMap = figureData.Colormap; + ncolors = size(cMap, 1); + + for m = 1:length(cData) + colorValue = max( min( cData(m), axisData.CLim(2) ), axisData.CLim(1) ); + scaleFactor = (colorValue - axisData.CLim(1)) / diff(axisData.CLim); + rgbColor = 255 * cMap( 1+floor(scaleFactor*(ncolors-1)), : ); + lineColor{m} = sprintf('rgb(%f,%f,%f)', rgbColor); + end + + end + end + + if filledMarker + marker.line.color = lineColor; + else + marker.color = lineColor; + end + + %-------------------------------------------------------------------------% + +end diff --git a/plotly/plotlyfig_aux/helpers/extractGeoMarker.m b/plotly/plotlyfig_aux/helpers/extractGeoMarker.m new file mode 100644 index 00000000..d1d20f13 --- /dev/null +++ b/plotly/plotlyfig_aux/helpers/extractGeoMarker.m @@ -0,0 +1,166 @@ +function marker = extractGeoMarker(geoData, axisData) + + %-------------------------------------------------------------------------% + + %-FIGURE STRUCTURE-% + figureData = get(ancestor(geoData.Parent,'figure')); + + %-INITIALIZE OUTPUT-% + marker = struct(); + + %-------------------------------------------------------------------------% + + %-MARKER SIZEREF-% + marker.sizeref = 1; + + %-------------------------------------------------------------------------% + + %-MARKER SIZEMODE-% + marker.sizemode = 'area'; + + %-------------------------------------------------------------------------% + + %-MARKER SIZE (STYLE)-% + marker.size = geoData.SizeData; + + %-------------------------------------------------------------------------% + + %-MARKER SYMBOL (STYLE)-% + if ~strcmp(geoData.Marker,'none') + + switch geoData.Marker + case '.' + marksymbol = 'circle'; + case 'o' + marksymbol = 'circle'; + case 'x' + marksymbol = 'x-thin-open'; + case '+' + marksymbol = 'cross-thin-open'; + case '*' + marksymbol = 'asterisk-open'; + case {'s','square'} + marksymbol = 'square'; + case {'d','diamond'} + marksymbol = 'diamond'; + case 'v' + marksymbol = 'triangle-down'; + case '^' + marksymbol = 'star-triangle-up'; + case '<' + marksymbol = 'triangle-left'; + case '>' + marksymbol = 'triangle-right'; + case {'p','pentagram'} + marksymbol = 'star'; + case {'h','hexagram'} + marksymbol = 'hexagram'; + end + + marker.symbol = marksymbol; + end + + %-------------------------------------------------------------------------% + + %-MARKER LINE WIDTH (STYLE)-% + marker.line.width = 2*geoData.LineWidth; + + %-------------------------------------------------------------------------% + + %--MARKER FILL COLOR--% + + % marker face color + faceColor = geoData.MarkerFaceColor; + + filledMarkerSet = {'o','square','s','diamond','d','v','^', '<','>','hexagram','pentagram'}; + filledMarker = ismember(geoData.Marker, filledMarkerSet); + + if filledMarker + + if isnumeric(faceColor) + markerColor = sprintf('rgb(%f,%f,%f)', 255 * faceColor); + + else + + switch faceColor + + case 'none' + + markerColor = 'rgba(0,0,0,0)'; + + case 'auto' + + if ~strcmp(axisData.Color,'none') + col = 255*axisData.Color; + else + col = 255*figureData.Color; + end + + markerColor = sprintf('rgb(%f,%f,%f)', col); + + case 'flat' + + cData = geoData.CData; + cMap = figureData.Colormap; + ncolors = size(cMap, 1); + + for m = 1:length(cData) + colorValue = max( min( cData(m), axisData.CLim(2) ), axisData.CLim(1) ); + scaleFactor = (colorValue - axisData.CLim(1)) / diff(axisData.CLim); + rgbColor = 255 * cMap( 1+floor(scaleFactor*(ncolors-1)), : ); + markerColor{m} = sprintf('rgb(%f,%f,%f)', rgbColor); + end + end + end + + %-set marker color-% + marker.color = markerColor; + + end + + %-------------------------------------------------------------------------% + + %-MARKER LINE COLOR-% + + % marker edge color + edgeColor = geoData.MarkerEdgeColor; + + if isnumeric(edgeColor) + lineColor = sprintf('rgb(%f,%f,%f)', 255 * edgeColor); + + else + switch edgeColor + + case 'none' + + lineColor = 'rgba(0,0,0,0)'; + + case 'auto' + + % TODO + + case 'flat' + + cData = geoData.CData; + cMap = figureData.Colormap; + ncolors = size(cMap, 1); + + for m = 1:length(cData) + colorValue = max( min( cData(m), axisData.CLim(2) ), axisData.CLim(1) ); + scaleFactor = (colorValue - axisData.CLim(1)) / diff(axisData.CLim); + rgbColor = 255 * cMap( 1+floor(scaleFactor*(ncolors-1)), : ); + lineColor{m} = sprintf('rgb(%f,%f,%f)', rgbColor); + end + + end + end + + if filledMarker + marker.line.color = lineColor; + else + marker.color = lineColor; + end + + %-------------------------------------------------------------------------% + +end