vtkChartBox.cxx 21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkChartBox.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkChartBox.h"

#include "vtkAnnotationLink.h"
#include "vtkAxis.h"
#include "vtkBrush.h"
#include "vtkCommand.h"
#include "vtkContext2D.h"
#include "vtkContextScene.h"
#include "vtkContextMapper2D.h"
#include "vtkContextMouseEvent.h"
#include "vtkDataArray.h"
#include "vtkIdTypeArray.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPen.h"
#include "vtkPlotBox.h"
#include "vtkPlotGrid.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
#include "vtkStringArray.h"
#include "vtkTable.h"
#include "vtkTextProperty.h"
#include "vtkTooltipItem.h"
#include "vtkTransform2D.h"

#include <algorithm>
#include <vector>


// Minimal storage class for STL containers etc.
class vtkChartBox::Private
{
public:
  Private()
    {
    this->Plot = vtkSmartPointer<vtkPlotBox>::New();
    this->YAxis->SetPosition(vtkAxis::LEFT);
    this->YAxis->SetPoint1(0, 0);
    this->YAxis->SetTitle("Y");
    }
  ~Private()
    {
    }
  vtkSmartPointer<vtkPlotBox> Plot;
  std::vector<float> XPosition;
  vtkNew<vtkTransform2D> Transform;
  vtkNew<vtkAxis> YAxis;
  vtkNew<vtkPlotGrid> Grid;
65
  float SelectedColumnDelta;
66 67 68 69 70 71 72 73 74 75 76 77
};

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkChartBox);

//-----------------------------------------------------------------------------
vtkChartBox::vtkChartBox()
{
  this->Storage = new vtkChartBox::Private;
  this->Storage->Plot->SetParent(this);
78
  this->AddItem(this->Storage->YAxis.GetPointer());
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
  this->GeometryValid = false;
  this->Selection = vtkIdTypeArray::New();
  this->SelectedColumn = -1;
  this->Storage->Plot->SetSelection(this->Selection);
  this->VisibleColumns = vtkStringArray::New();

  this->Tooltip = vtkSmartPointer<vtkTooltipItem>::New();
  this->Tooltip->SetVisible(false);
  this->AddItem(this->Tooltip);

  // Set up default mouse button assignments for parallel coordinates.
  this->SetActionToButton(vtkChart::PAN, vtkContextMouseEvent::RIGHT_BUTTON);
  this->SetActionToButton(vtkChart::SELECT, vtkContextMouseEvent::LEFT_BUTTON);
}

//-----------------------------------------------------------------------------
vtkChartBox::~vtkChartBox()
{
  this->Storage->Plot->SetSelection(NULL);
  delete this->Storage;
  this->Selection->Delete();
  this->VisibleColumns->Delete();
}

//-----------------------------------------------------------------------------
void vtkChartBox::Update()
{
  vtkTable* table = this->Storage->Plot->GetData()->GetInput();
  if (!table)
    {
    return;
    }

  if (table->GetMTime() < this->BuildTime && this->MTime < this->BuildTime)
  {
    return;
  }

  int nbCols = this->VisibleColumns->GetNumberOfTuples();

  this->Storage->XPosition.resize(nbCols);

  double grange[2] = { VTK_DOUBLE_MAX, VTK_DOUBLE_MIN };
  // Now set up their ranges and locations
  for (int i = 0; i < nbCols; ++i)
    {
    vtkDataArray* array =
126
      vtkArrayDownCast<vtkDataArray>(table->GetColumnByName(
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    this->VisibleColumns->GetValue(i)));
    if (array)
      {
      double range[2];
      array->GetRange(range);
      if (range[0] < grange[0])
        {
        grange[0] = range[0];
        }
      if (range[1] > grange[1])
        {
        grange[1] = range[1];
        }
      }
    }

  this->Storage->YAxis->SetMinimum(grange[0]);
  this->Storage->YAxis->SetMaximum(grange[1]);

  this->GeometryValid = false;
  this->BuildTime.Modified();
}

