Skip to content

Commit

Permalink
Merge pull request #1420 from mapbox/v8-remove-ops-constants
Browse files Browse the repository at this point in the history
Removed constants and color ops
  • Loading branch information
lucaswoj committed Aug 12, 2015
2 parents 9d43bf1 + 390ae96 commit fb07b76
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 369 deletions.
7 changes: 1 addition & 6 deletions js/style/paint_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var reference = require('./reference');
var parseCSSColor = require('csscolorparser').parseCSSColor;
var colorOps = require('color-ops');

module.exports = {};

Expand All @@ -16,11 +15,7 @@ reference.paint.forEach(function(className) {

if (value === undefined) continue;
if (prop.type === 'color') {
if (Array.isArray(value)) {
value = colorOps[value[0]](value[2], value[1]);
} else {
value = parseCSSColor(value);
}
value = parseCSSColor(value);
}

Calculated.prototype[p] = value;
Expand Down
5 changes: 2 additions & 3 deletions js/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function Style(stylesheet, animationLoop) {

this._loaded = true;
this.stylesheet = stylesheet;
stylesheet.constants = stylesheet.constants || {};

var sources = stylesheet.sources;
for (var id in sources) {
Expand Down Expand Up @@ -102,7 +101,7 @@ Style.prototype = util.inherit(Evented, {
this._order = [];

for (var i = 0; i < this.stylesheet.layers.length; i++) {
layer = new StyleLayer(this.stylesheet.layers[i], this.stylesheet.constants);
layer = new StyleLayer(this.stylesheet.layers[i]);
this._layers[layer.id] = layer;
this._order.push(layer.id);
}
Expand Down Expand Up @@ -287,7 +286,7 @@ Style.prototype = util.inherit(Evented, {
throw new Error('There is already a layer with this ID');
}
if (!(layer instanceof StyleLayer)) {
layer = new StyleLayer(layer, this.stylesheet.constants);
layer = new StyleLayer(layer);
}
this._layers[layer.id] = layer;
this._order.splice(before ? this._order.indexOf(before) : Infinity, 0, layer.id);
Expand Down
89 changes: 0 additions & 89 deletions js/style/style_constant.js

This file was deleted.

42 changes: 8 additions & 34 deletions js/style/style_declaration.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var parseCSSColor = require('csscolorparser').parseCSSColor;
var ColorOps = require('color-ops');
var MapboxGLFunction = require('mapbox-gl-function');
var util = require('../util/util');

Expand Down Expand Up @@ -62,20 +61,13 @@ function transitioned(calculate) {

var colorCache = {};

function replaceStrings(color) {
color[2] = replaceStrings(color[2]);
if (color[3]) color[3] = replaceStrings(color[3]);
return color;
}

function parseColor(input) {

var output;
if (colorCache[input]) {
return colorCache[input];

// RGBA array
} else if (Array.isArray(input) && typeof input[0] === 'number') {
} else if (Array.isArray(input)) {
return input;

// GL function
Expand All @@ -86,36 +78,18 @@ function parseColor(input) {
})
});

// CSS color string
} else if (isString(input)) {
output = colorDowngrade(parseCSSColor(input));
// Color string
} else if (typeof input === 'string') {
var output = colorDowngrade(parseCSSColor(input));
colorCache[input] = output;
return output;

// color operation array
} else if (Array.isArray(input)) {
var op = input[0];
var degree = input[1];
input[2] = colorUpgrade(parseColor(input[2]));

if (op === 'mix') {
input[3] = colorUpgrade(parseColor(input[3]));
output = colorDowngrade(ColorOps[op](input[2], input[3], degree));
} else {
output = colorDowngrade(ColorOps[op](input[2], degree));
}
} else {
throw new Error('Invalid color ' + input);
}

colorCache[input] = output;
return output;
}

function colorUpgrade(color) {
return [color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 1];
}

function colorDowngrade(color) {
return [color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 1];
}

function isString(value) {
return typeof value === 'string' || value instanceof String;
}
13 changes: 5 additions & 8 deletions js/style/style_declaration_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var util = require('../util/util');
var reference = require('./reference');
var StyleConstant = require('./style_constant');
var StyleDeclaration = require('./style_declaration');

var lookup = {
Expand All @@ -16,14 +15,12 @@ reference.layer.type.values.forEach(function(type) {
});

function makeConstructor(reference) {
function StyleDeclarationSet(properties, constants) {
function StyleDeclarationSet(properties) {
this._values = {};
this._transitions = {};

this._constants = constants;

for (var k in properties) {
this[k] = StyleConstant.resolve(properties[k], this._constants);
this[k] = properties[k];
}
}

Expand All @@ -32,7 +29,7 @@ function makeConstructor(reference) {

Object.defineProperty(StyleDeclarationSet.prototype, k, {
set: function(v) {
this._values[k] = new StyleDeclaration(property, StyleConstant.resolve(v, this._constants));
this._values[k] = new StyleDeclaration(property, v);
},
get: function() {
return this._values[k].value;
Expand Down Expand Up @@ -80,6 +77,6 @@ function makeConstructor(reference) {
return StyleDeclarationSet;
}

module.exports = function(renderType, layerType, properties, constants) {
return new lookup[renderType][layerType](properties, constants);
module.exports = function(renderType, layerType, properties) {
return new lookup[renderType][layerType](properties);
};
13 changes: 5 additions & 8 deletions js/style/style_layer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
'use strict';

var util = require('../util/util');
var StyleConstant = require('./style_constant');
var StyleTransition = require('./style_transition');
var StyleDeclarationSet = require('./style_declaration_set');
var LayoutProperties = require('./layout_properties');
var PaintProperties = require('./paint_properties');

module.exports = StyleLayer;

function StyleLayer(layer, constants) {
function StyleLayer(layer) {
this._layer = layer;
this._constants = constants;

this.id = layer.id;
this.ref = layer.ref;
Expand All @@ -26,8 +24,7 @@ function StyleLayer(layer, constants) {
StyleLayer.prototype = {
resolveLayout: function() {
if (!this.ref) {
this.layout = new LayoutProperties[this.type](
StyleConstant.resolveAll(this._layer.layout, this._constants));
this.layout = new LayoutProperties[this.type](this._layer.layout);

if (this.layout['symbol-placement'] === 'line') {
if (!this.layout.hasOwnProperty('text-rotation-alignment')) {
Expand All @@ -42,7 +39,7 @@ StyleLayer.prototype = {
},

setLayoutProperty: function(name, value) {
this.layout[name] = StyleConstant.resolve(value, this._constants);
this.layout[name] = value;
},

getLayoutProperty: function(name) {
Expand All @@ -61,15 +58,15 @@ StyleLayer.prototype = {
if (!match)
continue;
this._resolved[match[1] || ''] =
new StyleDeclarationSet('paint', this.type, this._layer[p], this._constants);
new StyleDeclarationSet('paint', this.type, this._layer[p]);
}
},

setPaintProperty: function(name, value, klass) {
var declarations = this._resolved[klass || ''];
if (!declarations) {
declarations = this._resolved[klass || ''] =
new StyleDeclarationSet('paint', this.type, {}, this._constants);
new StyleDeclarationSet('paint', this.type, {});
}
declarations[name] = value;
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"documentation": "git+https://github.com/documentationjs/documentation#d341019b32a8a257a93bd55586e7f09f42e29341",
"eslint": "^0.14.1",
"istanbul": "^0.3.0",
"mapbox-gl-test-suite": "git+https://github.com/mapbox/mapbox-gl-test-suite.git#b7e38a3e4ec6ee2051ac4e8e2215994be91951e4",
"mapbox-gl-test-suite": "git+https://github.com/mapbox/mapbox-gl-test-suite.git#3fbb91f077faa19a4fd352a9d1b48f85604deabc",
"marked": "0.3.x",
"mkdirp": "^0.5.0",
"prova": "^2.1.2",
Expand Down
Loading

0 comments on commit fb07b76

Please sign in to comment.