Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement label for Y Axis Add editorconfig file #404

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]

# Change these settings to your own preference
indent_style = space
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rickshaw source code is indented with tabs!

indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
134 changes: 134 additions & 0 deletions examples/labels.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<!doctype html>
<link type="text/css" rel="stylesheet" href="../src/css/graph.css">
<link type="text/css" rel="stylesheet" href="../src/css/detail.css">
<link type="text/css" rel="stylesheet" href="css/lines.css">

<script src="../vendor/d3.v3.js"></script>
<script src="../rickshaw.js"></script>
<style type="text/css">
#axis0 {
position: absolute;
height: 250px;
width: 40px;
}
#axis1 {
position: absolute;
left: 1040px;
height: 250px;
width: 40px;
}
#chart {
left: 50px;
width: 1000px;
position: absolute;
}
#axis {
position: relative;
top: 250px;
left: 40px;
height: 40px;
}
</style>
<div id="axis0"></div>
<div id="chart"></div>
<div id="axis1"></div>
<div id="axis"></div>

<script type="text/javascript">
var data, graph, i, max, min, point, random, scales, series, _i, _j, _k, _l, _len, _len1, _len2, _ref;

data = [[], []];

random = new Rickshaw.Fixtures.RandomData(12 * 60 * 60);

for (i = _i = 0; _i < 100; i = ++_i) {
random.addData(data);
}

scales = [];

_ref = data[1];
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
point = _ref[_j];
point.y *= point.y;
}

for (_k = 0, _len1 = data.length; _k < _len1; _k++) {
series = data[_k];
min = Number.MAX_VALUE;
max = Number.MIN_VALUE;
for (_l = 0, _len2 = series.length; _l < _len2; _l++) {
point = series[_l];
min = Math.min(min, point.y);
max = Math.max(max, point.y);
}
if (_k === 0) {
scales.push(d3.scale.linear().domain([min, max]).nice());
} else {
scales.push(d3.scale.pow().domain([min, max]).nice());
}
}

graph = new Rickshaw.Graph({
element: document.getElementById("chart"),
renderer: 'line',
series: [
{
color: 'steelblue',
data: data[0],
name: 'Series A',
scale: scales[0]
}, {
color: 'lightblue',
data: data[1],
name: 'Series B',
scale: scales[1]
}
]
});

new Rickshaw.Graph.Axis.Y.Scaled({
element: document.getElementById('axis0'),
graph: graph,
orientation: 'right',
scale: scales[0],
label: {
text: 'ms',
color: 'black',
opacity: 0.5,
fontSize: '12px',
offsetX: '1em',
offsetY: '0em',
},
tickFormat: Rickshaw.Fixtures.Number.formatKMBT
});

new Rickshaw.Graph.Axis.Y.Scaled({
element: document.getElementById('axis1'),
graph: graph,
grid: false,
orientation: 'left',
scale: scales[1],
label: {
text: 'click',
color: 'red',
opacity: 0.5,
fontSize: '12px',
offsetX: '2em',
offsetY: '-7em',
},
tickFormat: Rickshaw.Fixtures.Number.formatKMBT
});

new Rickshaw.Graph.Axis.X( {
graph: graph,
orientation: 'bottom',
element: document.getElementById('axis')
});

new Rickshaw.Graph.HoverDetail({
graph: graph
});

graph.render();
</script>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rickshaw",
"version": "1.4.6",
"version": "1.4.7",
"dependencies": {
"d3": "~3.3.6"
},
Expand Down
23 changes: 20 additions & 3 deletions rickshaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,7 @@ Rickshaw.Graph.Axis.Y = Rickshaw.Class.create( {

initialize: function(args) {

this.args = args;
this.graph = args.graph;
this.orientation = args.orientation || 'right';

Expand Down Expand Up @@ -1707,6 +1708,21 @@ Rickshaw.Graph.Axis.Y = Rickshaw.Class.create( {
.attr("transform", transform)
.call(axis.ticks(this.ticks).tickSubdivide(0).tickSize(this.tickSize));

// add label
if (this.args.label && this.args.label.text) {
var label = this.args.label;
this.vis.append("text")
.attr("class", "axis-label")
.attr("text-anchor", "end")
.attr("y", label.offsetX || "1em")
.attr("x", label.offsetY || "1em")
.style("color", label.color || "black")
.style("opacity", label.opacity || "0.5")
.style("font-size", label.fontSize || "10px")
.attr("transform", "rotate(-90)")
.text(label.text);
}

return axis;
},

Expand Down Expand Up @@ -1931,6 +1947,8 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
line.element.classList.add('disabled');
}

self.graph.update();

}.bind(this);

var label = line.element.getElementsByTagName('span')[0];
Expand Down Expand Up @@ -1976,6 +1994,8 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {

}

self.graph.update();

};

};
Expand Down Expand Up @@ -2017,12 +2037,10 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
}

s.disabled = true;
self.graph.update();
};

s.enable = function() {
s.disabled = false;
self.graph.update();
};
} );
};
Expand Down Expand Up @@ -3759,7 +3777,6 @@ Rickshaw.Graph.Smoother = Rickshaw.Class.create({
max: 100,
slide: function( event, ui ) {
self.setScale(ui.value);
self.graph.update();
}
} );
} );
Expand Down
6 changes: 3 additions & 3 deletions rickshaw.min.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/js/Rickshaw.Graph.Axis.Y.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Rickshaw.Graph.Axis.Y = Rickshaw.Class.create( {

initialize: function(args) {

this.args = args;
this.graph = args.graph;
this.orientation = args.orientation || 'right';

Expand Down Expand Up @@ -101,6 +102,21 @@ Rickshaw.Graph.Axis.Y = Rickshaw.Class.create( {
.attr("transform", transform)
.call(axis.ticks(this.ticks).tickSubdivide(0).tickSize(this.tickSize));

// add label
if (this.args.label && this.args.label.text) {
var label = this.args.label;
this.vis.append("text")
.attr("class", "axis-label")
.attr("text-anchor", "end")
.attr("y", label.offsetX || "1em")
.attr("x", label.offsetY || "1em")
.style("color", label.color || "black")
.style("opacity", label.opacity || "0.5")
.style("font-size", label.fontSize || "10px")
.attr("transform", "rotate(-90)")
.text(label.text);
}

return axis;
},

Expand Down