------------------------------------------------------------------------------
| 1065 | |
| 1066 | //------------------------------------------------------------------------------ |
| 1067 | bool vtkHeatmapItem::MouseDoubleClickEvent(const vtkContextMouseEvent& event) |
| 1068 | { |
| 1069 | // get the position of the double click and convert it to scene coordinates |
| 1070 | double pos[3]; |
| 1071 | vtkNew<vtkMatrix3x3> inverse; |
| 1072 | pos[0] = event.GetPos().GetX(); |
| 1073 | pos[1] = event.GetPos().GetY(); |
| 1074 | pos[2] = 0; |
| 1075 | this->GetScene()->GetTransform()->GetInverse(inverse); |
| 1076 | inverse->MultiplyPoint(pos, pos); |
| 1077 | if (pos[0] <= this->MaxX && pos[0] >= this->MinX && pos[1] <= this->MaxY && pos[1] >= this->MinY) |
| 1078 | { |
| 1079 | vtkIdType column = 0; |
| 1080 | int orientation = this->GetOrientation(); |
| 1081 | if (orientation == vtkHeatmapItem::UP_TO_DOWN || orientation == vtkHeatmapItem::DOWN_TO_UP) |
| 1082 | { |
| 1083 | column = static_cast<vtkIdType>(floor((pos[1] - this->MinY) / this->CellWidth)); |
| 1084 | } |
| 1085 | else |
| 1086 | { |
| 1087 | column = static_cast<vtkIdType>(floor((pos[0] - this->MinX) / this->CellWidth)); |
| 1088 | } |
| 1089 | ++column; |
| 1090 | |
| 1091 | if (!this->LegendPositionSet) |
| 1092 | { |
| 1093 | this->PositionLegends(this->GetOrientation()); |
| 1094 | } |
| 1095 | |
| 1096 | if (this->Table->GetValue(0, column).IsString()) |
| 1097 | { |
| 1098 | // categorical data |
| 1099 | // generate an array of distinct values from this column |
| 1100 | vtkStringArray* stringColumn = |
| 1101 | vtkArrayDownCast<vtkStringArray>(this->Table->GetColumn(column)); |
| 1102 | this->CategoryLegendValues->Reset(); |
| 1103 | this->CategoryLegendValues->Squeeze(); |
| 1104 | stringColumn->SetMaxDiscreteValues(stringColumn->GetNumberOfTuples() - 1); |
| 1105 | stringColumn->GetProminentComponentValues(0, this->CategoryLegendValues); |
| 1106 | this->CategoryLegendValues->Modified(); |
| 1107 | |
| 1108 | // these distinct values become the input to our categorical legend |
| 1109 | this->CategoryLegend->SetValues(this->CategoryLegendValues); |
| 1110 | this->CategoryLegend->SetTitle(this->Table->GetColumn(column)->GetName()); |
| 1111 | this->CategoryLegend->SetVisible(true); |
| 1112 | this->ColorLegend->SetVisible(false); |
| 1113 | this->Scene->SetDirty(true); |
| 1114 | return true; |
| 1115 | } |
| 1116 | else |
| 1117 | { |
| 1118 | // continuous data |
| 1119 | // set up the scalar bar legend |
| 1120 | this->ColorLegend->GetTransferFunction()->SetRange( |
| 1121 | this->ColumnRanges[column].first, this->ColumnRanges[column].second); |
| 1122 | |
| 1123 | this->ColorLegend->SetTitle(this->Table->GetColumn(column)->GetName()); |
| 1124 |