//-----------------------------------------------------------------------------
bool vtkChartBox::Paint(vtkContext2D *painter)
{
  if (this->GetScene()->GetViewWidth() == 0 ||
      this->GetScene()->GetViewHeight() == 0 ||
      !this->Visible || !this->Storage->Plot->GetVisible() ||
      this->VisibleColumns->GetNumberOfTuples() < 1)
    {
    // The geometry of the chart must be valid before anything can be drawn
    return false;
    }

162
  //this->UpdateGeometry(painter);
163
  this->Update();
164
  this->UpdateGeometry(painter);
165 166 167 168 169 170 171 172 173 174

  // Handle selections
  vtkIdTypeArray *idArray = 0;
  if (this->AnnotationLink)
    {
    vtkSelection *selection = this->AnnotationLink->GetCurrentSelection();
    if (selection->GetNumberOfNodes() &&
        this->AnnotationLink->GetMTime() > this->Storage->Plot->GetMTime())
      {
      vtkSelectionNode *node = selection->GetNode(0);
175
      idArray = vtkArrayDownCast<vtkIdTypeArray>(node->GetSelectionList());
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
      this->Storage->Plot->SetSelection(idArray);
      }
    }
  else
    {
    vtkDebugMacro("No annotation link set.");
    }

  painter->PushMatrix();
  painter->SetTransform(this->Storage->Transform.GetPointer());
  this->Storage->Plot->Paint(painter);
  painter->PopMatrix();

  this->Storage->YAxis->Paint(painter);

  if (this->GetShowLegend())
    {
    vtkRectf rect;
    rect.Set(0, 2, 10, 20);
    this->Storage->Plot->PaintLegend(painter, rect, 0);
    }

  if (this->Tooltip && this->Tooltip->GetVisible())
    {
    this->Tooltip->Paint(painter);
    }

  return true;
}

//-----------------------------------------------------------------------------
void vtkChartBox::SetColumnVisibility(const vtkStdString& name,
                                      bool visible)
{
  if (visible)
    {
    for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i)
      {
      if (this->VisibleColumns->GetValue(i) == name)
        {
        // Already there, nothing more needs to be done
        return;
        }
      }
    // Add the column to the end of the list
    this->VisibleColumns->InsertNextValue(name);
    this->Modified();
    this->Update();
    }
  else
    {
    // Remove the value if present
    for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i)
      {
      if (this->VisibleColumns->GetValue(i) == name)
        {
        // Move all the later elements down by one, and reduce the size
        while (i < this->VisibleColumns->GetNumberOfTuples()-1)
          {
          this->VisibleColumns->SetValue(i, this->VisibleColumns->GetValue(i+1));
          ++i;
          }
        this->VisibleColumns->SetNumberOfTuples(
            this->VisibleColumns->GetNumberOfTuples()-1);
        if (this->SelectedColumn >= this->VisibleColumns->GetNumberOfTuples())
          {
          this->SelectedColumn = -1;
          }
        this->Modified();
        this->Update();
        return;
        }
      }
    }
}

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
//-----------------------------------------------------------------------------
void vtkChartBox::SetColumnVisibility(vtkIdType column, bool visible)
{
  vtkPlot *plot = this->GetPlot(0);
  if (!plot || !plot->GetInput())
    {
    return;
    }
  vtkTable *table = plot->GetInput();
  if (table)
    {
    this->SetColumnVisibility(table->GetColumnName(column), visible);
    }
}

267 268 269 270 271 272 273 274
//-----------------------------------------------------------------------------
void vtkChartBox::SetColumnVisibilityAll(bool visible)
{
  // We always need to clear the current visible columns.
  this->VisibleColumns->SetNumberOfTuples(0);
  this->SelectedColumn = -1;
  if (visible)
    {
275 276 277 278 279 280
    vtkPlot *plot = this->GetPlot(0);
    if (!plot || !plot->GetInput())
      {
      return;
      }
    vtkTable *table = plot->GetInput();
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
    for (vtkIdType i = 0; i < table->GetNumberOfColumns(); ++i)
      {
      this->SetColumnVisibility(table->GetColumnName(i), visible);
      }
    }
}

//-----------------------------------------------------------------------------
bool vtkChartBox::GetColumnVisibility(const vtkStdString& name)
{
  for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i)
    {
    if (this->VisibleColumns->GetValue(i) == name)
      {
      return true;
      }
    }
  return false;
}

301 302 303 304 305 306 307 308 309 310 311 312
//-----------------------------------------------------------------------------
bool vtkChartBox::GetColumnVisibility(vtkIdType column)
{
  vtkPlot *plot = this->GetPlot(0);
  if (!plot || !plot->GetInput())
    {
    return false;
    }
  vtkTable *table = plot->GetInput();
  return this->GetColumnVisibility(table->GetColumnName(column));
}

313 314 315 316 317 318
//-----------------------------------------------------------------------------
vtkIdType vtkChartBox::GetNumberOfVisibleColumns()
{
  return this->VisibleColumns->GetNumberOfTuples();
}

