@@ -238,12 +238,30 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
238238 });
239239 }
240240 else {
241-
242- // Use the clusters set for points color
243- dropRegions << new DropWidget::DropRegion (this , " Color" , description, " palette" , true , [this , candidateDataset]() {
244- _settingsAction.getColoringAction ().addColorDataset (candidateDataset);
245- _settingsAction.getColoringAction ().setCurrentColorDataset (candidateDataset);
246- });
241+ if (candidateDataset.isValid ())
242+ {
243+ // Check to set whether the number of data points comprised throughout all clusters is the same number
244+ // as the number of data points in the dataset we are trying to color
245+ int totalNumIndices = 0 ;
246+ for (const Cluster& cluster : candidateDataset->getClusters ())
247+ {
248+ totalNumIndices += cluster.getIndices ().size ();
249+ }
250+
251+ if (totalNumIndices == _positionDataset->getNumPoints ())
252+ {
253+ // Use the clusters set for points color
254+ dropRegions << new DropWidget::DropRegion (this , " Color" , description, " palette" , true , [this , candidateDataset]() {
255+ _settingsAction.getColoringAction ().addColorDataset (candidateDataset);
256+ _settingsAction.getColoringAction ().setCurrentColorDataset (candidateDataset);
257+ });
258+ }
259+ else
260+ {
261+ // Number of indices in clusters doesn't match point dataset
262+ dropRegions << new DropWidget::DropRegion (this , " Incompatible data" , " Cluster data does not match number of data points" , " exclamation-circle" , false );
263+ }
264+ }
247265 }
248266 }
249267 else {
@@ -264,8 +282,6 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
264282 getLearningCenterAction ().addVideos (QStringList ({ " Practitioner" , " Developer" }));
265283
266284 setOverlayActionsTargetWidget (_scatterPlotWidget);
267-
268-
269285}
270286
271287ScatterplotPlugin::~ScatterplotPlugin ()
@@ -397,6 +413,10 @@ void ScatterplotPlugin::init()
397413 connect (&_settingsAction.getColoringAction ().getColorByAction (), &OptionAction::currentIndexChanged, this , &ScatterplotPlugin::updateHeadsUpDisplay);
398414 connect (&_settingsAction.getPlotAction ().getPointPlotAction ().getSizeAction (), &ScalarAction::sourceDataChanged, this , &ScatterplotPlugin::updateHeadsUpDisplay);
399415 connect (&_settingsAction.getPlotAction ().getPointPlotAction ().getOpacityAction (), &ScalarAction::sourceDataChanged, this , &ScatterplotPlugin::updateHeadsUpDisplay);
416+
417+ updateHeadsUpDisplayTextColor ();
418+
419+ connect (&_settingsAction.getMiscellaneousAction ().getBackgroundColorAction (), &ColorAction::colorChanged, this , &ScatterplotPlugin::updateHeadsUpDisplayTextColor);
400420}
401421
402422void ScatterplotPlugin::loadData (const Datasets& datasets)
@@ -816,25 +836,24 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
816836 if (!clusters.isValid () || !_positionDataset.isValid ())
817837 return ;
818838
819- // Mapping from local to global indices
820- std::vector<std::uint32_t > globalIndices;
821-
822839 // Get global indices from the position dataset
823840 int totalNumPoints = 0 ;
824841 if (_positionDataset->isDerivedData ())
825842 totalNumPoints = _positionSourceDataset->getFullDataset <Points>()->getNumPoints ();
826843 else
827844 totalNumPoints = _positionDataset->getFullDataset <Points>()->getNumPoints ();
828845
846+ // Mapping from local to global indices
847+ std::vector<std::uint32_t > globalIndices;
829848 _positionDataset->getGlobalIndices (globalIndices);
830849
831850 // Generate color buffer for global and local colors
832851 std::vector<Vector3f> globalColors (totalNumPoints);
833- std::vector<Vector3f> localColors (_positions. size () );
852+ std::vector<Vector3f> localColors (_numPoints );
834853
835854 const auto & clusterVec = clusters->getClusters ();
836855
837- if (totalNumPoints == _positions. size () && clusterVec.size () == totalNumPoints)
856+ if (totalNumPoints == _numPoints && clusterVec.size () == totalNumPoints)
838857 {
839858 for (size_t i = 0 ; i < static_cast <size_t >(clusterVec.size ()); i++)
840859 {
@@ -845,14 +864,15 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
845864 }
846865
847866 }
848- else
867+ else if (globalIndices. size () == _numPoints)
849868 {
850869 // Loop over all clusters and populate global colors
851870 for (const auto & cluster : clusterVec)
852871 {
853- const auto color = cluster.getColor ();
872+ const auto color = cluster.getColor ();
873+ const auto colVec = Vector3f (color.redF (), color.greenF (), color.blueF ());
854874 for (const auto & index : cluster.getIndices ())
855- globalColors[index] = Vector3f (color. redF (), color. greenF (), color. blueF ()) ;
875+ globalColors[index] = colVec ;
856876
857877 }
858878
@@ -1017,6 +1037,19 @@ void ScatterplotPlugin::updateHeadsUpDisplay()
10171037 }
10181038}
10191039
1040+ void ScatterplotPlugin::updateHeadsUpDisplayTextColor ()
1041+ {
1042+ if (auto headsUpDisplayWidget = getWidget ().findChild <QWidget*>(" HeadsUpDisplayWidget" )) {
1043+ if (auto headsUpDisplayWidgetTreeView = headsUpDisplayWidget->findChild <QTreeView*>(" TreeView" )) {
1044+ QPalette palette = headsUpDisplayWidgetTreeView->palette ();
1045+
1046+ palette.setColor (QPalette::Text, _settingsAction.getMiscellaneousAction ().getBackgroundColorAction ().getColor ().lightnessF () > .5f ? Qt::black : Qt::white);
1047+
1048+ headsUpDisplayWidgetTreeView->setPalette (palette);
1049+ }
1050+ }
1051+ }
1052+
10201053void ScatterplotPlugin::fromVariantMap (const QVariantMap& variantMap)
10211054{
10221055 ViewPlugin::fromVariantMap (variantMap);
@@ -1038,6 +1071,8 @@ void ScatterplotPlugin::fromVariantMap(const QVariantMap& variantMap)
10381071
10391072 _scatterPlotWidget->update ();
10401073 }
1074+
1075+ updateHeadsUpDisplayTextColor ();
10411076}
10421077
10431078QVariantMap ScatterplotPlugin::toVariantMap () const
0 commit comments