mirror of https://github.com/vitalif/dimple
Patched Order Rules
parent
660ba1d868
commit
f4ae0a014a
|
@ -1,5 +1,5 @@
|
||||||
<div id="chartContainer">
|
<div id="chartContainer">
|
||||||
<script src="/lib/d3.v3.min.js"></script>
|
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div id="chartContainer">
|
<div id="chartContainer">
|
||||||
<script src="/lib/d3.v3.min.js"></script>
|
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// This is the simple vertical grouped stacked 100% bar example
|
// This is the simple vertical grouped stacked 100% bar example
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div id="chartContainer">
|
<div id="chartContainer">
|
||||||
<script src="/lib/d3.v3.min.js"></script>
|
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// Start off with a couple of rows of data
|
// Start off with a couple of rows of data
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div id="chartContainer">
|
<div id="chartContainer">
|
||||||
<script src="/lib/d3.v3.min.js"></script>
|
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div id="chartContainer">
|
<div id="chartContainer">
|
||||||
<script src="/lib/d3.v3.min.js"></script>
|
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div id="chartContainer">
|
<div id="chartContainer">
|
||||||
<script src="/lib/d3.v3.min.js"></script>
|
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||||
|
|
|
@ -1,19 +1,34 @@
|
||||||
<div id="chartContainer">
|
<div id="chartContainer">
|
||||||
<script src="/lib/d3.v3.min.js"></script>
|
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
<script src="/dist/dimple.v2.0.2.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||||
d3.tsv("/data/example_data.tsv", function (data) {
|
d3.tsv("/data/example_data.tsv", function (data) {
|
||||||
var myChart = new dimple.chart(svg, data);
|
var myChart = new dimple.chart(svg, data);
|
||||||
myChart.setBounds(60, 50, 460, 280);
|
myChart.setBounds(60, 50, 460, 280);
|
||||||
var monthAxis = myChart.addCategoryAxis("x", "Month");
|
|
||||||
monthAxis.addOrderRule("Date");
|
data = [
|
||||||
var volumeAxis = myChart.addMeasureAxis("y", "Unit Sales");
|
{ "Int": 1, "Float": 234, "Text": "XFBGR", "Date": "12/5/99", "Group": "A"},
|
||||||
var profitAxis = myChart.addMeasureAxis("y", "Operating Profit");
|
{ "Int": 2, "Float": 54.35, "Text": "YTREB", "Date": "1/1/00", "Group": "A"},
|
||||||
myChart.addSeries("Quantity", dimple.plot.line, [monthAxis, volumeAxis]);
|
{ "Int": 3, "Float": -453, "Text": "XGFDY", "Date": "2 February 2007", "Group": "B"},
|
||||||
myChart.addSeries("Op. Profit", dimple.plot.line, [monthAxis, profitAxis]);
|
{ "Int": 4, "Float": 5436546, "Text": "XGFDE", "Date": "2000-03-01", "Group": "B"},
|
||||||
myChart.addLegend(200, 10, 380, 20, "right");
|
{ "Int": 5, "Float": 4323, "Text": "YTREB", "Date": "10/10/2000", "Group": "C"},
|
||||||
myChart.draw();
|
{ "Int": 6, "Float": 0, "Text": "GFDHN", "Date": "11/10/2000", "Group": "C"},
|
||||||
|
{ "Int": 7, "Float": -453, "Text": "TRET", "Date": "10/9/2000", "Group": "D"},
|
||||||
|
{ "Int": 1, "Float": 5436546, "Text": "GFDGFDHG", "Date": "10/10/2000", "Group": "E"}
|
||||||
|
];
|
||||||
|
var s = dimple._getOrderedList(data, "Int", { ordering : "Text" });
|
||||||
|
console.log(s);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// var monthAxis = myChart.addCategoryAxis("x", "Owner");
|
||||||
|
// monthAxis.addOrderRule("Brand");
|
||||||
|
// var volumeAxis = myChart.addMeasureAxis("y", "Unit Sales");
|
||||||
|
// var profitAxis = myChart.addMeasureAxis("y", "Operating Profit");
|
||||||
|
// myChart.addSeries("Quantity", dimple.plot.line, [monthAxis, volumeAxis]);
|
||||||
|
// myChart.addSeries("Op. Profit", dimple.plot.line, [monthAxis, profitAxis]);
|
||||||
|
// myChart.addLegend(200, 10, 380, 20, "right");
|
||||||
|
// myChart.draw();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
|
@ -3939,6 +3939,7 @@
|
||||||
mainArray = [].concat(mainField),
|
mainArray = [].concat(mainField),
|
||||||
fields = [].concat(mainField),
|
fields = [].concat(mainField),
|
||||||
defs = [];
|
defs = [];
|
||||||
|
|
||||||
// Force the level definitions into an array
|
// Force the level definitions into an array
|
||||||
if (levelDefinitions !== null && levelDefinitions !== undefined) {
|
if (levelDefinitions !== null && levelDefinitions !== undefined) {
|
||||||
defs = defs.concat(levelDefinitions);
|
defs = defs.concat(levelDefinitions);
|
||||||
|
@ -3947,7 +3948,9 @@
|
||||||
defs = defs.concat({ ordering: mainArray, desc: false });
|
defs = defs.concat({ ordering: mainArray, desc: false });
|
||||||
// Exclude fields if this does not contain a function
|
// Exclude fields if this does not contain a function
|
||||||
defs.forEach(function (def) {
|
defs.forEach(function (def) {
|
||||||
var field;
|
var field,
|
||||||
|
values = [],
|
||||||
|
tempFields = [];
|
||||||
if (typeof def.ordering === "function") {
|
if (typeof def.ordering === "function") {
|
||||||
for (field in data[0]) {
|
for (field in data[0]) {
|
||||||
if (data[0].hasOwnProperty(field) && fields.indexOf(field) === -1) {
|
if (data[0].hasOwnProperty(field) && fields.indexOf(field) === -1) {
|
||||||
|
@ -3956,6 +3959,21 @@
|
||||||
}
|
}
|
||||||
} else if (!(def.ordering instanceof Array)) {
|
} else if (!(def.ordering instanceof Array)) {
|
||||||
fields.push(def.ordering);
|
fields.push(def.ordering);
|
||||||
|
} else {
|
||||||
|
// We now receive fields as an array or values as an array which is a bit of an oversight in the API
|
||||||
|
// We will therefore check the values of the array against the fields in the data
|
||||||
|
for (field = 0; field < def.ordering.length; field += 1) {
|
||||||
|
if (data[0].hasOwnProperty(def.ordering[field])) {
|
||||||
|
tempFields.push(def.ordering[field]);
|
||||||
|
}
|
||||||
|
values.push(def.ordering[field]);
|
||||||
|
}
|
||||||
|
// If more than half of the values are fields we will assume that these are fields and not dimension values
|
||||||
|
if (tempFields.length > values.length / 2) {
|
||||||
|
fields.concat(tempFields);
|
||||||
|
} else {
|
||||||
|
def.values = values;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
rollupData = dimple._rollUp(data, mainArray, fields);
|
rollupData = dimple._rollUp(data, mainArray, fields);
|
||||||
|
@ -3968,7 +3986,6 @@
|
||||||
var desc = (def.desc === null || def.desc === undefined ? false : def.desc),
|
var desc = (def.desc === null || def.desc === undefined ? false : def.desc),
|
||||||
ordering = def.ordering,
|
ordering = def.ordering,
|
||||||
orderArray = [],
|
orderArray = [],
|
||||||
field = (typeof ordering === "string" ? ordering : null),
|
|
||||||
sum = function (array) {
|
sum = function (array) {
|
||||||
var total = 0,
|
var total = 0,
|
||||||
i;
|
i;
|
||||||
|
@ -4003,12 +4020,12 @@
|
||||||
sortStack.push(function (a, b) {
|
sortStack.push(function (a, b) {
|
||||||
return (desc ? -1 : 1) * ordering(a, b);
|
return (desc ? -1 : 1) * ordering(a, b);
|
||||||
});
|
});
|
||||||
} else if (ordering instanceof Array) {
|
} else if (def.values && def.values.length > 0) {
|
||||||
// The order list may be an array of arrays
|
// The order list may be an array of arrays
|
||||||
// combine the values with pipe delimiters.
|
// combine the values with pipe delimiters.
|
||||||
// The delimiter is irrelevant as long as it is consistent
|
// The delimiter is irrelevant as long as it is consistent
|
||||||
// with the sort predicate below
|
// with the sort predicate below
|
||||||
ordering.forEach(function (d) {
|
def.values.forEach(function (d) {
|
||||||
orderArray.push(([].concat(d)).join("|"));
|
orderArray.push(([].concat(d)).join("|"));
|
||||||
}, this);
|
}, this);
|
||||||
// Sort according to the axis position
|
// Sort according to the axis position
|
||||||
|
@ -4035,16 +4052,18 @@
|
||||||
return (desc ? -1 : 1) * (aIx - bIx);
|
return (desc ? -1 : 1) * (aIx - bIx);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Sort the data
|
([].concat(def.ordering)).forEach(function (field) {
|
||||||
sortStack.push(function (a, b) {
|
// Sort the data
|
||||||
// The result value
|
sortStack.push(function (a, b) {
|
||||||
var result = 0;
|
// The result value
|
||||||
// Find the field
|
var result = 0;
|
||||||
if (a[field] !== undefined && b[field] !== undefined) {
|
// Find the field
|
||||||
// Compare just the first mapped value
|
if (a[field] !== undefined && b[field] !== undefined) {
|
||||||
result = compare([].concat(a[field]), [].concat(b[field]));
|
// Compare just the first mapped value
|
||||||
}
|
result = compare([].concat(a[field]), [].concat(b[field]));
|
||||||
return (desc ? -1 : 1) * result;
|
}
|
||||||
|
return (desc ? -1 : 1) * result;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -8,6 +8,7 @@
|
||||||
mainArray = [].concat(mainField),
|
mainArray = [].concat(mainField),
|
||||||
fields = [].concat(mainField),
|
fields = [].concat(mainField),
|
||||||
defs = [];
|
defs = [];
|
||||||
|
|
||||||
// Force the level definitions into an array
|
// Force the level definitions into an array
|
||||||
if (levelDefinitions !== null && levelDefinitions !== undefined) {
|
if (levelDefinitions !== null && levelDefinitions !== undefined) {
|
||||||
defs = defs.concat(levelDefinitions);
|
defs = defs.concat(levelDefinitions);
|
||||||
|
@ -16,7 +17,9 @@
|
||||||
defs = defs.concat({ ordering: mainArray, desc: false });
|
defs = defs.concat({ ordering: mainArray, desc: false });
|
||||||
// Exclude fields if this does not contain a function
|
// Exclude fields if this does not contain a function
|
||||||
defs.forEach(function (def) {
|
defs.forEach(function (def) {
|
||||||
var field;
|
var field,
|
||||||
|
values = [],
|
||||||
|
tempFields = [];
|
||||||
if (typeof def.ordering === "function") {
|
if (typeof def.ordering === "function") {
|
||||||
for (field in data[0]) {
|
for (field in data[0]) {
|
||||||
if (data[0].hasOwnProperty(field) && fields.indexOf(field) === -1) {
|
if (data[0].hasOwnProperty(field) && fields.indexOf(field) === -1) {
|
||||||
|
@ -25,6 +28,21 @@
|
||||||
}
|
}
|
||||||
} else if (!(def.ordering instanceof Array)) {
|
} else if (!(def.ordering instanceof Array)) {
|
||||||
fields.push(def.ordering);
|
fields.push(def.ordering);
|
||||||
|
} else {
|
||||||
|
// We now receive fields as an array or values as an array which is a bit of an oversight in the API
|
||||||
|
// We will therefore check the values of the array against the fields in the data
|
||||||
|
for (field = 0; field < def.ordering.length; field += 1) {
|
||||||
|
if (data[0].hasOwnProperty(def.ordering[field])) {
|
||||||
|
tempFields.push(def.ordering[field]);
|
||||||
|
}
|
||||||
|
values.push(def.ordering[field]);
|
||||||
|
}
|
||||||
|
// If more than half of the values are fields we will assume that these are fields and not dimension values
|
||||||
|
if (tempFields.length > values.length / 2) {
|
||||||
|
fields.concat(tempFields);
|
||||||
|
} else {
|
||||||
|
def.values = values;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
rollupData = dimple._rollUp(data, mainArray, fields);
|
rollupData = dimple._rollUp(data, mainArray, fields);
|
||||||
|
@ -37,7 +55,6 @@
|
||||||
var desc = (def.desc === null || def.desc === undefined ? false : def.desc),
|
var desc = (def.desc === null || def.desc === undefined ? false : def.desc),
|
||||||
ordering = def.ordering,
|
ordering = def.ordering,
|
||||||
orderArray = [],
|
orderArray = [],
|
||||||
field = (typeof ordering === "string" ? ordering : null),
|
|
||||||
sum = function (array) {
|
sum = function (array) {
|
||||||
var total = 0,
|
var total = 0,
|
||||||
i;
|
i;
|
||||||
|
@ -72,12 +89,12 @@
|
||||||
sortStack.push(function (a, b) {
|
sortStack.push(function (a, b) {
|
||||||
return (desc ? -1 : 1) * ordering(a, b);
|
return (desc ? -1 : 1) * ordering(a, b);
|
||||||
});
|
});
|
||||||
} else if (ordering instanceof Array) {
|
} else if (def.values && def.values.length > 0) {
|
||||||
// The order list may be an array of arrays
|
// The order list may be an array of arrays
|
||||||
// combine the values with pipe delimiters.
|
// combine the values with pipe delimiters.
|
||||||
// The delimiter is irrelevant as long as it is consistent
|
// The delimiter is irrelevant as long as it is consistent
|
||||||
// with the sort predicate below
|
// with the sort predicate below
|
||||||
ordering.forEach(function (d) {
|
def.values.forEach(function (d) {
|
||||||
orderArray.push(([].concat(d)).join("|"));
|
orderArray.push(([].concat(d)).join("|"));
|
||||||
}, this);
|
}, this);
|
||||||
// Sort according to the axis position
|
// Sort according to the axis position
|
||||||
|
@ -104,16 +121,18 @@
|
||||||
return (desc ? -1 : 1) * (aIx - bIx);
|
return (desc ? -1 : 1) * (aIx - bIx);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Sort the data
|
([].concat(def.ordering)).forEach(function (field) {
|
||||||
sortStack.push(function (a, b) {
|
// Sort the data
|
||||||
// The result value
|
sortStack.push(function (a, b) {
|
||||||
var result = 0;
|
// The result value
|
||||||
// Find the field
|
var result = 0;
|
||||||
if (a[field] !== undefined && b[field] !== undefined) {
|
// Find the field
|
||||||
// Compare just the first mapped value
|
if (a[field] !== undefined && b[field] !== undefined) {
|
||||||
result = compare([].concat(a[field]), [].concat(b[field]));
|
// Compare just the first mapped value
|
||||||
}
|
result = compare([].concat(a[field]), [].concat(b[field]));
|
||||||
return (desc ? -1 : 1) * result;
|
}
|
||||||
|
return (desc ? -1 : 1) * result;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
define(["dimple"], function (dimple) {
|
define(["dimple"], function (dimple) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
xdescribe("_getOrderedList", function () {
|
describe("_getOrderedList", function () {
|
||||||
var data,
|
var data,
|
||||||
getResults;
|
getResults;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
define(["dimple"], function (dimple) {
|
define(["dimple"], function (dimple) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
xdescribe("_rollUp", function () {
|
describe("_rollUp", function () {
|
||||||
var data,
|
var data,
|
||||||
getResults;
|
getResults;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
define(["dimple", "d3"], function (dimple, d3) {
|
define(["dimple", "d3"], function (dimple, d3) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
xdescribe("newSvg", function () {
|
describe("newSvg", function () {
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
d3.select("body").append("div").attr("id", "itDiv");
|
d3.select("body").append("div").attr("id", "itDiv");
|
||||||
|
|
Loading…
Reference in New Issue