319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
//-----------------------------------------------------------------------------
vtkIdType vtkChartBox::GetColumnId(const vtkStdString& name)
{
  vtkPlot *plot = this->GetPlot(0);
  if (!plot || !plot->GetInput())
    {
    return -1;
    }
  vtkTable *table = plot->GetInput();
  vtkIdType nbColumn = table->GetNumberOfColumns();
  for (vtkIdType i = 0; i < nbColumn; i++)
    {
    if (!strcmp(table->GetColumnName(i), name.c_str()))
      {
      return i;
      }
    }
  return -1;
}

339 340 341 342 343 344 345 346 347 348 349
//-----------------------------------------------------------------------------
vtkAxis* vtkChartBox::GetYAxis()
{
  return this->Storage->YAxis.GetPointer();
}

//-----------------------------------------------------------------------------
void vtkChartBox::SetPlot(vtkPlotBox *plot)
{
  this->Storage->Plot = plot;
  this->Storage->Plot->SetParent(this);
350
  this->Modified();
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
}

//-----------------------------------------------------------------------------
vtkPlot* vtkChartBox::GetPlot(vtkIdType)
{
  return this->Storage->Plot;
}

//-----------------------------------------------------------------------------
vtkIdType vtkChartBox::GetNumberOfPlots()
{
  return 1;
}

//-----------------------------------------------------------------------------
float vtkChartBox::GetXPosition(int index)
{
  return (index < static_cast<int>(this->Storage->XPosition.size())) ?
    this->Storage->XPosition[index] : 0;
}

//-----------------------------------------------------------------------------
373
void vtkChartBox::UpdateGeometry(vtkContext2D* painter)
374 375 376 377 378 379 380
{
  vtkVector2i geometry(this->GetScene()->GetViewWidth(),
                       this->GetScene()->GetViewHeight());

  if (geometry.GetX() != this->Geometry[0] ||
    geometry.GetY() != this->Geometry[1] || !this->GeometryValid)
    {
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
    vtkAxis* axis = this->Storage->YAxis.GetPointer();

    axis->SetPoint1(0, this->Point1[1]);
    axis->SetPoint2(0, this->Point2[1]);
    if (axis->GetBehavior() == 0)
      {
      axis->AutoScale();
      }
    axis->Update();

    int leftBorder = 0;
    if (axis->GetVisible())
      {
      vtkRectf bounds = axis->GetBoundingRect(painter);
      leftBorder = int(bounds.GetWidth());;
      }
    axis->SetPoint1(leftBorder, this->Point1[1]);
    axis->SetPoint2(leftBorder, this->Point2[1]);

400 401
    // Take up the entire window right now, this could be made configurable
    this->SetGeometry(geometry.GetData());
402 403 404 405

    vtkVector2i tileScale = this->Scene->GetLogicalTileScale();
    this->SetBorders(leftBorder, 30 * tileScale.GetY(),
                     0, 20 * tileScale.GetY());
406

407
    int nbPlots = static_cast<int>(this->Storage->XPosition.size());
408
    // Iterate through the axes and set them up to span the chart area.
409
    int xStep = (this->Point2[0] - this->Point1[0]) / nbPlots;
410 411
    int x = this->Point1[0] + (xStep / 2);

412
    for (int i = 0; i < nbPlots; ++i)
413 414 415 416 417 418
      {
      this->Storage->XPosition[i] = x;

      x += xStep;
      }
    this->GeometryValid = true;
419

420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
    // Cause the plot transform to be recalculated if necessary
    this->CalculatePlotTransform();

    if (this->VisibleColumns->GetNumberOfValues() > 1)
      {
      this->Storage->Plot->SetBoxWidth(0.5f *
        (this->GetXPosition(1) - this->GetXPosition(0)));
      }

    this->Storage->Plot->Update();
    }
}

//-----------------------------------------------------------------------------
void vtkChartBox::CalculatePlotTransform()
{
  // In the case of box plots everything is plotted in a normalized
  // system, where the range is from 0.0 to 1.0 in the y axis, and in screen
  // coordinates along the x axis.
  vtkAxis* axis = this->Storage->YAxis.GetPointer();
  float *min = axis->GetPoint1();
  float *max = axis->GetPoint2();
  float yScale = 1.0f / (max[1] - min[1]);

  this->Storage->Transform->Identity();
  this->Storage->Transform->Translate(0, axis->GetPoint1()[1]);
  // Get the scale for the plot area from the x and y axes
  this->Storage->Transform->Scale(1.0, 1.0 / yScale);
}

//-----------------------------------------------------------------------------
bool vtkChartBox::Hit(const vtkContextMouseEvent &mouse)
{
  vtkVector2i pos(mouse.GetScreenPos());
  float width = this->Storage->Plot->GetBoxWidth() / 2.f;
  return
    pos[0] > this->Point1[0] - width &&
    pos[0] < this->Point2[0] + width &&
    pos[1] > this->Point1[1] &&
    pos[1] < this->Point2[1];
}

