diff options
author | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-12-04 13:19:11 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-12-04 13:19:11 +0000 |
commit | 25b8d94d705e820fc755385c3bdb89f764939945 (patch) | |
tree | b4d07639eb812e1b3f62e126b48b0d55e5b40864 /storage | |
parent | 952a877611d657cfa0166b14699c8731b18f7587 (diff) |
Remove unused (and not working) graphing utilities
Diffstat (limited to 'storage')
-rw-r--r-- | storage/CMakeLists.txt | 1 | ||||
-rw-r--r-- | storage/src/tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | storage/src/tests/storageutil/.gitignore | 13 | ||||
-rw-r--r-- | storage/src/tests/storageutil/CMakeLists.txt | 9 | ||||
-rw-r--r-- | storage/src/tests/storageutil/charttest.cpp | 61 | ||||
-rw-r--r-- | storage/src/tests/storageutil/functortest.cpp | 54 | ||||
-rw-r--r-- | storage/src/tests/storageutil/palettetest.cpp | 29 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageutil/CMakeLists.txt | 3 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageutil/functor.h | 60 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageutil/graph.cpp | 206 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageutil/graph.h | 99 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageutil/palette.cpp | 110 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageutil/palette.h | 32 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageutil/piechart.cpp | 201 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageutil/piechart.h | 66 |
15 files changed, 0 insertions, 945 deletions
diff --git a/storage/CMakeLists.txt b/storage/CMakeLists.txt index 5c24d4adb3b..269785d629e 100644 --- a/storage/CMakeLists.txt +++ b/storage/CMakeLists.txt @@ -64,6 +64,5 @@ vespa_define_module( src/tests/persistence/common src/tests/persistence/filestorage src/tests/storageserver - src/tests/storageutil src/tests/visiting ) diff --git a/storage/src/tests/CMakeLists.txt b/storage/src/tests/CMakeLists.txt index 9962949edde..a0264bf2946 100644 --- a/storage/src/tests/CMakeLists.txt +++ b/storage/src/tests/CMakeLists.txt @@ -5,7 +5,6 @@ vespa_add_executable(storage_testrunner_app TEST DEPENDS storage_teststorageserver storage_testbucketmover - storage_teststorageutil storage_testvisiting storage_testbucketdb storage_testcommon diff --git a/storage/src/tests/storageutil/.gitignore b/storage/src/tests/storageutil/.gitignore deleted file mode 100644 index a080232d5f3..00000000000 --- a/storage/src/tests/storageutil/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -*.So -*.lo -*.o -.*.swp -.config.log -.depend -.depend.NEW -.deps -.libs -Makefile -statefile* -testrunner -testrunner.core diff --git a/storage/src/tests/storageutil/CMakeLists.txt b/storage/src/tests/storageutil/CMakeLists.txt deleted file mode 100644 index 68d2517bda3..00000000000 --- a/storage/src/tests/storageutil/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_library(storage_teststorageutil TEST - SOURCES - charttest.cpp - functortest.cpp - palettetest.cpp - DEPENDS - storage -) diff --git a/storage/src/tests/storageutil/charttest.cpp b/storage/src/tests/storageutil/charttest.cpp deleted file mode 100644 index d16f3f11747..00000000000 --- a/storage/src/tests/storageutil/charttest.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/storage/storageutil/piechart.h> -#include <vespa/vdstestlib/cppunit/macros.h> -#include <fstream> - -namespace storage { - -struct PieChartTest : public CppUnit::TestFixture -{ - void testWriteHtmlFile(); - - CPPUNIT_TEST_SUITE(PieChartTest); - CPPUNIT_TEST(testWriteHtmlFile); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(PieChartTest); - -namespace { - void printHtmlFile(const std::string& filename, const PieChart& chart) { - std::ofstream out(filename.c_str()); - out << "<html>\n" - << " <head>\n" - << " "; - PieChart::printHtmlHeadAdditions(out, " "); - out << "\n <title>Pie example</title>\n" - << " </head>\n" - << " <body>\n" - << " "; - chart.printCanvas(out, 500, 400); - out << "\n "; - chart.printScript(out, " "); - out << "\n </body>\n" - << "</html>\n"; - out.close(); - } -} - -void -PieChartTest::testWriteHtmlFile() -{ - { - PieChart chart("mypie"); - chart.add(10, "put"); - chart.add(20, "get"); - chart.add(50, "free"); - - printHtmlFile("piefile.html", chart); - } - { - PieChart chart("mypie", PieChart::SCHEME_CUSTOM); - chart.add(10, "put", PieChart::RED); - chart.add(20, "get", PieChart::GREEN); - chart.add(50, "free", PieChart::BLUE); - - printHtmlFile("piefile-customcols.html", chart); - } -} - -} // storage diff --git a/storage/src/tests/storageutil/functortest.cpp b/storage/src/tests/storageutil/functortest.cpp deleted file mode 100644 index 0fa1eeaaa8a..00000000000 --- a/storage/src/tests/storageutil/functortest.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <cppunit/extensions/HelperMacros.h> -#include <list> -#include <string> -#include <algorithm> -#include <vespa/storage/storageutil/functor.h> - -class Functor_Test : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(Functor_Test); - CPPUNIT_TEST(testReplace); - CPPUNIT_TEST(testDeletePointer); - CPPUNIT_TEST_SUITE_END(); - -public: - -protected: - void testReplace(); - void testDeletePointer(); -}; - -using namespace storage; -using namespace std; - -CPPUNIT_TEST_SUITE_REGISTRATION(Functor_Test); - -void Functor_Test::testReplace() -{ - string source("this.is.a.string.with.many.dots."); - for_each(source.begin(), source.end(), Functor::Replace<char>('.', '_')); - CPPUNIT_ASSERT_EQUAL(string("this_is_a_string_with_many_dots_"), source); -} - -namespace { - - static int instanceCounter = 0; - - class TestClass { - public: - TestClass() { instanceCounter++; } - ~TestClass() { instanceCounter--; } - }; -} - -void Functor_Test::testDeletePointer() -{ - list<TestClass*> mylist; - mylist.push_back(new TestClass()); - mylist.push_back(new TestClass()); - mylist.push_back(new TestClass()); - CPPUNIT_ASSERT_EQUAL(3, instanceCounter); - for_each(mylist.begin(), mylist.end(), Functor::DeletePointer()); - CPPUNIT_ASSERT_EQUAL(0, instanceCounter); -} diff --git a/storage/src/tests/storageutil/palettetest.cpp b/storage/src/tests/storageutil/palettetest.cpp deleted file mode 100644 index a5d1b7f8b22..00000000000 --- a/storage/src/tests/storageutil/palettetest.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/storage/storageutil/palette.h> -#include <vespa/vdstestlib/cppunit/macros.h> - -namespace storage { - -struct PaletteTest : public CppUnit::TestFixture { - void testNormalUsage(); - - CPPUNIT_TEST_SUITE(PaletteTest); - CPPUNIT_TEST(testNormalUsage); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(PaletteTest); - -void -PaletteTest::testNormalUsage() -{ - std::ofstream out("palette.html"); - out << "<html><body>\n"; - Palette palette(75); - palette.printHtmlTablePalette(out); - out << "</body></html>\n"; - out.close(); -} - -} // storage diff --git a/storage/src/vespa/storage/storageutil/CMakeLists.txt b/storage/src/vespa/storage/storageutil/CMakeLists.txt index 6317465ab8e..df942a049fb 100644 --- a/storage/src/vespa/storage/storageutil/CMakeLists.txt +++ b/storage/src/vespa/storage/storageutil/CMakeLists.txt @@ -2,9 +2,6 @@ vespa_add_library(storage_storageutil OBJECT SOURCES bloomfilter.cpp - graph.cpp - palette.cpp - piechart.cpp DEPENDS AFTER storage_storageconfig diff --git a/storage/src/vespa/storage/storageutil/functor.h b/storage/src/vespa/storage/storageutil/functor.h deleted file mode 100644 index 4ca6b4bf926..00000000000 --- a/storage/src/vespa/storage/storageutil/functor.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** - * @ingroup storageutil - * - * @brief Functors ards storage, not dependent on external messaging. - * - * @author H�kon Humberset - * @date 2005-05-13 - * @version $Id$ - */ - -#pragma once - -namespace storage { - -class Functor { -public: - - /** - * For instance, using this functor you can say: - * - * string mystring("this is a test"); - * for_each(mystring.begin(), mystring.end(), - * Functor.Replace<char>(' ', '_')); - * - * or - * - * vector<string> myvector; - * for_each(myvector.begin(), myvector.end(), - * Functor.Replace<string>("this", "that")); - */ - template<class T> - class Replace { - private: - const T& _what; - const T& _with; - - public: - Replace(const T& what, const T& with) - : _what(what), - _with(with) {} - - void operator()(T& element) const - { if (element == _what) element = _with; } - }; - - /** - * To easily delete containers of pointers. - * - * for_each(myvec.begin(), myvec.end(), Functor::DeletePointer()); - */ - class DeletePointer { - public: - template<class T> void operator()(T *ptr) const { delete ptr; } - }; - -}; - -} - diff --git a/storage/src/vespa/storage/storageutil/graph.cpp b/storage/src/vespa/storage/storageutil/graph.cpp deleted file mode 100644 index 391d5c14c66..00000000000 --- a/storage/src/vespa/storage/storageutil/graph.cpp +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "graph.h" -#include <vespa/vespalib/util/exceptions.h> -#include <iomanip> - -namespace storage { - -Graph::Entry::Entry(const std::vector<Point>& v, const std::string& name, int32_t col) - : points(v), - _name(name), - _color(col) -{} - - Graph::Entry::~Entry() {} - -void -Graph::printHtmlHeadAdditions(std::ostream& out, const std::string& indent) -{ - (void) out; - (void) indent; - // FIXME this used to reference Yahoo-internal JS URIs -} - -Graph::Graph(const std::string& name, ColorScheme cs) - : _name(name), - _graphs(), - _colors(cs), - _leftPad(50), - _rightPad(0), - _topPad(0), - _bottomPad(0) -{} - -Graph::~Graph() {} - -void -Graph::add(const std::vector<Point>& values, const std::string& name) -{ - if (_colors == SCHEME_CUSTOM) { - throw vespalib::IllegalArgumentException( - "Using custom color scheme you need to supply a color for each " - "graph.", VESPA_STRLOC); - } - _graphs.push_back(Entry(values, name, UNDEFINED)); -} - -void -Graph::add(const std::vector<Point>& values, const std::string& name, Color c) -{ - if (_colors != SCHEME_CUSTOM) { - throw vespalib::IllegalArgumentException( - "Not using custom color scheme you cannot supply a custom " - "color for a graph.", VESPA_STRLOC); - } - _graphs.push_back(Entry(values, name, c)); -} - -void -Graph::add(const std::vector<Point>& values, const std::string& name, int32_t c) -{ - if (_colors != SCHEME_CUSTOM) { - throw vespalib::IllegalArgumentException( - "Not using custom color scheme you cannot supply a custom " - "color for a graph.", VESPA_STRLOC); - } - _graphs.push_back(Entry(values, name, (Color) c)); -} - -void -Graph::printCanvas(std::ostream& out, uint32_t width, uint32_t height) const -{ - out << "<div><canvas id=\"" << _name << "\" width=\"" << width - << "\" height=\"" << height << "\"/></div>"; -} - -namespace { - void printDatasetDefinition(std::ostream& o, const std::string& i, - const std::string& n, const std::vector<Graph::Entry>& e) - { - o << i << " var " << n << "_dataset = {\n" << std::dec; - bool first = true; - for (std::vector<Graph::Entry>::const_iterator it = e.begin(); - it != e.end(); ++it) - { - if (!first) o << ",\n"; - first = false; - o << i << " '" << it->_name << "': ["; - for (uint32_t j=0; j<it->points.size(); ++j) { - if (j != 0) o << ", "; - o << "[" << it->points[j].x << ", " << it->points[j].y << "]"; - } - o << "]"; - } - o << "\n" << i << " };"; - } - - void printCustomColorScheme(std::ostream& o, const std::string& i, - const std::string& n, const std::vector<Graph::Entry>& e) - { - o << " var " << n << "_customScheme = new Hash({\n" << std::hex; - bool first = true; - for (std::vector<Graph::Entry>::const_iterator it = e.begin(); - it != e.end(); ++it) - { - if (!first) o << ",\n"; - first = false; - o << i << " '" << it->_name << "': '#" << std::setw(6) - << std::setfill('0') << (it->_color & 0x00FFFFFF) << "'"; - } - o << "\n" << i << " });" << std::dec; - } - - void printOptions(std::ostream& o, const std::string& i, - const std::string& n, Graph::ColorScheme c, - const std::vector<Graph::Axis>& xAxis, - const std::vector<Graph::Axis>& yAxis, - uint32_t leftpad, uint32_t rightpad, - uint32_t toppad, uint32_t bottompad, - uint32_t legendXPos, uint32_t legendYPos) - { - o << " var " << n << "_options = {\n" - << i << " padding: {\n" - << i << " left: " << leftpad << ",\n" - << i << " right: " << rightpad << ",\n" - << i << " top: " << toppad << ",\n" - << i << " bottom: " << bottompad << ",\n" - << i << " },\n" - << i << " background: {\n" - << i << " color: '#ffffff'\n" - << i << " },\n" - << i << " shouldFill: true,\n"; - if (c == Graph::SCHEME_CUSTOM) { - o << i << " \"colorScheme\": " << n << "_customScheme,\n"; - } else { - o << i << " colorScheme: '"; - switch (c) { - case Graph::SCHEME_RED: o << "red"; break; - case Graph::SCHEME_BLUE: o << "blue"; break; - case Graph::SCHEME_CUSTOM: break; - } - o << "',\n"; - } - o << i << " legend: {\n" - << i << " opacity: 0.9,\n" - << i << " position: {\n" - << i << " top: " << legendYPos << ",\n" - << i << " left: " << legendXPos << "\n" - << i << " }\n" - << i << " },\n" - << i << " axis: {\n" - << i << " labelColor: '#000000',\n" - << i << " x: {\n"; - if (xAxis.size() > 0) { - o << i << " ticks: [\n"; - for (uint32_t j=0; j<xAxis.size(); ++j) { - o << i << " {v:" << xAxis[j].value << ", label:'" - << xAxis[j].name << "'},\n"; - } - o << i << " ]\n"; - } - o << i << " },\n" - << i << " y: {\n"; - if (yAxis.size() > 0) { - o << i << " ticks: [\n"; - for (uint32_t j=0; j<yAxis.size(); ++j) { - o << i << " {v:" << yAxis[j].value << ", label:'" - << yAxis[j].name << "'},\n"; - } - o << i << " ]\n"; - } - - o << i << " }\n" - << i << " }\n" - << i << " };"; - } - - void printChart(std::ostream& o, const std::string& i, const std::string& n) - { - o << " var " << n << "_chart = new Plotr.LineChart('" << n - << "', " << n << "_options);\n" - << i << " " << n << "_chart.addDataset(" << n << "_dataset);\n" - << i << " " << n << "_chart.render();"; - } -} - -void -Graph::printScript(std::ostream& out, const std::string& indent) const -{ - out << "<script type=\"text/javascript\">\n"; - printDatasetDefinition(out, indent, _name, _graphs); - if (_colors == SCHEME_CUSTOM) { - out << "\n" << indent; - printCustomColorScheme(out, indent, _name, _graphs); - } - out << "\n" << indent; - printOptions(out, indent, _name, _colors, _xAxis, _yAxis, - _leftPad, _rightPad, _topPad, _bottomPad, - _legendXPos, _legendYPos); - out << "\n" << indent; - printChart(out, indent, _name); - out << "\n" << indent << "</script>"; -} - -} // storage - diff --git a/storage/src/vespa/storage/storageutil/graph.h b/storage/src/vespa/storage/storageutil/graph.h deleted file mode 100644 index e39a0b59686..00000000000 --- a/storage/src/vespa/storage/storageutil/graph.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** - * \class storage::Graph - * \ingroup util - * - * \brief Helper library to print graphs in HTML. - */ - -#pragma once - -#include <string> -#include <vector> -#include <ostream> - -namespace storage { - -class Graph { -public: - enum ColorScheme { - SCHEME_CUSTOM, - SCHEME_RED, - SCHEME_BLUE - }; - enum Color { - UNDEFINED = -1, - BLACK = 0x000000, - RED = 0xFF0000, - GREEN = 0x00FF00, - BLUE = 0x0000FF, - WHITE = 0xFFFFFF, - YELLOW = 0xFFFF00 - }; - struct Point { - double x; - double y; - - Point(double x_, double y_) : x(x_), y(y_) {} - }; - struct Entry { - std::vector<Point> points; - std::string _name; - int32_t _color; - - Entry(const std::vector<Point>& v, const std::string& name, int32_t col); - Entry(Entry &&) = default; - Entry & operator = (Entry &&) = default; - ~Entry(); - }; - struct Axis { - double value; - std::string name; - - Axis(double val, const std::string& name_) : value(val), name(name_) {} - }; - - static void printHtmlHeadAdditions( - std::ostream& out, const std::string& indent = ""); - -private: - const std::string _name; - std::vector<Entry> _graphs; - ColorScheme _colors; - std::vector<Axis> _xAxis; - std::vector<Axis> _yAxis; - uint32_t _leftPad; - uint32_t _rightPad; - uint32_t _topPad; - uint32_t _bottomPad; - uint32_t _legendXPos; - uint32_t _legendYPos; - -public: - Graph(const std::string&, ColorScheme = SCHEME_BLUE); - ~Graph(); - - void add(const std::vector<Point>&, const std::string& name); - void add(const std::vector<Point>&, const std::string& name, Color c); - void add(const std::vector<Point>&, const std::string& name, int32_t color); - - void addXAxisLabel(double value, const std::string& name) - { _xAxis.push_back(Axis(value, name)); } - void addYAxisLabel(double value, const std::string& name) - { _yAxis.push_back(Axis(value, name)); } - - void setBorders(uint32_t left, uint32_t right, - uint32_t top, uint32_t bottom) - { - _leftPad = left; _rightPad = right; _topPad = top; _bottomPad = bottom; - } - - void setLegendPos(uint32_t left, uint32_t top) - { _legendXPos = left; _legendYPos = top; } - - void printCanvas(std::ostream& out, uint32_t width, uint32_t height) const; - void printScript(std::ostream& out, const std::string& indent = "") const; -}; - -} // storage - diff --git a/storage/src/vespa/storage/storageutil/palette.cpp b/storage/src/vespa/storage/storageutil/palette.cpp deleted file mode 100644 index 31e2f9e426c..00000000000 --- a/storage/src/vespa/storage/storageutil/palette.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "palette.h" - -#include <iostream> -#include <iomanip> - -namespace storage { - -namespace { - struct Col { - int16_t red; - int16_t green; - int16_t blue; - - Col(int16_t r, int16_t g, int16_t b) : red(r), green(g), blue(b) {} - }; - - std::vector<Col> createMainColors() { - std::vector<Col> v; - v.push_back(Col(128, 128, 128)); - v.push_back(Col(255, 0, 0)); - v.push_back(Col(255, 255, 0)); - v.push_back(Col(255, 0, 255)); - v.push_back(Col(0, 255, 0)); - v.push_back(Col(0, 255, 255)); - v.push_back(Col(0, 0, 255)); - v.push_back(Col(128, 64, 192)); - v.push_back(Col(192, 128, 64)); - v.push_back(Col(64, 192, 128)); - return v; - } - - std::vector<Col> mainColors(createMainColors()); -} - -Palette::Palette(uint32_t colorCount) -{ - - uint32_t variations = (colorCount + mainColors.size() - 1) - / (mainColors.size()); - int16_t darkvars = variations / 2; - int16_t lightvars = (variations - 1) / 2; - - std::vector<Col> darkVars; - if (darkvars > 0) { - for (int32_t i=darkvars; i>0; --i) { - for (uint32_t j=0; j<mainColors.size(); ++j) { - Col& main(mainColors[j]); - int rdiff = main.red / (darkvars + 1); - int gdiff = main.green / (darkvars + 1); - int bdiff = main.blue / (darkvars + 1); - darkVars.push_back(Col( - std::max(0, main.red - rdiff * i), - std::max(0, main.green - gdiff * i), - std::max(0, main.blue - bdiff * i))); - } - } - } - std::vector<Col> lightVars; - if (lightvars > 0) { - for (int32_t i=1; i<=lightvars; ++i) { - for (uint32_t j=0; j<mainColors.size(); ++j) { - Col& main(mainColors[j]); - int rdiff = (255 - main.red) / (lightvars + 1); - int gdiff = (255 - main.green) / (lightvars + 1); - int bdiff = (255 - main.blue) / (lightvars + 1); - lightVars.push_back(Col( - std::min(255, main.red + rdiff * i), - std::min(255, main.green + gdiff * i), - std::min(255, main.blue + bdiff * i))); - } - } - } - for (std::vector<Col>::const_iterator it = darkVars.begin(); - it != darkVars.end(); ++it) - { - _colors.push_back((it->red << 16) | (it->green << 8) | it->blue); - } - for (std::vector<Col>::const_iterator it = mainColors.begin(); - it != mainColors.end(); ++it) - { - _colors.push_back((it->red << 16) | (it->green << 8) | it->blue); - } - for (std::vector<Col>::const_iterator it = lightVars.begin(); - it != lightVars.end(); ++it) - { - _colors.push_back((it->red << 16) | (it->green << 8) | it->blue); - } -} - -void -Palette::printHtmlTablePalette(std::ostream& out) const -{ - out << "<table>" << std::hex << std::setfill('0'); - uint32_t col = 0; - while (col < _colors.size()) { - out << "\n<tr>"; - for (uint32_t i=0; i<mainColors.size(); ++i) { - out << "\n <td bgcolor=\"#" << std::setw(6) << _colors[col++] - << "\">"; - for (uint32_t j=0; j<6; ++j) out << " "; - out << "</td>"; - } - out << "\n</tr>"; - } - out << "\n</table>" << std::dec; -} - -} // storage diff --git a/storage/src/vespa/storage/storageutil/palette.h b/storage/src/vespa/storage/storageutil/palette.h deleted file mode 100644 index e8db8a40aff..00000000000 --- a/storage/src/vespa/storage/storageutil/palette.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** - * \class storage::Palette - * - * \brief Contains a set of distinct colors. - * - * When writing graphics like charts one wants to use distinct colors. - * This class defines some distinct colors. - */ - -#pragma once - -#include <vector> -#include <cstdint> -#include <iosfwd> - -namespace storage { - -class Palette { - std::vector<uint32_t> _colors; - -public: - Palette(uint32_t colorCount); - - uint32_t operator[](uint32_t colorIndex) const - { return _colors[colorIndex]; } - - void printHtmlTablePalette(std::ostream& out) const; -}; - -} // storage - diff --git a/storage/src/vespa/storage/storageutil/piechart.cpp b/storage/src/vespa/storage/storageutil/piechart.cpp deleted file mode 100644 index 60080a14ead..00000000000 --- a/storage/src/vespa/storage/storageutil/piechart.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "piechart.h" - -#include <iomanip> -#include <vespa/vespalib/util/exceptions.h> - -namespace storage { - -double PieChart::_minValue = 0.0000001; - -PieChart::Entry::Entry(double val, const std::string& name, int32_t col) - : _value(val), _name(name), _color(col) -{ -} - -void -PieChart::printHtmlHeadAdditions(std::ostream& out, const std::string& indent) -{ - (void) out; - (void) indent; - // FIXME this used to reference Yahoo-internal JS URIs. - // Deprecated functionality either way. -} - -PieChart::PieChart(const std::string& name, ColorScheme cs) - : _name(name), - _values(), - _colors(cs), - _printLabels(true) -{} - -PieChart::~PieChart() {} - -void -PieChart::add(double value, const std::string& name) -{ - if (value < _minValue) { - std::ostringstream ost; - ost << "Value of " << value << " is below the minimum supported value " - << "of the pie chart (" << _minValue << ")"; - throw vespalib::IllegalArgumentException(ost.str(), VESPA_STRLOC); - } - if (_colors == SCHEME_CUSTOM) { - throw vespalib::IllegalArgumentException( - "Using custom color scheme you need to supply a color for each " - "value.", VESPA_STRLOC); - } - _values.push_back(Entry(value, name, UNDEFINED)); -} - -void -PieChart::add(double value, const std::string& name, Color c) -{ - if (value < _minValue) { - std::ostringstream ost; - ost << "Value of " << value << " is below the minimum supported value " - << "of the pie chart (" << _minValue << ")"; - throw vespalib::IllegalArgumentException(ost.str(), VESPA_STRLOC); - } - if (_colors != SCHEME_CUSTOM) { - throw vespalib::IllegalArgumentException( - "Not using custom color scheme you cannot supply a custom " - "color for a value.", VESPA_STRLOC); - } - _values.push_back(Entry(value, name, c)); -} - -void -PieChart::add(double value, const std::string& name, int32_t color) -{ - if (value < _minValue) { - std::ostringstream ost; - ost << "Value of " << value << " is below the minimum supported value " - << "of the pie chart (" << _minValue << ")"; - throw vespalib::IllegalArgumentException(ost.str(), VESPA_STRLOC); - } - if (_colors != SCHEME_CUSTOM) { - throw vespalib::IllegalArgumentException( - "Not using custom color scheme you cannot supply a custom " - "color for a value.", VESPA_STRLOC); - } - _values.push_back(Entry(value, name, (Color) color)); -} - -void -PieChart::printCanvas(std::ostream& out, uint32_t width, uint32_t height) const -{ - out << "<div><canvas id=\"" << _name << "\" width=\"" << width - << "\" height=\"" << height << "\"/></div>"; -} - -namespace { - void printDatasetDefinition(std::ostream& o, const std::string& i, - const std::string& n, const std::vector<PieChart::Entry>& e) - { - o << i << " var " << n << "_dataset = {\n" << std::dec; - bool first = true; - for (std::vector<PieChart::Entry>::const_iterator it = e.begin(); - it != e.end(); ++it) - { - if (!first) o << ",\n"; - first = false; - o << i << " '" << it->_name << "': [[0," << it->_value - << "]]"; - } - o << "\n" << i << " };"; - } - - void printCustomColorScheme(std::ostream& o, const std::string& i, - const std::string& n, const std::vector<PieChart::Entry>& e) - { - o << " var " << n << "_customScheme = new Hash({\n" << std::hex; - bool first = true; - for (std::vector<PieChart::Entry>::const_iterator it = e.begin(); - it != e.end(); ++it) - { - if (!first) o << ",\n"; - first = false; - o << i << " '" << it->_name << "': '#" << std::setw(6) - << std::setfill('0') << (it->_color & 0x00FFFFFF) << "'"; - } - o << "\n" << i << " });" << std::dec; - } - - void printOptions(std::ostream& o, const std::string& i, - const std::string& n, const std::vector<PieChart::Entry>& e, - PieChart::ColorScheme c, bool printLabels) - { - o << " var " << n << "_options = {\n" - << i << " padding: {\n" - << i << " left: 0,\n" - << i << " right: 0,\n" - << i << " top: 0,\n" - << i << " bottom: 0,\n" - << i << " },\n" - << i << " background: {\n" - << i << " color: '#ffffff'\n" - << i << " },\n" - << i << " pieRadius: '0.4',\n"; - if (c == PieChart::SCHEME_CUSTOM) { - o << i << " \"colorScheme\": " << n << "_customScheme,\n"; - } else { - o << i << " colorScheme: '"; - switch (c) { - case PieChart::SCHEME_RED: o << "red"; break; - case PieChart::SCHEME_BLUE: o << "blue"; break; - case PieChart::SCHEME_CUSTOM: break; - } - o << "',\n"; - } - o << i << " axis: {\n" - << i << " labelColor: '#000000',\n" - << i << " x: {\n"; - if (!printLabels) { - o << i << " hide: true,\n"; - } - o << i << " ticks: [\n"; - bool first = true; - uint32_t tmp = 0; - for (std::vector<PieChart::Entry>::const_iterator it = e.begin(); - it != e.end(); ++it) - { - if (!first) o << ",\n"; - first = false; - o << i << " {v:" << tmp++ << ", label:'" << it->_name - << "'}"; - } - o << "\n" << i << " ]\n"; - o << i << " }\n" - << i << " }\n" - << i << " };"; - } - - void printPie(std::ostream& o, const std::string& i, const std::string& n) - { - o << " var " << n << "_pie = new Plotr.PieChart('" << n << "', " - << n << "_options);\n" - << i << " " << n << "_pie.addDataset(" << n << "_dataset);\n" - << i << " " << n << "_pie.render();"; - } -} - -void -PieChart::printScript(std::ostream& out, const std::string& indent) const -{ - out << "<script type=\"text/javascript\">\n"; - printDatasetDefinition(out, indent, _name, _values); - if (_colors == SCHEME_CUSTOM) { - out << "\n" << indent; - printCustomColorScheme(out, indent, _name, _values); - } - out << "\n" << indent; - printOptions(out, indent, _name, _values, _colors, _printLabels); - out << "\n" << indent; - printPie(out, indent, _name); - out << "\n" << indent << "</script>"; -} - -} // storage - diff --git a/storage/src/vespa/storage/storageutil/piechart.h b/storage/src/vespa/storage/storageutil/piechart.h deleted file mode 100644 index c0c26bdcb65..00000000000 --- a/storage/src/vespa/storage/storageutil/piechart.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** - * \class storage::PieChart - * \ingroup util - * - * \brief Helper library to print pie charts in HTML. - */ - -#pragma once - -#include <string> -#include <vector> -#include <ostream> - -namespace storage { - -class PieChart { -public: - static double _minValue; - - enum ColorScheme { - SCHEME_CUSTOM, - SCHEME_RED, - SCHEME_BLUE - }; - enum Color { - UNDEFINED = -1, - BLACK = 0x000000, - RED = 0xFF0000, - GREEN = 0x00FF00, - BLUE = 0x0000FF, - WHITE = 0xFFFFFF - }; - struct Entry { - double _value; - std::string _name; - int32_t _color; - - Entry(double val, const std::string& name, int32_t col); - }; - - static void printHtmlHeadAdditions( - std::ostream& out, const std::string& indent = ""); - -private: - const std::string _name; - std::vector<Entry> _values; - ColorScheme _colors; - bool _printLabels; - -public: - PieChart(const std::string&, ColorScheme = SCHEME_BLUE); - ~PieChart(); - - void printLabels(bool doprint) { _printLabels = doprint; } - - void add(double value, const std::string& name); - void add(double value, const std::string& name, Color c); - void add(double value, const std::string& name, int32_t color); - - void printCanvas(std::ostream& out, uint32_t width, uint32_t height) const; - void printScript(std::ostream& out, const std::string& indent = "") const; -}; - -} // storage - |