//-----------------------------------------------------------------------------
bool vtkChartBox::MouseMoveEvent(const vtkContextMouseEvent &mouse)
{
  if (mouse.GetButton() == this->Actions.Pan() && this->SelectedColumn >= 0)
    {
    if (this->Tooltip)
      {
      this->Tooltip->SetVisible(false);
      }

472 473 474
    // Move the plot in x
    float posX = mouse.GetScenePos().GetX() + this->SelectedColumnDelta;
    this->Storage->XPosition[this->SelectedColumn] = posX;
475 476 477 478 479 480 481

    int nbCols = static_cast<int>(this->Storage->XPosition.size());
    int left = this->SelectedColumn - 1;
    int right = this->SelectedColumn + 1;

    float width = this->Storage->Plot->GetBoxWidth() * 0.5f;

482
    if (left >= 0 && (posX - width) < this->Storage->XPosition[left])
483 484 485 486
      {
      this->SwapAxes(this->SelectedColumn, this->SelectedColumn - 1);
      this->SelectedColumn--;
      }
487
    else if (right < nbCols && (posX + width) > this->Storage->XPosition[right])
488 489 490 491 492
      {
      this->SwapAxes(this->SelectedColumn, this->SelectedColumn + 1);
      this->SelectedColumn++;
      }
    this->Scene->SetDirty(true);
493
    this->Storage->XPosition[this->SelectedColumn] = posX;
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
    }

  if (mouse.GetButton() == vtkContextMouseEvent::NO_BUTTON)
    {
    this->Scene->SetDirty(true);

    if (this->Tooltip)
      {
      this->Tooltip->SetVisible(this->LocatePointInPlots(mouse));
      }
    }
  return true;
}

//-----------------------------------------------------------------------------
bool vtkChartBox::MouseButtonPressEvent(const vtkContextMouseEvent& mouse)
{
  if (mouse.GetButton() == this->Actions.Pan())
    {
513
    // Select a plot if we are within range
514 515 516 517 518 519 520 521 522 523 524 525
    if (mouse.GetScenePos()[1] > this->Point1[1] &&
        mouse.GetScenePos()[1] < this->Point2[1])
      {
      // Iterate over the axes, see if we are within 10 pixels of an axis
      for (size_t i = 0; i < this->Storage->XPosition.size(); ++i)
        {
        float selX = this->Storage->XPosition[i];
        float width = this->Storage->Plot->GetBoxWidth() / 2.f;
        if (selX - width < mouse.GetScenePos()[0] &&
            selX + width > mouse.GetScenePos()[0])
          {
          this->SelectedColumn = static_cast<int>(i);
526 527
          this->SelectedColumnDelta =
            this->GetXPosition(this->SelectedColumn) - mouse.GetScenePos().GetX();
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
          this->Scene->SetDirty(true);
          return true;
          }
        }
      }
    this->SelectedColumn = -1;
    this->Scene->SetDirty(true);
    return true;
    }

  return false;
}

//-----------------------------------------------------------------------------
bool vtkChartBox::MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse)
{
  this->SelectedColumn = -1;
  if (mouse.GetButton() == this->Actions.Select())
    {
    if (this->SelectedColumn >= 0)
      {
      if (this->AnnotationLink)
        {
        vtkSelection* selection = vtkSelection::New();
        vtkSelectionNode* node = vtkSelectionNode::New();
        selection->AddNode(node);
        node->SetContentType(vtkSelectionNode::INDICES);
        node->SetFieldType(vtkSelectionNode::POINT);

        node->SetSelectionList(this->Storage->Plot->GetSelection());
        this->AnnotationLink->SetCurrentSelection(selection);
        selection->Delete();
        node->Delete();
        }
      this->InvokeEvent(vtkCommand::SelectionChangedEvent);
      this->Scene->SetDirty(true);
      }
    return true;
    }
  else if (mouse.GetButton() == this->Actions.Pan())
    {
    this->GeometryValid = false;
    this->SelectedColumn = -1;
    return true;
    }
  this->Scene->SetDirty(true);
  return true;
}

//-----------------------------------------------------------------------------
int vtkChartBox::LocatePointInPlot(const vtkVector2f &position,
                                   const vtkVector2f &tolerance,
                                   vtkVector2f &plotPos,
                                   vtkPlot *plot,
                                   vtkIdType &)
{
  if (plot && plot->GetVisible())
    {
    vtkPlotBox* plotBar = vtkPlotBox::SafeDownCast(plot);
    if (plotBar)
      {
      // If the plot is a vtkPlotBar, get the segment index too
      return plotBar->GetNearestPoint(position, tolerance,
                                      &plotPos);
      }
    else
      {
      return plot->GetNearestPoint(position, tolerance, &plotPos);
      }
    }
  return -1;
}

//-----------------------------------------------------------------------------
bool vtkChartBox::LocatePointInPlots(const vtkContextMouseEvent &mouse,
                                     int invokeEvent)
{
  vtkVector2i pos(mouse.GetScreenPos());
  if (pos[0] > this->Point1[0] &&
      pos[0] < this->Point2[0] &&
      pos[1] > this->Point1[1] &&
      pos[1] < this->Point2[1])
    {
    vtkVector2f plotPos, position;
    vtkTransform2D* transform =
      this->Storage->Transform.GetPointer();
    transform->InverseTransformPoints(mouse.GetPos().GetData(),
      position.GetData(), 1);
    // Use a tolerance of +/- 5 pixels
    vtkVector2f tolerance(5*(1.0/transform->GetMatrix()->GetElement(0, 0)),
      5*(1.0/transform->GetMatrix()->GetElement(1, 1)));

    vtkPlot* plot = this->Storage->Plot.GetPointer();
621
    vtkIdType segmentIndex = -1;
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
    int seriesIndex =
      LocatePointInPlot(position, tolerance, plotPos, plot, segmentIndex);

    if (seriesIndex >= 0)
      {
      // We found a point, set up the tooltip and return
      vtkRectd ss(plot->GetShiftScale());
      vtkVector2d plotPosd(plotPos[0] / ss[2] - ss[0],
        plotPos[1] / ss[3] - ss[1]);
      this->SetTooltipInfo(mouse, plotPosd, seriesIndex, plot,
        segmentIndex);
      if (invokeEvent >= 0)
        {
        vtkChartBoxData plotIndex;
        plotIndex.SeriesName =
          this->GetVisibleColumns()->GetValue(seriesIndex);
        plotIndex.Position = plotPos;
        plotIndex.ScreenPosition = mouse.GetScreenPos();
Ben Boeckel's avatar
Ben Boeckel committed
640
        plotIndex.Index = segmentIndex;
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
        // Invoke an event, with the client data supplied
        this->InvokeEvent(invokeEvent, static_cast<void*>(&plotIndex));
        }
      return true;
      }
    }
  return false;
}

//-----------------------------------------------------------------------------
void vtkChartBox::SetTooltip(vtkTooltipItem *tooltip)
{
  if (tooltip == this->Tooltip)
    {
    // nothing to change
    return;
    }

  if (this->Tooltip)
    {
    // remove current tooltip from scene
    this->RemoveItem(this->Tooltip);
    }

  this->Tooltip = tooltip;

  if (this->Tooltip)
    {
    // add new tooltip to scene
    this->AddItem(this->Tooltip);
    }
}

//-----------------------------------------------------------------------------
vtkTooltipItem* vtkChartBox::GetTooltip()
{
  return this->Tooltip;
}

//-----------------------------------------------------------------------------
void vtkChartBox::SetTooltipInfo(const vtkContextMouseEvent& mouse,
                                 const vtkVector2d &plotPos,
                                 vtkIdType seriesIndex, vtkPlot* plot,
                                 vtkIdType segmentIndex)
{
  if (!this->Tooltip)
    {
    return;
    }

  // Have the plot generate its tooltip label
  vtkStdString tooltipLabel = plot->GetTooltipLabel(plotPos, seriesIndex,
                                                    segmentIndex);

  // Set the tooltip
  this->Tooltip->SetText(tooltipLabel);
  this->Tooltip->SetPosition(mouse.GetScreenPos()[0] + 2,
                             mouse.GetScreenPos()[1] + 2);
}

//-----------------------------------------------------------------------------
void vtkChartBox::PrintSelf(ostream &os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}

//-----------------------------------------------------------------------------
void vtkChartBox::SwapAxes(int a1, int a2)
{
  vtkStdString colTmp = this->VisibleColumns->GetValue(a1);
  this->VisibleColumns->SetValue(a1, this->VisibleColumns->GetValue(a2));
  this->VisibleColumns->SetValue(a2, colTmp);

714 715 716 717 718 719
  int xStep = (this->Point2[0] - this->Point1[0]) /
                (static_cast<int>(this->Storage->XPosition.size()));
  int xPos = (this->Point1[0] + (xStep / 2)) + xStep * a1;
  this->Storage->XPosition[a1] = xPos;

  this->GeometryValid = true;
720 721 722

  this->Storage->Plot->Update();
}